]> git.sur5r.net Git - i3/i3/blob - testcases/t/09-stacking.t
Merge branch 'next'
[i3/i3] / testcases / t / 09-stacking.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3 # Beware that this test uses workspace 9 to perform some tests (it expects
4 # the workspace to be empty).
5 # TODO: skip it by default?
6
7 use i3test tests => 22;
8 use X11::XCB qw(:all);
9 use Time::HiRes qw(sleep);
10
11 BEGIN {
12     use_ok('X11::XCB::Connection') or BAIL_OUT('Cannot load X11::XCB::Connection');
13 }
14
15 SKIP: {
16     skip "stacking test not yet updated", 21;
17
18 my $x = X11::XCB::Connection->new;
19
20 my $i3 = i3;
21
22 # Switch to the nineth workspace
23 $i3->command('9')->recv;
24
25 #####################################################################
26 # Create two windows and make sure focus switching works
27 #####################################################################
28
29 my $top = i3test::open_standard_window($x);
30 sleep(0.25);
31 my $mid = i3test::open_standard_window($x);
32 sleep(0.25);
33 my $bottom = i3test::open_standard_window($x);
34 sleep(0.25);
35
36 diag("top id = " . $top->id);
37 diag("mid id = " . $mid->id);
38 diag("bottom id = " . $bottom->id);
39
40 #
41 # Returns the input focus after sending the given command to i3 via IPC
42 # end sleeping for half a second to make sure i3 reacted
43 #
44 sub focus_after {
45     my $msg = shift;
46
47     $i3->command($msg)->recv;
48     return $x->input_focus;
49 }
50
51 $focus = $x->input_focus;
52 is($focus, $bottom->id, "Latest window focused");
53
54 $focus = focus_after("s");
55 is($focus, $bottom->id, "Last window still focused");
56
57 $focus = focus_after("k");
58 is($focus, $mid->id, "Middle window focused");
59
60 $focus = focus_after("k");
61 is($focus, $top->id, "Top window focused");
62
63 #####################################################################
64 # Test focus wrapping
65 #####################################################################
66
67 $focus = focus_after("k");
68 is($focus, $bottom->id, "Bottom window focused (wrapping to the top works)");
69
70 $focus = focus_after("j");
71 is($focus, $top->id, "Top window focused (wrapping to the bottom works)");
72
73 #####################################################################
74 # Restore of focus after moving windows out/into the stack
75 #####################################################################
76
77 $focus = focus_after("ml");
78 is($focus, $top->id, "Top window still focused (focus after moving)");
79
80 $focus = focus_after("h");
81 is($focus, $bottom->id, "Bottom window focused (focus after moving)");
82
83 my $new = i3test::open_standard_window($x);
84 sleep(0.25);
85
86 # By now, we have this layout:
87 # ----------------
88 # | mid    |
89 # | bottom | top
90 # | new    |
91 # ----------------
92
93 $focus = focus_after("l");
94 is($focus, $top->id, "Got top window");
95
96 $focus = focus_after("mh");
97 is($focus, $top->id, "Moved it into the stack");
98
99 $focus = focus_after("k");
100 is($focus, $new->id, "Window above is new");
101
102 $focus = focus_after("k");
103 is($focus, $bottom->id, "Window above is bottom");
104
105 $focus = focus_after("k");
106 is($focus, $mid->id, "Window above is mid");
107
108 $focus = focus_after("k");
109 is($focus, $top->id, "At top again");
110
111 $focus = focus_after("ml");
112 is($focus, $top->id, "Still at top, moved out");
113
114 $focus = focus_after("h");
115 is($focus, $mid->id, "At mid again");
116
117 $focus = focus_after("j");
118 is($focus, $bottom->id, "At bottom again");
119
120 $focus = focus_after("l");
121 is($focus, $top->id, "At top again");
122
123 $focus = focus_after("mh");
124 is($focus, $top->id, "Still at top, moved into");
125
126 $focus = focus_after("k");
127 is($focus, $bottom->id, "Window above is bottom");
128
129 $focus = focus_after("k");
130 is($focus, $mid->id, "Window above is mid");
131
132 }