[vlc-commits] macosx: more hotkey improvements

Felix Paul Kühne git at videolan.org
Wed Apr 6 00:10:03 CEST 2011


vlc | branch: master | Felix Paul Kühne <fkuehne at videolan.org> | Wed Apr  6 00:09:50 2011 +0200| [b7e7be200882e350fee3ffffb0afc52900f274ab] | committer: Felix Paul Kühne

macosx: more hotkey improvements

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=b7e7be200882e350fee3ffffb0afc52900f274ab
---

 modules/gui/macosx/intf.h         |    3 ++
 modules/gui/macosx/intf.m         |   67 +++++++++++++++++++++++++++++++-----
 modules/gui/macosx/simple_prefs.m |   17 ++++++++-
 3 files changed, 75 insertions(+), 12 deletions(-)

diff --git a/modules/gui/macosx/intf.h b/modules/gui/macosx/intf.h
index 7097cf1..fd6d264 100644
--- a/modules/gui/macosx/intf.h
+++ b/modules/gui/macosx/intf.h
@@ -337,6 +337,8 @@ struct intf_sys_t
 
     AppleRemote * o_remote;
     BOOL b_remote_button_hold; /* true as long as the user holds the left,right,plus or minus on the remote control */
+
+    NSArray *o_usedHotkeys;
 }
 
 + (VLCMain *)sharedInstance;
@@ -368,6 +370,7 @@ struct intf_sys_t
 - (BOOL)hasDefinedShortcutKey:(NSEvent *)o_event;
 - (NSString *)VLCKeyToString:(NSString *)theString;
 - (unsigned int)VLCModifiersToCocoa:(NSString *)theString;
+- (void)updateCurrentlyUsedHotkeys;
 
 - (void)initStrings;
 
diff --git a/modules/gui/macosx/intf.m b/modules/gui/macosx/intf.m
index 54dc8f9..686ae73 100644
--- a/modules/gui/macosx/intf.m
+++ b/modules/gui/macosx/intf.m
@@ -34,6 +34,7 @@
 #include <vlc_keys.h>
 #include <vlc_dialog.h>
 #include <vlc_url.h>
+#include <vlc_modules.h>
 #include <unistd.h> /* execl() */
 
 #import "intf.h"
@@ -65,6 +66,8 @@ static void Run ( intf_thread_t *p_intf );
 
 static void * ManageThread( void *user_data );
 
+static unsigned int VLCModifiersToCocoa( unsigned int i_key );
+
 static void updateProgressPanel (void *, const char *, float);
 static bool checkProgressPanel (void *);
 static void destroyProgressPanel (void *);
@@ -1325,7 +1328,6 @@ unsigned int CocoaKeyToVLC( unichar i_key )
 
 - (NSString *)VLCKeyToString:(NSString *)theString
 {
-    NSLog( @"got: %@", theString );
     if (![theString isEqualToString:@""]) {
         theString = [theString stringByReplacingOccurrencesOfString:@"Command" withString:@""];
         theString = [theString stringByReplacingOccurrencesOfString:@"Alt" withString:@""];
@@ -1334,7 +1336,6 @@ unsigned int CocoaKeyToVLC( unichar i_key )
         theString = [theString stringByReplacingOccurrencesOfString:@"+" withString:@""];
         theString = [theString stringByReplacingOccurrencesOfString:@"-" withString:@""];
     }
-    NSLog( @"returning: %@", theString );
     return theString;
 }
 
@@ -1351,21 +1352,38 @@ unsigned int CocoaKeyToVLC( unichar i_key )
     unsigned int i_pressed_modifiers = 0;
     const struct hotkey *p_hotkeys;
     int i;
-
+    NSMutableString *tempString = [[[NSMutableString alloc] init] autorelease];
+    NSMutableString *tempStringPlus = [[[NSMutableString alloc] init] autorelease];
+    
     val.i_int = 0;
     p_hotkeys = p_intf->p_libvlc->p_hotkeys;
 
     i_pressed_modifiers = [o_event modifierFlags];
 
-    if( i_pressed_modifiers & NSShiftKeyMask )
+    if( i_pressed_modifiers & NSShiftKeyMask ) {
         val.i_int |= KEY_MODIFIER_SHIFT;
-    if( i_pressed_modifiers & NSControlKeyMask )
+        [tempString appendString:@"Shift-"];
+        [tempStringPlus appendString:@"Shift+"];
+    }
+    if( i_pressed_modifiers & NSControlKeyMask ) {
         val.i_int |= KEY_MODIFIER_CTRL;
-    if( i_pressed_modifiers & NSAlternateKeyMask )
+        [tempString appendString:@"Ctrl-"];
+        [tempStringPlus appendString:@"Ctrl+"];
+    }
+    if( i_pressed_modifiers & NSAlternateKeyMask ) {
         val.i_int |= KEY_MODIFIER_ALT;
-    if( i_pressed_modifiers & NSCommandKeyMask )
+        [tempString appendString:@"Alt-"];
+        [tempStringPlus appendString:@"Alt+"];
+    }
+    if( i_pressed_modifiers & NSCommandKeyMask ) {
         val.i_int |= KEY_MODIFIER_COMMAND;
-
+        [tempString appendString:@"Command-"];
+        [tempStringPlus appendString:@"Command+"];
+    }
+    
+    [tempString appendString:[[o_event charactersIgnoringModifiers] lowercaseString]];
+    [tempStringPlus appendString:[[o_event charactersIgnoringModifiers] lowercaseString]];
+    
     key = [[o_event charactersIgnoringModifiers] characterAtIndex: 0];
 
     switch( key )
@@ -1385,15 +1403,44 @@ unsigned int CocoaKeyToVLC( unichar i_key )
 
     val.i_int |= CocoaKeyToVLC( key );
 
-    if( p_hotkeys[i].psz_action != NULL )
+    if( [o_usedHotkeys indexOfObject: tempString] != NSNotFound || [o_usedHotkeys indexOfObject: tempStringPlus] != NSNotFound )
     {
-        var_SetInteger( p_intf->p_libvlc, "key-pressed", val.i_int );
+        var_Set( p_intf->p_libvlc, "key-pressed", val );
         return YES;
     }
 
     return NO;
 }
 
+- (void)updateCurrentlyUsedHotkeys
+{
+    NSMutableArray *o_tempArray = [[NSMutableArray alloc] init];
+    /* Get the main Module */
+    module_t *p_main = module_get_main();
+    assert( p_main );
+    unsigned confsize;
+    module_config_t *p_config;
+    
+    p_config = module_config_get (p_main, &confsize);
+    
+    for (size_t i = 0; i < confsize; i++)
+    {
+        module_config_t *p_item = p_config + i;
+        
+        if( (p_item->i_type & CONFIG_ITEM) && p_item->psz_name != NULL
+           && !strncmp( p_item->psz_name , "key-", 4 )
+           && !EMPTY_STR( p_item->psz_text ) )
+        {
+            if (p_item->value.psz)
+                [o_tempArray addObject: [NSString stringWithUTF8String:p_item->value.psz]];
+        }
+    }
+    module_config_free (p_config);
+    module_release (p_main);
+    o_usedHotkeys = [[NSArray alloc] initWithArray: o_usedHotkeys copyItems: YES];    
+}
+
+
 #pragma mark -
 #pragma mark Other objects getters
 
diff --git a/modules/gui/macosx/simple_prefs.m b/modules/gui/macosx/simple_prefs.m
index 1e6df8b..10cc5b2 100644
--- a/modules/gui/macosx/simple_prefs.m
+++ b/modules/gui/macosx/simple_prefs.m
@@ -84,6 +84,7 @@ static VLCSimplePrefs *_o_sharedInstance = nil;
         theString = [theString stringByReplacingOccurrencesOfString:@"Ctrl" withString: [NSString stringWithUTF8String: "\xE2\x8C\x83"]];
         theString = [theString stringByReplacingOccurrencesOfString:@"+" withString:@""];
         theString = [theString stringByReplacingOccurrencesOfString:@"-" withString:@""];
+        theString = [theString capitalizedString];
     }
     else
         theString = [NSString stringWithString:_NS("Not Set")];
@@ -104,7 +105,7 @@ static VLCSimplePrefs *_o_sharedInstance = nil;
     [o_sprefs_win setToolbar: o_sprefs_toolbar];
 
     /* setup useful stuff */
-    o_hotkeysNonUseableKeys = [[NSArray arrayWithObjects: @"Command-c", @"Command-x", @"Command-v", @"Command-a", @"Command-," , @"Command-h", @"Command-Alt-h", @"Command-Shift-o", @"Command-o", @"Command-d", @"Command-n", @"Command-s", @"Command-z", @"Command-l", @"Command-r", @"Command-0", @"Command-1", @"Command-2", @"Command-3", @"Command-m", @"Command-w", @"Command-Shift-w", @"Command-Shift-c", @"Command-Shift-p", @"Command-i", @"Command-e", @"Command-Shift-e", @"Command-b", @"Command-Shift-m", @"Command-Ctrl-m", @"Command-?", @"Command-Alt-?", nil] retain];
+    o_hotkeysNonUseableKeys = [[NSArray arrayWithObjects: @"Command-c", @"Command-x", @"Command-v", @"Command-a", @"Command-," , @"Command-h", @"Command-Alt-h", @"Command-Shift-o", @"Command-o", @"Command-d", @"Command-n", @"Command-s", @"Command-z", @"Command-l", @"Command-r", @"Command-3", @"Command-m", @"Command-w", @"Command-Shift-w", @"Command-Shift-c", @"Command-Shift-p", @"Command-i", @"Command-e", @"Command-Shift-e", @"Command-b", @"Command-Shift-m", @"Command-Ctrl-m", @"Command-?", @"Command-Alt-?", nil] retain];
 }
 
 #define CreateToolbarItem( o_name, o_desc, o_img, sel ) \
@@ -1243,6 +1244,11 @@ static inline void save_module_list( intf_thread_t * p_intf, id object, const ch
         i_returnValue = [o_hotkeySettings indexOfObject: o_keyInTransition];
         if( i_returnValue != NSNotFound )
             [o_hotkeySettings replaceObjectAtIndex: i_returnValue withObject: [NSString string]];
+        NSString *tempString;
+        tempString = [o_keyInTransition stringByReplacingOccurrencesOfString:@"-" withString:@"+"];
+        i_returnValue = [o_hotkeySettings indexOfObject: tempString];
+        if( i_returnValue != NSNotFound )
+            [o_hotkeySettings replaceObjectAtIndex: i_returnValue withObject: [NSString string]];
 
         [o_hotkeySettings replaceObjectAtIndex: [o_hotkeys_listbox selectedRow] withObject: [o_keyInTransition retain]];
 
@@ -1284,8 +1290,9 @@ static inline void save_module_list( intf_thread_t * p_intf, id object, const ch
 
 - (BOOL)changeHotkeyTo: (NSString *)theKey
 {
-    NSInteger i_returnValue;
+    NSInteger i_returnValue, i_returnValue2;
     i_returnValue = [o_hotkeysNonUseableKeys indexOfObject: theKey];
+
     if( i_returnValue != NSNotFound || [theKey isEqualToString:@""] )
     {
         [o_hotkeys_change_keys_lbl setStringValue: _NS("Invalid combination")];
@@ -1298,10 +1305,16 @@ static inline void save_module_list( intf_thread_t * p_intf, id object, const ch
         [o_hotkeys_change_keys_lbl setStringValue: [self OSXStringKeyToString:theKey]];
 
         i_returnValue = [o_hotkeySettings indexOfObject: theKey];
+        i_returnValue2 = [o_hotkeySettings indexOfObject: [theKey stringByReplacingOccurrencesOfString:@"-" withString:@"+"]];
         if( i_returnValue != NSNotFound )
             [o_hotkeys_change_taken_lbl setStringValue: [NSString stringWithFormat:
                                                          _NS("This combination is already taken by \"%@\"."),
                                                          [o_hotkeyDescriptions objectAtIndex: i_returnValue]]];
+        else if( i_returnValue2 != NSNotFound )
+            [o_hotkeys_change_taken_lbl setStringValue: [NSString stringWithFormat:
+                                                         _NS("This combination is already taken by \"%@\"."),
+                                                         [o_hotkeyDescriptions objectAtIndex: i_returnValue2]]];
+        
         else
             [o_hotkeys_change_taken_lbl setStringValue: @""];
 



More information about the vlc-commits mailing list