]> git.sur5r.net Git - i3/i3/blob - testcases/t/506-focus-right.t
Update ewmh focused only when new focus is different (#3496)
[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 # • https://build.i3wm.org/docs/testsuite.html
6 #   (or docs/testsuite)
7 #
8 # • https://build.i3wm.org/docs/lib-i3test.html
9 #   (alternatively: perldoc ./testcases/lib/i3test.pm)
10 #
11 # • https://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     sync_with_i3;
32     $x->root->warp_pointer(0, 0);
33     sync_with_i3;
34
35     ############################################################################
36     # Ensure that moving left and right works.
37     ############################################################################
38
39     # First ensure both workspaces have something to focus
40     cmd "workspace 1";
41     my $left_win = open_window;
42
43     cmd "workspace 2";
44     my $right_win = open_window;
45
46     is($x->input_focus, $right_win->id, 'right window focused');
47
48     cmd "focus output left";
49     is($x->input_focus, $left_win->id, 'left window focused');
50
51     cmd "focus output right";
52     is($x->input_focus, $right_win->id, 'right window focused');
53
54     cmd "focus output right";
55     is($x->input_focus, $left_win->id, 'left window focused (wrapping)');
56
57     cmd "focus output left";
58     is($x->input_focus, $right_win->id, 'right window focused (wrapping)');
59
60     ############################################################################
61     # Ensure that moving down/up from S0 doesn’t crash i3 and is a no-op.
62     ############################################################################
63
64     my $second = fresh_workspace(output => 1);
65     my $third_win = open_window;
66
67     cmd "focus output down";
68     is($x->input_focus, $third_win->id, 'right window still focused');
69
70     cmd "focus output up";
71     is($x->input_focus, $third_win->id, 'right window still focused');
72
73     does_i3_live;
74
75     exit_gracefully($pid);
76 }
77
78 # Screen setup looks like this:
79 # +----+
80 # |    |--------+
81 # | S1 |   S2   |
82 # |    |--------+
83 # +----+
84 #
85 my $config = <<EOT;
86 # i3 config file (v4)
87 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
88
89 fake-outputs 1080x1920+0+0,1920x1080+1080+500
90 EOT
91
92 test_focus_left_right($config);
93
94 # Screen setup looks like this:
95 # +----+--------+
96 # |    |   S2   |
97 # | S1 |--------+
98 # |    |
99 # +----+
100 #
101 $config = <<EOT;
102 # i3 config file (v4)
103 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
104
105 fake-outputs 1080x1920+0+0,1920x200+1080+0
106 EOT
107
108 test_focus_left_right($config);
109
110 # Screen setup looks like this:
111 # +----+
112 # |    |
113 # | S1 |--------+
114 # |    |   S2   |
115 # +----+--------+
116 #
117 $config = <<EOT;
118 # i3 config file (v4)
119 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
120
121 fake-outputs 1080x1920+0+0,1920x200+1080+1720
122 EOT
123
124 test_focus_left_right($config);
125
126 # Screen setup looks like this:
127 # +----+        +----+
128 # |    |        |    |
129 # | S1 |--------+ S3 |
130 # |    |   S2   |    |
131 # +----+--------+----+
132 #
133 $config = <<EOT;
134 # i3 config file (v4)
135 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
136
137 fake-outputs 1080x1920+0+0,1920x200+1080+1720,1080x1920+1280+0
138 EOT
139
140 my $pid = launch_with_config($config);
141
142 my $i3 = i3(get_socket_path(0));
143
144 sync_with_i3;
145 $x->root->warp_pointer(0, 0);
146 sync_with_i3;
147
148 ############################################################################
149 # Ensure that focusing right/left works in the expected order.
150 ############################################################################
151
152 sub get_focused_output {
153     my $tree = i3(get_socket_path())->get_tree->recv;
154     my ($focused_id) = @{$tree->{focus}};
155     my ($output) = grep { $_->{id} == $focused_id } @{$tree->{nodes}};
156     return $output->{name};
157 }
158
159 is(get_focused_output(), 'fake-0', 'focus on fake-0');
160
161 cmd 'focus output right';
162 is(get_focused_output(), 'fake-1', 'focus on fake-1');
163
164 cmd 'focus output right';
165 is(get_focused_output(), 'fake-2', 'focus on fake-2');
166
167 cmd 'focus output left';
168 is(get_focused_output(), 'fake-1', 'focus on fake-1');
169
170 cmd 'focus output left';
171 is(get_focused_output(), 'fake-0', 'focus on fake-0');
172
173 cmd 'focus output left';
174 is(get_focused_output(), 'fake-2', 'focus on fake-2 (wrapping)');
175
176 cmd 'focus output right';
177 is(get_focused_output(), 'fake-0', 'focus on fake-0 (wrapping)');
178
179 exit_gracefully($pid);
180
181 done_testing;