Reset the keyboard when we lose input focus
authorSam Lantinga <slouken@libsdl.org>
Wed, 07 Nov 2012 11:13:28 -0800
changeset 6661cd8befc0a969
parent 6660 4fa0723e6874
child 6662 698c2e533a7e
Reset the keyboard when we lose input focus
src/events/SDL_keyboard.c
src/video/x11/SDL_x11events.c
     1.1 --- a/src/events/SDL_keyboard.c	Wed Nov 07 08:49:59 2012 -0800
     1.2 +++ b/src/events/SDL_keyboard.c	Wed Nov 07 11:13:28 2012 -0800
     1.3 @@ -28,6 +28,8 @@
     1.4  #include "../video/SDL_sysvideo.h"
     1.5  
     1.6  
     1.7 +/*#define DEBUG_KEYBOARD*/
     1.8 +
     1.9  /* Global keyboard information */
    1.10  
    1.11  typedef struct SDL_Keyboard SDL_Keyboard;
    1.12 @@ -563,6 +565,9 @@
    1.13      SDL_Keyboard *keyboard = &SDL_keyboard;
    1.14      SDL_Scancode scancode;
    1.15  
    1.16 +#ifdef DEBUG_KEYBOARD
    1.17 +    printf("Resetting keyboard\n");
    1.18 +#endif
    1.19      for (scancode = 0; scancode < SDL_NUM_SCANCODES; ++scancode) {
    1.20          if (keyboard->keystate[scancode] == SDL_PRESSED) {
    1.21              SDL_SendKeyboardKey(SDL_RELEASED, scancode);
    1.22 @@ -633,6 +638,9 @@
    1.23                  video->StartTextInput(video);
    1.24              }
    1.25          }
    1.26 +    } else {
    1.27 +        /* We won't get anymore keyboard messages, so reset keyboard state */
    1.28 +        SDL_ResetKeyboard();
    1.29      }
    1.30  }
    1.31  
    1.32 @@ -648,7 +656,7 @@
    1.33      if (!scancode) {
    1.34          return 0;
    1.35      }
    1.36 -#if 0
    1.37 +#ifdef DEBUG_KEYBOARD
    1.38      printf("The '%s' key has been %s\n", SDL_GetScancodeName(scancode),
    1.39             state == SDL_PRESSED ? "pressed" : "released");
    1.40  #endif
     2.1 --- a/src/video/x11/SDL_x11events.c	Wed Nov 07 08:49:59 2012 -0800
     2.2 +++ b/src/video/x11/SDL_x11events.c	Wed Nov 07 11:13:28 2012 -0800
     2.3 @@ -258,6 +258,13 @@
     2.4  #ifdef DEBUG_XEVENTS
     2.5              printf("window %p: FocusIn!\n", data);
     2.6  #endif
     2.7 +            if (data->pending_focus == PENDING_FOCUS_OUT &&
     2.8 +                data->window == SDL_GetKeyboardFocus()) {
     2.9 +                /* We want to reset the keyboard here, because we may have
    2.10 +                   missed keyboard messages after our previous FocusOut.
    2.11 +                 */
    2.12 +                SDL_ResetKeyboard();
    2.13 +            }
    2.14              data->pending_focus = PENDING_FOCUS_IN;
    2.15              data->pending_focus_time = SDL_GetTicks() + PENDING_FOCUS_IN_TIME;
    2.16          }