From ba45f2004f568455a1b3f846516dc2614737eff8 Mon Sep 17 00:00:00 2001 From: der richter Date: Wed, 27 Mar 2024 23:22:56 +0100 Subject: [PATCH] mac: cleanup swift bridge header imports and unify them --- osdep/mac/app_bridge.h | 2 - osdep/mac/app_bridge.m | 5 +++ osdep/mac/app_bridge_objc.h | 33 ++++++++++++++- osdep/mac/app_hub.swift | 2 + osdep/mac/event_helper.swift | 2 + osdep/mac/input_helper.swift | 1 + osdep/mac/menu_bar.swift | 2 + osdep/mac/meson.build | 2 +- osdep/mac/remote_command_center.swift | 1 + osdep/mac/swift_bridge.h | 61 --------------------------- osdep/mac/touch_bar.swift | 2 + video/out/mac/common.swift | 4 +- video/out/mac/metal_layer.swift | 1 + video/out/vulkan/context_mac.m | 2 + 14 files changed, 53 insertions(+), 67 deletions(-) delete mode 100644 osdep/mac/swift_bridge.h diff --git a/osdep/mac/app_bridge.h b/osdep/mac/app_bridge.h index 72553b409b..27cc2413ea 100644 --- a/osdep/mac/app_bridge.h +++ b/osdep/mac/app_bridge.h @@ -17,8 +17,6 @@ #pragma once -#include "input/input.h" - enum { FRAME_VISIBLE = 0, FRAME_WHOLE, diff --git a/osdep/mac/app_bridge.m b/osdep/mac/app_bridge.m index d0f17465a8..ab8470d9cc 100644 --- a/osdep/mac/app_bridge.m +++ b/osdep/mac/app_bridge.m @@ -75,6 +75,11 @@ NSData *app_bridge_icon(void) return [NSData dataWithBytesNoCopy:(void *)app_icon length:sizeof(app_icon) - 1 freeWhenDone:NO]; } +void app_bridge_tarray_append(void *t, char ***a, int *i, char *s) +{ + MP_TARRAY_APPEND(t, *a, *i, s); +} + const struct m_sub_options *app_bridge_mac_conf(void) { return &macos_conf; diff --git a/osdep/mac/app_bridge_objc.h b/osdep/mac/app_bridge_objc.h index 31cf90662b..c34b09736c 100644 --- a/osdep/mac/app_bridge_objc.h +++ b/osdep/mac/app_bridge_objc.h @@ -15,10 +15,41 @@ * License along with mpv. If not, see . */ -#import +#import + +#include "player/client.h" +#include "video/out/libmpv.h" +#include "libmpv/render_gl.h" + +#include "options/m_config.h" +#include "player/core.h" +#include "input/input.h" +#include "input/event.h" +#include "input/keycodes.h" +#include "video/out/win_state.h" #include "osdep/mac/app_bridge.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; +static int SWIFT_MBTN_RIGHT = MP_MBTN_RIGHT; +static int SWIFT_WHEEL_UP = MP_WHEEL_UP; +static int SWIFT_WHEEL_DOWN = MP_WHEEL_DOWN; +static int SWIFT_WHEEL_LEFT = MP_WHEEL_LEFT; +static int SWIFT_WHEEL_RIGHT = MP_WHEEL_RIGHT; +static int SWIFT_MBTN_BACK = MP_MBTN_BACK; +static int SWIFT_MBTN_FORWARD = MP_MBTN_FORWARD; +static int SWIFT_MBTN9 = MP_MBTN9; + +static int SWIFT_KEY_MOUSE_LEAVE = MP_KEY_MOUSE_LEAVE; +static int SWIFT_KEY_MOUSE_ENTER = MP_KEY_MOUSE_ENTER; + +static const char *swift_mpv_version = mpv_version; +static const char *swift_mpv_copyright = mpv_copyright; NSData *app_bridge_icon(void); +void app_bridge_tarray_append(void *t, char ***a, int *i, char *s); const struct m_sub_options *app_bridge_mac_conf(void); const struct m_sub_options *app_bridge_vo_conf(void); diff --git a/osdep/mac/app_hub.swift b/osdep/mac/app_hub.swift index 22f30dd9b3..6d4b00fa4c 100644 --- a/osdep/mac/app_hub.swift +++ b/osdep/mac/app_hub.swift @@ -15,6 +15,8 @@ * License along with mpv. If not, see . */ +import Cocoa + class AppHub: NSObject { @objc static let shared = AppHub() diff --git a/osdep/mac/event_helper.swift b/osdep/mac/event_helper.swift index 7170136478..277a9aa08d 100644 --- a/osdep/mac/event_helper.swift +++ b/osdep/mac/event_helper.swift @@ -15,6 +15,8 @@ * License along with mpv. If not, see . */ +import Cocoa + protocol EventSubscriber: AnyObject { var uid: Int { get } func handle(event: EventHelper.Event) diff --git a/osdep/mac/input_helper.swift b/osdep/mac/input_helper.swift index d53bfe779b..52a5404f0a 100644 --- a/osdep/mac/input_helper.swift +++ b/osdep/mac/input_helper.swift @@ -15,6 +15,7 @@ * License along with mpv. If not, see . */ +import Cocoa import Carbon.HIToolbox class InputHelper: NSObject { diff --git a/osdep/mac/menu_bar.swift b/osdep/mac/menu_bar.swift index cd3be5cb27..8768348db7 100644 --- a/osdep/mac/menu_bar.swift +++ b/osdep/mac/menu_bar.swift @@ -15,6 +15,8 @@ * License along with mpv. If not, see . */ +import Cocoa + extension MenuBar { class MenuItem: NSMenuItem { var config: Config? diff --git a/osdep/mac/meson.build b/osdep/mac/meson.build index de32eb2a3c..8ddbdbaddf 100644 --- a/osdep/mac/meson.build +++ b/osdep/mac/meson.build @@ -1,5 +1,5 @@ # custom swift targets -bridge = join_paths(source_root, 'osdep/mac/swift_bridge.h') +bridge = join_paths(source_root, 'osdep/mac/app_bridge_objc.h') header = join_paths(build_root, 'osdep/mac/swift.h') module = join_paths(build_root, 'osdep/mac/swift.swiftmodule') target = join_paths(build_root, 'osdep/mac/swift.o') diff --git a/osdep/mac/remote_command_center.swift b/osdep/mac/remote_command_center.swift index 4e3244a152..358a0a00dd 100644 --- a/osdep/mac/remote_command_center.swift +++ b/osdep/mac/remote_command_center.swift @@ -15,6 +15,7 @@ * License along with mpv. If not, see . */ +import Cocoa import MediaPlayer extension RemoteCommandCenter { diff --git a/osdep/mac/swift_bridge.h b/osdep/mac/swift_bridge.h deleted file mode 100644 index fd236bf6a4..0000000000 --- a/osdep/mac/swift_bridge.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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 . - */ - -// including frameworks here again doesn't make sense, but otherwise the swift -// compiler doesn't include the needed headers in our generated header file -#import -#import - -#include "player/client.h" -#include "video/out/libmpv.h" -#include "libmpv/render_gl.h" - -#include "options/m_config.h" -#include "player/core.h" -#include "input/input.h" -#include "input/event.h" -#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; -static int SWIFT_MBTN_RIGHT = MP_MBTN_RIGHT; -static int SWIFT_WHEEL_UP = MP_WHEEL_UP; -static int SWIFT_WHEEL_DOWN = MP_WHEEL_DOWN; -static int SWIFT_WHEEL_LEFT = MP_WHEEL_LEFT; -static int SWIFT_WHEEL_RIGHT = MP_WHEEL_RIGHT; -static int SWIFT_MBTN_BACK = MP_MBTN_BACK; -static int SWIFT_MBTN_FORWARD = MP_MBTN_FORWARD; -static int SWIFT_MBTN9 = MP_MBTN9; - -static int SWIFT_KEY_MOUSE_LEAVE = MP_KEY_MOUSE_LEAVE; -static int SWIFT_KEY_MOUSE_ENTER = MP_KEY_MOUSE_ENTER; - -static const char *swift_mpv_version = mpv_version; -static const char *swift_mpv_copyright = mpv_copyright; - -// only used from Swift files and therefore seen as unused by the c compiler -static void SWIFT_TARRAY_STRING_APPEND(void *t, char ***a, int *i, char *s) __attribute__ ((unused)); - -static void SWIFT_TARRAY_STRING_APPEND(void *t, char ***a, int *i, char *s) -{ - MP_TARRAY_APPEND(t, *a, *i, s); -} diff --git a/osdep/mac/touch_bar.swift b/osdep/mac/touch_bar.swift index 811ffcafa4..8e64c51b22 100644 --- a/osdep/mac/touch_bar.swift +++ b/osdep/mac/touch_bar.swift @@ -15,6 +15,8 @@ * License along with mpv. If not, see . */ +import Cocoa + extension NSTouchBar.CustomizationIdentifier { public static let customId: NSTouchBar.CustomizationIdentifier = "io.mpv.touchbar" } diff --git a/video/out/mac/common.swift b/video/out/mac/common.swift index 2bcf9dee44..d507a388aa 100644 --- a/video/out/mac/common.swift +++ b/video/out/mac/common.swift @@ -626,8 +626,8 @@ class Common: NSObject { var count: Int32 = 0 let displayName = getCurrentScreen()?.localizedName ?? "Unknown" - SWIFT_TARRAY_STRING_APPEND(nil, &array, &count, ta_xstrdup(nil, displayName)) - SWIFT_TARRAY_STRING_APPEND(nil, &array, &count, nil) + app_bridge_tarray_append(nil, &array, &count, ta_xstrdup(nil, displayName)) + app_bridge_tarray_append(nil, &array, &count, nil) dnames.pointee = array return VO_TRUE case VOCTRL_GET_DISPLAY_RES: diff --git a/video/out/mac/metal_layer.swift b/video/out/mac/metal_layer.swift index 9d2b5bd353..7fc419af4b 100644 --- a/video/out/mac/metal_layer.swift +++ b/video/out/mac/metal_layer.swift @@ -16,6 +16,7 @@ */ import Cocoa +import QuartzCore class MetalLayer: CAMetalLayer { unowned var common: MacCommon diff --git a/video/out/vulkan/context_mac.m b/video/out/vulkan/context_mac.m index 5621e6dca3..be5c077155 100644 --- a/video/out/vulkan/context_mac.m +++ b/video/out/vulkan/context_mac.m @@ -15,6 +15,8 @@ * License along with mpv. If not, see . */ +#import + #include "video/out/gpu/context.h" #include "osdep/mac/swift.h"