]> git.sur5r.net Git - i3/i3/blob - testcases/t/506-focus-right.t
Merge branch 'next'
[i3/i3] / testcases / t / 506-focus-right.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3 #
4 # Please read the following documents before working on tests:
5 # • http://build.i3wm.org/docs/testsuite.html
6 #   (or docs/testsuite)
7 #
8 # • http://build.i3wm.org/docs/lib-i3test.html
9 #   (alternatively: perldoc ./testcases/lib/i3test.pm)
10 #
11 # • http://build.i3wm.org/docs/ipc.html
12 #   (or docs/ipc)
13 #
14 # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
15 #   (unless you are already familiar with Perl)
16 #
17 # Verifies that focus output right works with monitor setups that don’t line up
18 # on their x/y coordinates.
19 #
20 # ticket #771, bug still present in commit dd743f3b55b2f86d9f1f69ef7952ae8ece4de504
21 #
22 use i3test i3_autostart => 0;
23
24 sub test_focus_left_right {
25     my ($config) = @_;
26
27     my $pid = launch_with_config($config);
28
29     my $i3 = i3(get_socket_path(0));
30
31     $x->root->warp_pointer(0, 0);
32     sync_with_i3;
33
34     ############################################################################
35     # Ensure that moving left and right works.
36     ############################################################################
37
38     # First ensure both workspaces have something to focus
39     cmd "workspace 1";
40     my $left_win = open_window;
41
42     cmd "workspace 2";
43     my $right_win = open_window;
44
45     is($x->input_focus, $right_win->id, 'right window focused');
46
47     cmd "focus output left";
48     is($x->input_focus, $left_win->id, 'left window focused');
49
50     cmd "focus output right";
51     is($x->input_focus, $right_win->id, 'right window focused');
52
53     cmd "focus output right";
54     is($x->input_focus, $left_win->id, 'left window focused (wrapping)');
55
56     cmd "focus output left";
57     is($x->input_focus, $right_win->id, 'right window focused (wrapping)');
58
59     ############################################################################
60     # Ensure that moving down/up from S0 doesn’t crash i3 and is a no-op.
61     ############################################################################
62
63     my $second = fresh_workspace(output => 1);
64     my $third_win = open_window;
65
66     cmd "focus output down";
67     is($x->input_focus, $third_win->id, 'right window still focused');
68
69     cmd "focus output up";
70     is($x->input_focus, $third_win->id, 'right window still focused');
71
72     does_i3_live;
73
74     exit_gracefully($pid);
75 }
76
77 # Screen setup looks like this:
78 # +----+
79 # |    |--------+
80 # | S1 |   S2   |
81 # |    |--------+
82 # +----+
83 #
84 my $config = <<EOT;
85 # i3 config file (v4)
86 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
87
88 fake-outputs 1080x1920+0+0,1920x1080+1080+500
89 EOT
90
91 test_focus_left_right($config);
92
93 # Screen setup looks like this:
94 # +----+--------+
95 # |    |   S2   |
96 # | S1 |--------+
97 # |    |
98 # +----+
99 #
100 $config = <<EOT;
101 # i3 config file (v4)
102 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
103
104 fake-outputs 1080x1920+0+0,1920x200+1080+0
105 EOT
106
107 test_focus_left_right($config);
108
109 # Screen setup looks like this:
110 # +----+
111 # |    |
112 # | S1 |--------+
113 # |    |   S2   |
114 # +----+--------+
115 #
116 $config = <<EOT;
117 # i3 config file (v4)
118 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
119
120 fake-outputs 1080x1920+0+0,1920x200+1080+1720
121 EOT
122
123 test_focus_left_right($config);
124
125 # Screen setup looks like this:
126 # +----+        +----+
127 # |    |        |    |
128 # | S1 |--------+ S3 |
129 # |    |   S2   |    |
130 # +----+--------+----+
131 #
132 $config = <<EOT;
133 # i3 config file (v4)
134 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
135
136 fake-outputs 1080x1920+0+0,1920x200+1080+1720,1080x1920+1280+0
137 EOT
138
139 my $pid = launch_with_config($config);
140
141 my $i3 = i3(get_socket_path(0));
142
143 $x->root->warp_pointer(0, 0);
144 sync_with_i3;
145
146 ############################################################################
147 # Ensure that focusing right/left works in the expected order.
148 ############################################################################
149
150 sub get_focused_output {
151     my $tree = i3(get_socket_path())->get_tree->recv;
152     my ($focused_id) = @{$tree->{focus}};
153     my ($output) = grep { $_->{id} == $focused_id } @{$tree->{nodes}};
154     return $output->{name};
155 }
156
157 is(get_focused_output(), 'fake-0', 'focus on fake-0');
158
159 cmd 'focus output right';
160 is(get_focused_output(), 'fake-1', 'focus on fake-1');
161
162 cmd 'focus output right';
163 is(get_focused_output(), 'fake-2', 'focus on fake-2');
164
165 cmd 'focus output left';
166 is(get_focused_output(), 'fake-1', 'focus on fake-1');
167
168 cmd 'focus output left';
169 is(get_focused_output(), 'fake-0', 'focus on fake-0');
170
171 cmd 'focus output left';
172 is(get_focused_output(), 'fake-2', 'focus on fake-2 (wrapping)');
173
174 cmd 'focus output right';
175 is(get_focused_output(), 'fake-0', 'focus on fake-0 (wrapping)');
176
177 exit_gracefully($pid);
178
179 done_testing;