From 658bf5adff869010f9c0422f79d84a7080ee400e Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Mon, 3 Oct 2011 21:54:36 +0100 Subject: [PATCH] Bugfix: Warp pointer to the correct window when using the 'focus' command Comment in the code makes the fix clear, I think. Steps to reproduce the issue: 1) On the right monitor, open two terminals (h-split workspace) 2) 'i3 mark foo' on the right terminal 3) Focus the left terminal 4) Switch to the left monitor 5) i3 '[con_mark="foo"] focus' 6) the left window will contain the pointer (and is focused for a short period of time, or even permanently due to race conditions) --- src/cmdparse.y | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/cmdparse.y b/src/cmdparse.y index da962cf4..ecc4bc02 100644 --- a/src/cmdparse.y +++ b/src/cmdparse.y @@ -440,6 +440,24 @@ focus: int count = 0; TAILQ_FOREACH(current, &owindows, owindows) { Con *ws = con_get_workspace(current->con); + + /* If the container is not on the current workspace, + * workspace_show() will switch to a different workspace and (if + * enabled) trigger a mouse pointer warp to the currently focused + * container (!) on the target workspace. + * + * Therefore, before calling workspace_show(), we make sure that + * 'current' will be focused on the workspace. However, we cannot + * just con_focus(current) because then the pointer will not be + * warped at all (the code thinks we are already there). + * + * So we focus 'current' to make it the currently focused window of + * the target workspace, then revert focus. */ + Con *currently_focused = focused; + con_focus(current->con); + con_focus(currently_focused); + + /* Now switch to the workspace, then focus */ workspace_show(ws); LOG("focusing %p / %s\n", current->con, current->con->name); con_focus(current->con); -- 2.39.5