[PATCH v2 2/2] winex11.drv: Forward clip_fullscreen_window to foreground thread.

Rémi Bernon rbernon at codeweavers.com
Thu Oct 1 15:24:31 CDT 2020


If the current thread isn't the foreground thread. Otherwise we may
clip the cursor in the wrong thread, that isn't expecting mouse messages
or may not be checking its messages.

Red Faction has some race condition where this can happen for instance,
with clip_fullscreen_window called from X11DRV_DisplayDevices_Update
callback in a background thread. This thread starts clipping the cursor,
and the foreground thread isn't receiving MotionNotify events anymore.

Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
---

v2: Only forward the call done in update_windows_on_display_change,
    from X11DRV_DisplayDevices_Update. The other calls should already
    be in the correct thread and guarded with foreground window checks.

    Doing in clip_fullscreen_window made the returned value confusing.

 dlls/winex11.drv/display.c | 11 +++++++++--
 dlls/winex11.drv/mouse.c   |  6 ++++--
 dlls/winex11.drv/window.c  |  2 +-
 dlls/winex11.drv/x11drv.h  |  2 +-
 4 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/dlls/winex11.drv/display.c b/dlls/winex11.drv/display.c
index 3e9e4474d4c..78fb922df60 100644
--- a/dlls/winex11.drv/display.c
+++ b/dlls/winex11.drv/display.c
@@ -370,14 +370,14 @@ static BOOL CALLBACK update_windows_on_display_change(HWND hwnd, LPARAM lparam)
         XReconfigureWMWindow(data->display, data->whole_window, data->vis.screen, mask, &changes);
     }
     release_win_data(data);
-    if (hwnd == GetForegroundWindow())
-        clip_fullscreen_window(hwnd, TRUE);
     return TRUE;
 }
 
 void X11DRV_DisplayDevices_Update(BOOL send_display_change)
 {
     RECT old_virtual_rect, new_virtual_rect;
+    DWORD tid, pid;
+    HWND foreground;
     UINT mask = 0;
 
     old_virtual_rect = get_virtual_screen_rect();
@@ -392,6 +392,13 @@ void X11DRV_DisplayDevices_Update(BOOL send_display_change)
 
     X11DRV_resize_desktop(send_display_change);
     EnumWindows(update_windows_on_display_change, (LPARAM)mask);
+
+    /* forward clip_fullscreen_window request to the foreground window */
+    if ((foreground = GetForegroundWindow()) && (tid = GetWindowThreadProcessId( foreground, &pid )) && pid == GetCurrentProcessId())
+    {
+        if (tid == GetCurrentThreadId()) clip_fullscreen_window( foreground, TRUE );
+        else SendNotifyMessageW( foreground, WM_X11DRV_CLIP_CURSOR_REQUEST, TRUE, TRUE );
+    }
 }
 
 /* Initialize a GPU instance.
diff --git a/dlls/winex11.drv/mouse.c b/dlls/winex11.drv/mouse.c
index add38a95ba7..dd25f8b172c 100644
--- a/dlls/winex11.drv/mouse.c
+++ b/dlls/winex11.drv/mouse.c
@@ -1530,7 +1530,7 @@ BOOL CDECL X11DRV_ClipCursor( LPCRECT clip )
         if (tid && tid != GetCurrentThreadId() && pid == GetCurrentProcessId())
         {
             TRACE( "forwarding clip request to %p\n", foreground );
-            SendNotifyMessageW( foreground, WM_X11DRV_CLIP_CURSOR_REQUEST, 0, 0 );
+            SendNotifyMessageW( foreground, WM_X11DRV_CLIP_CURSOR_REQUEST, FALSE, FALSE );
             return TRUE;
         }
 
@@ -1559,7 +1559,7 @@ BOOL CDECL X11DRV_ClipCursor( LPCRECT clip )
  *
  * Function called upon receiving a WM_X11DRV_CLIP_CURSOR_REQUEST.
  */
-LRESULT clip_cursor_request( HWND hwnd )
+LRESULT clip_cursor_request( HWND hwnd, BOOL fullscreen, BOOL reset )
 {
     RECT clip;
 
@@ -1567,6 +1567,8 @@ LRESULT clip_cursor_request( HWND hwnd )
         WARN( "ignoring clip cursor request on desktop window.\n" );
     else if (hwnd != GetForegroundWindow())
         WARN( "ignoring clip cursor request on non-foreground window.\n" );
+    else if (fullscreen)
+        clip_fullscreen_window( hwnd, reset );
     else
     {
         GetClipCursor( &clip );
diff --git a/dlls/winex11.drv/window.c b/dlls/winex11.drv/window.c
index b0312b1a18b..457173964eb 100644
--- a/dlls/winex11.drv/window.c
+++ b/dlls/winex11.drv/window.c
@@ -2784,7 +2784,7 @@ LRESULT CDECL X11DRV_WindowMessage( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
     case WM_X11DRV_CLIP_CURSOR_NOTIFY:
         return clip_cursor_notify( hwnd, (HWND)wp, (HWND)lp );
     case WM_X11DRV_CLIP_CURSOR_REQUEST:
-        return clip_cursor_request( hwnd );
+        return clip_cursor_request( hwnd, (BOOL)wp, (BOOL)lp );
     default:
         FIXME( "got window msg %x hwnd %p wp %lx lp %lx\n", msg, hwnd, wp, lp );
         return 0;
diff --git a/dlls/winex11.drv/x11drv.h b/dlls/winex11.drv/x11drv.h
index d4ee4a7c8df..173d94b9efa 100644
--- a/dlls/winex11.drv/x11drv.h
+++ b/dlls/winex11.drv/x11drv.h
@@ -628,7 +628,7 @@ extern void CDECL X11DRV_SetFocus( HWND hwnd ) DECLSPEC_HIDDEN;
 extern void set_window_cursor( Window window, HCURSOR handle ) DECLSPEC_HIDDEN;
 extern void sync_window_cursor( Window window ) DECLSPEC_HIDDEN;
 extern LRESULT clip_cursor_notify( HWND hwnd, HWND prev_clip_hwnd, HWND new_clip_hwnd ) DECLSPEC_HIDDEN;
-extern LRESULT clip_cursor_request( HWND hwnd ) DECLSPEC_HIDDEN;
+extern LRESULT clip_cursor_request( HWND hwnd, BOOL fullscreen, BOOL reset ) DECLSPEC_HIDDEN;
 extern void ungrab_clipping_window(void) DECLSPEC_HIDDEN;
 extern void reset_clipping_window(void) DECLSPEC_HIDDEN;
 extern void retry_grab_clipping_window(void) DECLSPEC_HIDDEN;
-- 
2.28.0




More information about the wine-devel mailing list