mirror of https://github.com/mpv-player/mpv
cocoa: always compile OSX application code with cocoa
This unbreaks compiling command line player and libmpv at the same time. The problem was that doing so silently disabled the OSX application thing - but the command line player can not use the vo_opengl Cocoa backend without it. The OSX application code is basically dead in libmpv, but it's not that much code anyway. If you want a mpv binary that does not create an OSX application singleton (and creates a menu etc.), you must disable cocoa completely, as cocoa can't be used anyway in this case.
This commit is contained in:
parent
d8e92322fa
commit
19a5b20752
|
@ -32,6 +32,5 @@ typedef enum {
|
|||
// multithreaded wrapper for mpv_main
|
||||
int cocoa_main(mpv_main_fn mpv_main, int argc, char *argv[]);
|
||||
void cocoa_register_menu_item_action(MPMenuKey key, void* action);
|
||||
void terminate_cocoa_application(void);
|
||||
|
||||
#endif /* MPV_MACOSX_APPLICATION */
|
||||
|
|
|
@ -29,6 +29,10 @@
|
|||
|
||||
#define MPV_PROTOCOL @"mpv://"
|
||||
|
||||
// Whether the NSApplication singleton was created. If this is false, we are
|
||||
// running in libmpv mode, and cocoa_main() was never called.
|
||||
static bool application_instantiated;
|
||||
|
||||
static pthread_t playback_thread_id;
|
||||
|
||||
@interface Application ()
|
||||
|
@ -53,11 +57,17 @@ static pthread_t playback_thread_id;
|
|||
- (void)setAppleMenu:(NSMenu *)aMenu;
|
||||
@end
|
||||
|
||||
Application *mpv_shared_app(void)
|
||||
static Application *mpv_shared_app(void)
|
||||
{
|
||||
return (Application *)[Application sharedApplication];
|
||||
}
|
||||
|
||||
static void terminate_cocoa_application(void)
|
||||
{
|
||||
[NSApp hide:NSApp];
|
||||
[NSApp terminate:NSApp];
|
||||
}
|
||||
|
||||
@implementation Application
|
||||
@synthesize menuItems = _menu_items;
|
||||
@synthesize openCount = _open_count;
|
||||
|
@ -247,12 +257,6 @@ struct playback_thread_ctx {
|
|||
char ***argv;
|
||||
};
|
||||
|
||||
void terminate_cocoa_application(void)
|
||||
{
|
||||
[NSApp hide:NSApp];
|
||||
[NSApp terminate:NSApp];
|
||||
}
|
||||
|
||||
static void cocoa_run_runloop(void)
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
|
@ -274,7 +278,8 @@ static void *playback_thread(void *ctx_obj)
|
|||
|
||||
void cocoa_register_menu_item_action(MPMenuKey key, void* action)
|
||||
{
|
||||
[NSApp registerSelector:(SEL)action forKey:key];
|
||||
if (application_instantiated)
|
||||
[NSApp registerSelector:(SEL)action forKey:key];
|
||||
}
|
||||
|
||||
static void init_cocoa_application(bool regular)
|
||||
|
@ -359,6 +364,8 @@ static bool bundle_started_from_finder(int argc, char **argv)
|
|||
int cocoa_main(mpv_main_fn mpv_main, int argc, char *argv[])
|
||||
{
|
||||
@autoreleasepool {
|
||||
application_instantiated = true;
|
||||
|
||||
struct playback_thread_ctx ctx = {0};
|
||||
ctx.mpv_main = mpv_main;
|
||||
ctx.argc = &argc;
|
||||
|
|
|
@ -27,5 +27,3 @@
|
|||
@property(nonatomic, retain) NSArray *files;
|
||||
@property(nonatomic, assign) size_t openCount;
|
||||
@end
|
||||
|
||||
Application *mpv_shared_app(void);
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
#include "config.h"
|
||||
#include "core.h"
|
||||
|
||||
#if HAVE_COCOA_APPLICATION
|
||||
#if HAVE_COCOA
|
||||
#include "osdep/macosx_application.h"
|
||||
#endif
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
#if HAVE_COCOA_APPLICATION
|
||||
#if HAVE_COCOA
|
||||
return cocoa_main(mpv_main, argc, argv);
|
||||
#else
|
||||
return mpv_main(argc, argv);
|
||||
|
|
|
@ -35,10 +35,8 @@
|
|||
|
||||
#include "config.h"
|
||||
|
||||
#if HAVE_COCOA_APPLICATION
|
||||
# include "osdep/macosx_application.h"
|
||||
# include "osdep/macosx_application_objc.h"
|
||||
#endif
|
||||
#include "osdep/macosx_application.h"
|
||||
#include "osdep/macosx_application_objc.h"
|
||||
|
||||
#include "options/options.h"
|
||||
#include "video/out/vo.h"
|
||||
|
@ -462,13 +460,11 @@ static void create_ui(struct vo *vo, struct mp_rect *win, int geo_flags)
|
|||
[view signalMousePosition];
|
||||
s->adapter = adapter;
|
||||
|
||||
#if HAVE_COCOA_APPLICATION
|
||||
cocoa_register_menu_item_action(MPM_H_SIZE, @selector(halfSize));
|
||||
cocoa_register_menu_item_action(MPM_N_SIZE, @selector(normalSize));
|
||||
cocoa_register_menu_item_action(MPM_D_SIZE, @selector(doubleSize));
|
||||
cocoa_register_menu_item_action(MPM_MINIMIZE, @selector(performMiniaturize:));
|
||||
cocoa_register_menu_item_action(MPM_ZOOM, @selector(performZoom:));
|
||||
#endif
|
||||
|
||||
s->video = [[MpvVideoView alloc] initWithFrame:[s->view bounds]];
|
||||
[s->video setWantsBestResolutionOpenGLSurface:YES];
|
||||
|
|
6
wscript
6
wscript
|
@ -769,12 +769,6 @@ standalone_features = [
|
|||
'desc': 'w32 executable',
|
||||
'deps_any': [ 'os-win32', 'os-cygwin'],
|
||||
'func': check_ctx_vars('WINDRES')
|
||||
}, {
|
||||
'name': 'cocoa-application',
|
||||
'desc': 'standalone Cocoa application',
|
||||
'deps': [ 'cocoa' ],
|
||||
'deps_neg': [ 'libmpv-shared', 'libmpv-static' ],
|
||||
'func': check_true
|
||||
}, {
|
||||
'name': '--apple-remote',
|
||||
'desc': 'Apple Remote support',
|
||||
|
|
|
@ -373,7 +373,7 @@ def build(ctx):
|
|||
( "osdep/threads.c" ),
|
||||
|
||||
( "osdep/ar/HIDRemote.m", "apple-remote" ),
|
||||
( "osdep/macosx_application.m", "cocoa-application" ),
|
||||
( "osdep/macosx_application.m", "cocoa" ),
|
||||
( "osdep/macosx_events.m", "cocoa" ),
|
||||
( "osdep/semaphore_osx.c" ),
|
||||
( "osdep/subprocess.c" ),
|
||||
|
|
Loading…
Reference in New Issue