Просмотр исходного кода

Workaround a macOS cursor-related bug.

This fixes an macOS bug that is only known to occur in fullscreen windows on the built-in displays of newer MacBooks with camera notches. When the mouse is moved near the top of such a window (within about 44 units) and then moved back down, the cursor rects aren't respected. This can cause the default cursor to be visible when it should not be.
Brian Collins 2 лет назад
Родитель
Сommit
f1690e265e
1 измененных файлов с 25 добавлено и 11 удалено
  1. 25 11
      src/video/cocoa/SDL_cocoawindow.m

+ 25 - 11
src/video/cocoa/SDL_cocoawindow.m

@@ -460,6 +460,17 @@ static void Cocoa_UpdateClipCursor(SDL_Window * window)
     }
     }
 }
 }
 
 
+static NSCursor *Cocoa_GetDesiredCursor(void)
+{
+    SDL_Mouse *mouse = SDL_GetMouse();
+
+    if (mouse->cursor_shown && mouse->cur_cursor && !mouse->relative_mode) {
+        return (__bridge NSCursor *)mouse->cur_cursor->driverdata;
+    }
+
+    return [NSCursor invisibleCursor];
+}
+
 
 
 @implementation Cocoa_WindowListener
 @implementation Cocoa_WindowListener
 
 
@@ -1323,6 +1334,7 @@ static int Cocoa_SendMouseButtonClicks(SDL_Mouse * mouse, NSEvent *theEvent, SDL
     NSPoint point;
     NSPoint point;
     int x, y;
     int x, y;
     SDL_Window *window;
     SDL_Window *window;
+    NSView *contentView;
 
 
     if (!mouse) {
     if (!mouse) {
         return;
         return;
@@ -1330,6 +1342,17 @@ static int Cocoa_SendMouseButtonClicks(SDL_Mouse * mouse, NSEvent *theEvent, SDL
 
 
     mouseID = mouse->mouseID;
     mouseID = mouse->mouseID;
     window = _data.window;
     window = _data.window;
+    contentView = _data.sdlContentView;
+    point = [theEvent locationInWindow];
+
+    if ([contentView mouse:[contentView convertPoint:point fromView:nil] inRect:[contentView bounds]] &&
+        [NSCursor currentCursor] != Cocoa_GetDesiredCursor()) {
+        // The wrong cursor is on screen, fix it. This fixes an macOS bug that is only known to
+        // occur in fullscreen windows on the built-in displays of newer MacBooks with camera
+        // notches. When the mouse is moved near the top of such a window (within about 44 units)
+        // and then moved back down, the cursor rects aren't respected.
+        [_data.nswindow invalidateCursorRectsForView:contentView];
+    }
 
 
     if ([self processHitTest:theEvent]) {
     if ([self processHitTest:theEvent]) {
         SDL_SendWindowEvent(window, SDL_WINDOWEVENT_HIT_TEST, 0, 0);
         SDL_SendWindowEvent(window, SDL_WINDOWEVENT_HIT_TEST, 0, 0);
@@ -1340,7 +1363,6 @@ static int Cocoa_SendMouseButtonClicks(SDL_Mouse * mouse, NSEvent *theEvent, SDL
         return;
         return;
     }
     }
 
 
-    point = [theEvent locationInWindow];
     x = (int)point.x;
     x = (int)point.x;
     y = (int)(window->h - point.y);
     y = (int)(window->h - point.y);
 
 
@@ -1590,17 +1612,9 @@ static int Cocoa_SendMouseButtonClicks(SDL_Mouse * mouse, NSEvent *theEvent, SDL
 
 
 - (void)resetCursorRects
 - (void)resetCursorRects
 {
 {
-    SDL_Mouse *mouse;
     [super resetCursorRects];
     [super resetCursorRects];
-    mouse = SDL_GetMouse();
-
-    if (mouse->cursor_shown && mouse->cur_cursor && !mouse->relative_mode) {
-        [self addCursorRect:[self bounds]
-                     cursor:(__bridge NSCursor *)mouse->cur_cursor->driverdata];
-    } else {
-        [self addCursorRect:[self bounds]
-                     cursor:[NSCursor invisibleCursor]];
-    }
+    [self addCursorRect:[self bounds]
+                 cursor:Cocoa_GetDesiredCursor()];
 }
 }
 
 
 - (BOOL)acceptsFirstMouse:(NSEvent *)theEvent
 - (BOOL)acceptsFirstMouse:(NSEvent *)theEvent