2 # vim:ts=4:sw=4:expandtab
4 # Please read the following documents before working on tests:
5 # • http://build.i3wm.org/docs/testsuite.html
8 # • http://build.i3wm.org/docs/lib-i3test.html
9 # (alternatively: perldoc ./testcases/lib/i3test.pm)
11 # • http://build.i3wm.org/docs/ipc.html
14 # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
15 # (unless you are already familiar with Perl)
17 # Tests for _NET_WM_DESKTOP.
19 use i3test i3_autostart => 0;
20 use X11::XCB qw(:all);
22 ###############################################################################
24 sub get_net_wm_desktop {
28 my $cookie = $x->get_property(
31 $x->atom(name => '_NET_WM_DESKTOP')->id,
32 $x->atom(name => 'CARDINAL')->id,
37 my $reply = $x->get_property_reply($cookie->{sequence});
38 return undef if $reply->{length} != 1;
40 return unpack("L", $reply->{value});
43 sub send_net_wm_desktop {
45 my $msg = pack "CCSLLLLLL",
46 X11::XCB::CLIENT_MESSAGE, 32, 0,
48 $x->atom(name => '_NET_WM_DESKTOP')->id,
51 $x->send_event(0, $x->get_root_window(), X11::XCB::EVENT_MASK_SUBSTRUCTURE_REDIRECT, $msg);
55 sub open_window_with_net_wm_desktop {
57 my $window = open_window(
63 $x->atom(name => '_NET_WM_DESKTOP')->id,
64 $x->atom(name => 'CARDINAL')->id,
72 # We don’t wait for MapNotify and instead sync with i3 so that we don’t need
73 # to encounter the full timeout of 4s when opening a window on a non-visible
81 ###############################################################################
85 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
88 status_command i3status
92 my $pid = launch_with_config($config);
94 ###############################################################################
95 # Upon managing a window which does not set _NET_WM_DESKTOP, the property is
97 ###############################################################################
100 my $con = open_window;
102 is(get_net_wm_desktop($con), 0, '_NET_WM_DESKTOP is set upon managing a window');
106 ###############################################################################
107 # Upon managing a window which sets _NET_WM_DESKTOP, the window is moved to
108 # the specified desktop.
109 ###############################################################################
118 $con = open_window_with_net_wm_desktop(1);
120 is(get_net_wm_desktop($con), 1, '_NET_WM_DESKTOP still has the correct value');
121 is_num_children('1', 2, 'The window was moved to workspace 1');
125 ###############################################################################
126 # Upon managing a window which sets _NET_WM_DESKTOP to the appropriate value,
127 # the window is made sticky and floating.
128 ###############################################################################
131 $con = open_window_with_net_wm_desktop(0xFFFFFFFF);
133 is(get_net_wm_desktop($con), 0xFFFFFFFF, '_NET_WM_DESKTOP still has the correct value');
134 is(@{get_ws('0')->{floating_nodes}}, 1, 'The window is floating');
135 ok(get_ws('0')->{floating_nodes}->[0]->{nodes}->[0]->{sticky}, 'The window is sticky');
139 ###############################################################################
140 # _NET_WM_DESKTOP is updated when the window is moved to another workspace
141 # on the same output.
142 ###############################################################################
151 cmd 'move window to workspace 1';
153 is(get_net_wm_desktop($con), 1, '_NET_WM_DESKTOP is updated when moving the window');
157 ###############################################################################
158 # _NET_WM_DESKTOP is updated when the floating window is moved to another
159 # workspace on the same output.
160 ###############################################################################
168 cmd 'floating enable';
170 cmd 'move window to workspace 1';
172 is(get_net_wm_desktop($con), 1, '_NET_WM_DESKTOP is updated when moving the window');
176 ###############################################################################
177 # _NET_WM_DESKTOP is removed when the window is withdrawn.
178 ###############################################################################
181 is(get_net_wm_desktop($con), 0, '_NET_WM_DESKTOP is set (sanity check)');
184 wait_for_unmap($con);
186 is(get_net_wm_desktop($con), undef, '_NET_WM_DESKTOP is removed');
190 ###############################################################################
191 # A _NET_WM_DESKTOP client message sent to the root window moves a window
192 # to the correct workspace.
193 ###############################################################################
202 is_num_children('0', 2, 'The window is on workspace 0');
204 send_net_wm_desktop($con, 1);
206 is_num_children('0', 1, 'The window is no longer on workspace 0');
207 is_num_children('1', 2, 'The window is now on workspace 1');
208 is(get_net_wm_desktop($con), 1, '_NET_WM_DESKTOP is updated');
212 ###############################################################################
213 # A _NET_WM_DESKTOP client message sent to the root window can make a window
215 ###############################################################################
220 send_net_wm_desktop($con, 0xFFFFFFFF);
222 is(get_net_wm_desktop($con), 0xFFFFFFFF, '_NET_WM_DESKTOP is updated');
223 is(@{get_ws('0')->{floating_nodes}}, 1, 'The window is floating');
224 ok(get_ws('0')->{floating_nodes}->[0]->{nodes}->[0]->{sticky}, 'The window is sticky');
228 ###############################################################################
229 # _NET_WM_DESKTOP is updated when a new workspace with a lower number is
231 ###############################################################################
235 is(get_net_wm_desktop($con), 0, '_NET_WM_DESKTOP is set sanity check)');
238 is(get_net_wm_desktop($con), 1, '_NET_WM_DESKTOP is updated');
242 ###############################################################################
243 # _NET_WM_DESKTOP is updated when a window is made sticky by command.
244 ###############################################################################
248 cmd 'floating enable';
249 is(get_net_wm_desktop($con), 0, '_NET_WM_DESKTOP is set sanity check)');
252 is(get_net_wm_desktop($con), 0xFFFFFFFF, '_NET_WM_DESKTOP is updated');
256 ###############################################################################
257 # _NET_WM_DESKTOP is updated when a window is made sticky by client message.
258 ###############################################################################
262 cmd 'floating enable';
263 is(get_net_wm_desktop($con), 0, '_NET_WM_DESKTOP is set sanity check)');
265 my $msg = pack "CCSLLLLLL",
266 X11::XCB::CLIENT_MESSAGE, 32, 0,
268 $x->atom(name => '_NET_WM_STATE')->id,
270 $x->atom(name => '_NET_WM_STATE_STICKY')->id,
273 $x->send_event(0, $x->get_root_window(), X11::XCB::EVENT_MASK_SUBSTRUCTURE_REDIRECT, $msg);
276 is(get_net_wm_desktop($con), 0xFFFFFFFF, '_NET_WM_DESKTOP is updated');
280 ###############################################################################
281 # _NET_WM_DESKTOP is updated when a window is moved to the scratchpad.
282 ###############################################################################
286 cmd 'floating enable';
287 is(get_net_wm_desktop($con), 0, '_NET_WM_DESKTOP is set sanity check)');
289 cmd 'move scratchpad';
290 is(get_net_wm_desktop($con), 0xFFFFFFFF, '_NET_WM_DESKTOP is updated');
292 cmd 'scratchpad show';
293 is(get_net_wm_desktop($con), 0, '_NET_WM_DESKTOP is set sanity check)');
297 ###############################################################################
299 exit_gracefully($pid);