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

Commit

Permalink
Major bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Szymon Wilczek committed Jun 19, 2008
1 parent 314ff74 commit d35dac3
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 33 deletions.
67 changes: 38 additions & 29 deletions src/video/x11/SDL_x11events.c
Expand Up @@ -32,13 +32,20 @@
//XEventClass *SDL_XEvents;
//int SDL_numOfEvents;

extern int motion;
extern int button_pressed;
extern int button_released;

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

SDL_zero(xevent); /* valgrind fix. --ryan. */
XNextEvent(videodata->display, &xevent);
Expand Down Expand Up @@ -171,34 +178,6 @@ X11_DispatchEvent(_THIS)
}
break;

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

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

/* Key press? */
case KeyPress:{
KeyCode keycode = xevent.xkey.keycode;
Expand Down Expand Up @@ -310,14 +289,44 @@ X11_DispatchEvent(_THIS)
break;

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

/* Mouse button release? */
else if(xevent.type==button_released)//ButtonRelease
{
XDeviceButtonReleasedEvent* released=(XDeviceButtonReleasedEvent*)&xevent;
SDL_SendMouseButton(released->deviceid, SDL_RELEASED,
released->button);
}
else
{
#ifdef DEBUG_XEVENTS
printf("Unhandled event %d\n", xevent.type);
printf("Unhandled event %d\n", xevent.type);
#endif
}
}
break;
}
}


/* Ack! XPending() actually performs a blocking read if no events available */
int
X11_Pending(Display * display)
Expand Down
2 changes: 1 addition & 1 deletion src/video/x11/SDL_x11mouse.c
Expand Up @@ -37,7 +37,7 @@ X11_InitMouse(_THIS)
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;

DevList=XListInputDevices(data->display, &numOfDevices);

SDL_XDevices=(XDevice**) SDL_malloc(sizeof(XDevice));
for(i=0;i<numOfDevices;++i)
{
if((DevList[i].use!=IsXPointer && DevList[i].use!=IsXKeyboard))
Expand Down
20 changes: 17 additions & 3 deletions src/video/x11/SDL_x11video.c
Expand Up @@ -34,6 +34,7 @@ XDevice **SDL_XDevices;
int SDL_NumOfXDevices;
XEventClass SDL_XEvents[256];
int SDL_NumOfXEvents;
int motion, button_pressed, button_released;

/* Initialization/Query functions */
static int X11_VideoInit(_THIS);
Expand Down Expand Up @@ -262,9 +263,17 @@ X11_VideoInit(_THIS)

/* button events */
DeviceButtonPress(SDL_XDevices[i],c_not_needed,xEvent);
if (xEvent) SDL_XEvents[index++] = xEvent;
if (xEvent)
{
SDL_XEvents[index++] = xEvent;
button_pressed=c_not_needed;
}
DeviceButtonRelease(SDL_XDevices[i],c_not_needed,xEvent);
if (xEvent) SDL_XEvents[index++] = xEvent;
if (xEvent)
{
SDL_XEvents[index++] = xEvent;
button_released=c_not_needed;
}

/* proximity events */
ProximityIn(SDL_XDevices[i],c_not_needed,xEvent);
Expand All @@ -274,7 +283,12 @@ X11_VideoInit(_THIS)

/* motion events */
DeviceMotionNotify(SDL_XDevices[i],c_not_needed,xEvent);
if (xEvent) SDL_XEvents[index++] = xEvent;
if (xEvent)
{
SDL_XEvents[index++] = xEvent;
motion=c_not_needed;
//printf("motion: %d", c_not_needed);
}

/* device state */
DeviceStateNotify(SDL_XDevices[i],c_not_needed,xEvent);
Expand Down

0 comments on commit d35dac3

Please sign in to comment.