From 204e3f0df63d9e9ad93d8ece0b6dcfa4c5246fa7 Mon Sep 17 00:00:00 2001 From: der richter Date: Tue, 19 Mar 2024 23:15:42 +0100 Subject: mac/option: rename option structs to properly represent their content also optimise option cache setup. --- osdep/mac/application.m | 4 ++-- osdep/mac/application_objc.h | 4 ++-- osdep/mac/input_helper.swift | 6 +++--- osdep/mac/option_helper.swift | 50 +++++++++++++++++++------------------------ 4 files changed, 29 insertions(+), 35 deletions(-) (limited to 'osdep/mac') diff --git a/osdep/mac/application.m b/osdep/mac/application.m index 5eef3a9fa3..32066d8ae0 100644 --- a/osdep/mac/application.m +++ b/osdep/mac/application.m @@ -181,12 +181,12 @@ static const char mac_icon[] = #endif } -+ (const struct m_sub_options *)getMacOSConf ++ (const struct m_sub_options *)getMacConf { return &macos_conf; } -+ (const struct m_sub_options *)getVoSubConf ++ (const struct m_sub_options *)getVoConf { return &vo_sub_opts; } diff --git a/osdep/mac/application_objc.h b/osdep/mac/application_objc.h index b79ce1f167..3417652949 100644 --- a/osdep/mac/application_objc.h +++ b/osdep/mac/application_objc.h @@ -28,8 +28,8 @@ struct mpv_handle; - (NSImage *)getMPVIcon; - (void)processEvent:(struct mpv_event *)event; - (void)initCocoaCb:(struct mpv_handle *)ctx; -+ (const struct m_sub_options *)getMacOSConf; -+ (const struct m_sub_options *)getVoSubConf; ++ (const struct m_sub_options *)getMacConf; ++ (const struct m_sub_options *)getVoConf; @property(nonatomic, retain) MenuBar *menuBar; @property(nonatomic, assign) size_t openCount; diff --git a/osdep/mac/input_helper.swift b/osdep/mac/input_helper.swift index 9225acc8e6..70099ce3ae 100644 --- a/osdep/mac/input_helper.swift +++ b/osdep/mac/input_helper.swift @@ -232,11 +232,11 @@ class InputHelper: NSObject { @objc func open(files: [String]) { lock.withLock { guard let input = input else { return } - if (option?.opts.drag_and_drop ?? -1) == -2 { return } + if (option?.vo.drag_and_drop ?? -1) == -2 { return } var action = NSEvent.modifierFlags.contains(.shift) ? DND_APPEND : DND_REPLACE - if (option?.opts.drag_and_drop ?? -1) >= 0 { - action = mp_dnd_action(UInt32(option?.opts.drag_and_drop ?? Int32(DND_REPLACE.rawValue))) + if (option?.vo.drag_and_drop ?? -1) >= 0 { + action = mp_dnd_action(UInt32(option?.vo.drag_and_drop ?? Int32(DND_REPLACE.rawValue))) } let filesClean = files.map{ $0.hasPrefix("file:///.file/id=") ? (URL(string: $0)?.path ?? $0) : $0 } diff --git a/osdep/mac/option_helper.swift b/osdep/mac/option_helper.swift index 943651967d..0763a04315 100644 --- a/osdep/mac/option_helper.swift +++ b/osdep/mac/option_helper.swift @@ -20,61 +20,55 @@ import Cocoa typealias swift_wakeup_cb_fn = (@convention(c) (UnsafeMutableRawPointer?) -> Void)? class OptionHelper: NSObject { - var optsCachePtr: UnsafeMutablePointer - var macOptsCachePtr: UnsafeMutablePointer + var voCachePtr: UnsafeMutablePointer + var macCachePtr: UnsafeMutablePointer - var optsPtr: UnsafeMutablePointer - { get { return UnsafeMutablePointer(OpaquePointer(optsCachePtr.pointee.opts)) } } - var macOptsPtr: UnsafeMutablePointer - { get { return UnsafeMutablePointer(OpaquePointer(macOptsCachePtr.pointee.opts)) } } + var voPtr: UnsafeMutablePointer + { get { return UnsafeMutablePointer(OpaquePointer(voCachePtr.pointee.opts)) } } + var macPtr: UnsafeMutablePointer + { get { return UnsafeMutablePointer(OpaquePointer(macCachePtr.pointee.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 opts: mp_vo_opts { get { return optsPtr.pointee } } - var macOpts: macos_opts { get { return macOptsPtr.pointee } } + var vo: mp_vo_opts { get { return voPtr.pointee } } + var mac: macos_opts { get { return macPtr.pointee } } init(_ taParent: UnsafeMutableRawPointer, _ global: OpaquePointer?) { - guard let cache = m_config_cache_alloc(taParent, global, Application.getVoSubConf()), - let macCache = m_config_cache_alloc(taParent, global, Application.getMacOSConf()) else - { - // will never be hit, mp_get_config_group asserts for invalid groups - exit(1) - } - optsCachePtr = cache - macOptsCachePtr = macCache + voCachePtr = m_config_cache_alloc(taParent, global, Application.getVoConf()) + macCachePtr = m_config_cache_alloc(taParent, global, Application.getMacConf()) } func nextChangedOption(property: inout UnsafeMutableRawPointer?) -> Bool { - return m_config_cache_get_next_changed(optsCachePtr, &property) + return m_config_cache_get_next_changed(voCachePtr, &property) } func setOption(fullscreen: Bool) { - optsPtr.pointee.fullscreen = fullscreen - _ = withUnsafeMutableBytes(of: &optsPtr.pointee.fullscreen) { (ptr: UnsafeMutableRawBufferPointer) in - m_config_cache_write_opt(optsCachePtr, ptr.baseAddress) + voPtr.pointee.fullscreen = fullscreen + _ = withUnsafeMutableBytes(of: &voPtr.pointee.fullscreen) { (ptr: UnsafeMutableRawBufferPointer) in + m_config_cache_write_opt(voCachePtr, ptr.baseAddress) } } func setOption(minimized: Bool) { - optsPtr.pointee.window_minimized = minimized - _ = withUnsafeMutableBytes(of: &optsPtr.pointee.window_minimized) { (ptr: UnsafeMutableRawBufferPointer) in - m_config_cache_write_opt(optsCachePtr, ptr.baseAddress) + voPtr.pointee.window_minimized = minimized + _ = withUnsafeMutableBytes(of: &voPtr.pointee.window_minimized) { (ptr: UnsafeMutableRawBufferPointer) in + m_config_cache_write_opt(voCachePtr, ptr.baseAddress) } } func setOption(maximized: Bool) { - optsPtr.pointee.window_maximized = maximized - _ = withUnsafeMutableBytes(of: &optsPtr.pointee.window_maximized) { (ptr: UnsafeMutableRawBufferPointer) in - m_config_cache_write_opt(optsCachePtr, ptr.baseAddress) + voPtr.pointee.window_maximized = maximized + _ = withUnsafeMutableBytes(of: &voPtr.pointee.window_maximized) { (ptr: UnsafeMutableRawBufferPointer) in + m_config_cache_write_opt(voCachePtr, ptr.baseAddress) } } func setMacOptionCallback(_ callback: swift_wakeup_cb_fn, context object: AnyObject) { - m_config_cache_set_wakeup_cb(macOptsCachePtr, callback, TypeHelper.bridge(obj: object)) + m_config_cache_set_wakeup_cb(macCachePtr, callback, TypeHelper.bridge(obj: object)) } func nextChangedMacOption(property: inout UnsafeMutableRawPointer?) -> Bool { - return m_config_cache_get_next_changed(macOptsCachePtr, &property) + return m_config_cache_get_next_changed(macCachePtr, &property) } } -- cgit v1.2.3