comparison src/video/x11/SDL_x11video.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 ee331407574f
comparison
equal deleted inserted replaced
2939:084e5b4fc5be 2940:b93965a16fe0
26 #include "../SDL_sysvideo.h" 26 #include "../SDL_sysvideo.h"
27 #include "../SDL_pixels_c.h" 27 #include "../SDL_pixels_c.h"
28 28
29 #include "SDL_x11video.h" 29 #include "SDL_x11video.h"
30 30
31 #if SDL_VIDEO_DRIVER_X11_XINPUT
32 XDevice **SDL_XDevices;
33 int SDL_NumOfXDevices;
34 XEventClass SDL_XEvents[256];
35 int SDL_NumOfXEvents;
36 int motion, button_pressed, button_released; /* the definitions of the mice events */
37 int proximity_in, proximity_out;
38 #endif
39 31
40 /* Initialization/Query functions */ 32 /* Initialization/Query functions */
41 static int X11_VideoInit(_THIS); 33 static int X11_VideoInit(_THIS);
42 static void X11_VideoQuit(_THIS); 34 static void X11_VideoQuit(_THIS);
43 35
216 208
217 209
218 int 210 int
219 X11_VideoInit(_THIS) 211 X11_VideoInit(_THIS)
220 { 212 {
221 int i, index = 0, event_code;
222 XEventClass xEvent;
223 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; 213 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
224 214
225 /* Get the window class name, usually the name of the application */ 215 /* Get the window class name, usually the name of the application */
226 data->classname = get_classname(); 216 data->classname = get_classname();
227 217
251 if (X11_InitKeyboard(_this) != 0) { 241 if (X11_InitKeyboard(_this) != 0) {
252 return -1; 242 return -1;
253 } 243 }
254 X11_InitMouse(_this); 244 X11_InitMouse(_this);
255 245
256 /* Set reasonable defaults, in case !SDL_VIDEO_DRIVER_X11_XINPUT */
257 motion = MotionNotify;
258 button_pressed = ButtonPress;
259 button_released = ButtonRelease;
260
261 #if SDL_VIDEO_DRIVER_X11_XINPUT
262 /* we're generating the table of events that should be recognized */
263 for (i = 0; i < SDL_NumOfXDevices; ++i) {
264 /* button events */
265 DeviceButtonPress(SDL_XDevices[i], event_code, xEvent);
266 if (xEvent) {
267 SDL_XEvents[index++] = xEvent;
268 button_pressed = event_code;
269 }
270 DeviceButtonRelease(SDL_XDevices[i], event_code, xEvent);
271 if (xEvent) {
272 SDL_XEvents[index++] = xEvent;
273 button_released = event_code;
274 }
275
276 /* proximity events */
277 ProximityIn(SDL_XDevices[i], event_code, xEvent);
278 if (xEvent) {
279 SDL_XEvents[index++] = xEvent;
280 proximity_in = event_code;
281 }
282 ProximityOut(SDL_XDevices[i], event_code, xEvent);
283 if (xEvent) {
284 SDL_XEvents[index++] = xEvent;
285 proximity_out = event_code;
286 }
287
288 /* motion events */
289 DeviceMotionNotify(SDL_XDevices[i], event_code, xEvent);
290 if (xEvent) {
291 SDL_XEvents[index++] = xEvent;
292 motion = event_code;
293 }
294
295 }
296 SDL_NumOfXEvents = index;
297 #endif
298
299 return 0; 246 return 0;
300 } 247 }
301 248
302 void 249 void
303 X11_VideoQuit(_THIS) 250 X11_VideoQuit(_THIS)
316 data->dpms_enabled); 263 data->dpms_enabled);
317 264
318 X11_QuitModes(_this); 265 X11_QuitModes(_this);
319 X11_QuitKeyboard(_this); 266 X11_QuitKeyboard(_this);
320 X11_QuitMouse(_this); 267 X11_QuitMouse(_this);
321
322 #if SDL_VIDEO_DRIVER_X11_XINPUT
323 free(SDL_XDevices);
324 #endif
325 } 268 }
326 269
327 /* vim: set ts=4 sw=4 expandtab: */ 270 /* vim: set ts=4 sw=4 expandtab: */