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 7312 b36811d7db33
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
--- a/include/SDL_keyboard.h	Mon Jun 17 07:14:20 2013 -0700
+++ b/include/SDL_keyboard.h	Tue Jun 18 00:39:47 2013 -0700
@@ -41,13 +41,15 @@
 
 /**
  *  \brief The SDL keysym structure, used in key events.
+ *
+ *  \note  If you are looking for translated character input, see the ::SDL_TEXTINPUT event.
  */
 typedef struct SDL_Keysym
 {
     SDL_Scancode scancode;      /**< SDL physical key code - see ::SDL_Scancode for details */
     SDL_Keycode sym;            /**< SDL virtual key code - see ::SDL_Keycode for details */
     Uint16 mod;                 /**< current key modifiers */
-    Uint32 unicode;             /**< \deprecated use SDL_TextInputEvent instead */
+    Uint32 unused;
 } SDL_Keysym;
 
 /* Function prototypes */
--- a/src/events/SDL_keyboard.c	Mon Jun 17 07:14:20 2013 -0700
+++ b/src/events/SDL_keyboard.c	Tue Jun 18 00:39:47 2013 -0700
@@ -774,7 +774,6 @@
         event.key.keysym.scancode = scancode;
         event.key.keysym.sym = keyboard->keymap[scancode];
         event.key.keysym.mod = modstate;
-        event.key.keysym.unicode = 0;
         event.key.windowID = keyboard->focus ? keyboard->focus->id : 0;
         posted = (SDL_PushEvent(&event) > 0);
     }
--- a/src/video/directfb/SDL_DirectFB_events.c	Mon Jun 17 07:14:20 2013 -0700
+++ b/src/video/directfb/SDL_DirectFB_events.c	Tue Jun 18 00:39:47 2013 -0700
@@ -64,9 +64,9 @@
 
 
 static SDL_Keysym *DirectFB_TranslateKey(_THIS, DFBWindowEvent * evt,
-                                         SDL_Keysym * keysym);
+                                         SDL_Keysym * keysym, Uint32 *unicode);
 static SDL_Keysym *DirectFB_TranslateKeyInputEvent(_THIS, DFBInputEvent * evt,
-                                                   SDL_Keysym * keysym);
+                                                   SDL_Keysym * keysym, Uint32 *unicode);
 
 static void DirectFB_InitOSKeymap(_THIS, SDL_Scancode * keypmap, int numkeys);
 static int DirectFB_TranslateButton(DFBInputDeviceButtonIdentifier button);
@@ -176,6 +176,7 @@
     SDL_DFB_DEVICEDATA(_this);
     SDL_DFB_WINDOWDATA(sdlwin);
     SDL_Keysym keysym;
+    Uint32 unicode;
     char text[SDL_TEXTINPUTEVENT_TEXT_SIZE];
 
     if (evt->clazz == DFEC_WINDOW) {
@@ -231,12 +232,12 @@
             break;
         case DWET_KEYDOWN:
             if (!devdata->use_linux_input) {
-                DirectFB_TranslateKey(_this, evt, &keysym);
+                DirectFB_TranslateKey(_this, evt, &keysym, &unicode);
                 /*printf("Scancode %d  %d %d\n", keysym.scancode, evt->key_code, evt->key_id);*/
                 SDL_SendKeyboardKey_ex(0, SDL_PRESSED, keysym.scancode);
                 if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) {
                     SDL_zero(text);
-                    UnicodeToUtf8(keysym.unicode, text);
+                    UnicodeToUtf8(unicode, text);
                     if (*text) {
                         SDL_SendKeyboardText_ex(0, text);
                     }
@@ -245,7 +246,7 @@
             break;
         case DWET_KEYUP:
             if (!devdata->use_linux_input) {
-                DirectFB_TranslateKey(_this, evt, &keysym);
+                DirectFB_TranslateKey(_this, evt, &keysym, &unicode);
                 SDL_SendKeyboardKey_ex(0, SDL_RELEASED, keysym.scancode);
             }
             break;
@@ -309,6 +310,7 @@
     SDL_DFB_DEVICEDATA(_this);
     SDL_Keysym keysym;
     int kbd_idx;
+    Uint32 unicode;
     char text[SDL_TEXTINPUTEVENT_TEXT_SIZE];
 
     if (!devdata->use_linux_input) {
@@ -366,12 +368,12 @@
             break;
         case DIET_KEYPRESS:
             kbd_idx = KbdIndex(_this, ievt->device_id);
-            DirectFB_TranslateKeyInputEvent(_this, ievt, &keysym);
+            DirectFB_TranslateKeyInputEvent(_this, ievt, &keysym, &unicode);
             /*printf("Scancode %d  %d %d\n", keysym.scancode, evt->key_code, evt->key_id); */
             SDL_SendKeyboardKey_ex(kbd_idx, SDL_PRESSED, keysym.scancode);
             if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) {
                 SDL_zero(text);
-                UnicodeToUtf8(keysym.unicode, text);
+                UnicodeToUtf8(unicode, text);
                 if (*text) {
                     SDL_SendKeyboardText_ex(kbd_idx, text);
                 }
@@ -379,7 +381,7 @@
             break;
         case DIET_KEYRELEASE:
             kbd_idx = KbdIndex(_this, ievt->device_id);
-            DirectFB_TranslateKeyInputEvent(_this, ievt, &keysym);
+            DirectFB_TranslateKeyInputEvent(_this, ievt, &keysym, &unicode);
             SDL_SendKeyboardKey_ex(kbd_idx, SDL_RELEASED, keysym.scancode);
             break;
         case DIET_BUTTONPRESS:
@@ -575,7 +577,7 @@
 }
 
 static SDL_Keysym *
-DirectFB_TranslateKey(_THIS, DFBWindowEvent * evt, SDL_Keysym * keysym)
+DirectFB_TranslateKey(_THIS, DFBWindowEvent * evt, SDL_Keysym * keysym, Uint32 *unicode)
 {
     SDL_DFB_DEVICEDATA(_this);
     int kbd_idx = 0; /* Window events lag the device source KbdIndex(_this, evt->device_id); */
@@ -595,18 +597,18 @@
             keysym->scancode = SDL_SCANCODE_UNKNOWN;
     }
 
-    keysym->unicode =
+    *unicode =
         (DFB_KEY_TYPE(evt->key_symbol) == DIKT_UNICODE) ? evt->key_symbol : 0;
-    if (keysym->unicode == 0 &&
+    if (*unicode == 0 &&
         (evt->key_symbol > 0 && evt->key_symbol < 255))
-        keysym->unicode = evt->key_symbol;
+        *unicode = evt->key_symbol;
 
     return keysym;
 }
 
 static SDL_Keysym *
 DirectFB_TranslateKeyInputEvent(_THIS, DFBInputEvent * evt,
-                                SDL_Keysym * keysym)
+                                SDL_Keysym * keysym, Uint32 *unicode)
 {
     SDL_DFB_DEVICEDATA(_this);
     int kbd_idx = KbdIndex(_this, evt->device_id);
@@ -625,11 +627,11 @@
             keysym->scancode = SDL_SCANCODE_UNKNOWN;
     }
 
-    keysym->unicode =
+    *unicode =
         (DFB_KEY_TYPE(evt->key_symbol) == DIKT_UNICODE) ? evt->key_symbol : 0;
-    if (keysym->unicode == 0 &&
+    if (*unicode == 0 &&
         (evt->key_symbol > 0 && evt->key_symbol < 255))
-        keysym->unicode = evt->key_symbol;
+        *unicode = evt->key_symbol;
 
     return keysym;
 }
--- a/test/checkkeys.c	Mon Jun 17 07:14:20 2013 -0700
+++ b/test/checkkeys.c	Tue Jun 18 00:39:47 2013 -0700
@@ -107,24 +107,6 @@
                 SDL_GetScancodeName(sym->scancode),
                 pressed ? "pressed " : "released");
     }
-
-    /* Print the translated character, if one exists */
-    if (sym->unicode) {
-        /* Is it a control-character? */
-        if (sym->unicode < ' ') {
-            print_string(&spot, &left, " (^%c)", sym->unicode + '@');
-        } else {
-#ifdef UNICODE
-            print_string(&spot, &left, " (%c)", sym->unicode);
-#else
-            /* This is a Latin-1 program, so only show 8-bits */
-            if (!(sym->unicode & 0xFF00))
-                print_string(&spot, &left, " (%c)", sym->unicode);
-            else
-                print_string(&spot, &left, " (0x%X)", sym->unicode);
-#endif
-        }
-    }
     print_modifiers(&spot, &left);
     if (repeat) {
         print_string(&spot, &left, " (repeat)");