Fixed bug 1916 - SDL_Keysym contains a deprecated field for unicode which may be removed.
authorSam Lantinga <slouken@libsdl.org>
Tue, 18 Jun 2013 00:39:47 -0700
changeset 7312b36811d7db33
parent 7311 56e66417dcee
child 7313 c7346a060a7d
Fixed bug 1916 - SDL_Keysym contains a deprecated field for unicode which may be removed.

Philipp Wiesemann

SDL_Keysym contains a deprecated field for unicode which may be removed for SDL 2.0 release.

As far as I can tell the field is not set on all "major" platforms and therefore will not be useful for most users. Its existence in a public header therefore becomes (in my opinion) only confusing.
include/SDL_keyboard.h
src/events/SDL_keyboard.c
src/video/directfb/SDL_DirectFB_events.c
test/checkkeys.c
     1.1 --- a/include/SDL_keyboard.h	Mon Jun 17 07:14:20 2013 -0700
     1.2 +++ b/include/SDL_keyboard.h	Tue Jun 18 00:39:47 2013 -0700
     1.3 @@ -41,13 +41,15 @@
     1.4  
     1.5  /**
     1.6   *  \brief The SDL keysym structure, used in key events.
     1.7 + *
     1.8 + *  \note  If you are looking for translated character input, see the ::SDL_TEXTINPUT event.
     1.9   */
    1.10  typedef struct SDL_Keysym
    1.11  {
    1.12      SDL_Scancode scancode;      /**< SDL physical key code - see ::SDL_Scancode for details */
    1.13      SDL_Keycode sym;            /**< SDL virtual key code - see ::SDL_Keycode for details */
    1.14      Uint16 mod;                 /**< current key modifiers */
    1.15 -    Uint32 unicode;             /**< \deprecated use SDL_TextInputEvent instead */
    1.16 +    Uint32 unused;
    1.17  } SDL_Keysym;
    1.18  
    1.19  /* Function prototypes */
     2.1 --- a/src/events/SDL_keyboard.c	Mon Jun 17 07:14:20 2013 -0700
     2.2 +++ b/src/events/SDL_keyboard.c	Tue Jun 18 00:39:47 2013 -0700
     2.3 @@ -774,7 +774,6 @@
     2.4          event.key.keysym.scancode = scancode;
     2.5          event.key.keysym.sym = keyboard->keymap[scancode];
     2.6          event.key.keysym.mod = modstate;
     2.7 -        event.key.keysym.unicode = 0;
     2.8          event.key.windowID = keyboard->focus ? keyboard->focus->id : 0;
     2.9          posted = (SDL_PushEvent(&event) > 0);
    2.10      }
     3.1 --- a/src/video/directfb/SDL_DirectFB_events.c	Mon Jun 17 07:14:20 2013 -0700
     3.2 +++ b/src/video/directfb/SDL_DirectFB_events.c	Tue Jun 18 00:39:47 2013 -0700
     3.3 @@ -64,9 +64,9 @@
     3.4  
     3.5  
     3.6  static SDL_Keysym *DirectFB_TranslateKey(_THIS, DFBWindowEvent * evt,
     3.7 -                                         SDL_Keysym * keysym);
     3.8 +                                         SDL_Keysym * keysym, Uint32 *unicode);
     3.9  static SDL_Keysym *DirectFB_TranslateKeyInputEvent(_THIS, DFBInputEvent * evt,
    3.10 -                                                   SDL_Keysym * keysym);
    3.11 +                                                   SDL_Keysym * keysym, Uint32 *unicode);
    3.12  
    3.13  static void DirectFB_InitOSKeymap(_THIS, SDL_Scancode * keypmap, int numkeys);
    3.14  static int DirectFB_TranslateButton(DFBInputDeviceButtonIdentifier button);
    3.15 @@ -176,6 +176,7 @@
    3.16      SDL_DFB_DEVICEDATA(_this);
    3.17      SDL_DFB_WINDOWDATA(sdlwin);
    3.18      SDL_Keysym keysym;
    3.19 +    Uint32 unicode;
    3.20      char text[SDL_TEXTINPUTEVENT_TEXT_SIZE];
    3.21  
    3.22      if (evt->clazz == DFEC_WINDOW) {
    3.23 @@ -231,12 +232,12 @@
    3.24              break;
    3.25          case DWET_KEYDOWN:
    3.26              if (!devdata->use_linux_input) {
    3.27 -                DirectFB_TranslateKey(_this, evt, &keysym);
    3.28 +                DirectFB_TranslateKey(_this, evt, &keysym, &unicode);
    3.29                  /*printf("Scancode %d  %d %d\n", keysym.scancode, evt->key_code, evt->key_id);*/
    3.30                  SDL_SendKeyboardKey_ex(0, SDL_PRESSED, keysym.scancode);
    3.31                  if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) {
    3.32                      SDL_zero(text);
    3.33 -                    UnicodeToUtf8(keysym.unicode, text);
    3.34 +                    UnicodeToUtf8(unicode, text);
    3.35                      if (*text) {
    3.36                          SDL_SendKeyboardText_ex(0, text);
    3.37                      }
    3.38 @@ -245,7 +246,7 @@
    3.39              break;
    3.40          case DWET_KEYUP:
    3.41              if (!devdata->use_linux_input) {
    3.42 -                DirectFB_TranslateKey(_this, evt, &keysym);
    3.43 +                DirectFB_TranslateKey(_this, evt, &keysym, &unicode);
    3.44                  SDL_SendKeyboardKey_ex(0, SDL_RELEASED, keysym.scancode);
    3.45              }
    3.46              break;
    3.47 @@ -309,6 +310,7 @@
    3.48      SDL_DFB_DEVICEDATA(_this);
    3.49      SDL_Keysym keysym;
    3.50      int kbd_idx;
    3.51 +    Uint32 unicode;
    3.52      char text[SDL_TEXTINPUTEVENT_TEXT_SIZE];
    3.53  
    3.54      if (!devdata->use_linux_input) {
    3.55 @@ -366,12 +368,12 @@
    3.56              break;
    3.57          case DIET_KEYPRESS:
    3.58              kbd_idx = KbdIndex(_this, ievt->device_id);
    3.59 -            DirectFB_TranslateKeyInputEvent(_this, ievt, &keysym);
    3.60 +            DirectFB_TranslateKeyInputEvent(_this, ievt, &keysym, &unicode);
    3.61              /*printf("Scancode %d  %d %d\n", keysym.scancode, evt->key_code, evt->key_id); */
    3.62              SDL_SendKeyboardKey_ex(kbd_idx, SDL_PRESSED, keysym.scancode);
    3.63              if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) {
    3.64                  SDL_zero(text);
    3.65 -                UnicodeToUtf8(keysym.unicode, text);
    3.66 +                UnicodeToUtf8(unicode, text);
    3.67                  if (*text) {
    3.68                      SDL_SendKeyboardText_ex(kbd_idx, text);
    3.69                  }
    3.70 @@ -379,7 +381,7 @@
    3.71              break;
    3.72          case DIET_KEYRELEASE:
    3.73              kbd_idx = KbdIndex(_this, ievt->device_id);
    3.74 -            DirectFB_TranslateKeyInputEvent(_this, ievt, &keysym);
    3.75 +            DirectFB_TranslateKeyInputEvent(_this, ievt, &keysym, &unicode);
    3.76              SDL_SendKeyboardKey_ex(kbd_idx, SDL_RELEASED, keysym.scancode);
    3.77              break;
    3.78          case DIET_BUTTONPRESS:
    3.79 @@ -575,7 +577,7 @@
    3.80  }
    3.81  
    3.82  static SDL_Keysym *
    3.83 -DirectFB_TranslateKey(_THIS, DFBWindowEvent * evt, SDL_Keysym * keysym)
    3.84 +DirectFB_TranslateKey(_THIS, DFBWindowEvent * evt, SDL_Keysym * keysym, Uint32 *unicode)
    3.85  {
    3.86      SDL_DFB_DEVICEDATA(_this);
    3.87      int kbd_idx = 0; /* Window events lag the device source KbdIndex(_this, evt->device_id); */
    3.88 @@ -595,18 +597,18 @@
    3.89              keysym->scancode = SDL_SCANCODE_UNKNOWN;
    3.90      }
    3.91  
    3.92 -    keysym->unicode =
    3.93 +    *unicode =
    3.94          (DFB_KEY_TYPE(evt->key_symbol) == DIKT_UNICODE) ? evt->key_symbol : 0;
    3.95 -    if (keysym->unicode == 0 &&
    3.96 +    if (*unicode == 0 &&
    3.97          (evt->key_symbol > 0 && evt->key_symbol < 255))
    3.98 -        keysym->unicode = evt->key_symbol;
    3.99 +        *unicode = evt->key_symbol;
   3.100  
   3.101      return keysym;
   3.102  }
   3.103  
   3.104  static SDL_Keysym *
   3.105  DirectFB_TranslateKeyInputEvent(_THIS, DFBInputEvent * evt,
   3.106 -                                SDL_Keysym * keysym)
   3.107 +                                SDL_Keysym * keysym, Uint32 *unicode)
   3.108  {
   3.109      SDL_DFB_DEVICEDATA(_this);
   3.110      int kbd_idx = KbdIndex(_this, evt->device_id);
   3.111 @@ -625,11 +627,11 @@
   3.112              keysym->scancode = SDL_SCANCODE_UNKNOWN;
   3.113      }
   3.114  
   3.115 -    keysym->unicode =
   3.116 +    *unicode =
   3.117          (DFB_KEY_TYPE(evt->key_symbol) == DIKT_UNICODE) ? evt->key_symbol : 0;
   3.118 -    if (keysym->unicode == 0 &&
   3.119 +    if (*unicode == 0 &&
   3.120          (evt->key_symbol > 0 && evt->key_symbol < 255))
   3.121 -        keysym->unicode = evt->key_symbol;
   3.122 +        *unicode = evt->key_symbol;
   3.123  
   3.124      return keysym;
   3.125  }
     4.1 --- a/test/checkkeys.c	Mon Jun 17 07:14:20 2013 -0700
     4.2 +++ b/test/checkkeys.c	Tue Jun 18 00:39:47 2013 -0700
     4.3 @@ -107,24 +107,6 @@
     4.4                  SDL_GetScancodeName(sym->scancode),
     4.5                  pressed ? "pressed " : "released");
     4.6      }
     4.7 -
     4.8 -    /* Print the translated character, if one exists */
     4.9 -    if (sym->unicode) {
    4.10 -        /* Is it a control-character? */
    4.11 -        if (sym->unicode < ' ') {
    4.12 -            print_string(&spot, &left, " (^%c)", sym->unicode + '@');
    4.13 -        } else {
    4.14 -#ifdef UNICODE
    4.15 -            print_string(&spot, &left, " (%c)", sym->unicode);
    4.16 -#else
    4.17 -            /* This is a Latin-1 program, so only show 8-bits */
    4.18 -            if (!(sym->unicode & 0xFF00))
    4.19 -                print_string(&spot, &left, " (%c)", sym->unicode);
    4.20 -            else
    4.21 -                print_string(&spot, &left, " (0x%X)", sym->unicode);
    4.22 -#endif
    4.23 -        }
    4.24 -    }
    4.25      print_modifiers(&spot, &left);
    4.26      if (repeat) {
    4.27          print_string(&spot, &left, " (repeat)");