From da9922b40da5bc581815a4357340f3f128e8c5cb Mon Sep 17 00:00:00 2001
From: Alexandre Julliard <julliard@winehq.org>
Date: Wed, 27 Apr 2011 16:00:02 +0200
Subject: [PATCH] winex11: Ignore MotionNotify events if we have pending
 RawMotion events.

---
 dlls/winex11.drv/event.c  | 26 +++++++++++++++++++++++++-
 dlls/winex11.drv/mouse.c  |  1 -
 dlls/winex11.drv/x11drv.h |  1 +
 3 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/dlls/winex11.drv/event.c b/dlls/winex11.drv/event.c
index 0233a61e210..30d8553ea8c 100644
--- a/dlls/winex11.drv/event.c
+++ b/dlls/winex11.drv/event.c
@@ -32,6 +32,9 @@
 #include <X11/Xlib.h>
 #include <X11/Xresource.h>
 #include <X11/Xutil.h>
+#ifdef HAVE_X11_EXTENSIONS_XINPUT2_H
+#include <X11/extensions/XInput2.h>
+#endif
 
 #include <assert.h>
 #include <stdarg.h>
@@ -154,6 +157,8 @@ static const char * event_names[MAX_EVENT_HANDLERS] =
     "SelectionNotify", "ColormapNotify", "ClientMessage", "MappingNotify", "GenericEvent"
 };
 
+int xinput2_opcode = 0;
+
 /* return the name of an X event */
 static const char *dbgstr_event( int type )
 {
@@ -236,7 +241,8 @@ enum event_merge_action
 {
     MERGE_DISCARD,  /* discard the old event */
     MERGE_HANDLE,   /* handle the old event */
-    MERGE_KEEP      /* keep the old event for future merging */
+    MERGE_KEEP,     /* keep the old event for future merging */
+    MERGE_IGNORE    /* ignore the new event, keep the old one */
 };
 
 /***********************************************************************
@@ -270,6 +276,22 @@ static enum event_merge_action merge_events( XEvent *prev, XEvent *next )
             return MERGE_DISCARD;
         }
         break;
+#ifdef HAVE_X11_EXTENSIONS_XINPUT2_H
+    case GenericEvent:
+        if (prev->xcookie.extension != xinput2_opcode) break;
+        if (prev->xcookie.evtype != XI_RawMotion) break;
+        switch (next->type)
+        {
+        case MotionNotify:
+            if (next->xany.window == x11drv_thread_data()->clip_window)
+            {
+                TRACE( "ignoring MotionNotify for clip window\n" );
+                return MERGE_IGNORE;
+            }
+            break;
+        }
+        break;
+#endif
     }
     return MERGE_HANDLE;
 }
@@ -363,6 +385,8 @@ static int process_events( Display *display, Bool (*filter)(Display*, XEvent*,XP
             break;
         case MERGE_KEEP:  /* handle new, keep prev for future merging */
             call_event_handler( display, &event );
+            /* fall through */
+        case MERGE_IGNORE: /* ignore new, keep prev for future merging */
             free_event_data( &event );
             break;
         }
diff --git a/dlls/winex11.drv/mouse.c b/dlls/winex11.drv/mouse.c
index c4e0b59e2ba..7f45a2a87a4 100644
--- a/dlls/winex11.drv/mouse.c
+++ b/dlls/winex11.drv/mouse.c
@@ -130,7 +130,6 @@ static Cursor create_cursor( HANDLE handle );
 
 #ifdef HAVE_X11_EXTENSIONS_XINPUT2_H
 static BOOL xinput2_available;
-static int xinput2_opcode;
 static int xinput2_core_pointer;
 #define MAKE_FUNCPTR(f) static typeof(f) * p##f
 MAKE_FUNCPTR(XIFreeDeviceInfo);
diff --git a/dlls/winex11.drv/x11drv.h b/dlls/winex11.drv/x11drv.h
index cfe2509dd76..7113a02cb11 100644
--- a/dlls/winex11.drv/x11drv.h
+++ b/dlls/winex11.drv/x11drv.h
@@ -733,6 +733,7 @@ extern void X11DRV_SelectionClear( HWND hWnd, XEvent *event );
 extern void X11DRV_MappingNotify( HWND hWnd, XEvent *event );
 extern void X11DRV_GenericEvent( HWND hwnd, XEvent *event );
 
+extern int xinput2_opcode;
 extern Bool (*pXGetEventData)( Display *display, XEvent /*XGenericEventCookie*/ *event );
 extern void (*pXFreeEventData)( Display *display, XEvent /*XGenericEventCookie*/ *event );
 
-- 
GitLab