summaryrefslogtreecommitdiffstats
path: root/osdep
diff options
context:
space:
mode:
authorAkemi <der.richter@gmx.de>2018-09-26 15:33:34 +0200
committerJan Ekström <jeebjp@gmail.com>2019-02-10 22:39:25 +0200
commit6ce570359aa06469d3ead822227058ec87c86b30 (patch)
tree42226a3ef2492da2472344859db6c45ebb10b794 /osdep
parentace61c120f18733f3cfc88273fdbad6fb1db5bc6 (diff)
downloadmpv-6ce570359aa06469d3ead822227058ec87c86b30.tar.bz2
mpv-6ce570359aa06469d3ead822227058ec87c86b30.tar.xz
cocoa-cb: add support for VOCTRL_GET_DISPLAY_NAMES
Diffstat (limited to 'osdep')
-rw-r--r--osdep/macOS_swift_bridge.h8
-rw-r--r--osdep/macOS_swift_extensions.swift30
2 files changed, 38 insertions, 0 deletions
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
+ }
+ }
}