From 45c1c586809b00f093e07eeaffda01372c94f0c5 Mon Sep 17 00:00:00 2001 From: der richter Date: Sun, 17 Nov 2024 16:02:43 +0100 Subject: [PATCH] mac/compat: fix compatibility for deployment targets lower than SDK ver the swift parts can't be nicely encapsulated in the compat file because it lags proper target version compile time checks. Fixes #15292 --- osdep/mac/compat.h | 7 ++++++- osdep/mac/swift_compat.swift | 4 ---- video/out/mac/common.swift | 7 +++++-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/osdep/mac/compat.h b/osdep/mac/compat.h index 3f9d9fc2e0..9b6c7171ea 100644 --- a/osdep/mac/compat.h +++ b/osdep/mac/compat.h @@ -17,12 +17,17 @@ #pragma once +#include #include "config.h" #ifndef GL_SILENCE_DEPRECATION #define GL_SILENCE_DEPRECATION #endif -#if !HAVE_MACOS_12_FEATURES +#ifndef MAC_OS_VERSION_12_0 +#define MAC_OS_VERSION_12_0 120000 +#endif + +#if !HAVE_MACOS_12_FEATURES || (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_VERSION_12_0) #define kAudioObjectPropertyElementMain kAudioObjectPropertyElementMaster #endif diff --git a/osdep/mac/swift_compat.swift b/osdep/mac/swift_compat.swift index 9b72a4828b..24365cdd4a 100644 --- a/osdep/mac/swift_compat.swift +++ b/osdep/mac/swift_compat.swift @@ -44,10 +44,6 @@ extension NSDraggingInfo { } #endif -#if !HAVE_MACOS_12_FEATURES -let kIOMainPortDefault: mach_port_t = kIOMasterPortDefault -#endif - #if !HAVE_MACOS_12_FEATURES && HAVE_MACOS_11_FEATURES @available(macOS 11.0, *) extension CGColorSpace { diff --git a/video/out/mac/common.swift b/video/out/mac/common.swift index 5af87e15cb..9b123b9cdd 100644 --- a/video/out/mac/common.swift +++ b/video/out/mac/common.swift @@ -281,13 +281,16 @@ class Common: NSObject { } func initLightSensor() { - let srv = IOServiceGetMatchingService(kIOMainPortDefault, IOServiceMatching("AppleLMUController")) + let mainPort: mach_port_t + if #available(macOS 12.0, *) { mainPort = kIOMainPortDefault } else { mainPort = kIOMasterPortDefault } + + let srv = IOServiceGetMatchingService(mainPort, IOServiceMatching("AppleLMUController")) if srv == IO_OBJECT_NULL { log.verbose("Can't find an ambient light sensor") return } - lightSensorIOPort = IONotificationPortCreate(kIOMainPortDefault) + lightSensorIOPort = IONotificationPortCreate(mainPort) IONotificationPortSetDispatchQueue(lightSensorIOPort, queue) var n = io_object_t() IOServiceAddInterestNotification(lightSensorIOPort, srv, kIOGeneralInterest, lightSensorCallback,