Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
…ow things work. Currently implemented: detecting many pointing devices and pressure detection. Still a bug. Each program has to be comipled with a flag -lXi
  • Loading branch information
Szymon Wilczek committed Jun 6, 2008
1 parent 68f032f commit 314ff74
Show file tree
Hide file tree
Showing 13 changed files with 247 additions and 39 deletions.
2 changes: 1 addition & 1 deletion configure.in
Expand Up @@ -1055,7 +1055,7 @@ AC_HELP_STRING([--enable-x11-shared], [dynamically load X11 support [[default=ma
AC_DEFINE_UNQUOTED(SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT, "$x11ext_lib")
else
enable_x11_shared=no
EXTRA_LDFLAGS="$EXTRA_LDFLAGS $X_LIBS -lX11 -lXext"
EXTRA_LDFLAGS="$EXTRA_LDFLAGS $X_LIBS -lX11 -lXext -lXi"
fi
have_video=yes

Expand Down
1 change: 1 addition & 0 deletions include/SDL_events.h
Expand Up @@ -170,6 +170,7 @@ typedef struct SDL_MouseMotionEvent
Uint8 state; /**< The current button state */
int x; /**< X coordinate, relative to window */
int y; /**< Y coordinate, relative to window */
int z;
int xrel; /**< The relative motion in the X direction */
int yrel; /**< The relative motion in the Y direction */
SDL_WindowID windowID; /**< The window with mouse focus, if any */
Expand Down
2 changes: 1 addition & 1 deletion include/SDL_keysym.h
Expand Up @@ -242,7 +242,7 @@ enum
SDLK_KBDILLUMDOWN = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KBDILLUMDOWN),
SDLK_KBDILLUMUP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KBDILLUMUP),
SDLK_EJECT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_EJECT),
SDLK_SLEEP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_SLEEP),
SDLK_SLEEP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_SLEEP)
};

/**
Expand Down
5 changes: 5 additions & 0 deletions include/SDL_mouse.h
Expand Up @@ -203,6 +203,11 @@ extern DECLSPEC int SDLCALL SDL_ShowCursor(int toggle);
Button 2: Middle mouse button
Button 3: Right mouse button
*/

extern DECLSPEC int SDLCALL SDL_GetNumOfMice(void);

extern DECLSPEC char* SDLCALL SDL_GetMouseName(int index);

#define SDL_BUTTON(X) (1 << ((X)-1))
#define SDL_BUTTON_LEFT 1
#define SDL_BUTTON_MIDDLE 2
Expand Down
82 changes: 70 additions & 12 deletions src/events/SDL_mouse.c
Expand Up @@ -31,6 +31,8 @@
static int SDL_num_mice;
static int SDL_current_mouse;
static SDL_Mouse **SDL_mice;
int *SDL_IdIndex;
int SDL_highestId;


/* Public functions */
Expand All @@ -50,11 +52,11 @@ SDL_GetMouse(int index)
}

int
SDL_AddMouse(const SDL_Mouse * mouse, int index)
SDL_AddMouse(const SDL_Mouse * mouse, int index, char* name)
{
SDL_Mouse **mice;
int selected_mouse;

char* temp_name;
/* Add the mouse to the list of mice */
if (index < 0 || index >= SDL_num_mice || SDL_mice[index]) {
mice =
Expand All @@ -74,8 +76,8 @@ SDL_AddMouse(const SDL_Mouse * mouse, int index)
return -1;
}
*SDL_mice[index] = *mouse;

/* Create the default cursor for the mouse */
SDL_mice[index]->name=SDL_malloc(strlen(name)*sizeof(char));
strcpy(SDL_mice[index]->name,name);
SDL_mice[index]->cursor_shown = SDL_TRUE;
selected_mouse = SDL_SelectMouse(index);
SDL_mice[index]->cur_cursor = NULL;
Expand All @@ -98,6 +100,7 @@ SDL_DelMouse(int index)
}

mouse->def_cursor = NULL;
SDL_free(mouse->name);
while (mouse->cursors) {
SDL_FreeCursor(mouse->cursors);
}
Expand Down Expand Up @@ -266,8 +269,9 @@ SDL_GetRelativeMouseState(int *x, int *y)
}

void
SDL_SetMouseFocus(int index, SDL_WindowID windowID)
SDL_SetMouseFocus(int id, SDL_WindowID windowID)
{
int index = SDL_GetIndexById(id);
SDL_Mouse *mouse = SDL_GetMouse(index);
int i;
SDL_bool focus;
Expand Down Expand Up @@ -315,8 +319,9 @@ SDL_SetMouseFocus(int index, SDL_WindowID windowID)
}

int
SDL_SendMouseMotion(int index, int relative, int x, int y)
SDL_SendMouseMotion(int id, int relative, int x, int y,int z)
{
int index=SDL_GetIndexById(id);
SDL_Mouse *mouse = SDL_GetMouse(index);
int posted;
int xrel;
Expand Down Expand Up @@ -352,6 +357,7 @@ SDL_SendMouseMotion(int index, int relative, int x, int y)
}
mouse->xdelta += xrel;
mouse->ydelta += yrel;
mouse->z=z;

/* Move the mouse cursor, if needed */
if (mouse->cursor_shown && !mouse->relative_mode &&
Expand All @@ -368,6 +374,7 @@ SDL_SendMouseMotion(int index, int relative, int x, int y)
event.motion.state = mouse->buttonstate;
event.motion.x = mouse->x;
event.motion.y = mouse->y;
event.motion.z = mouse->z;
event.motion.xrel = xrel;
event.motion.yrel = yrel;
event.motion.windowID = mouse->focus;
Expand All @@ -377,8 +384,9 @@ SDL_SendMouseMotion(int index, int relative, int x, int y)
}

int
SDL_SendMouseButton(int index, Uint8 state, Uint8 button)
SDL_SendMouseButton(int id, Uint8 state, Uint8 button)
{
int index=SDL_GetIndexById(id);
SDL_Mouse *mouse = SDL_GetMouse(index);
int posted;
Uint8 type;
Expand All @@ -398,10 +406,10 @@ SDL_SendMouseButton(int index, Uint8 state, Uint8 button)
mouse->buttonstate |= SDL_BUTTON(button);
break;
case SDL_RELEASED:
if (!(mouse->buttonstate & SDL_BUTTON(button))) {
/* Ignore this event, no state change */
return 0;
}
//if (!(mouse->buttonstate & SDL_BUTTON(button))) {
// /* Ignore this event, no state change */
// return 0;
//}*/
type = SDL_MOUSEBUTTONUP;
mouse->buttonstate &= ~SDL_BUTTON(button);
break;
Expand Down Expand Up @@ -463,7 +471,7 @@ SDL_WarpMouseInWindow(SDL_WindowID windowID, int x, int y)
mouse->WarpMouse(mouse, windowID, x, y);
} else {
SDL_SetMouseFocus(SDL_current_mouse, windowID);
SDL_SendMouseMotion(SDL_current_mouse, 0, x, y);
SDL_SendMouseMotion(SDL_current_mouse, 0, x, y,0);
}
}

Expand Down Expand Up @@ -649,4 +657,54 @@ SDL_ShowCursor(int toggle)
return shown;
}

void SDL_SetIndexId(int id, int index)
{
if(id>SDL_highestId)
{
int *indexes;
indexes =
(int*) SDL_realloc(SDL_IdIndex,
(id + 1) * sizeof(int));
if (!indexes) {
SDL_OutOfMemory();
return -1;
}
SDL_IdIndex=indexes;
SDL_IdIndex[id]=index;
SDL_highestId=id;
}
else
{
SDL_IdIndex[id]=index;
}
}

int SDL_GetIndexById(int id)
{
if(id>SDL_highestId)
{
return -1;
}
else
{
return SDL_IdIndex[id];
}
}

int SDL_GetNumOfMice(void)
{
return SDL_num_mice;
}

char* SDL_GetMouseName(int index)
{
SDL_Mouse* mouse = SDL_GetMouse(index);
if(!mouse)
{
return NULL;
}
return mouse->name;
}


/* vi: set ts=4 sw=4 expandtab: */
17 changes: 15 additions & 2 deletions src/events/SDL_mouse_c.h
Expand Up @@ -58,10 +58,13 @@ struct SDL_Mouse

/* Data common to all mice */
SDL_WindowID focus;
int which;
int x;
int y;
int z;
int xdelta;
int ydelta;
char* name;
Uint8 buttonstate;
SDL_bool relative_mode;
SDL_bool flush_motion;
Expand All @@ -84,7 +87,7 @@ extern SDL_Mouse *SDL_GetMouse(int index);
/* Add a mouse, possibly reattaching at a particular index (or -1),
returning the index of the mouse, or -1 if there was an error.
*/
extern int SDL_AddMouse(const SDL_Mouse * mouse, int index);
extern int SDL_AddMouse(const SDL_Mouse * mouse, int index, char* name);

/* Remove a mouse at an index, clearing the slot for later */
extern void SDL_DelMouse(int index);
Expand All @@ -96,7 +99,7 @@ extern void SDL_ResetMouse(int index);
extern void SDL_SetMouseFocus(int index, SDL_WindowID windowID);

/* Send a mouse motion event for a mouse at an index */
extern int SDL_SendMouseMotion(int index, int relative, int x, int y);
extern int SDL_SendMouseMotion(int index, int relative, int x, int y, int z);

/* Send a mouse button event for a mouse at an index */
extern int SDL_SendMouseButton(int index, Uint8 state, Uint8 button);
Expand All @@ -107,6 +110,16 @@ extern int SDL_SendMouseWheel(int index, int x, int y);
/* Shutdown the mouse subsystem */
extern void SDL_MouseQuit(void);

extern int SDL_GetIndexById(int id);

extern void SDL_SetIndexId(int id, int index);

extern int SDL_GetNumOfMice(void);

extern char* SDL_GetMouseName(int index);



#endif /* _SDL_mouse_c_h */

/* vi: set ts=4 sw=4 expandtab: */
2 changes: 1 addition & 1 deletion src/video/x11/SDL_x11dyn.h
Expand Up @@ -29,7 +29,7 @@
#include <X11/Xatom.h>
#include <X11/Xlibint.h>
#include <X11/Xproto.h>

//#include <X11/extensions/XInput.h>
#include "../Xext/extensions/Xext.h"
#include "../Xext/extensions/extutil.h"

Expand Down
41 changes: 25 additions & 16 deletions src/video/x11/SDL_x11events.c
Expand Up @@ -29,13 +29,16 @@
#include "SDL_x11video.h"
#include "../../events/SDL_events_c.h"

//XEventClass *SDL_XEvents;
//int SDL_numOfEvents;

static void
X11_DispatchEvent(_THIS)
{
SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
SDL_WindowData *data;
XEvent xevent;
int i;
int i,z;

SDL_zero(xevent); /* valgrind fix. --ryan. */
XNextEvent(videodata->display, &xevent);
Expand Down Expand Up @@ -91,9 +94,10 @@ X11_DispatchEvent(_THIS)
#endif
if ((xevent.xcrossing.mode != NotifyGrab) &&
(xevent.xcrossing.mode != NotifyUngrab)) {
SDL_SetMouseFocus(videodata->mouse, data->windowID);
SDL_SendMouseMotion(videodata->mouse, 0, xevent.xcrossing.x,
xevent.xcrossing.y);
XDeviceMotionEvent* move=(XDeviceMotionEvent*)&xevent;
SDL_SetMouseFocus(move->deviceid, data->windowID);
SDL_SendMouseMotion(move->deviceid, 0, move->x,
move->y,move->axis_data[2]);
}
}
break;
Expand All @@ -111,9 +115,10 @@ X11_DispatchEvent(_THIS)
if ((xevent.xcrossing.mode != NotifyGrab) &&
(xevent.xcrossing.mode != NotifyUngrab) &&
(xevent.xcrossing.detail != NotifyInferior)) {
SDL_SendMouseMotion(videodata->mouse, 0,
xevent.xcrossing.x, xevent.xcrossing.y);
SDL_SetMouseFocus(videodata->mouse, 0);
XDeviceMotionEvent* move=(XDeviceMotionEvent*)&xevent;
SDL_SendMouseMotion(move->deviceid, 0,
move->x, move->y,move->axis_data[2]);
SDL_SetMouseFocus(move->deviceid, 0);
}
}
break;
Expand Down Expand Up @@ -167,26 +172,30 @@ X11_DispatchEvent(_THIS)
break;

/* Mouse motion? */
case MotionNotify:{
case 103:{ //MotionNotify
#ifdef DEBUG_MOTION
printf("X11 motion: %d,%d\n", xevent.xmotion.x, xevent.xmotion.y);
#endif
SDL_SendMouseMotion(videodata->mouse, 0, xevent.xmotion.x,
xevent.xmotion.y);
XDeviceMotionEvent* move=(XDeviceMotionEvent*)&xevent;
SDL_SendMouseMotion(move->deviceid, 0, move->x,
move->y,move->axis_data[2]);
}
break;
/*case MotionNotify:{
/* Mouse button press? */
case ButtonPress:{
SDL_SendMouseButton(videodata->mouse, SDL_PRESSED,
xevent.xbutton.button);
case 101:{//ButtonPress
XDeviceButtonPressedEvent* pressed=(XDeviceButtonPressedEvent*)&xevent;
SDL_SendMouseButton(pressed->deviceid, SDL_PRESSED,
pressed->button);
}
break;

/* Mouse button release? */
case ButtonRelease:{
SDL_SendMouseButton(videodata->mouse, SDL_RELEASED,
xevent.xbutton.button);
case 102:{//ButtonRelease
XDeviceButtonReleasedEvent* released=(XDeviceButtonReleasedEvent*)&xevent;
SDL_SendMouseButton(released->deviceid, SDL_RELEASED,
released->button);
}
break;

Expand Down

0 comments on commit 314ff74

Please sign in to comment.