Mercurial > sdl-ios-xcode
comparison src/video/x11/SDL_x11mouse.c @ 4661:03dcb795c583
Merged changes from the main SDL codebase
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 12 Jul 2010 21:09:23 -0700 |
parents | 3e69e077cb95 |
children | b530ef003506 |
comparison
equal
deleted
inserted
replaced
4660:b15e7017409b | 4661:03dcb795c583 |
---|---|
22 #include "SDL_config.h" | 22 #include "SDL_config.h" |
23 #include "SDL_x11video.h" | 23 #include "SDL_x11video.h" |
24 #include "SDL_x11mouse.h" | 24 #include "SDL_x11mouse.h" |
25 #include "../../events/SDL_mouse_c.h" | 25 #include "../../events/SDL_mouse_c.h" |
26 | 26 |
27 #if SDL_VIDEO_DRIVER_X11_XINPUT | |
28 static void | |
29 X11_FreeMouse(SDL_Mouse * mouse) | |
30 { | |
31 X11_MouseData *data = (X11_MouseData *) mouse->driverdata; | |
32 | |
33 if (data) { | |
34 XCloseDevice(data->display, data->device); | |
35 SDL_free(data); | |
36 } | |
37 } | |
38 #endif | |
39 | |
40 void | 27 void |
41 X11_InitMouse(_THIS) | 28 X11_InitMouse(_THIS) |
42 { | 29 { |
43 SDL_Mouse mouse; | |
44 #if SDL_VIDEO_DRIVER_X11_XINPUT | |
45 Display *display = ((SDL_VideoData *) _this->driverdata)->display; | |
46 X11_MouseData *data; | |
47 int i, j, n; | |
48 XDeviceInfo *DevList; | |
49 XAnyClassPtr deviceClass; | |
50 int event_code; | |
51 XEventClass xEvent; | |
52 #endif | |
53 int num_mice = 0; | |
54 | |
55 SDL_zero(mouse); | |
56 | |
57 #if SDL_VIDEO_DRIVER_X11_XINPUT | |
58 /* we're getting the list of input devices */ | |
59 n = 0; | |
60 if (SDL_X11_HAVE_XINPUT) { | |
61 DevList = XListInputDevices(display, &n); | |
62 } | |
63 | |
64 /* we're aquiring valuators: mice, tablets, etc. */ | |
65 for (i = 0; i < n; ++i) { | |
66 /* if it's the core pointer or core keyborard we don't want it */ | |
67 if ((DevList[i].use != IsXPointer && DevList[i].use != IsXKeyboard)) { | |
68 /* we have to check all of the device classes */ | |
69 deviceClass = DevList[i].inputclassinfo; | |
70 for (j = 0; j < DevList[i].num_classes; ++j) { | |
71 if (deviceClass->class == ValuatorClass) { /* bingo ;) */ | |
72 XValuatorInfo *valInfo; | |
73 | |
74 data = (X11_MouseData *) SDL_calloc(1, sizeof(*data)); | |
75 if (!data) { | |
76 continue; | |
77 } | |
78 data->display = display; | |
79 data->device = XOpenDevice(display, DevList[i].id); | |
80 | |
81 /* motion events */ | |
82 DeviceMotionNotify(data->device, event_code, xEvent); | |
83 if (xEvent) { | |
84 data->xevents[data->num_xevents++] = xEvent; | |
85 data->motion = event_code; | |
86 } | |
87 | |
88 /* button events */ | |
89 DeviceButtonPress(data->device, event_code, xEvent); | |
90 if (xEvent) { | |
91 data->xevents[data->num_xevents++] = xEvent; | |
92 data->button_pressed = event_code; | |
93 } | |
94 DeviceButtonRelease(data->device, event_code, xEvent); | |
95 if (xEvent) { | |
96 data->xevents[data->num_xevents++] = xEvent; | |
97 data->button_released = event_code; | |
98 } | |
99 | |
100 /* proximity events */ | |
101 ProximityIn(data->device, event_code, xEvent); | |
102 if (xEvent) { | |
103 data->xevents[data->num_xevents++] = xEvent; | |
104 data->proximity_in = event_code; | |
105 } | |
106 ProximityOut(data->device, event_code, xEvent); | |
107 if (xEvent) { | |
108 data->xevents[data->num_xevents++] = xEvent; | |
109 data->proximity_out = event_code; | |
110 } | |
111 | |
112 SDL_zero(mouse); | |
113 mouse.id = DevList[i].id; | |
114 mouse.FreeMouse = X11_FreeMouse; | |
115 mouse.driverdata = data; | |
116 | |
117 /* lets get the device parameters */ | |
118 valInfo = (XValuatorInfo *) deviceClass; | |
119 /* if the device reports pressure, lets check it parameteres */ | |
120 if (valInfo->num_axes > 2) { | |
121 SDL_AddMouse(&mouse, DevList[i].name, | |
122 valInfo->axes[2].max_value, | |
123 valInfo->axes[2].min_value, 1); | |
124 } else { | |
125 SDL_AddMouse(&mouse, DevList[i].name, 0, 0, 1); | |
126 } | |
127 #ifndef IsXExtensionPointer | |
128 #define IsXExtensionPointer 4 | |
129 #endif | |
130 if (DevList[i].use == IsXExtensionPointer) { | |
131 ++num_mice; | |
132 } | |
133 break; | |
134 } | |
135 /* if it's not class we're interested in, lets go further */ | |
136 deviceClass = | |
137 (XAnyClassPtr) ((char *) deviceClass + | |
138 deviceClass->length); | |
139 } | |
140 } | |
141 } | |
142 XFreeDeviceList(DevList); | |
143 #endif | |
144 | |
145 if (num_mice == 0) { | |
146 SDL_zero(mouse); | |
147 SDL_AddMouse(&mouse, "CorePointer", 0, 0, 1); | |
148 } | |
149 } | 30 } |
150 | 31 |
151 void | 32 void |
152 X11_QuitMouse(_THIS) | 33 X11_QuitMouse(_THIS) |
153 { | 34 { |
154 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; | |
155 | |
156 /* !!! FIXME: use XCloseDevice()? Or maybe handle under SDL_MouseQuit()? */ | |
157 | |
158 /* let's delete all of the mice */ | |
159 SDL_MouseQuit(); | |
160 } | 35 } |
161 | 36 |
162 /* vi: set ts=4 sw=4 expandtab: */ | 37 /* vi: set ts=4 sw=4 expandtab: */ |