From 7139a14f1c174a162f75f2827cd2c2296a0916f5 Mon Sep 17 00:00:00 2001 From: der richter Date: Thu, 23 Nov 2023 17:34:55 +0100 Subject: [PATCH 1/2] mac: cleanup some unused and unneeded code --- osdep/macosx_application.h | 1 - video/out/mac/title_bar.swift | 8 +------- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/osdep/macosx_application.h b/osdep/macosx_application.h index 753b9f033fdab..646cbc9b8acfa 100644 --- a/osdep/macosx_application.h +++ b/osdep/macosx_application.h @@ -33,7 +33,6 @@ enum { }; struct macos_opts { - int macos_title_bar_style; int macos_title_bar_appearance; int macos_title_bar_material; struct m_color macos_title_bar_color; diff --git a/video/out/mac/title_bar.swift b/video/out/mac/title_bar.swift index 764c1ff5dd531..879ff9df10cfd 100644 --- a/video/out/mac/title_bar.swift +++ b/video/out/mac/title_bar.swift @@ -195,10 +195,6 @@ class TitleBar: NSVisualEffectView { default: return nil } - - - let style = UserDefaults.standard.string(forKey: "AppleInterfaceStyle") - return appearanceFrom(string: style == nil ? "aqua" : "vibrantDark") } func materialFrom(string: String) -> NSVisualEffectView.Material { @@ -221,9 +217,7 @@ class TitleBar: NSVisualEffectView { case "15", "light": return .light case "16", "mediumLight": return .mediumLight case "17", "ultraDark": return .ultraDark - default: break + default: return .titlebar } - - return .titlebar } } From eb4f5cc916c8f0b587d435a18a943f9a255321ab Mon Sep 17 00:00:00 2001 From: der richter Date: Thu, 23 Nov 2023 17:44:02 +0100 Subject: [PATCH 2/2] mac: fix libmpv usage without embedding NSApp is only an Application when initialised from mpv itself. when used via libmpv an Application is never initialised and mpv would always immediately exit. make the retrieval of the vo and mac options static so they can be retrieved in all cases. Fixes #12518 --- osdep/macos/libmpv_helper.swift | 6 ++---- osdep/macos/mpv_helper.swift | 15 +++------------ osdep/macosx_application.m | 4 ++-- osdep/macosx_application_objc.h | 4 ++-- 4 files changed, 9 insertions(+), 20 deletions(-) diff --git a/osdep/macos/libmpv_helper.swift b/osdep/macos/libmpv_helper.swift index 8b1c697da2be1..572b250980afc 100644 --- a/osdep/macos/libmpv_helper.swift +++ b/osdep/macos/libmpv_helper.swift @@ -34,10 +34,8 @@ class LibmpvHelper { mpvHandle = mpv log = LogHelper(mpLog) - guard let app = NSApp as? Application, - let ptr = mp_get_config_group(nil, - mp_client_get_global(mpvHandle), - app.getMacOSConf()) else + let global = mp_client_get_global(mpvHandle) + guard let ptr = mp_get_config_group(nil, global, Application.getMacOSConf()) else { log.sendError("macOS config group couldn't be retrieved'") exit(1) diff --git a/osdep/macos/mpv_helper.swift b/osdep/macos/mpv_helper.swift index 3b2a7162cb83b..6e5a80dc89e67 100644 --- a/osdep/macos/mpv_helper.swift +++ b/osdep/macos/mpv_helper.swift @@ -42,23 +42,14 @@ class MPVHelper { self.vo = vo self.log = log - guard let app = NSApp as? Application, - let cache = m_config_cache_alloc(vo, vo.pointee.global, app.getVoSubConf()) else + guard let cache = m_config_cache_alloc(vo, vo.pointee.global, Application.getVoSubConf()), + let macCache = m_config_cache_alloc(vo, vo.pointee.global, Application.getMacOSConf()) else { - log.sendError("NSApp couldn't be retrieved") + // will never be hit, mp_get_config_group asserts for invalid groups exit(1) } - optsCachePtr = cache optsPtr = UnsafeMutablePointer(OpaquePointer(cache.pointee.opts)) - - guard let macCache = m_config_cache_alloc(vo, - vo.pointee.global, - app.getMacOSConf()) else - { - // will never be hit, mp_get_config_group asserts for invalid groups - exit(1) - } macOptsCachePtr = macCache macOptsPtr = UnsafeMutablePointer(OpaquePointer(macCache.pointee.opts)) } diff --git a/osdep/macosx_application.m b/osdep/macosx_application.m index 73503ad66c4ed..1a1c6aefc07e8 100644 --- a/osdep/macosx_application.m +++ b/osdep/macosx_application.m @@ -190,12 +190,12 @@ - (void)setMpvHandle:(struct mpv_handle *)ctx #endif } -- (const struct m_sub_options *)getMacOSConf ++ (const struct m_sub_options *)getMacOSConf { return &macos_conf; } -- (const struct m_sub_options *)getVoSubConf ++ (const struct m_sub_options *)getVoSubConf { return &vo_sub_opts; } diff --git a/osdep/macosx_application_objc.h b/osdep/macosx_application_objc.h index 11959a83eaf12..fab968dba8212 100644 --- a/osdep/macosx_application_objc.h +++ b/osdep/macosx_application_objc.h @@ -31,8 +31,8 @@ struct mpv_handle; - (void)stopMPV:(char *)cmd; - (void)openFiles:(NSArray *)filenames; - (void)setMpvHandle:(struct mpv_handle *)ctx; -- (const struct m_sub_options *)getMacOSConf; -- (const struct m_sub_options *)getVoSubConf; ++ (const struct m_sub_options *)getMacOSConf; ++ (const struct m_sub_options *)getVoSubConf; @property(nonatomic, retain) MenuBar *menuBar; @property(nonatomic, assign) size_t openCount;