Blob Blame History Raw
From b21bd3f820e875aa67b8f8dcb7b648eaebb7d926 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Florian=20M=C3=BCllner?= <fmuellner@gnome.org>
Date: Thu, 9 Jul 2015 17:39:05 +0200
Subject: [PATCH] events: Don't use XIEvent serial numbers

XInput2 uses the raw sequence number for XIEvent serials, which only
matches the serial number in XEvents up to 16 bits[0]. So in order to
be able to make reliable comparisons with serials from other events or
calls to XNextRequest(), always use the field from the original XEvent
rather than the XIEvent serial.

[0] http://cgit.freedesktop.org/xorg/lib/libX11/tree/src/XlibInt.c#n265
---
 src/x11/events.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/src/x11/events.c b/src/x11/events.c
index bf2dd9b..fbfd2dd 100644
--- a/src/x11/events.c
+++ b/src/x11/events.c
@@ -691,7 +691,8 @@ meta_spew_event_print (MetaDisplay *display,
 static gboolean
 handle_window_focus_event (MetaDisplay  *display,
                            MetaWindow   *window,
-                           XIEnterEvent *event)
+                           XIEnterEvent *event,
+                           unsigned long serial)
 {
   MetaWindow *focus_window;
 #ifdef WITH_VERBOSE_MODE
@@ -726,7 +727,7 @@ handle_window_focus_event (MetaDisplay  *display,
               event->event, window_type,
               meta_event_mode_to_string (event->mode),
               meta_event_detail_to_string (event->mode),
-              event->serial);
+              serial);
 #endif
 
   /* FIXME our pointer tracking is broken; see how
@@ -770,7 +771,7 @@ handle_window_focus_event (MetaDisplay  *display,
   if (event->evtype == XI_FocusIn)
     {
       display->server_focus_window = event->event;
-      display->server_focus_serial = event->serial;
+      display->server_focus_serial = serial;
       focus_window = window;
     }
   else if (event->evtype == XI_FocusOut)
@@ -784,7 +785,7 @@ handle_window_focus_event (MetaDisplay  *display,
         }
 
       display->server_focus_window = None;
-      display->server_focus_serial = event->serial;
+      display->server_focus_serial = serial;
       focus_window = NULL;
     }
   else
@@ -834,8 +835,9 @@ crossing_serial_is_ignored (MetaDisplay  *display,
 }
 
 static gboolean
-handle_input_xevent (MetaDisplay *display,
-                     XIEvent     *input_event)
+handle_input_xevent (MetaDisplay  *display,
+                     XIEvent      *input_event,
+                     unsigned long serial)
 {
   XIEnterEvent *enter_event = (XIEnterEvent *) input_event;
   Window modified;
@@ -872,7 +874,7 @@ handle_input_xevent (MetaDisplay *display,
       /* Check if we've entered a window; do this even if window->has_focus to
        * avoid races.
        */
-      if (window && !crossing_serial_is_ignored (display, input_event->serial) &&
+      if (window && !crossing_serial_is_ignored (display, serial) &&
           enter_event->mode != XINotifyGrab &&
           enter_event->mode != XINotifyUngrab &&
           enter_event->detail != XINotifyInferior &&
@@ -897,7 +899,7 @@ handle_input_xevent (MetaDisplay *display,
       break;
     case XI_FocusIn:
     case XI_FocusOut:
-      if (handle_window_focus_event (display, window, enter_event) &&
+      if (handle_window_focus_event (display, window, enter_event, serial) &&
           enter_event->event == enter_event->root)
         {
           if (enter_event->evtype == XI_FocusIn &&
@@ -1741,7 +1743,7 @@ meta_display_handle_xevent (MetaDisplay *display,
     }
 #endif /* HAVE_XI23 */
 
-  if (handle_input_xevent (display, input_event))
+  if (handle_input_xevent (display, input_event, event->xany.serial))
     {
       bypass_gtk = bypass_compositor = TRUE;
       goto out;
-- 
2.4.3