comparison src/video/x11/SDL_x11events.c @ 1168:045f186426e1

Dynamically load X11 libraries like we currently do for alsa, esd, etc. This allows you to run an SDL program on a system without Xlib, since it'll just report the x11 target unavailable at runtime.
author Ryan C. Gordon <icculus@icculus.org>
date Sat, 05 Nov 2005 19:53:37 +0000
parents 787b8d2c23e4
children 9867f3d86e44
comparison
equal deleted inserted replaced
1167:435c2e481299 1168:045f186426e1
72 { 72 {
73 XEvent peekevent; 73 XEvent peekevent;
74 int repeated; 74 int repeated;
75 75
76 repeated = 0; 76 repeated = 0;
77 if ( XPending(display) ) { 77 if ( pXPending(display) ) {
78 XPeekEvent(display, &peekevent); 78 pXPeekEvent(display, &peekevent);
79 if ( (peekevent.type == KeyPress) && 79 if ( (peekevent.type == KeyPress) &&
80 (peekevent.xkey.keycode == event->xkey.keycode) && 80 (peekevent.xkey.keycode == event->xkey.keycode) &&
81 ((peekevent.xkey.time-event->xkey.time) < 2) ) { 81 ((peekevent.xkey.time-event->xkey.time) < 2) ) {
82 repeated = 1; 82 repeated = 1;
83 XNextEvent(display, &peekevent); 83 pXNextEvent(display, &peekevent);
84 } 84 }
85 } 85 }
86 return(repeated); 86 return(repeated);
87 } 87 }
88 88
113 if ( (xevent->xmotion.x < MOUSE_FUDGE_FACTOR) || 113 if ( (xevent->xmotion.x < MOUSE_FUDGE_FACTOR) ||
114 (xevent->xmotion.x > (w-MOUSE_FUDGE_FACTOR)) || 114 (xevent->xmotion.x > (w-MOUSE_FUDGE_FACTOR)) ||
115 (xevent->xmotion.y < MOUSE_FUDGE_FACTOR) || 115 (xevent->xmotion.y < MOUSE_FUDGE_FACTOR) ||
116 (xevent->xmotion.y > (h-MOUSE_FUDGE_FACTOR)) ) { 116 (xevent->xmotion.y > (h-MOUSE_FUDGE_FACTOR)) ) {
117 /* Get the events that have accumulated */ 117 /* Get the events that have accumulated */
118 while ( XCheckTypedEvent(SDL_Display, MotionNotify, xevent) ) { 118 while ( pXCheckTypedEvent(SDL_Display, MotionNotify, xevent) ) {
119 deltax = xevent->xmotion.x - mouse_last.x; 119 deltax = xevent->xmotion.x - mouse_last.x;
120 deltay = xevent->xmotion.y - mouse_last.y; 120 deltay = xevent->xmotion.y - mouse_last.y;
121 #ifdef DEBUG_MOTION 121 #ifdef DEBUG_MOTION
122 printf("Extra mouse motion: %d,%d\n", deltax, deltay); 122 printf("Extra mouse motion: %d,%d\n", deltax, deltay);
123 #endif 123 #endif
125 mouse_last.y = xevent->xmotion.y; 125 mouse_last.y = xevent->xmotion.y;
126 posted += SDL_PrivateMouseMotion(0, 1, deltax, deltay); 126 posted += SDL_PrivateMouseMotion(0, 1, deltax, deltay);
127 } 127 }
128 mouse_last.x = w/2; 128 mouse_last.x = w/2;
129 mouse_last.y = h/2; 129 mouse_last.y = h/2;
130 XWarpPointer(SDL_Display, None, SDL_Window, 0, 0, 0, 0, 130 pXWarpPointer(SDL_Display, None, SDL_Window, 0, 0, 0, 0,
131 mouse_last.x, mouse_last.y); 131 mouse_last.x, mouse_last.y);
132 for ( i=0; i<10; ++i ) { 132 for ( i=0; i<10; ++i ) {
133 XMaskEvent(SDL_Display, PointerMotionMask, xevent); 133 pXMaskEvent(SDL_Display, PointerMotionMask, xevent);
134 if ( (xevent->xmotion.x > 134 if ( (xevent->xmotion.x >
135 (mouse_last.x-MOUSE_FUDGE_FACTOR)) && 135 (mouse_last.x-MOUSE_FUDGE_FACTOR)) &&
136 (xevent->xmotion.x < 136 (xevent->xmotion.x <
137 (mouse_last.x+MOUSE_FUDGE_FACTOR)) && 137 (mouse_last.x+MOUSE_FUDGE_FACTOR)) &&
138 (xevent->xmotion.y > 138 (xevent->xmotion.y >
158 { 158 {
159 int posted; 159 int posted;
160 XEvent xevent; 160 XEvent xevent;
161 161
162 memset(&xevent, '\0', sizeof (XEvent)); /* valgrind fix. --ryan. */ 162 memset(&xevent, '\0', sizeof (XEvent)); /* valgrind fix. --ryan. */
163 XNextEvent(SDL_Display, &xevent); 163 pXNextEvent(SDL_Display, &xevent);
164 164
165 posted = 0; 165 posted = 0;
166 switch (xevent.type) { 166 switch (xevent.type) {
167 167
168 /* Gaining mouse coverage? */ 168 /* Gaining mouse coverage? */
435 435
436 /* Ack! XPending() actually performs a blocking read if no events available */ 436 /* Ack! XPending() actually performs a blocking read if no events available */
437 int X11_Pending(Display *display) 437 int X11_Pending(Display *display)
438 { 438 {
439 /* Flush the display connection and look to see if events are queued */ 439 /* Flush the display connection and look to see if events are queued */
440 XFlush(display); 440 pXFlush(display);
441 if ( XEventsQueued(display, QueuedAlready) ) { 441 if ( pXEventsQueued(display, QueuedAlready) ) {
442 return(1); 442 return(1);
443 } 443 }
444 444
445 /* More drastic measures are required -- see if X is ready to talk */ 445 /* More drastic measures are required -- see if X is ready to talk */
446 { 446 {
450 450
451 x11_fd = ConnectionNumber(display); 451 x11_fd = ConnectionNumber(display);
452 FD_ZERO(&fdset); 452 FD_ZERO(&fdset);
453 FD_SET(x11_fd, &fdset); 453 FD_SET(x11_fd, &fdset);
454 if ( select(x11_fd+1, &fdset, NULL, NULL, &zero_time) == 1 ) { 454 if ( select(x11_fd+1, &fdset, NULL, NULL, &zero_time) == 1 ) {
455 return(XPending(display)); 455 return(pXPending(display));
456 } 456 }
457 } 457 }
458 458
459 /* Oh well, nothing is ready .. */ 459 /* Oh well, nothing is ready .. */
460 return(0); 460 return(0);
617 { 617 {
618 KeySym xsym; 618 KeySym xsym;
619 619
620 /* Get the raw keyboard scancode */ 620 /* Get the raw keyboard scancode */
621 keysym->scancode = kc; 621 keysym->scancode = kc;
622 xsym = XKeycodeToKeysym(display, kc, 0); 622 xsym = pXKeycodeToKeysym(display, kc, 0);
623 #ifdef DEBUG_KEYS 623 #ifdef DEBUG_KEYS
624 fprintf(stderr, "Translating key 0x%.4x (%d)\n", xsym, kc); 624 fprintf(stderr, "Translating key 0x%.4x (%d)\n", xsym, kc);
625 #endif 625 #endif
626 /* Get the translated SDL virtual keysym */ 626 /* Get the translated SDL virtual keysym */
627 keysym->sym = SDLK_UNKNOWN; 627 keysym->sym = SDLK_UNKNOWN;
709 if ( SDL_GetModState() & KMOD_MODE ) { 709 if ( SDL_GetModState() & KMOD_MODE ) {
710 xkey->state |= (1<<13); 710 xkey->state |= (1<<13);
711 } 711 }
712 #endif 712 #endif
713 /* Look up the translated value for the key event */ 713 /* Look up the translated value for the key event */
714 if ( XLookupString(xkey, (char *)keybuf, sizeof(keybuf), 714 if ( pXLookupString(xkey, (char *)keybuf, sizeof(keybuf),
715 NULL, &state) ) { 715 NULL, &state) ) {
716 /* 716 /*
717 * FIXME,: XLookupString() may yield more than one 717 * FIXME,: XLookupString() may yield more than one
718 * character, so we need a mechanism to allow for 718 * character, so we need a mechanism to allow for
719 * this (perhaps generate null keypress events with 719 * this (perhaps generate null keypress events with
737 unsigned n; 737 unsigned n;
738 738
739 if(got_masks) 739 if(got_masks)
740 return; 740 return;
741 741
742 xmods = XGetModifierMapping(display); 742 xmods = pXGetModifierMapping(display);
743 n = xmods->max_keypermod; 743 n = xmods->max_keypermod;
744 for(i = 3; i < 8; i++) { 744 for(i = 3; i < 8; i++) {
745 for(j = 0; j < n; j++) { 745 for(j = 0; j < n; j++) {
746 KeyCode kc = xmods->modifiermap[i * n + j]; 746 KeyCode kc = xmods->modifiermap[i * n + j];
747 KeySym ks = XKeycodeToKeysym(display, kc, 0); 747 KeySym ks = pXKeycodeToKeysym(display, kc, 0);
748 unsigned mask = 1 << i; 748 unsigned mask = 1 << i;
749 switch(ks) { 749 switch(ks) {
750 case XK_Num_Lock: 750 case XK_Num_Lock:
751 num_mask = mask; break; 751 num_mask = mask; break;
752 case XK_Alt_L: 752 case XK_Alt_L:
760 case XK_Mode_switch: 760 case XK_Mode_switch:
761 mode_switch_mask = mask; break; 761 mode_switch_mask = mask; break;
762 } 762 }
763 } 763 }
764 } 764 }
765 XFreeModifiermap(xmods); 765 pXFreeModifiermap(xmods);
766 got_masks = 1; 766 got_masks = 1;
767 } 767 }
768 768
769 769
770 /* 770 /*
802 xsym = 0xFE00 | i; 802 xsym = 0xFE00 | i;
803 break; 803 break;
804 } 804 }
805 } 805 }
806 806
807 xkey.keycode = XKeysymToKeycode(xkey.display, xsym); 807 xkey.keycode = pXKeysymToKeycode(xkey.display, xsym);
808 808
809 get_modifier_masks(SDL_Display); 809 get_modifier_masks(SDL_Display);
810 if(modifiers & KMOD_SHIFT) 810 if(modifiers & KMOD_SHIFT)
811 xkey.state |= ShiftMask; 811 xkey.state |= ShiftMask;
812 if(modifiers & KMOD_CAPS) 812 if(modifiers & KMOD_CAPS)
825 xkey.state |= meta_r_mask; 825 xkey.state |= meta_r_mask;
826 if(modifiers & KMOD_NUM) 826 if(modifiers & KMOD_NUM)
827 xkey.state |= num_mask; 827 xkey.state |= num_mask;
828 828
829 unicode = 0; 829 unicode = 0;
830 if ( XLookupString(&xkey, keybuf, sizeof(keybuf), NULL, NULL) ) 830 if ( pXLookupString(&xkey, keybuf, sizeof(keybuf), NULL, NULL) )
831 unicode = (unsigned char)keybuf[0]; 831 unicode = (unsigned char)keybuf[0];
832 return(unicode); 832 return(unicode);
833 } 833 }
834 834
835 /* 835 /*
849 int x, y; 849 int x, y;
850 unsigned int mask; 850 unsigned int mask;
851 851
852 /* The first time the window is mapped, we initialize key state */ 852 /* The first time the window is mapped, we initialize key state */
853 if ( ! key_vec ) { 853 if ( ! key_vec ) {
854 XQueryKeymap(display, keys_return); 854 pXQueryKeymap(display, keys_return);
855 key_vec = keys_return; 855 key_vec = keys_return;
856 } 856 }
857 857
858 /* Get the keyboard modifier state */ 858 /* Get the keyboard modifier state */
859 modstate = 0; 859 modstate = 0;
860 get_modifier_masks(display); 860 get_modifier_masks(display);
861 if ( XQueryPointer(display, DefaultRootWindow(display), 861 if ( pXQueryPointer(display, DefaultRootWindow(display),
862 &junk_window, &junk_window, &x, &y, &x, &y, &mask) ) { 862 &junk_window, &junk_window, &x, &y, &x, &y, &mask) ) {
863 if ( mask & LockMask ) { 863 if ( mask & LockMask ) {
864 modstate |= KMOD_CAPS; 864 modstate |= KMOD_CAPS;
865 } 865 }
866 if ( mask & mode_switch_mask ) { 866 if ( mask & mode_switch_mask ) {