1
mirror of https://github.com/mpv-player/mpv synced 2024-11-11 00:15:33 +01:00

cocoa: remove the setNextKeyView hack

Just use makeFirstResponder on the mpv events view from client code
if you need the built in keyboard events (this is easier for dealing with view
nesting).
This commit is contained in:
Stefano Pigozzi 2015-02-28 14:50:06 +01:00
parent 721e430cd2
commit 03a69bac95
2 changed files with 14 additions and 6 deletions

View File

@ -33,6 +33,7 @@ static inline void check_error(int status)
mpv_handle *mpv; mpv_handle *mpv;
dispatch_queue_t queue; dispatch_queue_t queue;
NSWindow *w; NSWindow *w;
NSView *wrapper;
} }
@end @end
@ -55,6 +56,12 @@ static void wakeup(void *);
[self->w makeMainWindow]; [self->w makeMainWindow];
[self->w makeKeyAndOrderFront:nil]; [self->w makeKeyAndOrderFront:nil];
NSRect frame = [[self->w contentView] bounds];
self->wrapper = [[NSView alloc] initWithFrame:frame];
[self->wrapper setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
[[self->w contentView] addSubview:self->wrapper];
[self->wrapper release];
NSMenu *m = [[NSMenu alloc] initWithTitle:@"AMainMenu"]; NSMenu *m = [[NSMenu alloc] initWithTitle:@"AMainMenu"];
NSMenuItem *item = [m addItemWithTitle:@"Apple" action:nil keyEquivalent:@""]; NSMenuItem *item = [m addItemWithTitle:@"Apple" action:nil keyEquivalent:@""];
NSMenu *sm = [[NSMenu alloc] initWithTitle:@"Apple"]; NSMenu *sm = [[NSMenu alloc] initWithTitle:@"Apple"];
@ -95,7 +102,7 @@ static void wakeup(void *);
exit(1); exit(1);
} }
int64_t wid = (intptr_t) [self->w contentView]; int64_t wid = (intptr_t) self->wrapper;
check_error(mpv_set_option(mpv, "wid", MPV_FORMAT_INT64, &wid)); check_error(mpv_set_option(mpv, "wid", MPV_FORMAT_INT64, &wid));
// Maybe set some options here, like default key bindings. // Maybe set some options here, like default key bindings.
@ -138,7 +145,12 @@ static void wakeup(void *);
case MPV_EVENT_VIDEO_RECONFIG: { case MPV_EVENT_VIDEO_RECONFIG: {
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
[self->w selectNextKeyView:nil]; NSArray *subviews = [self->wrapper subviews];
if ([subviews count] > 0) {
// mpv's events view
NSView *eview = [self->wrapper subviews][0];
[self->w makeFirstResponder:eview];
}
}); });
} }

View File

@ -380,10 +380,6 @@ static void create_ui(struct vo *vo, struct mp_rect *win, int geo_flags)
s->view = view; s->view = view;
[parent addSubview:s->view]; [parent addSubview:s->view];
// insert ourselves as the next key view so that clients can give key
// focus to the mpv view by calling -[NSWindow selectNextKeyView:]
[parent setNextKeyView:s->view];
#if HAVE_COCOA_APPLICATION #if HAVE_COCOA_APPLICATION
cocoa_register_menu_item_action(MPM_H_SIZE, @selector(halfSize)); 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_N_SIZE, @selector(normalSize));