Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Couriersud to Sam
Browse files Browse the repository at this point in the history
I have done some quick changes and at least the code compiles again. It
also works with a number of the test executables with the DFB X11
backend. I hope to find time to get SDLMAME to work with latest SDL1.3
(i.e. rip out multi-keyboard, multi-mice & cursor support) next week to
test it further.

Regards,

Andr?
  • Loading branch information
slouken committed Jul 24, 2010
1 parent bd53ed5 commit 434904a
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 50 deletions.
6 changes: 3 additions & 3 deletions src/video/directfb/SDL_DirectFB_WM.c
Expand Up @@ -210,7 +210,7 @@ DirectFB_WM_MaximizeWindow(_THIS, SDL_Window * window)
windata->window->MoveTo(windata->window, 0, 0);
windata->window->Resize(windata->window,
display->current_mode.w, display->current_mode.h);
SDL_SendWindowEvent(windata->sdl_id, SDL_WINDOWEVENT_MAXIMIZED, 0, 0);
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MAXIMIZED, 0, 0);
}

void
Expand All @@ -226,7 +226,7 @@ DirectFB_WM_RestoreWindow(_THIS, SDL_Window * window)
windata->restore.y);
windata->window->Resize(windata->window, windata->restore.w,
windata->restore.h);
SDL_SendWindowEvent(windata->sdl_id, SDL_WINDOWEVENT_RESTORED, 0, 0);
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESTORED, 0, 0);
}

enum
Expand Down Expand Up @@ -304,7 +304,7 @@ DirectFB_WM_ProcessEvent(_THIS, SDL_Window * window, DFBWindowEvent * evt)
case WM_POS_NONE:
return 0;
case WM_POS_CLOSE:
SDL_SendWindowEvent(windata->sdl_id, SDL_WINDOWEVENT_CLOSE, 0,
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_CLOSE, 0,
0);
return 1;
case WM_POS_MAX:
Expand Down
105 changes: 72 additions & 33 deletions src/video/directfb/SDL_DirectFB_events.c
Expand Up @@ -32,6 +32,19 @@
#include "../../events/scancodes_linux.h"
#include "SDL_DirectFB_events.h"

#if USE_MULTI_API
#define SDL_SendMouseMotion_ex(id, relative, x, y, p) SDL_SendMouseMotion(id, relative, x, y, p)
#define SDL_SendMouseButton_ex(id, state, button) SDL_SendMouseButton(id, state, button)
#define SDL_SendKeyboardKey_ex(id, state, scancode) SDL_SendKeyboardKey(id, state, scancode)
#define SDL_SendKeyboardText_ex(id, text) SDL_SendKeyboardText(id, text)
#else
#define SDL_SendMouseMotion_ex(id, relative, x, y, p) SDL_SendMouseMotion(relative, x, y)
#define SDL_SendMouseButton_ex(id, state, button) SDL_SendMouseButton(state, button)
#define SDL_SendKeyboardKey_ex(id, state, scancode) SDL_SendKeyboardKey(state, scancode)
#define SDL_SendKeyboardText_ex(id, text) SDL_SendKeyboardText(text)
#endif


/* The translation tables from a DirectFB keycode to a SDL keysym */
static SDLKey oskeymap[256];
static int sys_ids;
Expand All @@ -54,7 +67,6 @@ DirectFB_SetContext(_THIS, SDL_Window *window)
* This has simply no effect.
*/

SDL_Window *window = SDL_GetWindowFromID(id);
SDL_VideoDisplay *display = window->display;
DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata;
int ret;
Expand All @@ -72,27 +84,36 @@ DirectFB_SetContext(_THIS, SDL_Window *window)
static void
FocusAllMice(_THIS, SDL_Window *window)
{
#if USE_MULTI_API
SDL_DFB_DEVICEDATA(_this);
int index;

for (index = 0; index < devdata->num_mice; index++)
SDL_SetMouseFocus(devdata->mouse_id[index], id);
#else
SDL_SetMouseFocus(window);
#endif
}


static void
FocusAllKeyboards(_THIS, SDL_Window *window)
{
#if USE_MULTI_API
SDL_DFB_DEVICEDATA(_this);
int index;

for (index = 0; index < devdata->num_keyboard; index++)
SDL_SetKeyboardFocus(index, id);
#else
SDL_SetKeyboardFocus(window);
#endif
}

static void
MotionAllMice(_THIS, int x, int y)
{
#if USE_MULTI_API
SDL_DFB_DEVICEDATA(_this);
int index;

Expand All @@ -102,6 +123,7 @@ MotionAllMice(_THIS, int x, int y)
mouse->y = mouse->last_y = y;
//SDL_SendMouseMotion(devdata->mouse_id[index], 0, x, y, 0);
}
#endif
}

static int
Expand Down Expand Up @@ -150,9 +172,9 @@ ProcessWindowEvent(_THIS, DFB_WindowData * p, Uint32 flags,
case DWET_BUTTONDOWN:
if (ClientXY(p, &evt->x, &evt->y)) {
if (!devdata->use_linux_input) {
SDL_SendMouseMotion(devdata->mouse_id[0], 0, evt->x,
SDL_SendMouseMotion_ex(devdata->mouse_id[0], 0, evt->x,
evt->y, 0);
SDL_SendMouseButton(devdata->mouse_id[0],
SDL_SendMouseButton_ex(devdata->mouse_id[0],
SDL_PRESSED,
DirectFB_TranslateButton
(evt->button));
Expand All @@ -164,9 +186,9 @@ ProcessWindowEvent(_THIS, DFB_WindowData * p, Uint32 flags,
case DWET_BUTTONUP:
if (ClientXY(p, &evt->x, &evt->y)) {
if (!devdata->use_linux_input) {
SDL_SendMouseMotion(devdata->mouse_id[0], 0, evt->x,
SDL_SendMouseMotion_ex(devdata->mouse_id[0], 0, evt->x,
evt->y, 0);
SDL_SendMouseButton(devdata->mouse_id[0],
SDL_SendMouseButton_ex(devdata->mouse_id[0],
SDL_RELEASED,
DirectFB_TranslateButton
(evt->button));
Expand All @@ -177,10 +199,10 @@ ProcessWindowEvent(_THIS, DFB_WindowData * p, Uint32 flags,
break;
case DWET_MOTION:
if (ClientXY(p, &evt->x, &evt->y)) {
SDL_Window *window = p->window;
SDL_Window *window = p->sdl_window;
if (!devdata->use_linux_input) {
if (!(flags & SDL_WINDOW_INPUT_GRABBED))
SDL_SendMouseMotion(devdata->mouse_id[0], 0,
SDL_SendMouseMotion_ex(devdata->mouse_id[0], 0,
evt->x, evt->y, 0);
} else {
/* relative movements are not exact!
Expand All @@ -200,31 +222,31 @@ ProcessWindowEvent(_THIS, DFB_WindowData * p, Uint32 flags,
case DWET_KEYDOWN:
if (!devdata->use_linux_input) {
DirectFB_TranslateKey(_this, evt, &keysym);
SDL_SendKeyboardKey(0, SDL_PRESSED, keysym.scancode);
SDL_SendKeyboardKey_ex(0, SDL_PRESSED, keysym.scancode);
if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) {
SDL_memcpy(text, &keysym.unicode, 4);
text[4] = 0;
if (*text) {
SDL_SendKeyboardText(0, text);
SDL_SendKeyboardText_ex(0, text);
}
}
}
break;
case DWET_KEYUP:
if (!devdata->use_linux_input) {
DirectFB_TranslateKey(_this, evt, &keysym);
SDL_SendKeyboardKey(0, SDL_RELEASED, keysym.scancode);
SDL_SendKeyboardKey_ex(0, SDL_RELEASED, keysym.scancode);
}
break;
case DWET_POSITION:
if (ClientXY(p, &evt->x, &evt->y)) {
SDL_SendWindowEvent(p->window, SDL_WINDOWEVENT_MOVED,
SDL_SendWindowEvent(p->sdl_window, SDL_WINDOWEVENT_MOVED,
evt->x, evt->y);
}
break;
case DWET_POSITION_SIZE:
if (ClientXY(p, &evt->x, &evt->y)) {
SDL_SendWindowEvent(p->window, SDL_WINDOWEVENT_MOVED,
SDL_SendWindowEvent(p->sdl_window, SDL_WINDOWEVENT_MOVED,
evt->x, evt->y);
}
/* fall throught */
Expand All @@ -234,32 +256,32 @@ ProcessWindowEvent(_THIS, DFB_WindowData * p, Uint32 flags,
evt->h -=
(p->theme.top_size + p->theme.bottom_size +
p->theme.caption_size);
SDL_SendWindowEvent(p->window, SDL_WINDOWEVENT_RESIZED,
SDL_SendWindowEvent(p->sdl_window, SDL_WINDOWEVENT_RESIZED,
evt->w, evt->h);
break;
case DWET_CLOSE:
SDL_SendWindowEvent(p->window, SDL_WINDOWEVENT_CLOSE, 0, 0);
SDL_SendWindowEvent(p->sdl_window, SDL_WINDOWEVENT_CLOSE, 0, 0);
break;
case DWET_GOTFOCUS:
DirectFB_SetContext(_this, p->window);
FocusAllKeyboards(_this, p->window);
SDL_SendWindowEvent(p->window, SDL_WINDOWEVENT_FOCUS_GAINED,
DirectFB_SetContext(_this, p->sdl_window);
FocusAllKeyboards(_this, p->sdl_window);
SDL_SendWindowEvent(p->sdl_window, SDL_WINDOWEVENT_FOCUS_GAINED,
0, 0);
break;
case DWET_LOSTFOCUS:
SDL_SendWindowEvent(p->window, SDL_WINDOWEVENT_FOCUS_LOST, 0, 0);
SDL_SendWindowEvent(p->sdl_window, SDL_WINDOWEVENT_FOCUS_LOST, 0, 0);
FocusAllKeyboards(_this, 0);
break;
case DWET_ENTER:
/* SDL_DirectFB_ReshowCursor(_this, 0); */
FocusAllMice(_this, p->window);
FocusAllMice(_this, p->sdl_window);
// FIXME: when do we really enter ?
if (ClientXY(p, &evt->x, &evt->y))
MotionAllMice(_this, evt->x, evt->y);
SDL_SendWindowEvent(p->window, SDL_WINDOWEVENT_ENTER, 0, 0);
SDL_SendWindowEvent(p->sdl_window, SDL_WINDOWEVENT_ENTER, 0, 0);
break;
case DWET_LEAVE:
SDL_SendWindowEvent(p->window, SDL_WINDOWEVENT_LEAVE, 0, 0);
SDL_SendWindowEvent(p->sdl_window, SDL_WINDOWEVENT_LEAVE, 0, 0);
FocusAllMice(_this, 0);
/* SDL_DirectFB_ReshowCursor(_this, 1); */
break;
Expand All @@ -271,7 +293,7 @@ ProcessWindowEvent(_THIS, DFB_WindowData * p, Uint32 flags,
}

static void
ProcessInputEvent(_THIS, Sint32 grabbed_window, DFBInputEvent * ievt)
ProcessInputEvent(_THIS, SDL_Window *grabbed_window, DFBInputEvent * ievt)
{
SDL_DFB_DEVICEDATA(_this);
SDL_keysym keysym;
Expand All @@ -280,16 +302,17 @@ ProcessInputEvent(_THIS, Sint32 grabbed_window, DFBInputEvent * ievt)

if (!devdata->use_linux_input) {
if (ievt->type == DIET_AXISMOTION) {
if ((grabbed_window >= 0) && (ievt->flags & DIEF_AXISREL)) {
if ((grabbed_window != NULL) && (ievt->flags & DIEF_AXISREL)) {
if (ievt->axis == DIAI_X)
SDL_SendMouseMotion(ievt->device_id, 1,
SDL_SendMouseMotion_ex(ievt->device_id, 1,
ievt->axisrel, 0, 0);
else if (ievt->axis == DIAI_Y)
SDL_SendMouseMotion(ievt->device_id, 1, 0,
SDL_SendMouseMotion_ex(ievt->device_id, 1, 0,
ievt->axisrel, 0);
}
}
} else {
#if USE_MULTI_API
static int last_x, last_y;

switch (ievt->type) {
Expand All @@ -308,34 +331,34 @@ ProcessInputEvent(_THIS, Sint32 grabbed_window, DFBInputEvent * ievt)
int x, y;

windata->window->GetPosition(windata->window, &x, &y);
SDL_SendMouseMotion(ievt->device_id, 0,
SDL_SendMouseMotion_ex(ievt->device_id, 0,
last_x - (x +
windata->client.x),
last_y - (y +
windata->client.y), 0);
} else {
SDL_SendMouseMotion(ievt->device_id, 0, last_x,
SDL_SendMouseMotion_ex(ievt->device_id, 0, last_x,
last_y, 0);
}
}
} else if (ievt->flags & DIEF_AXISREL) {
if (ievt->axis == DIAI_X)
SDL_SendMouseMotion(ievt->device_id, 1,
SDL_SendMouseMotion_ex(ievt->device_id, 1,
ievt->axisrel, 0, 0);
else if (ievt->axis == DIAI_Y)
SDL_SendMouseMotion(ievt->device_id, 1, 0,
SDL_SendMouseMotion_ex(ievt->device_id, 1, 0,
ievt->axisrel, 0);
}
break;
case DIET_KEYPRESS:
kbd_idx = KbdIndex(_this, ievt->device_id);
DirectFB_TranslateKeyInputEvent(_this, kbd_idx, ievt, &keysym);
SDL_SendKeyboardKey(kbd_idx, SDL_PRESSED, keysym.scancode);
SDL_SendKeyboardKey_ex(kbd_idx, SDL_PRESSED, keysym.scancode);
if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) {
SDL_memcpy(text, &keysym.unicode, 4);
text[4] = 0;
if (*text) {
SDL_SendKeyboardText(kbd_idx, text);
SDL_SendKeyboardText_ex(kbd_idx, text);
}
}
break;
Expand Down Expand Up @@ -363,6 +386,7 @@ ProcessInputEvent(_THIS, Sint32 grabbed_window, DFBInputEvent * ievt)
default:
break; /* please gcc */
}
#endif
}
}

Expand All @@ -378,7 +402,7 @@ DirectFB_PumpEventsWindow(_THIS)

for (p = devdata->firstwin; p != NULL; p = p->next) {
DFBWindowEvent evt;
SDL_Window *w = SDL_GetWindowFromID(p->window);
SDL_Window *w = p->sdl_window;

if (w->flags & SDL_WINDOW_INPUT_GRABBED) {
grabbed_window = w;
Expand Down Expand Up @@ -603,26 +627,35 @@ input_device_cb(DFBInputDeviceID device_id,
DFBInputDeviceDescription desc, void *callbackdata)
{
DFB_DeviceData *devdata = callbackdata;
#if USE_MULTI_API
SDL_Keyboard keyboard;
#endif
SDLKey keymap[SDL_NUM_SCANCODES];

if ((desc.caps & DIDTF_KEYBOARD) && device_id == DIDID_KEYBOARD) {
#if USE_MULTI_API
SDL_zero(keyboard);
SDL_AddKeyboard(&keyboard, 0);
#endif
devdata->keyboard[0].id = device_id;
devdata->keyboard[0].is_generic = 0;
if (!strncmp("X11", desc.name, 3))
devdata->keyboard[0].is_generic = 1;

SDL_GetDefaultKeymap(keymap);
#if USE_MULTI_API
SDL_SetKeymap(0, 0, keymap, SDL_NUM_SCANCODES);
#else
SDL_SetKeymap(0, keymap, SDL_NUM_SCANCODES);
#endif
devdata->num_keyboard++;

return DFENUM_CANCEL;
}
return DFENUM_OK;
}

#if USE_MULTI_API
static DFBEnumerationResult
EnumKeyboards(DFBInputDeviceID device_id,
DFBInputDeviceDescription desc, void *callbackdata)
Expand Down Expand Up @@ -652,6 +685,7 @@ EnumKeyboards(DFBInputDeviceID device_id,
}
return DFENUM_OK;
}
#endif

void
DirectFB_InitKeyboard(_THIS)
Expand All @@ -662,6 +696,7 @@ DirectFB_InitKeyboard(_THIS)
DirectFB_InitOSKeymap(_this, &oskeymap[0], SDL_arraysize(oskeymap));

devdata->num_keyboard = 0;
#if USE_MULTI_API
if (devdata->use_linux_input) {
sys_ids = 0;
SDL_DFB_CHECK(devdata->dfb->
Expand All @@ -672,11 +707,14 @@ DirectFB_InitKeyboard(_THIS)
EnumKeyboards,
devdata));
}
} else {
} else
#else
{
SDL_DFB_CHECK(devdata->dfb->EnumInputDevices(devdata->dfb,
input_device_cb,
devdata));
}
#endif
}

void
Expand Down Expand Up @@ -759,3 +797,4 @@ DirectFB_PumpEvents(_THIS)
}
}
#endif

2 changes: 1 addition & 1 deletion src/video/directfb/SDL_DirectFB_modes.h
Expand Up @@ -26,7 +26,7 @@

#include "SDL_DirectFB_video.h"

#define SDL_DFB_DISPLAYDATA(dev, win) DFB_DisplayData *dispdata = ((win && dev) ? (DFB_DisplayData *) (dev)->displays[(win)->display].driverdata : NULL)
#define SDL_DFB_DISPLAYDATA(dev, win) DFB_DisplayData *dispdata = ((win && dev) ? (DFB_DisplayData *) (win)->display->driverdata : NULL)

typedef struct _DFB_DisplayData DFB_DisplayData;
struct _DFB_DisplayData
Expand Down

0 comments on commit 434904a

Please sign in to comment.