x11drv: [1/2] Move cached cursor position from under x11's lock and into it's own.

Vitaliy Margolen wine-patch at kievinfo.com
Mon Oct 2 07:17:06 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.
Also it is better to have a separate lock when we won't call X to retrieve it.


 dlls/winex11.drv/mouse.c |   50 +++++++++++++++++++++++++++++++---------------
 1 files changed, 34 insertions(+), 16 deletions(-)

-------------- next part --------------
cbd15e95723dd8af2f2d18d3157c414a6f01a2e3
diff --git a/dlls/winex11.drv/mouse.c b/dlls/winex11.drv/mouse.c
index a64d7cc..14ffcc7 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
  *
@@ -239,9 +250,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)
     {
@@ -261,23 +269,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)
@@ -287,10 +294,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)
@@ -694,9 +702,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;
 }
 
@@ -709,19 +720,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