comparison src/video/x11/SDL_x11events.c @ 2940:b93965a16fe0

Fixed X11 mouse motion/button events - it's not actually safe to cast mouse events to device events. Fixed building SDL without XInput support Simplified the process of registering a mouse device
author Sam Lantinga <slouken@libsdl.org>
date Thu, 01 Jan 2009 07:59:08 +0000
parents 99210400e8b9
children 1e431c2631ee
comparison
equal deleted inserted replaced
2939:084e5b4fc5be 2940:b93965a16fe0
26 #include <unistd.h> 26 #include <unistd.h>
27 27
28 #include "SDL_syswm.h" 28 #include "SDL_syswm.h"
29 #include "SDL_x11video.h" 29 #include "SDL_x11video.h"
30 #include "../../events/SDL_events_c.h" 30 #include "../../events/SDL_events_c.h"
31 #include "../../events/SDL_mouse_c.h"
31 32
32 static void 33 static void
33 X11_DispatchEvent(_THIS) 34 X11_DispatchEvent(_THIS)
34 { 35 {
35 SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata; 36 SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
89 if (xevent.xcrossing.mode == NotifyUngrab) 90 if (xevent.xcrossing.mode == NotifyUngrab)
90 printf("Mode: NotifyUngrab\n"); 91 printf("Mode: NotifyUngrab\n");
91 #endif 92 #endif
92 if ((xevent.xcrossing.mode != NotifyGrab) && 93 if ((xevent.xcrossing.mode != NotifyGrab) &&
93 (xevent.xcrossing.mode != NotifyUngrab)) { 94 (xevent.xcrossing.mode != NotifyUngrab)) {
94 XDeviceMotionEvent *move = (XDeviceMotionEvent *) & xevent; 95 /* FIXME: Should we reset data for all mice? */
95 SDL_SetMouseFocus(move->deviceid, data->windowID); 96 #if 0
96 SDL_SendMouseMotion(move->deviceid, 0, move->x, 97 SDL_SetMouseFocus(0, data->windowID);
97 move->y, move->axis_data[2]); 98 SDL_SendMouseMotion(0, 0, move->x, move->y, 0);
99 #endif
98 } 100 }
99 } 101 }
100 break; 102 break;
101 103
102 /* Losing mouse coverage? */ 104 /* Losing mouse coverage? */
110 printf("Mode: NotifyUngrab\n"); 112 printf("Mode: NotifyUngrab\n");
111 #endif 113 #endif
112 if ((xevent.xcrossing.mode != NotifyGrab) && 114 if ((xevent.xcrossing.mode != NotifyGrab) &&
113 (xevent.xcrossing.mode != NotifyUngrab) && 115 (xevent.xcrossing.mode != NotifyUngrab) &&
114 (xevent.xcrossing.detail != NotifyInferior)) { 116 (xevent.xcrossing.detail != NotifyInferior)) {
115 XDeviceMotionEvent *move = (XDeviceMotionEvent *) & xevent; 117 /* FIXME: Should we reset data for all mice? */
116 SDL_SetMouseFocus(move->deviceid, 0); 118 #if 0
119 SDL_SetMouseFocus(0, 0);
120 #endif
117 } 121 }
118 } 122 }
119 break; 123 break;
120 124
121 /* Gaining input focus? */ 125 /* Gaining input focus? */
274 SDL_SendWindowEvent(data->windowID, SDL_WINDOWEVENT_EXPOSED, 0, 278 SDL_SendWindowEvent(data->windowID, SDL_WINDOWEVENT_EXPOSED, 0,
275 0); 279 0);
276 } 280 }
277 break; 281 break;
278 282
283 case MotionNotify:
284 #ifdef DEBUG_MOTION
285 printf("X11 motion: %d,%d\n", xevent.xmotion.x, xevent.xmotion.y);
286 #endif
287 SDL_SendMouseMotion(0, 0, xevent.xmotion.x, xevent.xmotion.y, 0);
288 break;
289
290 case ButtonPress:
291 SDL_SendMouseButton(0, SDL_PRESSED, xevent.xbutton.button);
292 break;
293
294 case ButtonRelease:
295 SDL_SendMouseButton(0, SDL_RELEASED, xevent.xbutton.button);
296 break;
297
279 default:{ 298 default:{
280 if (xevent.type == motion) { /* MotionNotify */ 299 #if SDL_VIDEO_DRIVER_X11_XINPUT
300 for (i = 0; i < SDL_GetNumMice(); ++i) {
301 SDL_Mouse *mouse;
302 X11_MouseData *data;
303
304 mouse = SDL_GetMouse(i);
305 data = (X11_MouseData *)mouse->driverdata;
306 if (!data) {
307 continue;
308 }
309
310 if (xevent.type == data->motion) { /* MotionNotify */
281 XDeviceMotionEvent *move = (XDeviceMotionEvent *) & xevent; 311 XDeviceMotionEvent *move = (XDeviceMotionEvent *) & xevent;
282 #ifdef DEBUG_MOTION 312 #ifdef DEBUG_MOTION
283 printf("X11 motion: %d,%d\n", move->x, move->y); 313 printf("X11 motion: %d,%d\n", move->x, move->y);
284 #endif 314 #endif
285 SDL_SendMouseMotion(move->deviceid, 0, move->x, 315 SDL_SendMouseMotion(move->deviceid, 0, move->x, move->y, move->axis_data[2]);
286 move->y, move->axis_data[2]); 316 return;
287 } else if (xevent.type == button_pressed) { /* ButtonPress */ 317 }
318 if (xevent.type == data->button_pressed) { /* ButtonPress */
288 XDeviceButtonPressedEvent *pressed = 319 XDeviceButtonPressedEvent *pressed =
289 (XDeviceButtonPressedEvent *) & xevent; 320 (XDeviceButtonPressedEvent *) & xevent;
290 SDL_SendMouseButton(pressed->deviceid, SDL_PRESSED, 321 SDL_SendMouseButton(pressed->deviceid, SDL_PRESSED, pressed->button);
291 pressed->button); 322 return;
292 } else if (xevent.type == button_released) { /* ButtonRelease */ 323 }
324 if (xevent.type == data->button_released) { /* ButtonRelease */
293 XDeviceButtonReleasedEvent *released = 325 XDeviceButtonReleasedEvent *released =
294 (XDeviceButtonReleasedEvent *) & xevent; 326 (XDeviceButtonReleasedEvent *) & xevent;
295 SDL_SendMouseButton(released->deviceid, SDL_RELEASED, 327 SDL_SendMouseButton(released->deviceid, SDL_RELEASED, released->button);
296 released->button); 328 return;
297 } else if (xevent.type == proximity_in) { 329 }
330 if (xevent.type == data->proximity_in) {
298 XProximityNotifyEvent *proximity = 331 XProximityNotifyEvent *proximity =
299 (XProximityNotifyEvent *) & xevent; 332 (XProximityNotifyEvent *) & xevent;
300 SDL_SendProximity(proximity->deviceid, proximity->x, 333 SDL_SendProximity(proximity->deviceid, proximity->x, proximity->y, SDL_PROXIMITYIN);
301 proximity->y, SDL_PROXIMITYIN); 334 return;
302 } else if (xevent.type == proximity_out) { 335 }
336 if (xevent.type == data->proximity_out) {
303 XProximityNotifyEvent *proximity = 337 XProximityNotifyEvent *proximity =
304 (XProximityNotifyEvent *) & xevent; 338 (XProximityNotifyEvent *) & xevent;
305 SDL_SendProximity(proximity->deviceid, proximity->x, 339 SDL_SendProximity(proximity->deviceid, proximity->x, proximity->y, SDL_PROXIMITYOUT);
306 proximity->y, SDL_PROXIMITYOUT); 340 return;
307 } 341 }
308 #ifdef DEBUG_XEVENTS 342 }
309 else { 343 #endif
310 printf("Unhandled event %d\n", xevent.type); 344 #ifdef DEBUG_XEVENTS
311 } 345 printf("Unhandled event %d\n", xevent.type);
312 #endif 346 #endif
313 } 347 }
314 break; 348 break;
315 } 349 }
316 } 350 }