comparison src/video/x11/SDL_x11events.c @ 4465:3e69e077cb95

Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API. Plus, this lets me start implementing cursor support.
author Sam Lantinga <slouken@libsdl.org>
date Sun, 09 May 2010 20:47:22 -0700
parents faa9fc8e7f67
children 791b3256fb22
comparison
equal deleted inserted replaced
4464:fa77a6429698 4465:3e69e077cb95
21 */ 21 */
22 #include "SDL_config.h" 22 #include "SDL_config.h"
23 23
24 #include <sys/types.h> 24 #include <sys/types.h>
25 #include <sys/time.h> 25 #include <sys/time.h>
26 #include <signal.h>
26 #include <unistd.h> 27 #include <unistd.h>
27 28
28 #include "SDL_x11video.h" 29 #include "SDL_x11video.h"
29 #include "../../events/SDL_events_c.h" 30 #include "../../events/SDL_events_c.h"
30 #include "../../events/SDL_mouse_c.h" 31 #include "../../events/SDL_mouse_c.h"
31 32
33 #include "SDL_timer.h"
32 #include "SDL_syswm.h" 34 #include "SDL_syswm.h"
33 35
34 static void 36 static void
35 X11_DispatchEvent(_THIS) 37 X11_DispatchEvent(_THIS)
36 { 38 {
91 if (xevent.xcrossing.mode == NotifyGrab) 93 if (xevent.xcrossing.mode == NotifyGrab)
92 printf("Mode: NotifyGrab\n"); 94 printf("Mode: NotifyGrab\n");
93 if (xevent.xcrossing.mode == NotifyUngrab) 95 if (xevent.xcrossing.mode == NotifyUngrab)
94 printf("Mode: NotifyUngrab\n"); 96 printf("Mode: NotifyUngrab\n");
95 #endif 97 #endif
96 #if 1 98 SDL_SetMouseFocus(data->window);
97 /* FIXME: Should we reset data for all mice? */
98 for (i = 0; i < SDL_GetNumMice(); ++i) {
99 SDL_Mouse *mouse = SDL_GetMouse(i);
100 SDL_SetMouseFocus(mouse->id, data->window);
101 }
102 #endif
103 } 99 }
104 break; 100 break;
105 101
106 /* Losing mouse coverage? */ 102 /* Losing mouse coverage? */
107 case LeaveNotify:{ 103 case LeaveNotify:{
114 printf("Mode: NotifyGrab\n"); 110 printf("Mode: NotifyGrab\n");
115 if (xevent.xcrossing.mode == NotifyUngrab) 111 if (xevent.xcrossing.mode == NotifyUngrab)
116 printf("Mode: NotifyUngrab\n"); 112 printf("Mode: NotifyUngrab\n");
117 #endif 113 #endif
118 if (xevent.xcrossing.detail != NotifyInferior) { 114 if (xevent.xcrossing.detail != NotifyInferior) {
119 #if 1 115 SDL_SetMouseFocus(NULL);
120 /* FIXME: Should we reset data for all mice? */
121 for (i = 0; i < SDL_GetNumMice(); ++i) {
122 SDL_Mouse *mouse = SDL_GetMouse(i);
123 SDL_SetMouseFocus(mouse->id, 0);
124 }
125 #endif
126 } 116 }
127 } 117 }
128 break; 118 break;
129 119
130 /* Gaining input focus? */ 120 /* Gaining input focus? */
131 case FocusIn:{ 121 case FocusIn:{
132 #ifdef DEBUG_XEVENTS 122 #ifdef DEBUG_XEVENTS
133 printf("FocusIn!\n"); 123 printf("FocusIn!\n");
134 #endif 124 #endif
135 SDL_SetKeyboardFocus(videodata->keyboard, data->window); 125 SDL_SetKeyboardFocus(data->window);
136 #ifdef X_HAVE_UTF8_STRING 126 #ifdef X_HAVE_UTF8_STRING
137 if (data->ic) { 127 if (data->ic) {
138 XSetICFocus(data->ic); 128 XSetICFocus(data->ic);
139 } 129 }
140 #endif 130 #endif
144 /* Losing input focus? */ 134 /* Losing input focus? */
145 case FocusOut:{ 135 case FocusOut:{
146 #ifdef DEBUG_XEVENTS 136 #ifdef DEBUG_XEVENTS
147 printf("FocusOut!\n"); 137 printf("FocusOut!\n");
148 #endif 138 #endif
149 SDL_SetKeyboardFocus(videodata->keyboard, 0); 139 SDL_SetKeyboardFocus(NULL);
150 #ifdef X_HAVE_UTF8_STRING 140 #ifdef X_HAVE_UTF8_STRING
151 if (data->ic) { 141 if (data->ic) {
152 XUnsetICFocus(data->ic); 142 XUnsetICFocus(data->ic);
153 } 143 }
154 #endif 144 #endif
183 Status status = 0; 173 Status status = 0;
184 174
185 #ifdef DEBUG_XEVENTS 175 #ifdef DEBUG_XEVENTS
186 printf("KeyPress (X11 keycode = 0x%X)\n", xevent.xkey.keycode); 176 printf("KeyPress (X11 keycode = 0x%X)\n", xevent.xkey.keycode);
187 #endif 177 #endif
188 SDL_SendKeyboardKey(videodata->keyboard, SDL_PRESSED, 178 SDL_SendKeyboardKey(SDL_PRESSED, videodata->key_layout[keycode]);
189 videodata->key_layout[keycode]);
190 #if 0 179 #if 0
191 if (videodata->key_layout[keycode] == SDLK_UNKNOWN) { 180 if (videodata->key_layout[keycode] == SDLK_UNKNOWN) {
192 int min_keycode, max_keycode; 181 int min_keycode, max_keycode;
193 XDisplayKeycodes(videodata->display, &min_keycode, 182 XDisplayKeycodes(videodata->display, &min_keycode,
194 &max_keycode); 183 &max_keycode);
208 } 197 }
209 #else 198 #else
210 XLookupString(&xevent.xkey, text, sizeof(text), &keysym, NULL); 199 XLookupString(&xevent.xkey, text, sizeof(text), &keysym, NULL);
211 #endif 200 #endif
212 if (*text) { 201 if (*text) {
213 SDL_SendKeyboardText(videodata->keyboard, text); 202 SDL_SendKeyboardText(text);
214 } 203 }
215 } 204 }
216 break; 205 break;
217 206
218 /* Key release? */ 207 /* Key release? */
220 KeyCode keycode = xevent.xkey.keycode; 209 KeyCode keycode = xevent.xkey.keycode;
221 210
222 #ifdef DEBUG_XEVENTS 211 #ifdef DEBUG_XEVENTS
223 printf("KeyRelease (X11 keycode = 0x%X)\n", xevent.xkey.keycode); 212 printf("KeyRelease (X11 keycode = 0x%X)\n", xevent.xkey.keycode);
224 #endif 213 #endif
225 SDL_SendKeyboardKey(videodata->keyboard, SDL_RELEASED, 214 SDL_SendKeyboardKey(SDL_RELEASED, videodata->key_layout[keycode]);
226 videodata->key_layout[keycode]);
227 } 215 }
228 break; 216 break;
229 217
230 /* Have we been iconified? */ 218 /* Have we been iconified? */
231 case UnmapNotify:{ 219 case UnmapNotify:{
278 #endif 266 #endif
279 SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_EXPOSED, 0, 0); 267 SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_EXPOSED, 0, 0);
280 } 268 }
281 break; 269 break;
282 270
271 case MotionNotify:{
272 #ifdef DEBUG_MOTION
273 printf("X11 motion: %d,%d\n", xevent.xmotion.x, xevent.xmotion.y);
274 #endif
275 SDL_SendMouseMotion(0, xevent.xmotion.x, xevent.xmotion.y);
276 }
277 break;
278
279 case ButtonPress:{
280 SDL_SendMouseButton(SDL_PRESSED, xevent.xbutton.button);
281 }
282 break;
283
284 case ButtonRelease:{
285 SDL_SendMouseButton(SDL_RELEASED, xevent.xbutton.button);
286 }
287 break;
288
283 default:{ 289 default:{
284 for (i = 0; i < SDL_GetNumMice(); ++i) {
285 SDL_Mouse *mouse;
286 #if SDL_VIDEO_DRIVER_X11_XINPUT
287 X11_MouseData *data;
288 #endif
289
290 mouse = SDL_GetMouse(i);
291 if (!mouse->driverdata) {
292 switch (xevent.type) {
293 case MotionNotify:
294 #ifdef DEBUG_MOTION
295 printf("X11 motion: %d,%d\n", xevent.xmotion.x,
296 xevent.xmotion.y);
297 #endif
298 SDL_SendMouseMotion(mouse->id, 0, xevent.xmotion.x,
299 xevent.xmotion.y, 0);
300 break;
301
302 case ButtonPress:
303 SDL_SendMouseButton(mouse->id, SDL_PRESSED,
304 xevent.xbutton.button);
305 break;
306
307 case ButtonRelease:
308 SDL_SendMouseButton(mouse->id, SDL_RELEASED,
309 xevent.xbutton.button);
310 break;
311 }
312 continue;
313 }
314 #if SDL_VIDEO_DRIVER_X11_XINPUT
315 data = (X11_MouseData *) mouse->driverdata;
316 if (xevent.type == data->motion) {
317 XDeviceMotionEvent *move =
318 (XDeviceMotionEvent *) & xevent;
319 #ifdef DEBUG_MOTION
320 printf("X11 motion: %d,%d\n", move->x, move->y);
321 #endif
322 SDL_SendMouseMotion(move->deviceid, 0, move->x, move->y,
323 move->axis_data[2]);
324 return;
325 }
326 if (xevent.type == data->button_pressed) {
327 XDeviceButtonPressedEvent *pressed =
328 (XDeviceButtonPressedEvent *) & xevent;
329 SDL_SendMouseButton(pressed->deviceid, SDL_PRESSED,
330 pressed->button);
331 return;
332 }
333 if (xevent.type == data->button_released) {
334 XDeviceButtonReleasedEvent *released =
335 (XDeviceButtonReleasedEvent *) & xevent;
336 SDL_SendMouseButton(released->deviceid, SDL_RELEASED,
337 released->button);
338 return;
339 }
340 if (xevent.type == data->proximity_in) {
341 XProximityNotifyEvent *proximity =
342 (XProximityNotifyEvent *) & xevent;
343 SDL_SendProximity(proximity->deviceid, proximity->x,
344 proximity->y, SDL_PROXIMITYIN);
345 return;
346 }
347 if (xevent.type == data->proximity_out) {
348 XProximityNotifyEvent *proximity =
349 (XProximityNotifyEvent *) & xevent;
350 SDL_SendProximity(proximity->deviceid, proximity->x,
351 proximity->y, SDL_PROXIMITYOUT);
352 return;
353 }
354 #endif
355 }
356 #ifdef DEBUG_XEVENTS 290 #ifdef DEBUG_XEVENTS
357 printf("Unhandled event %d\n", xevent.type); 291 printf("Unhandled event %d\n", xevent.type);
358 #endif 292 #endif
359 } 293 }
360 break; 294 break;