diff --git a/osdep/mac/app_hub.swift b/osdep/mac/app_hub.swift index c74333383c..60854a3b91 100644 --- a/osdep/mac/app_hub.swift +++ b/osdep/mac/app_hub.swift @@ -21,6 +21,7 @@ class AppHub: NSObject { var mpv: OpaquePointer? @objc var input: InputHelper var event: EventHelper? + var menu: MenuBar? #if HAVE_MACOS_MEDIA_PLAYER var remote: RemoteCommandCenter? #endif @@ -33,6 +34,7 @@ class AppHub: NSObject { private override init() { input = InputHelper() super.init() + if isApplication { menu = MenuBar(self) } #if HAVE_MACOS_MEDIA_PLAYER remote = RemoteCommandCenter(self) #endif diff --git a/osdep/mac/application.m b/osdep/mac/application.m index 361fffa84e..0f506b91ce 100644 --- a/osdep/mac/application.m +++ b/osdep/mac/application.m @@ -58,7 +58,6 @@ static void terminate_cocoa_application(void) } @implementation Application -@synthesize menuBar = _menu_bar; @synthesize openCount = _open_count; @synthesize cocoaCB = _cocoa_cb; @@ -183,7 +182,6 @@ static void init_cocoa_application(bool regular) { NSApp = mpv_shared_app(); [NSApp setDelegate:NSApp]; - [NSApp setMenuBar:[[MenuBar alloc] init]]; // Will be set to Regular from cocoa_common during UI creation so that we // don't create an icon when playing audio only files. diff --git a/osdep/mac/application_objc.h b/osdep/mac/application_objc.h index f2f2ca8e27..4864e0d62b 100644 --- a/osdep/mac/application_objc.h +++ b/osdep/mac/application_objc.h @@ -19,7 +19,6 @@ #include "osdep/mac/application.h" @class CocoaCB; -@class MenuBar; struct mpv_event; struct mpv_handle; @@ -27,7 +26,6 @@ struct mpv_handle; - (void)initCocoaCb:(struct mpv_handle *)ctx; -@property(nonatomic, retain) MenuBar *menuBar; @property(nonatomic, assign) size_t openCount; @property(nonatomic, retain) CocoaCB *cocoaCB; @end diff --git a/osdep/mac/menu_bar.swift b/osdep/mac/menu_bar.swift index 2dfa53f5db..cd3be5cb27 100644 --- a/osdep/mac/menu_bar.swift +++ b/osdep/mac/menu_bar.swift @@ -68,18 +68,20 @@ extension MenuBar { } class MenuBar: NSObject { + unowned let appHub: AppHub let mainMenu = NSMenu(title: "Main") let servicesMenu = NSMenu(title: "Services") var menuConfigs: [Config] = [] var dynamicMenuItems: [Type:[MenuItem]] = [:] let appIcon: NSImage - @objc override init() { + @objc init(_ appHub: AppHub) { + self.appHub = appHub UserDefaults.standard.set(false, forKey: "NSFullScreenMenuItemEverywhere") UserDefaults.standard.set(true, forKey: "NSDisabledDictationMenuItem") UserDefaults.standard.set(true, forKey: "NSDisabledCharacterPaletteMenuItem") NSWindow.allowsAutomaticWindowTabbing = false - appIcon = AppHub.shared.getIcon() + appIcon = appHub.getIcon() super.init() @@ -318,7 +320,7 @@ class MenuBar: NSObject { @objc func quit(_ menuItem: MenuItem) { guard let menuConfig = menuItem.config else { return } - AppHub.shared.input.command(menuConfig.command) + appHub.input.command(menuConfig.command) } @objc func openFiles() { @@ -327,7 +329,7 @@ class MenuBar: NSObject { panel.canChooseDirectories = true if panel.runModal() == .OK { - AppHub.shared.input.open(files: panel.urls.map { $0.path }) + appHub.input.open(files: panel.urls.map { $0.path }) } } @@ -335,7 +337,7 @@ class MenuBar: NSObject { let panel = NSOpenPanel() if panel.runModal() == .OK, let url = panel.urls.first { - AppHub.shared.input.command("loadlist \"\(url.path)\"") + appHub.input.command("loadlist \"\(url.path)\"") } } @@ -355,13 +357,13 @@ class MenuBar: NSObject { } if alert.runModal() == .alertFirstButtonReturn && input.stringValue.count > 0 { - AppHub.shared.input.open(files: [input.stringValue]) + appHub.input.open(files: [input.stringValue]) } } @objc func command(_ menuItem: MenuItem) { guard let menuConfig = menuItem.config else { return } - AppHub.shared.input.command(menuConfig.command) + appHub.input.command(menuConfig.command) } @objc func url(_ menuItem: MenuItem) { diff --git a/video/out/mac/window.swift b/video/out/mac/window.swift index 719ae9fb05..31eab71d29 100644 --- a/video/out/mac/window.swift +++ b/video/out/mac/window.swift @@ -105,13 +105,11 @@ class Window: NSWindow, NSWindowDelegate { currentScreen = screen unfScreen = screen - if let app = NSApp as? Application { - app.menuBar.register(#selector(setHalfWindowSize), key: .itemHalfSize) - app.menuBar.register(#selector(setNormalWindowSize), key: .itemNormalSize) - app.menuBar.register(#selector(setDoubleWindowSize), key: .itemDoubleSize) - app.menuBar.register(#selector(performMiniaturize(_:)), key: .itemMinimize) - app.menuBar.register(#selector(performZoom(_:)), key: .itemZoom) - } + AppHub.shared.menu?.register(#selector(setHalfWindowSize), key: .itemHalfSize) + AppHub.shared.menu?.register(#selector(setNormalWindowSize), key: .itemNormalSize) + AppHub.shared.menu?.register(#selector(setDoubleWindowSize), key: .itemDoubleSize) + AppHub.shared.menu?.register(#selector(performMiniaturize(_:)), key: .itemMinimize) + AppHub.shared.menu?.register(#selector(performZoom(_:)), key: .itemZoom) } override func toggleFullScreen(_ sender: Any?) {