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 <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2012-12-13 20:31:18 +01:00
parent 6db7bdfcb9
commit 0b6b3bb458
1 changed files with 11 additions and 1 deletions

View File

@ -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))