comparison src/video/x11/SDL_x11mouse.c @ 2710:44e49d3fa6cf

Final merge of Google Summer of Code 2008 work... Many-mouse and tablet support by Szymon Wilczek, mentored by Ryan C. Gordon Everything concerning the project is noted on the wiki: http://wilku.ravenlord.ws/doku.php?id=start
author Sam Lantinga <slouken@libsdl.org>
date Mon, 25 Aug 2008 06:33:00 +0000
parents a344e42bce3b
children 6fc50bdd88c0
comparison
equal deleted inserted replaced
2709:fd3f0f1147e7 2710:44e49d3fa6cf
26 #include "../../events/SDL_mouse_c.h" 26 #include "../../events/SDL_mouse_c.h"
27 27
28 void 28 void
29 X11_InitMouse(_THIS) 29 X11_InitMouse(_THIS)
30 { 30 {
31 extern XDevice **SDL_XDevices;
32 XDevice **newDevices;
33 int i, j, index = 0, numOfDevices;
34 extern int SDL_NumOfXDevices;
35 XDeviceInfo *DevList;
36 XAnyClassPtr deviceClass;
31 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; 37 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
32 SDL_Mouse mouse;
33 38
34 SDL_zero(mouse); 39 /* we're getting the list of input devices */
35 data->mouse = SDL_AddMouse(&mouse, -1); 40 DevList = XListInputDevices(data->display, &numOfDevices);
41 SDL_XDevices = (XDevice **) SDL_malloc(sizeof(XDevice));
42
43 /* we're aquiring valuators:mices, tablets, etc. */
44 for (i = 0; i < numOfDevices; ++i) {
45 /* if it's the core pointer or core keyborard we don't want it */
46 if ((DevList[i].use != IsXPointer && DevList[i].use != IsXKeyboard)) {
47 /* we have to check all of the device classes */
48 deviceClass = DevList[i].inputclassinfo;
49 for (j = 0; j < DevList[i].num_classes; ++j) {
50 if (deviceClass->class == ValuatorClass) { /* bingo ;) */
51 XValuatorInfo *valInfo;
52 SDL_Mouse mouse;
53
54 newDevices =
55 (XDevice **) SDL_realloc(SDL_XDevices,
56 (index +
57 1) * sizeof(*newDevices));
58 if (!newDevices) {
59 SDL_OutOfMemory();
60 return;
61 }
62 SDL_XDevices = newDevices;
63 SDL_XDevices[index] =
64 XOpenDevice(data->display, DevList[i].id);
65 SDL_zero(mouse);
66
67 /* the id of the device differs from its index
68 * so we're assigning the index of a device to it's id */
69 SDL_SetMouseIndexId(DevList[i].id, index);
70 /* lets get the device parameters */
71 valInfo = (XValuatorInfo *) deviceClass;
72 /* if the device reports pressure, lets check it parameteres */
73 if (valInfo->num_axes > 2) {
74 data->mouse =
75 SDL_AddMouse(&mouse, index++, DevList[i].name,
76 valInfo->axes[2].max_value,
77 valInfo->axes[2].min_value, 1);
78 } else {
79 data->mouse =
80 SDL_AddMouse(&mouse, index++, DevList[i].name, 0,
81 0, 1);
82 }
83 break;
84 }
85 /* if it's not class we're interested in, lets go further */
86 deviceClass =
87 (XAnyClassPtr) ((char *) deviceClass +
88 deviceClass->length);
89 }
90 }
91 }
92 XFreeDeviceList(DevList);
93
94 SDL_NumOfXDevices = index;
36 } 95 }
37 96
38 void 97 void
39 X11_QuitMouse(_THIS) 98 X11_QuitMouse(_THIS)
40 { 99 {
41 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; 100 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
42 101
43 SDL_DelMouse(data->mouse); 102 /* let's delete all of the mice */
103 SDL_MouseQuit();
44 } 104 }
45 105
46 /* vi: set ts=4 sw=4 expandtab: */ 106 /* vi: set ts=4 sw=4 expandtab: */