Commit 61a7bca8 authored by Sam Lantinga's avatar Sam Lantinga

Date: Sun, 07 Dec 2008 13:35:23 +0100

From: Couriersud
Subject: SDL: Mouse last_x, last_y into SDL_Mouse

the attached diff moves the static vars last_x and last_y into
SDL_Mouse. These, as far as I understand it, should be tied to the
individual mouse.

The patch also makes the code check for out of window conditions of
mouse->x,y when relative movements are passed to MouseSendMotion.

Also attached is the latest DirectFB code (dfb20081208) supporting
multiple mice and keyboards. This works quite well with sdlmame now. It
however needs more testing with different directfb configurations.

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403322
parent 0c30a927
...@@ -33,7 +33,6 @@ static int SDL_current_mouse = -1; ...@@ -33,7 +33,6 @@ static int SDL_current_mouse = -1;
static SDL_Mouse **SDL_mice = NULL; static SDL_Mouse **SDL_mice = NULL;
static int *SDL_IdIndex = NULL; static int *SDL_IdIndex = NULL;
static int SDL_highestId = -1; static int SDL_highestId = -1;
static int last_x, last_y; /* the last reported x and y coordinates by the system cursor */
/* Public functions */ /* Public functions */
...@@ -61,12 +60,15 @@ SDL_SetMouseIndexId(int id, int index) ...@@ -61,12 +60,15 @@ SDL_SetMouseIndexId(int id, int index)
} }
if (id > SDL_highestId) { if (id > SDL_highestId) {
int *indexes; int *indexes;
int i;
indexes = (int *) SDL_realloc(SDL_IdIndex, (id + 1) * sizeof(int)); indexes = (int *) SDL_realloc(SDL_IdIndex, (id + 1) * sizeof(int));
if (!indexes) { if (!indexes) {
SDL_OutOfMemory(); SDL_OutOfMemory();
return -1; return -1;
} }
SDL_IdIndex = indexes; SDL_IdIndex = indexes;
for (i = SDL_highestId + 1; i <= id; i++)
SDL_IdIndex[i] = -1;
SDL_IdIndex[id] = index; SDL_IdIndex[id] = index;
SDL_highestId = id; SDL_highestId = id;
} else { } else {
...@@ -378,8 +380,8 @@ SDL_SendProximity(int id, int x, int y, int type) ...@@ -378,8 +380,8 @@ SDL_SendProximity(int id, int x, int y, int type)
return 0; return 0;
} }
last_x = x; mouse->last_x = x;
last_y = y; mouse->last_y = y;
if (SDL_ProcessEvents[type] == SDL_ENABLE) { if (SDL_ProcessEvents[type] == SDL_ENABLE) {
SDL_Event event; SDL_Event event;
event.proximity.which = (Uint8) index; event.proximity.which = (Uint8) index;
...@@ -405,6 +407,7 @@ SDL_SendMouseMotion(int id, int relative, int x, int y, int pressure) ...@@ -405,6 +407,7 @@ SDL_SendMouseMotion(int id, int relative, int x, int y, int pressure)
int posted; int posted;
int xrel; int xrel;
int yrel; int yrel;
int x_max = 0, y_max = 0;
if (!mouse || mouse->flush_motion) { if (!mouse || mouse->flush_motion) {
return 0; return 0;
...@@ -412,8 +415,8 @@ SDL_SendMouseMotion(int id, int relative, int x, int y, int pressure) ...@@ -412,8 +415,8 @@ SDL_SendMouseMotion(int id, int relative, int x, int y, int pressure)
/* if the mouse is out of proximity we don't to want to have any motion from it */ /* if the mouse is out of proximity we don't to want to have any motion from it */
if (mouse->proximity == SDL_FALSE) { if (mouse->proximity == SDL_FALSE) {
last_x = x; mouse->last_x = x;
last_y = y; mouse->last_y = y;
return 0; return 0;
} }
...@@ -421,11 +424,11 @@ SDL_SendMouseMotion(int id, int relative, int x, int y, int pressure) ...@@ -421,11 +424,11 @@ SDL_SendMouseMotion(int id, int relative, int x, int y, int pressure)
if (relative) { if (relative) {
xrel = x; xrel = x;
yrel = y; yrel = y;
x = (last_x + x); x = (mouse->last_x + x);
y = (last_y + y); y = (mouse->last_y + y);
} else { } else {
xrel = x - last_x; xrel = x - mouse->last_x;
yrel = y - last_y; yrel = y - mouse->last_y;
} }
/* Drop events that don't change state */ /* Drop events that don't change state */
...@@ -441,27 +444,26 @@ SDL_SendMouseMotion(int id, int relative, int x, int y, int pressure) ...@@ -441,27 +444,26 @@ SDL_SendMouseMotion(int id, int relative, int x, int y, int pressure)
mouse->x = x; mouse->x = x;
mouse->y = y; mouse->y = y;
} else { } else {
/* while using the relative mode and many windows, we have to be mouse->x += xrel;
sure that the pointers find themselves inside the windows */ mouse->y += yrel;
int x_max, y_max; }
SDL_GetWindowSize(mouse->focus, &x_max, &y_max); SDL_GetWindowSize(mouse->focus, &x_max, &y_max);
if (mouse->x + xrel > x_max) { /* make sure that the pointers find themselves inside the windows */
mouse->x = x_max; /* only check if mouse->xmax is set ! */
} else if (mouse->x + xrel < 0) { if (x_max && mouse->x > x_max) {
mouse->x = 0; mouse->x = x_max;
} else { } else if (mouse->x < 0) {
mouse->x += xrel; mouse->x = 0;
} }
if (mouse->y + yrel > y_max) {
mouse->y = y_max; if (y_max && mouse->y > y_max) {
} else if (mouse->y + yrel < 0) { mouse->y = y_max;
mouse->y = 0; } else if (mouse->y < 0) {
} else { mouse->y = 0;
mouse->y += yrel;
}
} }
mouse->xdelta += xrel; mouse->xdelta += xrel;
mouse->ydelta += yrel; mouse->ydelta += yrel;
mouse->pressure = pressure; mouse->pressure = pressure;
...@@ -491,8 +493,8 @@ SDL_SendMouseMotion(int id, int relative, int x, int y, int pressure) ...@@ -491,8 +493,8 @@ SDL_SendMouseMotion(int id, int relative, int x, int y, int pressure)
event.motion.cursor = mouse->current_end; event.motion.cursor = mouse->current_end;
posted = (SDL_PushEvent(&event) > 0); posted = (SDL_PushEvent(&event) > 0);
} }
last_x = x; mouse->last_x = x;
last_y = y; mouse->last_y = y;
return posted; return posted;
} }
......
...@@ -71,6 +71,7 @@ struct SDL_Mouse ...@@ -71,6 +71,7 @@ struct SDL_Mouse
int z; /* for future use */ int z; /* for future use */
int xdelta; int xdelta;
int ydelta; int ydelta;
int last_x, last_y; /* the last reported x and y coordinates */
char *name; char *name;
Uint8 buttonstate; Uint8 buttonstate;
SDL_bool relative_mode; SDL_bool relative_mode;
......
...@@ -1054,7 +1054,7 @@ SDL_GetWindowSize(SDL_WindowID windowID, int *w, int *h) ...@@ -1054,7 +1054,7 @@ SDL_GetWindowSize(SDL_WindowID windowID, int *w, int *h)
{ {
SDL_Window *window = SDL_GetWindowFromID(windowID); SDL_Window *window = SDL_GetWindowFromID(windowID);
if (!window) { if (window) {
if (w) { if (w) {
*w = window->w; *w = window->w;
} }
......
...@@ -33,12 +33,16 @@ ...@@ -33,12 +33,16 @@
#include "SDL_DirectFB_events.h" #include "SDL_DirectFB_events.h"
/* The translation tables from a DirectFB keycode to a SDL keysym */ /* The translation tables from a DirectFB keycode to a SDL keysym */
static SDLKey keymap[256]; static SDLKey oskeymap[256];
static int sys_ids;
static SDL_keysym *DirectFB_TranslateKey(_THIS, DFBWindowEvent * evt, static SDL_keysym *DirectFB_TranslateKey(_THIS, DFBWindowEvent * evt,
SDL_keysym * keysym); SDL_keysym * keysym);
static SDL_keysym *DirectFB_TranslateKeyInputEvent(_THIS, int index,
DFBInputEvent * evt,
SDL_keysym * keysym);
static void DirectFB_InitOSKeymap(_THIS); static void DirectFB_InitOSKeymap(_THIS, SDLKey * keypmap, int numkeys);
static int DirectFB_TranslateButton(DFBInputDeviceButtonIdentifier button); static int DirectFB_TranslateButton(DFBInputDeviceButtonIdentifier button);
static void static void
...@@ -65,19 +69,68 @@ DirectFB_SetContext(_THIS, SDL_WindowID id) ...@@ -65,19 +69,68 @@ DirectFB_SetContext(_THIS, SDL_WindowID id)
} }
static void
FocusAllMice(_THIS, SDL_WindowID id)
{
SDL_DFB_DEVICEDATA(_this);
int index;
for (index = 0; index < devdata->num_mice; index++)
SDL_SetMouseFocus(devdata->mouse_id[index], id);
}
static void
FocusAllKeyboards(_THIS, SDL_WindowID id)
{
SDL_DFB_DEVICEDATA(_this);
int index;
for (index = 0; index < devdata->num_keyboard; index++)
SDL_SetKeyboardFocus(index, id);
}
static void
MotionAllMice(_THIS, int x, int y)
{
SDL_DFB_DEVICEDATA(_this);
int index;
for (index = 0; index < devdata->num_mice; index++) {
SDL_Mouse *mouse = SDL_GetMouse(index);
mouse->x = mouse->last_x = x;
mouse->y = mouse->last_y = y;
//SDL_SendMouseMotion(devdata->mouse_id[index], 0, x, y, 0);
}
}
static int
KbdIndex(_THIS, int id)
{
SDL_DFB_DEVICEDATA(_this);
int index;
for (index = 0; index < devdata->num_keyboard; index++) {
if (devdata->keyboard[index].id == id)
return index;
}
return -1;
}
void void
DirectFB_PumpEventsWindow(_THIS) DirectFB_PumpEventsWindow(_THIS)
{ {
SDL_DFB_DEVICEDATA(_this); SDL_DFB_DEVICEDATA(_this);
DFB_WindowData *p; DFB_WindowData *p;
DFBWindowEvent evt;
DFBInputEvent ievt; DFBInputEvent ievt;
SDL_WindowID grabbed_window; Sint32 /* SDL_WindowID */ grabbed_window;
char text[5]; char text[5];
int kbd_idx;
grabbed_window = -1; grabbed_window = -1;
for (p = devdata->firstwin; p != NULL; p = p->next) { for (p = devdata->firstwin; p != NULL; p = p->next) {
DFBWindowEvent evt;
SDL_Window *w = SDL_GetWindowFromID(p->id); SDL_Window *w = SDL_GetWindowFromID(p->id);
if (w->flags & SDL_WINDOW_INPUT_GRABBED) { if (w->flags & SDL_WINDOW_INPUT_GRABBED) {
...@@ -91,34 +144,62 @@ DirectFB_PumpEventsWindow(_THIS) ...@@ -91,34 +144,62 @@ DirectFB_PumpEventsWindow(_THIS)
if (evt.clazz == DFEC_WINDOW) { if (evt.clazz == DFEC_WINDOW) {
switch (evt.type) { switch (evt.type) {
case DWET_BUTTONDOWN: case DWET_BUTTONDOWN:
SDL_SendMouseButton(devdata->mouse, SDL_PRESSED, if (!LINUX_INPUT_SUPPORT) {
DirectFB_TranslateButton(evt.button)); SDL_SendMouseMotion(devdata->mouse_id[0], 0, evt.cx,
evt.cy, 0);
SDL_SendMouseButton(devdata->mouse_id[0], SDL_PRESSED,
DirectFB_TranslateButton(evt.
button));
} else {
MotionAllMice(_this, evt.x, evt.y);
}
break; break;
case DWET_BUTTONUP: case DWET_BUTTONUP:
SDL_SendMouseButton(devdata->mouse, SDL_RELEASED, if (!LINUX_INPUT_SUPPORT) {
DirectFB_TranslateButton(evt.button)); SDL_SendMouseMotion(devdata->mouse_id[0], 0, evt.cx,
evt.cy, 0);
SDL_SendMouseButton(devdata->mouse_id[0],
SDL_RELEASED,
DirectFB_TranslateButton(evt.
button));
} else {
MotionAllMice(_this, evt.x, evt.y);
}
break; break;
case DWET_MOTION: case DWET_MOTION:
if (!(w->flags & SDL_WINDOW_INPUT_GRABBED)) if (!LINUX_INPUT_SUPPORT) {
SDL_SendMouseMotion(devdata->mouse, 0, evt.cx, evt.cy, if (!(w->flags & SDL_WINDOW_INPUT_GRABBED))
0); SDL_SendMouseMotion(devdata->mouse_id[0], 0,
evt.cx, evt.cy, 0);
} else {
/* relative movements are not exact!
* This code should limit the number of events sent.
* However it kills MAME axis recognition ... */
static int cnt = 0;
if (1 && ++cnt > 20) {
MotionAllMice(_this, evt.x, evt.y);
cnt = 0;
}
}
break; break;
case DWET_KEYDOWN: case DWET_KEYDOWN:
DirectFB_TranslateKey(_this, &evt, &keysym); if (!LINUX_INPUT_SUPPORT) {
SDL_SendKeyboardKey(devdata->keyboard, SDL_PRESSED, DirectFB_TranslateKey(_this, &evt, &keysym);
keysym.scancode); SDL_SendKeyboardKey(0, SDL_PRESSED, keysym.scancode);
if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) { if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) {
SDL_memcpy(text, &keysym.unicode, 4); SDL_memcpy(text, &keysym.unicode, 4);
text[4] = 0; text[4] = 0;
if (*text) { if (*text) {
SDL_SendKeyboardText(devdata->keyboard, text); SDL_SendKeyboardText(0, text);
}
} }
} }
break; break;
case DWET_KEYUP: case DWET_KEYUP:
DirectFB_TranslateKey(_this, &evt, &keysym); if (!LINUX_INPUT_SUPPORT) {
SDL_SendKeyboardKey(devdata->keyboard, SDL_RELEASED, DirectFB_TranslateKey(_this, &evt, &keysym);
keysym.scancode); SDL_SendKeyboardKey(0, SDL_RELEASED, keysym.scancode);
}
break; break;
case DWET_POSITION_SIZE: case DWET_POSITION_SIZE:
if (evt.x != w->x || evt.y != w->y) if (evt.x != w->x || evt.y != w->y)
...@@ -143,23 +224,24 @@ DirectFB_PumpEventsWindow(_THIS) ...@@ -143,23 +224,24 @@ DirectFB_PumpEventsWindow(_THIS)
break; break;
case DWET_GOTFOCUS: case DWET_GOTFOCUS:
DirectFB_SetContext(_this, p->id); DirectFB_SetContext(_this, p->id);
SDL_SetKeyboardFocus(devdata->keyboard, p->id); FocusAllKeyboards(_this, p->id);
SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_FOCUS_GAINED, SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_FOCUS_GAINED,
0, 0); 0, 0);
break; break;
case DWET_LOSTFOCUS: case DWET_LOSTFOCUS:
SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_FOCUS_LOST, 0, SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_FOCUS_LOST, 0,
0); 0);
SDL_SetKeyboardFocus(devdata->keyboard, 0); FocusAllKeyboards(_this, 0);
break; break;
case DWET_ENTER: case DWET_ENTER:
/* SDL_DirectFB_ReshowCursor(_this, 0); */ /* SDL_DirectFB_ReshowCursor(_this, 0); */
SDL_SetMouseFocus(devdata->mouse, p->id); FocusAllMice(_this, p->id);
MotionAllMice(_this, evt.x, evt.y);
SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_ENTER, 0, 0); SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_ENTER, 0, 0);
break; break;
case DWET_LEAVE: case DWET_LEAVE:
SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_LEAVE, 0, 0); SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_LEAVE, 0, 0);
SDL_SetMouseFocus(devdata->mouse, 0); FocusAllMice(_this, 0);
/* SDL_DirectFB_ReshowCursor(_this, 1); */ /* SDL_DirectFB_ReshowCursor(_this, 1); */
break; break;
default: default:
...@@ -174,32 +256,94 @@ DirectFB_PumpEventsWindow(_THIS) ...@@ -174,32 +256,94 @@ DirectFB_PumpEventsWindow(_THIS)
/* Now get relative events in case we need them */ /* Now get relative events in case we need them */
while (devdata->events->GetEvent(devdata->events, while (devdata->events->GetEvent(devdata->events,
DFB_EVENT(&ievt)) == DFB_OK) { DFB_EVENT(&ievt)) == DFB_OK) {
if (grabbed_window >= 0) { SDL_keysym keysym;
switch (ievt.type) {
case DIET_AXISMOTION:
if (!LINUX_INPUT_SUPPORT) {
if ((grabbed_window >= 0) && (ievt.flags & DIEF_AXISREL)) {
printf("rel devid %d\n", ievt.device_id);
if (ievt.axis == DIAI_X)
SDL_SendMouseMotion(ievt.device_id, 1, ievt.axisrel,
0, 0);
else if (ievt.axis == DIAI_Y)
SDL_SendMouseMotion(ievt.device_id, 1, 0,
ievt.axisrel, 0);
}
}
break;
}
if (LINUX_INPUT_SUPPORT) {
IDirectFBInputDevice *idev;
static int last_x, last_y;
switch (ievt.type) { switch (ievt.type) {
case DIET_AXISMOTION: case DIET_AXISMOTION:
if (ievt.flags & DIEF_AXISREL) { if (ievt.flags & DIEF_AXISABS) {
if (ievt.axis == DIAI_X)
last_x = ievt.axisabs;
else if (ievt.axis == DIAI_Y)
last_y = ievt.axisabs;
if (!(ievt.flags & DIEF_FOLLOW))
SDL_SendMouseMotion(ievt.device_id, 0, last_x, last_y,
0);
} else if (ievt.flags & DIEF_AXISREL) {
//printf("rel %d %d\n", ievt.device_id, ievt.axisrel);
if (ievt.axis == DIAI_X) if (ievt.axis == DIAI_X)
SDL_SendMouseMotion(devdata->mouse, 1, ievt.axisrel, SDL_SendMouseMotion(ievt.device_id, 1, ievt.axisrel,
0, 0); 0, 0);
else if (ievt.axis == DIAI_Y) else if (ievt.axis == DIAI_Y)
SDL_SendMouseMotion(devdata->mouse, 1, 0, SDL_SendMouseMotion(ievt.device_id, 1, 0,
ievt.axisrel, 0); ievt.axisrel, 0);
} }
break; break;
default: 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);
if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) {
SDL_memcpy(text, &keysym.unicode, 4);
text[4] = 0;
if (*text) {
SDL_SendKeyboardText(kbd_idx, text);
}
}
break;
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);
break;
case DIET_BUTTONPRESS:
if (ievt.buttons & DIBM_LEFT)
SDL_SendMouseButton(ievt.device_id, SDL_PRESSED, 1);
if (ievt.buttons & DIBM_MIDDLE)
SDL_SendMouseButton(ievt.device_id, SDL_PRESSED, 2);
if (ievt.buttons & DIBM_RIGHT)
SDL_SendMouseButton(ievt.device_id, SDL_PRESSED, 3);
break;
case DIET_BUTTONRELEASE:
if (!(ievt.buttons & DIBM_LEFT))
SDL_SendMouseButton(ievt.device_id, SDL_RELEASED, 1);
if (!(ievt.buttons & DIBM_MIDDLE))
SDL_SendMouseButton(ievt.device_id, SDL_RELEASED, 2);
if (!(ievt.buttons & DIBM_RIGHT))
SDL_SendMouseButton(ievt.device_id, SDL_RELEASED, 3);
break;
} }
} }
} }
} }
void void
DirectFB_InitOSKeymap(_THIS) DirectFB_InitOSKeymap(_THIS, SDLKey * keymap, int numkeys)
{ {
int i; int i;
/* Initialize the DirectFB key translation table */ /* Initialize the DirectFB key translation table */
for (i = 0; i < SDL_arraysize(keymap); ++i) for (i = 0; i < numkeys; ++i)
keymap[i] = SDL_SCANCODE_UNKNOWN; keymap[i] = SDL_SCANCODE_UNKNOWN;
keymap[DIKI_A - DIKI_UNKNOWN] = SDL_SCANCODE_A; keymap[DIKI_A - DIKI_UNKNOWN] = SDL_SCANCODE_A;
...@@ -332,9 +476,10 @@ DirectFB_TranslateKey(_THIS, DFBWindowEvent * evt, SDL_keysym * keysym) ...@@ -332,9 +476,10 @@ DirectFB_TranslateKey(_THIS, DFBWindowEvent * evt, SDL_keysym * keysym)
else else
keysym->scancode = SDL_SCANCODE_UNKNOWN; keysym->scancode = SDL_SCANCODE_UNKNOWN;
if (keysym->scancode == SDL_SCANCODE_UNKNOWN || devdata->kbdgeneric) { if (keysym->scancode == SDL_SCANCODE_UNKNOWN
if (evt->key_id - DIKI_UNKNOWN < SDL_arraysize(keymap)) || devdata->keyboard[0].is_generic) {
keysym->scancode = keymap[evt->key_id - DIKI_UNKNOWN]; if (evt->key_id - DIKI_UNKNOWN < SDL_arraysize(oskeymap))
keysym->scancode = oskeymap[evt->key_id - DIKI_UNKNOWN];
else else
keysym->scancode = SDL_SCANCODE_UNKNOWN; keysym->scancode = SDL_SCANCODE_UNKNOWN;
} }
...@@ -348,6 +493,34 @@ DirectFB_TranslateKey(_THIS, DFBWindowEvent * evt, SDL_keysym * keysym) ...@@ -348,6 +493,34 @@ DirectFB_TranslateKey(_THIS, DFBWindowEvent * evt, SDL_keysym * keysym)
return keysym; return keysym;
} }
static SDL_keysym *
DirectFB_TranslateKeyInputEvent(_THIS, int index, DFBInputEvent * evt,
SDL_keysym * keysym)
{
SDL_DFB_DEVICEDATA(_this);
if (evt->key_code >= 0
&& evt->key_code < SDL_arraysize(linux_scancode_table))
keysym->scancode = linux_scancode_table[evt->key_code];
else
keysym->scancode = SDL_SCANCODE_UNKNOWN;
if (keysym->scancode == SDL_SCANCODE_UNKNOWN
|| devdata->keyboard[index].is_generic) {
if (evt->key_id - DIKI_UNKNOWN < SDL_arraysize(oskeymap))
keysym->scancode = oskeymap[evt->key_id - DIKI_UNKNOWN];
else
keysym->scancode = SDL_SCANCODE_UNKNOWN;
}
keysym->unicode =
(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;
}
static int static int
DirectFB_TranslateButton(DFBInputDeviceButtonIdentifier button) DirectFB_TranslateButton(DFBInputDeviceButtonIdentifier button)
{ {
...@@ -373,14 +546,49 @@ input_device_cb(DFBInputDeviceID device_id, DFBInputDeviceDescription desc, ...@@ -373,14 +546,49 @@ input_device_cb(DFBInputDeviceID device_id, DFBInputDeviceDescription desc,
if ((desc.caps & DIDTF_KEYBOARD) && device_id == DIDID_KEYBOARD) { if ((desc.caps & DIDTF_KEYBOARD) && device_id == DIDID_KEYBOARD) {
SDL_zero(keyboard); SDL_zero(keyboard);
devdata->keyboard = SDL_AddKeyboard(&keyboard, -1); SDL_AddKeyboard(&keyboard, 0);
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);
SDL_SetKeymap(0, 0, keymap, SDL_NUM_SCANCODES);
devdata->num_keyboard++;
return DFENUM_CANCEL;
}
return DFENUM_OK;
}
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)) if (!strncmp("X11", desc.name, 3))
devdata->kbdgeneric = 1; devdata->keyboard[devdata->num_keyboard].is_generic = 1;
SDL_GetDefaultKeymap(keymap); SDL_GetDefaultKeymap(keymap);
SDL_SetKeymap(devdata->keyboard, 0, keymap, SDL_NUM_SCANCODES); SDL_SetKeymap(devdata->num_keyboard, 0, keymap, SDL_NUM_SCANCODES);
devdata->num_keyboard++;
} }
return DFB_OK; return DFENUM_OK;
} }
void void
...@@ -389,12 +597,24 @@ DirectFB_InitKeyboard(_THIS) ...@@ -389,12 +597,24 @@ DirectFB_InitKeyboard(_THIS)
SDL_DFB_DEVICEDATA(_this); SDL_DFB_DEVICEDATA(_this);
int ret; int ret;
DirectFB_InitOSKeymap(_this); DirectFB_InitOSKeymap(_this, &oskeymap[0], SDL_arraysize(oskeymap));
devdata->kbdgeneric = 0; devdata->num_keyboard = 0;
if (LINUX_INPUT_SUPPORT) {
SDL_DFB_CHECK(devdata->dfb-> sys_ids = 0;
EnumInputDevices(devdata->dfb, input_device_cb, devdata)); SDL_DFB_CHECK(devdata->dfb->
EnumInputDevices(devdata->dfb, EnumKeyboards, devdata));
if (devdata->num_keyboard == 0) {
sys_ids = 1;
SDL_DFB_CHECK(devdata->dfb->
EnumInputDevices(devdata->dfb, EnumKeyboards,
devdata));
}
} else {
SDL_DFB_CHECK(devdata->dfb->
EnumInputDevices(devdata->dfb, input_device_cb,
devdata));
}
} }
void void
...@@ -403,7 +623,7 @@ DirectFB_QuitKeyboard(_THIS) ...@@ -403,7 +623,7 @@ DirectFB_QuitKeyboard(_THIS)
SDL_DFB_DEVICEDATA(_this); SDL_DFB_DEVICEDATA(_this);
int ret; int ret;
SDL_DelKeyboard(devdata->keyboard); SDL_KeyboardQuit();
} }
......
...@@ -35,22 +35,67 @@ static void DirectFB_WarpMouse(SDL_Mouse * mouse, SDL_WindowID windowID, ...@@ -35,22 +35,67 @@ static void DirectFB_WarpMouse(SDL_Mouse * mouse, SDL_WindowID windowID,
int x, int y); int x, int y);
static void DirectFB_FreeMouse(SDL_Mouse * mouse); static void DirectFB_FreeMouse(SDL_Mouse * mouse);
static int id_mask;
static DFBEnumerationResult
EnumMice(DFBInputDeviceID device_id,
DFBInputDeviceDescription desc, void *callbackdata)
{
DFB_DeviceData *devdata = callbackdata;
if ((desc.type & DIDTF_MOUSE) && (device_id & id_mask)) {
SDL_Mouse mouse;
SDL_zero(mouse);
mouse.CreateCursor = DirectFB_CreateCursor;
mouse.ShowCursor = DirectFB_ShowCursor;
mouse.MoveCursor = DirectFB_MoveCursor;
mouse.FreeCursor = DirectFB_FreeCursor;
mouse.WarpMouse = DirectFB_WarpMouse;
mouse.FreeMouse = DirectFB_FreeMouse;
mouse.cursor_shown = 1;
SDL_SetMouseIndexId(device_id, devdata->num_mice);
SDL_AddMouse(&mouse, devdata->num_mice, desc.name, 0, 0, 1);
devdata->mouse_id[devdata->num_mice] = device_id;
devdata->num_mice++;
}
return DFENUM_OK;
}
void void
DirectFB_InitMouse(_THIS) DirectFB_InitMouse(_THIS)
{ {
SDL_DFB_DEVICEDATA(_this); SDL_DFB_DEVICEDATA(_this);
SDL_Mouse mouse;
devdata->num_mice = 0;
SDL_zero(mouse); if (LINUX_INPUT_SUPPORT) {
mouse.CreateCursor = DirectFB_CreateCursor; /* try non-core devices first */
mouse.ShowCursor = DirectFB_ShowCursor; id_mask = 0xF0;
mouse.MoveCursor = DirectFB_MoveCursor; devdata->dfb->EnumInputDevices(devdata->dfb, EnumMice, devdata);
mouse.FreeCursor = DirectFB_FreeCursor; if (devdata->num_mice == 0) {
mouse.WarpMouse = DirectFB_WarpMouse; /* try core devices */
mouse.FreeMouse = DirectFB_FreeMouse; id_mask = 0x0F;
mouse.cursor_shown = 1; devdata->dfb->EnumInputDevices(devdata->dfb, EnumMice, devdata);
SDL_SetMouseIndexId(0, 0); /* ID == Index ! */ }
devdata->mouse = SDL_AddMouse(&mouse, 0, "Mouse", 0, 0, 1); }
if (devdata->num_mice == 0) {
SDL_Mouse mouse;
SDL_zero(mouse);
mouse.CreateCursor = DirectFB_CreateCursor;
mouse.ShowCursor = DirectFB_ShowCursor;
mouse.MoveCursor = DirectFB_MoveCursor;
mouse.FreeCursor = DirectFB_FreeCursor;
mouse.WarpMouse = DirectFB_WarpMouse;
mouse.FreeMouse = DirectFB_FreeMouse;
mouse.cursor_shown = 1;
SDL_SetMouseIndexId(0, 0); /* ID == Index ! */
devdata->mouse_id[0] = 0;
SDL_AddMouse(&mouse, 0, "Mouse", 0, 0, 1);
devdata->num_mice = 1;
}
} }
void void
...@@ -58,7 +103,11 @@ DirectFB_QuitMouse(_THIS) ...@@ -58,7 +103,11 @@ DirectFB_QuitMouse(_THIS)
{ {
SDL_DFB_DEVICEDATA(_this); SDL_DFB_DEVICEDATA(_this);
SDL_DelMouse(devdata->mouse); if (LINUX_INPUT_SUPPORT) {
SDL_MouseQuit();
} else {
SDL_DelMouse(0);
}
} }
/* Create a cursor from a surface */ /* Create a cursor from a surface */
......
...@@ -155,9 +155,16 @@ DirectFB_VideoInit(_THIS) ...@@ -155,9 +155,16 @@ DirectFB_VideoInit(_THIS)
devdata->use_yuv_underlays = atoi(stemp); devdata->use_yuv_underlays = atoi(stemp);
/* Create global Eventbuffer for axis events */ /* Create global Eventbuffer for axis events */
SDL_DFB_CHECKERR(dfb-> if (LINUX_INPUT_SUPPORT) {
CreateInputEventBuffer(dfb, DICAPS_AXES /*DICAPS_ALL */ , SDL_DFB_CHECKERR(dfb->
DFB_TRUE, &devdata->events)); CreateInputEventBuffer(dfb, DICAPS_ALL,
DFB_TRUE, &devdata->events));
} else {
SDL_DFB_CHECKERR(dfb->
CreateInputEventBuffer(dfb,
DICAPS_AXES /*DICAPS_ALL */ ,
DFB_TRUE, &devdata->events));
}
devdata->initialized = 1; devdata->initialized = 1;
devdata->dfb = dfb; devdata->dfb = dfb;
......
...@@ -31,6 +31,8 @@ ...@@ -31,6 +31,8 @@
#include "SDL_mouse.h" #include "SDL_mouse.h"
#define LINUX_INPUT_SUPPORT 1
#define DEBUG 0 #define DEBUG 0
#define LOG_CHANNEL stdout #define LOG_CHANNEL stdout
...@@ -124,9 +126,14 @@ struct _DFB_DeviceData ...@@ -124,9 +126,14 @@ struct _DFB_DeviceData
int initialized; int initialized;
IDirectFB *dfb; IDirectFB *dfb;
int mouse; int num_mice;
int keyboard; int mouse_id[0x100];
int kbdgeneric; int num_keyboard;
struct
{
int is_generic;
int id;
} keyboard[10];
DFB_WindowData *firstwin; DFB_WindowData *firstwin;
int use_yuv_underlays; int use_yuv_underlays;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment