changeset 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 4eb759edddf5
children 91f1706b27be
files src/video/directfb/SDL_DirectFB_events.c src/video/directfb/SDL_DirectFB_events.h src/video/directfb/SDL_DirectFB_mouse.c src/video/directfb/SDL_DirectFB_render.c src/video/directfb/SDL_DirectFB_video.c src/video/directfb/SDL_DirectFB_video.h
diffstat 6 files changed, 418 insertions(+), 226 deletions(-) [+]
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)
 {
--- a/src/video/directfb/SDL_DirectFB_events.h	Tue Aug 26 02:26:18 2008 +0000
+++ b/src/video/directfb/SDL_DirectFB_events.h	Tue Aug 26 02:32:45 2008 +0000
@@ -24,5 +24,6 @@
 #include "SDL_DirectFB_video.h"
 
 /* Functions to be exported */
-extern void DirectFB_InitOSKeymap(_THIS);
+extern void DirectFB_InitKeyboard(_THIS);
 extern void DirectFB_PumpEventsWindow(_THIS);
+extern SDLKey DirectFB_GetLayoutKey(_THIS, SDLKey physicalKey);
--- a/src/video/directfb/SDL_DirectFB_mouse.c	Tue Aug 26 02:26:18 2008 +0000
+++ b/src/video/directfb/SDL_DirectFB_mouse.c	Tue Aug 26 02:32:45 2008 +0000
@@ -80,7 +80,7 @@
 
     dsc.flags =
         DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_CAPS;
-    dsc.caps = DSCAPS_NONE;     //DSCAPS_SYSTEMONLY;
+    dsc.caps = DSCAPS_VIDEOONLY;
     dsc.width = surface->w;
     dsc.height = surface->h;
     dsc.pixelformat = DSPF_ARGB;
@@ -101,7 +101,6 @@
             dest[i] = 0x00000000;
         else
             dest[i] = p[i];
-    //memcpy(dest, surface->pixels, surface->w * surface->h * 4);
     curdata->surf->Unlock(curdata->surf);
     return cursor;
   error:
@@ -112,7 +111,6 @@
 static int
 DirectFB_ShowCursor(SDL_Cursor * cursor)
 {
-    //FIXME check for null cursor here
     SDL_DFB_CURSORDATA(cursor);
     SDL_VideoDevice *dev = SDL_GetVideoDevice();
     SDL_DFB_DEVICEDATA(dev);
@@ -136,7 +134,6 @@
             SDL_DFB_CHECKERR(windata->window->
                              SetCursorShape(windata->window, curdata->surf,
                                             curdata->hotx, curdata->hoty));
-        //FIXME: This is somehow a directfb issue
         //TODO: Check administrative 
         SDL_DFB_CHECKERR(dispdata->layer->
                          SetCooperativeLevel(dispdata->layer,
@@ -176,7 +173,6 @@
 static void
 DirectFB_WarpMouse(SDL_Mouse * mouse, SDL_WindowID windowID, int x, int y)
 {
-//      SDL_DFB_CURSORDATA(cursor);     
     SDL_Window *window = SDL_GetWindowFromID(windowID);
     SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
     DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata;
--- a/src/video/directfb/SDL_DirectFB_render.c	Tue Aug 26 02:26:18 2008 +0000
+++ b/src/video/directfb/SDL_DirectFB_render.c	Tue Aug 26 02:32:45 2008 +0000
@@ -87,7 +87,8 @@
      (SDL_TEXTUREMODULATE_NONE | SDL_TEXTUREMODULATE_COLOR |
       SDL_TEXTUREMODULATE_ALPHA),
      (SDL_TEXTUREBLENDMODE_NONE | SDL_TEXTUREBLENDMODE_MASK |
-      SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_MOD),
+      SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD |
+      SDL_TEXTUREBLENDMODE_MOD),
      (SDL_TEXTURESCALEMODE_NONE | SDL_TEXTURESCALEMODE_FAST),
      14,
      {
@@ -124,16 +125,9 @@
     void *pixels;
     int pitch;
     IDirectFBPalette *palette;
+    DFB_DisplayData *display;
 } DirectFB_TextureData;
 
-static void
-UpdateYUVTextureData(SDL_Texture * texture)
-{
-    /*
-     * Not needed - directfb supports yuv surfaces
-     */
-}
-
 void
 DirectFB_AddRenderDriver(_THIS)
 {
@@ -178,7 +172,7 @@
     renderer->DestroyTexture = DirectFB_DestroyTexture;
     renderer->DestroyRenderer = DirectFB_DestroyRenderer;
     renderer->info = DirectFB_RenderDriver.info;
-    renderer->window = window->id;      // SDL window id
+    renderer->window = window->id;      /* SDL window id */
     renderer->driverdata = data;
 
     renderer->info.flags =
@@ -200,7 +194,7 @@
     else
         renderer->info.flags |= SDL_RENDERER_SINGLEBUFFER;
 
-    data->isyuvdirect = 0;
+    data->isyuvdirect = 1;      /* default is on! */
     p = getenv("SDL_DIRECTFB_YUV_DIRECT");
     if (p)
         data->isyuvdirect = atoi(p);
@@ -293,6 +287,55 @@
 }
 
 static int
+DirectFB_AcquireVidLayer(SDL_Renderer * renderer, SDL_Texture * texture)
+{
+    SDL_DFB_RENDERERDATA(renderer);
+    SDL_Window *window = SDL_GetWindowFromID(renderer->window);
+    SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
+    SDL_DFB_DEVICEDATA(display->device);
+    DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata;
+    DirectFB_TextureData *data = texture->driverdata;
+    DFBDisplayLayerConfig layconf;
+    int ret;
+
+    if (renddata->isyuvdirect && (dispdata->vidID >= 0)
+        && (!dispdata->vidIDinuse)
+        && SDL_ISPIXELFORMAT_FOURCC(data->format)) {
+        layconf.flags = DLCONF_WIDTH | DLCONF_HEIGHT | DLCONF_PIXELFORMAT;
+        layconf.width = texture->w;
+        layconf.height = texture->h;
+        layconf.pixelformat = SDLToDFBPixelFormat(data->format);
+
+        SDL_DFB_CHECKERR(devdata->dfb->
+                         GetDisplayLayer(devdata->dfb, dispdata->vidID,
+                                         &data->vidlayer));
+        SDL_DFB_CHECKERR(data->vidlayer->
+                         SetCooperativeLevel(data->vidlayer,
+                                             DLSCL_EXCLUSIVE));
+        SDL_DFB_CHECKERR(data->vidlayer->
+                         SetConfiguration(data->vidlayer, &layconf));
+        SDL_DFB_CHECKERR(data->vidlayer->
+                         GetSurface(data->vidlayer, &data->surface));
+        //SDL_DFB_CHECKERR(data->vidlayer->GetDescription(data->vidlayer, laydsc));
+        dispdata->vidIDinuse = 1;
+        data->display = dispdata;
+        SDL_DFB_DEBUG("Created HW YUV surface\n");
+
+        return 0;
+    }
+    return 1;
+  error:
+    if (data->vidlayer) {
+        SDL_DFB_RELEASE(data->surface);
+        SDL_DFB_CHECKERR(data->vidlayer->
+                         SetCooperativeLevel(data->vidlayer,
+                                             DLSCL_ADMINISTRATIVE));
+        SDL_DFB_RELEASE(data->vidlayer);
+    }
+    return 1;
+}
+
+static int
 DirectFB_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
 {
     SDL_DFB_RENDERERDATA(renderer);
@@ -300,7 +343,6 @@
     SDL_DFB_WINDOWDATA(window);
     SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
     SDL_DFB_DEVICEDATA(display->device);
-    DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata;
     DirectFB_TextureData *data;
     DFBResult ret;
     DFBSurfaceDescription dsc;
@@ -313,37 +355,23 @@
     data->format = texture->format;
     data->pitch = (texture->w * SDL_BYTESPERPIXEL(data->format));
     data->vidlayer = NULL;
-    if (renddata->isyuvdirect && (dispdata->vidID >= 0)
-        && SDL_ISPIXELFORMAT_FOURCC(data->format)) {
-        SDL_DFB_CHECKERR(devdata->dfb->
-                         GetDisplayLayer(devdata->dfb, dispdata->vidID,
-                                         &data->vidlayer));
-        layconf.flags = DLCONF_WIDTH | DLCONF_HEIGHT | DLCONF_PIXELFORMAT;
-        layconf.width = texture->w;
-        layconf.height = texture->h;
-        layconf.pixelformat = SDLToDFBPixelFormat(data->format);
 
-        SDL_DFB_CHECKERR(data->vidlayer->
-                         SetCooperativeLevel(data->vidlayer,
-                                             DLSCL_EXCLUSIVE));
-        SDL_DFB_CHECKERR(data->vidlayer->
-                         SetConfiguration(data->vidlayer, &layconf));
-        SDL_DFB_CHECKERR(data->vidlayer->
-                         GetSurface(data->vidlayer, &data->surface));
-        SDL_DFB_CHECKERR(data->vidlayer->
-                         GetDescription(data->vidlayer, &laydsc));
-        SDL_DFB_DEBUG("Created HW YUV surface\n");
-    }
-    if (!data->vidlayer) {
+    if (DirectFB_AcquireVidLayer(renderer, texture) != 0) {
         /* fill surface description */
         dsc.flags =
             DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_CAPS;
         dsc.width = texture->w;
         dsc.height = texture->h;
-        /* Never use DSCAPS_VIDEOONLY here. It kills performance
+        /* <1.2 Never use DSCAPS_VIDEOONLY here. It kills performance
          * No DSCAPS_SYSTEMONLY either - let dfb decide
+         * 1.2: DSCAPS_SYSTEMONLY boosts performance by factor ~8
          */
-        dsc.caps = 0;           //DSCAPS_PREMULTIPLIED;
+        dsc.caps = DSCAPS_PREMULTIPLIED;
+
+        if (texture->access == SDL_TEXTUREACCESS_STREAMING)
+            dsc.caps |= DSCAPS_SYSTEMONLY;
+        else
+            dsc.caps |= DSCAPS_VIDEOONLY;
 
         /* find the right pixelformat */
 
@@ -469,6 +497,7 @@
     case SDL_TEXTUREBLENDMODE_NONE:
     case SDL_TEXTUREBLENDMODE_MASK:
     case SDL_TEXTUREBLENDMODE_BLEND:
+    case SDL_TEXTUREBLENDMODE_ADD:
     case SDL_TEXTUREBLENDMODE_MOD:
         return 0;
     default:
@@ -513,8 +542,8 @@
     size_t length;
 
     SDL_DFB_CHECKERR(data->surface->Lock(data->surface,
-                                         DSLF_WRITE | DSLF_READ, &dpixels,
-                                         &dpitch));
+                                         DSLF_WRITE | DSLF_READ,
+                                         ((void **) &dpixels), &dpitch));
     src = (Uint8 *) pixels;
     dst =
         (Uint8 *) dpixels + rect->y * dpitch +
@@ -648,27 +677,52 @@
         if (texture->
             modMode & (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA))
         {
-            u8 alpha = 0xFF;
-            if (texture->modMode & SDL_TEXTUREMODULATE_ALPHA)
+            Uint8 alpha = 0xFF;
+            if (texture->modMode & SDL_TEXTUREMODULATE_ALPHA) {
                 alpha = texture->a;
-            if (texture->modMode & SDL_TEXTUREMODULATE_COLOR)
+                flags |= DSBLIT_SRC_PREMULTCOLOR;
+                SDL_DFB_CHECKERR(data->surface->SetColor(data->surface, 0xFF,
+                                                         0xFF, 0xFF, alpha));
+            }
+            if (texture->modMode & SDL_TEXTUREMODULATE_COLOR) {
                 SDL_DFB_CHECKERR(data->surface->
                                  SetColor(data->surface, texture->r,
                                           texture->g, texture->b, alpha));
-            else
-                SDL_DFB_CHECKERR(data->surface->SetColor(data->surface, 0xFF,
-                                                         0xFF, 0xFF, alpha));
-            // Only works together ....
-            flags |= DSBLIT_COLORIZE | DSBLIT_SRC_PREMULTCOLOR;
+                /* Only works together .... */
+                flags |= DSBLIT_COLORIZE | DSBLIT_SRC_PREMULTCOLOR;
+            }
         }
 
-        if (texture->
-            blendMode & (SDL_TEXTUREBLENDMODE_MASK |
-                         SDL_TEXTUREBLENDMODE_BLEND)) {
+        switch (texture->blendMode) {
+        case SDL_TEXTUREBLENDMODE_NONE: /**< No blending */
+            flags |= DSBLIT_NOFX;
+            data->surface->SetSrcBlendFunction(data->surface, DSBF_ONE);
+            data->surface->SetDstBlendFunction(data->surface, DSBF_ZERO);
+            break;
+        case SDL_TEXTUREBLENDMODE_MASK: /**< dst = A ? src : dst (alpha is mask) */
+            flags |= DSBLIT_BLEND_ALPHACHANNEL;
+            data->surface->SetSrcBlendFunction(data->surface, DSBF_SRCALPHA);
+            data->surface->SetDstBlendFunction(data->surface,
+                                               DSBF_INVSRCALPHA);
+            break;
+        case SDL_TEXTUREBLENDMODE_BLEND:/**< dst = (src * A) + (dst * (1-A)) */
             flags |= DSBLIT_BLEND_ALPHACHANNEL;
-        } else {
-            flags |= DSBLIT_NOFX;
+            data->surface->SetSrcBlendFunction(data->surface, DSBF_SRCALPHA);
+            data->surface->SetDstBlendFunction(data->surface,
+                                               DSBF_INVSRCALPHA);
+            break;
+        case SDL_TEXTUREBLENDMODE_ADD:  /**< dst = (src * A) + dst */
+            flags |= DSBLIT_BLEND_ALPHACHANNEL;
+            data->surface->SetSrcBlendFunction(data->surface, DSBF_SRCALPHA);
+            data->surface->SetDstBlendFunction(data->surface, DSBF_ONE);
+            break;
+        case SDL_TEXTUREBLENDMODE_MOD:  /**< dst = src * dst */
+            flags |= DSBLIT_BLEND_ALPHACHANNEL;
+            data->surface->SetSrcBlendFunction(data->surface, DSBF_DESTCOLOR);
+            data->surface->SetDstBlendFunction(data->surface, DSBF_ZERO);
+            break;
         }
+
         SDL_DFB_CHECKERR(data->surface->
                          SetBlittingFlags(data->surface, flags));
         if (srcrect->w == dstrect->w && srcrect->h == dstrect->h) {
@@ -720,6 +774,11 @@
     }
     SDL_DFB_RELEASE(data->palette);
     SDL_DFB_RELEASE(data->surface);
+    if (data->display) {
+        data->display->vidIDinuse = 0;
+        data->vidlayer->SetCooperativeLevel(data->vidlayer,
+                                            DLSCL_ADMINISTRATIVE);
+    }
     SDL_DFB_RELEASE(data->vidlayer);
     SDL_free(data);
     texture->driverdata = NULL;
--- a/src/video/directfb/SDL_DirectFB_video.c	Tue Aug 26 02:26:18 2008 +0000
+++ b/src/video/directfb/SDL_DirectFB_video.c	Tue Aug 26 02:32:45 2008 +0000
@@ -23,11 +23,6 @@
 	
 */
 
-/* TODO: Various
- * Add Mouse support from 1.2 directfb driver
- * - Interface is defined in SDL_Mouse.c.h
- * - Default Cursor automatically created
- */
 
 #include "SDL_config.h"
 
@@ -141,7 +136,6 @@
     device->GetDisplayGammaRamp = NULL;
 #endif
     device->PumpEvents = DirectFB_PumpEventsWindow;
-
     device->CreateWindow = DirectFB_CreateWindow;
     device->CreateWindowFrom = DirectFB_CreateWindowFrom;
     device->SetWindowTitle = DirectFB_SetWindowTitle;
@@ -299,14 +293,11 @@
     DFB_DisplayData *dispdata;
     DFB_DeviceData *devdata;
     SDL_DisplayMode mode;
-    SDL_Keyboard keyboard;
     int i;
     DFBResult ret;
     int tcw[DFB_MAX_SCREENS];
     int tch[DFB_MAX_SCREENS];
 
-    SDL_zero(keyboard);
-
     SDL_DFB_CHECKERR(DirectFBInit(NULL, NULL));
     SDL_DFB_CHECKERR(DirectFBCreate(&dfb));
 
@@ -325,7 +316,15 @@
         devdata->aux = i;
         SDL_DFB_CHECKERR(screen->
                          EnumDisplayLayers(screen, &cbLayers, devdata));
+#if (DIRECTFB_MAJOR_VERSION >= 1)
         screen->GetSize(screen, &tcw[i], &tch[i]);
+#else
+        /* FIXME: this is only used to center windows
+         *        Should be done otherwise, e.g. get surface from layer
+         */
+        tcw[i] = 800;
+        tch[i] = 600;
+#endif
         screen->Release(screen);
     }
 
@@ -369,6 +368,7 @@
         /* YUV - Video layer */
 
         dispdata->vidID = devdata->vidlayer[i];
+        dispdata->vidIDinuse = 0;
 
         SDL_zero(display);
 
@@ -400,9 +400,8 @@
 
     DirectFB_AddRenderDriver(_this);
     DirectFB_InitMouse(_this);
+    DirectFB_InitKeyboard(_this);
     //devdata->mouse = SDL_AddMouse(&mouse, -1);
-    devdata->keyboard = SDL_AddKeyboard(&keyboard, -1);
-    DirectFB_InitOSKeymap(_this);
 
     return 0;
 
@@ -453,8 +452,6 @@
         //SDL_free(dispdata);
     }
 
-    //SDL_DFB_RELEASE(devdata->eventbuffer);
-
     SDL_DFB_RELEASE(devdata->dfb);
 
     SDL_DelMouse(devdata->mouse);
@@ -579,12 +576,13 @@
     DFBDisplayLayerConfig config, rconfig;
     DFBDisplayLayerConfigFlags fail = 0;
     DFBResult ret;
+    DFB_WindowData *win;
 
     SDL_DFB_CHECKERR(data->layer->
                      SetCooperativeLevel(data->layer, DLSCL_ADMINISTRATIVE));
 
     SDL_DFB_CHECKERR(data->layer->GetConfiguration(data->layer, &config));
-    config.flags = DLCONF_WIDTH | DLCONF_HEIGHT | DLCONF_BUFFERMODE;
+    config.flags = DLCONF_WIDTH | DLCONF_HEIGHT;        // | DLCONF_BUFFERMODE;
     if (mode->format != SDL_PIXELFORMAT_UNKNOWN) {
         config.flags |= DLCONF_PIXELFORMAT;
         config.pixelformat = SDLToDFBPixelFormat(mode->format);
@@ -593,7 +591,7 @@
     config.width = mode->w;
     config.height = mode->h;
 
-    config.buffermode = DLBM_BACKVIDEO;
+    //config.buffermode = DLBM_BACKVIDEO;
 
     //config.pixelformat = GetFormatForBpp (bpp, HIDDEN->layer);
 
@@ -614,12 +612,35 @@
 
     if ((config.width != rconfig.width) ||
         (config.height != rconfig.height) ||
-        (config.pixelformat != rconfig.pixelformat)) {
+        ((mode->format != SDL_PIXELFORMAT_UNKNOWN)
+         && (config.pixelformat != rconfig.pixelformat))) {
         SDL_DFB_DEBUG("Error setting mode %dx%d-%x\n", mode->w, mode->h,
                       mode->format);
         return -1;
     }
 
+    data->pixelformat = rconfig.pixelformat;
+    data->cw = config.width;
+    data->ch = config.height;
+    SDL_CurrentDisplay.current_mode = *mode;
+
+    /*
+     * FIXME: video mode switch is currently broken
+     * 
+     * DirectFB 1.2.0-rc1 even has a broken cursor after a switch
+     * The following code needs to be revisited whether it is still 
+     * needed once the switch works again.
+     */
+
+    win = devdata->firstwin;
+
+    while (win) {
+        SDL_DFB_RELEASE(win->surface);
+        SDL_DFB_CHECKERR(win->window->GetSurface(win->window, &win->surface));
+        win = win->next;
+    }
+
+
     return 0;
   error:
     return -1;
@@ -680,8 +701,16 @@
     }
 
     desc.flags =
-        DWDESC_WIDTH | DWDESC_HEIGHT | DWDESC_CAPS | DWDESC_PIXELFORMAT |
+        DWDESC_WIDTH | DWDESC_HEIGHT /*| DWDESC_CAPS */  | DWDESC_PIXELFORMAT
+        |
         DWDESC_SURFACE_CAPS;
+
+#if (DIRECTFB_MAJOR_VERSION == 1) && (DIRECTFB_MINOR_VERSION >= 0)
+    /* Needed for 1.2 */
+    desc.flags |= DWDESC_POSX | DWDESC_POSY;
+    desc.posx = x;
+    desc.posy = y;
+#else
     if (!(window->flags & SDL_WINDOW_FULLSCREEN)
         && window->x != SDL_WINDOWPOS_UNDEFINED
         && window->y != SDL_WINDOWPOS_UNDEFINED) {
@@ -689,12 +718,13 @@
         desc.posx = x;
         desc.posy = y;
     }
+#endif
 
     desc.width = window->w;
     desc.height = window->h;
     desc.pixelformat = dispdata->pixelformat;
-    desc.caps = 0;              //DWCAPS_DOUBLEBUFFER;
-    desc.surface_caps = DSCAPS_DOUBLE | DSCAPS_TRIPLE;  //| DSCAPS_PREMULTIPLIED;
+    desc.caps = 0;              // DWCAPS_DOUBLEBUFFER;
+    desc.surface_caps = DSCAPS_DOUBLE | DSCAPS_TRIPLE / DSCAPS_PREMULTIPLIED;
 
     /* Create the window. */
     SDL_DFB_CHECKERR(dispdata->layer->
@@ -790,21 +820,52 @@
     SDL_DFB_DEVICEDATA(_this);
     SDL_DFB_WINDOWDATA(window);
     SDL_DFB_DISPLAYDATA(_this, window);
+    int x, y;
 
-    if (!(window->flags & SDL_WINDOW_FULLSCREEN))
-        windata->window->MoveTo(windata->window, window->x, window->y);
+    if (window->y == SDL_WINDOWPOS_UNDEFINED)
+        y = 0;
+    else
+        y = window->y;
+
+    if (window->x == SDL_WINDOWPOS_UNDEFINED)
+        x = 0;
+    else
+        x = window->x;
+
+    if (window->flags & SDL_WINDOW_FULLSCREEN) {
+        x = 0;
+        y = 0;
+    }
+    //if (!(window->flags & SDL_WINDOW_FULLSCREEN))
+    windata->window->MoveTo(windata->window, x, y);
 }
 
 static void
 DirectFB_SetWindowSize(_THIS, SDL_Window * window)
 {
+    int ret;
     SDL_DFB_DEVICEDATA(_this);
     SDL_DFB_WINDOWDATA(window);
     SDL_DFB_DISPLAYDATA(_this, window);
 
-    if (!(window->flags & SDL_WINDOW_FULLSCREEN))
-        windata->window->Resize(windata->window, window->w, window->h);
+    if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
+        int ch, cw;
+
+        //      SDL_DFB_DEBUG("Resize %d %d %d %d\n", cw, ch, window->w, window->h);
+#if (DIRECTFB_MAJOR_VERSION == 1) && (DIRECTFB_MINOR_VERSION >= 0)
+        SDL_DFB_CHECKERR(windata->window->
+                         ResizeSurface(windata->window, window->w,
+                                       window->h));
+#else
+        SDL_DFB_CHECKERR(windata->window->
+                         Resize(windata->window, window->w, window->h));
+#endif
+        SDL_DFB_CHECKERR(windata->window->GetSize(windata->window, &window->w, &window->h));    /* if a window manager should have decided otherwise */
+    }
+  error:
+    return;
 }
+
 static void
 DirectFB_ShowWindow(_THIS, SDL_Window * window)
 {
--- a/src/video/directfb/SDL_DirectFB_video.h	Tue Aug 26 02:26:18 2008 +0000
+++ b/src/video/directfb/SDL_DirectFB_video.h	Tue Aug 26 02:32:45 2008 +0000
@@ -114,8 +114,11 @@
 {
     IDirectFBDisplayLayer *layer;
     DFBSurfacePixelFormat pixelformat;
+    //FIXME: support for multiple layer ...
     DFBDisplayLayerID vidID;
 
+    int vidIDinuse;
+
     int cw;
     int ch;
 
@@ -139,9 +142,9 @@
     IDirectFBGL *gl_context;
     IDirectFBEventBuffer *eventbuffer;
     DFBWindowID windowID;
-    int id;                     // SDL window id
+    int id;                     /* SDL window id */
     DFB_WindowData *next;
-    u8 opacity;
+    Uint8 opacity;
 };
 
 typedef struct _DFB_DeviceData DFB_DeviceData;
@@ -152,6 +155,7 @@
     IDirectFB *dfb;
     int mouse;
     int keyboard;
+    int kbdgeneric;
     DFB_WindowData *firstwin;
 
     int numscreens;
@@ -159,10 +163,9 @@
     DFBDisplayLayerID gralayer[DFB_MAX_SCREENS];
     DFBDisplayLayerID vidlayer[DFB_MAX_SCREENS];
 
-    // auxiliary integer for callbacks
-    int aux;
+    int aux;                    /* auxiliary integer for callbacks */
 
-    // OpenGL
+    /* OpenGL */
     void (*glFinish) (void);
     void (*glFlush) (void);
 };