diff --git a/DOCS/man/input.rst b/DOCS/man/input.rst index f9fa59121d..67e545fbd1 100644 --- a/DOCS/man/input.rst +++ b/DOCS/man/input.rst @@ -2711,11 +2711,11 @@ Property list are the GDI names (\\.\DISPLAY1, \\.\DISPLAY2, etc.) and the first display in the list will be the one that Windows considers associated with the window (as determined by the MonitorFromWindow API.) On macOS these are the - Display Product Names as used in the System Information and only one display - name is returned since a window can only be on one screen. On Wayland, these - are the wl_output names if protocol version >= 4 is used - (LVDS-1, HDMI-A-1, X11-1, etc.), or the wl_output model reported by the - geometry event if protocol version < 4 is used. + Display Product Names as used in the System Information with a serial number + in brackets and only one display name is returned since a window can only be + on one screen. On Wayland, these are the wl_output names if protocol + version >= 4 is used (LVDS-1, HDMI-A-1, X11-1, etc.), or the wl_output model + reported by the geometry event if protocol version < 4 is used. ``display-fps`` The refresh rate of the current display. Currently, this is the lowest FPS diff --git a/osdep/mac/swift_extensions.swift b/osdep/mac/swift_extensions.swift index ed6c86cd2a..2bb3d4bf7c 100644 --- a/osdep/mac/swift_extensions.swift +++ b/osdep/mac/swift_extensions.swift @@ -28,6 +28,30 @@ extension NSScreen { return deviceDescription[.screenNumber] as? CGDirectDisplayID ?? 0 } } + + public var serialNumber: String { + get { + return String(CGDisplaySerialNumber(displayID)) + } + } + + public var name: String { + get { + // force unwrapping is fine here, regex is guaranteed to be valid + let regex = try! NSRegularExpression(pattern: " \\(\\d+\\)$", options: .caseInsensitive) + return regex.stringByReplacingMatches( + in: localizedName, + range: NSRange(location: 0, length: localizedName.count), + withTemplate: "" + ) + } + } + + public var uniqueName: String { + get { + return name + " (\(serialNumber))" + } + } } extension NSColor { diff --git a/video/out/mac/common.swift b/video/out/mac/common.swift index 594a4b8e8a..74ce3c1903 100644 --- a/video/out/mac/common.swift +++ b/video/out/mac/common.swift @@ -387,7 +387,7 @@ class Common: NSObject { func getScreenBy(name screenName: String?) -> NSScreen? { for screen in NSScreen.screens { - if screen.localizedName == screenName { + if [screen.localizedName, screen.name, screen.uniqueName, screen.serialNumber].contains(screenName) { return screen } } @@ -622,7 +622,7 @@ class Common: NSObject { let dnames = data!.assumingMemoryBound(to: UnsafeMutablePointer?>?.self) var array: UnsafeMutablePointer?>? = nil var count: Int32 = 0 - let displayName = getCurrentScreen()?.localizedName ?? "Unknown" + let displayName = getCurrentScreen()?.uniqueName ?? "Unknown" app_bridge_tarray_append(nil, &array, &count, ta_xstrdup(nil, displayName)) app_bridge_tarray_append(nil, &array, &count, nil)