]> git.sesse.net Git - vlc/commitdiff
* Mac OS X: intercept and respond to user-configured VLC hotkeys, rather
authorAndre Pang <andrep@videolan.org>
Tue, 20 Apr 2004 04:24:52 +0000 (04:24 +0000)
committerAndre Pang <andrep@videolan.org>
Tue, 20 Apr 2004 04:24:52 +0000 (04:24 +0000)
  than only responding to shortcut keys which are defined in the .nib
  interface file

modules/gui/macosx/intf.h
modules/gui/macosx/intf.m
modules/gui/macosx/misc.m
modules/gui/macosx/vout.m

index 30f763d8eb58a231e10844344360ebbc77428848..6eb88e062c52d1df31ebcf08775b6df9cfe2e198 100644 (file)
@@ -44,6 +44,7 @@
 
 - (void)setIntf:(intf_thread_t *)p_intf;
 - (intf_thread_t *)getIntf;
+- (BOOL)hasDefinedShortcutKey:(NSEvent *)o_event;
 
 @end
 
index d8bfb1645286d7a085484597be810f46e1bb072c..6941b578942b57ce9508df93ea43031408d9e434 100644 (file)
@@ -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 )
index 1eaec9463cbc1fa1531cdfb6f95777950b68515c..faf4f5bd1ed3f9c9ad44db26dfdebf9e4c0d1e27 100644 (file)
@@ -23,6 +23,7 @@
 
 #include <Cocoa/Cocoa.h>
 
+#include "intf.h"                                          /* VLCApplication */
 #include "misc.h"
 #include "playlist.h"
 
 
     return( self );
 }
+
+- (BOOL)performKeyEquivalent:(NSEvent *)o_event
+{
+    return [( (VLCApplication *) [VLCApplication sharedApplication] )
+            hasDefinedShortcutKey:o_event];
+}
+
 @end
 
 
index 63cd013f568ec4023f7b211bcdef56d38905fedd..ea68589cdcb4e8da5c61a6050ace0b0bb464a041 100644 (file)
@@ -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;