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.

(cherry picked from commit f1690e265e)
This commit is contained in:
Brian Collins 2024-03-16 16:27:14 -04:00 committed by Sam Lantinga
parent 863f39fb9f
commit ef54e0c4f4
1 changed files with 25 additions and 11 deletions

View File

@ -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
@ -1323,6 +1334,7 @@ static int Cocoa_SendMouseButtonClicks(SDL_Mouse * mouse, NSEvent *theEvent, SDL
NSPoint point;
int x, y;
SDL_Window *window;
NSView *contentView;
if (!mouse) {
return;
@ -1330,6 +1342,17 @@ static int Cocoa_SendMouseButtonClicks(SDL_Mouse * mouse, NSEvent *theEvent, SDL
mouseID = mouse->mouseID;
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]) {
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_HIT_TEST, 0, 0);
@ -1340,7 +1363,6 @@ static int Cocoa_SendMouseButtonClicks(SDL_Mouse * mouse, NSEvent *theEvent, SDL
return;
}
point = [theEvent locationInWindow];
x = (int)point.x;
y = (int)(window->h - point.y);
@ -1590,17 +1612,9 @@ static int Cocoa_SendMouseButtonClicks(SDL_Mouse * mouse, NSEvent *theEvent, SDL
- (void)resetCursorRects
{
SDL_Mouse *mouse;
[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