Commit 6325b1c3 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)
(cherry picked from commit c97faddc527a0455c93419982b23763a3d6485d8)

Conflicts:
	modules/gui/macosx/MainWindow.m
	modules/gui/macosx/intf.m
parent c772af6d
......@@ -113,11 +113,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
......@@ -750,7 +754,7 @@ static VLCMainWindow *_o_sharedInstance = nil;
[o_split_view setHidden: YES];
[o_video_view setHidden: NO];
if( [[o_video_view subviews] count] > 0 )
[self makeFirstResponder: [[o_video_view subviews] objectAtIndex:0]];
}
......@@ -821,7 +825,7 @@ static VLCMainWindow *_o_sharedInstance = nil;
- (void)setRepeatOne
{
[o_repeat_btn setImage: o_repeat_one_img];
[o_repeat_btn setAlternateImage: o_repeat_one_pressed_img];
[o_repeat_btn setAlternateImage: o_repeat_one_pressed_img];
}
- (void)setRepeatAll
......@@ -1026,7 +1030,7 @@ static VLCMainWindow *_o_sharedInstance = nil;
* which will fit inside the screen.
*
* This method is based upon NSWindow.m, part of the GNUstep GUI Library, licensed under LGPLv2+.
* Authors: Scott Christley <scottc@net-community.com>, Venkat Ajjanagadde <venkat@ocbi.com>,
* Authors: Scott Christley <scottc@net-community.com>, Venkat Ajjanagadde <venkat@ocbi.com>,
* Felipe A. Rodriguez <far@ix.netcom.com>, Richard Frith-Macdonald <richard@brainstorm.co.uk>
* Copyright (C) 1996 Free Software Foundation, Inc.
*/
......@@ -1052,7 +1056,7 @@ static VLCMainWindow *_o_sharedInstance = nil;
difference2 = screenRect.origin.y - frameRect.origin.y;
difference2 -= difference;
// Take in account the space between the top of window and the top of the
// Take in account the space between the top of window and the top of the
// screen which can be used to move the bottom of the window on the screen
if (difference2 > 0)
{
......@@ -1080,7 +1084,7 @@ static VLCMainWindow *_o_sharedInstance = nil;
be allowed to zoom to full screen.
*
* This method is based upon NSWindow.m, part of the GNUstep GUI Library, licensed under LGPLv2+.
* Authors: Scott Christley <scottc@net-community.com>, Venkat Ajjanagadde <venkat@ocbi.com>,
* Authors: Scott Christley <scottc@net-community.com>, Venkat Ajjanagadde <venkat@ocbi.com>,
* Felipe A. Rodriguez <far@ix.netcom.com>, Richard Frith-Macdonald <richard@brainstorm.co.uk>
* Copyright (C) 1996 Free Software Foundation, Inc.
*/
......@@ -1163,7 +1167,7 @@ static VLCMainWindow *_o_sharedInstance = nil;
// needed when entering lion fullscreen mode
if( b_fullscreen )
return proposedFrameSize;
if( [[VLCCoreInteraction sharedInstance] aspectRatioIsLocked] )
{
NSRect videoWindowFrame = [videoWindow frame];
......@@ -2163,14 +2167,14 @@ static VLCMainWindow *_o_sharedInstance = nil;
[NSApp setPresentationOptions:(NSApplicationPresentationFullScreen | NSApplicationPresentationAutoHideDock | NSApplicationPresentationAutoHideMenuBar)];
var_SetBool( pl_Get( VLCIntf ), "fullscreen", true );
vout_thread_t *p_vout = getVout();
if( p_vout )
{
var_SetBool( p_vout, "fullscreen", true );
vlc_object_release( p_vout );
}
[o_video_view setFrame: [[self contentView] frame]];
b_fullscreen = YES;
......@@ -2195,7 +2199,7 @@ static VLCMainWindow *_o_sharedInstance = nil;
if ([[VLCMain sharedInstance] activeVideoPlayback])
[o_bottombar_view setHidden: YES];
[self setMovableByWindowBackground: NO];
}
......@@ -2213,7 +2217,7 @@ static VLCMainWindow *_o_sharedInstance = nil;
{
var_SetBool( pl_Get( VLCIntf ), "fullscreen", false );
vout_thread_t *p_vout = getVout();
if( p_vout )
{
......@@ -2247,7 +2251,7 @@ static VLCMainWindow *_o_sharedInstance = nil;
if ([[VLCMain sharedInstance] activeVideoPlayback])
[o_bottombar_view setHidden: NO];
[self setMovableByWindowBackground: YES];
}
......@@ -2594,7 +2598,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];
}
......@@ -2712,7 +2716,7 @@ static VLCMainWindow *_o_sharedInstance = nil;
* which will fit inside the screen.
*
* This method is based upon NSWindow.m, part of the GNUstep GUI Library, licensed under LGPLv2+.
* Authors: Scott Christley <scottc@net-community.com>, Venkat Ajjanagadde <venkat@ocbi.com>,
* Authors: Scott Christley <scottc@net-community.com>, Venkat Ajjanagadde <venkat@ocbi.com>,
* Felipe A. Rodriguez <far@ix.netcom.com>, Richard Frith-Macdonald <richard@brainstorm.co.uk>
* Copyright (C) 1996 Free Software Foundation, Inc.
*/
......@@ -2738,7 +2742,7 @@ static VLCMainWindow *_o_sharedInstance = nil;
difference2 = screenRect.origin.y - frameRect.origin.y;
difference2 -= difference;
// Take in account the space between the top of window and the top of the
// Take in account the space between the top of window and the top of the
// screen which can be used to move the bottom of the window on the screen
if (difference2 > 0)
{
......@@ -2766,7 +2770,7 @@ static VLCMainWindow *_o_sharedInstance = nil;
be allowed to zoom to full screen.
*
* This method is based upon NSWindow.m, part of the GNUstep GUI Library, licensed under LGPLv2+.
* Authors: Scott Christley <scottc@net-community.com>, Venkat Ajjanagadde <venkat@ocbi.com>,
* Authors: Scott Christley <scottc@net-community.com>, Venkat Ajjanagadde <venkat@ocbi.com>,
* Felipe A. Rodriguez <far@ix.netcom.com>, Richard Frith-Macdonald <richard@brainstorm.co.uk>
* Copyright (C) 1996 Free Software Foundation, Inc.
*/
......@@ -2810,7 +2814,7 @@ static VLCMainWindow *_o_sharedInstance = nil;
{
if( !b_dark_interface )
return [super accessibilityAttributeNames];
static NSMutableArray *attributes = nil;
if ( attributes == nil ) {
attributes = [[super accessibilityAttributeNames] mutableCopy];
......@@ -2819,7 +2823,7 @@ static VLCMainWindow *_o_sharedInstance = nil;
NSAccessibilityMinimizeButtonAttribute,
NSAccessibilityZoomButtonAttribute,
nil];
for( NSString *attribute in appendAttributes )
{
if( ![attributes containsObject:attribute] )
......@@ -2834,20 +2838,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];
}
......
......@@ -140,41 +140,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;
......
......@@ -1340,62 +1340,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;
}
}
val.i_int |= CocoaKeyToVLC( key );
if( key == 0x0020 ) // space key
{
[[VLCCoreInteraction sharedInstance] play];
return YES;
}
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) )
val.i_int |= CocoaKeyToVLC( key );
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;
......@@ -1427,7 +1431,7 @@ unsigned int CocoaKeyToVLC( unichar i_key )
}
}
module_config_free (p_config);
if( o_usedHotkeys )
[o_usedHotkeys release];
o_usedHotkeys = [[NSArray alloc] initWithArray: o_tempArray copyItems: YES];
......@@ -1444,7 +1448,7 @@ unsigned int CocoaKeyToVLC( unichar i_key )
if (b_nativeFullscreenMode)
{
// this is called twice in certain situations, so only toogle if we really need to
if( ( b_fullscreen && !([NSApp currentSystemPresentationOptions] & NSApplicationPresentationFullScreen) ) ||
if( ( b_fullscreen && !([NSApp currentSystemPresentationOptions] & NSApplicationPresentationFullScreen) ) ||
( !b_fullscreen && ([NSApp currentSystemPresentationOptions] & NSApplicationPresentationFullScreen) ) )
[o_mainwindow toggleFullScreen: self];
......@@ -1477,10 +1481,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 );
}
}
......@@ -2039,7 +2043,7 @@ unsigned int CocoaKeyToVLC( unichar i_key )
{
if (aTableView == o_msgs_table)
return [o_msg_arr count];
return 0;
return 0;
}
- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
......
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