Mercurial > sdl-ios-xcode
comparison src/video/x11/SDL_x11events.c @ 1575:3ba88cb7eb1b
Updated dynamic X11 code. See details in Bugzilla #170.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Wed, 22 Mar 2006 05:00:59 +0000 |
parents | d910939febfa |
children | 5b0805ceb50f |
comparison
equal
deleted
inserted
replaced
1574:0fd72308659e | 1575:3ba88cb7eb1b |
---|---|
185 { | 185 { |
186 XEvent peekevent; | 186 XEvent peekevent; |
187 int repeated; | 187 int repeated; |
188 | 188 |
189 repeated = 0; | 189 repeated = 0; |
190 if ( pXPending(display) ) { | 190 if ( XPending(display) ) { |
191 pXPeekEvent(display, &peekevent); | 191 XPeekEvent(display, &peekevent); |
192 if ( (peekevent.type == KeyPress) && | 192 if ( (peekevent.type == KeyPress) && |
193 (peekevent.xkey.keycode == event->xkey.keycode) && | 193 (peekevent.xkey.keycode == event->xkey.keycode) && |
194 ((peekevent.xkey.time-event->xkey.time) < 2) ) { | 194 ((peekevent.xkey.time-event->xkey.time) < 2) ) { |
195 repeated = 1; | 195 repeated = 1; |
196 pXNextEvent(display, &peekevent); | 196 XNextEvent(display, &peekevent); |
197 } | 197 } |
198 } | 198 } |
199 return(repeated); | 199 return(repeated); |
200 } | 200 } |
201 | 201 |
226 if ( (xevent->xmotion.x < MOUSE_FUDGE_FACTOR) || | 226 if ( (xevent->xmotion.x < MOUSE_FUDGE_FACTOR) || |
227 (xevent->xmotion.x > (w-MOUSE_FUDGE_FACTOR)) || | 227 (xevent->xmotion.x > (w-MOUSE_FUDGE_FACTOR)) || |
228 (xevent->xmotion.y < MOUSE_FUDGE_FACTOR) || | 228 (xevent->xmotion.y < MOUSE_FUDGE_FACTOR) || |
229 (xevent->xmotion.y > (h-MOUSE_FUDGE_FACTOR)) ) { | 229 (xevent->xmotion.y > (h-MOUSE_FUDGE_FACTOR)) ) { |
230 /* Get the events that have accumulated */ | 230 /* Get the events that have accumulated */ |
231 while ( pXCheckTypedEvent(SDL_Display, MotionNotify, xevent) ) { | 231 while ( XCheckTypedEvent(SDL_Display, MotionNotify, xevent) ) { |
232 deltax = xevent->xmotion.x - mouse_last.x; | 232 deltax = xevent->xmotion.x - mouse_last.x; |
233 deltay = xevent->xmotion.y - mouse_last.y; | 233 deltay = xevent->xmotion.y - mouse_last.y; |
234 #ifdef DEBUG_MOTION | 234 #ifdef DEBUG_MOTION |
235 printf("Extra mouse motion: %d,%d\n", deltax, deltay); | 235 printf("Extra mouse motion: %d,%d\n", deltax, deltay); |
236 #endif | 236 #endif |
238 mouse_last.y = xevent->xmotion.y; | 238 mouse_last.y = xevent->xmotion.y; |
239 posted += SDL_PrivateMouseMotion(0, 1, deltax, deltay); | 239 posted += SDL_PrivateMouseMotion(0, 1, deltax, deltay); |
240 } | 240 } |
241 mouse_last.x = w/2; | 241 mouse_last.x = w/2; |
242 mouse_last.y = h/2; | 242 mouse_last.y = h/2; |
243 pXWarpPointer(SDL_Display, None, SDL_Window, 0, 0, 0, 0, | 243 XWarpPointer(SDL_Display, None, SDL_Window, 0, 0, 0, 0, |
244 mouse_last.x, mouse_last.y); | 244 mouse_last.x, mouse_last.y); |
245 for ( i=0; i<10; ++i ) { | 245 for ( i=0; i<10; ++i ) { |
246 pXMaskEvent(SDL_Display, PointerMotionMask, xevent); | 246 XMaskEvent(SDL_Display, PointerMotionMask, xevent); |
247 if ( (xevent->xmotion.x > | 247 if ( (xevent->xmotion.x > |
248 (mouse_last.x-MOUSE_FUDGE_FACTOR)) && | 248 (mouse_last.x-MOUSE_FUDGE_FACTOR)) && |
249 (xevent->xmotion.x < | 249 (xevent->xmotion.x < |
250 (mouse_last.x+MOUSE_FUDGE_FACTOR)) && | 250 (mouse_last.x+MOUSE_FUDGE_FACTOR)) && |
251 (xevent->xmotion.y > | 251 (xevent->xmotion.y > |
271 { | 271 { |
272 int posted; | 272 int posted; |
273 XEvent xevent; | 273 XEvent xevent; |
274 | 274 |
275 SDL_memset(&xevent, '\0', sizeof (XEvent)); /* valgrind fix. --ryan. */ | 275 SDL_memset(&xevent, '\0', sizeof (XEvent)); /* valgrind fix. --ryan. */ |
276 pXNextEvent(SDL_Display, &xevent); | 276 XNextEvent(SDL_Display, &xevent); |
277 | 277 |
278 posted = 0; | 278 posted = 0; |
279 switch (xevent.type) { | 279 switch (xevent.type) { |
280 | 280 |
281 /* Gaining mouse coverage? */ | 281 /* Gaining mouse coverage? */ |
330 #endif | 330 #endif |
331 posted = SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS); | 331 posted = SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS); |
332 | 332 |
333 #ifdef X_HAVE_UTF8_STRING | 333 #ifdef X_HAVE_UTF8_STRING |
334 if ( SDL_IC != NULL ) { | 334 if ( SDL_IC != NULL ) { |
335 pXSetICFocus(SDL_IC); | 335 XSetICFocus(SDL_IC); |
336 } | 336 } |
337 #endif | 337 #endif |
338 /* Queue entry into fullscreen mode */ | 338 /* Queue entry into fullscreen mode */ |
339 switch_waiting = 0x01 | SDL_FULLSCREEN; | 339 switch_waiting = 0x01 | SDL_FULLSCREEN; |
340 switch_time = SDL_GetTicks() + 1500; | 340 switch_time = SDL_GetTicks() + 1500; |
348 #endif | 348 #endif |
349 posted = SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS); | 349 posted = SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS); |
350 | 350 |
351 #ifdef X_HAVE_UTF8_STRING | 351 #ifdef X_HAVE_UTF8_STRING |
352 if ( SDL_IC != NULL ) { | 352 if ( SDL_IC != NULL ) { |
353 pXUnsetICFocus(SDL_IC); | 353 XUnsetICFocus(SDL_IC); |
354 } | 354 } |
355 #endif | 355 #endif |
356 /* Queue leaving fullscreen mode */ | 356 /* Queue leaving fullscreen mode */ |
357 switch_waiting = 0x01; | 357 switch_waiting = 0x01; |
358 switch_time = SDL_GetTicks() + 200; | 358 switch_time = SDL_GetTicks() + 200; |
431 if ( !SDL_TranslateUNICODE ) { | 431 if ( !SDL_TranslateUNICODE ) { |
432 posted = SDL_PrivateKeyboard(SDL_PRESSED, &keysym); | 432 posted = SDL_PrivateKeyboard(SDL_PRESSED, &keysym); |
433 break; | 433 break; |
434 } | 434 } |
435 | 435 |
436 if ( pXFilterEvent(&xevent, None) ) { | 436 if ( XFilterEvent(&xevent, None) ) { |
437 if ( xevent.xkey.keycode ) { | 437 if ( xevent.xkey.keycode ) { |
438 posted = SDL_PrivateKeyboard(SDL_PRESSED, &keysym); | 438 posted = SDL_PrivateKeyboard(SDL_PRESSED, &keysym); |
439 } else { | 439 } else { |
440 /* Save event to be associated with IM text | 440 /* Save event to be associated with IM text |
441 In 1.3 we'll have a text event instead.. */ | 441 In 1.3 we'll have a text event instead.. */ |
448 #ifdef X_HAVE_UTF8_STRING | 448 #ifdef X_HAVE_UTF8_STRING |
449 if ( SDL_IC != NULL ) { | 449 if ( SDL_IC != NULL ) { |
450 static Status state; | 450 static Status state; |
451 /* A UTF-8 character can be at most 6 bytes */ | 451 /* A UTF-8 character can be at most 6 bytes */ |
452 char keybuf[6]; | 452 char keybuf[6]; |
453 if ( pXutf8LookupString(SDL_IC, &xevent.xkey, | 453 if ( Xutf8LookupString(SDL_IC, &xevent.xkey, |
454 keybuf, sizeof(keybuf), | 454 keybuf, sizeof(keybuf), |
455 NULL, &state) ) { | 455 NULL, &state) ) { |
456 keysym.unicode = Utf8ToUcs4((Uint8*)keybuf); | 456 keysym.unicode = Utf8ToUcs4((Uint8*)keybuf); |
457 } | 457 } |
458 } | 458 } |
460 #endif | 460 #endif |
461 { | 461 { |
462 static XComposeStatus state; | 462 static XComposeStatus state; |
463 char keybuf[32]; | 463 char keybuf[32]; |
464 | 464 |
465 if ( pXLookupString(&xevent.xkey, | 465 if ( XLookupString(&xevent.xkey, |
466 keybuf, sizeof(keybuf), | 466 keybuf, sizeof(keybuf), |
467 NULL, &state) ) { | 467 NULL, &state) ) { |
468 /* | 468 /* |
469 * FIXME: XLookupString() may yield more than one | 469 * FIXME: XLookupString() may yield more than one |
470 * character, so we need a mechanism to allow for | 470 * character, so we need a mechanism to allow for |
620 | 620 |
621 /* Ack! XPending() actually performs a blocking read if no events available */ | 621 /* Ack! XPending() actually performs a blocking read if no events available */ |
622 int X11_Pending(Display *display) | 622 int X11_Pending(Display *display) |
623 { | 623 { |
624 /* Flush the display connection and look to see if events are queued */ | 624 /* Flush the display connection and look to see if events are queued */ |
625 pXFlush(display); | 625 XFlush(display); |
626 if ( pXEventsQueued(display, QueuedAlready) ) { | 626 if ( XEventsQueued(display, QueuedAlready) ) { |
627 return(1); | 627 return(1); |
628 } | 628 } |
629 | 629 |
630 /* More drastic measures are required -- see if X is ready to talk */ | 630 /* More drastic measures are required -- see if X is ready to talk */ |
631 { | 631 { |
635 | 635 |
636 x11_fd = ConnectionNumber(display); | 636 x11_fd = ConnectionNumber(display); |
637 FD_ZERO(&fdset); | 637 FD_ZERO(&fdset); |
638 FD_SET(x11_fd, &fdset); | 638 FD_SET(x11_fd, &fdset); |
639 if ( select(x11_fd+1, &fdset, NULL, NULL, &zero_time) == 1 ) { | 639 if ( select(x11_fd+1, &fdset, NULL, NULL, &zero_time) == 1 ) { |
640 return(pXPending(display)); | 640 return(XPending(display)); |
641 } | 641 } |
642 } | 642 } |
643 | 643 |
644 /* Oh well, nothing is ready .. */ | 644 /* Oh well, nothing is ready .. */ |
645 return(0); | 645 return(0); |
825 SDLKey X11_TranslateKeycode(Display *display, KeyCode kc) | 825 SDLKey X11_TranslateKeycode(Display *display, KeyCode kc) |
826 { | 826 { |
827 KeySym xsym; | 827 KeySym xsym; |
828 SDLKey key; | 828 SDLKey key; |
829 | 829 |
830 xsym = pXKeycodeToKeysym(display, kc, 0); | 830 xsym = XKeycodeToKeysym(display, kc, 0); |
831 #ifdef DEBUG_KEYS | 831 #ifdef DEBUG_KEYS |
832 fprintf(stderr, "Translating key code %d -> 0x%.4x\n", kc, xsym); | 832 fprintf(stderr, "Translating key code %d -> 0x%.4x\n", kc, xsym); |
833 #endif | 833 #endif |
834 key = SDLK_UNKNOWN; | 834 key = SDLK_UNKNOWN; |
835 if ( xsym ) { | 835 if ( xsym ) { |
912 unsigned n; | 912 unsigned n; |
913 | 913 |
914 if(got_masks) | 914 if(got_masks) |
915 return; | 915 return; |
916 | 916 |
917 xmods = pXGetModifierMapping(display); | 917 xmods = XGetModifierMapping(display); |
918 n = xmods->max_keypermod; | 918 n = xmods->max_keypermod; |
919 for(i = 3; i < 8; i++) { | 919 for(i = 3; i < 8; i++) { |
920 for(j = 0; j < n; j++) { | 920 for(j = 0; j < n; j++) { |
921 KeyCode kc = xmods->modifiermap[i * n + j]; | 921 KeyCode kc = xmods->modifiermap[i * n + j]; |
922 KeySym ks = pXKeycodeToKeysym(display, kc, 0); | 922 KeySym ks = XKeycodeToKeysym(display, kc, 0); |
923 unsigned mask = 1 << i; | 923 unsigned mask = 1 << i; |
924 switch(ks) { | 924 switch(ks) { |
925 case XK_Num_Lock: | 925 case XK_Num_Lock: |
926 num_mask = mask; break; | 926 num_mask = mask; break; |
927 case XK_Alt_L: | 927 case XK_Alt_L: |
935 case XK_Mode_switch: | 935 case XK_Mode_switch: |
936 mode_switch_mask = mask; break; | 936 mode_switch_mask = mask; break; |
937 } | 937 } |
938 } | 938 } |
939 } | 939 } |
940 pXFreeModifiermap(xmods); | 940 XFreeModifiermap(xmods); |
941 got_masks = 1; | 941 got_masks = 1; |
942 } | 942 } |
943 | 943 |
944 | 944 |
945 /* | 945 /* |
977 xsym = 0xFE00 | i; | 977 xsym = 0xFE00 | i; |
978 break; | 978 break; |
979 } | 979 } |
980 } | 980 } |
981 | 981 |
982 xkey.keycode = pXKeysymToKeycode(xkey.display, xsym); | 982 xkey.keycode = XKeysymToKeycode(xkey.display, xsym); |
983 | 983 |
984 get_modifier_masks(SDL_Display); | 984 get_modifier_masks(SDL_Display); |
985 if(modifiers & KMOD_SHIFT) | 985 if(modifiers & KMOD_SHIFT) |
986 xkey.state |= ShiftMask; | 986 xkey.state |= ShiftMask; |
987 if(modifiers & KMOD_CAPS) | 987 if(modifiers & KMOD_CAPS) |
1000 xkey.state |= meta_r_mask; | 1000 xkey.state |= meta_r_mask; |
1001 if(modifiers & KMOD_NUM) | 1001 if(modifiers & KMOD_NUM) |
1002 xkey.state |= num_mask; | 1002 xkey.state |= num_mask; |
1003 | 1003 |
1004 unicode = 0; | 1004 unicode = 0; |
1005 if ( pXLookupString(&xkey, keybuf, sizeof(keybuf), NULL, NULL) ) | 1005 if ( XLookupString(&xkey, keybuf, sizeof(keybuf), NULL, NULL) ) |
1006 unicode = (unsigned char)keybuf[0]; | 1006 unicode = (unsigned char)keybuf[0]; |
1007 return(unicode); | 1007 return(unicode); |
1008 } | 1008 } |
1009 | 1009 |
1010 | 1010 |
1023 int x, y; | 1023 int x, y; |
1024 unsigned int mask; | 1024 unsigned int mask; |
1025 | 1025 |
1026 /* The first time the window is mapped, we initialize key state */ | 1026 /* The first time the window is mapped, we initialize key state */ |
1027 if ( ! key_vec ) { | 1027 if ( ! key_vec ) { |
1028 pXQueryKeymap(display, keys_return); | 1028 XQueryKeymap(display, keys_return); |
1029 key_vec = keys_return; | 1029 key_vec = keys_return; |
1030 } | 1030 } |
1031 | 1031 |
1032 /* Get the keyboard modifier state */ | 1032 /* Get the keyboard modifier state */ |
1033 modstate = 0; | 1033 modstate = 0; |
1034 get_modifier_masks(display); | 1034 get_modifier_masks(display); |
1035 if ( pXQueryPointer(display, DefaultRootWindow(display), | 1035 if ( XQueryPointer(display, DefaultRootWindow(display), |
1036 &junk_window, &junk_window, &x, &y, &x, &y, &mask) ) { | 1036 &junk_window, &junk_window, &x, &y, &x, &y, &mask) ) { |
1037 if ( mask & LockMask ) { | 1037 if ( mask & LockMask ) { |
1038 modstate |= KMOD_CAPS; | 1038 modstate |= KMOD_CAPS; |
1039 } | 1039 } |
1040 if ( mask & mode_switch_mask ) { | 1040 if ( mask & mode_switch_mask ) { |