From 325cc98d7d3e77faa195e1043e9f6790a783fd1a Mon Sep 17 00:00:00 2001 From: Tim Clem Date: Tue, 19 Oct 2021 14:21:09 -0700 Subject: [PATCH] winemac.drv: Simplify cursor clipping code paths. Centralizes all clipping behavior into -startClippingCursor: and -stopClippingCursor. Signed-off-by: Tim Clem Signed-off-by: Alexandre Julliard --- 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 2d18da7f99a..80625265161 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);