Mercurial > sdl-ios-xcode
diff src/video/directfb/SDL_DirectFB_events.c @ 4568:25b9cd8bdc30
Couriersud to Sam
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é
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Fri, 23 Jul 2010 21:33:00 -0700 |
parents | f7b03b6838cb |
children | b196d2758026 |
line wrap: on
line diff
--- a/src/video/directfb/SDL_DirectFB_events.c Thu Jul 22 22:09:04 2010 -0700 +++ b/src/video/directfb/SDL_DirectFB_events.c Fri Jul 23 21:33:00 2010 -0700 @@ -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; @@ -54,7 +67,6 @@ * 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; @@ -72,27 +84,36 @@ 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; @@ -102,6 +123,7 @@ mouse->y = mouse->last_y = y; //SDL_SendMouseMotion(devdata->mouse_id[index], 0, x, y, 0); } +#endif } static int @@ -150,9 +172,9 @@ 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)); @@ -164,9 +186,9 @@ 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)); @@ -177,10 +199,10 @@ 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! @@ -200,12 +222,12 @@ 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); } } } @@ -213,18 +235,18 @@ 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 */ @@ -234,32 +256,32 @@ 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; @@ -271,7 +293,7 @@ } static void -ProcessInputEvent(_THIS, Sint32 grabbed_window, DFBInputEvent * ievt) +ProcessInputEvent(_THIS, SDL_Window *grabbed_window, DFBInputEvent * ievt) { SDL_DFB_DEVICEDATA(_this); SDL_keysym keysym; @@ -280,16 +302,17 @@ 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) { @@ -308,34 +331,34 @@ 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; @@ -363,6 +386,7 @@ default: break; /* please gcc */ } +#endif } } @@ -378,7 +402,7 @@ 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; @@ -603,19 +627,27 @@ 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; @@ -623,6 +655,7 @@ return DFENUM_OK; } +#if USE_MULTI_API static DFBEnumerationResult EnumKeyboards(DFBInputDeviceID device_id, DFBInputDeviceDescription desc, void *callbackdata) @@ -652,6 +685,7 @@ } return DFENUM_OK; } +#endif void DirectFB_InitKeyboard(_THIS) @@ -662,6 +696,7 @@ 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-> @@ -672,11 +707,14 @@ EnumKeyboards, devdata)); } - } else { + } else +#else + { SDL_DFB_CHECK(devdata->dfb->EnumInputDevices(devdata->dfb, input_device_cb, devdata)); } +#endif } void @@ -759,3 +797,4 @@ } } #endif +