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. --- DOCS/interface-changes.rst | 1 + DOCS/man/options.rst | 5 ----- etc/builtin.conf | 1 - input/input.c | 8 -------- osdep/macosx_application.m | 4 ++-- osdep/macosx_compat.h | 2 -- osdep/macosx_events.h | 2 -- osdep/macosx_events.m | 30 +++++++++++------------------- osdep/macosx_events_objc.h | 2 ++ video/out/cocoa/events_view.m | 10 ---------- video/out/cocoa/mpvadapter.h | 1 - video/out/cocoa_common.m | 8 -------- 12 files changed, 16 insertions(+), 58 deletions(-) diff --git a/DOCS/interface-changes.rst b/DOCS/interface-changes.rst index 253ea98a39..bcffc69cee 100644 --- a/DOCS/interface-changes.rst +++ b/DOCS/interface-changes.rst @@ -30,6 +30,7 @@ Interface changes input_size instead - add --sub-filter-sdh - add --sub-filter-sdh-harder + - remove --input-app-events option (macOS) --- mpv 0.24.0 --- - deprecate --hwdec-api and replace it with --opengl-hwdec-interop. The new option accepts both --hwdec values, as well as named backends. diff --git a/DOCS/man/options.rst b/DOCS/man/options.rst index 19e331a468..f6f3e98472 100644 --- a/DOCS/man/options.rst +++ b/DOCS/man/options.rst @@ -2923,11 +2923,6 @@ Input (This option was renamed from ``--input-x11-keyboard``.) -``--input-app-events=`` - (OS X only) - Enable/disable application wide keyboard events so that keyboard shortcuts - can be processed without a window. Enabled by default (except for libmpv). - OSD --- diff --git a/etc/builtin.conf b/etc/builtin.conf index 533dce7127..1d93df9606 100644 --- a/etc/builtin.conf +++ b/etc/builtin.conf @@ -24,7 +24,6 @@ stop-playback-on-init-failure=yes # OSX/Cocoa global input hooks input-appleremote=no input-media-keys=no -input-app-events=no [encoding] vo=lavc diff --git a/input/input.c b/input/input.c index f0f9f64e9b..b8cc142da2 100644 --- a/input/input.c +++ b/input/input.c @@ -168,7 +168,6 @@ struct input_opts { int use_alt_gr; int use_appleremote; int use_media_keys; - int use_app_events; int default_bindings; int enable_mouse_movements; int vo_key_input; @@ -193,7 +192,6 @@ const struct m_sub_options input_config = { #if HAVE_COCOA OPT_FLAG("input-appleremote", use_appleremote, 0), OPT_FLAG("input-media-keys", use_media_keys, 0), - OPT_FLAG("input-app-events", use_app_events, M_OPT_FIXED), #endif OPT_FLAG("window-dragging", allow_win_drag, 0), OPT_REPLACED("input-x11-keyboard", "input-vo-keyboard"), @@ -210,7 +208,6 @@ const struct m_sub_options input_config = { #if HAVE_COCOA .use_appleremote = 1, .use_media_keys = 1, - .use_app_events = 1, #endif .default_bindings = 1, .vo_key_input = 1, @@ -1298,11 +1295,6 @@ void mp_input_load_config(struct input_ctx *ictx) talloc_free(tmp); } -#if HAVE_COCOA - if (ictx->opts->use_app_events) - cocoa_start_event_monitor(); -#endif - #if defined(__MINGW32__) if (ictx->global->opts->input_file && *ictx->global->opts->input_file) mp_input_pipe_add(ictx, ictx->global->opts->input_file); diff --git a/osdep/macosx_application.m b/osdep/macosx_application.m index cccd60b4e2..fb3d742ed8 100644 --- a/osdep/macosx_application.m +++ b/osdep/macosx_application.m @@ -81,8 +81,8 @@ static void terminate_cocoa_application(void) - (void)sendEvent:(NSEvent *)event { - [super sendEvent:event]; - + if (![_eventsResponder processKeyEvent:event]) + [super sendEvent:event]; [_eventsResponder wakeup]; } diff --git a/osdep/macosx_compat.h b/osdep/macosx_compat.h index 06b8cbd175..1cb5018382 100644 --- a/osdep/macosx_compat.h +++ b/osdep/macosx_compat.h @@ -37,8 +37,6 @@ static const NSEventType NSEventTypeSystemDefined = NSSystemDefined; static const NSEventType NSEventTypeKeyDown = NSKeyDown; static const NSEventType NSEventTypeKeyUp = NSKeyUp; -static const NSEventMask NSEventMaskKeyDown = NSKeyDownMask; -static const NSEventMask NSEventMaskKeyUp = NSKeyUpMask; static const NSEventMask NSEventMaskLeftMouseUp = NSLeftMouseUpMask; #if (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_10) diff --git a/osdep/macosx_events.h b/osdep/macosx_events.h index 019f24feef..9da3cb27bc 100644 --- a/osdep/macosx_events.h +++ b/osdep/macosx_events.h @@ -28,8 +28,6 @@ void cocoa_put_key(int keycode); void cocoa_put_key_with_modifiers(int keycode, int modifiers); void cocoa_put_key_event(void *event); -void cocoa_start_event_monitor(void); - void cocoa_init_apple_remote(void); void cocoa_uninit_apple_remote(void); 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] & diff --git a/osdep/macosx_events_objc.h b/osdep/macosx_events_objc.h index 99f00dcc1e..ff5db938c9 100644 --- a/osdep/macosx_events_objc.h +++ b/osdep/macosx_events_objc.h @@ -42,4 +42,6 @@ struct input_ctx; - (void)handleFilesArray:(NSArray *)files; +- (bool)processKeyEvent:(NSEvent *)event; + @end diff --git a/video/out/cocoa/events_view.m b/video/out/cocoa/events_view.m index 8be74d5e15..3184947a5b 100644 --- a/video/out/cocoa/events_view.m +++ b/video/out/cocoa/events_view.m @@ -124,16 +124,6 @@ - (BOOL)resignFirstResponder { return YES; } -- (void)keyDown:(NSEvent *)event -{ - [self.adapter putKeyEvent:event]; -} - -- (void)keyUp:(NSEvent *)event -{ - [self.adapter putKeyEvent:event]; -} - - (BOOL)canHideCursor { return !self.hasMouseDown && [self containsMouseLocation] diff --git a/video/out/cocoa/mpvadapter.h b/video/out/cocoa/mpvadapter.h index b5fa8adbf4..eb40df0983 100644 --- a/video/out/cocoa/mpvadapter.h +++ b/video/out/cocoa/mpvadapter.h @@ -21,7 +21,6 @@ @interface MpvCocoaAdapter : NSObject - (void)setNeedsResize; - (void)signalMouseMovement:(NSPoint)point; -- (void)putKeyEvent:(NSEvent*)event; - (void)putKey:(int)mpkey withModifiers:(int)modifiers; - (void)putAxis:(int)mpkey delta:(float)delta; - (void)putCommand:(char*)cmd; diff --git a/video/out/cocoa_common.m b/video/out/cocoa_common.m index bab2c41b0d..5e295ec8ef 100644 --- a/video/out/cocoa_common.m +++ b/video/out/cocoa_common.m @@ -810,9 +810,6 @@ static int vo_cocoa_fullscreen(struct vo *vo) return VO_NOTIMPL; [s->window toggleFullScreen:nil]; - // for whatever reason sometimes cocoa doesn't create an up event on - // the fullscreen input key - cocoa_put_key(MP_INPUT_RELEASE_ALL); return VO_TRUE; } @@ -955,11 +952,6 @@ int vo_cocoa_control(struct vo *vo, int *events, int request, void *arg) mp_input_set_mouse_pos(self.vout->input_ctx, point.x, point.y); } -- (void)putKeyEvent:(NSEvent*)event -{ - cocoa_put_key_event(event); -} - - (void)putKey:(int)mpkey withModifiers:(int)modifiers { cocoa_put_key_with_modifiers(mpkey, modifiers); -- cgit v1.2.3