Mercurial > sdl-ios-xcode
comparison src/video/x11/SDL_x11events.c @ 1668:4da1ee79c9af SDL-1.3
more tweaking indent options
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 29 May 2006 04:04:35 +0000 |
parents | 782fd950bd46 |
children |
comparison
equal
deleted
inserted
replaced
1667:1fddae038bc8 | 1668:4da1ee79c9af |
---|---|
53 /*#define DEBUG_XEVENTS*/ | 53 /*#define DEBUG_XEVENTS*/ |
54 | 54 |
55 /* The translation tables from an X11 keysym to a SDL keysym */ | 55 /* The translation tables from an X11 keysym to a SDL keysym */ |
56 static SDLKey ODD_keymap[256]; | 56 static SDLKey ODD_keymap[256]; |
57 static SDLKey MISC_keymap[256]; | 57 static SDLKey MISC_keymap[256]; |
58 SDLKey X11_TranslateKeycode (Display * display, KeyCode kc); | 58 SDLKey X11_TranslateKeycode(Display * display, KeyCode kc); |
59 | 59 |
60 | 60 |
61 #ifdef X_HAVE_UTF8_STRING | 61 #ifdef X_HAVE_UTF8_STRING |
62 Uint32 | 62 Uint32 |
63 Utf8ToUcs4 (const Uint8 * utf8) | 63 Utf8ToUcs4(const Uint8 * utf8) |
64 { | 64 { |
65 Uint32 c; | 65 Uint32 c; |
66 int i = 1; | 66 int i = 1; |
67 int noOctets = 0; | 67 int noOctets = 0; |
68 int firstOctetMask = 0; | 68 int firstOctetMask = 0; |
182 | 182 |
183 /* Check to see if this is a repeated key. | 183 /* Check to see if this is a repeated key. |
184 (idea shamelessly lifted from GII -- thanks guys! :) | 184 (idea shamelessly lifted from GII -- thanks guys! :) |
185 */ | 185 */ |
186 static int | 186 static int |
187 X11_KeyRepeat (Display * display, XEvent * event) | 187 X11_KeyRepeat(Display * display, XEvent * event) |
188 { | 188 { |
189 XEvent peekevent; | 189 XEvent peekevent; |
190 int repeated; | 190 int repeated; |
191 | 191 |
192 repeated = 0; | 192 repeated = 0; |
193 if (XPending (display)) { | 193 if (XPending(display)) { |
194 XPeekEvent (display, &peekevent); | 194 XPeekEvent(display, &peekevent); |
195 if ((peekevent.type == KeyPress) && | 195 if ((peekevent.type == KeyPress) && |
196 (peekevent.xkey.keycode == event->xkey.keycode) && | 196 (peekevent.xkey.keycode == event->xkey.keycode) && |
197 ((peekevent.xkey.time - event->xkey.time) < 2)) { | 197 ((peekevent.xkey.time - event->xkey.time) < 2)) { |
198 repeated = 1; | 198 repeated = 1; |
199 XNextEvent (display, &peekevent); | 199 XNextEvent(display, &peekevent); |
200 } | 200 } |
201 } | 201 } |
202 return (repeated); | 202 return (repeated); |
203 } | 203 } |
204 | 204 |
208 warping the pointer when it reaches the edge, and then wait for it. | 208 warping the pointer when it reaches the edge, and then wait for it. |
209 */ | 209 */ |
210 #define MOUSE_FUDGE_FACTOR 8 | 210 #define MOUSE_FUDGE_FACTOR 8 |
211 | 211 |
212 static __inline__ int | 212 static __inline__ int |
213 X11_WarpedMotion (_THIS, XEvent * xevent) | 213 X11_WarpedMotion(_THIS, XEvent * xevent) |
214 { | 214 { |
215 int w, h, i; | 215 int w, h, i; |
216 int deltax, deltay; | 216 int deltax, deltay; |
217 int posted; | 217 int posted; |
218 | 218 |
219 w = SDL_VideoSurface->w; | 219 w = SDL_VideoSurface->w; |
220 h = SDL_VideoSurface->h; | 220 h = SDL_VideoSurface->h; |
221 deltax = xevent->xmotion.x - mouse_last.x; | 221 deltax = xevent->xmotion.x - mouse_last.x; |
222 deltay = xevent->xmotion.y - mouse_last.y; | 222 deltay = xevent->xmotion.y - mouse_last.y; |
223 #ifdef DEBUG_MOTION | 223 #ifdef DEBUG_MOTION |
224 printf ("Warped mouse motion: %d,%d\n", deltax, deltay); | 224 printf("Warped mouse motion: %d,%d\n", deltax, deltay); |
225 #endif | 225 #endif |
226 mouse_last.x = xevent->xmotion.x; | 226 mouse_last.x = xevent->xmotion.x; |
227 mouse_last.y = xevent->xmotion.y; | 227 mouse_last.y = xevent->xmotion.y; |
228 posted = SDL_PrivateMouseMotion (0, 1, deltax, deltay); | 228 posted = SDL_PrivateMouseMotion(0, 1, deltax, deltay); |
229 | 229 |
230 if ((xevent->xmotion.x < MOUSE_FUDGE_FACTOR) || | 230 if ((xevent->xmotion.x < MOUSE_FUDGE_FACTOR) || |
231 (xevent->xmotion.x > (w - MOUSE_FUDGE_FACTOR)) || | 231 (xevent->xmotion.x > (w - MOUSE_FUDGE_FACTOR)) || |
232 (xevent->xmotion.y < MOUSE_FUDGE_FACTOR) || | 232 (xevent->xmotion.y < MOUSE_FUDGE_FACTOR) || |
233 (xevent->xmotion.y > (h - MOUSE_FUDGE_FACTOR))) { | 233 (xevent->xmotion.y > (h - MOUSE_FUDGE_FACTOR))) { |
234 /* Get the events that have accumulated */ | 234 /* Get the events that have accumulated */ |
235 while (XCheckTypedEvent (SDL_Display, MotionNotify, xevent)) { | 235 while (XCheckTypedEvent(SDL_Display, MotionNotify, xevent)) { |
236 deltax = xevent->xmotion.x - mouse_last.x; | 236 deltax = xevent->xmotion.x - mouse_last.x; |
237 deltay = xevent->xmotion.y - mouse_last.y; | 237 deltay = xevent->xmotion.y - mouse_last.y; |
238 #ifdef DEBUG_MOTION | 238 #ifdef DEBUG_MOTION |
239 printf ("Extra mouse motion: %d,%d\n", deltax, deltay); | 239 printf("Extra mouse motion: %d,%d\n", deltax, deltay); |
240 #endif | 240 #endif |
241 mouse_last.x = xevent->xmotion.x; | 241 mouse_last.x = xevent->xmotion.x; |
242 mouse_last.y = xevent->xmotion.y; | 242 mouse_last.y = xevent->xmotion.y; |
243 posted += SDL_PrivateMouseMotion (0, 1, deltax, deltay); | 243 posted += SDL_PrivateMouseMotion(0, 1, deltax, deltay); |
244 } | 244 } |
245 mouse_last.x = w / 2; | 245 mouse_last.x = w / 2; |
246 mouse_last.y = h / 2; | 246 mouse_last.y = h / 2; |
247 XWarpPointer (SDL_Display, None, SDL_Window, 0, 0, 0, 0, | 247 XWarpPointer(SDL_Display, None, SDL_Window, 0, 0, 0, 0, |
248 mouse_last.x, mouse_last.y); | 248 mouse_last.x, mouse_last.y); |
249 for (i = 0; i < 10; ++i) { | 249 for (i = 0; i < 10; ++i) { |
250 XMaskEvent (SDL_Display, PointerMotionMask, xevent); | 250 XMaskEvent(SDL_Display, PointerMotionMask, xevent); |
251 if ((xevent->xmotion.x > | 251 if ((xevent->xmotion.x > |
252 (mouse_last.x - MOUSE_FUDGE_FACTOR)) && | 252 (mouse_last.x - MOUSE_FUDGE_FACTOR)) && |
253 (xevent->xmotion.x < | 253 (xevent->xmotion.x < |
254 (mouse_last.x + MOUSE_FUDGE_FACTOR)) && | 254 (mouse_last.x + MOUSE_FUDGE_FACTOR)) && |
255 (xevent->xmotion.y > | 255 (xevent->xmotion.y > |
256 (mouse_last.y - MOUSE_FUDGE_FACTOR)) && | 256 (mouse_last.y - MOUSE_FUDGE_FACTOR)) && |
257 (xevent->xmotion.y < (mouse_last.y + MOUSE_FUDGE_FACTOR))) { | 257 (xevent->xmotion.y < (mouse_last.y + MOUSE_FUDGE_FACTOR))) { |
258 break; | 258 break; |
259 } | 259 } |
260 #ifdef DEBUG_XEVENTS | 260 #ifdef DEBUG_XEVENTS |
261 printf ("Lost mouse motion: %d,%d\n", xevent->xmotion.x, | 261 printf("Lost mouse motion: %d,%d\n", xevent->xmotion.x, |
262 xevent->xmotion.y); | 262 xevent->xmotion.y); |
263 #endif | 263 #endif |
264 } | 264 } |
265 #ifdef DEBUG_XEVENTS | 265 #ifdef DEBUG_XEVENTS |
266 if (i == 10) { | 266 if (i == 10) { |
267 printf ("Warning: didn't detect mouse warp motion\n"); | 267 printf("Warning: didn't detect mouse warp motion\n"); |
268 } | 268 } |
269 #endif | 269 #endif |
270 } | 270 } |
271 return (posted); | 271 return (posted); |
272 } | 272 } |
273 | 273 |
274 static int | 274 static int |
275 X11_DispatchEvent (_THIS) | 275 X11_DispatchEvent(_THIS) |
276 { | 276 { |
277 int posted; | 277 int posted; |
278 XEvent xevent; | 278 XEvent xevent; |
279 | 279 |
280 SDL_memset (&xevent, '\0', sizeof (XEvent)); /* valgrind fix. --ryan. */ | 280 SDL_memset(&xevent, '\0', sizeof(XEvent)); /* valgrind fix. --ryan. */ |
281 XNextEvent (SDL_Display, &xevent); | 281 XNextEvent(SDL_Display, &xevent); |
282 | 282 |
283 posted = 0; | 283 posted = 0; |
284 switch (xevent.type) { | 284 switch (xevent.type) { |
285 | 285 |
286 /* Gaining mouse coverage? */ | 286 /* Gaining mouse coverage? */ |
287 case EnterNotify: | 287 case EnterNotify: |
288 { | 288 { |
289 #ifdef DEBUG_XEVENTS | 289 #ifdef DEBUG_XEVENTS |
290 printf ("EnterNotify! (%d,%d)\n", xevent.xcrossing.x, | 290 printf("EnterNotify! (%d,%d)\n", xevent.xcrossing.x, |
291 xevent.xcrossing.y); | 291 xevent.xcrossing.y); |
292 if (xevent.xcrossing.mode == NotifyGrab) | 292 if (xevent.xcrossing.mode == NotifyGrab) |
293 printf ("Mode: NotifyGrab\n"); | 293 printf("Mode: NotifyGrab\n"); |
294 if (xevent.xcrossing.mode == NotifyUngrab) | 294 if (xevent.xcrossing.mode == NotifyUngrab) |
295 printf ("Mode: NotifyUngrab\n"); | 295 printf("Mode: NotifyUngrab\n"); |
296 #endif | 296 #endif |
297 if ((xevent.xcrossing.mode != NotifyGrab) && | 297 if ((xevent.xcrossing.mode != NotifyGrab) && |
298 (xevent.xcrossing.mode != NotifyUngrab)) { | 298 (xevent.xcrossing.mode != NotifyUngrab)) { |
299 if (SDL_CurrentWindow.input_grab == SDL_GRAB_OFF) { | 299 if (SDL_CurrentWindow.input_grab == SDL_GRAB_OFF) { |
300 posted = SDL_PrivateAppActive (1, SDL_APPMOUSEFOCUS); | 300 posted = SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS); |
301 } | 301 } |
302 posted = SDL_PrivateMouseMotion (0, 0, | 302 posted = SDL_PrivateMouseMotion(0, 0, |
303 xevent.xcrossing.x, | 303 xevent.xcrossing.x, |
304 xevent.xcrossing.y); | 304 xevent.xcrossing.y); |
305 } | 305 } |
306 } | 306 } |
307 break; | 307 break; |
308 | 308 |
309 /* Losing mouse coverage? */ | 309 /* Losing mouse coverage? */ |
310 case LeaveNotify: | 310 case LeaveNotify: |
311 { | 311 { |
312 #ifdef DEBUG_XEVENTS | 312 #ifdef DEBUG_XEVENTS |
313 printf ("LeaveNotify! (%d,%d)\n", xevent.xcrossing.x, | 313 printf("LeaveNotify! (%d,%d)\n", xevent.xcrossing.x, |
314 xevent.xcrossing.y); | 314 xevent.xcrossing.y); |
315 if (xevent.xcrossing.mode == NotifyGrab) | 315 if (xevent.xcrossing.mode == NotifyGrab) |
316 printf ("Mode: NotifyGrab\n"); | 316 printf("Mode: NotifyGrab\n"); |
317 if (xevent.xcrossing.mode == NotifyUngrab) | 317 if (xevent.xcrossing.mode == NotifyUngrab) |
318 printf ("Mode: NotifyUngrab\n"); | 318 printf("Mode: NotifyUngrab\n"); |
319 #endif | 319 #endif |
320 if ((xevent.xcrossing.mode != NotifyGrab) && | 320 if ((xevent.xcrossing.mode != NotifyGrab) && |
321 (xevent.xcrossing.mode != NotifyUngrab) && | 321 (xevent.xcrossing.mode != NotifyUngrab) && |
322 (xevent.xcrossing.detail != NotifyInferior)) { | 322 (xevent.xcrossing.detail != NotifyInferior)) { |
323 if (SDL_CurrentWindow.input_grab == SDL_GRAB_OFF) { | 323 if (SDL_CurrentWindow.input_grab == SDL_GRAB_OFF) { |
324 posted = SDL_PrivateAppActive (0, SDL_APPMOUSEFOCUS); | 324 posted = SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS); |
325 } else { | 325 } else { |
326 posted = SDL_PrivateMouseMotion (0, 0, | 326 posted = SDL_PrivateMouseMotion(0, 0, |
327 xevent.xcrossing.x, | 327 xevent.xcrossing.x, |
328 xevent.xcrossing.y); | 328 xevent.xcrossing.y); |
329 } | 329 } |
330 } | 330 } |
331 } | 331 } |
332 break; | 332 break; |
333 | 333 |
334 /* Gaining input focus? */ | 334 /* Gaining input focus? */ |
335 case FocusIn: | 335 case FocusIn: |
336 { | 336 { |
337 #ifdef DEBUG_XEVENTS | 337 #ifdef DEBUG_XEVENTS |
338 printf ("FocusIn!\n"); | 338 printf("FocusIn!\n"); |
339 #endif | 339 #endif |
340 posted = SDL_PrivateAppActive (1, SDL_APPINPUTFOCUS); | 340 posted = SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS); |
341 | 341 |
342 #ifdef X_HAVE_UTF8_STRING | 342 #ifdef X_HAVE_UTF8_STRING |
343 if (SDL_IC != NULL) { | 343 if (SDL_IC != NULL) { |
344 XSetICFocus (SDL_IC); | 344 XSetICFocus(SDL_IC); |
345 } | 345 } |
346 #endif | 346 #endif |
347 /* Queue entry into fullscreen mode */ | 347 /* Queue entry into fullscreen mode */ |
348 switch_waiting = 0x01 | SDL_FULLSCREEN; | 348 switch_waiting = 0x01 | SDL_FULLSCREEN; |
349 switch_time = SDL_GetTicks () + 1500; | 349 switch_time = SDL_GetTicks() + 1500; |
350 } | 350 } |
351 break; | 351 break; |
352 | 352 |
353 /* Losing input focus? */ | 353 /* Losing input focus? */ |
354 case FocusOut: | 354 case FocusOut: |
355 { | 355 { |
356 #ifdef DEBUG_XEVENTS | 356 #ifdef DEBUG_XEVENTS |
357 printf ("FocusOut!\n"); | 357 printf("FocusOut!\n"); |
358 #endif | 358 #endif |
359 posted = SDL_PrivateAppActive (0, SDL_APPINPUTFOCUS); | 359 posted = SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS); |
360 | 360 |
361 #ifdef X_HAVE_UTF8_STRING | 361 #ifdef X_HAVE_UTF8_STRING |
362 if (SDL_IC != NULL) { | 362 if (SDL_IC != NULL) { |
363 XUnsetICFocus (SDL_IC); | 363 XUnsetICFocus(SDL_IC); |
364 } | 364 } |
365 #endif | 365 #endif |
366 /* Queue leaving fullscreen mode */ | 366 /* Queue leaving fullscreen mode */ |
367 switch_waiting = 0x01; | 367 switch_waiting = 0x01; |
368 switch_time = SDL_GetTicks () + 200; | 368 switch_time = SDL_GetTicks() + 200; |
369 } | 369 } |
370 break; | 370 break; |
371 | 371 |
372 /* Generated upon EnterWindow and FocusIn */ | 372 /* Generated upon EnterWindow and FocusIn */ |
373 case KeymapNotify: | 373 case KeymapNotify: |
374 { | 374 { |
375 #ifdef DEBUG_XEVENTS | 375 #ifdef DEBUG_XEVENTS |
376 printf ("KeymapNotify!\n"); | 376 printf("KeymapNotify!\n"); |
377 #endif | 377 #endif |
378 X11_SetKeyboardState (SDL_Display, xevent.xkeymap.key_vector); | 378 X11_SetKeyboardState(SDL_Display, xevent.xkeymap.key_vector); |
379 } | 379 } |
380 break; | 380 break; |
381 | 381 |
382 /* Mouse motion? */ | 382 /* Mouse motion? */ |
383 case MotionNotify: | 383 case MotionNotify: |
384 { | 384 { |
385 if (SDL_VideoSurface) { | 385 if (SDL_VideoSurface) { |
386 if (mouse_relative) { | 386 if (mouse_relative) { |
387 if (using_dga & DGA_MOUSE) { | 387 if (using_dga & DGA_MOUSE) { |
388 #ifdef DEBUG_MOTION | 388 #ifdef DEBUG_MOTION |
389 printf ("DGA motion: %d,%d\n", | 389 printf("DGA motion: %d,%d\n", |
390 xevent.xmotion.x_root, xevent.xmotion.y_root); | 390 xevent.xmotion.x_root, xevent.xmotion.y_root); |
391 #endif | 391 #endif |
392 posted = SDL_PrivateMouseMotion (0, 1, | 392 posted = SDL_PrivateMouseMotion(0, 1, |
393 xevent. | 393 xevent. |
394 xmotion. | 394 xmotion. |
395 x_root, | 395 x_root, |
396 xevent. | 396 xevent. |
397 xmotion.y_root); | 397 xmotion.y_root); |
398 } else { | 398 } else { |
399 posted = X11_WarpedMotion (_this, &xevent); | 399 posted = X11_WarpedMotion(_this, &xevent); |
400 } | 400 } |
401 } else { | 401 } else { |
402 #ifdef DEBUG_MOTION | 402 #ifdef DEBUG_MOTION |
403 printf ("X11 motion: %d,%d\n", xevent.xmotion.x, | 403 printf("X11 motion: %d,%d\n", xevent.xmotion.x, |
404 xevent.xmotion.y); | 404 xevent.xmotion.y); |
405 #endif | 405 #endif |
406 posted = SDL_PrivateMouseMotion (0, 0, | 406 posted = SDL_PrivateMouseMotion(0, 0, |
407 xevent.xmotion.x, | 407 xevent.xmotion.x, |
408 xevent.xmotion.y); | 408 xevent.xmotion.y); |
409 } | 409 } |
410 } | 410 } |
411 } | 411 } |
412 break; | 412 break; |
413 | 413 |
414 /* Mouse button press? */ | 414 /* Mouse button press? */ |
415 case ButtonPress: | 415 case ButtonPress: |
416 { | 416 { |
417 posted = SDL_PrivateMouseButton (SDL_PRESSED, | 417 posted = SDL_PrivateMouseButton(SDL_PRESSED, |
418 xevent.xbutton.button, 0, 0); | 418 xevent.xbutton.button, 0, 0); |
419 } | 419 } |
420 break; | 420 break; |
421 | 421 |
422 /* Mouse button release? */ | 422 /* Mouse button release? */ |
423 case ButtonRelease: | 423 case ButtonRelease: |
424 { | 424 { |
425 posted = SDL_PrivateMouseButton (SDL_RELEASED, | 425 posted = SDL_PrivateMouseButton(SDL_RELEASED, |
426 xevent.xbutton.button, 0, 0); | 426 xevent.xbutton.button, 0, 0); |
427 } | 427 } |
428 break; | 428 break; |
429 | 429 |
430 /* Key press? */ | 430 /* Key press? */ |
431 case KeyPress: | 431 case KeyPress: |
433 static SDL_keysym saved_keysym; | 433 static SDL_keysym saved_keysym; |
434 SDL_keysym keysym; | 434 SDL_keysym keysym; |
435 KeyCode keycode = xevent.xkey.keycode; | 435 KeyCode keycode = xevent.xkey.keycode; |
436 | 436 |
437 #ifdef DEBUG_XEVENTS | 437 #ifdef DEBUG_XEVENTS |
438 printf ("KeyPress (X11 keycode = 0x%X)\n", xevent.xkey.keycode); | 438 printf("KeyPress (X11 keycode = 0x%X)\n", xevent.xkey.keycode); |
439 #endif | 439 #endif |
440 /* Get the translated SDL virtual keysym */ | 440 /* Get the translated SDL virtual keysym */ |
441 if (keycode) { | 441 if (keycode) { |
442 keysym.scancode = keycode; | 442 keysym.scancode = keycode; |
443 keysym.sym = X11_TranslateKeycode (SDL_Display, keycode); | 443 keysym.sym = X11_TranslateKeycode(SDL_Display, keycode); |
444 keysym.mod = KMOD_NONE; | 444 keysym.mod = KMOD_NONE; |
445 keysym.unicode = 0; | 445 keysym.unicode = 0; |
446 } else { | 446 } else { |
447 keysym = saved_keysym; | 447 keysym = saved_keysym; |
448 } | 448 } |
449 | 449 |
450 /* If we're not doing translation, we're done! */ | 450 /* If we're not doing translation, we're done! */ |
451 if (!SDL_TranslateUNICODE) { | 451 if (!SDL_TranslateUNICODE) { |
452 posted = SDL_PrivateKeyboard (SDL_PRESSED, &keysym); | 452 posted = SDL_PrivateKeyboard(SDL_PRESSED, &keysym); |
453 break; | 453 break; |
454 } | 454 } |
455 | 455 |
456 if (XFilterEvent (&xevent, None)) { | 456 if (XFilterEvent(&xevent, None)) { |
457 if (xevent.xkey.keycode) { | 457 if (xevent.xkey.keycode) { |
458 posted = SDL_PrivateKeyboard (SDL_PRESSED, &keysym); | 458 posted = SDL_PrivateKeyboard(SDL_PRESSED, &keysym); |
459 } else { | 459 } else { |
460 /* Save event to be associated with IM text | 460 /* Save event to be associated with IM text |
461 In 1.3 we'll have a text event instead.. */ | 461 In 1.3 we'll have a text event instead.. */ |
462 saved_keysym = keysym; | 462 saved_keysym = keysym; |
463 } | 463 } |
468 #ifdef X_HAVE_UTF8_STRING | 468 #ifdef X_HAVE_UTF8_STRING |
469 if (SDL_IC != NULL) { | 469 if (SDL_IC != NULL) { |
470 static Status state; | 470 static Status state; |
471 /* A UTF-8 character can be at most 6 bytes */ | 471 /* A UTF-8 character can be at most 6 bytes */ |
472 char keybuf[6]; | 472 char keybuf[6]; |
473 if (Xutf8LookupString (SDL_IC, &xevent.xkey, | 473 if (Xutf8LookupString(SDL_IC, &xevent.xkey, |
474 keybuf, sizeof (keybuf), | 474 keybuf, sizeof(keybuf), NULL, &state)) { |
475 NULL, &state)) { | 475 keysym.unicode = Utf8ToUcs4((Uint8 *) keybuf); |
476 keysym.unicode = Utf8ToUcs4 ((Uint8 *) keybuf); | |
477 } | 476 } |
478 } else | 477 } else |
479 #endif | 478 #endif |
480 { | 479 { |
481 static XComposeStatus state; | 480 static XComposeStatus state; |
482 char keybuf[32]; | 481 char keybuf[32]; |
483 | 482 |
484 if (XLookupString (&xevent.xkey, | 483 if (XLookupString(&xevent.xkey, |
485 keybuf, sizeof (keybuf), NULL, &state)) { | 484 keybuf, sizeof(keybuf), NULL, &state)) { |
486 /* | 485 /* |
487 * FIXME: XLookupString() may yield more than one | 486 * FIXME: XLookupString() may yield more than one |
488 * character, so we need a mechanism to allow for | 487 * character, so we need a mechanism to allow for |
489 * this (perhaps null keypress events with a | 488 * this (perhaps null keypress events with a |
490 * unicode value) | 489 * unicode value) |
491 */ | 490 */ |
492 keysym.unicode = (Uint8) keybuf[0]; | 491 keysym.unicode = (Uint8) keybuf[0]; |
493 } | 492 } |
494 } | 493 } |
495 posted = SDL_PrivateKeyboard (SDL_PRESSED, &keysym); | 494 posted = SDL_PrivateKeyboard(SDL_PRESSED, &keysym); |
496 } | 495 } |
497 break; | 496 break; |
498 | 497 |
499 /* Key release? */ | 498 /* Key release? */ |
500 case KeyRelease: | 499 case KeyRelease: |
501 { | 500 { |
502 SDL_keysym keysym; | 501 SDL_keysym keysym; |
503 KeyCode keycode = xevent.xkey.keycode; | 502 KeyCode keycode = xevent.xkey.keycode; |
504 | 503 |
505 #ifdef DEBUG_XEVENTS | 504 #ifdef DEBUG_XEVENTS |
506 printf ("KeyRelease (X11 keycode = 0x%X)\n", xevent.xkey.keycode); | 505 printf("KeyRelease (X11 keycode = 0x%X)\n", xevent.xkey.keycode); |
507 #endif | 506 #endif |
508 /* Check to see if this is a repeated key */ | 507 /* Check to see if this is a repeated key */ |
509 if (X11_KeyRepeat (SDL_Display, &xevent)) { | 508 if (X11_KeyRepeat(SDL_Display, &xevent)) { |
510 break; | 509 break; |
511 } | 510 } |
512 | 511 |
513 /* Get the translated SDL virtual keysym */ | 512 /* Get the translated SDL virtual keysym */ |
514 keysym.scancode = keycode; | 513 keysym.scancode = keycode; |
515 keysym.sym = X11_TranslateKeycode (SDL_Display, keycode); | 514 keysym.sym = X11_TranslateKeycode(SDL_Display, keycode); |
516 keysym.mod = KMOD_NONE; | 515 keysym.mod = KMOD_NONE; |
517 keysym.unicode = 0; | 516 keysym.unicode = 0; |
518 | 517 |
519 posted = SDL_PrivateKeyboard (SDL_RELEASED, &keysym); | 518 posted = SDL_PrivateKeyboard(SDL_RELEASED, &keysym); |
520 } | 519 } |
521 break; | 520 break; |
522 | 521 |
523 /* Have we been iconified? */ | 522 /* Have we been iconified? */ |
524 case UnmapNotify: | 523 case UnmapNotify: |
525 { | 524 { |
526 #ifdef DEBUG_XEVENTS | 525 #ifdef DEBUG_XEVENTS |
527 printf ("UnmapNotify!\n"); | 526 printf("UnmapNotify!\n"); |
528 #endif | 527 #endif |
529 /* If we're active, make ourselves inactive */ | 528 /* If we're active, make ourselves inactive */ |
530 if (SDL_GetAppState () & SDL_APPACTIVE) { | 529 if (SDL_GetAppState() & SDL_APPACTIVE) { |
531 /* Swap out the gamma before we go inactive */ | 530 /* Swap out the gamma before we go inactive */ |
532 X11_SwapVidModeGamma (_this); | 531 X11_SwapVidModeGamma(_this); |
533 | 532 |
534 /* Send an internal deactivate event */ | 533 /* Send an internal deactivate event */ |
535 posted = SDL_PrivateAppActive (0, | 534 posted = SDL_PrivateAppActive(0, |
536 SDL_APPACTIVE | | 535 SDL_APPACTIVE | |
537 SDL_APPINPUTFOCUS); | 536 SDL_APPINPUTFOCUS); |
538 } | 537 } |
539 } | 538 } |
540 break; | 539 break; |
541 | 540 |
542 /* Have we been restored? */ | 541 /* Have we been restored? */ |
543 case MapNotify: | 542 case MapNotify: |
544 { | 543 { |
545 #ifdef DEBUG_XEVENTS | 544 #ifdef DEBUG_XEVENTS |
546 printf ("MapNotify!\n"); | 545 printf("MapNotify!\n"); |
547 #endif | 546 #endif |
548 /* If we're not active, make ourselves active */ | 547 /* If we're not active, make ourselves active */ |
549 if (!(SDL_GetAppState () & SDL_APPACTIVE)) { | 548 if (!(SDL_GetAppState() & SDL_APPACTIVE)) { |
550 /* Send an internal activate event */ | 549 /* Send an internal activate event */ |
551 posted = SDL_PrivateAppActive (1, SDL_APPACTIVE); | 550 posted = SDL_PrivateAppActive(1, SDL_APPACTIVE); |
552 | 551 |
553 /* Now that we're active, swap the gamma back */ | 552 /* Now that we're active, swap the gamma back */ |
554 X11_SwapVidModeGamma (_this); | 553 X11_SwapVidModeGamma(_this); |
555 } | 554 } |
556 | 555 |
557 if (SDL_VideoSurface && | 556 if (SDL_VideoSurface && |
558 (SDL_VideoSurface->flags & SDL_FULLSCREEN)) { | 557 (SDL_VideoSurface->flags & SDL_FULLSCREEN)) { |
559 X11_EnterFullScreen (_this); | 558 X11_EnterFullScreen(_this); |
560 } else { | 559 } else { |
561 X11_GrabInputNoLock (_this, SDL_CurrentWindow.input_grab); | 560 X11_GrabInputNoLock(_this, SDL_CurrentWindow.input_grab); |
562 } | 561 } |
563 X11_CheckMouseModeNoLock (_this); | 562 X11_CheckMouseModeNoLock(_this); |
564 | 563 |
565 if (SDL_VideoSurface) { | 564 if (SDL_VideoSurface) { |
566 X11_RefreshDisplay (_this); | 565 X11_RefreshDisplay(_this); |
567 } | 566 } |
568 } | 567 } |
569 break; | 568 break; |
570 | 569 |
571 /* Have we been resized or moved? */ | 570 /* Have we been resized or moved? */ |
572 case ConfigureNotify: | 571 case ConfigureNotify: |
573 { | 572 { |
574 #ifdef DEBUG_XEVENTS | 573 #ifdef DEBUG_XEVENTS |
575 printf ("ConfigureNotify! (resize: %dx%d)\n", | 574 printf("ConfigureNotify! (resize: %dx%d)\n", |
576 xevent.xconfigure.width, xevent.xconfigure.height); | 575 xevent.xconfigure.width, xevent.xconfigure.height); |
577 #endif | 576 #endif |
578 if (SDL_VideoSurface) { | 577 if (SDL_VideoSurface) { |
579 if ((xevent.xconfigure.width != SDL_VideoSurface->w) || | 578 if ((xevent.xconfigure.width != SDL_VideoSurface->w) || |
580 (xevent.xconfigure.height != SDL_VideoSurface->h)) { | 579 (xevent.xconfigure.height != SDL_VideoSurface->h)) { |
581 /* FIXME: Find a better fix for the bug with KDE 1.2 */ | 580 /* FIXME: Find a better fix for the bug with KDE 1.2 */ |
582 if (!((xevent.xconfigure.width == 32) && | 581 if (!((xevent.xconfigure.width == 32) && |
583 (xevent.xconfigure.height == 32))) { | 582 (xevent.xconfigure.height == 32))) { |
584 SDL_PrivateResize (xevent.xconfigure.width, | 583 SDL_PrivateResize(xevent.xconfigure.width, |
585 xevent.xconfigure.height); | 584 xevent.xconfigure.height); |
586 } | 585 } |
587 } else { | 586 } else { |
588 /* OpenGL windows need to know about the change */ | 587 /* OpenGL windows need to know about the change */ |
589 if (SDL_VideoSurface->flags & SDL_INTERNALOPENGL) { | 588 if (SDL_VideoSurface->flags & SDL_INTERNALOPENGL) { |
590 SDL_PrivateExpose (); | 589 SDL_PrivateExpose(); |
591 } | 590 } |
592 } | 591 } |
593 } | 592 } |
594 } | 593 } |
595 break; | 594 break; |
597 /* Have we been requested to quit (or another client message?) */ | 596 /* Have we been requested to quit (or another client message?) */ |
598 case ClientMessage: | 597 case ClientMessage: |
599 { | 598 { |
600 if ((xevent.xclient.format == 32) && | 599 if ((xevent.xclient.format == 32) && |
601 (xevent.xclient.data.l[0] == WM_DELETE_WINDOW)) { | 600 (xevent.xclient.data.l[0] == WM_DELETE_WINDOW)) { |
602 posted = SDL_PrivateQuit (); | 601 posted = SDL_PrivateQuit(); |
603 } else if (SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE) { | 602 } else if (SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE) { |
604 SDL_SysWMmsg wmmsg; | 603 SDL_SysWMmsg wmmsg; |
605 | 604 |
606 SDL_VERSION (&wmmsg.version); | 605 SDL_VERSION(&wmmsg.version); |
607 wmmsg.subsystem = SDL_SYSWM_X11; | 606 wmmsg.subsystem = SDL_SYSWM_X11; |
608 wmmsg.event.xevent = xevent; | 607 wmmsg.event.xevent = xevent; |
609 posted = SDL_PrivateSysWMEvent (&wmmsg); | 608 posted = SDL_PrivateSysWMEvent(&wmmsg); |
610 } | 609 } |
611 } | 610 } |
612 break; | 611 break; |
613 | 612 |
614 /* Do we need to refresh ourselves? */ | 613 /* Do we need to refresh ourselves? */ |
615 case Expose: | 614 case Expose: |
616 { | 615 { |
617 #ifdef DEBUG_XEVENTS | 616 #ifdef DEBUG_XEVENTS |
618 printf ("Expose (count = %d)\n", xevent.xexpose.count); | 617 printf("Expose (count = %d)\n", xevent.xexpose.count); |
619 #endif | 618 #endif |
620 if (SDL_VideoSurface && (xevent.xexpose.count == 0)) { | 619 if (SDL_VideoSurface && (xevent.xexpose.count == 0)) { |
621 X11_RefreshDisplay (_this); | 620 X11_RefreshDisplay(_this); |
622 } | 621 } |
623 } | 622 } |
624 break; | 623 break; |
625 | 624 |
626 default: | 625 default: |
627 { | 626 { |
628 #ifdef DEBUG_XEVENTS | 627 #ifdef DEBUG_XEVENTS |
629 printf ("Unhandled event %d\n", xevent.type); | 628 printf("Unhandled event %d\n", xevent.type); |
630 #endif | 629 #endif |
631 /* Only post the event if we're watching for it */ | 630 /* Only post the event if we're watching for it */ |
632 if (SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE) { | 631 if (SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE) { |
633 SDL_SysWMmsg wmmsg; | 632 SDL_SysWMmsg wmmsg; |
634 | 633 |
635 SDL_VERSION (&wmmsg.version); | 634 SDL_VERSION(&wmmsg.version); |
636 wmmsg.subsystem = SDL_SYSWM_X11; | 635 wmmsg.subsystem = SDL_SYSWM_X11; |
637 wmmsg.event.xevent = xevent; | 636 wmmsg.event.xevent = xevent; |
638 posted = SDL_PrivateSysWMEvent (&wmmsg); | 637 posted = SDL_PrivateSysWMEvent(&wmmsg); |
639 } | 638 } |
640 } | 639 } |
641 break; | 640 break; |
642 } | 641 } |
643 return (posted); | 642 return (posted); |
644 } | 643 } |
645 | 644 |
646 /* Ack! XPending() actually performs a blocking read if no events available */ | 645 /* Ack! XPending() actually performs a blocking read if no events available */ |
647 int | 646 int |
648 X11_Pending (Display * display) | 647 X11_Pending(Display * display) |
649 { | 648 { |
650 /* Flush the display connection and look to see if events are queued */ | 649 /* Flush the display connection and look to see if events are queued */ |
651 XFlush (display); | 650 XFlush(display); |
652 if (XEventsQueued (display, QueuedAlready)) { | 651 if (XEventsQueued(display, QueuedAlready)) { |
653 return (1); | 652 return (1); |
654 } | 653 } |
655 | 654 |
656 /* More drastic measures are required -- see if X is ready to talk */ | 655 /* More drastic measures are required -- see if X is ready to talk */ |
657 { | 656 { |
658 static struct timeval zero_time; /* static == 0 */ | 657 static struct timeval zero_time; /* static == 0 */ |
659 int x11_fd; | 658 int x11_fd; |
660 fd_set fdset; | 659 fd_set fdset; |
661 | 660 |
662 x11_fd = ConnectionNumber (display); | 661 x11_fd = ConnectionNumber(display); |
663 FD_ZERO (&fdset); | 662 FD_ZERO(&fdset); |
664 FD_SET (x11_fd, &fdset); | 663 FD_SET(x11_fd, &fdset); |
665 if (select (x11_fd + 1, &fdset, NULL, NULL, &zero_time) == 1) { | 664 if (select(x11_fd + 1, &fdset, NULL, NULL, &zero_time) == 1) { |
666 return (XPending (display)); | 665 return (XPending(display)); |
667 } | 666 } |
668 } | 667 } |
669 | 668 |
670 /* Oh well, nothing is ready .. */ | 669 /* Oh well, nothing is ready .. */ |
671 return (0); | 670 return (0); |
672 } | 671 } |
673 | 672 |
674 void | 673 void |
675 X11_PumpEvents (_THIS) | 674 X11_PumpEvents(_THIS) |
676 { | 675 { |
677 int pending; | 676 int pending; |
678 | 677 |
679 /* Keep processing pending events */ | 678 /* Keep processing pending events */ |
680 pending = 0; | 679 pending = 0; |
681 while (X11_Pending (SDL_Display)) { | 680 while (X11_Pending(SDL_Display)) { |
682 X11_DispatchEvent (_this); | 681 X11_DispatchEvent(_this); |
683 ++pending; | 682 ++pending; |
684 } | 683 } |
685 if (switch_waiting) { | 684 if (switch_waiting) { |
686 Uint32 now; | 685 Uint32 now; |
687 | 686 |
688 now = SDL_GetTicks (); | 687 now = SDL_GetTicks(); |
689 if (pending || !SDL_VideoSurface) { | 688 if (pending || !SDL_VideoSurface) { |
690 /* Try again later... */ | 689 /* Try again later... */ |
691 if (switch_waiting & SDL_FULLSCREEN) { | 690 if (switch_waiting & SDL_FULLSCREEN) { |
692 switch_time = now + 1500; | 691 switch_time = now + 1500; |
693 } else { | 692 } else { |
698 | 697 |
699 go_fullscreen = switch_waiting & SDL_FULLSCREEN; | 698 go_fullscreen = switch_waiting & SDL_FULLSCREEN; |
700 switch_waiting = 0; | 699 switch_waiting = 0; |
701 if (SDL_VideoSurface->flags & SDL_FULLSCREEN) { | 700 if (SDL_VideoSurface->flags & SDL_FULLSCREEN) { |
702 if (go_fullscreen) { | 701 if (go_fullscreen) { |
703 X11_EnterFullScreen (_this); | 702 X11_EnterFullScreen(_this); |
704 } else { | 703 } else { |
705 X11_LeaveFullScreen (_this); | 704 X11_LeaveFullScreen(_this); |
706 } | 705 } |
707 } | 706 } |
708 /* Handle focus in/out when grabbed */ | 707 /* Handle focus in/out when grabbed */ |
709 if (go_fullscreen) { | 708 if (go_fullscreen) { |
710 X11_GrabInputNoLock (_this, SDL_CurrentWindow.input_grab); | 709 X11_GrabInputNoLock(_this, SDL_CurrentWindow.input_grab); |
711 } else { | 710 } else { |
712 X11_GrabInputNoLock (_this, SDL_GRAB_OFF); | 711 X11_GrabInputNoLock(_this, SDL_GRAB_OFF); |
713 } | 712 } |
714 X11_CheckMouseModeNoLock (_this); | 713 X11_CheckMouseModeNoLock(_this); |
715 } | 714 } |
716 } | 715 } |
717 } | 716 } |
718 | 717 |
719 void | 718 void |
720 X11_InitKeymap (void) | 719 X11_InitKeymap(void) |
721 { | 720 { |
722 int i; | 721 int i; |
723 | 722 |
724 /* Odd keys used in international keyboards */ | 723 /* Odd keys used in international keyboards */ |
725 for (i = 0; i < SDL_arraysize (ODD_keymap); ++i) | 724 for (i = 0; i < SDL_arraysize(ODD_keymap); ++i) |
726 ODD_keymap[i] = SDLK_UNKNOWN; | 725 ODD_keymap[i] = SDLK_UNKNOWN; |
727 | 726 |
728 /* Some of these might be mappable to an existing SDLK_ code */ | 727 /* Some of these might be mappable to an existing SDLK_ code */ |
729 ODD_keymap[XK_dead_grave & 0xFF] = SDLK_COMPOSE; | 728 ODD_keymap[XK_dead_grave & 0xFF] = SDLK_COMPOSE; |
730 ODD_keymap[XK_dead_acute & 0xFF] = SDLK_COMPOSE; | 729 ODD_keymap[XK_dead_acute & 0xFF] = SDLK_COMPOSE; |
756 #ifdef XK_ISO_Level3_Shift | 755 #ifdef XK_ISO_Level3_Shift |
757 ODD_keymap[XK_ISO_Level3_Shift & 0xFF] = SDLK_MODE; /* "Alt Gr" key */ | 756 ODD_keymap[XK_ISO_Level3_Shift & 0xFF] = SDLK_MODE; /* "Alt Gr" key */ |
758 #endif | 757 #endif |
759 | 758 |
760 /* Map the miscellaneous keys */ | 759 /* Map the miscellaneous keys */ |
761 for (i = 0; i < SDL_arraysize (MISC_keymap); ++i) | 760 for (i = 0; i < SDL_arraysize(MISC_keymap); ++i) |
762 MISC_keymap[i] = SDLK_UNKNOWN; | 761 MISC_keymap[i] = SDLK_UNKNOWN; |
763 | 762 |
764 /* These X keysyms have 0xFF as the high byte */ | 763 /* These X keysyms have 0xFF as the high byte */ |
765 MISC_keymap[XK_BackSpace & 0xFF] = SDLK_BACKSPACE; | 764 MISC_keymap[XK_BackSpace & 0xFF] = SDLK_BACKSPACE; |
766 MISC_keymap[XK_Tab & 0xFF] = SDLK_TAB; | 765 MISC_keymap[XK_Tab & 0xFF] = SDLK_TAB; |
849 MISC_keymap[XK_Hyper_R & 0xFF] = SDLK_MENU; /* Windows "Menu" key */ | 848 MISC_keymap[XK_Hyper_R & 0xFF] = SDLK_MENU; /* Windows "Menu" key */ |
850 } | 849 } |
851 | 850 |
852 /* Get the translated SDL virtual keysym */ | 851 /* Get the translated SDL virtual keysym */ |
853 SDLKey | 852 SDLKey |
854 X11_TranslateKeycode (Display * display, KeyCode kc) | 853 X11_TranslateKeycode(Display * display, KeyCode kc) |
855 { | 854 { |
856 KeySym xsym; | 855 KeySym xsym; |
857 SDLKey key; | 856 SDLKey key; |
858 | 857 |
859 xsym = XKeycodeToKeysym (display, kc, 0); | 858 xsym = XKeycodeToKeysym(display, kc, 0); |
860 #ifdef DEBUG_KEYS | 859 #ifdef DEBUG_KEYS |
861 fprintf (stderr, "Translating key code %d -> 0x%.4x\n", kc, xsym); | 860 fprintf(stderr, "Translating key code %d -> 0x%.4x\n", kc, xsym); |
862 #endif | 861 #endif |
863 key = SDLK_UNKNOWN; | 862 key = SDLK_UNKNOWN; |
864 if (xsym) { | 863 if (xsym) { |
865 switch (xsym >> 8) { | 864 switch (xsym >> 8) { |
866 case 0x1005FF: | 865 case 0x1005FF: |
932 /* X11 modifier masks for various keys */ | 931 /* X11 modifier masks for various keys */ |
933 static unsigned meta_l_mask, meta_r_mask, alt_l_mask, alt_r_mask; | 932 static unsigned meta_l_mask, meta_r_mask, alt_l_mask, alt_r_mask; |
934 static unsigned num_mask, mode_switch_mask; | 933 static unsigned num_mask, mode_switch_mask; |
935 | 934 |
936 static void | 935 static void |
937 get_modifier_masks (Display * display) | 936 get_modifier_masks(Display * display) |
938 { | 937 { |
939 static unsigned got_masks; | 938 static unsigned got_masks; |
940 int i, j; | 939 int i, j; |
941 XModifierKeymap *xmods; | 940 XModifierKeymap *xmods; |
942 unsigned n; | 941 unsigned n; |
943 | 942 |
944 if (got_masks) | 943 if (got_masks) |
945 return; | 944 return; |
946 | 945 |
947 xmods = XGetModifierMapping (display); | 946 xmods = XGetModifierMapping(display); |
948 n = xmods->max_keypermod; | 947 n = xmods->max_keypermod; |
949 for (i = 3; i < 8; i++) { | 948 for (i = 3; i < 8; i++) { |
950 for (j = 0; j < n; j++) { | 949 for (j = 0; j < n; j++) { |
951 KeyCode kc = xmods->modifiermap[i * n + j]; | 950 KeyCode kc = xmods->modifiermap[i * n + j]; |
952 KeySym ks = XKeycodeToKeysym (display, kc, 0); | 951 KeySym ks = XKeycodeToKeysym(display, kc, 0); |
953 unsigned mask = 1 << i; | 952 unsigned mask = 1 << i; |
954 switch (ks) { | 953 switch (ks) { |
955 case XK_Num_Lock: | 954 case XK_Num_Lock: |
956 num_mask = mask; | 955 num_mask = mask; |
957 break; | 956 break; |
971 mode_switch_mask = mask; | 970 mode_switch_mask = mask; |
972 break; | 971 break; |
973 } | 972 } |
974 } | 973 } |
975 } | 974 } |
976 XFreeModifiermap (xmods); | 975 XFreeModifiermap(xmods); |
977 got_masks = 1; | 976 got_masks = 1; |
978 } | 977 } |
979 | 978 |
980 | 979 |
981 /* | 980 /* |
987 * Note that it isn't completely accurate either; in particular, multi-key | 986 * Note that it isn't completely accurate either; in particular, multi-key |
988 * sequences (dead accents, compose key sequences) will not work since the | 987 * sequences (dead accents, compose key sequences) will not work since the |
989 * state has been irrevocably lost. | 988 * state has been irrevocably lost. |
990 */ | 989 */ |
991 Uint16 | 990 Uint16 |
992 X11_KeyToUnicode (SDLKey keysym, SDLMod modifiers) | 991 X11_KeyToUnicode(SDLKey keysym, SDLMod modifiers) |
993 { | 992 { |
994 SDL_VideoDevice *_this = SDL_GetVideoDevice (); | 993 SDL_VideoDevice *_this = SDL_GetVideoDevice(); |
995 char keybuf[32]; | 994 char keybuf[32]; |
996 int i; | 995 int i; |
997 KeySym xsym = 0; | 996 KeySym xsym = 0; |
998 XKeyEvent xkey; | 997 XKeyEvent xkey; |
999 Uint16 unicode; | 998 Uint16 unicode; |
1000 | 999 |
1001 if (!_this || !SDL_Display) { | 1000 if (!_this || !SDL_Display) { |
1002 return 0; | 1001 return 0; |
1003 } | 1002 } |
1004 | 1003 |
1005 SDL_memset (&xkey, 0, sizeof (xkey)); | 1004 SDL_memset(&xkey, 0, sizeof(xkey)); |
1006 xkey.display = SDL_Display; | 1005 xkey.display = SDL_Display; |
1007 | 1006 |
1008 xsym = keysym; /* last resort if not found */ | 1007 xsym = keysym; /* last resort if not found */ |
1009 for (i = 0; i < 256; ++i) { | 1008 for (i = 0; i < 256; ++i) { |
1010 if (MISC_keymap[i] == keysym) { | 1009 if (MISC_keymap[i] == keysym) { |
1014 xsym = 0xFE00 | i; | 1013 xsym = 0xFE00 | i; |
1015 break; | 1014 break; |
1016 } | 1015 } |
1017 } | 1016 } |
1018 | 1017 |
1019 xkey.keycode = XKeysymToKeycode (xkey.display, xsym); | 1018 xkey.keycode = XKeysymToKeycode(xkey.display, xsym); |
1020 | 1019 |
1021 get_modifier_masks (SDL_Display); | 1020 get_modifier_masks(SDL_Display); |
1022 if (modifiers & KMOD_SHIFT) | 1021 if (modifiers & KMOD_SHIFT) |
1023 xkey.state |= ShiftMask; | 1022 xkey.state |= ShiftMask; |
1024 if (modifiers & KMOD_CAPS) | 1023 if (modifiers & KMOD_CAPS) |
1025 xkey.state |= LockMask; | 1024 xkey.state |= LockMask; |
1026 if (modifiers & KMOD_CTRL) | 1025 if (modifiers & KMOD_CTRL) |
1037 xkey.state |= meta_r_mask; | 1036 xkey.state |= meta_r_mask; |
1038 if (modifiers & KMOD_NUM) | 1037 if (modifiers & KMOD_NUM) |
1039 xkey.state |= num_mask; | 1038 xkey.state |= num_mask; |
1040 | 1039 |
1041 unicode = 0; | 1040 unicode = 0; |
1042 if (XLookupString (&xkey, keybuf, sizeof (keybuf), NULL, NULL)) | 1041 if (XLookupString(&xkey, keybuf, sizeof(keybuf), NULL, NULL)) |
1043 unicode = (unsigned char) keybuf[0]; | 1042 unicode = (unsigned char) keybuf[0]; |
1044 return (unicode); | 1043 return (unicode); |
1045 } | 1044 } |
1046 | 1045 |
1047 | 1046 |
1049 * Called when focus is regained, to read the keyboard state and generate | 1048 * Called when focus is regained, to read the keyboard state and generate |
1050 * synthetic keypress/release events. | 1049 * synthetic keypress/release events. |
1051 * key_vec is a bit vector of keycodes (256 bits) | 1050 * key_vec is a bit vector of keycodes (256 bits) |
1052 */ | 1051 */ |
1053 void | 1052 void |
1054 X11_SetKeyboardState (Display * display, const char *key_vec) | 1053 X11_SetKeyboardState(Display * display, const char *key_vec) |
1055 { | 1054 { |
1056 char keys_return[32]; | 1055 char keys_return[32]; |
1057 int i; | 1056 int i; |
1058 Uint8 *kstate = SDL_GetKeyState (NULL); | 1057 Uint8 *kstate = SDL_GetKeyState(NULL); |
1059 SDLMod modstate; | 1058 SDLMod modstate; |
1060 Window junk_window; | 1059 Window junk_window; |
1061 int x, y; | 1060 int x, y; |
1062 unsigned int mask; | 1061 unsigned int mask; |
1063 | 1062 |
1064 /* The first time the window is mapped, we initialize key state */ | 1063 /* The first time the window is mapped, we initialize key state */ |
1065 if (!key_vec) { | 1064 if (!key_vec) { |
1066 XQueryKeymap (display, keys_return); | 1065 XQueryKeymap(display, keys_return); |
1067 key_vec = keys_return; | 1066 key_vec = keys_return; |
1068 } | 1067 } |
1069 | 1068 |
1070 /* Get the keyboard modifier state */ | 1069 /* Get the keyboard modifier state */ |
1071 modstate = 0; | 1070 modstate = 0; |
1072 get_modifier_masks (display); | 1071 get_modifier_masks(display); |
1073 if (XQueryPointer (display, DefaultRootWindow (display), | 1072 if (XQueryPointer(display, DefaultRootWindow(display), |
1074 &junk_window, &junk_window, &x, &y, &x, &y, &mask)) { | 1073 &junk_window, &junk_window, &x, &y, &x, &y, &mask)) { |
1075 if (mask & LockMask) { | 1074 if (mask & LockMask) { |
1076 modstate |= KMOD_CAPS; | 1075 modstate |= KMOD_CAPS; |
1077 } | 1076 } |
1078 if (mask & mode_switch_mask) { | 1077 if (mask & mode_switch_mask) { |
1079 modstate |= KMOD_MODE; | 1078 modstate |= KMOD_MODE; |
1082 modstate |= KMOD_NUM; | 1081 modstate |= KMOD_NUM; |
1083 } | 1082 } |
1084 } | 1083 } |
1085 | 1084 |
1086 /* Zero the new keyboard state and generate it */ | 1085 /* Zero the new keyboard state and generate it */ |
1087 SDL_memset (kstate, 0, SDLK_LAST); | 1086 SDL_memset(kstate, 0, SDLK_LAST); |
1088 /* | 1087 /* |
1089 * An obvious optimisation is to check entire longwords at a time in | 1088 * An obvious optimisation is to check entire longwords at a time in |
1090 * both loops, but we can't be sure the arrays are aligned so it's not | 1089 * both loops, but we can't be sure the arrays are aligned so it's not |
1091 * worth the extra complexity | 1090 * worth the extra complexity |
1092 */ | 1091 */ |
1096 continue; | 1095 continue; |
1097 for (j = 0; j < 8; j++) { | 1096 for (j = 0; j < 8; j++) { |
1098 if (key_vec[i] & (1 << j)) { | 1097 if (key_vec[i] & (1 << j)) { |
1099 SDLKey key; | 1098 SDLKey key; |
1100 KeyCode kc = (i << 3 | j); | 1099 KeyCode kc = (i << 3 | j); |
1101 key = X11_TranslateKeycode (display, kc); | 1100 key = X11_TranslateKeycode(display, kc); |
1102 if (key == SDLK_UNKNOWN) { | 1101 if (key == SDLK_UNKNOWN) { |
1103 continue; | 1102 continue; |
1104 } | 1103 } |
1105 kstate[key] = SDL_PRESSED; | 1104 kstate[key] = SDL_PRESSED; |
1106 switch (key) { | 1105 switch (key) { |
1146 } else { | 1145 } else { |
1147 kstate[SDLK_NUMLOCK] = SDL_RELEASED; | 1146 kstate[SDLK_NUMLOCK] = SDL_RELEASED; |
1148 } | 1147 } |
1149 | 1148 |
1150 /* Set the final modifier state */ | 1149 /* Set the final modifier state */ |
1151 SDL_SetModState (modstate); | 1150 SDL_SetModState(modstate); |
1152 } | 1151 } |
1153 | 1152 |
1154 void | 1153 void |
1155 X11_InitOSKeymap (_THIS) | 1154 X11_InitOSKeymap(_THIS) |
1156 { | 1155 { |
1157 X11_InitKeymap (); | 1156 X11_InitKeymap(); |
1158 } | 1157 } |
1159 | 1158 |
1160 void | 1159 void |
1161 X11_SaveScreenSaver (Display * display, int *saved_timeout, BOOL * dpms) | 1160 X11_SaveScreenSaver(Display * display, int *saved_timeout, BOOL * dpms) |
1162 { | 1161 { |
1163 int timeout, interval, prefer_blank, allow_exp; | 1162 int timeout, interval, prefer_blank, allow_exp; |
1164 XGetScreenSaver (display, &timeout, &interval, &prefer_blank, &allow_exp); | 1163 XGetScreenSaver(display, &timeout, &interval, &prefer_blank, &allow_exp); |
1165 *saved_timeout = timeout; | 1164 *saved_timeout = timeout; |
1166 | 1165 |
1167 #if SDL_VIDEO_DRIVER_X11_DPMS | 1166 #if SDL_VIDEO_DRIVER_X11_DPMS |
1168 if (SDL_X11_HAVE_DPMS) { | 1167 if (SDL_X11_HAVE_DPMS) { |
1169 int dummy; | 1168 int dummy; |
1170 if (DPMSQueryExtension (display, &dummy, &dummy)) { | 1169 if (DPMSQueryExtension(display, &dummy, &dummy)) { |
1171 CARD16 state; | 1170 CARD16 state; |
1172 DPMSInfo (display, &state, dpms); | 1171 DPMSInfo(display, &state, dpms); |
1173 } | 1172 } |
1174 } | 1173 } |
1175 #else | 1174 #else |
1176 *dpms = 0; | 1175 *dpms = 0; |
1177 #endif /* SDL_VIDEO_DRIVER_X11_DPMS */ | 1176 #endif /* SDL_VIDEO_DRIVER_X11_DPMS */ |
1178 } | 1177 } |
1179 | 1178 |
1180 void | 1179 void |
1181 X11_DisableScreenSaver (Display * display) | 1180 X11_DisableScreenSaver(Display * display) |
1182 { | 1181 { |
1183 int timeout, interval, prefer_blank, allow_exp; | 1182 int timeout, interval, prefer_blank, allow_exp; |
1184 XGetScreenSaver (display, &timeout, &interval, &prefer_blank, &allow_exp); | 1183 XGetScreenSaver(display, &timeout, &interval, &prefer_blank, &allow_exp); |
1185 timeout = 0; | 1184 timeout = 0; |
1186 XSetScreenSaver (display, timeout, interval, prefer_blank, allow_exp); | 1185 XSetScreenSaver(display, timeout, interval, prefer_blank, allow_exp); |
1187 | 1186 |
1188 #if SDL_VIDEO_DRIVER_X11_DPMS | 1187 #if SDL_VIDEO_DRIVER_X11_DPMS |
1189 if (SDL_X11_HAVE_DPMS) { | 1188 if (SDL_X11_HAVE_DPMS) { |
1190 int dummy; | 1189 int dummy; |
1191 if (DPMSQueryExtension (display, &dummy, &dummy)) { | 1190 if (DPMSQueryExtension(display, &dummy, &dummy)) { |
1192 DPMSDisable (display); | 1191 DPMSDisable(display); |
1193 } | 1192 } |
1194 } | 1193 } |
1195 #endif /* SDL_VIDEO_DRIVER_X11_DPMS */ | 1194 #endif /* SDL_VIDEO_DRIVER_X11_DPMS */ |
1196 } | 1195 } |
1197 | 1196 |
1198 void | 1197 void |
1199 X11_RestoreScreenSaver (Display * display, int saved_timeout, BOOL dpms) | 1198 X11_RestoreScreenSaver(Display * display, int saved_timeout, BOOL dpms) |
1200 { | 1199 { |
1201 int timeout, interval, prefer_blank, allow_exp; | 1200 int timeout, interval, prefer_blank, allow_exp; |
1202 XGetScreenSaver (display, &timeout, &interval, &prefer_blank, &allow_exp); | 1201 XGetScreenSaver(display, &timeout, &interval, &prefer_blank, &allow_exp); |
1203 timeout = saved_timeout; | 1202 timeout = saved_timeout; |
1204 XSetScreenSaver (display, timeout, interval, prefer_blank, allow_exp); | 1203 XSetScreenSaver(display, timeout, interval, prefer_blank, allow_exp); |
1205 | 1204 |
1206 #if SDL_VIDEO_DRIVER_X11_DPMS | 1205 #if SDL_VIDEO_DRIVER_X11_DPMS |
1207 if (SDL_X11_HAVE_DPMS) { | 1206 if (SDL_X11_HAVE_DPMS) { |
1208 int dummy; | 1207 int dummy; |
1209 if (DPMSQueryExtension (display, &dummy, &dummy)) { | 1208 if (DPMSQueryExtension(display, &dummy, &dummy)) { |
1210 if (dpms) { | 1209 if (dpms) { |
1211 DPMSEnable (display); | 1210 DPMSEnable(display); |
1212 } | 1211 } |
1213 } | 1212 } |
1214 } | 1213 } |
1215 #endif /* SDL_VIDEO_DRIVER_X11_DPMS */ | 1214 #endif /* SDL_VIDEO_DRIVER_X11_DPMS */ |
1216 } | 1215 } |