From 0b6b3bb458e491adf0a5b1bcf31449a41ba3b842 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Thu, 13 Dec 2012 20:31:18 +0100 Subject: [PATCH] Correctly handle focus across restarts (FS#1055) X11 is a great protocol. When a window manager dies, it can make sure that client windows don't get destroyed via the save-set. However, revert-to-parent focus handling means that the focus now shifts to the parent which gets destroyed and afterwards the focus is "none", which is a really bad state. Fix this in two places: First, when shutting down, we switch to PointerRoot mode. This makes sure that the input focus follows the mouse pointer if no window manager is started. Also make sure that we set the input focus the way we want it to be after start up. This obviously cleans up any weird state which might exist before we manage the input focus. Signed-off-by: Uli Schlachter --- awesome.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/awesome.c b/awesome.c index e629ce1d2..9178d36ac 100644 --- a/awesome.c +++ b/awesome.c @@ -74,7 +74,15 @@ awesome_atexit(bool restart) /* Close Lua */ lua_close(globalconf.L); - xcb_flush(globalconf.connection); + /* X11 is a great protocol. There is a save-set so that reparenting WMs + * don't kill clients when they shut down. However, when a focused windows + * is saved, the focus will move to its parent with revert-to none. + * Immediately afterwards, this parent is destroyed and the focus is gone. + * Work around this by placing the focus where we like it to be. + */ + xcb_set_input_focus(globalconf.connection, XCB_INPUT_FOCUS_POINTER_ROOT, + XCB_NONE, XCB_CURRENT_TIME); + xcb_aux_sync(globalconf.connection); /* Disconnect *after* closing lua */ xcb_disconnect(globalconf.connection); @@ -369,6 +377,8 @@ main(int argc, char **argv) XSetEventQueueOwner(globalconf.display, XCBOwnsEventQueue); globalconf.default_screen = XDefaultScreen(globalconf.display); globalconf.connection = XGetXCBConnection(globalconf.display); + /* We have no clue where the input focus is right now */ + globalconf.focus.need_update = true; /* Double checking that connection is good and operatable with xcb */ if(xcb_connection_has_error(globalconf.connection))