mirror of
https://github.com/mpv-player/mpv
synced 2024-12-28 01:52:19 +00:00
cocoa_common: fix crash with dead key input and simplify related code
Fixes #29. When a user used dead input keys (like the accent key), `mpv` crashed because the code tried to access the 0 element of a characters array (which was empty). While I was closing this bug, I refactored some related conditionals to make the code more readable.
This commit is contained in:
parent
a090c07453
commit
145c965135
@ -51,9 +51,21 @@
|
|||||||
#define NSOpenGLProfileVersion3_2Core 0x3200
|
#define NSOpenGLProfileVersion3_2Core 0x3200
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define NSLeftAlternateKeyMask (0x000020 | NSAlternateKeyMask)
|
#define NSLeftAlternateKeyMask (0x000020 | NSAlternateKeyMask)
|
||||||
#define NSRightAlternateKeyMask (0x000040 | NSAlternateKeyMask)
|
#define NSRightAlternateKeyMask (0x000040 | NSAlternateKeyMask)
|
||||||
|
|
||||||
|
static bool LeftAltPressed(NSEvent *event)
|
||||||
|
{
|
||||||
|
return ([event modifierFlags] & NSLeftAlternateKeyMask) ==
|
||||||
|
NSLeftAlternateKeyMask;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool RightAltPressed(NSEvent *event)
|
||||||
|
{
|
||||||
|
return ([event modifierFlags] & NSRightAlternateKeyMask) ==
|
||||||
|
NSRightAlternateKeyMask;
|
||||||
|
}
|
||||||
|
|
||||||
// add methods not available on OSX versions prior to 10.7
|
// add methods not available on OSX versions prior to 10.7
|
||||||
#ifndef MAC_OS_X_VERSION_10_7
|
#ifndef MAC_OS_X_VERSION_10_7
|
||||||
@interface NSView (IntroducedInLion)
|
@interface NSView (IntroducedInLion)
|
||||||
@ -678,22 +690,21 @@ void create_menu()
|
|||||||
|
|
||||||
- (void)keyDown:(NSEvent *)theEvent
|
- (void)keyDown:(NSEvent *)theEvent
|
||||||
{
|
{
|
||||||
unsigned char charcode;
|
NSString *chars;
|
||||||
if (([theEvent modifierFlags] & NSRightAlternateKeyMask) ==
|
|
||||||
NSRightAlternateKeyMask)
|
|
||||||
charcode = *[[theEvent characters] UTF8String];
|
|
||||||
else
|
|
||||||
charcode = [[theEvent charactersIgnoringModifiers] characterAtIndex:0];
|
|
||||||
|
|
||||||
int key = convert_key([theEvent keyCode], charcode);
|
if (RightAltPressed(theEvent))
|
||||||
|
chars = [theEvent characters];
|
||||||
|
else
|
||||||
|
chars = [theEvent charactersIgnoringModifiers];
|
||||||
|
|
||||||
|
int key = convert_key([theEvent keyCode], *[chars UTF8String]);
|
||||||
|
|
||||||
if (key > -1) {
|
if (key > -1) {
|
||||||
if ([theEvent modifierFlags] & NSShiftKeyMask)
|
if ([theEvent modifierFlags] & NSShiftKeyMask)
|
||||||
key |= MP_KEY_MODIFIER_SHIFT;
|
key |= MP_KEY_MODIFIER_SHIFT;
|
||||||
if ([theEvent modifierFlags] & NSControlKeyMask)
|
if ([theEvent modifierFlags] & NSControlKeyMask)
|
||||||
key |= MP_KEY_MODIFIER_CTRL;
|
key |= MP_KEY_MODIFIER_CTRL;
|
||||||
if (([theEvent modifierFlags] & NSLeftAlternateKeyMask) ==
|
if (LeftAltPressed(theEvent))
|
||||||
NSLeftAlternateKeyMask)
|
|
||||||
key |= MP_KEY_MODIFIER_ALT;
|
key |= MP_KEY_MODIFIER_ALT;
|
||||||
if ([theEvent modifierFlags] & NSCommandKeyMask)
|
if ([theEvent modifierFlags] & NSCommandKeyMask)
|
||||||
key |= MP_KEY_MODIFIER_META;
|
key |= MP_KEY_MODIFIER_META;
|
||||||
|
Loading…
Reference in New Issue
Block a user