]> git.sur5r.net Git - i3/i3/commitdiff
Bugfix: only honor _NET_ACTIVE_WINDOW for visible windows (+test) (Thanks Tucos)
authorMichael Stapelberg <michael@stapelberg.de>
Sun, 12 Aug 2012 14:08:31 +0000 (16:08 +0200)
committerMichael Stapelberg <michael@stapelberg.de>
Sun, 12 Aug 2012 14:08:53 +0000 (16:08 +0200)
fixes #774

src/handlers.c
testcases/t/195-net-active-window.t [new file with mode: 0644]

index a69a62690fc40ba804abd0d4a63e342ee777dedf..31543626c3acd098583fad0f8902da5ed24ed018 100644 (file)
@@ -635,6 +635,15 @@ static void handle_client_message(xcb_client_message_event_t *event) {
             return;
         }
 
+        Con *ws = con_get_workspace(con);
+        if (!workspace_is_visible(ws)) {
+            DLOG("Workspace not visible, ignoring _NET_ACTIVE_WINDOW\n");
+            return;
+        }
+
+        if (ws != con_get_workspace(focused))
+            workspace_show(ws);
+
         con_focus(con);
         tree_render();
     } else if (event->type == A_I3_SYNC) {
diff --git a/testcases/t/195-net-active-window.t b/testcases/t/195-net-active-window.t
new file mode 100644 (file)
index 0000000..f392378
--- /dev/null
@@ -0,0 +1,54 @@
+#!perl
+# vim:ts=4:sw=4:expandtab
+# Verifies that the _NET_ACTIVE_WINDOW message only changes focus when the
+# window is on a visible workspace.
+# ticket #774, bug still present in commit 1e49f1b08a3035c1f238fcd6615e332216ab582e
+use i3test;
+
+sub send_net_active_window {
+    my ($id) = @_;
+
+    my $msg = pack "CCSLLLLLLL",
+        X11::XCB::CLIENT_MESSAGE, # response_type
+        32, # format
+        0, # sequence
+        $id, # destination window
+        $x->atom(name => '_NET_ACTIVE_WINDOW')->id,
+        0,
+        0,
+        0,
+        0,
+        0;
+
+    $x->send_event(0, $x->get_root_window(), X11::XCB::EVENT_MASK_SUBSTRUCTURE_REDIRECT, $msg);
+}
+
+my $ws1 = fresh_workspace;
+my $win1 = open_window;
+my $win2 = open_window;
+
+################################################################################
+# Ensure that the _NET_ACTIVE_WINDOW ClientMessage works when windows are visible
+################################################################################
+
+is($x->input_focus, $win2->id, 'window 2 has focus');
+
+send_net_active_window($win1->id);
+
+is($x->input_focus, $win1->id, 'window 1 has focus');
+
+################################################################################
+# Switch to a different workspace and ensure sending the _NET_ACTIVE_WINDOW
+# ClientMessage has no effect anymore.
+################################################################################
+
+my $ws2 = fresh_workspace;
+my $win3 = open_window;
+
+is($x->input_focus, $win3->id, 'window 3 has focus');
+
+send_net_active_window($win1->id);
+
+is($x->input_focus, $win3->id, 'window 3 still has focus');
+
+done_testing;