i3 - improved tiling WM


bugfix: don't set input focus if not accepted

Patch status: merged

Patch by Tony Crisci

Long description:

http://tronche.com/gui/x/icccm/sec-4.html#s-4.1.7

> Clients using the Globally Active model can only use a SetInputFocus request
> to acquire the input focus when they do not already have it on receipt of one
> of the following events:
> * ButtonPress
> * ButtonRelease
> * Passive-grabbed KeyPress
> * Passive-grabbed KeyRelease

Since managing a window happens on a MapNotify (which is absent from this
list), the window cannot accept input focus, so we should not try to focus
the window at all.

Fixes an issue with xfce4-notifyd which (correctly) declines focus when
we send WM_TAKE_FOCUS, which puts i3 in a state where i3 focus and X
focus are different when a notification appears.

To apply this patch, use:
curl http://cr.i3wm.org/patch/584/raw.patch | git am

b/src/manage.c

31
@@ -505,7 +505,7 @@ void manage_window(xcb_window_t window, xcb_get_window_attributes_cookie_t cooki
32
 
33
     /* Defer setting focus after the 'new' event has been sent to ensure the
34
      * proper window event sequence. */
35
-    if (set_focus) {
36
+    if (set_focus && !nc->window->doesnt_accept_focus) {
37
         DLOG("Now setting focus.\n");
38
         con_focus(nc);
39
     }

b/testcases/t/158-wm_take_focus.t

44
@@ -59,6 +59,18 @@ subtest 'Window without WM_TAKE_FOCUS', sub {
45
     done_testing;
46
 };
47
 
48
+# http://tronche.com/gui/x/icccm/sec-4.html#s-4.1.7
49
+# > Clients using the Globally Active model can only use a SetInputFocus request
50
+# > to acquire the input focus when they do not already have it on receipt of one
51
+# > of the following events:
52
+# > * ButtonPress
53
+# > * ButtonRelease
54
+# > * Passive-grabbed KeyPress
55
+# > * Passive-grabbed KeyRelease  
56
+#
57
+# Since managing a window happens on a MapNotify (which is absent from this
58
+# list), the window cannot accept input focus, so we should not try to focus
59
+# the window at all (right?)
60
 subtest 'Window with WM_TAKE_FOCUS and without InputHint', sub {
61
     fresh_workspace;
62
 
63
@@ -74,7 +86,7 @@ subtest 'Window with WM_TAKE_FOCUS and without InputHint', sub {
64
 
65
     $window->map;
66
 
67
-    ok(recv_take_focus($window), 'got ClientMessage with WM_TAKE_FOCUS atom');
68
+    ok(!recv_take_focus($window), 'did not receive ClientMessage');
69
 
70
     done_testing;
71
 };