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 */
/* only check if mouse->xmax is set ! */
if (x_max && mouse->x > x_max) {
mouse->x = x_max; mouse->x = x_max;
} else if (mouse->x + xrel < 0) { } else if (mouse->x < 0) {
mouse->x = 0; mouse->x = 0;
} else {
mouse->x += xrel;
} }
if (mouse->y + yrel > y_max) {
if (y_max && mouse->y > y_max) {
mouse->y = y_max; mouse->y = y_max;
} else if (mouse->y + yrel < 0) { } else if (mouse->y < 0) {
mouse->y = 0; mouse->y = 0;
} else {
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;
} }
......
This diff is collapsed.
...@@ -35,10 +35,51 @@ static void DirectFB_WarpMouse(SDL_Mouse * mouse, SDL_WindowID windowID, ...@@ -35,10 +35,51 @@ 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);
devdata->num_mice = 0;
if (LINUX_INPUT_SUPPORT) {
/* try non-core devices first */
id_mask = 0xF0;
devdata->dfb->EnumInputDevices(devdata->dfb, EnumMice, devdata);
if (devdata->num_mice == 0) {
/* try core devices */
id_mask = 0x0F;
devdata->dfb->EnumInputDevices(devdata->dfb, EnumMice, devdata);
}
}
if (devdata->num_mice == 0) {
SDL_Mouse mouse; SDL_Mouse mouse;
SDL_zero(mouse); SDL_zero(mouse);
...@@ -49,8 +90,12 @@ DirectFB_InitMouse(_THIS) ...@@ -49,8 +90,12 @@ DirectFB_InitMouse(_THIS)
mouse.WarpMouse = DirectFB_WarpMouse; mouse.WarpMouse = DirectFB_WarpMouse;
mouse.FreeMouse = DirectFB_FreeMouse; mouse.FreeMouse = DirectFB_FreeMouse;
mouse.cursor_shown = 1; mouse.cursor_shown = 1;
SDL_SetMouseIndexId(0, 0); /* ID == Index ! */ SDL_SetMouseIndexId(0, 0); /* ID == Index ! */
devdata->mouse = SDL_AddMouse(&mouse, 0, "Mouse", 0, 0, 1); 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 */
if (LINUX_INPUT_SUPPORT) {
SDL_DFB_CHECKERR(dfb-> SDL_DFB_CHECKERR(dfb->
CreateInputEventBuffer(dfb, DICAPS_AXES /*DICAPS_ALL */ , CreateInputEventBuffer(dfb, DICAPS_ALL,
DFB_TRUE, &devdata->events)); 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