Explorar el Código

cocoa: Always add a window-sized NSTrackingArea to each window.

Previously this was only done on older macOSes, but it seems to work on all
versions, afaict.

Reference Issue #12725.
Ryan C. Gordon hace 9 meses
padre
commit
47717f22fd
Se han modificado 1 ficheros con 8 adiciones y 9 borrados
  1. 8 9
      src/video/cocoa/SDL_cocoawindow.m

+ 8 - 9
src/video/cocoa/SDL_cocoawindow.m

@@ -2112,20 +2112,19 @@ static void Cocoa_SendMouseButtonClicks(SDL_Mouse *mouse, NSEvent *theEvent, SDL
     }
 }
 
+// NSTrackingArea is how Cocoa tells you when the mouse cursor has entered or
+//  left certain regions. We put one over our entire window so we know when
+//  it has "mouse focus."
 - (void)updateTrackingAreas
 {
     [super updateTrackingAreas];
 
-    if (@available(macOS 12.0, *)) {
-        // we (currently) use the tracking areas as a workaround for older macOSes, but we might be safe everywhere...
-    } else {
-        SDL_CocoaWindowData *windata = (__bridge SDL_CocoaWindowData *)_sdlWindow->internal;
-        if (_trackingArea) {
-            [self removeTrackingArea:_trackingArea];
-        }
-        _trackingArea = [[NSTrackingArea alloc] initWithRect:[self bounds] options:NSTrackingMouseEnteredAndExited|NSTrackingActiveAlways owner:windata.listener userInfo:nil];
-        [self addTrackingArea:_trackingArea];
+    SDL_CocoaWindowData *windata = (__bridge SDL_CocoaWindowData *)_sdlWindow->internal;
+    if (_trackingArea) {
+        [self removeTrackingArea:_trackingArea];
     }
+    _trackingArea = [[NSTrackingArea alloc] initWithRect:[self bounds] options:NSTrackingMouseEnteredAndExited|NSTrackingActiveAlways owner:windata.listener userInfo:nil];
+    [self addTrackingArea:_trackingArea];
 }
 @end