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/out/mac/common.swift | |
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/out/mac/common.swift')
-rw-r--r-- | video/out/mac/common.swift | 41 |
1 files changed, 40 insertions, 1 deletions
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 + } + } + } } |