0
0
mirror of https://github.com/mpv-player/mpv.git synced 2024-09-20 12:02:23 +02:00

libmpv: cocoa: add basic menu

This commit is contained in:
Stefano Pigozzi 2014-10-27 19:10:09 +01:00
parent c18cf4394d
commit 58effd3fec

View File

@ -8,9 +8,6 @@
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
#define EMBED_VIEW 1
#if EMBED_VIEW
@interface CocoaWindow : NSWindow @interface CocoaWindow : NSWindow
@end @end
@ -26,11 +23,9 @@
NSWindow *w; NSWindow *w;
} }
@end @end
#endif
static void wakeup(void *); static void wakeup(void *);
#if EMBED_VIEW
@implementation AppDelegate @implementation AppDelegate
- (void)createWindow { - (void)createWindow {
@ -47,9 +42,15 @@ static void wakeup(void *);
[self->w setTitle:@"cocoabasic example"]; [self->w setTitle:@"cocoabasic example"];
[self->w makeMainWindow]; [self->w makeMainWindow];
[self->w makeKeyAndOrderFront:nil]; [self->w makeKeyAndOrderFront:nil];
NSMenu *m = [[NSMenu alloc] initWithTitle:@"AMainMenu"];
NSMenuItem *item = [m addItemWithTitle:@"Apple" action:nil keyEquivalent:@""];
NSMenu *sm = [[NSMenu alloc] initWithTitle:@"Apple"];
[m setSubmenu:sm forItem:item];
[sm addItemWithTitle: @"Shutdown mpv" action:@selector(shutdown) keyEquivalent:@"s"];
[NSApp setMenu:m];
[NSApp activateIgnoringOtherApps:YES]; [NSApp activateIgnoringOtherApps:YES];
} }
#endif
- (void) applicationDidFinishLaunching:(NSNotification *)notification { - (void) applicationDidFinishLaunching:(NSNotification *)notification {
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular]; [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
@ -68,9 +69,7 @@ static void wakeup(void *);
} }
NSString *filename = args[1]; NSString *filename = args[1];
#if EMBED_VIEW
[self createWindow]; [self createWindow];
#endif
// Deal with MPV in the background. // Deal with MPV in the background.
queue = dispatch_queue_create("mpv", DISPATCH_QUEUE_SERIAL); queue = dispatch_queue_create("mpv", DISPATCH_QUEUE_SERIAL);
@ -82,10 +81,8 @@ static void wakeup(void *);
exit(1); exit(1);
} }
#if EMBED_VIEW
int64_t wid = (intptr_t) [self->w contentView]; int64_t wid = (intptr_t) [self->w contentView];
check_error(mpv_set_option(mpv, "wid", MPV_FORMAT_INT64, &wid)); check_error(mpv_set_option(mpv, "wid", MPV_FORMAT_INT64, &wid));
#endif
// Maybe set some options here, like default key bindings. // Maybe set some options here, like default key bindings.
// NOTE: Interaction with the window seems to be broken for now. // NOTE: Interaction with the window seems to be broken for now.