Mercurial > sdl-ios-xcode
diff src/video/directfb/SDL_DirectFB_events.c @ 4636:b196d2758026
Couriersud to Sam
Hi Sam,
20100815_1.diff contains updates for the directfb driver:
- more documentation, mainly on software OpenGL in README.directfb
- Revised error handling leading to leaner code
- Improved/fixed OpenGL handling of multiple contexts.
- Made the built-in simple window manager handle OpenGL windows.
- Rewrote pixelformat mapping - this was quite ugly before.
Well, all software GL, but working :-)
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 16 Aug 2010 09:04:55 -0700 |
parents | 25b9cd8bdc30 |
children | 25d4feb7c127 |
line wrap: on
line diff
--- a/src/video/directfb/SDL_DirectFB_events.c Sat Aug 14 12:28:43 2010 -0700 +++ b/src/video/directfb/SDL_DirectFB_events.c Mon Aug 16 09:04:55 2010 -0700 @@ -33,21 +33,28 @@ #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_SendMouseMotion_ex(w, id, relative, x, y, p) SDL_SendMouseMotion(id, relative, x, y, p) +#define SDL_SendMouseButton_ex(w, 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_SendMouseMotion_ex(w, id, relative, x, y, p) SDL_SendMouseMotion(w, relative, x, y) +#define SDL_SendMouseButton_ex(w, id, state, button) SDL_SendMouseButton(w, state, button) #define SDL_SendKeyboardKey_ex(id, state, scancode) SDL_SendKeyboardKey(state, scancode) #define SDL_SendKeyboardText_ex(id, text) SDL_SendKeyboardText(text) #endif +typedef struct _cb_data cb_data; +struct _cb_data +{ + DFB_DeviceData *devdata; + int sys_ids; + int sys_kbd; +}; /* The translation tables from a DirectFB keycode to a SDL keysym */ static SDLKey oskeymap[256]; -static int sys_ids; + static SDL_keysym *DirectFB_TranslateKey(_THIS, DFBWindowEvent * evt, SDL_keysym * keysym); @@ -69,14 +76,11 @@ SDL_VideoDisplay *display = window->display; DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata; - int ret; + /* FIXME: should we handle the error */ if (dispdata->vidIDinuse) - SDL_DFB_CHECKERR(dispdata->vidlayer->SwitchContext(dispdata->vidlayer, + SDL_DFB_CHECK(dispdata->vidlayer->SwitchContext(dispdata->vidlayer, DFB_TRUE)); - - error: - return; #endif } @@ -172,9 +176,9 @@ case DWET_BUTTONDOWN: if (ClientXY(p, &evt->x, &evt->y)) { if (!devdata->use_linux_input) { - SDL_SendMouseMotion_ex(devdata->mouse_id[0], 0, evt->x, + SDL_SendMouseMotion_ex(p->sdl_window, devdata->mouse_id[0], 0, evt->x, evt->y, 0); - SDL_SendMouseButton_ex(devdata->mouse_id[0], + SDL_SendMouseButton_ex(p->sdl_window, devdata->mouse_id[0], SDL_PRESSED, DirectFB_TranslateButton (evt->button)); @@ -186,9 +190,9 @@ case DWET_BUTTONUP: if (ClientXY(p, &evt->x, &evt->y)) { if (!devdata->use_linux_input) { - SDL_SendMouseMotion_ex(devdata->mouse_id[0], 0, evt->x, + SDL_SendMouseMotion_ex(p->sdl_window, devdata->mouse_id[0], 0, evt->x, evt->y, 0); - SDL_SendMouseButton_ex(devdata->mouse_id[0], + SDL_SendMouseButton_ex(p->sdl_window, devdata->mouse_id[0], SDL_RELEASED, DirectFB_TranslateButton (evt->button)); @@ -202,7 +206,7 @@ SDL_Window *window = p->sdl_window; if (!devdata->use_linux_input) { if (!(flags & SDL_WINDOW_INPUT_GRABBED)) - SDL_SendMouseMotion_ex(devdata->mouse_id[0], 0, + SDL_SendMouseMotion_ex(p->sdl_window, devdata->mouse_id[0], 0, evt->x, evt->y, 0); } else { /* relative movements are not exact! @@ -215,7 +219,7 @@ } } if (!(window->flags & SDL_WINDOW_MOUSE_FOCUS)) - SDL_SendWindowEvent(p->window, SDL_WINDOWEVENT_ENTER, 0, + SDL_SendWindowEvent(p->sdl_window, SDL_WINDOWEVENT_ENTER, 0, 0); } break; @@ -293,7 +297,7 @@ } static void -ProcessInputEvent(_THIS, SDL_Window *grabbed_window, DFBInputEvent * ievt) +ProcessInputEvent(_THIS, DFBInputEvent * ievt) { SDL_DFB_DEVICEDATA(_this); SDL_keysym keysym; @@ -302,17 +306,16 @@ if (!devdata->use_linux_input) { if (ievt->type == DIET_AXISMOTION) { - if ((grabbed_window != NULL) && (ievt->flags & DIEF_AXISREL)) { + if ((devdata->grabbed_window != NULL) && (ievt->flags & DIEF_AXISREL)) { if (ievt->axis == DIAI_X) - SDL_SendMouseMotion_ex(ievt->device_id, 1, + SDL_SendMouseMotion_ex(devdata->grabbed_window, ievt->device_id, 1, ievt->axisrel, 0, 0); else if (ievt->axis == DIAI_Y) - SDL_SendMouseMotion_ex(ievt->device_id, 1, 0, + SDL_SendMouseMotion_ex(devdata->grabbed_window, ievt->device_id, 1, 0, ievt->axisrel, 0); } } } else { -#if USE_MULTI_API static int last_x, last_y; switch (ievt->type) { @@ -323,30 +326,34 @@ else if (ievt->axis == DIAI_Y) last_y = ievt->axisabs; if (!(ievt->flags & DIEF_FOLLOW)) { +#if USE_MULTI_API SDL_Mouse *mouse = SDL_GetMouse(ievt->device_id); SDL_Window *window = SDL_GetWindowFromID(mouse->focus); +#else + SDL_Window *window = devdata->grabbed_window; +#endif if (window) { DFB_WindowData *windata = (DFB_WindowData *) window->driverdata; int x, y; windata->window->GetPosition(windata->window, &x, &y); - SDL_SendMouseMotion_ex(ievt->device_id, 0, + SDL_SendMouseMotion_ex(window, ievt->device_id, 0, last_x - (x + windata->client.x), last_y - (y + windata->client.y), 0); } else { - SDL_SendMouseMotion_ex(ievt->device_id, 0, last_x, + SDL_SendMouseMotion_ex(window, ievt->device_id, 0, last_x, last_y, 0); } } } else if (ievt->flags & DIEF_AXISREL) { if (ievt->axis == DIAI_X) - SDL_SendMouseMotion_ex(ievt->device_id, 1, + SDL_SendMouseMotion_ex(devdata->grabbed_window, ievt->device_id, 1, ievt->axisrel, 0, 0); else if (ievt->axis == DIAI_Y) - SDL_SendMouseMotion_ex(ievt->device_id, 1, 0, + SDL_SendMouseMotion_ex(devdata->grabbed_window, ievt->device_id, 1, 0, ievt->axisrel, 0); } break; @@ -365,28 +372,27 @@ case DIET_KEYRELEASE: kbd_idx = KbdIndex(_this, ievt->device_id); DirectFB_TranslateKeyInputEvent(_this, kbd_idx, ievt, &keysym); - SDL_SendKeyboardKey(kbd_idx, SDL_RELEASED, keysym.scancode); + SDL_SendKeyboardKey_ex(kbd_idx, SDL_RELEASED, keysym.scancode); break; case DIET_BUTTONPRESS: if (ievt->buttons & DIBM_LEFT) - SDL_SendMouseButton(ievt->device_id, SDL_PRESSED, 1); + SDL_SendMouseButton_ex(devdata->grabbed_window, ievt->device_id, SDL_PRESSED, 1); if (ievt->buttons & DIBM_MIDDLE) - SDL_SendMouseButton(ievt->device_id, SDL_PRESSED, 2); + SDL_SendMouseButton_ex(devdata->grabbed_window, ievt->device_id, SDL_PRESSED, 2); if (ievt->buttons & DIBM_RIGHT) - SDL_SendMouseButton(ievt->device_id, SDL_PRESSED, 3); + SDL_SendMouseButton_ex(devdata->grabbed_window, ievt->device_id, SDL_PRESSED, 3); break; case DIET_BUTTONRELEASE: if (!(ievt->buttons & DIBM_LEFT)) - SDL_SendMouseButton(ievt->device_id, SDL_RELEASED, 1); + SDL_SendMouseButton_ex(devdata->grabbed_window, ievt->device_id, SDL_RELEASED, 1); if (!(ievt->buttons & DIBM_MIDDLE)) - SDL_SendMouseButton(ievt->device_id, SDL_RELEASED, 2); + SDL_SendMouseButton_ex(devdata->grabbed_window, ievt->device_id, SDL_RELEASED, 2); if (!(ievt->buttons & DIBM_RIGHT)) - SDL_SendMouseButton(ievt->device_id, SDL_RELEASED, 3); + SDL_SendMouseButton_ex(devdata->grabbed_window, ievt->device_id, SDL_RELEASED, 3); break; default: break; /* please gcc */ } -#endif } } @@ -396,18 +402,11 @@ SDL_DFB_DEVICEDATA(_this); DFB_WindowData *p; DFBInputEvent ievt; - SDL_Window *grabbed_window; - - grabbed_window = NULL; for (p = devdata->firstwin; p != NULL; p = p->next) { DFBWindowEvent evt; SDL_Window *w = p->sdl_window; - if (w->flags & SDL_WINDOW_INPUT_GRABBED) { - grabbed_window = w; - } - while (p->eventbuffer->GetEvent(p->eventbuffer, DFB_EVENT(&evt)) == DFB_OK) { if (!DirectFB_WM_ProcessEvent(_this, w, &evt)) @@ -418,7 +417,7 @@ /* Now get relative events in case we need them */ while (devdata->events->GetEvent(devdata->events, DFB_EVENT(&ievt)) == DFB_OK) { - ProcessInputEvent(_this, grabbed_window, &ievt); + ProcessInputEvent(_this, &ievt); } } @@ -623,105 +622,87 @@ } static DFBEnumerationResult -input_device_cb(DFBInputDeviceID device_id, +EnumKeyboards(DFBInputDeviceID device_id, DFBInputDeviceDescription desc, void *callbackdata) { - DFB_DeviceData *devdata = callbackdata; + cb_data *cb = callbackdata; + DFB_DeviceData *devdata = cb->devdata; #if USE_MULTI_API SDL_Keyboard keyboard; #endif SDLKey keymap[SDL_NUM_SCANCODES]; - if ((desc.caps & DIDTF_KEYBOARD) && device_id == DIDID_KEYBOARD) { + if (!cb->sys_kbd) { + if (cb->sys_ids) { + if (device_id >= 0x10) + return DFENUM_OK; + } else { + if (device_id < 0x10) + return DFENUM_OK; + } + } else { + if (device_id != DIDID_KEYBOARD) + return DFENUM_OK; + } + + if ((desc.caps & DIDTF_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); + SDL_AddKeyboard(&keyboard, devdata->num_keyboard); #endif - devdata->num_keyboard++; - - return DFENUM_CANCEL; - } - return DFENUM_OK; -} - -#if USE_MULTI_API -static DFBEnumerationResult -EnumKeyboards(DFBInputDeviceID device_id, - DFBInputDeviceDescription desc, void *callbackdata) -{ - DFB_DeviceData *devdata = callbackdata; - SDL_Keyboard keyboard; - SDLKey keymap[SDL_NUM_SCANCODES]; - - if (sys_ids) { - if (device_id >= 0x10) - return DFENUM_OK; - } else { - if (device_id < 0x10) - return DFENUM_OK; - } - if ((desc.caps & DIDTF_KEYBOARD)) { - SDL_zero(keyboard); - SDL_AddKeyboard(&keyboard, devdata->num_keyboard); devdata->keyboard[devdata->num_keyboard].id = device_id; devdata->keyboard[devdata->num_keyboard].is_generic = 0; if (!strncmp("X11", desc.name, 3)) devdata->keyboard[devdata->num_keyboard].is_generic = 1; SDL_GetDefaultKeymap(keymap); +#if USE_MULTI_API SDL_SetKeymap(devdata->num_keyboard, 0, keymap, SDL_NUM_SCANCODES); +#else + SDL_SetKeymap(0, keymap, SDL_NUM_SCANCODES); +#endif devdata->num_keyboard++; + + if (cb->sys_kbd) + return DFENUM_CANCEL; } return DFENUM_OK; } -#endif void DirectFB_InitKeyboard(_THIS) { SDL_DFB_DEVICEDATA(_this); - int ret; - + cb_data cb; + DirectFB_InitOSKeymap(_this, &oskeymap[0], SDL_arraysize(oskeymap)); devdata->num_keyboard = 0; -#if USE_MULTI_API + cb.devdata = devdata; + if (devdata->use_linux_input) { - sys_ids = 0; + cb.sys_kbd = 0; + cb.sys_ids = 0; SDL_DFB_CHECK(devdata->dfb-> - EnumInputDevices(devdata->dfb, EnumKeyboards, devdata)); + EnumInputDevices(devdata->dfb, EnumKeyboards, &cb)); if (devdata->num_keyboard == 0) { - sys_ids = 1; + cb.sys_ids = 1; SDL_DFB_CHECK(devdata->dfb->EnumInputDevices(devdata->dfb, EnumKeyboards, - devdata)); + &cb)); } - } else -#else - { + } else { + cb.sys_kbd = 1; SDL_DFB_CHECK(devdata->dfb->EnumInputDevices(devdata->dfb, - input_device_cb, - devdata)); + EnumKeyboards, + &cb)); } -#endif } void DirectFB_QuitKeyboard(_THIS) { - SDL_DFB_DEVICEDATA(_this); - int ret; + //SDL_DFB_DEVICEDATA(_this); SDL_KeyboardQuit();