summaryrefslogtreecommitdiff
path: root/src/core/display.c
diff options
context:
space:
mode:
authorJasper St. Pierre <jstpierre@mecheye.net>2013-05-25 16:09:08 -0400
committerJasper St. Pierre <jstpierre@mecheye.net>2013-05-28 14:59:20 -0400
commit8747b97ba3024ce28789336f7e0221be1ecacb70 (patch)
tree84f9e44f9b5fcf22e995012631cd03a1e538f6f1 /src/core/display.c
parentd20078574e8d980ce0a35e4e6d2f5e13d3ad94c7 (diff)
downloadmutter-8747b97ba3024ce28789336f7e0221be1ecacb70.tar.gz
display: Ensure that we ignore our own focus events for focus predictions
When we set the input focus, we first set the predicted window, and then try to process focus events. But as XI_FocusOut on the existing window comes before XI_FocusIn on the new window, we'll see the focus out on the old window and think the focus is going to nothing, which makes mutter think the prediction failed. This didn't really matter as nothing paid attention to the focus window changing, but with gnome-shell's focus rework, we'll try and drop keyboard focus in events like these. Fix this by making sure that we ignore focus window changes of our own cause when updating the focus window field, by ignoring all focus events that have a serial the same as the focus request or lower. Note that if mutter doens't make any requests after the focus request, this could be racy, as another client could steal the focus, but mutter would ignore it as the serial was the same. Bump the serial by making a dummy ChangeProperty request to the root window in this case. https://bugzilla.gnome.org/show_bug.cgi?id=701017
Diffstat (limited to 'src/core/display.c')
-rw-r--r--src/core/display.c32
1 files changed, 29 insertions, 3 deletions
diff --git a/src/core/display.c b/src/core/display.c
index 60cb00c72..263c70fd1 100644
--- a/src/core/display.c
+++ b/src/core/display.c
@@ -1952,6 +1952,7 @@ request_xserver_input_focus_change (MetaDisplay *display,
guint32 timestamp)
{
MetaWindow *meta_window;
+ gulong serial;
if (timestamp_too_old (display, &timestamp))
return;
@@ -1959,14 +1960,39 @@ request_xserver_input_focus_change (MetaDisplay *display,
meta_window = meta_display_lookup_x_window (display, xwindow);
meta_error_trap_push (display);
- update_focus_window (display,
- meta_window,
- XNextRequest (display->xdisplay));
+
+ /* In order for mutter to know that the focus request succeeded, we track
+ * the serial of the "focus request" we made, but if we take the serial
+ * of the XSetInputFocus request, then there's no way to determine the
+ * difference between focus events as a result of the SetInputFocus and
+ * focus events that other clients send around the same time. Ensure that
+ * we know which is which by making two requests that the server will
+ * process at the same time.
+ */
+ meta_display_grab (display);
XSetInputFocus (display->xdisplay,
xwindow,
RevertToPointerRoot,
timestamp);
+
+ serial = XNextRequest (display->xdisplay);
+
+ {
+ unsigned long data[1] = { 0 };
+
+ XChangeProperty (display->xdisplay, display->timestamp_pinging_window,
+ display->atom__MUTTER_FOCUS_SET,
+ XA_CARDINAL,
+ 32, PropModeReplace, (guchar*) data, 1);
+ }
+
+ meta_display_ungrab (display);
+
+ update_focus_window (display,
+ meta_window,
+ serial);
+
meta_error_trap_pop (display);
display->last_focus_time = timestamp;