diff options
author | der richter <der.richter@gmx.de> | 2020-07-31 10:37:02 +0200 |
---|---|---|
committer | der richter <der.richter@gmx.de> | 2020-08-22 14:22:49 +0200 |
commit | 5fb0f36937cc38b9db88dc9b8631cba75536c5be (patch) | |
tree | 00c7792bf3f0ef93ff142ec419bc20a64e177424 /video | |
parent | 9035a51b133dbf288818a871f040413d80c2d3b0 (diff) | |
download | mpv-5fb0f36937cc38b9db88dc9b8631cba75536c5be.tar.bz2 mpv-5fb0f36937cc38b9db88dc9b8631cba75536c5be.tar.xz |
mac: use config cache und wakeup for mac option runtime changes
remove the libmpv observer for the macOS specific options and use a
config cache + change callback for runtime changes. this is also a
preparation for new backends and generalises even more, since libmpv
functions can't and shouldn't be used in usual vo backends. for feature
parity the config cache is used.
Diffstat (limited to 'video')
-rw-r--r-- | video/out/cocoa_cb_common.swift | 33 | ||||
-rw-r--r-- | video/out/mac/common.swift | 41 | ||||
-rw-r--r-- | video/out/mac/window.swift | 16 |
3 files changed, 48 insertions, 42 deletions
diff --git a/video/out/cocoa_cb_common.swift b/video/out/cocoa_cb_common.swift index 10e3c30cc1..fb868e5c1f 100644 --- a/video/out/cocoa_cb_common.swift +++ b/video/out/cocoa_cb_common.swift @@ -36,11 +36,6 @@ class CocoaCB: Common { libmpv = LibmpvHelper(mpvHandle, newlog) super.init(newlog) layer = GLLayer(cocoaCB: self) - - libmpv.observeString("macos-title-bar-style") - libmpv.observeString("macos-title-bar-appearance") - libmpv.observeString("macos-title-bar-material") - libmpv.observeString("macos-title-bar-color") } func preinit(_ vo: UnsafeMutablePointer<vo>) { @@ -238,34 +233,6 @@ class CocoaCB: Common { switch event.pointee.event_id { case MPV_EVENT_SHUTDOWN: shutdown() - case MPV_EVENT_PROPERTY_CHANGE: - if backendState == .initialized { - handlePropertyChange(event) - } - default: - break - } - } - - func handlePropertyChange(_ event: UnsafePointer<mpv_event>) { - let pData = OpaquePointer(event.pointee.data) - guard let property = UnsafePointer<mpv_event_property>(pData)?.pointee else { - return - } - - switch String(cString: property.name) { - case "macos-title-bar-appearance": - if let data = LibmpvHelper.mpvStringArrayToString(property.data) { - titleBar?.set(appearance: data) - } - case "macos-title-bar-material": - if let data = LibmpvHelper.mpvStringArrayToString(property.data) { - titleBar?.set(material: data) - } - case "macos-title-bar-color": - if let data = LibmpvHelper.mpvStringArrayToString(property.data) { - titleBar?.set(color: data) - } default: break } diff --git a/video/out/mac/common.swift b/video/out/mac/common.swift index c5b99bc0fd..28898c2840 100644 --- a/video/out/mac/common.swift +++ b/video/out/mac/common.swift @@ -49,9 +49,15 @@ class Common: NSObject { } func initMisc(_ vo: UnsafeMutablePointer<vo>) { + guard let mpv = mpv else { + log.sendError("Something went wrong, no MPVHelper was initialized") + exit(1) + } + startDisplayLink(vo) initLightSensor() addDisplayReconfigureObserver() + mpv.setMacOptionCallback(macOptsWakeupCallback, context: self) } func initApp() { @@ -438,7 +444,7 @@ class Common: NSObject { return VO_TRUE case VOCTRL_VO_OPTS_CHANGED: var o: UnsafeMutableRawPointer? - while mpv.nextChangedConfig(property: &o) { + while mpv.nextChangedOption(property: &o) { guard let opt = o else { log.sendError("No changed options was retrieved") return VO_TRUE @@ -546,4 +552,37 @@ class Common: NSObject { return VO_NOTIMPL } } + + let macOptsWakeupCallback: swift_wakeup_cb_fn = { ( ctx ) in + let com = unsafeBitCast(ctx, to: Common.self) + DispatchQueue.main.async { + com.macOptsUpdate() + } + } + + func macOptsUpdate() { + guard let mpv = mpv else { + log.sendWarning("Unexpected nil value in mac opts update") + return + } + + var o: UnsafeMutableRawPointer? + while mpv.nextChangedMacOption(property: &o) { + guard let opt = o else { + log.sendWarning("Could not retrieve changed mac option") + return + } + + switch opt { + case UnsafeMutableRawPointer(&mpv.macOptsPtr.pointee.macos_title_bar_appearance): + titleBar?.set(appearance: Int(mpv.macOpts.macos_title_bar_appearance)) + case UnsafeMutableRawPointer(&mpv.macOptsPtr.pointee.macos_title_bar_material): + titleBar?.set(material: Int(mpv.macOpts.macos_title_bar_material)) + case UnsafeMutableRawPointer(&mpv.macOptsPtr.pointee.macos_title_bar_color): + titleBar?.set(color: mpv.macOpts.macos_title_bar_color) + default: + break + } + } + } } diff --git a/video/out/mac/window.swift b/video/out/mac/window.swift index 8ba9031101..5b7e77dcff 100644 --- a/video/out/mac/window.swift +++ b/video/out/mac/window.swift @@ -183,7 +183,7 @@ class Window: NSWindow, NSWindowDelegate { func windowDidEnterFullScreen(_ notification: Notification) { isInFullscreen = true - mpv?.setConfigProperty(fullscreen: isInFullscreen) + mpv?.setOption(fullscreen: isInFullscreen) common.updateCursorVisibility() endAnimation(frame) common.titleBar?.show() @@ -192,7 +192,7 @@ class Window: NSWindow, NSWindowDelegate { func windowDidExitFullScreen(_ notification: Notification) { guard let tScreen = targetScreen else { return } isInFullscreen = false - mpv?.setConfigProperty(fullscreen: isInFullscreen) + mpv?.setOption(fullscreen: isInFullscreen) endAnimation(calculateWindowPosition(for: tScreen, withoutBounds: targetScreen == screen)) common.view?.layerContentsPlacement = .scaleProportionallyToFit } @@ -230,7 +230,7 @@ class Window: NSWindow, NSWindowDelegate { setFrame(targetFrame, display: true) endAnimation() isInFullscreen = true - mpv?.setConfigProperty(fullscreen: isInFullscreen) + mpv?.setOption(fullscreen: isInFullscreen) common.windowSetToFullScreen() } @@ -242,7 +242,7 @@ class Window: NSWindow, NSWindowDelegate { styleMask.remove(.fullScreen) endAnimation() isInFullscreen = false - mpv?.setConfigProperty(fullscreen: isInFullscreen) + mpv?.setOption(fullscreen: isInFullscreen) common.windowSetToWindow() } @@ -496,7 +496,7 @@ class Window: NSWindow, NSWindowDelegate { func windowDidEndLiveResize(_ notification: Notification) { common.windowDidEndLiveResize() - mpv?.setConfigProperty(maximized: isZoomed) + mpv?.setOption(maximized: isZoomed) if let contentViewFrame = contentView?.frame, !isAnimating && !isInFullscreen @@ -515,11 +515,11 @@ class Window: NSWindow, NSWindowDelegate { } func windowDidMiniaturize(_ notification: Notification) { - mpv?.setConfigProperty(minimized: true) + mpv?.setOption(minimized: true) } func windowDidDeminiaturize(_ notification: Notification) { - mpv?.setConfigProperty(minimized: false) + mpv?.setOption(minimized: false) } func windowDidResignKey(_ notification: Notification) { @@ -542,6 +542,6 @@ class Window: NSWindow, NSWindowDelegate { } func windowDidMove(_ notification: Notification) { - mpv?.setConfigProperty(maximized: isZoomed) + mpv?.setOption(maximized: isZoomed) } } |