SDL: macOS: remove dead code for supporting 10.6 at runtime.

From f871c178b9319ec1f05c41f0389fcead13acbf1a Mon Sep 17 00:00:00 2001
From: Alex Szpakowski <[EMAIL REDACTED]>
Date: Tue, 10 May 2022 17:32:24 -0300
Subject: [PATCH] macOS: remove dead code for supporting 10.6 at runtime.

---
 include/SDL_hints.h                  |  4 +---
 src/video/cocoa/SDL_cocoaevents.m    | 33 ++++++----------------------
 src/video/cocoa/SDL_cocoakeyboard.m  |  9 +-------
 src/video/cocoa/SDL_cocoametalview.m |  7 ++----
 src/video/cocoa/SDL_cocoamodes.m     | 32 +--------------------------
 src/video/cocoa/SDL_cocoamouse.m     |  8 +++----
 src/video/cocoa/SDL_cocoaopengl.m    | 25 ++++++---------------
 src/video/cocoa/SDL_cocoavideo.h     |  2 --
 src/video/cocoa/SDL_cocoavideo.m     |  5 +----
 src/video/cocoa/SDL_cocoawindow.m    | 14 ++++--------
 10 files changed, 27 insertions(+), 112 deletions(-)

diff --git a/include/SDL_hints.h b/include/SDL_hints.h
index cc5d46663ac..83cfe89a69a 100644
--- a/include/SDL_hints.h
+++ b/include/SDL_hints.h
@@ -1469,9 +1469,7 @@ extern "C" {
  *                SDL_WINDOW_RESIZABLE windows will offer the "fullscreen"
  *                button on their titlebars).
  *
- *  The default value is "1". Spaces are disabled regardless of this hint if
- *   the OS isn't at least Mac OS X Lion (10.7). This hint must be set before
- *   any windows are created.
+ *  The default value is "1". This hint must be set before any windows are created.
  */
 #define SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES    "SDL_VIDEO_MAC_FULLSCREEN_SPACES"
 
diff --git a/src/video/cocoa/SDL_cocoaevents.m b/src/video/cocoa/SDL_cocoaevents.m
index 774a93b6391..3a256d2cf67 100644
--- a/src/video/cocoa/SDL_cocoaevents.m
+++ b/src/video/cocoa/SDL_cocoaevents.m
@@ -424,15 +424,13 @@ - (void)handleURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEv
 
     [windowMenu addItemWithTitle:@"Zoom" action:@selector(performZoom:) keyEquivalent:@""];
     
-    /* Add the fullscreen toggle menu option, if supported */
-    if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6) {
-        /* Cocoa should update the title to Enter or Exit Full Screen automatically.
-         * But if not, then just fallback to Toggle Full Screen.
-         */
-        menuItem = [[NSMenuItem alloc] initWithTitle:@"Toggle Full Screen" action:@selector(toggleFullScreen:) keyEquivalent:@"f"];
-        [menuItem setKeyEquivalentModifierMask:NSEventModifierFlagControl | NSEventModifierFlagCommand];
-        [windowMenu addItem:menuItem];
-    }
+    /* Add the fullscreen toggle menu option. */
+    /* Cocoa should update the title to Enter or Exit Full Screen automatically.
+     * But if not, then just fallback to Toggle Full Screen.
+     */
+    menuItem = [[NSMenuItem alloc] initWithTitle:@"Toggle Full Screen" action:@selector(toggleFullScreen:) keyEquivalent:@"f"];
+    [menuItem setKeyEquivalentModifierMask:NSEventModifierFlagControl | NSEventModifierFlagCommand];
+    [windowMenu addItem:menuItem];
 
     /* Put menu into the menubar */
     menuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""];
@@ -505,19 +503,6 @@ - (void)handleURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEv
 int
 Cocoa_PumpEventsUntilDate(_THIS, NSDate *expiration, bool accumulate)
 {
-#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
-    /* Update activity every 30 seconds to prevent screensaver */
-    SDL_VideoData *data = (SDL_VideoData *)_this->driverdata;
-    if (_this->suspend_screensaver && !data->screensaver_use_iopm) {
-        Uint32 now = SDL_GetTicks();
-        if (!data->screensaver_activity ||
-            SDL_TICKS_PASSED(now, data->screensaver_activity + 30000)) {
-            UpdateSystemActivity(UsrActivity);
-            data->screensaver_activity = now;
-        }
-    }
-#endif
-
     for ( ; ; ) {
         NSEvent *event = [NSApp nextEventMatchingMask:NSEventMaskAny untilDate:expiration inMode:NSDefaultRunLoopMode dequeue:YES ];
         if ( event == nil ) {
@@ -584,10 +569,6 @@ void Cocoa_SendWakeupEvent(_THIS, SDL_Window *window)
 {
     SDL_VideoData *data = (__bridge SDL_VideoData *)_this->driverdata;
 
-    if (!data.screensaver_use_iopm) {
-        return;
-    }
-
     if (data.screensaver_assertion) {
         IOPMAssertionRelease(data.screensaver_assertion);
         data.screensaver_assertion = kIOPMNullAssertionID;
diff --git a/src/video/cocoa/SDL_cocoakeyboard.m b/src/video/cocoa/SDL_cocoakeyboard.m
index 2c9606b0f01..59ee39dc007 100644
--- a/src/video/cocoa/SDL_cocoakeyboard.m
+++ b/src/video/cocoa/SDL_cocoakeyboard.m
@@ -140,14 +140,7 @@ - (NSRect)firstRectForCharacterRange:(NSRange)aRange actualRange:(NSRangePointer
             aRange.location, aRange.length, windowHeight,
             NSStringFromRect(rect));
 
-#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
-    if (![window respondsToSelector:@selector(convertRectToScreen:)]) {
-        rect.origin = [window convertBaseToScreen:rect.origin];
-    } else
-#endif
-    {
-        rect = [window convertRectToScreen:rect];
-    }
+    rect = [window convertRectToScreen:rect];
 
     return rect;
 }
diff --git a/src/video/cocoa/SDL_cocoametalview.m b/src/video/cocoa/SDL_cocoametalview.m
index 3732ebb9ea8..ebdc921a19f 100644
--- a/src/video/cocoa/SDL_cocoametalview.m
+++ b/src/video/cocoa/SDL_cocoametalview.m
@@ -187,11 +187,8 @@ - (NSView *)hitTest:(NSPoint)point {
         /* Fall back to the viewport size. */
         NSRect viewport = [contentView bounds];
         if (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) {
-            /* This gives us the correct viewport for a Retina-enabled view, only
-             * supported on 10.7+. */
-            if ([contentView respondsToSelector:@selector(convertRectToBacking:)]) {
-                viewport = [contentView convertRectToBacking:viewport];
-            }
+            /* This gives us the correct viewport for a Retina-enabled view. */
+            viewport = [contentView convertRectToBacking:viewport];
         }
         if (w) {
             *w = viewport.size.width;
diff --git a/src/video/cocoa/SDL_cocoamodes.m b/src/video/cocoa/SDL_cocoamodes.m
index 140425856d4..88284b50541 100644
--- a/src/video/cocoa/SDL_cocoamodes.m
+++ b/src/video/cocoa/SDL_cocoamodes.m
@@ -31,9 +31,6 @@
 #include <CoreVideo/CVBase.h>
 #include <CoreVideo/CVDisplayLink.h>
 
-/* we need this for ShowMenuBar() and HideMenuBar(). */
-#include <Carbon/Carbon.h>
-
 /* This gets us MAC_OS_X_VERSION_MIN_REQUIRED... */
 #include <AvailabilityMacros.h>
 
@@ -45,23 +42,6 @@
 #endif
 
 
-static void
-Cocoa_ToggleMenuBar(const BOOL show)
-{
-    /* !!! FIXME: keep an eye on this.
-     * ShowMenuBar/HideMenuBar is officially unavailable for 64-bit binaries.
-     *  It happens to work, as of 10.7, but we're going to see if
-     *  we can just simply do without it on newer OSes...
-     */
-#if (MAC_OS_X_VERSION_MIN_REQUIRED < 1070) && !defined(__LP64__)
-    if (show) {
-        ShowMenuBar();
-    } else {
-        HideMenuBar();
-    }
-#endif
-}
-
 static int
 CG_SetError(const char *prefix, CGDisplayErr result)
 {
@@ -497,7 +477,7 @@
                 CFRelease(dmOptions);
             } else
 #endif
-            if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6) {
+            {
                 // fallback for 10.7
                 scaleFactor = [screen backingScaleFactor];
                 displayNativeSize.width = displayNativeSize.width * scaleFactor;
@@ -646,10 +626,6 @@
         } else {
             CGDisplayRelease(displaydata->display);
         }
-
-        if (CGDisplayIsMain(displaydata->display)) {
-            Cocoa_ToggleMenuBar(YES);
-        }
     } else {
         /* Put up the blanking window (a window above all other windows) */
         if (CGDisplayIsMain(displaydata->display)) {
@@ -669,11 +645,6 @@
             CG_SetError("CGDisplaySwitchToMode()", result);
             goto ERR_NO_SWITCH;
         }
-
-        /* Hide the menu bar so it doesn't intercept events */
-        if (CGDisplayIsMain(displaydata->display)) {
-            Cocoa_ToggleMenuBar(NO);
-        }
     }
 
     /* Fade in again (asynchronously) */
@@ -720,7 +691,6 @@
             CFRelease(mode->modes);
         }
     }
-    Cocoa_ToggleMenuBar(YES);
 }
 
 #endif /* SDL_VIDEO_DRIVER_COCOA */
diff --git a/src/video/cocoa/SDL_cocoamouse.m b/src/video/cocoa/SDL_cocoamouse.m
index 70d2db37896..25041eb64ef 100644
--- a/src/video/cocoa/SDL_cocoamouse.m
+++ b/src/video/cocoa/SDL_cocoamouse.m
@@ -461,15 +461,13 @@ + (NSCursor *)invisibleCursor
     CGFloat y = [event deltaY];
     SDL_MouseWheelDirection direction = SDL_MOUSEWHEEL_NORMAL;
 
-    if ([event respondsToSelector:@selector(isDirectionInvertedFromDevice)]) {
-        if ([event isDirectionInvertedFromDevice] == YES) {
-            direction = SDL_MOUSEWHEEL_FLIPPED;
-        }
+    if ([event isDirectionInvertedFromDevice] == YES) {
+        direction = SDL_MOUSEWHEEL_FLIPPED;
     }
 
     /* For discrete scroll events from conventional mice, always send a full tick.
        For continuous scroll events from trackpads, send fractional deltas for smoother scrolling. */
-    if (![event respondsToSelector:@selector(hasPreciseScrollingDeltas)] || ![event hasPreciseScrollingDeltas]) {
+    if (![event hasPreciseScrollingDeltas]) {
         if (x > 0) {
             x = SDL_ceil(x);
         } else if (x < 0) {
diff --git a/src/video/cocoa/SDL_cocoaopengl.m b/src/video/cocoa/SDL_cocoaopengl.m
index 1ec8f9b8b25..aa2f51eaa18 100644
--- a/src/video/cocoa/SDL_cocoaopengl.m
+++ b/src/video/cocoa/SDL_cocoaopengl.m
@@ -180,7 +180,6 @@ - (void)explicitUpdate
 {
     SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
     SDL_DisplayData *displaydata = (SDL_DisplayData *)display->driverdata;
-    SDL_bool lion_or_later = floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6;
     NSOpenGLPixelFormatAttribute attr[32];
     NSOpenGLPixelFormat *fmt;
     SDLOpenGLContext *context;
@@ -214,22 +213,15 @@ - (void)explicitUpdate
         return NULL;
 #endif
     }
-    if ((_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_CORE) && !lion_or_later) {
-        SDL_SetError ("OpenGL Core Profile is not supported on this platform version");
-        return NULL;
-    }
 
     attr[i++] = NSOpenGLPFAAllowOfflineRenderers;
 
-    /* specify a profile if we're on Lion (10.7) or later. */
-    if (lion_or_later) {
-        NSOpenGLPixelFormatAttribute profile = NSOpenGLProfileVersionLegacy;
-        if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_CORE) {
-            profile = NSOpenGLProfileVersion3_2Core;
-        }
-        attr[i++] = NSOpenGLPFAOpenGLProfile;
-        attr[i++] = profile;
+    NSOpenGLPixelFormatAttribute profile = NSOpenGLProfileVersionLegacy;
+    if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_CORE) {
+        profile = NSOpenGLProfileVersion3_2Core;
     }
+    attr[i++] = NSOpenGLPFAOpenGLProfile;
+    attr[i++] = profile;
 
     attr[i++] = NSOpenGLPFAColorSize;
     attr[i++] = SDL_BYTESPERPIXEL(display->current_mode.format)*8;
@@ -377,11 +369,8 @@ - (void)explicitUpdate
     NSRect viewport = [contentView bounds];
 
     if (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) {
-        /* This gives us the correct viewport for a Retina-enabled view, only
-         * supported on 10.7+. */
-        if ([contentView respondsToSelector:@selector(convertRectToBacking:)]) {
-            viewport = [contentView convertRectToBacking:viewport];
-        }
+        /* This gives us the correct viewport for a Retina-enabled view. */
+        viewport = [contentView convertRectToBacking:viewport];
     }
 
     if (w) {
diff --git a/src/video/cocoa/SDL_cocoavideo.h b/src/video/cocoa/SDL_cocoavideo.h
index 826b52ec676..4de8511a351 100644
--- a/src/video/cocoa/SDL_cocoavideo.h
+++ b/src/video/cocoa/SDL_cocoavideo.h
@@ -103,8 +103,6 @@ DECLARE_ALERT_STYLE(Critical);
     @property (nonatomic) void *key_layout;
     @property (nonatomic) SDLTranslatorResponder *fieldEdit;
     @property (nonatomic) NSInteger clipboard_count;
-    @property (nonatomic) Uint32 screensaver_activity;
-    @property (nonatomic) BOOL screensaver_use_iopm;
     @property (nonatomic) IOPMAssertionID screensaver_assertion;
     @property (nonatomic) SDL_mutex *swaplock;
 @end
diff --git a/src/video/cocoa/SDL_cocoavideo.m b/src/video/cocoa/SDL_cocoavideo.m
index dbc4fc93795..1df31f64823 100644
--- a/src/video/cocoa/SDL_cocoavideo.m
+++ b/src/video/cocoa/SDL_cocoavideo.m
@@ -196,10 +196,7 @@ @implementation SDL_VideoData
         return -1;
     }
 
-    data.allow_spaces = ((floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6) && SDL_GetHintBoolean(SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES, SDL_TRUE));
-
-    /* The IOPM assertion API can disable the screensaver as of 10.7. */
-    data.screensaver_use_iopm = floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6;
+    data.allow_spaces = SDL_GetHintBoolean(SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES, SDL_TRUE);
 
     data.swaplock = SDL_CreateMutex();
     if (!data.swaplock) {
diff --git a/src/video/cocoa/SDL_cocoawindow.m b/src/video/cocoa/SDL_cocoawindow.m
index a9d9b85018c..79430251b9c 100644
--- a/src/video/cocoa/SDL_cocoawindow.m
+++ b/src/video/cocoa/SDL_cocoawindow.m
@@ -1713,8 +1713,6 @@ - (BOOL)acceptsFirstMouse:(NSEvent *)theEvent
 #endif
 
     if (videodata.allow_spaces) {
-        SDL_assert(floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6);
-        SDL_assert([nswindow respondsToSelector:@selector(toggleFullScreen:)]);
         /* we put FULLSCREEN_DESKTOP windows in their own Space, without a toggle button or menubar, later */
         if (window->flags & SDL_WINDOW_RESIZABLE) {
             /* resizable windows are Spaces-friendly: they get the "go fullscreen" toggle button on their titlebar. */
@@ -1738,10 +1736,8 @@ - (BOOL)acceptsFirstMouse:(NSEvent *)theEvent
     #endif
     /* Note: as of the macOS 10.15 SDK, this defaults to YES instead of NO when
      * the NSHighResolutionCapable boolean is set in Info.plist. */
-    if ([contentView respondsToSelector:@selector(setWantsBestResolutionOpenGLSurface:)]) {
-        BOOL highdpi = (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) != 0;
-        [contentView setWantsBestResolutionOpenGLSurface:highdpi];
-    }
+    BOOL highdpi = (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) != 0;
+    [contentView setWantsBestResolutionOpenGLSurface:highdpi];
     #ifdef __clang__
     #pragma clang diagnostic pop
     #endif
@@ -1813,10 +1809,8 @@ - (BOOL)acceptsFirstMouse:(NSEvent *)theEvent
     #endif
     /* Note: as of the macOS 10.15 SDK, this defaults to YES instead of NO when
      * the NSHighResolutionCapable boolean is set in Info.plist. */
-    if ([nsview respondsToSelector:@selector(setWantsBestResolutionOpenGLSurface:)]) {
-        BOOL highdpi = (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) != 0;
-        [nsview setWantsBestResolutionOpenGLSurface:highdpi];
-    }
+    BOOL highdpi = (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) != 0;
+    [nsview setWantsBestResolutionOpenGLSurface:highdpi];
     #ifdef __clang__
     #pragma clang diagnostic pop
     #endif