Commit c97faddc authored by Felix Paul Kühne's avatar Felix Paul Kühne

macosx: fixed NSRangeException when triggering modifier keys without...

macosx: fixed NSRangeException when triggering modifier keys without characters as enabled by some international keyboards (close #7268)
parent 001a7f6e
...@@ -114,11 +114,15 @@ static VLCMainWindow *_o_sharedInstance = nil; ...@@ -114,11 +114,15 @@ static VLCMainWindow *_o_sharedInstance = nil;
unsigned int i_keyModifiers = [[VLCMain sharedInstance] VLCModifiersToCocoa:o_key]; unsigned int i_keyModifiers = [[VLCMain sharedInstance] VLCModifiersToCocoa:o_key];
return [[[o_event charactersIgnoringModifiers] lowercaseString] isEqualToString: [[VLCMain sharedInstance] VLCKeyToString: o_key]] && NSString * characters = [o_event charactersIgnoringModifiers];
(i_keyModifiers & NSShiftKeyMask) == ([o_event modifierFlags] & NSShiftKeyMask) && if ([characters length] > 0) {
(i_keyModifiers & NSControlKeyMask) == ([o_event modifierFlags] & NSControlKeyMask) && return [[characters lowercaseString] isEqualToString: [[VLCMain sharedInstance] VLCKeyToString: o_key]] &&
(i_keyModifiers & NSAlternateKeyMask) == ([o_event modifierFlags] & NSAlternateKeyMask) && (i_keyModifiers & NSShiftKeyMask) == ([o_event modifierFlags] & NSShiftKeyMask) &&
(i_keyModifiers & NSCommandKeyMask) == ([o_event modifierFlags] & NSCommandKeyMask); (i_keyModifiers & NSControlKeyMask) == ([o_event modifierFlags] & NSControlKeyMask) &&
(i_keyModifiers & NSAlternateKeyMask) == ([o_event modifierFlags] & NSAlternateKeyMask) &&
(i_keyModifiers & NSCommandKeyMask) == ([o_event modifierFlags] & NSCommandKeyMask);
}
return NO;
} }
- (BOOL)performKeyEquivalent:(NSEvent *)o_event - (BOOL)performKeyEquivalent:(NSEvent *)o_event
...@@ -2846,7 +2850,7 @@ static VLCMainWindow *_o_sharedInstance = nil; ...@@ -2846,7 +2850,7 @@ static VLCMainWindow *_o_sharedInstance = nil;
if( [o_attribute_name isEqualTo: NSAccessibilityMinimizeButtonAttribute] ) if( [o_attribute_name isEqualTo: NSAccessibilityMinimizeButtonAttribute] )
return [[o_tbv minimizeButton] cell]; return [[o_tbv minimizeButton] cell];
if( [o_attribute_name isEqualTo: NSAccessibilityZoomButtonAttribute] ) if( [o_attribute_name isEqualTo: NSAccessibilityZoomButtonAttribute] )
return [[o_tbv zoomButton] cell]; return [[o_tbv zoomButton] cell];
} }
...@@ -3062,7 +3066,7 @@ static VLCMainWindow *_o_sharedInstance = nil; ...@@ -3062,7 +3066,7 @@ static VLCMainWindow *_o_sharedInstance = nil;
{ {
if( !b_dark_interface ) if( !b_dark_interface )
return [super accessibilityAttributeNames]; return [super accessibilityAttributeNames];
static NSMutableArray *attributes = nil; static NSMutableArray *attributes = nil;
if ( attributes == nil ) { if ( attributes == nil ) {
attributes = [[super accessibilityAttributeNames] mutableCopy]; attributes = [[super accessibilityAttributeNames] mutableCopy];
...@@ -3071,7 +3075,7 @@ static VLCMainWindow *_o_sharedInstance = nil; ...@@ -3071,7 +3075,7 @@ static VLCMainWindow *_o_sharedInstance = nil;
NSAccessibilityMinimizeButtonAttribute, NSAccessibilityMinimizeButtonAttribute,
NSAccessibilityZoomButtonAttribute, NSAccessibilityZoomButtonAttribute,
nil]; nil];
for( NSString *attribute in appendAttributes ) for( NSString *attribute in appendAttributes )
{ {
if( ![attributes containsObject:attribute] ) if( ![attributes containsObject:attribute] )
...@@ -3086,20 +3090,20 @@ static VLCMainWindow *_o_sharedInstance = nil; ...@@ -3086,20 +3090,20 @@ static VLCMainWindow *_o_sharedInstance = nil;
if( b_dark_interface ) if( b_dark_interface )
{ {
VLCMainWindowTitleView *o_tbv = [[VLCMainWindow sharedInstance] detachedTitlebarView]; VLCMainWindowTitleView *o_tbv = [[VLCMainWindow sharedInstance] detachedTitlebarView];
if( [o_attribute_name isEqualTo: NSAccessibilitySubroleAttribute] ) if( [o_attribute_name isEqualTo: NSAccessibilitySubroleAttribute] )
return NSAccessibilityStandardWindowSubrole; return NSAccessibilityStandardWindowSubrole;
if( [o_attribute_name isEqualTo: NSAccessibilityCloseButtonAttribute] ) if( [o_attribute_name isEqualTo: NSAccessibilityCloseButtonAttribute] )
return [[o_tbv closeButton] cell]; return [[o_tbv closeButton] cell];
if( [o_attribute_name isEqualTo: NSAccessibilityMinimizeButtonAttribute] ) if( [o_attribute_name isEqualTo: NSAccessibilityMinimizeButtonAttribute] )
return [[o_tbv minimizeButton] cell]; return [[o_tbv minimizeButton] cell];
if( [o_attribute_name isEqualTo: NSAccessibilityZoomButtonAttribute] ) if( [o_attribute_name isEqualTo: NSAccessibilityZoomButtonAttribute] )
return [[o_tbv zoomButton] cell]; return [[o_tbv zoomButton] cell];
} }
return [super accessibilityAttributeValue: o_attribute_name]; return [super accessibilityAttributeValue: o_attribute_name];
} }
......
...@@ -142,41 +142,46 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, ...@@ -142,41 +142,46 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
if( i_pressed_modifiers & NSCommandKeyMask ) if( i_pressed_modifiers & NSCommandKeyMask )
val.i_int |= KEY_MODIFIER_COMMAND; val.i_int |= KEY_MODIFIER_COMMAND;
key = [[[o_event charactersIgnoringModifiers] lowercaseString] characterAtIndex: 0]; NSString * characters = [o_event charactersIgnoringModifiers];
if ([characters length] > 0)
if( key )
{ {
vout_thread_t * p_vout = getVout(); key = [[characters lowercaseString] characterAtIndex: 0];
/* Escape should always get you out of fullscreen */
if( key == (unichar) 0x1b ) if( key )
{
playlist_t * p_playlist = pl_Get( VLCIntf );
if( var_GetBool( p_playlist, "fullscreen" ) )
[[VLCCoreInteraction sharedInstance] toggleFullscreen];
}
/* handle Lion's default key combo for fullscreen-toggle in addition to our own hotkeys */
else if( key == 'f' && i_pressed_modifiers & NSControlKeyMask && i_pressed_modifiers & NSCommandKeyMask )
[[VLCCoreInteraction sharedInstance] toggleFullscreen];
else if ( p_vout )
{ {
if( key == ' ' ) vout_thread_t * p_vout = getVout();
/* Escape should always get you out of fullscreen */
if( key == (unichar) 0x1b )
{ {
[[VLCCoreInteraction sharedInstance] play]; playlist_t * p_playlist = pl_Get( VLCIntf );
if( var_GetBool( p_playlist, "fullscreen") )
[[VLCCoreInteraction sharedInstance] toggleFullscreen];
} }
else /* handle Lion's default key combo for fullscreen-toggle in addition to our own hotkeys */
else if( key == 'f' && i_pressed_modifiers & NSControlKeyMask && i_pressed_modifiers & NSCommandKeyMask )
[[VLCCoreInteraction sharedInstance] toggleFullscreen];
else if ( p_vout )
{ {
val.i_int |= (int)CocoaKeyToVLC( key ); if( key == ' ' )
var_Set( p_vout->p_libvlc, "key-pressed", val ); {
[[VLCCoreInteraction sharedInstance] play];
}
else
{
val.i_int |= (int)CocoaKeyToVLC( key );
var_Set( p_vout->p_libvlc, "key-pressed", val );
}
} }
} else
else msg_Dbg( VLCIntf, "could not send keyevent to VLC core" );
msg_Dbg( VLCIntf, "could not send keyevent to VLC core" );
if (p_vout) if (p_vout)
vlc_object_release( p_vout ); vlc_object_release( p_vout );
return;
}
} }
else [super keyDown: o_event];
[super keyDown: o_event];
} }
- (BOOL)performKeyEquivalent:(NSEvent *)o_event - (BOOL)performKeyEquivalent:(NSEvent *)o_event
......
...@@ -345,34 +345,38 @@ ...@@ -345,34 +345,38 @@
- (BOOL)keyEvent:(NSEvent *)o_event - (BOOL)keyEvent:(NSEvent *)o_event
{ {
BOOL eventHandled = NO; BOOL eventHandled = NO;
unichar key = [[o_event charactersIgnoringModifiers] characterAtIndex: 0]; NSString * characters = [o_event charactersIgnoringModifiers];
if ([characters length] > 0)
if( key )
{ {
input_thread_t * p_input = pl_CurrentInput( VLCIntf ); unichar key = [characters characterAtIndex: 0];
if( p_input != NULL )
{
vout_thread_t *p_vout = input_GetVout( p_input );
if( p_vout != NULL ) if( key )
{
input_thread_t * p_input = pl_CurrentInput( VLCIntf );
if( p_input != NULL )
{ {
/* Escape */ vout_thread_t *p_vout = input_GetVout( p_input );
if( key == (unichar) 0x1b )
if( p_vout != NULL )
{ {
if (var_GetBool( p_vout, "fullscreen" )) /* Escape */
if( key == (unichar) 0x1b )
{ {
[[VLCCoreInteraction sharedInstance] toggleFullscreen]; if (var_GetBool( p_vout, "fullscreen" ))
{
[[VLCCoreInteraction sharedInstance] toggleFullscreen];
eventHandled = YES;
}
}
else if( key == ' ' )
{
[self play:self];
eventHandled = YES; eventHandled = YES;
} }
vlc_object_release( p_vout );
} }
else if( key == ' ' ) vlc_object_release( p_input );
{
[self play:self];
eventHandled = YES;
}
vlc_object_release( p_vout );
} }
vlc_object_release( p_input );
} }
} }
return eventHandled; return eventHandled;
......
...@@ -1350,62 +1350,66 @@ unsigned int CocoaKeyToVLC( unichar i_key ) ...@@ -1350,62 +1350,66 @@ unsigned int CocoaKeyToVLC( unichar i_key )
val.i_int |= KEY_MODIFIER_COMMAND; val.i_int |= KEY_MODIFIER_COMMAND;
} }
key = [[[o_event charactersIgnoringModifiers] lowercaseString] characterAtIndex: 0]; NSString * characters = [o_event charactersIgnoringModifiers];
if ([characters length] > 0)
/* 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 )
{ {
[[VLCCoreInteraction sharedInstance] toggleFullscreen]; key = [[characters lowercaseString] characterAtIndex: 0];
return YES;
}
if( !b_force ) /* 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 )
switch( key )
{ {
case NSDeleteCharacter: [[VLCCoreInteraction sharedInstance] toggleFullscreen];
case NSDeleteFunctionKey: return YES;
case NSDeleteCharFunctionKey:
case NSBackspaceCharacter:
case NSUpArrowFunctionKey:
case NSDownArrowFunctionKey:
case NSRightArrowFunctionKey:
case NSLeftArrowFunctionKey:
case NSEnterCharacter:
case NSCarriageReturnCharacter:
return NO;
} }
}
if( key == 0x0020 ) // space key if( !b_force )
{ {
[[VLCCoreInteraction sharedInstance] play]; switch( key )
return YES; {
} case NSDeleteCharacter:
case NSDeleteFunctionKey:
case NSDeleteCharFunctionKey:
case NSBackspaceCharacter:
case NSUpArrowFunctionKey:
case NSDownArrowFunctionKey:
case NSRightArrowFunctionKey:
case NSLeftArrowFunctionKey:
case NSEnterCharacter:
case NSCarriageReturnCharacter:
return NO;
}
}
if( key == 0x0020 ) // space key
{
[[VLCCoreInteraction sharedInstance] play];
return YES;
}
val.i_int |= CocoaKeyToVLC( key ); val.i_int |= CocoaKeyToVLC( key );
BOOL b_found_key = NO; BOOL b_found_key = NO;
for( int i = 0; i < [o_usedHotkeys count]; i++ ) 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; NSString *str = [o_usedHotkeys objectAtIndex: i];
break; unsigned int i_keyModifiers = [self VLCModifiersToCocoa: str];
if( [[characters 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 ) 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 );
return YES; return YES;
}
} }
return NO; return NO;
...@@ -1487,10 +1491,10 @@ unsigned int CocoaKeyToVLC( unichar i_key ) ...@@ -1487,10 +1491,10 @@ unsigned int CocoaKeyToVLC( unichar i_key )
- (void)checkFullscreenChange:(NSNumber *)o_full - (void)checkFullscreenChange:(NSNumber *)o_full
{ {
BOOL b_full = [o_full boolValue]; BOOL b_full = [o_full boolValue];
if( p_intf && !var_GetBool( pl_Get( p_intf ), "fullscreen" ) != !b_full ) if( p_intf && !var_GetBool( pl_Get( p_intf ), "fullscreen" ) != !b_full )
{ {
var_SetBool( pl_Get(p_intf), "fullscreen", b_full ); var_SetBool( pl_Get(p_intf), "fullscreen", b_full );
} }
} }
......
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