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
This commit is contained in:
der richter 2023-11-08 01:26:29 +01:00
parent 040a921964
commit a54cc02341
3 changed files with 4 additions and 33 deletions

View File

@ -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.

View File

@ -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 {

View File

@ -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<UnsafeMutablePointer<Int8>?>?.self)
var array: UnsafeMutablePointer<UnsafeMutablePointer<Int8>?>? = 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)