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 # Verifies the _NET_CURRENT_DESKTOP property correctly tracks the currently
18 # active workspace. Specifically checks that the property is 0 on startup with
19 # an empty config, tracks changes when switching workspaces and when
20 # workspaces are created and deleted.
22 # The property not being set on startup was last present in commit
23 # 6578976b6159437c16187cf8d1ea38aa9fec9fc8.
25 use i3test i3_autostart => 0;
26 use X11::XCB qw(PROP_MODE_REPLACE);
30 font font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
33 my $root = $x->get_root_window;
34 # Manually intern _NET_CURRENT_DESKTOP as $x->atom will not create atoms if
35 # they are not yet interned.
36 my $atom_cookie = $x->intern_atom(0, length("_NET_CURRENT_DESKTOP"), "_NET_CURRENT_DESKTOP");
37 my $_NET_CURRENT_DESKTOP = $x->intern_atom_reply($atom_cookie->{sequence})->{atom};
38 my $CARDINAL = $x->atom(name => 'CARDINAL')->id;
40 $x->delete_property($root, $_NET_CURRENT_DESKTOP);
44 # Returns the _NET_CURRENT_DESKTOP property from the root window. This is
45 # the 0 based index of the current desktop.
46 sub current_desktop_index {
49 my $cookie = $x->get_property(0, $root, $_NET_CURRENT_DESKTOP,
51 my $reply = $x->get_property_reply($cookie->{sequence});
53 return undef if $reply->{value_len} != 1;
54 return undef if $reply->{format} != 32;
55 return undef if $reply->{type} != $CARDINAL;
57 return unpack 'L', $reply->{value};
60 my $pid = launch_with_config($config);
62 is(current_desktop_index, 0, "Starting on desktop 0");
64 is(current_desktop_index, 0, "Change from empty to empty");
67 is(current_desktop_index, 0, "Open on 1 and view 0");
70 is(current_desktop_index, 1, "Open on 0 and view 1");
72 is(current_desktop_index, 2, "Open and view empty");
74 #########################################################
75 # Test the _NET_CURRENT_DESKTOP client request
76 # This request is sent by pagers and bars to switch the current desktop (which
77 # is like an ersatz workspace) to the given index
78 #########################################################
80 sub send_current_desktop_request {
83 my $msg = pack "CCSLLLLLL",
84 X11::XCB::CLIENT_MESSAGE, # response_type
88 $_NET_CURRENT_DESKTOP,
89 $idx, # data32[0] (the desktop index)
90 0, # data32[1] (can be a timestamp)
95 $x->send_event(0, $x->get_root_window(), X11::XCB::EVENT_MASK_SUBSTRUCTURE_REDIRECT, $msg);
98 send_current_desktop_request(1);
99 is(current_desktop_index, 1, 'current desktop request switched to desktop 1');
100 # note that _NET_CURRENT_DESKTOP is an index and that in this case, workspace 1
101 # is at index 1 as a convenience for the test
102 is(focused_ws, '1', 'current desktop request switched to workspace 1');
104 send_current_desktop_request(0);
105 is(current_desktop_index, 0, 'current desktop request switched to desktop 0');
106 is(focused_ws, '0', 'current desktop request switched to workspace 0');
108 exit_gracefully($pid);