summaryrefslogtreecommitdiffstats
path: root/osdep
diff options
context:
space:
mode:
authorder richter <der.richter@gmx.de>2024-03-26 00:06:42 +0100
committerder richter <der.richter@gmx.de>2024-03-29 14:20:40 +0100
commit1acca1d3c4c5952911a4b6ea4b8102898a244b57 (patch)
tree4757c6581cd5febaae3fc4dd28c5ef9ba1f61eed /osdep
parent86aea966d92053e3aca364a802c5619da2e7d428 (diff)
downloadmpv-1acca1d3c4c5952911a4b6ea4b8102898a244b57.tar.bz2
mpv-1acca1d3c4c5952911a4b6ea4b8102898a244b57.tar.xz
mac/apphub: move app icon into AppHub
split up AppHub header in obj-c and c parts and make it a bidirectional bridging.
Diffstat (limited to 'osdep')
-rw-r--r--osdep/mac/app_bridge.m12
-rw-r--r--osdep/mac/app_bridge_objc.h22
-rw-r--r--osdep/mac/app_hub.swift7
-rw-r--r--osdep/mac/application.m13
-rw-r--r--osdep/mac/application_objc.h1
-rw-r--r--osdep/mac/menu_bar.swift2
-rw-r--r--osdep/mac/remote_command_center.swift5
-rw-r--r--osdep/mac/swift_bridge.h2
8 files changed, 44 insertions, 20 deletions
diff --git a/osdep/mac/app_bridge.m b/osdep/mac/app_bridge.m
index 79024dc882..e5e4712ffe 100644
--- a/osdep/mac/app_bridge.m
+++ b/osdep/mac/app_bridge.m
@@ -17,11 +17,21 @@
#include "config.h"
-#include "osdep/mac/app_bridge.h"
+#import "osdep/mac/app_bridge_objc.h"
+
#if HAVE_SWIFT
#include "osdep/mac/swift.h"
#endif
+static const char app_icon[] =
+#include "TOOLS/osxbundle/icon.icns.inc"
+;
+
+NSData *app_bridge_icon(void)
+{
+ return [NSData dataWithBytesNoCopy:(void *)app_icon length:sizeof(app_icon) - 1 freeWhenDone:NO];
+}
+
void cocoa_init_media_keys(void)
{
[[AppHub shared] startRemote];
diff --git a/osdep/mac/app_bridge_objc.h b/osdep/mac/app_bridge_objc.h
new file mode 100644
index 0000000000..1655a60f0c
--- /dev/null
+++ b/osdep/mac/app_bridge_objc.h
@@ -0,0 +1,22 @@
+/*
+ * This file is part of mpv.
+ *
+ * mpv is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * mpv is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with mpv. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#import <Cocoa/Cocoa.h>
+
+#include "osdep/mac/app_bridge.h"
+
+NSData *app_bridge_icon(void);
diff --git a/osdep/mac/app_hub.swift b/osdep/mac/app_hub.swift
index a668948603..e77bf9381e 100644
--- a/osdep/mac/app_hub.swift
+++ b/osdep/mac/app_hub.swift
@@ -70,4 +70,11 @@ class AppHub: NSObject {
remote?.stop()
#endif
}
+
+ func getIcon() -> NSImage {
+ guard let iconData = app_bridge_icon(), let icon = NSImage(data: iconData) else {
+ return NSImage(size: NSSize(width: 1, height: 1))
+ }
+ return icon
+ }
}
diff --git a/osdep/mac/application.m b/osdep/mac/application.m
index f13b386a10..1e9cbee64b 100644
--- a/osdep/mac/application.m
+++ b/osdep/mac/application.m
@@ -141,19 +141,6 @@ static void terminate_cocoa_application(void)
[super dealloc];
}
-static const char mac_icon[] =
-#include "TOOLS/osxbundle/icon.icns.inc"
-;
-
-- (NSImage *)getMPVIcon
-{
- // The C string contains a trailing null, so we strip it away
- NSData *icon_data = [NSData dataWithBytesNoCopy:(void *)mac_icon
- length:sizeof(mac_icon) - 1
- freeWhenDone:NO];
- return [[NSImage alloc] initWithData:icon_data];
-}
-
#if HAVE_MACOS_TOUCHBAR
- (NSTouchBar *)makeTouchBar
{
diff --git a/osdep/mac/application_objc.h b/osdep/mac/application_objc.h
index 4c8beb20b3..123f938a47 100644
--- a/osdep/mac/application_objc.h
+++ b/osdep/mac/application_objc.h
@@ -25,7 +25,6 @@ struct mpv_handle;
@interface Application : NSApplication
-- (NSImage *)getMPVIcon;
- (void)initCocoaCb:(struct mpv_handle *)ctx;
+ (const struct m_sub_options *)getMacConf;
+ (const struct m_sub_options *)getVoConf;
diff --git a/osdep/mac/menu_bar.swift b/osdep/mac/menu_bar.swift
index f81e97daaf..2dfa53f5db 100644
--- a/osdep/mac/menu_bar.swift
+++ b/osdep/mac/menu_bar.swift
@@ -79,7 +79,7 @@ class MenuBar: NSObject {
UserDefaults.standard.set(true, forKey: "NSDisabledDictationMenuItem")
UserDefaults.standard.set(true, forKey: "NSDisabledCharacterPaletteMenuItem")
NSWindow.allowsAutomaticWindowTabbing = false
- appIcon = (NSApp as? Application)?.getMPVIcon() ?? NSImage(size: NSSize(width: 1, height: 1))
+ appIcon = AppHub.shared.getIcon()
super.init()
diff --git a/osdep/mac/remote_command_center.swift b/osdep/mac/remote_command_center.swift
index b000fcdb3e..4e3244a152 100644
--- a/osdep/mac/remote_command_center.swift
+++ b/osdep/mac/remote_command_center.swift
@@ -53,13 +53,14 @@ class RemoteCommandCenter: EventSubscriber {
var chapter: String? { didSet { updateInfoCenter() } }
var album: String? { didSet { updateInfoCenter() } }
var artist: String? { didSet { updateInfoCenter() } }
- var cover: NSImage = NSImage(size: NSSize(width: 256, height: 256))
+ var cover: NSImage
var infoCenter: MPNowPlayingInfoCenter { get { return MPNowPlayingInfoCenter.default() } }
var commandCenter: MPRemoteCommandCenter { get { return MPRemoteCommandCenter.shared() } }
init(_ appHub: AppHub) {
self.appHub = appHub
+ cover = appHub.getIcon()
configs = [
commandCenter.pauseCommand: Config(key: MP_KEY_PAUSEONLY, handler: keyHandler),
@@ -87,8 +88,6 @@ class RemoteCommandCenter: EventSubscriber {
commandCenter.bookmarkCommand,
]
- cover = (NSApp as? Application)?.getMPVIcon() ?? cover
-
for cmd in disabledCommands {
cmd.isEnabled = false
}
diff --git a/osdep/mac/swift_bridge.h b/osdep/mac/swift_bridge.h
index f4d1c545d7..fd236bf6a4 100644
--- a/osdep/mac/swift_bridge.h
+++ b/osdep/mac/swift_bridge.h
@@ -31,9 +31,9 @@
#include "input/keycodes.h"
#include "video/out/win_state.h"
+#include "osdep/mac/app_bridge_objc.h"
#include "osdep/mac/application_objc.h"
-
// complex macros won't get imported to Swift so we have to reassign them
static int SWIFT_MBTN_LEFT = MP_MBTN_LEFT;
static int SWIFT_MBTN_MID = MP_MBTN_MID;