]> git.sur5r.net Git - i3/i3/blob - testcases/t/09-stacking.t
083961fb22c5e93a26a651e9f1a03982c9966939
[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 Test::More tests => 24;
8 use Test::Deep;
9 use X11::XCB qw(:all);
10 use Data::Dumper;
11 use Time::HiRes qw(sleep);
12 use FindBin;
13 use lib "$FindBin::Bin/lib";
14 use i3test;
15
16 BEGIN {
17     use_ok('IO::Socket::UNIX') or BAIL_OUT('Cannot load IO::Socket::UNIX');
18     use_ok('X11::XCB::Connection') or BAIL_OUT('Cannot load X11::XCB::Connection');
19 }
20
21 X11::XCB::Connection->connect(':0');
22
23 my $sock = IO::Socket::UNIX->new(Peer => '/tmp/i3-ipc.sock');
24 isa_ok($sock, 'IO::Socket::UNIX');
25
26 # Switch to the nineth workspace
27 $sock->write(i3test::format_ipc_command("9"));
28
29 sleep(0.25);
30
31 #####################################################################
32 # Create two windows and make sure focus switching works
33 #####################################################################
34
35 my $top = i3test::open_standard_window;
36 sleep(0.25);
37 my $mid = i3test::open_standard_window;
38 sleep(0.25);
39 my $bottom = i3test::open_standard_window;
40 sleep(0.25);
41
42 diag("top id = " . $top->id);
43 diag("mid id = " . $mid->id);
44 diag("bottom id = " . $bottom->id);
45
46 #
47 # Returns the input focus after sending the given command to i3 via IPC
48 # end sleeping for half a second to make sure i3 reacted
49 #
50 sub focus_after {
51     my $msg = shift;
52
53     $sock->write(i3test::format_ipc_command($msg));
54     sleep(0.25);
55     return X11::XCB::Connection->input_focus;
56 }
57
58 $focus = X11::XCB::Connection->input_focus;
59 is($focus, $bottom->id, "Latest window focused");
60
61 $focus = focus_after("s");
62 is($focus, $bottom->id, "Last window still focused");
63
64 $focus = focus_after("k");
65 is($focus, $mid->id, "Middle window focused");
66
67 $focus = focus_after("k");
68 is($focus, $top->id, "Top window focused");
69
70 #####################################################################
71 # Test focus wrapping
72 #####################################################################
73
74 $focus = focus_after("k");
75 is($focus, $bottom->id, "Bottom window focused (wrapping to the top works)");
76
77 $focus = focus_after("j");
78 is($focus, $top->id, "Top window focused (wrapping to the bottom works)");
79
80 #####################################################################
81 # Restore of focus after moving windows out/into the stack
82 #####################################################################
83
84 $focus = focus_after("ml");
85 is($focus, $top->id, "Top window still focused (focus after moving)");
86
87 $focus = focus_after("h");
88 is($focus, $bottom->id, "Bottom window focused (focus after moving)");
89
90 my $new = i3test::open_standard_window;
91 sleep(0.25);
92
93 # By now, we have this layout:
94 # ----------------
95 # | mid    |
96 # | bottom | top
97 # | new    |
98 # ----------------
99
100 $focus = focus_after("l");
101 is($focus, $top->id, "Got top window");
102
103 $focus = focus_after("mh");
104 is($focus, $top->id, "Moved it into the stack");
105
106 $focus = focus_after("k");
107 is($focus, $new->id, "Window above is new");
108
109 $focus = focus_after("k");
110 is($focus, $bottom->id, "Window above is bottom");
111
112 $focus = focus_after("k");
113 is($focus, $mid->id, "Window above is mid");
114
115 $focus = focus_after("k");
116 is($focus, $top->id, "At top again");
117
118 $focus = focus_after("ml");
119 is($focus, $top->id, "Still at top, moved out");
120
121 $focus = focus_after("h");
122 is($focus, $mid->id, "At mid again");
123
124 $focus = focus_after("j");
125 is($focus, $bottom->id, "At bottom again");
126
127 $focus = focus_after("l");
128 is($focus, $top->id, "At top again");
129
130 $focus = focus_after("mh");
131 is($focus, $top->id, "Still at top, moved into");
132
133 $focus = focus_after("k");
134 is($focus, $bottom->id, "Window above is bottom");
135
136 $focus = focus_after("k");
137 is($focus, $mid->id, "Window above is mid");
138