Rémi Bernon : winex11.drv: Forward clip_fullscreen_window to foreground thread.

Alexandre Julliard julliard at winehq.org
Mon Oct 5 15:54:59 CDT 2020


Module: wine
Branch: master
Commit: 16984895f0191dad12d55dee422214645b51aece
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=16984895f0191dad12d55dee422214645b51aece

Author: Rémi Bernon <rbernon at codeweavers.com>
Date:   Thu Oct  1 22:24:31 2020 +0200

winex11.drv: Forward clip_fullscreen_window to foreground thread.

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>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 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 cf55a5c1fb..0f61f9f7b2 100644
--- a/dlls/winex11.drv/display.c
+++ b/dlls/winex11.drv/display.c
@@ -372,14 +372,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();
@@ -394,6 +394,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 add38a95ba..dd25f8b172 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 b0312b1a18..457173964e 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 d4ee4a7c8d..173d94b9ef 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;




More information about the wine-cvs mailing list