summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--osdep/macOS_swift_extensions.swift28
-rw-r--r--video/out/cocoa_cb_common.swift11
2 files changed, 32 insertions, 7 deletions
diff --git a/osdep/macOS_swift_extensions.swift b/osdep/macOS_swift_extensions.swift
new file mode 100644
index 0000000000..61e61aaffd
--- /dev/null
+++ b/osdep/macOS_swift_extensions.swift
@@ -0,0 +1,28 @@
+/*
+ * This file is part of mpv.
+ *
+ * mpv is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * mpv is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with mpv. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+import Cocoa
+
+extension NSScreen {
+
+ public var displayID: CGDirectDisplayID {
+ get {
+ return deviceDescription["NSScreenNumber"] as! CGDirectDisplayID
+ }
+ }
+
+}
diff --git a/video/out/cocoa_cb_common.swift b/video/out/cocoa_cb_common.swift
index 355fa537e1..41a571d1d0 100644
--- a/video/out/cocoa_cb_common.swift
+++ b/video/out/cocoa_cb_common.swift
@@ -148,10 +148,9 @@ class CocoaCB: NSObject {
func startDisplayLink(_ vo: UnsafeMutablePointer<vo>) {
let opts: mp_vo_opts = vo.pointee.opts.pointee
let screen = getScreenBy(id: Int(opts.screen_id)) ?? NSScreen.main()
- let displayId = screen!.deviceDescription["NSScreenNumber"] as! UInt32
CVDisplayLinkCreateWithActiveCGDisplays(&link)
- CVDisplayLinkSetCurrentCGDisplay(link!, displayId)
+ CVDisplayLinkSetCurrentCGDisplay(link!, screen!.displayID)
if #available(macOS 10.12, *) {
CVDisplayLinkSetOutputHandler(link!) { link, now, out, inFlags, outFlags -> CVReturn in
self.mpv.reportRenderFlip()
@@ -170,8 +169,7 @@ class CocoaCB: NSObject {
}
func updateDisplaylink() {
- let displayId = UInt32(window.screen!.deviceDescription["NSScreenNumber"] as! Int)
- CVDisplayLinkSetCurrentCGDisplay(link!, displayId)
+ CVDisplayLinkSetCurrentCGDisplay(link!, window.screen!.displayID)
queue.asyncAfter(deadline: DispatchTime.now() + 0.1) {
self.flagEvents(VO_EVENT_WIN_STATE)
@@ -302,9 +300,8 @@ class CocoaCB: NSObject {
var reconfigureCallback: CGDisplayReconfigurationCallBack = { (display, flags, userInfo) in
if flags.contains(.setModeFlag) {
let ccb: CocoaCB = MPVHelper.bridge(ptr: userInfo!)
- let displayID = (ccb.window.screen!.deviceDescription["NSScreenNumber"] as! NSNumber).intValue
- if UInt32(displayID) == display {
- ccb.mpv.sendVerbose("Detected display mode change, updating screen refresh rate\n");
+ if ccb.window.screen!.displayID == display {
+ ccb.mpv.sendVerbose("Detected display mode change, updating screen refresh rate");
ccb.flagEvents(VO_EVENT_WIN_STATE)
}
}