mirror of
https://github.com/mpv-player/mpv.git
synced 2025-12-26 21:00:21 +00:00
cocoa-cb: add support for VOCTRL_GET_DISPLAY_NAMES
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<UnsafeMutablePointer<Int8>?>?.self)
|
||||
var array: UnsafeMutablePointer<UnsafeMutablePointer<Int8>?>? = 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)
|
||||
|
||||
@@ -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" ),
|
||||
|
||||
Reference in New Issue
Block a user