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 => 7;
11 use Time::HiRes qw(sleep);
13 use Digest::SHA1 qw(sha1_base64);
14 use lib "$FindBin::Bin/lib";
19 use_ok('X11::XCB::Connection') or BAIL_OUT('Cannot load X11::XCB::Connection');
22 my $x = X11::XCB::Connection->new;
26 # Switch to the nineth workspace
27 $i3->command('9')->recv;
29 #####################################################################
30 # Create two windows and make sure focus switching works
31 #####################################################################
33 my $top = i3test::open_standard_window($x);
35 my $mid = i3test::open_standard_window($x);
37 my $bottom = i3test::open_standard_window($x);
40 diag("top id = " . $top->id);
41 diag("mid id = " . $mid->id);
42 diag("bottom id = " . $bottom->id);
45 # Returns the input focus after sending the given command to i3 via IPC
46 # end sleeping for half a second to make sure i3 reacted
51 $i3->command($msg)->recv;
52 return $x->input_focus;
55 $focus = $x->input_focus;
56 is($focus, $bottom->id, "Latest window focused");
58 $focus = focus_after("ml");
59 is($focus, $bottom->id, "Right window still focused");
61 $focus = focus_after("h");
62 is($focus, $mid->id, "Middle window focused");
64 #####################################################################
65 # Now goto a mark which does not exist
66 #####################################################################
68 my $random_mark = sha1_base64(rand());
70 $focus = focus_after("goto $random_mark");
71 is($focus, $mid->id, "focus unchanged");
73 $i3->command("mark $random_mark")->recv;
75 $focus = focus_after("k");
76 is($focus, $top->id, "Top window focused");
78 $focus = focus_after("goto $random_mark");
79 is($focus, $mid->id, "goto worked");