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