]> git.sur5r.net Git - i3/i3/blob - testcases/t/506-focus-right.t
1b8be06ddeae06ed7fdcec853db3b9d8cb03c70f
[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 from S0 doesn’t crash i3.
61     ############################################################################
62
63     my $second = fresh_workspace(output => 1);
64
65     cmd "focus output down";
66
67     does_i3_live;
68
69     exit_gracefully($pid);
70 }
71
72 # Screen setup looks like this:
73 # +----+
74 # |    |--------+
75 # | S1 |   S2   |
76 # |    |--------+
77 # +----+
78 #
79 my $config = <<EOT;
80 # i3 config file (v4)
81 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
82
83 fake-outputs 1080x1920+0+0,1920x1080+1080+500
84 EOT
85
86 test_focus_left_right($config);
87
88 # Screen setup looks like this:
89 # +----+--------+
90 # |    |   S2   |
91 # | S1 |--------+
92 # |    |
93 # +----+
94 #
95 $config = <<EOT;
96 # i3 config file (v4)
97 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
98
99 fake-outputs 1080x1920+0+0,1920x200+1080+0
100 EOT
101
102 test_focus_left_right($config);
103
104 # Screen setup looks like this:
105 # +----+
106 # |    |
107 # | S1 |--------+
108 # |    |   S2   |
109 # +----+--------+
110 #
111 $config = <<EOT;
112 # i3 config file (v4)
113 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
114
115 fake-outputs 1080x1920+0+0,1920x200+1080+1720
116 EOT
117
118 test_focus_left_right($config);
119
120 # Screen setup looks like this:
121 # +----+        +----+
122 # |    |        |    |
123 # | S1 |--------+ S3 |
124 # |    |   S2   |    |
125 # +----+--------+----+
126 #
127 $config = <<EOT;
128 # i3 config file (v4)
129 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
130
131 fake-outputs 1080x1920+0+0,1920x200+1080+1720,1080x1920+1280+0
132 EOT
133
134 my $pid = launch_with_config($config);
135
136 my $i3 = i3(get_socket_path(0));
137
138 $x->root->warp_pointer(0, 0);
139 sync_with_i3;
140
141 ############################################################################
142 # Ensure that focusing right/left works in the expected order.
143 ############################################################################
144
145 sub get_focused_output {
146     my $tree = i3(get_socket_path())->get_tree->recv;
147     my ($focused_id) = @{$tree->{focus}};
148     my ($output) = grep { $_->{id} == $focused_id } @{$tree->{nodes}};
149     return $output->{name};
150 }
151
152 is(get_focused_output(), 'fake-0', 'focus on fake-0');
153
154 cmd 'focus output right';
155 is(get_focused_output(), 'fake-1', 'focus on fake-1');
156
157 cmd 'focus output right';
158 is(get_focused_output(), 'fake-2', 'focus on fake-2');
159
160 cmd 'focus output left';
161 is(get_focused_output(), 'fake-1', 'focus on fake-1');
162
163 cmd 'focus output left';
164 is(get_focused_output(), 'fake-0', 'focus on fake-0');
165
166 cmd 'focus output left';
167 is(get_focused_output(), 'fake-2', 'focus on fake-2 (wrapping)');
168
169 cmd 'focus output right';
170 is(get_focused_output(), 'fake-0', 'focus on fake-0 (wrapping)');
171
172 exit_gracefully($pid);
173
174 done_testing;