]> git.sur5r.net Git - i3/i3/blob - testcases/t/06-focus.t
bugfix: don’t clean up workspace when switching to the same workspace
[i3/i3] / testcases / t / 06-focus.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 i3test tests => 13;
8 use X11::XCB qw(:all);
9 use Time::HiRes qw(sleep);
10
11 BEGIN {
12     use_ok('X11::XCB::Connection') or BAIL_OUT('Cannot load X11::XCB::Connection');
13 }
14
15 my $x = X11::XCB::Connection->new;
16
17 my $i3 = i3;
18
19 # Switch to the nineth workspace
20 $i3->command('9')->recv;
21
22 #####################################################################
23 # Create two windows and make sure focus switching works
24 #####################################################################
25
26 # Change mode of the container to "default" for following tests
27 $i3->command('d')->recv;
28
29 my $top = i3test::open_standard_window($x);
30 my $mid = i3test::open_standard_window($x);
31 my $bottom = i3test::open_standard_window($x);
32 sleep(0.25);
33
34 diag("top id = " . $top->id);
35 diag("mid id = " . $mid->id);
36 diag("bottom id = " . $bottom->id);
37
38 #
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
41 #
42 sub focus_after {
43     my $msg = shift;
44
45     $i3->command($msg)->recv;
46     return $x->input_focus;
47 }
48
49 $focus = $x->input_focus;
50 is($focus, $bottom->id, "Latest window focused");
51
52 $focus = focus_after("k");
53 is($focus, $mid->id, "Middle window focused");
54
55 $focus = focus_after("k");
56 is($focus, $top->id, "Top window focused");
57
58 #####################################################################
59 # Test focus wrapping
60 #####################################################################
61
62 $focus = focus_after("k");
63 is($focus, $bottom->id, "Bottom window focused (wrapping to the top works)");
64
65 $focus = focus_after("j");
66 is($focus, $top->id, "Top window focused (wrapping to the bottom works)");
67
68 ###############################################
69 # Test focus with empty containers and colspan
70 ###############################################
71
72 # Switch to the 10. workspace
73 $i3->command('10')->recv;
74
75 $top = i3test::open_standard_window($x);
76 $bottom = i3test::open_standard_window($x);
77 sleep 0.25;
78
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");
83
84 $focus = focus_after("sl");
85 is($focus, $bottom->id, "Bottom window focused");
86
87 $focus = focus_after("k");
88 is($focus, $top->id, "Top window focused");
89
90 # Same thing, but left/right instead of top/bottom
91
92 # Switch to the 11. workspace
93 $i3->command('11')->recv;
94
95 my $left = i3test::open_standard_window($x);
96 my $right = i3test::open_standard_window($x);
97 sleep 0.25;
98
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");
104
105 $focus = focus_after("sj");
106 is($focus, $left->id, "left window focused");
107
108 $focus = focus_after("l");
109 is($focus, $right->id, "right window focused");
110
111
112 diag( "Testing i3, Perl $], $^X" );