From 6ce570359aa06469d3ead822227058ec87c86b30 Mon Sep 17 00:00:00 2001 From: Akemi Date: Wed, 26 Sep 2018 15:33:34 +0200 Subject: cocoa-cb: add support for VOCTRL_GET_DISPLAY_NAMES --- DOCS/man/input.rst | 4 +++- osdep/macOS_swift_bridge.h | 8 ++++++++ osdep/macOS_swift_extensions.swift | 30 ++++++++++++++++++++++++++++++ video/out/cocoa_cb_common.swift | 14 ++++++++++++++ wscript_build.py | 1 + 5 files changed, 56 insertions(+), 1 deletion(-) diff --git a/DOCS/man/input.rst b/DOCS/man/input.rst index 2fcf6857e7..f55eea1409 100644 --- a/DOCS/man/input.rst +++ b/DOCS/man/input.rst @@ -1630,7 +1630,9 @@ Property list are the xrandr names (LVDS1, HDMI1, DP1, VGA1, etc.). On Windows, these 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.) + 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. ``display-fps`` (RW) The refresh rate of the current display. Currently, this is the lowest FPS diff --git a/osdep/macOS_swift_bridge.h b/osdep/macOS_swift_bridge.h index 4204b514d1..f0b549ca40 100644 --- a/osdep/macOS_swift_bridge.h +++ b/osdep/macOS_swift_bridge.h @@ -49,3 +49,11 @@ static int SWIFT_KEY_MOUSE_LEAVE = MP_KEY_MOUSE_LEAVE; static int SWIFT_KEY_MOUSE_ENTER = MP_KEY_MOUSE_ENTER; static int SWIFT_KEY_STATE_DOWN = MP_KEY_STATE_DOWN; static int SWIFT_KEY_STATE_UP = MP_KEY_STATE_UP; + +// only used from Swift files and therefore seen as unused by the c compiler +static void SWIFT_TARRAY_STRING_APPEND(void *t, char ***a, int *i, char *s) __attribute__ ((unused)); + +static void SWIFT_TARRAY_STRING_APPEND(void *t, char ***a, int *i, char *s) +{ + MP_TARRAY_APPEND(t, *a, *i, s); +} diff --git a/osdep/macOS_swift_extensions.swift b/osdep/macOS_swift_extensions.swift index 61e61aaffd..14d217f589 100644 --- a/osdep/macOS_swift_extensions.swift +++ b/osdep/macOS_swift_extensions.swift @@ -25,4 +25,34 @@ extension NSScreen { } } + 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) + let info = IODisplayCreateInfoDictionary(object, IOOptionBits(kIODisplayOnlyPreferredName)).takeRetainedValue() as! [String:AnyObject] + if (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 + } + } } diff --git a/video/out/cocoa_cb_common.swift b/video/out/cocoa_cb_common.swift index 41a571d1d0..ae79144d97 100644 --- a/video/out/cocoa_cb_common.swift +++ b/video/out/cocoa_cb_common.swift @@ -420,6 +420,20 @@ class CocoaCB: NSObject { let minimized = data!.assumingMemoryBound(to: Int32.self) minimized.pointee = ccb.window.isMiniaturized ? VO_WIN_STATE_MINIMIZED : Int32(0) return VO_TRUE + case VOCTRL_GET_DISPLAY_NAMES: + let opts: mp_vo_opts = vo!.pointee.opts!.pointee + let dnames = data!.assumingMemoryBound(to: UnsafeMutablePointer?>?.self) + var array: UnsafeMutablePointer?>? = nil + var count: Int32 = 0 + let screen = ccb.window != nil ? ccb.window.screen : + ccb.getScreenBy(id: Int(opts.screen_id)) ?? + NSScreen.main() + let displayName = screen?.displayName ?? "Unknown" + + SWIFT_TARRAY_STRING_APPEND(nil, &array, &count, ta_xstrdup(nil, displayName)) + SWIFT_TARRAY_STRING_APPEND(nil, &array, &count, nil) + dnames.pointee = array + return VO_TRUE case VOCTRL_UPDATE_WINDOW_TITLE: let titleData = data!.assumingMemoryBound(to: Int8.self) let title = String(cString: titleData) diff --git a/wscript_build.py b/wscript_build.py index 9c372a1115..db4be186b0 100644 --- a/wscript_build.py +++ b/wscript_build.py @@ -164,6 +164,7 @@ def build(ctx): if ctx.dependency_satisfied('macos-cocoa-cb'): swift_source = [ ( "osdep/macOS_mpv_helper.swift" ), + ( "osdep/macOS_swift_extensions.swift" ), ( "video/out/cocoa-cb/events_view.swift" ), ( "video/out/cocoa-cb/video_layer.swift" ), ( "video/out/cocoa-cb/window.swift" ), -- cgit v1.2.3