From a54cc02341fed3e1e2408a692aa4753718ee969f Mon Sep 17 00:00:00 2001 From: der richter Date: Wed, 8 Nov 2023 01:26:29 +0100 Subject: [PATCH] mac: change display name retrieval to localizedName NSScreen property the old displayName property via the IODisplay API is not working anymore on ARM based macs and was broken in at least one other case. instead we use the new localizedName property introduced in 10.15 of the NSScreen. we don't need any backwards compatibility since 10.15 is the oldest version we support now. configs and scripts that use the options and properties fs-screen-name, screen-name or display-names need to be adjusted since the names could differ from the previous implementation via the IODisplay API. Fixes #9697 --- DOCS/interface-changes.rst | 2 ++ osdep/macos/swift_extensions.swift | 31 ------------------------------ video/out/mac/common.swift | 4 ++-- 3 files changed, 4 insertions(+), 33 deletions(-) diff --git a/DOCS/interface-changes.rst b/DOCS/interface-changes.rst index 53ff736562..bc2d33fa83 100644 --- a/DOCS/interface-changes.rst +++ b/DOCS/interface-changes.rst @@ -115,6 +115,8 @@ Interface changes - add hdr metadata to `video-params` property - remove `hdr-metadata` property - add `--target-gamut` + - change the way display names are retrieved on macOS, usage of options and properties + `--fs-screen-name`, `--screen-name` and `display-names` needs to be adjusted --- mpv 0.36.0 --- - add `--target-contrast` - Target luminance value is now also applied when ICC profile is used. diff --git a/osdep/macos/swift_extensions.swift b/osdep/macos/swift_extensions.swift index a1aeb0abf7..127c568abe 100644 --- a/osdep/macos/swift_extensions.swift +++ b/osdep/macos/swift_extensions.swift @@ -28,37 +28,6 @@ extension NSScreen { return deviceDescription[.screenNumber] as? CGDirectDisplayID ?? 0 } } - - public var displayName: String? { - get { - var name: String? = nil - var object: io_object_t - var iter = io_iterator_t() - let matching = IOServiceMatching("IODisplayConnect") - let result = IOServiceGetMatchingServices(kIOMasterPortDefault, matching, &iter) - - if result != KERN_SUCCESS || iter == 0 { return nil } - - repeat { - object = IOIteratorNext(iter) - if let info = IODisplayCreateInfoDictionary(object, IOOptionBits(kIODisplayOnlyPreferredName)).takeRetainedValue() as? [String:AnyObject], - (info[kDisplayVendorID] as? UInt32 == CGDisplayVendorNumber(displayID) && - info[kDisplayProductID] as? UInt32 == CGDisplayModelNumber(displayID) && - info[kDisplaySerialNumber] as? UInt32 ?? 0 == CGDisplaySerialNumber(displayID)) - { - if let productNames = info["DisplayProductName"] as? [String:String], - let productName = productNames.first?.value - { - name = productName - break - } - } - } while object != 0 - - IOObjectRelease(iter) - return name - } - } } extension NSColor { diff --git a/video/out/mac/common.swift b/video/out/mac/common.swift index 6da99ca20b..aac705005f 100644 --- a/video/out/mac/common.swift +++ b/video/out/mac/common.swift @@ -396,7 +396,7 @@ class Common: NSObject { func getScreenBy(name screenName: String?) -> NSScreen? { for screen in NSScreen.screens { - if screen.displayName == screenName { + if screen.localizedName == screenName { return screen } } @@ -628,7 +628,7 @@ class Common: NSObject { let dnames = data!.assumingMemoryBound(to: UnsafeMutablePointer?>?.self) var array: UnsafeMutablePointer?>? = nil var count: Int32 = 0 - let displayName = getCurrentScreen()?.displayName ?? "Unknown" + let displayName = getCurrentScreen()?.localizedName ?? "Unknown" SWIFT_TARRAY_STRING_APPEND(nil, &array, &count, ta_xstrdup(nil, displayName)) SWIFT_TARRAY_STRING_APPEND(nil, &array, &count, nil)