Skip to content

Commit

Permalink
mac/compat: fix compatibility for deployment targets lower than SDK ver
Browse files Browse the repository at this point in the history
the swift parts can't be nicely encapsulated in the compat file because
it lags proper target version compile time checks.

Fixes #15292
  • Loading branch information
Akemi committed Nov 18, 2024
1 parent 46574d4 commit 45c1c58
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
7 changes: 6 additions & 1 deletion osdep/mac/compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,17 @@

#pragma once

#include <AvailabilityMacros.h>
#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
4 changes: 0 additions & 4 deletions osdep/mac/swift_compat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 5 additions & 2 deletions video/out/mac/common.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 45c1c58

Please sign in to comment.