Mac: Fix keyboard state if capslock was toggled while app wasn't in foreground.
authorRyan C. Gordon <icculus@icculus.org>
Sun, 27 Dec 2015 23:39:43 -0500
changeset 9972734c90ea9990
parent 9971 fa7c016ac2d3
child 9973 4d8a561cf978
Mac: Fix keyboard state if capslock was toggled while app wasn't in foreground.
src/video/cocoa/SDL_cocoawindow.m
     1.1 --- a/src/video/cocoa/SDL_cocoawindow.m	Sun Dec 27 22:26:27 2015 -0500
     1.2 +++ b/src/video/cocoa/SDL_cocoawindow.m	Sun Dec 27 23:39:43 2015 -0500
     1.3 @@ -588,6 +588,17 @@
     1.4      if ((isFullscreenSpace) && ((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP)) {
     1.5          [NSMenu setMenuBarVisible:NO];
     1.6      }
     1.7 +
     1.8 +    /* On pre-10.6, you might have the capslock key state wrong now. */
     1.9 +    if (floor(NSAppKitVersionNumber) >= NSAppKitVersionNumber10_6) {
    1.10 +        const unsigned int oldflags = _data->videodata->modifierFlags & NSAlphaShiftKeyMask;
    1.11 +        const unsigned int newflags = [NSEvent modifierFlags] & NSAlphaShiftKeyMask;
    1.12 +        if (oldflags != newflags) {
    1.13 +            _data->videodata->modifierFlags = (_data->videodata->modifierFlags & ~NSAlphaShiftKeyMask) | newflags;
    1.14 +            SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_CAPSLOCK);
    1.15 +            SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_CAPSLOCK);
    1.16 +        }
    1.17 +    }
    1.18  }
    1.19  
    1.20  - (void)windowDidResignKey:(NSNotification *)aNotification