mirror of
https://github.com/mpv-player/mpv
synced 2025-01-11 17:39:38 +00:00
cocoa-cb: use Swift Extensions for convenience
preparations for the following commit.
This commit is contained in:
parent
f2e7e81bda
commit
ace61c120f
28
osdep/macOS_swift_extensions.swift
Normal file
28
osdep/macOS_swift_extensions.swift
Normal file
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user