From 063ca8f0fe48c281944c5307b1e8bbb11bb22822 Mon Sep 17 00:00:00 2001 From: Akemi Date: Sun, 26 Mar 2017 20:32:04 +0200 Subject: osx: fix key input in certain circumstances for a reason i can just assume some key events can vanish from the event chain and mpv seems unresponsive. after quite some testing i could confirm that the events are present at the first entry point of the event chain, the sendEvent method of the Application, and that they vanish at a point afterwards. now we use that entry point to grab keyDown and keyUp events. we also stop propagating those key events to prevent the no key input' error sound. if we ever need the key events somewhere down the event chain we need to start propagating them again. though this is not necessary currently. --- osdep/macosx_events.m | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) (limited to 'osdep/macosx_events.m') diff --git a/osdep/macosx_events.m b/osdep/macosx_events.m index 47448fd965..6cddd40026 100644 --- a/osdep/macosx_events.m +++ b/osdep/macosx_events.m @@ -55,7 +55,6 @@ - (NSEvent *)handleKey:(NSEvent *)event; - (void)setMpvHandle:(struct mpv_handle *)ctx; - (void)readEvents; -- (void)startEventMonitor; - (void)startAppleRemote; - (void)stopAppleRemote; - (void)startMediaKeys; @@ -123,11 +122,6 @@ static int convert_key(unsigned key, unsigned charcode) return charcode; } -void cocoa_start_event_monitor(void) -{ - [[EventsResponder sharedInstance] startEventMonitor]; -} - void cocoa_init_apple_remote(void) { [[EventsResponder sharedInstance] startAppleRemote]; @@ -347,19 +341,6 @@ void cocoa_set_mpv_handle(struct mpv_handle *ctx) } } -- (void)startEventMonitor -{ - [NSEvent addLocalMonitorForEventsMatchingMask:NSEventMaskKeyDown|NSEventMaskKeyUp - handler:^(NSEvent *event) { - BOOL equivalent = [[NSApp mainMenu] performKeyEquivalent:event]; - if (equivalent) { - return (NSEvent *)nil; - } else { - return [self handleKey:event]; - } - }]; -} - - (void)startAppleRemote { @@ -527,6 +508,17 @@ void cocoa_set_mpv_handle(struct mpv_handle *ctx) return nil; } +- (bool)processKeyEvent:(NSEvent *)event +{ + if ((event.type == NSEventTypeKeyDown || event.type == NSEventTypeKeyUp) && + ![[NSApp mainMenu] performKeyEquivalent:event]) + { + [self handleKey:event]; + return true; + } + return false; +} + - (void)handleFilesArray:(NSArray *)files { enum mp_dnd_action action = [NSEvent modifierFlags] & -- cgit v1.2.3