Commit 1536ed21 authored by David Fuhrmann's avatar David Fuhrmann

macosx: several fixes and improvements for hotkey handling

- volume and mute hotkeys are handled by core now, providing a proper osd screen
- some fixes in detection if key combo is valid hotkey
- fix for mem leak
parent f47133cb
...@@ -102,14 +102,39 @@ static VLCMainWindow *_o_sharedInstance = nil; ...@@ -102,14 +102,39 @@ static VLCMainWindow *_o_sharedInstance = nil;
return self; return self;
} }
- (BOOL)isEvent:(NSEvent *)o_event forKey:(const char *)keyString
{
char *key;
NSString *o_key;
key = config_GetPsz( VLCIntf, keyString );
o_key = [NSString stringWithFormat:@"%s", key];
FREENULL( key );
unsigned int i_keyModifiers = [[VLCMain sharedInstance] VLCModifiersToCocoa:o_key];
return [[[o_event charactersIgnoringModifiers] lowercaseString] isEqualToString: [[VLCMain sharedInstance] VLCKeyToString: o_key]] &&
(i_keyModifiers & NSShiftKeyMask) == ([o_event modifierFlags] & NSShiftKeyMask) &&
(i_keyModifiers & NSControlKeyMask) == ([o_event modifierFlags] & NSControlKeyMask) &&
(i_keyModifiers & NSAlternateKeyMask) == ([o_event modifierFlags] & NSAlternateKeyMask) &&
(i_keyModifiers & NSCommandKeyMask) == ([o_event modifierFlags] & NSCommandKeyMask);
}
- (BOOL)performKeyEquivalent:(NSEvent *)o_event - (BOOL)performKeyEquivalent:(NSEvent *)o_event
{ {
/* We indeed want to prioritize Cocoa key equivalent against libvlc, // these are key events which should be handled by vlc core, but are attached to a main menu item
so we perform the menu equivalent now. */ if( ![self isEvent: o_event forKey: "key-vol-up"] &&
if([[NSApp mainMenu] performKeyEquivalent:o_event]) ![self isEvent: o_event forKey: "key-vol-down"] &&
return TRUE; ![self isEvent: o_event forKey: "key-vol-mute"] )
{
/* We indeed want to prioritize some Cocoa key equivalent against libvlc,
so we perform the menu equivalent now. */
if([[NSApp mainMenu] performKeyEquivalent:o_event])
return TRUE;
}
return [[VLCMain sharedInstance] hasDefinedShortcutKey:o_event] || [(VLCControls *)[[VLCMain sharedInstance] controls] keyEvent:o_event]; return [[VLCMain sharedInstance] hasDefinedShortcutKey:o_event] ||
[(VLCControls *)[[VLCMain sharedInstance] controls] keyEvent:o_event];
} }
- (void)dealloc - (void)dealloc
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#import "VideoView.h" #import "VideoView.h"
#import "CoreInteraction.h" #import "CoreInteraction.h"
#import "MainMenu.h" #import "MainMenu.h"
#import "MainWindow.h"
#import <vlc_common.h> #import <vlc_common.h>
#import <vlc_keys.h> #import <vlc_keys.h>
...@@ -174,6 +175,11 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, ...@@ -174,6 +175,11 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
[super keyDown: o_event]; [super keyDown: o_event];
} }
- (BOOL)performKeyEquivalent:(NSEvent *)o_event
{
return [[VLCMainWindow sharedInstance] performKeyEquivalent: o_event];
}
- (void)mouseDown:(NSEvent *)o_event - (void)mouseDown:(NSEvent *)o_event
{ {
if( ( [o_event type] == NSLeftMouseDown ) && if( ( [o_event type] == NSLeftMouseDown ) &&
......
...@@ -802,6 +802,8 @@ static VLCMain *_o_sharedMainInstance = nil; ...@@ -802,6 +802,8 @@ static VLCMain *_o_sharedMainInstance = nil;
[o_msg_arr removeAllObjects]; [o_msg_arr removeAllObjects];
[o_msg_arr release]; [o_msg_arr release];
o_msg_arr = NULL; o_msg_arr = NULL;
[o_usedHotkeys release];
o_usedHotkeys = NULL;
[o_msg_lock release]; [o_msg_lock release];
...@@ -1309,88 +1311,81 @@ unsigned int CocoaKeyToVLC( unichar i_key ) ...@@ -1309,88 +1311,81 @@ unsigned int CocoaKeyToVLC( unichar i_key )
unichar key = 0; unichar key = 0;
vlc_value_t val; vlc_value_t val;
unsigned int i_pressed_modifiers = 0; unsigned int i_pressed_modifiers = 0;
const struct hotkey *p_hotkeys;
int i;
NSMutableString *tempString = [[NSMutableString alloc] init];
NSMutableString *tempStringPlus = [[NSMutableString alloc] init];
val.i_int = 0; val.i_int = 0;
p_hotkeys = p_intf->p_libvlc->p_hotkeys;
i_pressed_modifiers = [o_event modifierFlags]; i_pressed_modifiers = [o_event modifierFlags];
if( i_pressed_modifiers & NSShiftKeyMask ) {
val.i_int |= KEY_MODIFIER_SHIFT;
[tempString appendString:@"Shift-"];
[tempStringPlus appendString:@"Shift+"];
}
if( i_pressed_modifiers & NSControlKeyMask ) { if( i_pressed_modifiers & NSControlKeyMask ) {
val.i_int |= KEY_MODIFIER_CTRL; val.i_int |= KEY_MODIFIER_CTRL;
[tempString appendString:@"Ctrl-"];
[tempStringPlus appendString:@"Ctrl+"];
} }
if( i_pressed_modifiers & NSAlternateKeyMask ) { if( i_pressed_modifiers & NSAlternateKeyMask ) {
val.i_int |= KEY_MODIFIER_ALT; val.i_int |= KEY_MODIFIER_ALT;
[tempString appendString:@"Alt-"]; }
[tempStringPlus appendString:@"Alt+"]; if( i_pressed_modifiers & NSShiftKeyMask ) {
val.i_int |= KEY_MODIFIER_SHIFT;
} }
if( i_pressed_modifiers & NSCommandKeyMask ) { if( i_pressed_modifiers & NSCommandKeyMask ) {
val.i_int |= KEY_MODIFIER_COMMAND; 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]; key = [[o_event charactersIgnoringModifiers] characterAtIndex: 0];
/* handle Lion's default key combo for fullscreen-toggle in addition to our own hotkeys */ /* handle Lion's default key combo for fullscreen-toggle in addition to our own hotkeys */
if( key == 'f' && i_pressed_modifiers & NSControlKeyMask && i_pressed_modifiers & NSCommandKeyMask ) if( key == 'f' && i_pressed_modifiers & NSControlKeyMask && i_pressed_modifiers & NSCommandKeyMask )
{ {
[[VLCCoreInteraction sharedInstance] toggleFullscreen]; [[VLCCoreInteraction sharedInstance] toggleFullscreen];
[tempString release];
[tempStringPlus release];
return YES; return YES;
} }
switch( key ) if( val.i_int == 0 ) // ignore only when no modifier is pressed
{ {
case NSDeleteCharacter: switch( key )
case NSDeleteFunctionKey: {
case NSDeleteCharFunctionKey: case NSDeleteCharacter:
case NSBackspaceCharacter: case NSDeleteFunctionKey:
case NSUpArrowFunctionKey: case NSDeleteCharFunctionKey:
case NSDownArrowFunctionKey: case NSBackspaceCharacter:
case NSRightArrowFunctionKey: case NSUpArrowFunctionKey:
case NSLeftArrowFunctionKey: case NSDownArrowFunctionKey:
case NSEnterCharacter: case NSRightArrowFunctionKey:
case NSCarriageReturnCharacter: case NSLeftArrowFunctionKey:
[tempString release]; case NSEnterCharacter:
[tempStringPlus release]; case NSCarriageReturnCharacter:
return NO; return NO;
}
} }
if( key == 0x0020 ) // space key if( key == 0x0020 ) // space key
{ {
[[VLCCoreInteraction sharedInstance] play]; [[VLCCoreInteraction sharedInstance] play];
[tempString release];
[tempStringPlus release];
return YES; return YES;
} }
val.i_int |= CocoaKeyToVLC( key ); val.i_int |= CocoaKeyToVLC( key );
if( [o_usedHotkeys indexOfObject: tempString] != NSNotFound || [o_usedHotkeys indexOfObject: tempStringPlus] != NSNotFound ) BOOL b_found_key = NO;
for( int i = 0; i < [o_usedHotkeys count]; i++ )
{
NSString *str = [o_usedHotkeys objectAtIndex: i];
unsigned int i_keyModifiers = [self VLCModifiersToCocoa: str];
if( [[[o_event charactersIgnoringModifiers] lowercaseString] isEqualToString: [self VLCKeyToString: str]] &&
(i_keyModifiers & NSShiftKeyMask) == (i_pressed_modifiers & NSShiftKeyMask) &&
(i_keyModifiers & NSControlKeyMask) == (i_pressed_modifiers & NSControlKeyMask) &&
(i_keyModifiers & NSAlternateKeyMask) == (i_pressed_modifiers & NSAlternateKeyMask) &&
(i_keyModifiers & NSCommandKeyMask) == (i_pressed_modifiers & NSCommandKeyMask) )
{
b_found_key = YES;
break;
}
}
if( b_found_key )
{ {
var_SetInteger( p_intf->p_libvlc, "key-pressed", val.i_int ); var_SetInteger( p_intf->p_libvlc, "key-pressed", val.i_int );
[tempString release];
[tempStringPlus release];
return YES; return YES;
} }
[tempString release];
[tempStringPlus release];
return NO; return NO;
} }
...@@ -1414,10 +1409,15 @@ unsigned int CocoaKeyToVLC( unichar i_key ) ...@@ -1414,10 +1409,15 @@ unsigned int CocoaKeyToVLC( unichar i_key )
&& !EMPTY_STR( p_item->psz_text ) ) && !EMPTY_STR( p_item->psz_text ) )
{ {
if (p_item->value.psz) if (p_item->value.psz)
{
[o_tempArray addObject: [NSString stringWithUTF8String:p_item->value.psz]]; [o_tempArray addObject: [NSString stringWithUTF8String:p_item->value.psz]];
}
} }
} }
module_config_free (p_config); module_config_free (p_config);
if( o_usedHotkeys )
[o_usedHotkeys release];
o_usedHotkeys = [[NSArray alloc] initWithArray: o_tempArray copyItems: YES]; o_usedHotkeys = [[NSArray alloc] initWithArray: o_tempArray copyItems: YES];
[o_tempArray release]; [o_tempArray release];
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment