diff options
author | der richter <der.richter@gmx.de> | 2019-11-30 23:47:52 +0100 |
---|---|---|
committer | der richter <der.richter@gmx.de> | 2019-12-15 20:07:11 +0100 |
commit | c8cc203735d73f62def2692d1027f45ac10c03db (patch) | |
tree | 021ddf9157de39ea066f727f7bc298eb2915531b /osdep/macos/mpv_helper.swift | |
parent | e5676a67eef087aba1ccc0ab707cc5f96cc09470 (diff) | |
download | mpv-c8cc203735d73f62def2692d1027f45ac10c03db.tar.bz2 mpv-c8cc203735d73f62def2692d1027f45ac10c03db.tar.xz |
cocoa-cb: use m_config_cache and new VOCTRL for option handling
this removes the direct access of the mp_vo_opts stuct via the vo struct
and replaces it with the m_config_cache usage. this updates the
fullscreen and window-minimized property via m_config_cache_write_opt
instead of the old mechanism via VOCTRL and event flagging. also use the
new VOCTRL_VO_OPTS_CHANGED event for fullscreen and border changes.
Diffstat (limited to 'osdep/macos/mpv_helper.swift')
-rw-r--r-- | osdep/macos/mpv_helper.swift | 41 |
1 files changed, 36 insertions, 5 deletions
diff --git a/osdep/macos/mpv_helper.swift b/osdep/macos/mpv_helper.swift index ce1fb5ffec..5e97470a09 100644 --- a/osdep/macos/mpv_helper.swift +++ b/osdep/macos/mpv_helper.swift @@ -20,24 +20,41 @@ import Cocoa class MPVHelper: LogHelper { var vo: UnsafeMutablePointer<vo> + var optsCachePtr: UnsafeMutablePointer<m_config_cache> + var optsPtr: UnsafeMutablePointer<mp_vo_opts> + + // these computed properties return a local copy of the struct accessed: + // - don't use if you rely on the pointers + // - only for reading var vout: vo { get { return vo.pointee } } - var opts: mp_vo_opts { get { return vout.opts.pointee } } + var optsCache: m_config_cache { get { return optsCachePtr.pointee } } + var opts: mp_vo_opts { get { return optsPtr.pointee } } + var input: OpaquePointer { get { return vout.input_ctx } } var macOpts: macos_opts = macos_opts() init(_ vo: UnsafeMutablePointer<vo>, _ name: String) { self.vo = vo + + guard let app = NSApp as? Application, + let cache = m_config_cache_alloc(vo, vo.pointee.global, app.getVoSubConf()) else + { + print("NSApp couldn't be retrieved") + exit(1) + } + let newlog = mp_log_new(vo, vo.pointee.log, name) + optsCachePtr = cache + optsPtr = UnsafeMutablePointer<mp_vo_opts>(OpaquePointer(cache.pointee.opts)) super.init(newlog) - guard let app = NSApp as? Application, - let ptr = mp_get_config_group(vo, + guard let ptr = mp_get_config_group(vo, vo.pointee.global, app.getMacOSConf()) else { - sendError("macOS config group couldn't be retrieved'") - exit(1) + // will never be hit, mp_get_config_group asserts for invalid groups + return } macOpts = UnsafeMutablePointer<macos_opts>(OpaquePointer(ptr)).pointee } @@ -59,6 +76,20 @@ class MPVHelper: LogHelper { mp_input_put_wheel(input, mpkey, delta) } + func nextChangedConfig(property: inout UnsafeMutableRawPointer?) -> Bool { + return m_config_cache_get_next_changed(optsCachePtr, &property) + } + + func setConfigProperty(fullscreen: Bool) { + optsPtr.pointee.fullscreen = Int32(fullscreen) + m_config_cache_write_opt(optsCachePtr, UnsafeMutableRawPointer(&optsPtr.pointee.fullscreen)) + } + + func setConfigProperty(minimized: Bool) { + optsPtr.pointee.window_minimized = Int32(minimized) + m_config_cache_write_opt(optsCachePtr, UnsafeMutableRawPointer(&optsPtr.pointee.window_minimized)) + } + func command(_ cmd: String) { let cCmd = UnsafePointer<Int8>(strdup(cmd)) let mpvCmd = mp_input_parse_cmd(input, bstr0(cCmd), "") |