[PATCH 1/5] winemac.drv: Simplify cursor clipping code paths.

Tim Clem tclem at codeweavers.com
Thu Oct 14 13:39:13 CDT 2021


Centralizes all clipping behavior into -startClippingCursor: and
-stopClippingCursor.

Signed-off-by: Tim Clem <tclem at codeweavers.com>
---
The current methods are confusingly named and, in some cases, broken.

-updateCursorClippingState has an incomplete picture of when clipping
should be enabled or disabled. Worse, -deactivateCursorClipping just
disables the event tap without calling
CGAssociateMouseAndMouseCursorPosition(true), so it will lock up the
cursor if called while the app is active. There are two main scenarios
where -updateCursorClippingState is called: when a window is being
dragged and when the app is (de)activated.

The drag-related calls can be removed entirely because the handlers in
window.c call ClipCursor(NULL) when a window is being dragged. (This is
in fact the only reason that the cursor doesn't get locked up when
windows are dragged right now.)

As for app (de)activation, the tap already ignores events if the app
isn't active, so the -updateCursorClippingState calls there can be
removed as well. (Moreover, Windows will cancel cursor clipping if the
app loses focus; the next patch calls -stopClippingCursor when the app
resigns active.)


 dlls/winemac.drv/cocoa_app.m | 52 +++++++++++-------------------------
 1 file changed, 15 insertions(+), 37 deletions(-)

diff --git a/dlls/winemac.drv/cocoa_app.m b/dlls/winemac.drv/cocoa_app.m
index 2d18da7f99a8..806252651613 100644
--- a/dlls/winemac.drv/cocoa_app.m
+++ b/dlls/winemac.drv/cocoa_app.m
@@ -1456,33 +1456,6 @@ - (BOOL) setCursorPosition:(CGPoint)pos
         return ret;
     }
 
-    - (void) activateCursorClipping
-    {
-        if (cursorClippingEventTap && !CGEventTapIsEnabled(cursorClippingEventTap))
-        {
-            CGEventTapEnable(cursorClippingEventTap, TRUE);
-            [self setCursorPosition:NSPointToCGPoint([self flippedMouseLocation:[NSEvent mouseLocation]])];
-        }
-    }
-
-    - (void) deactivateCursorClipping
-    {
-        if (cursorClippingEventTap && CGEventTapIsEnabled(cursorClippingEventTap))
-        {
-            CGEventTapEnable(cursorClippingEventTap, FALSE);
-            [warpRecords removeAllObjects];
-            lastSetCursorPositionTime = [[NSProcessInfo processInfo] systemUptime];
-        }
-    }
-
-    - (void) updateCursorClippingState
-    {
-        if (clippingCursor && [NSApp isActive] && ![windowsBeingDragged count])
-            [self activateCursorClipping];
-        else
-            [self deactivateCursorClipping];
-    }
-
     - (void) updateWindowsForCursorClipping
     {
         WineWindow* window;
@@ -1510,7 +1483,10 @@ - (BOOL) startClippingCursor:(CGRect)rect
 
         clippingCursor = TRUE;
         cursorClipRect = rect;
-        [self updateCursorClippingState];
+
+        CGEventTapEnable(cursorClippingEventTap, TRUE);
+        [self setCursorPosition:NSPointToCGPoint([self flippedMouseLocation:[NSEvent mouseLocation]])];
+
         [self updateWindowsForCursorClipping];
 
         return TRUE;
@@ -1518,12 +1494,21 @@ - (BOOL) startClippingCursor:(CGRect)rect
 
     - (BOOL) stopClippingCursor
     {
-        CGError err = CGAssociateMouseAndMouseCursorPosition(true);
+        CGError err;
+
+        if (!clippingCursor)
+            return TRUE;
+
+        err = CGAssociateMouseAndMouseCursorPosition(true);
         if (err != kCGErrorSuccess)
             return FALSE;
 
         clippingCursor = FALSE;
-        [self updateCursorClippingState];
+
+        CGEventTapEnable(cursorClippingEventTap, FALSE);
+        [warpRecords removeAllObjects];
+        lastSetCursorPositionTime = [[NSProcessInfo processInfo] systemUptime];
+
         [self updateWindowsForCursorClipping];
 
         return TRUE;
@@ -1554,7 +1539,6 @@ - (void) window:(WineWindow*)window isBeingDragged:(BOOL)dragged
             [windowsBeingDragged addObject:window];
         else
             [windowsBeingDragged removeObject:window];
-        [self updateCursorClippingState];
     }
 
     - (void) windowWillOrderOut:(WineWindow*)window
@@ -1584,7 +1568,6 @@ - (void) handleWindowDrag:(WineWindow*)window begin:(BOOL)begin
             [windowsBeingDragged removeObject:window];
             eventType = WINDOW_DRAG_END;
         }
-        [self updateCursorClippingState];
 
         event = macdrv_create_event(eventType, window);
         if (eventType == WINDOW_DRAG_BEGIN)
@@ -2161,7 +2144,6 @@ - (void) setupObservations
                 });
             }
             [windowsBeingDragged removeObject:window];
-            [self updateCursorClippingState];
         }];
 
         if (useDragNotifications) {
@@ -2305,8 +2287,6 @@ - (void)applicationDidBecomeActive:(NSNotification *)notification
             [self setMode:mode forDisplay:[displayID unsignedIntValue]];
         }
 
-        [self updateCursorClippingState];
-
         [self updateFullscreenWindows];
         [self adjustWindowLevels:YES];
 
@@ -2349,8 +2329,6 @@ - (void)applicationDidResignActive:(NSNotification *)notification
         macdrv_event* event;
         WineEventQueue* queue;
 
-        [self updateCursorClippingState];
-
         [self invalidateGotFocusEvents];
 
         event = macdrv_create_event(APP_DEACTIVATED, nil);
-- 
2.33.0




More information about the wine-devel mailing list