diff options
Diffstat (limited to 'osdep/mac')
-rw-r--r-- | osdep/mac/app_bridge.h | 20 | ||||
-rw-r--r-- | osdep/mac/app_bridge.m | 21 | ||||
-rw-r--r-- | osdep/mac/app_hub.swift | 2 | ||||
-rw-r--r-- | osdep/mac/event_helper.swift | 2 | ||||
-rw-r--r-- | osdep/mac/log_helper.swift | 13 | ||||
-rw-r--r-- | osdep/mac/menu_bar.swift | 4 | ||||
-rw-r--r-- | osdep/mac/meson.build | 12 | ||||
-rw-r--r-- | osdep/mac/swift_compat.swift | 18 |
8 files changed, 86 insertions, 6 deletions
diff --git a/osdep/mac/app_bridge.h b/osdep/mac/app_bridge.h index db03c8ebad..94ba745b3a 100644 --- a/osdep/mac/app_bridge.h +++ b/osdep/mac/app_bridge.h @@ -35,6 +35,24 @@ enum { RENDER_TIMER_PRECISE, }; +enum { + MAC_CSP_AUTO = -1, + MAC_CSP_DISPLAY_P3, + MAC_CSP_DISPLAY_P3_HLG, + MAC_CSP_DISPLAY_P3_PQ, + MAC_CSP_DISPLAY_P3_LINEAR, + MAC_CSP_DCI_P3, + MAC_CSP_BT_2020, + MAC_CSP_BT_2020_LINEAR, + MAC_CSP_BT_2100_HLG, + MAC_CSP_BT_2100_PQ, + MAC_CSP_BT_709, + MAC_CSP_SRGB, + MAC_CSP_SRGB_LINEAR, + MAC_CSP_RGB_LINEAR, + MAC_CSP_ADOBE, +}; + struct macos_opts { int macos_title_bar_appearance; int macos_title_bar_material; @@ -44,8 +62,10 @@ struct macos_opts { int macos_app_activation_policy; int macos_geometry_calculation; int macos_render_timer; + bool macos_menu_shortcuts; int cocoa_cb_sw_renderer; bool cocoa_cb_10bit_context; + int cocoa_cb_output_csp; }; void cocoa_init_media_keys(void); diff --git a/osdep/mac/app_bridge.m b/osdep/mac/app_bridge.m index bf39efe603..bea1ecae3e 100644 --- a/osdep/mac/app_bridge.m +++ b/osdep/mac/app_bridge.m @@ -52,9 +52,26 @@ const struct m_sub_options macos_conf = { {"macos-render-timer", OPT_CHOICE(macos_render_timer, {"callback", RENDER_TIMER_CALLBACK}, {"precise", RENDER_TIMER_PRECISE}, {"system", RENDER_TIMER_SYSTEM}, {"feedback", RENDER_TIMER_PRESENTATION_FEEDBACK})}, + {"macos-menu-shortcuts", OPT_BOOL(macos_menu_shortcuts)}, {"cocoa-cb-sw-renderer", OPT_CHOICE(cocoa_cb_sw_renderer, {"auto", -1}, {"no", 0}, {"yes", 1})}, {"cocoa-cb-10bit-context", OPT_BOOL(cocoa_cb_10bit_context)}, + {"cocoa-cb-output-csp", OPT_CHOICE(cocoa_cb_output_csp, + {"auto", MAC_CSP_AUTO}, + {"display-p3", MAC_CSP_DISPLAY_P3}, + {"display-p3-hlg", MAC_CSP_DISPLAY_P3_HLG}, + {"display-p3-pq", MAC_CSP_DISPLAY_P3_PQ}, + {"display-p3-linear", MAC_CSP_DISPLAY_P3_LINEAR}, + {"dci-p3", MAC_CSP_DCI_P3}, + {"bt.2020", MAC_CSP_BT_2020}, + {"bt.2020-linear", MAC_CSP_BT_2020_LINEAR}, + {"bt.2100-hlg", MAC_CSP_BT_2100_HLG}, + {"bt.2100-pq", MAC_CSP_BT_2100_PQ}, + {"bt.709", MAC_CSP_BT_709}, + {"srgb", MAC_CSP_SRGB}, + {"srgb-linear", MAC_CSP_SRGB_LINEAR}, + {"rgb-linear", MAC_CSP_RGB_LINEAR}, + {"adobe", MAC_CSP_ADOBE})}, {0} }, .size = sizeof(struct macos_opts), @@ -62,8 +79,10 @@ const struct m_sub_options macos_conf = { .macos_title_bar_color = {0, 0, 0, 0}, .macos_fs_animation_duration = -1, .macos_render_timer = RENDER_TIMER_CALLBACK, + .macos_menu_shortcuts = true, .cocoa_cb_sw_renderer = -1, - .cocoa_cb_10bit_context = true + .cocoa_cb_10bit_context = true, + .cocoa_cb_output_csp = MAC_CSP_AUTO, }, }; diff --git a/osdep/mac/app_hub.swift b/osdep/mac/app_hub.swift index 81390744dc..fd917bc80f 100644 --- a/osdep/mac/app_hub.swift +++ b/osdep/mac/app_hub.swift @@ -44,7 +44,6 @@ class AppHub: NSObject { input = InputHelper() log = LogHelper() super.init() - if isApplication { menu = MenuBar(self) } #if HAVE_MACOS_MEDIA_PLAYER remote = RemoteCommandCenter(self) #endif @@ -58,6 +57,7 @@ class AppHub: NSObject { log.log = mp_log_new(nil, mp_client_get_log(mpv), "app") option = OptionHelper(UnsafeMutablePointer(mpv), mp_client_get_global(mpv)) input.option = option + DispatchQueue.main.sync { menu = MenuBar(self) } } #if HAVE_MACOS_MEDIA_PLAYER diff --git a/osdep/mac/event_helper.swift b/osdep/mac/event_helper.swift index 0f194ce8aa..6331a64a9f 100644 --- a/osdep/mac/event_helper.swift +++ b/osdep/mac/event_helper.swift @@ -75,7 +75,7 @@ class EventHelper { mpv_set_wakeup_callback(mpv, wakeup, TypeHelper.bridge(obj: self)) } - func subscribe(_ subscriber: any EventSubscriber, event: Event) { + func subscribe(_ subscriber: EventSubscriber, event: Event) { guard let mpv = mpv else { return } if !event.name.isEmpty { diff --git a/osdep/mac/log_helper.swift b/osdep/mac/log_helper.swift index 690d7bcbc1..b3464fd1bd 100644 --- a/osdep/mac/log_helper.swift +++ b/osdep/mac/log_helper.swift @@ -20,7 +20,12 @@ import os class LogHelper { var log: OpaquePointer? - let logger = Logger(subsystem: "io.mpv", category: "mpv") +#if HAVE_MACOS_11_FEATURES + @available(macOS 11.0, *) + var logger: Logger? { + return Logger(subsystem: "io.mpv", category: "mpv") + } +#endif let loggerMapping: [Int: OSLogType] = [ MSGL_V: .debug, @@ -51,7 +56,11 @@ class LogHelper { func send(message: String, type: Int) { guard let log = log else { - logger.log(level: loggerMapping[type] ?? .default, "\(message, privacy: .public)") +#if HAVE_MACOS_11_FEATURES + if #available(macOS 11.0, *) { + logger?.log(level: loggerMapping[type] ?? .default, "\(message, privacy: .public)") + } +#endif return } diff --git a/osdep/mac/menu_bar.swift b/osdep/mac/menu_bar.swift index 4abbd912e1..a43f55f1ea 100644 --- a/osdep/mac/menu_bar.swift +++ b/osdep/mac/menu_bar.swift @@ -71,6 +71,7 @@ extension MenuBar { class MenuBar: NSObject { unowned let appHub: AppHub + var option: OptionHelper? { return appHub.option } let mainMenu = NSMenu(title: "Main") let servicesMenu = NSMenu(title: "Services") var menuConfigs: [Config] = [] @@ -272,7 +273,8 @@ class MenuBar: NSObject { } func createMenuItem(parentMenu: NSMenu, config: Config) -> MenuItem { - var item = MenuItem(title: config.name, action: config.action, keyEquivalent: config.key) + var item = MenuItem(title: config.name, action: config.action, + keyEquivalent: (option?.mac.macos_menu_shortcuts ?? true) ? config.key : "") item.config = config item.target = config.target item.keyEquivalentModifierMask = config.modifiers diff --git a/osdep/mac/meson.build b/osdep/mac/meson.build index 8ddbdbaddf..9116d81476 100644 --- a/osdep/mac/meson.build +++ b/osdep/mac/meson.build @@ -19,6 +19,18 @@ if get_option('optimization') != '0' swift_flags += '-O' endif +if macos_10_15_4_features.allowed() + swift_flags += ['-D', 'HAVE_MACOS_10_15_4_FEATURES'] +endif + +if macos_11_features.allowed() + swift_flags += ['-D', 'HAVE_MACOS_11_FEATURES'] +endif + +if macos_12_features.allowed() + swift_flags += ['-D', 'HAVE_MACOS_12_FEATURES'] +endif + if macos_cocoa_cb.allowed() swift_flags += ['-D', 'HAVE_MACOS_COCOA_CB'] endif diff --git a/osdep/mac/swift_compat.swift b/osdep/mac/swift_compat.swift index 6924d5cfca..24365cdd4a 100644 --- a/osdep/mac/swift_compat.swift +++ b/osdep/mac/swift_compat.swift @@ -15,6 +15,16 @@ * License along with mpv. If not, see <http://www.gnu.org/licenses/>. */ +#if !swift(>=5.7) +extension NSCondition { + func withLock<R>(_ body: () throws -> R) rethrows -> R { + self.lock() + defer { self.unlock() } + return try body() + } +} +#endif + #if !swift(>=5.0) extension Data { mutating func withUnsafeMutableBytes<Type>(_ body: (UnsafeMutableRawBufferPointer) throws -> Type) rethrows -> Type { @@ -33,3 +43,11 @@ extension NSDraggingInfo { } } #endif + +#if !HAVE_MACOS_12_FEATURES && HAVE_MACOS_11_FEATURES +@available(macOS 11.0, *) +extension CGColorSpace { + static let itur_2100_HLG: CFString = kCGColorSpaceITUR_2100_HLG + static let itur_2100_PQ: CFString = kCGColorSpaceITUR_2100_PQ +} +#endif |