21#include "../../SDL_internal.h"
23#if SDL_VIDEO_DRIVER_DIRECTFB
33#include "../../events/SDL_mouse_c.h"
34#include "../../events/SDL_keyboard_c.h"
35#include "../../events/SDL_windowevents_c.h"
36#include "../../events/SDL_events_c.h"
37#include "../../events/scancodes_linux.h"
38#include "../../events/scancodes_xfree86.h"
43#define SDL_SendMouseMotion_ex(w, id, relative, x, y, p) SDL_SendMouseMotion(w, id, relative, x, y, p)
44#define SDL_SendMouseButton_ex(w, id, state, button) SDL_SendMouseButton(w, id, state, button)
45#define SDL_SendKeyboardKey_ex(id, state, scancode) SDL_SendKeyboardKey(id, state, scancode)
46#define SDL_SendKeyboardText_ex(id, text) SDL_SendKeyboardText(id, text)
48#define SDL_SendMouseMotion_ex(w, id, relative, x, y, p) SDL_SendMouseMotion(w, id, relative, x, y)
49#define SDL_SendMouseButton_ex(w, id, state, button) SDL_SendMouseButton(w, id, state, button)
50#define SDL_SendKeyboardKey_ex(id, state, scancode) SDL_SendKeyboardKey(state, scancode)
51#define SDL_SendKeyboardText_ex(id, text) SDL_SendKeyboardText(text)
54typedef struct _cb_data cb_data;
57 DFB_DeviceData *devdata;
68static SDL_Keysym *DirectFB_TranslateKeyInputEvent(
_THIS, DFBInputEvent * evt,
72static int DirectFB_TranslateButton(DFBInputDeviceButtonIdentifier
button);
74static void UnicodeToUtf8(
Uint16 w ,
char *utf8buf)
76 unsigned char *utf8s = (
unsigned char *) utf8buf;
79 utf8s[0] = (
unsigned char )
w;
82 else if (
w < 0x0800 ) {
83 utf8s[0] = 0xc0 | ((
w ) >> 6 );
84 utf8s[1] = 0x80 | ((
w ) & 0x3f );
88 utf8s[0] = 0xe0 | ((
w ) >> 12 );
89 utf8s[1] = 0x80 | (( (
w ) >> 6 ) & 0x3f );
90 utf8s[2] = 0x80 | ((
w ) & 0x3f );
125MotionAllMice(
_THIS,
int x,
int y)
141KbdIndex(
_THIS,
int id)
147 if (devdata->keyboard[
index].id ==
id)
154ClientXY(DFB_WindowData *
p,
int *
x,
int *
y)
164 if (cx < 0 || cy < 0)
166 if (cx >=
p->client.w || cy >=
p->client.h)
182 if (evt->clazz == DFEC_WINDOW) {
184 case DWET_BUTTONDOWN:
185 if (ClientXY(windata, &evt->x, &evt->y)) {
186 if (!devdata->use_linux_input) {
187 SDL_SendMouseMotion_ex(sdlwin, devdata->mouse_id[0], 0, evt->x,
189 SDL_SendMouseButton_ex(sdlwin, devdata->mouse_id[0],
191 DirectFB_TranslateButton
194 MotionAllMice(
_this, evt->x, evt->y);
199 if (ClientXY(windata, &evt->x, &evt->y)) {
200 if (!devdata->use_linux_input) {
201 SDL_SendMouseMotion_ex(sdlwin, devdata->mouse_id[0], 0, evt->x,
203 SDL_SendMouseButton_ex(sdlwin, devdata->mouse_id[0],
205 DirectFB_TranslateButton
208 MotionAllMice(
_this, evt->x, evt->y);
213 if (ClientXY(windata, &evt->x, &evt->y)) {
214 if (!devdata->use_linux_input) {
216 SDL_SendMouseMotion_ex(sdlwin, devdata->mouse_id[0], 0,
223 if (1 && ++cnt > 20) {
224 MotionAllMice(
_this, evt->x, evt->y);
234 if (!devdata->use_linux_input) {
235 DirectFB_TranslateKey(
_this, evt, &keysym, &unicode);
240 UnicodeToUtf8(unicode,
text);
242 SDL_SendKeyboardText_ex(0,
text);
248 if (!devdata->use_linux_input) {
249 DirectFB_TranslateKey(
_this, evt, &keysym, &unicode);
254 if (ClientXY(windata, &evt->x, &evt->y)) {
259 case DWET_POSITION_SIZE:
260 if (ClientXY(windata, &evt->x, &evt->y)) {
267 evt->w -= (windata->theme.right_size + windata->theme.left_size);
269 (windata->theme.top_size + windata->theme.bottom_size +
270 windata->theme.caption_size);
279 FocusAllKeyboards(
_this, sdlwin);
285 FocusAllKeyboards(
_this, 0);
289 FocusAllMice(
_this, sdlwin);
291 if (ClientXY(windata, &evt->x, &evt->y))
292 MotionAllMice(
_this, evt->x, evt->y);
297 FocusAllMice(
_this, 0);
304 printf(
"Event Clazz %d\n", evt->clazz);
308ProcessInputEvent(
_THIS, DFBInputEvent * ievt)
316 if (!devdata->use_linux_input) {
317 if (ievt->type == DIET_AXISMOTION) {
318 if ((devdata->grabbed_window !=
NULL) && (ievt->flags & DIEF_AXISREL)) {
319 if (ievt->axis == DIAI_X)
320 SDL_SendMouseMotion_ex(devdata->grabbed_window, ievt->device_id, 1,
321 ievt->axisrel, 0, 0);
322 else if (ievt->axis == DIAI_Y)
323 SDL_SendMouseMotion_ex(devdata->grabbed_window, ievt->device_id, 1, 0,
328 static int last_x, last_y;
330 switch (ievt->type) {
331 case DIET_AXISMOTION:
332 if (ievt->flags & DIEF_AXISABS) {
333 if (ievt->axis == DIAI_X)
334 last_x = ievt->axisabs;
335 else if (ievt->axis == DIAI_Y)
336 last_y = ievt->axisabs;
337 if (!(ievt->flags & DIEF_FOLLOW)) {
345 DFB_WindowData *windata =
349 windata->dfbwin->GetPosition(windata->dfbwin, &
x, &
y);
350 SDL_SendMouseMotion_ex(
window, ievt->device_id, 0,
354 windata->client.y), 0);
356 SDL_SendMouseMotion_ex(
window, ievt->device_id, 0, last_x,
360 }
else if (ievt->flags & DIEF_AXISREL) {
361 if (ievt->axis == DIAI_X)
362 SDL_SendMouseMotion_ex(devdata->grabbed_window, ievt->device_id, 1,
363 ievt->axisrel, 0, 0);
364 else if (ievt->axis == DIAI_Y)
365 SDL_SendMouseMotion_ex(devdata->grabbed_window, ievt->device_id, 1, 0,
370 kbd_idx = KbdIndex(
_this, ievt->device_id);
371 DirectFB_TranslateKeyInputEvent(
_this, ievt, &keysym, &unicode);
376 UnicodeToUtf8(unicode,
text);
378 SDL_SendKeyboardText_ex(kbd_idx,
text);
382 case DIET_KEYRELEASE:
383 kbd_idx = KbdIndex(
_this, ievt->device_id);
384 DirectFB_TranslateKeyInputEvent(
_this, ievt, &keysym, &unicode);
387 case DIET_BUTTONPRESS:
388 if (ievt->buttons & DIBM_LEFT)
389 SDL_SendMouseButton_ex(devdata->grabbed_window, ievt->device_id,
SDL_PRESSED, 1);
390 if (ievt->buttons & DIBM_MIDDLE)
391 SDL_SendMouseButton_ex(devdata->grabbed_window, ievt->device_id,
SDL_PRESSED, 2);
392 if (ievt->buttons & DIBM_RIGHT)
393 SDL_SendMouseButton_ex(devdata->grabbed_window, ievt->device_id,
SDL_PRESSED, 3);
395 case DIET_BUTTONRELEASE:
396 if (!(ievt->buttons & DIBM_LEFT))
397 SDL_SendMouseButton_ex(devdata->grabbed_window, ievt->device_id,
SDL_RELEASED, 1);
398 if (!(ievt->buttons & DIBM_MIDDLE))
399 SDL_SendMouseButton_ex(devdata->grabbed_window, ievt->device_id,
SDL_RELEASED, 2);
400 if (!(ievt->buttons & DIBM_RIGHT))
401 SDL_SendMouseButton_ex(devdata->grabbed_window, ievt->device_id,
SDL_RELEASED, 3);
416 for (
w = devdata->firstwin;
w !=
NULL;
w =
w->next) {
420 while (windata->eventbuffer->GetEvent(windata->eventbuffer,
421 DFB_EVENT(&evt)) == DFB_OK) {
431 ProcessWindowEvent(
_this,
w, &evt);
437 while (devdata->events->GetEvent(devdata->events,
438 DFB_EVENT(&ievt)) == DFB_OK) {
447 ProcessInputEvent(
_this, &ievt);
457 for (
i = 0;
i < numkeys; ++
i)
584 DFB_KeyboardData *kbd = &devdata->keyboard[kbd_idx];
588 if (kbd->map && evt->key_code >= kbd->map_adjust &&
589 evt->key_code < kbd->map_size + kbd->map_adjust)
590 keysym->
scancode = kbd->map[evt->key_code - kbd->map_adjust];
593 devdata->keyboard[kbd_idx].is_generic) {
595 keysym->
scancode = oskeymap[evt->key_id - DIKI_UNKNOWN];
601 (DFB_KEY_TYPE(evt->key_symbol) == DIKT_UNICODE) ? evt->key_symbol : 0;
603 (evt->key_symbol > 0 && evt->key_symbol < 255))
604 *unicode = evt->key_symbol;
610DirectFB_TranslateKeyInputEvent(
_THIS, DFBInputEvent * evt,
614 int kbd_idx = KbdIndex(
_this, evt->device_id);
615 DFB_KeyboardData *kbd = &devdata->keyboard[kbd_idx];
619 if (kbd->map && evt->key_code >= kbd->map_adjust &&
620 evt->key_code < kbd->map_size + kbd->map_adjust)
621 keysym->
scancode = kbd->map[evt->key_code - kbd->map_adjust];
625 keysym->
scancode = oskeymap[evt->key_id - DIKI_UNKNOWN];
631 (DFB_KEY_TYPE(evt->key_symbol) == DIKT_UNICODE) ? evt->key_symbol : 0;
633 (evt->key_symbol > 0 && evt->key_symbol < 255))
634 *unicode = evt->key_symbol;
640DirectFB_TranslateButton(DFBInputDeviceButtonIdentifier
button)
654static DFBEnumerationResult
655EnumKeyboards(DFBInputDeviceID device_id,
656 DFBInputDeviceDescription desc,
void *callbackdata)
658 cb_data *cb = callbackdata;
659 DFB_DeviceData *devdata = cb->devdata;
667 if (device_id >= 0x10)
670 if (device_id < 0x10)
674 if (device_id != DIDID_KEYBOARD)
678 if ((desc.caps & DIDTF_KEYBOARD)) {
681 SDL_AddKeyboard(&keyboard, devdata->num_keyboard);
683 devdata->keyboard[devdata->num_keyboard].id = device_id;
684 devdata->keyboard[devdata->num_keyboard].is_generic = 0;
685 if (!strncmp(
"X11", desc.name, 3))
689 devdata->keyboard[devdata->num_keyboard].map_adjust = 8;
693 devdata->keyboard[devdata->num_keyboard].map_adjust = 0;
696 SDL_DFB_LOG(
"Keyboard %d - %s\n", device_id, desc.name);
704 devdata->num_keyboard++;
707 return DFENUM_CANCEL;
720 devdata->num_keyboard = 0;
721 cb.devdata = devdata;
723 if (devdata->use_linux_input) {
727 EnumInputDevices(devdata->dfb, EnumKeyboards, &cb));
728 if (devdata->num_keyboard == 0) {
int DirectFB_WM_ProcessEvent(_THIS, SDL_Window *window, DFBWindowEvent *evt)
void DirectFB_PumpEventsWindow(_THIS)
void DirectFB_QuitKeyboard(_THIS)
void DirectFB_InitKeyboard(_THIS)
void DirectFB_SetContext(_THIS, SDL_Window *window)
#define SDL_DFB_CHECK(x...)
#define SDL_DFB_LOG(x...)
#define SDL_DFB_DEVICEDATA(dev)
#define SDL_DFB_WINDOWDATA(win)
#define SDL_GetWindowFromID
int SDL_SendSysWMEvent(SDL_SysWMmsg *message)
#define SDL_TEXTINPUTEVENT_TEXT_SIZE
#define SDL_GetEventState(type)
void SDL_GetDefaultKeymap(SDL_Keycode *keymap)
void SDL_SetKeymap(int start, SDL_Keycode *keys, int length)
void SDL_SetKeyboardFocus(SDL_Window *window)
Sint32 SDL_Keycode
The SDL virtual key representation.
void SDL_SetMouseFocus(SDL_Window *window)
SDL_Mouse * SDL_GetMouse(void)
GLint GLint GLint GLint GLint GLint y
GLint GLint GLint GLint GLint x
GLubyte GLubyte GLubyte GLubyte w
SDL_Scancode
The SDL keyboard scancode representation.
@ SDL_SCANCODE_RIGHTBRACKET
@ SDL_SCANCODE_NONUSBACKSLASH
@ SDL_SCANCODE_APOSTROPHE
@ SDL_SCANCODE_NUMLOCKCLEAR
@ SDL_SCANCODE_PRINTSCREEN
@ SDL_SCANCODE_SCROLLLOCK
@ SDL_SCANCODE_LEFTBRACKET
@ SDL_SCANCODE_KP_MULTIPLY
@ SDL_SCANCODE_APPLICATION
#define SDL_arraysize(array)
#define SDL_VERSION(x)
Macro to determine SDL version program was compiled against.
static SDL_VideoDevice * _this
@ SDL_WINDOW_INPUT_GRABBED
@ SDL_WINDOWEVENT_FOCUS_LOST
@ SDL_WINDOWEVENT_RESIZED
@ SDL_WINDOWEVENT_FOCUS_GAINED
int SDL_SendWindowEvent(SDL_Window *window, Uint8 windowevent, int data1, int data2)
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
EGLSurface EGLNativeWindowType * window
static SDL_Scancode const linux_scancode_table[]
static const SDL_Scancode xfree86_scancode_table2[]
The SDL keysym structure, used in key events.
union SDL_SysWMmsg::@15 msg
The type used to identify a window.
static char text[MAX_TEXT_LENGTH]