2 # vim:ts=4:sw=4:expandtab
4 # Please read the following documents before working on tests:
5 # • http://build.i3wm.org/docs/testsuite.html
8 # • http://build.i3wm.org/docs/lib-i3test.html
9 # (alternatively: perldoc ./testcases/lib/i3test.pm)
11 # • http://build.i3wm.org/docs/ipc.html
14 # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
15 # (unless you are already familiar with Perl)
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?
21 use i3test tests => 22;
22 use X11::XCB qw(:all);
23 use Time::HiRes qw(sleep);
26 use_ok('X11::XCB::Connection') or BAIL_OUT('Cannot load X11::XCB::Connection');
30 skip "stacking test not yet updated", 21;
32 my $x = X11::XCB::Connection->new;
36 # Switch to the nineth workspace
37 $i3->command('9')->recv;
39 #####################################################################
40 # Create two windows and make sure focus switching works
41 #####################################################################
43 my $top = i3test::open_standard_window($x);
44 my $mid = i3test::open_standard_window($x);
45 my $bottom = i3test::open_standard_window($x);
48 diag("top id = " . $top->id);
49 diag("mid id = " . $mid->id);
50 diag("bottom id = " . $bottom->id);
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
59 $i3->command($msg)->recv;
60 return $x->input_focus;
63 my $focus = $x->input_focus;
64 is($focus, $bottom->id, "Latest window focused");
66 $focus = focus_after("s");
67 is($focus, $bottom->id, "Last window still focused");
69 $focus = focus_after("k");
70 is($focus, $mid->id, "Middle window focused");
72 $focus = focus_after("k");
73 is($focus, $top->id, "Top window focused");
75 #####################################################################
77 #####################################################################
79 $focus = focus_after("k");
80 is($focus, $bottom->id, "Bottom window focused (wrapping to the top works)");
82 $focus = focus_after("j");
83 is($focus, $top->id, "Top window focused (wrapping to the bottom works)");
85 #####################################################################
86 # Restore of focus after moving windows out/into the stack
87 #####################################################################
89 $focus = focus_after("ml");
90 is($focus, $top->id, "Top window still focused (focus after moving)");
92 $focus = focus_after("h");
93 is($focus, $bottom->id, "Bottom window focused (focus after moving)");
95 my $new = i3test::open_standard_window($x);
98 # By now, we have this layout:
105 $focus = focus_after("l");
106 is($focus, $top->id, "Got top window");
108 $focus = focus_after("mh");
109 is($focus, $top->id, "Moved it into the stack");
111 $focus = focus_after("k");
112 is($focus, $new->id, "Window above is new");
114 $focus = focus_after("k");
115 is($focus, $bottom->id, "Window above is bottom");
117 $focus = focus_after("k");
118 is($focus, $mid->id, "Window above is mid");
120 $focus = focus_after("k");
121 is($focus, $top->id, "At top again");
123 $focus = focus_after("ml");
124 is($focus, $top->id, "Still at top, moved out");
126 $focus = focus_after("h");
127 is($focus, $mid->id, "At mid again");
129 $focus = focus_after("j");
130 is($focus, $bottom->id, "At bottom again");
132 $focus = focus_after("l");
133 is($focus, $top->id, "At top again");
135 $focus = focus_after("mh");
136 is($focus, $top->id, "Still at top, moved into");
138 $focus = focus_after("k");
139 is($focus, $bottom->id, "Window above is bottom");
141 $focus = focus_after("k");
142 is($focus, $mid->id, "Window above is mid");