Fixed bug 2772 - SDL2 doesn't handle X KeymapNotify events
authorSam Lantinga
Thu, 28 May 2015 10:44:46 -0700
changeset 96691021c9bd0f64
parent 9668 6ab4d6f34afb
child 9670 418e4dee26cb
Fixed bug 2772 - SDL2 doesn't handle X KeymapNotify events

Jason Wyatt

Currently the keymapnotify event handling is commented out as FIXME in SDL_x11events.c (It looks like this may have functioned SDL1.2).

Not handling this event means that if a window manager shortcut such as ALT+SPACE is used, SDL will send an ALT key down signal, but not an up signal. Also querying SDL about the key state, it believes the ALT key remains pressed.
X passes the events keypress (alt), ?focusout?, ?focusin?, keymapnotify.
src/video/x11/SDL_x11events.c
     1.1 --- a/src/video/x11/SDL_x11events.c	Sat Dec 20 11:45:39 2014 -0500
     1.2 +++ b/src/video/x11/SDL_x11events.c	Thu May 28 10:44:46 2015 -0700
     1.3 @@ -40,6 +40,8 @@
     1.4  
     1.5  #include <stdio.h>
     1.6  
     1.7 +/*#define DEBUG_XEVENTS*/
     1.8 +
     1.9  #ifndef _NET_WM_MOVERESIZE_SIZE_TOPLEFT
    1.10  #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT      0
    1.11  #endif
    1.12 @@ -132,7 +134,6 @@
    1.13      if (a2 != None) atom[count++] = a2;
    1.14      return X11_PickTarget(disp, atom, count);
    1.15  }
    1.16 -/* #define DEBUG_XEVENTS */
    1.17  
    1.18  struct KeyRepeatCheckData
    1.19  {
    1.20 @@ -361,7 +362,7 @@
    1.21  }
    1.22  
    1.23  static void
    1.24 -X11_ReconcileKeyboardState(_THIS, const SDL_WindowData *data)
    1.25 +X11_ReconcileKeyboardState(_THIS)
    1.26  {
    1.27      SDL_VideoData *viddata = (SDL_VideoData *) _this->driverdata;
    1.28      Display *display = viddata->display;
    1.29 @@ -413,7 +414,7 @@
    1.30      printf("window %p: Dispatching FocusIn\n", data);
    1.31  #endif
    1.32      SDL_SetKeyboardFocus(data->window);
    1.33 -    X11_ReconcileKeyboardState(_this, data);
    1.34 +    X11_ReconcileKeyboardState(_this);
    1.35  #ifdef X_HAVE_UTF8_STRING
    1.36      if (data->ic) {
    1.37          X11_XSetICFocus(data->ic);
    1.38 @@ -633,6 +634,12 @@
    1.39          }
    1.40      }
    1.41      if (!data) {
    1.42 +        /* The window for KeymapNotify events is 0 */
    1.43 +        if (xevent.type == KeymapNotify) {
    1.44 +            if (SDL_GetKeyboardFocus() != NULL) {
    1.45 +                X11_ReconcileKeyboardState(_this);
    1.46 +            }
    1.47 +        }
    1.48          return;
    1.49      }
    1.50  
    1.51 @@ -747,17 +754,6 @@
    1.52          }
    1.53          break;
    1.54  
    1.55 -        /* Generated upon EnterWindow and FocusIn */
    1.56 -    case KeymapNotify:{
    1.57 -#ifdef DEBUG_XEVENTS
    1.58 -            printf("window %p: KeymapNotify!\n", data);
    1.59 -#endif
    1.60 -            /* FIXME:
    1.61 -               X11_SetKeyboardState(SDL_Display, xevent.xkeymap.key_vector);
    1.62 -             */
    1.63 -        }
    1.64 -        break;
    1.65 -
    1.66          /* Has the keyboard layout changed? */
    1.67      case MappingNotify:{
    1.68  #ifdef DEBUG_XEVENTS