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;
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);
NSString * characters = [o_event charactersIgnoringModifiers];
if ([characters length] > 0) {
return [[characters 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);
}
return NO;
}
- (BOOL)performKeyEquivalent:(NSEvent *)o_event
......@@ -2846,7 +2850,7 @@ static VLCMainWindow *_o_sharedInstance = nil;
if( [o_attribute_name isEqualTo: NSAccessibilityMinimizeButtonAttribute] )
return [[o_tbv minimizeButton] cell];
if( [o_attribute_name isEqualTo: NSAccessibilityZoomButtonAttribute] )
return [[o_tbv zoomButton] cell];
}
......@@ -3062,7 +3066,7 @@ static VLCMainWindow *_o_sharedInstance = nil;
{
if( !b_dark_interface )
return [super accessibilityAttributeNames];
static NSMutableArray *attributes = nil;
if ( attributes == nil ) {
attributes = [[super accessibilityAttributeNames] mutableCopy];
......@@ -3071,7 +3075,7 @@ static VLCMainWindow *_o_sharedInstance = nil;
NSAccessibilityMinimizeButtonAttribute,
NSAccessibilityZoomButtonAttribute,
nil];
for( NSString *attribute in appendAttributes )
{
if( ![attributes containsObject:attribute] )
......@@ -3086,20 +3090,20 @@ static VLCMainWindow *_o_sharedInstance = nil;
if( b_dark_interface )
{
VLCMainWindowTitleView *o_tbv = [[VLCMainWindow sharedInstance] detachedTitlebarView];
if( [o_attribute_name isEqualTo: NSAccessibilitySubroleAttribute] )
return NSAccessibilityStandardWindowSubrole;
if( [o_attribute_name isEqualTo: NSAccessibilityCloseButtonAttribute] )
return [[o_tbv closeButton] cell];
if( [o_attribute_name isEqualTo: NSAccessibilityMinimizeButtonAttribute] )
return [[o_tbv minimizeButton] cell];
if( [o_attribute_name isEqualTo: NSAccessibilityZoomButtonAttribute] )
return [[o_tbv zoomButton] cell];
}
return [super accessibilityAttributeValue: o_attribute_name];
}
......
......@@ -142,41 +142,46 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
if( i_pressed_modifiers & NSCommandKeyMask )
val.i_int |= KEY_MODIFIER_COMMAND;
key = [[[o_event charactersIgnoringModifiers] lowercaseString] characterAtIndex: 0];
if( key )
NSString * characters = [o_event charactersIgnoringModifiers];
if ([characters length] > 0)
{
vout_thread_t * p_vout = getVout();
/* Escape should always get you out of fullscreen */
if( key == (unichar) 0x1b )
{
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 )
key = [[characters lowercaseString] characterAtIndex: 0];
if( key )
{
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 );
var_Set( p_vout->p_libvlc, "key-pressed", val );
if( key == ' ' )
{
[[VLCCoreInteraction sharedInstance] play];
}
else
{
val.i_int |= (int)CocoaKeyToVLC( key );
var_Set( p_vout->p_libvlc, "key-pressed", val );
}
}
}
else
msg_Dbg( VLCIntf, "could not send keyevent to VLC core" );
else
msg_Dbg( VLCIntf, "could not send keyevent to VLC core" );
if (p_vout)
vlc_object_release( p_vout );
if (p_vout)
vlc_object_release( p_vout );
return;
}
}
else
[super keyDown: o_event];
[super keyDown: o_event];
}
- (BOOL)performKeyEquivalent:(NSEvent *)o_event
......
......@@ -345,34 +345,38 @@
- (BOOL)keyEvent:(NSEvent *)o_event
{
BOOL eventHandled = NO;
unichar key = [[o_event charactersIgnoringModifiers] characterAtIndex: 0];
if( key )
NSString * characters = [o_event charactersIgnoringModifiers];
if ([characters length] > 0)
{
input_thread_t * p_input = pl_CurrentInput( VLCIntf );
if( p_input != NULL )
{
vout_thread_t *p_vout = input_GetVout( p_input );
unichar key = [characters characterAtIndex: 0];
if( p_vout != NULL )
if( key )
{
input_thread_t * p_input = pl_CurrentInput( VLCIntf );
if( p_input != NULL )
{
/* Escape */
if( key == (unichar) 0x1b )
vout_thread_t *p_vout = input_GetVout( p_input );
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;
}
vlc_object_release( p_vout );
}
else if( key == ' ' )
{
[self play:self];
eventHandled = YES;
}
vlc_object_release( p_vout );
vlc_object_release( p_input );
}
vlc_object_release( p_input );
}
}
return eventHandled;
......
......@@ -1350,62 +1350,66 @@ unsigned int CocoaKeyToVLC( unichar i_key )
val.i_int |= KEY_MODIFIER_COMMAND;
}
key = [[[o_event charactersIgnoringModifiers] lowercaseString] characterAtIndex: 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 )
NSString * characters = [o_event charactersIgnoringModifiers];
if ([characters length] > 0)
{
[[VLCCoreInteraction sharedInstance] toggleFullscreen];
return YES;
}
key = [[characters lowercaseString] characterAtIndex: 0];
if( !b_force )
{
switch( key )
/* 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 )
{
case NSDeleteCharacter:
case NSDeleteFunctionKey:
case NSDeleteCharFunctionKey:
case NSBackspaceCharacter:
case NSUpArrowFunctionKey:
case NSDownArrowFunctionKey:
case NSRightArrowFunctionKey:
case NSLeftArrowFunctionKey:
case NSEnterCharacter:
case NSCarriageReturnCharacter:
return NO;
[[VLCCoreInteraction sharedInstance] toggleFullscreen];
return YES;
}
}
if( key == 0x0020 ) // space key
{
[[VLCCoreInteraction sharedInstance] play];
return YES;
}
if( !b_force )
{
switch( key )
{
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;
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) )
BOOL b_found_key = NO;
for( int i = 0; i < [o_usedHotkeys count]; i++ )
{
b_found_key = YES;
break;
NSString *str = [o_usedHotkeys objectAtIndex: i];
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 )
{
var_SetInteger( p_intf->p_libvlc, "key-pressed", val.i_int );
return YES;
if( b_found_key )
{
var_SetInteger( p_intf->p_libvlc, "key-pressed", val.i_int );
return YES;
}
}
return NO;
......@@ -1487,10 +1491,10 @@ unsigned int CocoaKeyToVLC( unichar i_key )
- (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 )
{
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