From 9c623237a0965223c78d8544708d7c1bac62d1ec Mon Sep 17 00:00:00 2001 From: Andre Pang Date: Tue, 20 Apr 2004 04:24:52 +0000 Subject: [PATCH] * Mac OS X: intercept and respond to user-configured VLC hotkeys, rather than only responding to shortcut keys which are defined in the .nib interface file --- modules/gui/macosx/intf.h | 1 + modules/gui/macosx/intf.m | 44 +++++++++++++++++++++++++++++++++++++++ modules/gui/macosx/misc.m | 8 +++++++ modules/gui/macosx/vout.m | 6 ++++++ 4 files changed, 59 insertions(+) diff --git a/modules/gui/macosx/intf.h b/modules/gui/macosx/intf.h index 30f763d8eb..6eb88e062c 100644 --- a/modules/gui/macosx/intf.h +++ b/modules/gui/macosx/intf.h @@ -44,6 +44,7 @@ - (void)setIntf:(intf_thread_t *)p_intf; - (intf_thread_t *)getIntf; +- (BOOL)hasDefinedShortcutKey:(NSEvent *)o_event; @end diff --git a/modules/gui/macosx/intf.m b/modules/gui/macosx/intf.m index d8bfb16452..6941b57894 100644 --- a/modules/gui/macosx/intf.m +++ b/modules/gui/macosx/intf.m @@ -212,6 +212,50 @@ static void Run( intf_thread_t *p_intf ) p_intf->p_vlc->b_die = VLC_TRUE; } + +/***************************************************************************** + * hasDefinedShortcutKey: Check to see if the key press is a defined VLC + * shortcut key. If it is, pass it off to VLC for handling and return YES, + * otherwise ignore it and return NO (where it will get handled by Cocoa). + *****************************************************************************/ +- (BOOL)hasDefinedShortcutKey:(NSEvent *)o_event +{ + unichar key = 0; + vlc_value_t val; + unsigned int i_pressed_modifiers = 0; + struct hotkey *p_hotkeys; + int i; + + val.i_int = 0; + p_hotkeys = p_intf->p_vlc->p_hotkeys; + + i_pressed_modifiers = [o_event modifierFlags]; + + if( i_pressed_modifiers & NSShiftKeyMask ) + val.i_int |= KEY_MODIFIER_SHIFT; + if( i_pressed_modifiers & NSControlKeyMask ) + val.i_int |= KEY_MODIFIER_CTRL; + if( i_pressed_modifiers & NSAlternateKeyMask ) + val.i_int |= KEY_MODIFIER_ALT; + if( i_pressed_modifiers & NSCommandKeyMask ) + val.i_int |= KEY_MODIFIER_COMMAND; + + key = [[o_event charactersIgnoringModifiers] characterAtIndex: 0]; + + val.i_int |= CocoaKeyToVLC( key ); + + for( i = 0; p_hotkeys[i].psz_action != NULL; i++ ) + { + if( p_hotkeys[i].i_key == val.i_int ) + { + var_Set( p_intf->p_vlc, "key-pressed", val ); + return YES; + } + } + + return NO; +} + @end int ExecuteOnMainThread( id target, SEL sel, void * p_arg ) diff --git a/modules/gui/macosx/misc.m b/modules/gui/macosx/misc.m index 1eaec9463c..faf4f5bd1e 100644 --- a/modules/gui/macosx/misc.m +++ b/modules/gui/macosx/misc.m @@ -23,6 +23,7 @@ #include +#include "intf.h" /* VLCApplication */ #include "misc.h" #include "playlist.h" @@ -40,6 +41,13 @@ return( self ); } + +- (BOOL)performKeyEquivalent:(NSEvent *)o_event +{ + return [( (VLCApplication *) [VLCApplication sharedApplication] ) + hasDefinedShortcutKey:o_event]; +} + @end diff --git a/modules/gui/macosx/vout.m b/modules/gui/macosx/vout.m index 63cd013f56..ea68589cdc 100644 --- a/modules/gui/macosx/vout.m +++ b/modules/gui/macosx/vout.m @@ -973,6 +973,12 @@ static void QTFreePicture( vout_thread_t *p_vout, picture_t *p_pic ) return( YES ); } +- (BOOL)performKeyEquivalent:(NSEvent *)o_event +{ + return [(VLCApplication *) [VLCApplication sharedApplication] + hasDefinedShortcutKey:o_event]; +} + - (void)keyDown:(NSEvent *)o_event { unichar key = 0; -- 2.39.2