aboutsummaryrefslogtreecommitdiff
path: root/testcases/t/316-drag-container.t
blob: 7e2b849450bd66db6b6c54858a5ff5e0038ff830 (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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
#!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)
#
# • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
#   (unless you are already familiar with Perl)
#
# Test dragging containers.

my ($width, $height) = (1000, 500);

my $config = <<"EOT";
# i3 config file (v4)
font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1

focus_follows_mouse no
floating_modifier Mod1

# 2 side by side outputs
fake-outputs ${width}x${height}+0+0P,${width}x${height}+${width}+0

bar {
    output primary
}
EOT
use i3test i3_autostart => 0;
use i3test::XTEST;
my $pid = launch_with_config($config);

sub start_drag {
    my ($pos_x, $pos_y) = @_;
    die "Drag outside of bounds!" unless $pos_x < $width * 2 && $pos_y < $height;

    $x->root->warp_pointer($pos_x, $pos_y);
    sync_with_i3;

    xtest_key_press(64);        # Alt_L
    xtest_button_press(1, $pos_x, $pos_y);
    xtest_sync_with_i3;
}

sub end_drag {
    my ($pos_x, $pos_y) = @_;
    die "Drag outside of bounds!" unless $pos_x < $width * 2 && $pos_y < $height;

    $x->root->warp_pointer($pos_x, $pos_y);
    sync_with_i3;

    xtest_button_release(1, $pos_x, $pos_y);
    xtest_key_release(64);      # Alt_L
    xtest_sync_with_i3;
}

my ($ws1, $ws2);
my ($A, $B, $tmp);
my ($A_id, $B_id);

sub move_subtest {
    my ($cb, $win) = @_;

    my @events = events_for($cb, 'window');
    my @move = grep { $_->{change} eq 'move' } @events;

    is(scalar @move, 1, 'Received 1 window::move event');
    is($move[0]->{container}->{window}, $A->{id}, "window id matches");
}

###############################################################################
# Drag floating container onto an empty workspace.
###############################################################################

$ws2 = fresh_workspace(output => 1);
$ws1 = fresh_workspace(output => 0);
$A = open_floating_window(rect => [ 30, 30, 50, 50 ]);

start_drag(40, 40);
end_drag(1050, 50);

is($x->input_focus, $A->id, 'Floating window moved to the right workspace');
is($ws2, focused_ws, 'Empty workspace focused after floating window dragged to it');

###############################################################################
# Drag tiling container onto an empty workspace.
###############################################################################

subtest "Draging tiling container onto an empty workspace produces move event", \&move_subtest,
sub {

$ws2 = fresh_workspace(output => 1);
$ws1 = fresh_workspace(output => 0);
$A = open_window;

start_drag(50, 50);
end_drag(1050, 50);

is($x->input_focus, $A->id, 'Tiling window moved to the right workspace');
is($ws2, focused_ws, 'Empty workspace focused after tiling window dragged to it');

};

###############################################################################
# Drag tiling container onto a container that closes before the drag is
# complete.
###############################################################################

$ws1 = fresh_workspace(output => 0);
$A = open_window;
open_window;

start_drag(600, 300);  # Start dragging the second window.

# Try to place it on the first window.
$x->root->warp_pointer(50, 50);
sync_with_i3;

cmd '[id=' . $A->id . '] kill';
sync_with_i3;
end_drag(50, 50);

is(@{get_ws_content($ws1)}, 1, 'One container left in ws1');

###############################################################################
# Drag tiling container onto a tiling container on an other workspace.
###############################################################################

subtest "Draging tiling container onto a tiling container on an other workspace produces move event", \&move_subtest,
sub {

$ws2 = fresh_workspace(output => 1);
open_window;
$B_id = get_focused($ws2);
$ws1 = fresh_workspace(output => 0);
$A = open_window;
$A_id = get_focused($ws1);

start_drag(50, 50);
end_drag(1500, 250);  # Center of right output, inner region.

is($ws2, focused_ws, 'Workspace focused after tiling window dragged to it');
$ws2 = get_ws($ws2);
is($ws2->{focus}[0], $A_id, 'A focused first, dragged container kept focus');
is($ws2->{focus}[1], $B_id, 'B focused second');

};

###############################################################################
# Drag tiling container onto a floating container on an other workspace.
###############################################################################

subtest "Draging tiling container onto a floating container on an other workspace produces move event", \&move_subtest,
sub {

$ws2 = fresh_workspace(output => 1);
open_floating_window;
$B_id = get_focused($ws2);
$ws1 = fresh_workspace(output => 0);
$A = open_window;
$A_id = get_focused($ws1);

start_drag(50, 50);
end_drag(1500, 250);

is($ws2, focused_ws, 'Workspace with one floating container focused after tiling window dragged to it');
$ws2 = get_ws($ws2);
is($ws2->{focus}[0], $A_id, 'A focused first, dragged container kept focus');
is($ws2->{floating_nodes}[0]->{nodes}[0]->{id}, $B_id, 'B exists & floating');

};

###############################################################################
# Drag tiling container onto a bar.
###############################################################################

subtest "Draging tiling container onto a bar produces move event", \&move_subtest,
sub {

$ws1 = fresh_workspace(output => 0);
open_window;
$B_id = get_focused($ws1);
$ws2 = fresh_workspace(output => 1);
$A = open_window;
$A_id = get_focused($ws2);

start_drag(1500, 250);
end_drag(1, 498);  # Bar on bottom of left output.

is($ws1, focused_ws, 'Workspace focused after tiling window dragged to its bar');
$ws1 = get_ws($ws1);
is($ws1->{focus}[0], $A_id, 'B focused first, dragged container kept focus');
is($ws1->{focus}[1], $B_id, 'A focused second');

};

###############################################################################
# Drag an unfocused tiling container onto it's self.
###############################################################################

$ws1 = fresh_workspace(output => 0);
open_window;
$A_id = get_focused($ws1);
open_window;
$B_id = get_focused($ws1);

start_drag(50, 50);
end_drag(450, 450);

$ws1 = get_ws($ws1);
is($ws1->{focus}[0], $B_id, 'B focused first, kept focus');
is($ws1->{focus}[1], $A_id, 'A focused second, unfocused dragged container didn\'t gain focus');

###############################################################################
# Drag an unfocused tiling container onto an occupied workspace.
###############################################################################

subtest "Draging unfocused tiling container onto an occupied workspace produces move event", \&move_subtest,
sub {

$ws1 = fresh_workspace(output => 0);
$A = open_window;
$A_id = get_focused($ws1);
$ws2 = fresh_workspace(output => 1);
open_window;
$B_id = get_focused($ws2);

start_drag(50, 50);
end_drag(1500, 250);  # Center of right output, inner region.

is($ws2, focused_ws, 'Workspace remained focused after dragging unfocused container');
$ws2 = get_ws($ws2);
is($ws2->{focus}[0], $B_id, 'B focused first, kept focus');
is($ws2->{focus}[1], $A_id, 'A focused second, unfocused container didn\'t steal focus');

};

###############################################################################
# Drag fullscreen container onto window in same workspace.
###############################################################################

$ws1 = fresh_workspace(output => 0);
open_window;
$A = open_window;
cmd 'fullscreen enable';

start_drag(900, 100);  # Second window
end_drag(50, 50);  # To first window

is($ws1, focused_ws, 'Workspace remained focused after dragging fullscreen container');
is_num_fullscreen($ws1, 1, 'Container still fullscreened');
is($x->input_focus, $A->id, 'Fullscreen container still focused');

###############################################################################
# Drag unfocused fullscreen container onto window in other workspace.
###############################################################################

subtest "Draging unfocused fullscreen container onto window in other workspace produces move event", \&move_subtest,
sub {

$ws1 = fresh_workspace(output => 0);
$A = open_window;
cmd 'fullscreen enable';
$ws2 = fresh_workspace(output => 1);
open_window;
open_window;

start_drag(900, 100);
end_drag(1000 + 500 * 0.15 + 10, 200);  # left of leftmost window

is($ws2, focused_ws, 'Workspace still focused after dragging fullscreen container to it');
is_num_fullscreen($ws1, 0, 'No fullscreen container in first workspace');
is_num_fullscreen($ws2, 1, 'Moved container still fullscreened');
is($x->input_focus, $A->id, 'Fullscreen container now focused');
$ws2 = get_ws($ws2);
is($ws2->{nodes}->[0]->{window}, $A->id, 'Fullscreen container now leftmost window in second workspace');

};

###############################################################################
# Drag unfocused fullscreen container onto left outter region of window in
# other workspace. The container shouldn't end up in $ws2 because it was
# dragged onto the outter region of the leftmost window. We must also check
# that the focus remains on the other window.
###############################################################################

subtest "Draging unfocused fullscreen container onto left outter region of window in other workspace produces move event", \&move_subtest,
sub {

$ws1 = fresh_workspace(output => 0);
open_window for (1..3);
$A = open_window;
$tmp = get_focused($ws1);
cmd 'fullscreen enable';
$ws2 = fresh_workspace(output => 1);
$B = open_window;

start_drag(990, 100);  # rightmost of $ws1
end_drag(1004, 100);  # outter region of window of $ws2

is($ws2, focused_ws, 'Workspace still focused after dragging fullscreen container to it');
is_num_fullscreen($ws1, 1, 'Fullscreen container still in first workspace');
is_num_fullscreen($ws2, 0, 'No fullscreen container in second workspace');
is($x->input_focus, $B->id, 'Window of second workspace still has focus');
is(get_focused($ws1), $tmp, 'Fullscreen container still focused in first workspace');
$ws1 = get_ws($ws1);
is($ws1->{nodes}->[3]->{window}, $A->id, 'Fullscreen container still rightmost window in first workspace');

};

exit_gracefully($pid);

###############################################################################

done_testing;