x11drv: Move cached cursor position from under x11's lock and into it's own.

Vitaliy Margolen wine-patch at kievinfo.com
Sun Aug 6 21:27:40 CDT 2006


ChangeLog:
x11drv: Move cached cursor position from under x11's lock and into it's own.

This makes mouse less dependent on X's delays. Some games do benefit from this.
Some games are not affected at all. But generally it's an improvement.

 dlls/winex11.drv/mouse.c |   50 +++++++++++++++++++++++++++++++---------------
 1 files changed, 34 insertions(+), 16 deletions(-)
-------------- next part --------------
f62e67afa5322b1d39884775395bb357b96db9ba
diff --git a/dlls/winex11.drv/mouse.c b/dlls/winex11.drv/mouse.c
index 3b6c4c4..c09217d 100644
--- a/dlls/winex11.drv/mouse.c
+++ b/dlls/winex11.drv/mouse.c
@@ -71,6 +71,17 @@ static const UINT button_up_flags[NB_BUT
 
 POINT cursor_pos;
 
+static CRITICAL_SECTION cursor_CritSection;
+static CRITICAL_SECTION_DEBUG critsect_debug =
+{
+    0, 0, &cursor_CritSection,
+    { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
+      0, 0, { (DWORD_PTR)(__FILE__ ": cursor_CritSection") }
+};
+static CRITICAL_SECTION cursor_CritSection = { &critsect_debug, -1, 0, 0, 0, 0 };
+
+BOOL X11DRV_SetCursorPos( INT x, INT y );
+
 /***********************************************************************
  *		get_coords
  *
@@ -243,9 +254,6 @@ void X11DRV_send_mouse_input( HWND hwnd,
             pt.x = x;
             pt.y = y;
         }
-        wine_tsx11_lock();
-        cursor_pos = pt;
-        wine_tsx11_unlock();
     }
     else if (flags & MOUSEEVENTF_MOVE)
     {
@@ -265,23 +273,22 @@ void X11DRV_send_mouse_input( HWND hwnd,
             if ((abs(y) > accel[1]) && (accel[2] == 2)) yMult = 4;
         }
 
-        wine_tsx11_lock();
+        EnterCriticalSection( &cursor_CritSection );
         pt.x = cursor_pos.x + (long)x * xMult;
         pt.y = cursor_pos.y + (long)y * yMult;
+        LeaveCriticalSection( &cursor_CritSection );
 
         /* Clip to the current screen size */
         if (pt.x < 0) pt.x = 0;
         else if (pt.x >= screen_width) pt.x = screen_width - 1;
         if (pt.y < 0) pt.y = 0;
         else if (pt.y >= screen_height) pt.y = screen_height - 1;
-        cursor_pos = pt;
-        wine_tsx11_unlock();
     }
     else
     {
-        wine_tsx11_lock();
+        EnterCriticalSection( &cursor_CritSection );
         pt = cursor_pos;
-        wine_tsx11_unlock();
+        LeaveCriticalSection( &cursor_CritSection );
     }
 
     if (flags & MOUSEEVENTF_MOVE)
@@ -291,10 +298,11 @@ void X11DRV_send_mouse_input( HWND hwnd,
         if ((injected_flags & LLMHF_INJECTED) &&
             ((flags & MOUSEEVENTF_ABSOLUTE) || x || y))  /* we have to actually move the cursor */
         {
-            TRACE( "warping to (%ld,%ld)\n", pt.x, pt.y );
-            wine_tsx11_lock();
-            XWarpPointer( thread_display(), root_window, root_window, 0, 0, 0, 0, pt.x, pt.y );
-            wine_tsx11_unlock();
+            X11DRV_SetCursorPos(pt.x, pt.y);
+        } else {
+            EnterCriticalSection( &cursor_CritSection );
+            cursor_pos = pt;
+            LeaveCriticalSection( &cursor_CritSection );
         }
     }
     if (flags & MOUSEEVENTF_LEFTDOWN)
@@ -698,9 +706,12 @@ BOOL X11DRV_SetCursorPos( INT x, INT y )
     wine_tsx11_lock();
     XWarpPointer( display, root_window, root_window, 0, 0, 0, 0, x, y );
     XFlush( display ); /* avoids bad mouse lag in games that do their own mouse warping */
+    wine_tsx11_unlock();
+
+    EnterCriticalSection( &cursor_CritSection );
     cursor_pos.x = x;
     cursor_pos.y = y;
-    wine_tsx11_unlock();
+    LeaveCriticalSection( &cursor_CritSection );
     return TRUE;
 }
 
@@ -713,19 +724,26 @@ BOOL X11DRV_GetCursorPos(LPPOINT pos)
     Window root, child;
     int rootX, rootY, winX, winY;
     unsigned int xstate;
+    BOOL res;
 
     wine_tsx11_lock();
-    if (XQueryPointer( display, root_window, &root, &child,
-                       &rootX, &rootY, &winX, &winY, &xstate ))
+    res = XQueryPointer( display, root_window, &root, &child,
+                         &rootX, &rootY, &winX, &winY, &xstate );
+    wine_tsx11_unlock();
+    if (res)
     {
         update_key_state( xstate );
         update_button_state( xstate );
         TRACE("pointer at (%d,%d)\n", winX, winY );
+        EnterCriticalSection( &cursor_CritSection );
         cursor_pos.x = winX;
         cursor_pos.y = winY;
+        LeaveCriticalSection( &cursor_CritSection );
     }
+    EnterCriticalSection( &cursor_CritSection );
     *pos = cursor_pos;
-    wine_tsx11_unlock();
+    LeaveCriticalSection( &cursor_CritSection );
+
     return TRUE;
 }
 


More information about the wine-patches mailing list