Welcome to awesome bug tracking system.

FS#800 - Setting and reading client.focus can result in different clients

Attached to Project: awesome
Opened by Uli Schlachter (psychon) - Tuesday, 17 August 2010, 15:25 GMT
Last edited by Uli Schlachter (psychon) - Saturday, 07 April 2012, 08:44 GMT
Task Type Bug Report
Category Core
Status Closed
Assigned To No-one
Operating System All
Severity High
Priority Urgent
Reported Version git/master
Due in Version 4.0
Due Date Undecided
Percent Complete 100%
Votes 0
Private No


This bug affects both the 3.4 and master branch (thanks to me cherry-picking...).
The commit in question is this one:

commit 6ed3b618449be3804daf3b60163a7c202558c52e
Author: Uli Schlachter <>
Date: Sun Aug 15 13:17:07 2010 +0200

Don't call "focus" hook in client_focus()

Later on that call will be done through a FocusIn event.

Signed-off-by: Uli Schlachter <>

diff --git a/client.c b/client.c
index 494f261..8042c3a 100644
--- a/client.c
+++ b/client.c
@@ -446,9 +446,6 @@ client_focus(client_t *c)
/* X11 doesn't let you focus a window that isn't viewable */

- if (!c->nofocus)
- client_focus_update(c);
client_set_focus(c, !c->nofocus);

Now let's take a look at the default config:

awful.key({ modkey, }, "j",
function ()
awful.client.focus.byidx( 1)
if client.focus then client.focus:raise() end

This first focuses a new client and then raises that client, if possible. The problem is that the above patch causes client.focus to only be updated after an event from the X server. This means that client.focus will still return the previously focused client and so the wrong client is raised.

Of course, reverting this commit fixes that, but this revealed sth that was already broken before. Clients with the WM_TAKE_FOCUS protocol that don't focus themselves or that have the noinput hint set will cause client.focus to read out the wrong client.
This task depends upon

Closed by  Uli Schlachter (psychon)
Saturday, 07 April 2012, 08:44 GMT
Reason for closing:  Fixed
Additional comments about closing:  Wow. This was apprently and accidentally fixed quite a while ago in a completely unrelated commit:

commit 3dbf89c990d4796c6a8170bb3eb10e74890b3233
Author: Uli Schlachter <>
Date: Sun Oct 10 14:50:35 2010 +0200

Lazyle set the input focus ( FS#804 )

Instead of immediately setting the X11 input focus when client.focus is assigned
something, we now just remember that we'll have to do something later. The focus
is then set in the next prepare call by libev (= after the current main loop run
is done).

Signed-off-by: Uli Schlachter <>
Comment by Uli Schlachter (psychon) - Tuesday, 17 August 2010, 19:35 GMT
As a work-around that restores the previous behavior:

commit 85c97f45fd4fca347317a8892872401630151a2a
Author: Uli Schlachter <>
Date: Tue Aug 17 21:33:07 2010 +0200

Revert "Don't call "focus" hook in client_focus()"

This reverts commit 27f9c0177a9d37e5b19732f7e9ff67860ab4bd48.

This commit broke code like the following because reading client.focus would
still return the previously focused client:

if client.focus then client.focus:raise() end