Skip to content

Commit f61d956

Browse files
committed
cocoa: add explicit tracking areas to the window.
This makes sure we get reliable mouse enter/exit events from the system on older macOS releases. Newer releases don't have this problem--my assumption is that Cocoa has a more aggressive default tracking area installed for some newer UI feature. For 3.2.16, we'll use the explicit tracking area on older macOSes only, but I'll remove that check in revision control for newer OSes and see what happens. Fixes #12725.
1 parent 58afb0d commit f61d956

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/video/cocoa/SDL_cocoawindow.m

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2019,6 +2019,7 @@ - (void)tabletPoint:(NSEvent *)theEvent
20192019
@interface SDL3View : NSView
20202020
{
20212021
SDL_Window *_sdlWindow;
2022+
NSTrackingArea *_trackingArea; // only used on macOS <= 11.0
20222023
}
20232024

20242025
- (void)setSDLWindow:(SDL_Window *)window;
@@ -2030,6 +2031,7 @@ - (void)drawRect:(NSRect)dirtyRect;
20302031
- (BOOL)acceptsFirstMouse:(NSEvent *)theEvent;
20312032
- (BOOL)wantsUpdateLayer;
20322033
- (void)updateLayer;
2034+
- (void)updateTrackingAreas;
20332035
@end
20342036

20352037
@implementation SDL3View
@@ -2110,6 +2112,21 @@ - (BOOL)acceptsFirstMouse:(NSEvent *)theEvent
21102112
}
21112113
}
21122114

2115+
- (void)updateTrackingAreas
2116+
{
2117+
[super updateTrackingAreas];
2118+
2119+
if (@available(macOS 12.0, *)) {
2120+
// we (currently) use the tracking areas as a workaround for older macOSes, but we might be safe everywhere...
2121+
} else {
2122+
SDL_CocoaWindowData *windata = (__bridge SDL_CocoaWindowData *)_sdlWindow->internal;
2123+
if (_trackingArea) {
2124+
[self removeTrackingArea:_trackingArea];
2125+
}
2126+
_trackingArea = [[NSTrackingArea alloc] initWithRect:[self bounds] options:NSTrackingMouseEnteredAndExited|NSTrackingActiveAlways owner:windata.listener userInfo:nil];
2127+
[self addTrackingArea:_trackingArea];
2128+
}
2129+
}
21132130
@end
21142131

21152132
static void Cocoa_UpdateMouseFocus()

0 commit comments

Comments
 (0)