aboutsummaryrefslogtreecommitdiff
path: root/testcases/t/510-focus-across-outputs.t
blob: 621119bbcdbe0caa8b140caf8720e23b0ef42a3f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#!perl
# vim:ts=4:sw=4:expandtab
#
# Please read the following documents before working on tests:
# • https://build.i3wm.org/docs/testsuite.html
#   (or docs/testsuite)
#
# • https://build.i3wm.org/docs/lib-i3test.html
#   (alternatively: perldoc ./testcases/lib/i3test.pm)
#
# • https://build.i3wm.org/docs/ipc.html
#   (or docs/ipc)
#
# • https://i3wm.org/downloads/modern_perl_a4.pdf
#   (unless you are already familiar with Perl)
#
# Tests that switching workspaces via 'focus $dir' never leaves a floating
# window focused.
#
use i3test i3_config => <<EOT;
# i3 config file (v4)
font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1

fake-outputs 1024x768+0+0,1024x768+1024+0,1024x768+0+768,1024x768+1024+768
EOT

my $s0_ws = fresh_workspace;
my $first = open_window;
my $second = open_window;
my $third = open_window;
cmd 'floating toggle';

# Focus screen 1
sync_with_i3;
$x->root->warp_pointer(1025, 0);
sync_with_i3;
my $s1_ws = fresh_workspace;

my $fourth = open_window;

# Focus screen 2
sync_with_i3;
$x->root->warp_pointer(0, 769);
sync_with_i3;
my $s2_ws = fresh_workspace;

my $fifth = open_window;

# Focus screen 3
sync_with_i3;
$x->root->warp_pointer(1025, 769);
sync_with_i3;
my $s3_ws = fresh_workspace;

my $sixth = open_window;
my $seventh = open_window;
my $eighth = open_window;
cmd 'floating toggle';

# Layout should look like this (windows 3 and 8 are floating):
#     S0      S1
# ┌───┬───┬───────┐
# │ ┌─┴─┐ │       │
# │1│ 3 │2│   4   │
# │ └─┬─┘ │       │
# ├───┴───┼───┬───┤
# │       │ ┌─┴─┐ │
# │   5   │6│ 8 │7│
# │       │ └─┬─┘ │
# └───────┴───┴───┘
#    S2       S3
#
###################################################################
# Test that focus (left|down|right|up) doesn't focus floating
# windows when moving into horizontally-split workspaces.
###################################################################

sub reset_focus {
    my $ws = shift;
    cmd "workspace $ws; focus floating";
}

cmd "workspace $s1_ws";
cmd 'focus left';
is($x->input_focus, $second->id, 'second window focused');
reset_focus $s0_ws;

cmd "workspace $s1_ws";
cmd 'focus down';
is($x->input_focus, $seventh->id, 'seventh window focused');
reset_focus $s3_ws;

cmd "workspace $s2_ws";
cmd 'focus right';
is($x->input_focus, $seventh->id, 'seventh window focused');
reset_focus $s3_ws;

cmd "workspace $s2_ws";
cmd 'focus up';
is($x->input_focus, $second->id, 'second window focused');
reset_focus $s0_ws;

###################################################################
# Put the workspaces on screens 0 and 3 into vertical split mode
# and test focus (left|down|right|up) again.
###################################################################

cmd "workspace $s0_ws";
is($x->input_focus, $third->id, 'third window focused');
cmd 'focus parent';
cmd 'focus parent';
cmd 'split v';
# Focus second or else $first gets to the top of the focus stack.
cmd '[id=' . $second->id . '] focus';
reset_focus $s0_ws;

cmd "workspace $s3_ws";
is($x->input_focus, $eighth->id, 'eighth window focused');
cmd 'focus parent';
cmd 'focus parent';
cmd 'split v';
cmd '[id=' . $sixth->id . '] focus';
reset_focus $s3_ws;

cmd "workspace $s1_ws";
cmd 'focus left';
is($x->input_focus, $second->id, 'second window focused');
reset_focus $s0_ws;

cmd "workspace $s1_ws";
cmd 'focus down';
is($x->input_focus, $sixth->id, 'sixth window focused');
reset_focus $s3_ws;

cmd "workspace $s2_ws";
cmd 'focus right';
is($x->input_focus, $sixth->id, 'sixth window focused');

cmd "workspace $s2_ws";
cmd 'focus up';
is($x->input_focus, $second->id, 'second window focused');

###################################################################
# Test that focus (left|down|right|up), when focusing across
# outputs, doesn't focus the next window in the given direction but
# the most focused window of the container in the given direction.
# In the following layout:
# [ WS1*[ ] WS2[ H[ A B* ] ] ]
# (where the asterisk denotes the focused container within its
# parent) moving right from WS1 should focus B which is focused
# inside WS2, not A which is the next window on the right of WS1.
# See issue #1160.
###################################################################

kill_all_windows;

sync_with_i3;
$x->root->warp_pointer(1025, 0);  # Second screen.
sync_with_i3;
$s1_ws = fresh_workspace;
$first = open_window;
$second = open_window;

sync_with_i3;
$x->root->warp_pointer(0, 0);  # First screen.
sync_with_i3;
$s0_ws = fresh_workspace;
open_window;
$third = open_window;

cmd 'focus right';
is($x->input_focus, $second->id, 'second window (rightmost) focused');
cmd 'focus left';
is($x->input_focus, $first->id, 'first window focused');
cmd 'focus left';
is($x->input_focus, $third->id, 'third window focused');


###################################################################
# Similar but with a tabbed layout.
###################################################################

cmd 'layout tabbed';
$fourth = open_window;
cmd 'focus left';
is($x->input_focus, $third->id, 'third window (tabbed) focused');
cmd "workspace $s1_ws";
cmd 'focus left';
is($x->input_focus, $third->id, 'third window (tabbed) focused');


###################################################################
# Similar but with a stacked layout on the bottom screen.
###################################################################

sync_with_i3;
$x->root->warp_pointer(0, 769);  # Third screen.
sync_with_i3;
$s2_ws = fresh_workspace;
cmd 'layout stacked';
$fifth = open_window;
$sixth = open_window;

cmd "workspace $s0_ws";
cmd 'focus down';
is($x->input_focus, $sixth->id, 'sixth window (stacked) focused');

###################################################################
# Similar but with a more complex layout.
###################################################################

sync_with_i3;
$x->root->warp_pointer(1025, 769);  # Fourth screen.
sync_with_i3;
$s3_ws = fresh_workspace;
open_window;
open_window;
cmd 'split v';
open_window;
open_window;
cmd 'split h';
my $nested = open_window;
open_window;
cmd 'focus left';
is($x->input_focus, $nested->id, 'nested window focused');

cmd "workspace $s1_ws";
cmd 'focus down';
is($x->input_focus, $nested->id, 'nested window focused from workspace above');

cmd "workspace $s2_ws";
cmd 'focus right';
is($x->input_focus, $nested->id, 'nested window focused from workspace on the left');

done_testing;