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?
7 use Test::More tests => 24;
11 use Time::HiRes qw(sleep);
13 use lib "$FindBin::Bin/lib";
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');
21 my $x = X11::XCB::Connection->new;
23 my $sock = IO::Socket::UNIX->new(Peer => '/tmp/i3-ipc.sock');
24 isa_ok($sock, 'IO::Socket::UNIX');
26 # Switch to the nineth workspace
27 $sock->write(i3test::format_ipc_command("9"));
31 #####################################################################
32 # Create two windows and make sure focus switching works
33 #####################################################################
35 my $top = i3test::open_standard_window($x);
37 my $mid = i3test::open_standard_window($x);
39 my $bottom = i3test::open_standard_window($x);
42 diag("top id = " . $top->id);
43 diag("mid id = " . $mid->id);
44 diag("bottom id = " . $bottom->id);
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
53 $sock->write(i3test::format_ipc_command($msg));
55 return $x->input_focus;
58 $focus = $x->input_focus;
59 is($focus, $bottom->id, "Latest window focused");
61 $focus = focus_after("s");
62 is($focus, $bottom->id, "Last window still focused");
64 $focus = focus_after("k");
65 is($focus, $mid->id, "Middle window focused");
67 $focus = focus_after("k");
68 is($focus, $top->id, "Top window focused");
70 #####################################################################
72 #####################################################################
74 $focus = focus_after("k");
75 is($focus, $bottom->id, "Bottom window focused (wrapping to the top works)");
77 $focus = focus_after("j");
78 is($focus, $top->id, "Top window focused (wrapping to the bottom works)");
80 #####################################################################
81 # Restore of focus after moving windows out/into the stack
82 #####################################################################
84 $focus = focus_after("ml");
85 is($focus, $top->id, "Top window still focused (focus after moving)");
87 $focus = focus_after("h");
88 is($focus, $bottom->id, "Bottom window focused (focus after moving)");
90 my $new = i3test::open_standard_window($x);
93 # By now, we have this layout:
100 $focus = focus_after("l");
101 is($focus, $top->id, "Got top window");
103 $focus = focus_after("mh");
104 is($focus, $top->id, "Moved it into the stack");
106 $focus = focus_after("k");
107 is($focus, $new->id, "Window above is new");
109 $focus = focus_after("k");
110 is($focus, $bottom->id, "Window above is bottom");
112 $focus = focus_after("k");
113 is($focus, $mid->id, "Window above is mid");
115 $focus = focus_after("k");
116 is($focus, $top->id, "At top again");
118 $focus = focus_after("ml");
119 is($focus, $top->id, "Still at top, moved out");
121 $focus = focus_after("h");
122 is($focus, $mid->id, "At mid again");
124 $focus = focus_after("j");
125 is($focus, $bottom->id, "At bottom again");
127 $focus = focus_after("l");
128 is($focus, $top->id, "At top again");
130 $focus = focus_after("mh");
131 is($focus, $top->id, "Still at top, moved into");
133 $focus = focus_after("k");
134 is($focus, $bottom->id, "Window above is bottom");
136 $focus = focus_after("k");
137 is($focus, $mid->id, "Window above is mid");