From 0e27ff3cd04d45cceff625d19bd028d360b1ed04 Mon Sep 17 00:00:00 2001 From: Steve Jones Date: Sat, 1 Feb 2014 16:09:51 +0000 Subject: [PATCH] Set EWMH desktop properties on startup. Calls ewmh_update_current_desktop on startup to set the _NET_CURRENT_DESKTOP property. Without this change the property only gets set after the workspaces have been manipulated. Also exclude hidden workspaces (i.e. those starting with "__" from the workspace index. Adds tests for startup and workspace switching. --- src/ewmh.c | 3 ++ src/main.c | 3 ++ testcases/t/217-NET_CURRENT_DESKTOP.t | 75 +++++++++++++++++++++++++++ 3 files changed, 81 insertions(+) create mode 100644 testcases/t/217-NET_CURRENT_DESKTOP.t diff --git a/src/ewmh.c b/src/ewmh.c index 0298de3d..331df5dd 100644 --- a/src/ewmh.c +++ b/src/ewmh.c @@ -27,6 +27,9 @@ void ewmh_update_current_desktop(void) { TAILQ_FOREACH(output, &(croot->nodes_head), nodes) { Con *ws; TAILQ_FOREACH(ws, &(output_get_content(output)->nodes_head), nodes) { + if (STARTS_WITH(ws->name, "__")) + continue; + if (ws == focused_ws) { xcb_change_property(conn, XCB_PROP_MODE_REPLACE, root, A__NET_CURRENT_DESKTOP, XCB_ATOM_CARDINAL, 32, 1, &idx); diff --git a/src/main.c b/src/main.c index ec73955d..5ff9afe0 100644 --- a/src/main.c +++ b/src/main.c @@ -761,6 +761,9 @@ int main(int argc, char *argv[]) { x_set_i3_atoms(); ewmh_update_workarea(); + /* Set the _NET_CURRENT_DESKTOP property. */ + ewmh_update_current_desktop(); + struct ev_io *xcb_watcher = scalloc(sizeof(struct ev_io)); struct ev_io *xkb = scalloc(sizeof(struct ev_io)); xcb_check = scalloc(sizeof(struct ev_check)); diff --git a/testcases/t/217-NET_CURRENT_DESKTOP.t b/testcases/t/217-NET_CURRENT_DESKTOP.t new file mode 100644 index 00000000..9ea4bd17 --- /dev/null +++ b/testcases/t/217-NET_CURRENT_DESKTOP.t @@ -0,0 +1,75 @@ +#!perl +# vim:ts=4:sw=4:expandtab +# +# Please read the following documents before working on tests: +# • http://build.i3wm.org/docs/testsuite.html +# (or docs/testsuite) +# +# • http://build.i3wm.org/docs/lib-i3test.html +# (alternatively: perldoc ./testcases/lib/i3test.pm) +# +# • http://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) +# +# Verifies the _NET_CURRENT_DESKTOP property correctly tracks the currently +# active workspace. Specifically checks that the property is 0 on startup with +# an empty config, tracks changes when switching workspaces and when +# workspaces are created and deleted. +# +# The property not being set on startup was last present in commit +# 6578976b6159437c16187cf8d1ea38aa9fec9fc8. + +use i3test i3_autostart => 0; +use X11::XCB qw(PROP_MODE_REPLACE); + +my $config = <get_root_window; +# Manually intern _NET_CURRENT_DESKTOP as $x->atom will not create atoms if +# they are not yet interned. +my $atom_cookie = $x->intern_atom(0, length("_NET_CURRENT_DESKTOP"), "_NET_CURRENT_DESKTOP"); +my $_NET_CURRENT_DESKTOP = $x->intern_atom_reply($atom_cookie->{sequence})->{atom}; +my $CARDINAL = $x->atom(name => 'CARDINAL')->id; + +$x->delete_property($root, $_NET_CURRENT_DESKTOP); + +$x->flush(); + +sub current_desktop_index { + # Returns the _NET_CURRENT_DESKTOP property from the root window. This is + # the 0 based index of the current desktop. + + my $cookie = $x->get_property(0, $root, $_NET_CURRENT_DESKTOP, + $CARDINAL, 0, 1); + my $reply = $x->get_property_reply($cookie->{sequence}); + + return undef if $reply->{value_len} != 1; + return undef if $reply->{format} != 32; + return undef if $reply->{type} != $CARDINAL; + + return unpack 'L', $reply->{value}; +} + +my $pid = launch_with_config($config); + +is(current_desktop_index, 0, "Starting on desktop 0"); +cmd 'workspace 1'; +is(current_desktop_index, 0, "Change from empty to empty"); +open_window; +cmd 'workspace 0'; +is(current_desktop_index, 0, "Open on 1 and view 0"); +open_window; +cmd 'workspace 1'; +is(current_desktop_index, 1, "Open on 0 and view 1"); +cmd 'workspace 2'; +is(current_desktop_index, 2, "Open and view empty"); + +exit_gracefully($pid); + +done_testing; -- 2.39.2