Ken Thomases : winemac: Restore app cursor settings when cursor moves back into an app window.

Alexandre Julliard julliard at winehq.org
Fri Jan 10 14:44:52 CST 2014


Module: wine
Branch: stable
Commit: 64fdb8ab0f763c9295064d24f24b1e40d4d6af6a
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=64fdb8ab0f763c9295064d24f24b1e40d4d6af6a

Author: Ken Thomases <ken at codeweavers.com>
Date:   Thu Oct 17 23:45:52 2013 -0500

winemac: Restore app cursor settings when cursor moves back into an app window.

The code had previously set the cursor back to the standard arrow and unhid
it when it left all app windows.  Now it restores the cursor image that the
app set and re-hides it if necessary when it moves back over any app window.

(cherry picked from commit 1c049e5031ff6ca3dc2ee874493aa6e685e8e9c2)

---

 dlls/winemac.drv/cocoa_app.h |    3 ++
 dlls/winemac.drv/cocoa_app.m |   80 ++++++++++++++++++++++++++++++++----------
 2 files changed, 65 insertions(+), 18 deletions(-)

diff --git a/dlls/winemac.drv/cocoa_app.h b/dlls/winemac.drv/cocoa_app.h
index a398bf1..07a4bc8 100644
--- a/dlls/winemac.drv/cocoa_app.h
+++ b/dlls/winemac.drv/cocoa_app.h
@@ -73,7 +73,10 @@ enum {
     NSArray*    cursorFrames;
     int         cursorFrame;
     NSTimer*    cursorTimer;
+    NSCursor*   cursor;
+    BOOL        cursorIsCurrent;
     BOOL        cursorHidden;
+    BOOL        clientWantsCursorHidden;
 
     BOOL clippingCursor;
     CGRect cursorClipRect;
diff --git a/dlls/winemac.drv/cocoa_app.m b/dlls/winemac.drv/cocoa_app.m
index 3d89082..1cc8d2d 100644
--- a/dlls/winemac.drv/cocoa_app.m
+++ b/dlls/winemac.drv/cocoa_app.m
@@ -80,6 +80,7 @@ int macdrv_err_on;
 @property (readwrite, copy, nonatomic) NSEvent* lastFlagsChanged;
 @property (copy, nonatomic) NSArray* cursorFrames;
 @property (retain, nonatomic) NSTimer* cursorTimer;
+ at property (retain, nonatomic) NSCursor* cursor;
 @property (retain, nonatomic) NSImage* applicationIcon;
 @property (readonly, nonatomic) BOOL inputSourceIsInputMethod;
 @property (retain, nonatomic) WineWindow* mouseCaptureWindow;
@@ -96,7 +97,7 @@ int macdrv_err_on;
 
     @synthesize keyboardType, lastFlagsChanged;
     @synthesize applicationIcon;
-    @synthesize cursorFrames, cursorTimer;
+    @synthesize cursorFrames, cursorTimer, cursor;
     @synthesize mouseCaptureWindow;
 
     + (void) initialize
@@ -172,6 +173,7 @@ int macdrv_err_on;
 
     - (void) dealloc
     {
+        [cursor release];
         [screenFrameCGRects release];
         [applicationIcon release];
         [warpRecords release];
@@ -785,21 +787,69 @@ int macdrv_err_on;
         return ([originalDisplayModes count] > 0 || displaysCapturedForFullscreen);
     }
 
+    - (void) updateCursor
+    {
+        if (lastTargetWindow)
+        {
+            if (clientWantsCursorHidden && !cursorHidden)
+            {
+                [NSCursor hide];
+                cursorHidden = TRUE;
+            }
+
+            if (!cursorIsCurrent)
+            {
+                [cursor set];
+                cursorIsCurrent = TRUE;
+            }
+
+            if (!clientWantsCursorHidden && cursorHidden)
+            {
+                [NSCursor unhide];
+                cursorHidden = FALSE;
+            }
+        }
+        else
+        {
+            if (cursorIsCurrent)
+            {
+                [[NSCursor arrowCursor] set];
+                cursorIsCurrent = FALSE;
+            }
+            if (cursorHidden)
+            {
+                [NSCursor unhide];
+                cursorHidden = FALSE;
+            }
+        }
+    }
+
     - (void) hideCursor
     {
-        if (!cursorHidden)
+        if (!clientWantsCursorHidden)
         {
-            [NSCursor hide];
-            cursorHidden = TRUE;
+            clientWantsCursorHidden = TRUE;
+            [self updateCursor];
         }
     }
 
     - (void) unhideCursor
     {
-        if (cursorHidden)
+        if (clientWantsCursorHidden)
         {
-            [NSCursor unhide];
-            cursorHidden = FALSE;
+            clientWantsCursorHidden = FALSE;
+            [self updateCursor];
+        }
+    }
+
+    - (void) setCursor:(NSCursor*)newCursor
+    {
+        if (newCursor != cursor)
+        {
+            [cursor release];
+            cursor = [newCursor retain];
+            cursorIsCurrent = FALSE;
+            [self updateCursor];
         }
     }
 
@@ -810,15 +860,12 @@ int macdrv_err_on;
         NSImage* image = [[NSImage alloc] initWithCGImage:cgimage size:NSZeroSize];
         CFDictionaryRef hotSpotDict = (CFDictionaryRef)[frame objectForKey:@"hotSpot"];
         CGPoint hotSpot;
-        NSCursor* cursor;
 
         if (!CGPointMakeWithDictionaryRepresentation(hotSpotDict, &hotSpot))
             hotSpot = CGPointZero;
-        cursor = [[NSCursor alloc] initWithImage:image hotSpot:NSPointFromCGPoint(hotSpot)];
+        self.cursor = [[[NSCursor alloc] initWithImage:image hotSpot:NSPointFromCGPoint(hotSpot)] autorelease];
         [image release];
-        [cursor set];
         [self unhideCursor];
-        [cursor release];
     }
 
     - (void) nextCursorFrame:(NSTimer*)theTimer
@@ -1466,12 +1513,10 @@ int macdrv_err_on;
 
             lastTargetWindow = targetWindow;
         }
-        else if (lastTargetWindow)
-        {
-            [[NSCursor arrowCursor] set];
-            [self unhideCursor];
+        else
             lastTargetWindow = nil;
-        }
+
+        [self updateCursor];
     }
 
     - (void) handleMouseButton:(NSEvent*)theEvent
@@ -2245,9 +2290,8 @@ void macdrv_set_cursor(CFStringRef name, CFArrayRef frames)
     {
         OnMainThreadAsync(^{
             WineApplicationController* controller = [WineApplicationController sharedController];
-            NSCursor* cursor = [NSCursor performSelector:sel];
             [controller setCursorWithFrames:nil];
-            [cursor set];
+            controller.cursor = [NSCursor performSelector:sel];
             [controller unhideCursor];
         });
     }




More information about the wine-cvs mailing list