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 i3test tests => 13;
9 use Time::HiRes qw(sleep);
12 use_ok('X11::XCB::Connection') or BAIL_OUT('Cannot load X11::XCB::Connection');
15 my $x = X11::XCB::Connection->new;
19 # Switch to the nineth workspace
20 $i3->command('9')->recv;
22 #####################################################################
23 # Create two windows and make sure focus switching works
24 #####################################################################
26 # Change mode of the container to "default" for following tests
27 $i3->command('d')->recv;
29 my $top = i3test::open_standard_window($x);
30 my $mid = i3test::open_standard_window($x);
31 my $bottom = i3test::open_standard_window($x);
34 diag("top id = " . $top->id);
35 diag("mid id = " . $mid->id);
36 diag("bottom id = " . $bottom->id);
39 # Returns the input focus after sending the given command to i3 via IPC
40 # end sleeping for half a second to make sure i3 reacted
45 $i3->command($msg)->recv;
46 return $x->input_focus;
49 $focus = $x->input_focus;
50 is($focus, $bottom->id, "Latest window focused");
52 $focus = focus_after("k");
53 is($focus, $mid->id, "Middle window focused");
55 $focus = focus_after("k");
56 is($focus, $top->id, "Top window focused");
58 #####################################################################
60 #####################################################################
62 $focus = focus_after("k");
63 is($focus, $bottom->id, "Bottom window focused (wrapping to the top works)");
65 $focus = focus_after("j");
66 is($focus, $top->id, "Top window focused (wrapping to the bottom works)");
68 ###############################################
69 # Test focus with empty containers and colspan
70 ###############################################
72 # Switch to the 10. workspace
73 $i3->command('10')->recv;
75 $top = i3test::open_standard_window($x);
76 $bottom = i3test::open_standard_window($x);
79 $focus = focus_after("mj");
80 $focus = focus_after("mh");
81 $focus = focus_after("k");
82 is($focus, $bottom->id, "Selecting top window without snapping doesn't work");
84 $focus = focus_after("sl");
85 is($focus, $bottom->id, "Bottom window focused");
87 $focus = focus_after("k");
88 is($focus, $top->id, "Top window focused");
90 # Same thing, but left/right instead of top/bottom
92 # Switch to the 11. workspace
93 $i3->command('11')->recv;
95 my $left = i3test::open_standard_window($x);
96 my $right = i3test::open_standard_window($x);
99 $focus = focus_after("ml");
100 $focus = focus_after("h");
101 $focus = focus_after("mk");
102 $focus = focus_after("l");
103 is($focus, $left->id, "Selecting right window without snapping doesn't work");
105 $focus = focus_after("sj");
106 is($focus, $left->id, "left window focused");
108 $focus = focus_after("l");
109 is($focus, $right->id, "right window focused");
112 diag( "Testing i3, Perl $], $^X" );