aboutsummaryrefslogtreecommitdiff
path: root/testcases/t/529-net-wm-desktop.t
blob: d9827326230b57bc726192df546d67af247e58c6 (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
#!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 for _NET_WM_DESKTOP.
# Ticket: #2153
use i3test i3_config => <<EOT;
# i3 config file (v4)
font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1

bar {
    status_command i3status
}
EOT
use X11::XCB qw(:all);

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

sub get_net_wm_desktop {
    sync_with_i3;

    my ($con) = @_;
    my $cookie = $x->get_property(
        0,
        $con->{id},
        $x->atom(name => '_NET_WM_DESKTOP')->id,
        $x->atom(name => 'CARDINAL')->id,
        0,
        1
    );

    my $reply = $x->get_property_reply($cookie->{sequence});
    return undef if $reply->{length} != 1;

    return unpack("L", $reply->{value});
}

sub send_net_wm_desktop {
    my ($con, $idx) = @_;
    my $msg = pack "CCSLLLLLL",
        X11::XCB::CLIENT_MESSAGE, 32, 0,
        $con->{id},
        $x->atom(name => '_NET_WM_DESKTOP')->id,
        $idx, 0, 0, 0, 0;

    $x->send_event(0, $x->get_root_window(), X11::XCB::EVENT_MASK_SUBSTRUCTURE_REDIRECT, $msg);
    sync_with_i3;
}

sub open_window_with_net_wm_desktop {
    my $idx = shift;
    my $window = open_window(
        before_map => sub {
            my ($window) = @_;
            $x->change_property(
                PROP_MODE_REPLACE,
                $window->id,
                $x->atom(name => '_NET_WM_DESKTOP')->id,
                $x->atom(name => 'CARDINAL')->id,
                32, 1,
                pack('L', $idx),
            );
        },
	dont_map => 1,
    );

    # We don’t wait for MapNotify and instead sync with i3 so that we don’t need
    # to encounter the full timeout of 4s when opening a window on a non-visible
    # workspace.
    $window->map;
    sync_with_i3;

    return $window;
}

###############################################################################
# Upon managing a window which does not set _NET_WM_DESKTOP, the property is
# set on the window.
###############################################################################

cmd 'workspace 1';
my $con = open_window;

is(get_net_wm_desktop($con), 0, '_NET_WM_DESKTOP is set upon managing a window');

kill_all_windows;

###############################################################################
# Upon managing a window which sets _NET_WM_DESKTOP, the window is moved to
# the specified desktop.
###############################################################################

cmd 'workspace 0';
open_window;
cmd 'workspace 1';
open_window;
cmd 'workspace 2';
open_window;

$con = open_window_with_net_wm_desktop(1);

is(get_net_wm_desktop($con), 1, '_NET_WM_DESKTOP still has the correct value');
is_num_children('1', 2, 'The window was moved to workspace 1');

kill_all_windows;

###############################################################################
# Upon managing a window which sets _NET_WM_DESKTOP to the appropriate value,
# the window is made sticky and floating.
###############################################################################

cmd 'workspace 0';
$con = open_window_with_net_wm_desktop(0xFFFFFFFF);

is(get_net_wm_desktop($con), 0xFFFFFFFF, '_NET_WM_DESKTOP still has the correct value');
is(@{get_ws('0')->{floating_nodes}}, 1, 'The window is floating');
ok(get_ws('0')->{floating_nodes}->[0]->{nodes}->[0]->{sticky}, 'The window is sticky');

kill_all_windows;

###############################################################################
# _NET_WM_DESKTOP is updated when the window is moved to another workspace
# on the same output.
###############################################################################

cmd 'workspace 0';
open_window;
cmd 'workspace 1';
open_window;
cmd 'workspace 0';
$con = open_window;

cmd 'move window to workspace 1';

is(get_net_wm_desktop($con), 1, '_NET_WM_DESKTOP is updated when moving the window');

kill_all_windows;

###############################################################################
# _NET_WM_DESKTOP is updated when the floating window is moved to another
# workspace on the same output.
###############################################################################

cmd 'workspace 0';
open_window;
cmd 'workspace 1';
open_window;
cmd 'workspace 0';
$con = open_window;
cmd 'floating enable';

cmd 'move window to workspace 1';

is(get_net_wm_desktop($con), 1, '_NET_WM_DESKTOP is updated when moving the window');

kill_all_windows;

###############################################################################
# _NET_WM_DESKTOP is removed when the window is withdrawn.
###############################################################################

$con = open_window;
is(get_net_wm_desktop($con), 0, '_NET_WM_DESKTOP is set (sanity check)');

$con->unmap;
wait_for_unmap($con);

is(get_net_wm_desktop($con), undef, '_NET_WM_DESKTOP is removed');

kill_all_windows;

###############################################################################
# A _NET_WM_DESKTOP client message sent to the root window moves a window
# to the correct workspace.
###############################################################################

cmd 'workspace 0';
open_window;
cmd 'workspace 1';
open_window;
cmd 'workspace 0';

$con = open_window;
is_num_children('0', 2, 'The window is on workspace 0');

send_net_wm_desktop($con, 1);

is_num_children('0', 1, 'The window is no longer on workspace 0');
is_num_children('1', 2, 'The window is now on workspace 1');
is(get_net_wm_desktop($con), 1, '_NET_WM_DESKTOP is updated');

kill_all_windows;

###############################################################################
# A _NET_WM_DESKTOP client message sent to the root window can make a window
# sticky.
###############################################################################

cmd 'workspace 0';
$con = open_window;

send_net_wm_desktop($con, 0xFFFFFFFF);

is(get_net_wm_desktop($con), 0xFFFFFFFF, '_NET_WM_DESKTOP is updated');
is(@{get_ws('0')->{floating_nodes}}, 1, 'The window is floating');
ok(get_ws('0')->{floating_nodes}->[0]->{nodes}->[0]->{sticky}, 'The window is sticky');

kill_all_windows;

###############################################################################
# _NET_WM_DESKTOP is updated when a new workspace with a lower number is
# opened and closed.
###############################################################################

cmd 'workspace 1';
$con = open_window;
is(get_net_wm_desktop($con), 0, '_NET_WM_DESKTOP is set sanity check)');

cmd 'workspace 0';
is(get_net_wm_desktop($con), 1, '_NET_WM_DESKTOP is updated');

kill_all_windows;

###############################################################################
# _NET_WM_DESKTOP is updated when a window is made sticky by command.
###############################################################################

cmd 'workspace 0';
$con = open_window;
cmd 'floating enable';
is(get_net_wm_desktop($con), 0, '_NET_WM_DESKTOP is set sanity check)');

cmd 'sticky enable';
is(get_net_wm_desktop($con), 0xFFFFFFFF, '_NET_WM_DESKTOP is updated');

kill_all_windows;

###############################################################################
# _NET_WM_DESKTOP is updated when a window is made sticky by client message.
###############################################################################

cmd 'workspace 0';
$con = open_window;
cmd 'floating enable';
is(get_net_wm_desktop($con), 0, '_NET_WM_DESKTOP is set sanity check)');

my $msg = pack "CCSLLLLLL",
    X11::XCB::CLIENT_MESSAGE, 32, 0,
    $con->{id},
    $x->atom(name => '_NET_WM_STATE')->id,
    1,
    $x->atom(name => '_NET_WM_STATE_STICKY')->id,
    0, 0, 0;

$x->send_event(0, $x->get_root_window(), X11::XCB::EVENT_MASK_SUBSTRUCTURE_REDIRECT, $msg);
sync_with_i3;

is(get_net_wm_desktop($con), 0xFFFFFFFF, '_NET_WM_DESKTOP is updated');

kill_all_windows;

###############################################################################
# _NET_WM_DESKTOP is updated when a window is moved to the scratchpad.
###############################################################################

cmd 'workspace 0';
$con = open_window;
cmd 'floating enable';
is(get_net_wm_desktop($con), 0, '_NET_WM_DESKTOP is set sanity check)');

cmd 'move scratchpad';
is(get_net_wm_desktop($con), 0xFFFFFFFF, '_NET_WM_DESKTOP is updated');

cmd 'scratchpad show';
is(get_net_wm_desktop($con), 0, '_NET_WM_DESKTOP is set sanity check)');

kill_all_windows;

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

done_testing;