diff src/video/directfb/SDL_DirectFB_events.c @ 2721:e82a0e3e9b0e

Date: Sun, 20 Jul 2008 22:34:37 +0200 From: Couriersud Subject: Updated DirectFB driver for SDL1.3 please find attached a patch for an updated directfb driver for SDL1.3. It does now - properly supported the new input api. - send unicode text events - support directfb windows - support multiple screens - support hardware YUV scaling for the first YUV texture created. - support hardware scaling for textures. - properly interpret streaming access - support software opengl if one manages to install the mesa directfb driver (broken/not broken in mesa svn) Within bugzilla (http://bugzilla.libsdl.org/show_bug.cgi?id=603) there is another patch which fixes a crash due to GL context creation. Kind regards, couriersud
author Sam Lantinga <slouken@libsdl.org>
date Tue, 26 Aug 2008 02:32:45 +0000
parents 1e690901ecd7
children 204be4fc2726
line wrap: on
line diff
--- a/src/video/directfb/SDL_DirectFB_events.c	Tue Aug 26 02:26:18 2008 +0000
+++ b/src/video/directfb/SDL_DirectFB_events.c	Tue Aug 26 02:32:45 2008 +0000
@@ -25,28 +25,55 @@
 
 #include <directfb.h>
 
-#include "SDL.h"
 #include "../SDL_sysvideo.h"
 #include "../../events/SDL_sysevents.h"
 #include "../../events/SDL_events_c.h"
+#include "../../events/SDL_keyboard_c.h"
+#include "../../events/scancodes_linux.h"
 #include "SDL_DirectFB_events.h"
 
 /* The translation tables from a DirectFB keycode to a SDL keysym */
 static SDLKey keymap[256];
 
-static SDL_keysym *DirectFB_TranslateKey(DFBInputDeviceKeyIdentifier key_id,
-                                         DFBInputDeviceKeySymbol key_symbol,
-                                         DFBInputDeviceModifierMask key_mod,
+static SDL_keysym *DirectFB_TranslateKey(_THIS, DFBWindowEvent * evt,
                                          SDL_keysym * keysym);
 
+static void DirectFB_InitOSKeymap(_THIS);
 static int DirectFB_TranslateButton(DFBInputDeviceButtonIdentifier button);
 
+static void
+DirectFB_SetContext(_THIS, SDL_WindowID id)
+{
+#if (DIRECTFB_MAJOR_VERSION >= 1)
+    /* FIXME: does not work on 1.0/1.2 with radeon driver
+     *        the approach did work with the matrox driver
+     *        Perhaps make this depending on env var, e.g. SDLDIRECTFB_SWITCHCONTEXT_SUPPORTED
+     */
+
+    if (getenv("SDLDIRECTFB_SWITCHCONTEXT_SUPPORTED") != NULL) {
+        SDL_DFB_DEVICEDATA(_this);
+        SDL_Window *window = SDL_GetWindowFromID(id);
+        SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
+        DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata;
+        if (dispdata->vidID >= 0 && dispdata->vidIDinuse) {
+            IDirectFBDisplayLayer *lay = NULL;
+            devdata->dfb->GetDisplayLayer(devdata->dfb, dispdata->vidID,
+                                          &lay);
+            if (lay)
+                lay->SwitchContext(lay, DFB_TRUE);
+        }
+    }
+#endif
+
+}
+
 void
 DirectFB_PumpEventsWindow(_THIS)
 {
     SDL_DFB_DEVICEDATA(_this);
     DFB_WindowData *p;
     DFBWindowEvent evt;
+    char text[5];
 
     for (p = devdata->firstwin; p != NULL; p = p->next) {
         while (p->eventbuffer->GetEvent(p->eventbuffer,
@@ -67,16 +94,21 @@
                     SDL_SendMouseMotion(devdata->mouse, 0, evt.cx, evt.cy);
                     break;
                 case DWET_KEYDOWN:
-                    DirectFB_TranslateKey(evt.key_id, evt.key_symbol,
-                                          evt.modifiers, &keysym);
+                    DirectFB_TranslateKey(_this, &evt, &keysym);
                     SDL_SendKeyboardKey(devdata->keyboard, SDL_PRESSED,
-                                        keysym.scancode, keysym.sym);
+                                        keysym.scancode);
+                    if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) {
+                        SDL_memcpy(text, &keysym.unicode, 4);
+                        text[4] = 0;
+                        if (*text) {
+                            SDL_SendKeyboardText(devdata->keyboard, text);
+                        }
+                    }
                     break;
                 case DWET_KEYUP:
-                    DirectFB_TranslateKey(evt.key_id, evt.key_symbol,
-                                          evt.modifiers, &keysym);
+                    DirectFB_TranslateKey(_this, &evt, &keysym);
                     SDL_SendKeyboardKey(devdata->keyboard, SDL_RELEASED,
-                                        keysym.scancode, keysym.sym);
+                                        keysym.scancode);
                     break;
                 case DWET_POSITION_SIZE:
                     SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_MOVED, evt.x,
@@ -96,17 +128,23 @@
                     SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_CLOSE, 0, 0);
                     break;
                 case DWET_GOTFOCUS:
-                    //TODO: Implement for yuv-overlay DirectFB_SwitchOverlayContext(this, evt.window_id);
+                    DirectFB_SetContext(_this, p->id);
                     SDL_SetKeyboardFocus(devdata->keyboard, p->id);
+                    SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_FOCUS_GAINED,
+                                        0, 0);
                     break;
                 case DWET_LOSTFOCUS:
+                    SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_FOCUS_LOST, 0,
+                                        0);
                     SDL_SetKeyboardFocus(devdata->keyboard, 0);
                     break;
                 case DWET_ENTER:
                     //SDL_DirectFB_ReshowCursor(_this, 0);
                     SDL_SetMouseFocus(devdata->mouse, p->id);
+                    SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_ENTER, 0, 0);
                     break;
                 case DWET_LEAVE:
+                    SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_LEAVE, 0, 0);
                     SDL_SetMouseFocus(devdata->mouse, 0);
                     //SDL_DirectFB_ReshowCursor(_this, 1);
                     break;
@@ -125,151 +163,149 @@
 
     /* Initialize the DirectFB key translation table */
     for (i = 0; i < SDL_arraysize(keymap); ++i)
-        keymap[i] = SDLK_UNKNOWN;
+        keymap[i] = SDL_SCANCODE_UNKNOWN;
 
-    keymap[DIKI_A - DIKI_UNKNOWN] = SDLK_a;
-    keymap[DIKI_B - DIKI_UNKNOWN] = SDLK_b;
-    keymap[DIKI_C - DIKI_UNKNOWN] = SDLK_c;
-    keymap[DIKI_D - DIKI_UNKNOWN] = SDLK_d;
-    keymap[DIKI_E - DIKI_UNKNOWN] = SDLK_e;
-    keymap[DIKI_F - DIKI_UNKNOWN] = SDLK_f;
-    keymap[DIKI_G - DIKI_UNKNOWN] = SDLK_g;
-    keymap[DIKI_H - DIKI_UNKNOWN] = SDLK_h;
-    keymap[DIKI_I - DIKI_UNKNOWN] = SDLK_i;
-    keymap[DIKI_J - DIKI_UNKNOWN] = SDLK_j;
-    keymap[DIKI_K - DIKI_UNKNOWN] = SDLK_k;
-    keymap[DIKI_L - DIKI_UNKNOWN] = SDLK_l;
-    keymap[DIKI_M - DIKI_UNKNOWN] = SDLK_m;
-    keymap[DIKI_N - DIKI_UNKNOWN] = SDLK_n;
-    keymap[DIKI_O - DIKI_UNKNOWN] = SDLK_o;
-    keymap[DIKI_P - DIKI_UNKNOWN] = SDLK_p;
-    keymap[DIKI_Q - DIKI_UNKNOWN] = SDLK_q;
-    keymap[DIKI_R - DIKI_UNKNOWN] = SDLK_r;
-    keymap[DIKI_S - DIKI_UNKNOWN] = SDLK_s;
-    keymap[DIKI_T - DIKI_UNKNOWN] = SDLK_t;
-    keymap[DIKI_U - DIKI_UNKNOWN] = SDLK_u;
-    keymap[DIKI_V - DIKI_UNKNOWN] = SDLK_v;
-    keymap[DIKI_W - DIKI_UNKNOWN] = SDLK_w;
-    keymap[DIKI_X - DIKI_UNKNOWN] = SDLK_x;
-    keymap[DIKI_Y - DIKI_UNKNOWN] = SDLK_y;
-    keymap[DIKI_Z - DIKI_UNKNOWN] = SDLK_z;
+    keymap[DIKI_A - DIKI_UNKNOWN] = SDL_SCANCODE_A;
+    keymap[DIKI_B - DIKI_UNKNOWN] = SDL_SCANCODE_B;
+    keymap[DIKI_C - DIKI_UNKNOWN] = SDL_SCANCODE_C;
+    keymap[DIKI_D - DIKI_UNKNOWN] = SDL_SCANCODE_D;
+    keymap[DIKI_E - DIKI_UNKNOWN] = SDL_SCANCODE_E;
+    keymap[DIKI_F - DIKI_UNKNOWN] = SDL_SCANCODE_F;
+    keymap[DIKI_G - DIKI_UNKNOWN] = SDL_SCANCODE_G;
+    keymap[DIKI_H - DIKI_UNKNOWN] = SDL_SCANCODE_H;
+    keymap[DIKI_I - DIKI_UNKNOWN] = SDL_SCANCODE_I;
+    keymap[DIKI_J - DIKI_UNKNOWN] = SDL_SCANCODE_J;
+    keymap[DIKI_K - DIKI_UNKNOWN] = SDL_SCANCODE_K;
+    keymap[DIKI_L - DIKI_UNKNOWN] = SDL_SCANCODE_L;
+    keymap[DIKI_M - DIKI_UNKNOWN] = SDL_SCANCODE_M;
+    keymap[DIKI_N - DIKI_UNKNOWN] = SDL_SCANCODE_N;
+    keymap[DIKI_O - DIKI_UNKNOWN] = SDL_SCANCODE_O;
+    keymap[DIKI_P - DIKI_UNKNOWN] = SDL_SCANCODE_P;
+    keymap[DIKI_Q - DIKI_UNKNOWN] = SDL_SCANCODE_Q;
+    keymap[DIKI_R - DIKI_UNKNOWN] = SDL_SCANCODE_R;
+    keymap[DIKI_S - DIKI_UNKNOWN] = SDL_SCANCODE_S;
+    keymap[DIKI_T - DIKI_UNKNOWN] = SDL_SCANCODE_T;
+    keymap[DIKI_U - DIKI_UNKNOWN] = SDL_SCANCODE_U;
+    keymap[DIKI_V - DIKI_UNKNOWN] = SDL_SCANCODE_V;
+    keymap[DIKI_W - DIKI_UNKNOWN] = SDL_SCANCODE_W;
+    keymap[DIKI_X - DIKI_UNKNOWN] = SDL_SCANCODE_X;
+    keymap[DIKI_Y - DIKI_UNKNOWN] = SDL_SCANCODE_Y;
+    keymap[DIKI_Z - DIKI_UNKNOWN] = SDL_SCANCODE_Z;
 
-    keymap[DIKI_0 - DIKI_UNKNOWN] = SDLK_0;
-    keymap[DIKI_1 - DIKI_UNKNOWN] = SDLK_1;
-    keymap[DIKI_2 - DIKI_UNKNOWN] = SDLK_2;
-    keymap[DIKI_3 - DIKI_UNKNOWN] = SDLK_3;
-    keymap[DIKI_4 - DIKI_UNKNOWN] = SDLK_4;
-    keymap[DIKI_5 - DIKI_UNKNOWN] = SDLK_5;
-    keymap[DIKI_6 - DIKI_UNKNOWN] = SDLK_6;
-    keymap[DIKI_7 - DIKI_UNKNOWN] = SDLK_7;
-    keymap[DIKI_8 - DIKI_UNKNOWN] = SDLK_8;
-    keymap[DIKI_9 - DIKI_UNKNOWN] = SDLK_9;
+    keymap[DIKI_0 - DIKI_UNKNOWN] = SDL_SCANCODE_0;
+    keymap[DIKI_1 - DIKI_UNKNOWN] = SDL_SCANCODE_1;
+    keymap[DIKI_2 - DIKI_UNKNOWN] = SDL_SCANCODE_2;
+    keymap[DIKI_3 - DIKI_UNKNOWN] = SDL_SCANCODE_3;
+    keymap[DIKI_4 - DIKI_UNKNOWN] = SDL_SCANCODE_4;
+    keymap[DIKI_5 - DIKI_UNKNOWN] = SDL_SCANCODE_5;
+    keymap[DIKI_6 - DIKI_UNKNOWN] = SDL_SCANCODE_6;
+    keymap[DIKI_7 - DIKI_UNKNOWN] = SDL_SCANCODE_7;
+    keymap[DIKI_8 - DIKI_UNKNOWN] = SDL_SCANCODE_8;
+    keymap[DIKI_9 - DIKI_UNKNOWN] = SDL_SCANCODE_9;
 
-    keymap[DIKI_F1 - DIKI_UNKNOWN] = SDLK_F1;
-    keymap[DIKI_F2 - DIKI_UNKNOWN] = SDLK_F2;
-    keymap[DIKI_F3 - DIKI_UNKNOWN] = SDLK_F3;
-    keymap[DIKI_F4 - DIKI_UNKNOWN] = SDLK_F4;
-    keymap[DIKI_F5 - DIKI_UNKNOWN] = SDLK_F5;
-    keymap[DIKI_F6 - DIKI_UNKNOWN] = SDLK_F6;
-    keymap[DIKI_F7 - DIKI_UNKNOWN] = SDLK_F7;
-    keymap[DIKI_F8 - DIKI_UNKNOWN] = SDLK_F8;
-    keymap[DIKI_F9 - DIKI_UNKNOWN] = SDLK_F9;
-    keymap[DIKI_F10 - DIKI_UNKNOWN] = SDLK_F10;
-    keymap[DIKI_F11 - DIKI_UNKNOWN] = SDLK_F11;
-    keymap[DIKI_F12 - DIKI_UNKNOWN] = SDLK_F12;
+    keymap[DIKI_F1 - DIKI_UNKNOWN] = SDL_SCANCODE_F1;
+    keymap[DIKI_F2 - DIKI_UNKNOWN] = SDL_SCANCODE_F2;
+    keymap[DIKI_F3 - DIKI_UNKNOWN] = SDL_SCANCODE_F3;
+    keymap[DIKI_F4 - DIKI_UNKNOWN] = SDL_SCANCODE_F4;
+    keymap[DIKI_F5 - DIKI_UNKNOWN] = SDL_SCANCODE_F5;
+    keymap[DIKI_F6 - DIKI_UNKNOWN] = SDL_SCANCODE_F6;
+    keymap[DIKI_F7 - DIKI_UNKNOWN] = SDL_SCANCODE_F7;
+    keymap[DIKI_F8 - DIKI_UNKNOWN] = SDL_SCANCODE_F8;
+    keymap[DIKI_F9 - DIKI_UNKNOWN] = SDL_SCANCODE_F9;
+    keymap[DIKI_F10 - DIKI_UNKNOWN] = SDL_SCANCODE_F10;
+    keymap[DIKI_F11 - DIKI_UNKNOWN] = SDL_SCANCODE_F11;
+    keymap[DIKI_F12 - DIKI_UNKNOWN] = SDL_SCANCODE_F12;
 
-    keymap[DIKI_ESCAPE - DIKI_UNKNOWN] = SDLK_ESCAPE;
-    keymap[DIKI_LEFT - DIKI_UNKNOWN] = SDLK_LEFT;
-    keymap[DIKI_RIGHT - DIKI_UNKNOWN] = SDLK_RIGHT;
-    keymap[DIKI_UP - DIKI_UNKNOWN] = SDLK_UP;
-    keymap[DIKI_DOWN - DIKI_UNKNOWN] = SDLK_DOWN;
-    keymap[DIKI_CONTROL_L - DIKI_UNKNOWN] = SDLK_LCTRL;
-    keymap[DIKI_CONTROL_R - DIKI_UNKNOWN] = SDLK_RCTRL;
-    keymap[DIKI_SHIFT_L - DIKI_UNKNOWN] = SDLK_LSHIFT;
-    keymap[DIKI_SHIFT_R - DIKI_UNKNOWN] = SDLK_RSHIFT;
-    keymap[DIKI_ALT_L - DIKI_UNKNOWN] = SDLK_LALT;
-    keymap[DIKI_ALT_R - DIKI_UNKNOWN] = SDLK_RALT;
-    keymap[DIKI_TAB - DIKI_UNKNOWN] = SDLK_TAB;
-    keymap[DIKI_ENTER - DIKI_UNKNOWN] = SDLK_RETURN;
-    keymap[DIKI_SPACE - DIKI_UNKNOWN] = SDLK_SPACE;
-    keymap[DIKI_BACKSPACE - DIKI_UNKNOWN] = SDLK_BACKSPACE;
-    keymap[DIKI_INSERT - DIKI_UNKNOWN] = SDLK_INSERT;
-    keymap[DIKI_DELETE - DIKI_UNKNOWN] = SDLK_DELETE;
-    keymap[DIKI_HOME - DIKI_UNKNOWN] = SDLK_HOME;
-    keymap[DIKI_END - DIKI_UNKNOWN] = SDLK_END;
-    keymap[DIKI_PAGE_UP - DIKI_UNKNOWN] = SDLK_PAGEUP;
-    keymap[DIKI_PAGE_DOWN - DIKI_UNKNOWN] = SDLK_PAGEDOWN;
-    keymap[DIKI_CAPS_LOCK - DIKI_UNKNOWN] = SDLK_CAPSLOCK;
-    keymap[DIKI_NUM_LOCK - DIKI_UNKNOWN] = SDLK_NUMLOCK;
-    keymap[DIKI_SCROLL_LOCK - DIKI_UNKNOWN] = SDLK_SCROLLOCK;
-    keymap[DIKI_PRINT - DIKI_UNKNOWN] = SDLK_PRINT;
-    keymap[DIKI_PAUSE - DIKI_UNKNOWN] = SDLK_PAUSE;
+    keymap[DIKI_ESCAPE - DIKI_UNKNOWN] = SDL_SCANCODE_ESCAPE;
+    keymap[DIKI_LEFT - DIKI_UNKNOWN] = SDL_SCANCODE_LEFT;
+    keymap[DIKI_RIGHT - DIKI_UNKNOWN] = SDL_SCANCODE_RIGHT;
+    keymap[DIKI_UP - DIKI_UNKNOWN] = SDL_SCANCODE_UP;
+    keymap[DIKI_DOWN - DIKI_UNKNOWN] = SDL_SCANCODE_DOWN;
+    keymap[DIKI_CONTROL_L - DIKI_UNKNOWN] = SDL_SCANCODE_LCTRL;
+    keymap[DIKI_CONTROL_R - DIKI_UNKNOWN] = SDL_SCANCODE_RCTRL;
+    keymap[DIKI_SHIFT_L - DIKI_UNKNOWN] = SDL_SCANCODE_LSHIFT;
+    keymap[DIKI_SHIFT_R - DIKI_UNKNOWN] = SDL_SCANCODE_RSHIFT;
+    keymap[DIKI_ALT_L - DIKI_UNKNOWN] = SDL_SCANCODE_LALT;
+    keymap[DIKI_ALT_R - DIKI_UNKNOWN] = SDL_SCANCODE_RALT;
+    keymap[DIKI_META_L - DIKI_UNKNOWN] = SDL_SCANCODE_LGUI;
+    keymap[DIKI_META_R - DIKI_UNKNOWN] = SDL_SCANCODE_RGUI;
+    keymap[DIKI_SUPER_L - DIKI_UNKNOWN] = SDL_SCANCODE_APPLICATION;
+    keymap[DIKI_SUPER_R - DIKI_UNKNOWN] = SDL_SCANCODE_APPLICATION;
+    //FIXME:Do we read hyper keys ?
+    //keymap[DIKI_HYPER_L - DIKI_UNKNOWN] = SDL_SCANCODE_APPLICATION;
+    //keymap[DIKI_HYPER_R - DIKI_UNKNOWN] = SDL_SCANCODE_APPLICATION;
+    keymap[DIKI_TAB - DIKI_UNKNOWN] = SDL_SCANCODE_TAB;
+    keymap[DIKI_ENTER - DIKI_UNKNOWN] = SDL_SCANCODE_RETURN;
+    keymap[DIKI_SPACE - DIKI_UNKNOWN] = SDL_SCANCODE_SPACE;
+    keymap[DIKI_BACKSPACE - DIKI_UNKNOWN] = SDL_SCANCODE_BACKSPACE;
+    keymap[DIKI_INSERT - DIKI_UNKNOWN] = SDL_SCANCODE_INSERT;
+    keymap[DIKI_DELETE - DIKI_UNKNOWN] = SDL_SCANCODE_DELETE;
+    keymap[DIKI_HOME - DIKI_UNKNOWN] = SDL_SCANCODE_HOME;
+    keymap[DIKI_END - DIKI_UNKNOWN] = SDL_SCANCODE_END;
+    keymap[DIKI_PAGE_UP - DIKI_UNKNOWN] = SDL_SCANCODE_PAGEUP;
+    keymap[DIKI_PAGE_DOWN - DIKI_UNKNOWN] = SDL_SCANCODE_PAGEDOWN;
+    keymap[DIKI_CAPS_LOCK - DIKI_UNKNOWN] = SDL_SCANCODE_CAPSLOCK;
+    keymap[DIKI_NUM_LOCK - DIKI_UNKNOWN] = SDL_SCANCODE_NUMLOCKCLEAR;
+    keymap[DIKI_SCROLL_LOCK - DIKI_UNKNOWN] = SDL_SCANCODE_SCROLLLOCK;
+    keymap[DIKI_PRINT - DIKI_UNKNOWN] = SDL_SCANCODE_PRINTSCREEN;
+    keymap[DIKI_PAUSE - DIKI_UNKNOWN] = SDL_SCANCODE_PAUSE;
 
-    keymap[DIKI_KP_EQUAL - DIKI_UNKNOWN] = SDLK_KP_EQUALS;
-    keymap[DIKI_KP_DECIMAL - DIKI_UNKNOWN] = SDLK_KP_PERIOD;
-    keymap[DIKI_KP_0 - DIKI_UNKNOWN] = SDLK_KP0;
-    keymap[DIKI_KP_1 - DIKI_UNKNOWN] = SDLK_KP1;
-    keymap[DIKI_KP_2 - DIKI_UNKNOWN] = SDLK_KP2;
-    keymap[DIKI_KP_3 - DIKI_UNKNOWN] = SDLK_KP3;
-    keymap[DIKI_KP_4 - DIKI_UNKNOWN] = SDLK_KP4;
-    keymap[DIKI_KP_5 - DIKI_UNKNOWN] = SDLK_KP5;
-    keymap[DIKI_KP_6 - DIKI_UNKNOWN] = SDLK_KP6;
-    keymap[DIKI_KP_7 - DIKI_UNKNOWN] = SDLK_KP7;
-    keymap[DIKI_KP_8 - DIKI_UNKNOWN] = SDLK_KP8;
-    keymap[DIKI_KP_9 - DIKI_UNKNOWN] = SDLK_KP9;
-    keymap[DIKI_KP_DIV - DIKI_UNKNOWN] = SDLK_KP_DIVIDE;
-    keymap[DIKI_KP_MULT - DIKI_UNKNOWN] = SDLK_KP_MULTIPLY;
-    keymap[DIKI_KP_MINUS - DIKI_UNKNOWN] = SDLK_KP_MINUS;
-    keymap[DIKI_KP_PLUS - DIKI_UNKNOWN] = SDLK_KP_PLUS;
-    keymap[DIKI_KP_ENTER - DIKI_UNKNOWN] = SDLK_KP_ENTER;
+    keymap[DIKI_KP_EQUAL - DIKI_UNKNOWN] = SDL_SCANCODE_KP_EQUALS;
+    keymap[DIKI_KP_DECIMAL - DIKI_UNKNOWN] = SDL_SCANCODE_KP_PERIOD;
+    keymap[DIKI_KP_0 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_0;
+    keymap[DIKI_KP_1 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_1;
+    keymap[DIKI_KP_2 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_2;
+    keymap[DIKI_KP_3 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_3;
+    keymap[DIKI_KP_4 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_4;
+    keymap[DIKI_KP_5 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_5;
+    keymap[DIKI_KP_6 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_6;
+    keymap[DIKI_KP_7 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_7;
+    keymap[DIKI_KP_8 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_8;
+    keymap[DIKI_KP_9 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_9;
+    keymap[DIKI_KP_DIV - DIKI_UNKNOWN] = SDL_SCANCODE_KP_DIVIDE;
+    keymap[DIKI_KP_MULT - DIKI_UNKNOWN] = SDL_SCANCODE_KP_MULTIPLY;
+    keymap[DIKI_KP_MINUS - DIKI_UNKNOWN] = SDL_SCANCODE_KP_MINUS;
+    keymap[DIKI_KP_PLUS - DIKI_UNKNOWN] = SDL_SCANCODE_KP_PLUS;
+    keymap[DIKI_KP_ENTER - DIKI_UNKNOWN] = SDL_SCANCODE_KP_ENTER;
 
-    keymap[DIKI_QUOTE_LEFT - DIKI_UNKNOWN] = SDLK_BACKQUOTE;    /*  TLDE  */
-    keymap[DIKI_MINUS_SIGN - DIKI_UNKNOWN] = SDLK_MINUS;        /*  AE11  */
-    keymap[DIKI_EQUALS_SIGN - DIKI_UNKNOWN] = SDLK_EQUALS;      /*  AE12  */
-    keymap[DIKI_BRACKET_LEFT - DIKI_UNKNOWN] = SDLK_RIGHTBRACKET;       /*  AD11  */
-    keymap[DIKI_BRACKET_RIGHT - DIKI_UNKNOWN] = SDLK_LEFTBRACKET;       /*  AD12  */
-    keymap[DIKI_BACKSLASH - DIKI_UNKNOWN] = SDLK_BACKSLASH;     /*  BKSL  */
-    keymap[DIKI_SEMICOLON - DIKI_UNKNOWN] = SDLK_SEMICOLON;     /*  AC10  */
-    keymap[DIKI_QUOTE_RIGHT - DIKI_UNKNOWN] = SDLK_QUOTE;       /*  AC11  */
-    keymap[DIKI_COMMA - DIKI_UNKNOWN] = SDLK_COMMA;     /*  AB08  */
-    keymap[DIKI_PERIOD - DIKI_UNKNOWN] = SDLK_PERIOD;   /*  AB09  */
-    keymap[DIKI_SLASH - DIKI_UNKNOWN] = SDLK_SLASH;     /*  AB10  */
-    keymap[DIKI_LESS_SIGN - DIKI_UNKNOWN] = SDLK_LESS;  /*  103rd  */
+    keymap[DIKI_QUOTE_LEFT - DIKI_UNKNOWN] = SDL_SCANCODE_GRAVE;        /*  TLDE  */
+    keymap[DIKI_MINUS_SIGN - DIKI_UNKNOWN] = SDL_SCANCODE_MINUS;        /*  AE11  */
+    keymap[DIKI_EQUALS_SIGN - DIKI_UNKNOWN] = SDL_SCANCODE_EQUALS;      /*  AE12  */
+    keymap[DIKI_BRACKET_LEFT - DIKI_UNKNOWN] = SDL_SCANCODE_RIGHTBRACKET;       /*  AD11  */
+    keymap[DIKI_BRACKET_RIGHT - DIKI_UNKNOWN] = SDL_SCANCODE_LEFTBRACKET;       /*  AD12  */
+    keymap[DIKI_BACKSLASH - DIKI_UNKNOWN] = SDL_SCANCODE_BACKSLASH;     /*  BKSL  */
+    keymap[DIKI_SEMICOLON - DIKI_UNKNOWN] = SDL_SCANCODE_SEMICOLON;     /*  AC10  */
+    keymap[DIKI_QUOTE_RIGHT - DIKI_UNKNOWN] = SDL_SCANCODE_APOSTROPHE;  /*  AC11  */
+    keymap[DIKI_COMMA - DIKI_UNKNOWN] = SDL_SCANCODE_COMMA;     /*  AB08  */
+    keymap[DIKI_PERIOD - DIKI_UNKNOWN] = SDL_SCANCODE_PERIOD;   /*  AB09  */
+    keymap[DIKI_SLASH - DIKI_UNKNOWN] = SDL_SCANCODE_SLASH;     /*  AB10  */
+    keymap[DIKI_LESS_SIGN - DIKI_UNKNOWN] = SDL_SCANCODE_NONUSBACKSLASH;        /*  103rd  */
+
 }
 
 static SDL_keysym *
-DirectFB_TranslateKey(DFBInputDeviceKeyIdentifier key_id,
-                      DFBInputDeviceKeySymbol key_symbol,
-                      DFBInputDeviceModifierMask key_mod, SDL_keysym * keysym)
+DirectFB_TranslateKey(_THIS, DFBWindowEvent * evt, SDL_keysym * keysym)
 {
-    SDLMod mod = KMOD_NONE;
+    SDL_DFB_DEVICEDATA(_this);
 
-    /*
-     *  Set modifier information 
-     */
+    if (evt->key_code >= 0
+        && evt->key_code < SDL_arraysize(linux_scancode_table))
+        keysym->scancode = linux_scancode_table[evt->key_code]; // key_id;
+    else
+        keysym->scancode = SDL_SCANCODE_UNKNOWN;
 
-    if (key_mod & DIMM_SHIFT)
-        mod = mod | KMOD_LSHIFT;
-    if (key_mod & DIMM_CONTROL)
-        mod = mod | KMOD_LCTRL;
-    if (key_mod & DIMM_ALT)
-        mod = mod | KMOD_LALT;
-    if (key_mod & DIMM_ALTGR)
-        mod = mod | KMOD_RALT;
-    if (key_mod & DIMM_META)
-        mod = mod | KMOD_LMETA;
+    if (keysym->scancode == SDL_SCANCODE_UNKNOWN || devdata->kbdgeneric) {
+        if (evt->key_id - DIKI_UNKNOWN < SDL_arraysize(keymap))
+            keysym->scancode = keymap[evt->key_id - DIKI_UNKNOWN];
+        else
+            keysym->scancode = SDL_SCANCODE_UNKNOWN;
+    }
 
-    /* Set the keysym information */
-    keysym->scancode = key_id;
-
-    keysym->mod = mod;
     keysym->unicode =
-        (DFB_KEY_TYPE(key_symbol) == DIKT_UNICODE) ? key_symbol : 0;
-
-    if (key_symbol > 0 && key_symbol < 255)
-        keysym->sym = key_symbol;
-    else
-        keysym->sym = keymap[key_id - DIKI_UNKNOWN];
+        (DFB_KEY_TYPE(evt->key_symbol) == DIKT_UNICODE) ? evt->key_symbol : 0;
+    if (keysym->unicode == 0
+        && (evt->key_symbol > 0 && evt->key_symbol < 255))
+        keysym->unicode = evt->key_symbol;
 
     return keysym;
 }
@@ -289,7 +325,43 @@
     }
 }
 
+static DFBEnumerationResult
+input_device_cb(DFBInputDeviceID device_id, DFBInputDeviceDescription desc,
+                void *callbackdata)
+{
+    DFB_DeviceData *devdata = callbackdata;
+    SDL_Keyboard keyboard;
+    SDL_scancode scancode;
+    SDLKey keymap[SDL_NUM_SCANCODES];
+
+    if ((desc.caps & DIDTF_KEYBOARD) && device_id == DIDID_KEYBOARD) {
+        SDL_zero(keyboard);
+        devdata->keyboard = SDL_AddKeyboard(&keyboard, -1);
+        if (!strncmp("X11", desc.name, 3))
+            devdata->kbdgeneric = 1;
+
+        SDL_GetDefaultKeymap(keymap);
+        SDL_SetKeymap(devdata->keyboard, 0, keymap, SDL_NUM_SCANCODES);
+    }
+    return DFB_OK;
+}
+
+void
+DirectFB_InitKeyboard(_THIS)
+{
+    SDL_DFB_DEVICEDATA(_this);
+    int ret;
+
+    DirectFB_InitOSKeymap(_this);
+
+    devdata->kbdgeneric = 0;
+
+    SDL_DFB_CHECK(devdata->dfb->
+                  EnumInputDevices(devdata->dfb, input_device_cb, devdata));
+}
+
 #if 0
+/* FIXME: Remove once determined this is not needed in fullscreen mode */
 void
 DirectFB_PumpEvents(_THIS)
 {