Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OSX] Modifiers pressed during window / desktop switching animations are not recorded #10600

Open
wants to merge 1 commit into
base: SDL2
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 46 additions & 1 deletion src/video/cocoa/SDL_cocoakeyboard.m
Original file line number Diff line number Diff line change
Expand Up @@ -383,9 +383,51 @@ void Cocoa_SetTextInputRect(_THIS, const SDL_Rect *rect)
[data.fieldEdit setInputRect:rect];
}

#define isBitSet(x,y) ((x & y) == y)

static void HandleModifiersIfDifferent(_THIS, unsigned int modflags){

SDL_Keymod currentMod;

currentMod = SDL_GetModState();

if(isBitSet(currentMod, KMOD_LSHIFT) != isBitSet(modflags, NX_DEVICELSHIFTKEYMASK)){
HandleModifiers(_this, SDL_SCANCODE_LSHIFT, modflags);
}

if(isBitSet(currentMod, KMOD_LCTRL) != isBitSet(modflags, NX_DEVICELCTLKEYMASK)){
HandleModifiers(_this, SDL_SCANCODE_LCTRL, modflags);
}

if(isBitSet(currentMod, KMOD_LALT) != isBitSet(modflags, NX_DEVICELALTKEYMASK)){
HandleModifiers(_this, SDL_SCANCODE_LALT, modflags);
}

if(isBitSet(currentMod, KMOD_LGUI) != isBitSet(modflags, NX_DEVICELCMDKEYMASK)){
HandleModifiers(_this, SDL_SCANCODE_LGUI, modflags);
}

if(isBitSet(currentMod, KMOD_RSHIFT) != isBitSet(modflags, NX_DEVICERSHIFTKEYMASK)){
HandleModifiers(_this, SDL_SCANCODE_RSHIFT, modflags);
}

if(isBitSet(currentMod, KMOD_RCTRL) != isBitSet(modflags, NX_DEVICERCTLKEYMASK)){
HandleModifiers(_this, SDL_SCANCODE_RCTRL, modflags);
}

if(isBitSet(currentMod, KMOD_RALT) != isBitSet(modflags, NX_DEVICERALTKEYMASK)){
HandleModifiers(_this, SDL_SCANCODE_RALT, modflags);
}

if(isBitSet(currentMod, KMOD_RGUI) != isBitSet(modflags, NX_DEVICERCMDKEYMASK)){
HandleModifiers(_this, SDL_SCANCODE_RGUI, modflags);
}
}

void Cocoa_HandleKeyEvent(_THIS, NSEvent *event)
{
unsigned short scancode;
unsigned int modflags;
SDL_Scancode code;
SDL_VideoData *data = _this ? ((__bridge SDL_VideoData *) _this->driverdata) : nil;
if (!data) {
Expand All @@ -409,13 +451,17 @@ void Cocoa_HandleKeyEvent(_THIS, NSEvent *event)
code = SDL_SCANCODE_UNKNOWN;
}

modflags = (unsigned int)[event modifierFlags];

switch ([event type]) {
case NSEventTypeKeyDown:
if (![event isARepeat]) {
/* See if we need to rebuild the keyboard layout */
UpdateKeymap(data, SDL_TRUE);
}

HandleModifiersIfDifferent(_this, modflags);

SDL_SendKeyboardKey(SDL_PRESSED, code);
#ifdef DEBUG_SCANCODES
if (code == SDL_SCANCODE_UNKNOWN) {
Expand All @@ -439,7 +485,6 @@ void Cocoa_HandleKeyEvent(_THIS, NSEvent *event)
break;
case NSEventTypeFlagsChanged: {
// see if the new modifierFlags mean any existing keys should be pressed/released...
const unsigned int modflags = (unsigned int)[event modifierFlags];
HandleModifiers(_this, SDL_SCANCODE_LSHIFT, modflags);
HandleModifiers(_this, SDL_SCANCODE_LCTRL, modflags);
HandleModifiers(_this, SDL_SCANCODE_LALT, modflags);
Expand Down
Loading