1package core
2
3import "testing"
4
5func TestKeyboardFocusOrder(t *testing.T) {
6 a := &screen{}
7 windows := map[*screen]WindowID{a: 1}
8 shown := true
9 cand := keyboardCandidates{window: 1, layerShown: func(WindowID) bool { return shown }, windows: func() map[*screen]WindowID { return windows }}
10 var k keyboard
11 if got := k.focus(cand); got != 1 {
12 t.Fatalf("focus = %d, want the window", got)
13 }
14 if !k.clickLayer(5, map[*screen]WindowID{a: 1}) || k.clickLayer(5, windows) {
15 t.Fatal("clickLayer change report")
16 }
17 if got := k.focus(cand); got != 5 {
18 t.Fatalf("focus = %d, want the clicked layer", got)
19 }
20 grab := cand
21 grab.grab = 7
22 if got := k.focus(grab); got != 7 {
23 t.Fatalf("focus = %d, want the grabbing popup", got)
24 }
25 grab.exclusive = 9
26 if got := k.focus(grab); got != 9 {
27 t.Fatalf("focus = %d, want the exclusive layer", got)
28 }
29 // The grab closed: the clicked layer still holds the keyboard.
30 if got := k.focus(cand); got != 5 {
31 t.Fatalf("focus = %d, want the clicked layer back", got)
32 }
33 // A window focus change on any output takes it back for good.
34 windows = map[*screen]WindowID{a: 2}
35 cand.window = 2
36 if got := k.focus(cand); got != 2 {
37 t.Fatalf("focus = %d, want the new window", got)
38 }
39 windows = map[*screen]WindowID{a: 1}
40 cand.window = 1
41 if got := k.focus(cand); got != 1 || k.layer != 0 {
42 t.Fatalf("focus = %d, layer %d; the layer must not come back", got, k.layer)
43 }
44}
45
46func TestKeyboardHiddenLayerLosesFocus(t *testing.T) {
47 windows := map[*screen]WindowID{}
48 shown := false
49 cand := keyboardCandidates{window: 1, layerShown: func(WindowID) bool { return shown }, windows: func() map[*screen]WindowID { return windows }}
50 var k keyboard
51 k.clickLayer(5, map[*screen]WindowID{})
52 if got := k.focus(cand); got != 1 {
53 t.Fatalf("focus = %d, want the window", got)
54 }
55 shown = true
56 if got := k.focus(cand); got != 1 {
57 t.Fatalf("focus = %d, the hidden layer must not come back", got)
58 }
59 k.clickLayer(5, map[*screen]WindowID{})
60 k.takeBack()
61 if got := k.focus(cand); got != 1 {
62 t.Fatalf("focus = %d after takeBack", got)
63 }
64}
65
66func TestKeyboardInhibit(t *testing.T) {
67 var k keyboard
68 if _, _, changed := k.inhibit(1, false); changed {
69 t.Fatal("no inhibitor changed")
70 }
71 if rel, act, changed := k.inhibit(1, true); rel != 0 || act != 1 || !changed || !k.inhibited(1) {
72 t.Fatalf("activate = %d, %d, %v", rel, act, changed)
73 }
74 if _, _, changed := k.inhibit(1, true); changed {
75 t.Fatal("same inhibitor changed")
76 }
77 if rel, act, changed := k.inhibit(2, true); rel != 1 || act != 2 || !changed {
78 t.Fatalf("switch = %d, %d, %v", rel, act, changed)
79 }
80 if rel, act, changed := k.inhibit(0, true); rel != 2 || act != 0 || !changed || k.inhibited(0) {
81 t.Fatalf("release = %d, %d, %v", rel, act, changed)
82 }
83}