annotate src/video/x11/SDL_x11events.c @ 1324:42e95163d553

Favor using pthread_mutexattr_settype() on Linux.
author Sam Lantinga <slouken@libsdl.org>
date Fri, 03 Feb 2006 06:33:54 +0000
parents c9b51268668f
children d12a63a8d95a
rev   line source
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1 /*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1196
diff changeset
3 Copyright (C) 1997-2006 Sam Lantinga
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
4
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1196
diff changeset
6 modify it under the terms of the GNU Lesser General Public
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1196
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
9
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1196
diff changeset
13 Lesser General Public License for more details.
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
14
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1196
diff changeset
15 You should have received a copy of the GNU Lesser General Public
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1196
diff changeset
16 License along with this library; if not, write to the Free Software
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1196
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
18
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
19 Sam Lantinga
252
e8157fcb3114 Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents: 161
diff changeset
20 slouken@libsdl.org
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
21 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
22
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
23 /* Handle the event stream, converting X11 events into SDL events */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
24
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
25 #include <stdio.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
26 #include <stdlib.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
27 #include <string.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
28 #include <setjmp.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
29 #include <X11/Xlib.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
30 #include <X11/Xutil.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
31 #include <X11/keysym.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
32 #ifdef __SVR4
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
33 #include <X11/Sunkeysym.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
34 #endif
75
b0ae59d0f3ee Added patches from FreeBSD ports
Sam Lantinga <slouken@lokigames.com>
parents: 14
diff changeset
35 #include <sys/types.h>
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
36 #include <sys/time.h>
75
b0ae59d0f3ee Added patches from FreeBSD ports
Sam Lantinga <slouken@lokigames.com>
parents: 14
diff changeset
37 #include <unistd.h>
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
38
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
39 #include "SDL.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
40 #include "SDL_syswm.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
41 #include "SDL_sysevents.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
42 #include "SDL_sysvideo.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
43 #include "SDL_events_c.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
44 #include "SDL_x11video.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
45 #include "SDL_x11dga_c.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
46 #include "SDL_x11modes_c.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
47 #include "SDL_x11image_c.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
48 #include "SDL_x11gamma_c.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
49 #include "SDL_x11wm_c.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
50 #include "SDL_x11mouse_c.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
51 #include "SDL_x11events_c.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
52
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
53
14
c3e9d4a623c1 Fixed stuck keys when changing the video mode
Sam Lantinga <slouken@lokigames.com>
parents: 12
diff changeset
54 /* Define this if you want to debug X11 events */
c3e9d4a623c1 Fixed stuck keys when changing the video mode
Sam Lantinga <slouken@lokigames.com>
parents: 12
diff changeset
55 /*#define DEBUG_XEVENTS*/
c3e9d4a623c1 Fixed stuck keys when changing the video mode
Sam Lantinga <slouken@lokigames.com>
parents: 12
diff changeset
56
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
57 /* The translation tables from an X11 keysym to a SDL keysym */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
58 static SDLKey ODD_keymap[256];
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
59 static SDLKey MISC_keymap[256];
1178
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
60 SDL_keysym *X11_TranslateKey(Display *display, XIC ic, XKeyEvent *xkey, KeyCode kc,
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
61 SDL_keysym *keysym);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
62
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
63 /* Check to see if this is a repeated key.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
64 (idea shamelessly lifted from GII -- thanks guys! :)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
65 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
66 static int X11_KeyRepeat(Display *display, XEvent *event)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
67 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
68 XEvent peekevent;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
69 int repeated;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
70
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
71 repeated = 0;
1168
045f186426e1 Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 1159
diff changeset
72 if ( pXPending(display) ) {
045f186426e1 Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 1159
diff changeset
73 pXPeekEvent(display, &peekevent);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
74 if ( (peekevent.type == KeyPress) &&
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
75 (peekevent.xkey.keycode == event->xkey.keycode) &&
12
34d956b20f75 Fix key repeat detection on newer X servers
Sam Lantinga <slouken@lokigames.com>
parents: 8
diff changeset
76 ((peekevent.xkey.time-event->xkey.time) < 2) ) {
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
77 repeated = 1;
1168
045f186426e1 Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 1159
diff changeset
78 pXNextEvent(display, &peekevent);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
79 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
80 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
81 return(repeated);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
82 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
83
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
84 /* Note: The X server buffers and accumulates mouse motion events, so
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
85 the motion event generated by the warp may not appear exactly as we
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
86 expect it to. We work around this (and improve performance) by only
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
87 warping the pointer when it reaches the edge, and then wait for it.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
88 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
89 #define MOUSE_FUDGE_FACTOR 8
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
90
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
91 static __inline__ int X11_WarpedMotion(_THIS, XEvent *xevent)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
92 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
93 int w, h, i;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
94 int deltax, deltay;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
95 int posted;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
96
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
97 w = SDL_VideoSurface->w;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
98 h = SDL_VideoSurface->h;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
99 deltax = xevent->xmotion.x - mouse_last.x;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
100 deltay = xevent->xmotion.y - mouse_last.y;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
101 #ifdef DEBUG_MOTION
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
102 printf("Warped mouse motion: %d,%d\n", deltax, deltay);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
103 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
104 mouse_last.x = xevent->xmotion.x;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
105 mouse_last.y = xevent->xmotion.y;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
106 posted = SDL_PrivateMouseMotion(0, 1, deltax, deltay);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
107
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
108 if ( (xevent->xmotion.x < MOUSE_FUDGE_FACTOR) ||
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
109 (xevent->xmotion.x > (w-MOUSE_FUDGE_FACTOR)) ||
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
110 (xevent->xmotion.y < MOUSE_FUDGE_FACTOR) ||
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
111 (xevent->xmotion.y > (h-MOUSE_FUDGE_FACTOR)) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
112 /* Get the events that have accumulated */
1168
045f186426e1 Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 1159
diff changeset
113 while ( pXCheckTypedEvent(SDL_Display, MotionNotify, xevent) ) {
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
114 deltax = xevent->xmotion.x - mouse_last.x;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
115 deltay = xevent->xmotion.y - mouse_last.y;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
116 #ifdef DEBUG_MOTION
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
117 printf("Extra mouse motion: %d,%d\n", deltax, deltay);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
118 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
119 mouse_last.x = xevent->xmotion.x;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
120 mouse_last.y = xevent->xmotion.y;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
121 posted += SDL_PrivateMouseMotion(0, 1, deltax, deltay);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
122 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
123 mouse_last.x = w/2;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
124 mouse_last.y = h/2;
1168
045f186426e1 Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 1159
diff changeset
125 pXWarpPointer(SDL_Display, None, SDL_Window, 0, 0, 0, 0,
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
126 mouse_last.x, mouse_last.y);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
127 for ( i=0; i<10; ++i ) {
1168
045f186426e1 Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 1159
diff changeset
128 pXMaskEvent(SDL_Display, PointerMotionMask, xevent);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
129 if ( (xevent->xmotion.x >
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
130 (mouse_last.x-MOUSE_FUDGE_FACTOR)) &&
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
131 (xevent->xmotion.x <
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
132 (mouse_last.x+MOUSE_FUDGE_FACTOR)) &&
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
133 (xevent->xmotion.y >
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
134 (mouse_last.y-MOUSE_FUDGE_FACTOR)) &&
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
135 (xevent->xmotion.y <
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
136 (mouse_last.y+MOUSE_FUDGE_FACTOR)) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
137 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
138 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
139 #ifdef DEBUG_XEVENTS
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
140 printf("Lost mouse motion: %d,%d\n", xevent->xmotion.x, xevent->xmotion.y);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
141 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
142 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
143 #ifdef DEBUG_XEVENTS
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
144 if ( i == 10 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
145 printf("Warning: didn't detect mouse warp motion\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
146 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
147 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
148 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
149 return(posted);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
150 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
151
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
152 static int X11_DispatchEvent(_THIS)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
153 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
154 int posted;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
155 XEvent xevent;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
156
1159
787b8d2c23e4 Valgrind fix.
Ryan C. Gordon <icculus@icculus.org>
parents: 805
diff changeset
157 memset(&xevent, '\0', sizeof (XEvent)); /* valgrind fix. --ryan. */
1168
045f186426e1 Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 1159
diff changeset
158 pXNextEvent(SDL_Display, &xevent);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
159
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
160 posted = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
161 switch (xevent.type) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
162
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
163 /* Gaining mouse coverage? */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
164 case EnterNotify: {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
165 #ifdef DEBUG_XEVENTS
82
2bddc38a9f5d When the mouse is grabbed, send the application the motion associated with
Sam Lantinga <slouken@lokigames.com>
parents: 75
diff changeset
166 printf("EnterNotify! (%d,%d)\n", xevent.xcrossing.x, xevent.xcrossing.y);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
167 if ( xevent.xcrossing.mode == NotifyGrab )
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
168 printf("Mode: NotifyGrab\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
169 if ( xevent.xcrossing.mode == NotifyUngrab )
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
170 printf("Mode: NotifyUngrab\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
171 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
172 if ( (xevent.xcrossing.mode != NotifyGrab) &&
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
173 (xevent.xcrossing.mode != NotifyUngrab) ) {
82
2bddc38a9f5d When the mouse is grabbed, send the application the motion associated with
Sam Lantinga <slouken@lokigames.com>
parents: 75
diff changeset
174 if ( this->input_grab == SDL_GRAB_OFF ) {
2bddc38a9f5d When the mouse is grabbed, send the application the motion associated with
Sam Lantinga <slouken@lokigames.com>
parents: 75
diff changeset
175 posted = SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
2bddc38a9f5d When the mouse is grabbed, send the application the motion associated with
Sam Lantinga <slouken@lokigames.com>
parents: 75
diff changeset
176 } else {
2bddc38a9f5d When the mouse is grabbed, send the application the motion associated with
Sam Lantinga <slouken@lokigames.com>
parents: 75
diff changeset
177 posted = SDL_PrivateMouseMotion(0, 0,
2bddc38a9f5d When the mouse is grabbed, send the application the motion associated with
Sam Lantinga <slouken@lokigames.com>
parents: 75
diff changeset
178 xevent.xcrossing.x,
2bddc38a9f5d When the mouse is grabbed, send the application the motion associated with
Sam Lantinga <slouken@lokigames.com>
parents: 75
diff changeset
179 xevent.xcrossing.y);
2bddc38a9f5d When the mouse is grabbed, send the application the motion associated with
Sam Lantinga <slouken@lokigames.com>
parents: 75
diff changeset
180 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
181 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
182 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
183 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
184
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
185 /* Losing mouse coverage? */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
186 case LeaveNotify: {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
187 #ifdef DEBUG_XEVENTS
82
2bddc38a9f5d When the mouse is grabbed, send the application the motion associated with
Sam Lantinga <slouken@lokigames.com>
parents: 75
diff changeset
188 printf("LeaveNotify! (%d,%d)\n", xevent.xcrossing.x, xevent.xcrossing.y);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
189 if ( xevent.xcrossing.mode == NotifyGrab )
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
190 printf("Mode: NotifyGrab\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
191 if ( xevent.xcrossing.mode == NotifyUngrab )
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
192 printf("Mode: NotifyUngrab\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
193 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
194 if ( (xevent.xcrossing.mode != NotifyGrab) &&
496
864a66f028d8 Don't be fooled by unclutter - the mouse isn't really leaving our window
Sam Lantinga <slouken@libsdl.org>
parents: 412
diff changeset
195 (xevent.xcrossing.mode != NotifyUngrab) &&
864a66f028d8 Don't be fooled by unclutter - the mouse isn't really leaving our window
Sam Lantinga <slouken@libsdl.org>
parents: 412
diff changeset
196 (xevent.xcrossing.detail != NotifyInferior) ) {
82
2bddc38a9f5d When the mouse is grabbed, send the application the motion associated with
Sam Lantinga <slouken@lokigames.com>
parents: 75
diff changeset
197 if ( this->input_grab == SDL_GRAB_OFF ) {
2bddc38a9f5d When the mouse is grabbed, send the application the motion associated with
Sam Lantinga <slouken@lokigames.com>
parents: 75
diff changeset
198 posted = SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);
2bddc38a9f5d When the mouse is grabbed, send the application the motion associated with
Sam Lantinga <slouken@lokigames.com>
parents: 75
diff changeset
199 } else {
2bddc38a9f5d When the mouse is grabbed, send the application the motion associated with
Sam Lantinga <slouken@lokigames.com>
parents: 75
diff changeset
200 posted = SDL_PrivateMouseMotion(0, 0,
2bddc38a9f5d When the mouse is grabbed, send the application the motion associated with
Sam Lantinga <slouken@lokigames.com>
parents: 75
diff changeset
201 xevent.xcrossing.x,
2bddc38a9f5d When the mouse is grabbed, send the application the motion associated with
Sam Lantinga <slouken@lokigames.com>
parents: 75
diff changeset
202 xevent.xcrossing.y);
2bddc38a9f5d When the mouse is grabbed, send the application the motion associated with
Sam Lantinga <slouken@lokigames.com>
parents: 75
diff changeset
203 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
204 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
205 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
206 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
207
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
208 /* Gaining input focus? */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
209 case FocusIn: {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
210 #ifdef DEBUG_XEVENTS
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
211 printf("FocusIn!\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
212 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
213 posted = SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
214
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
215 /* Queue entry into fullscreen mode */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
216 switch_waiting = 0x01 | SDL_FULLSCREEN;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
217 switch_time = SDL_GetTicks() + 1500;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
218 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
219 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
220
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
221 /* Losing input focus? */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
222 case FocusOut: {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
223 #ifdef DEBUG_XEVENTS
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
224 printf("FocusOut!\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
225 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
226 posted = SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
227
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
228 /* Queue leaving fullscreen mode */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
229 switch_waiting = 0x01;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
230 switch_time = SDL_GetTicks() + 200;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
231 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
232 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
233
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
234 /* Generated upon EnterWindow and FocusIn */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
235 case KeymapNotify: {
14
c3e9d4a623c1 Fixed stuck keys when changing the video mode
Sam Lantinga <slouken@lokigames.com>
parents: 12
diff changeset
236 #ifdef DEBUG_XEVENTS
c3e9d4a623c1 Fixed stuck keys when changing the video mode
Sam Lantinga <slouken@lokigames.com>
parents: 12
diff changeset
237 printf("KeymapNotify!\n");
c3e9d4a623c1 Fixed stuck keys when changing the video mode
Sam Lantinga <slouken@lokigames.com>
parents: 12
diff changeset
238 #endif
1178
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
239 X11_SetKeyboardState(SDL_Display, SDL_IC, xevent.xkeymap.key_vector);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
240 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
241 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
242
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
243 /* Mouse motion? */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
244 case MotionNotify: {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
245 if ( SDL_VideoSurface ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
246 if ( mouse_relative ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
247 if ( using_dga & DGA_MOUSE ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
248 #ifdef DEBUG_MOTION
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
249 printf("DGA motion: %d,%d\n", xevent.xmotion.x_root, xevent.xmotion.y_root);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
250 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
251 posted = SDL_PrivateMouseMotion(0, 1,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
252 xevent.xmotion.x_root,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
253 xevent.xmotion.y_root);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
254 } else {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
255 posted = X11_WarpedMotion(this,&xevent);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
256 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
257 } else {
82
2bddc38a9f5d When the mouse is grabbed, send the application the motion associated with
Sam Lantinga <slouken@lokigames.com>
parents: 75
diff changeset
258 #ifdef DEBUG_MOTION
2bddc38a9f5d When the mouse is grabbed, send the application the motion associated with
Sam Lantinga <slouken@lokigames.com>
parents: 75
diff changeset
259 printf("X11 motion: %d,%d\n", xevent.xmotion.x, xevent.xmotion.y);
2bddc38a9f5d When the mouse is grabbed, send the application the motion associated with
Sam Lantinga <slouken@lokigames.com>
parents: 75
diff changeset
260 #endif
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
261 posted = SDL_PrivateMouseMotion(0, 0,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
262 xevent.xmotion.x,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
263 xevent.xmotion.y);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
264 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
265 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
266 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
267 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
268
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
269 /* Mouse button press? */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
270 case ButtonPress: {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
271 posted = SDL_PrivateMouseButton(SDL_PRESSED,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
272 xevent.xbutton.button, 0, 0);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
273 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
274 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
275
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
276 /* Mouse button release? */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
277 case ButtonRelease: {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
278 posted = SDL_PrivateMouseButton(SDL_RELEASED,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
279 xevent.xbutton.button, 0, 0);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
280 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
281 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
282
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
283 /* Key press? */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
284 case KeyPress: {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
285 SDL_keysym keysym;
14
c3e9d4a623c1 Fixed stuck keys when changing the video mode
Sam Lantinga <slouken@lokigames.com>
parents: 12
diff changeset
286
c3e9d4a623c1 Fixed stuck keys when changing the video mode
Sam Lantinga <slouken@lokigames.com>
parents: 12
diff changeset
287 #ifdef DEBUG_XEVENTS
c3e9d4a623c1 Fixed stuck keys when changing the video mode
Sam Lantinga <slouken@lokigames.com>
parents: 12
diff changeset
288 printf("KeyPress (X11 keycode = 0x%X)\n", xevent.xkey.keycode);
c3e9d4a623c1 Fixed stuck keys when changing the video mode
Sam Lantinga <slouken@lokigames.com>
parents: 12
diff changeset
289 #endif
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
290 posted = SDL_PrivateKeyboard(SDL_PRESSED,
1178
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
291 X11_TranslateKey(SDL_Display, SDL_IC, &xevent.xkey,
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
292 xevent.xkey.keycode,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
293 &keysym));
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
294 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
295 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
296
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
297 /* Key release? */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
298 case KeyRelease: {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
299 SDL_keysym keysym;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
300
14
c3e9d4a623c1 Fixed stuck keys when changing the video mode
Sam Lantinga <slouken@lokigames.com>
parents: 12
diff changeset
301 #ifdef DEBUG_XEVENTS
c3e9d4a623c1 Fixed stuck keys when changing the video mode
Sam Lantinga <slouken@lokigames.com>
parents: 12
diff changeset
302 printf("KeyRelease (X11 keycode = 0x%X)\n", xevent.xkey.keycode);
c3e9d4a623c1 Fixed stuck keys when changing the video mode
Sam Lantinga <slouken@lokigames.com>
parents: 12
diff changeset
303 #endif
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
304 /* Check to see if this is a repeated key */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
305 if ( ! X11_KeyRepeat(SDL_Display, &xevent) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
306 posted = SDL_PrivateKeyboard(SDL_RELEASED,
1178
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
307 X11_TranslateKey(SDL_Display, SDL_IC, &xevent.xkey,
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
308 xevent.xkey.keycode,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
309 &keysym));
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
310 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
311 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
312 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
313
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
314 /* Have we been iconified? */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
315 case UnmapNotify: {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
316 #ifdef DEBUG_XEVENTS
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
317 printf("UnmapNotify!\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
318 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
319 /* If we're active, make ourselves inactive */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
320 if ( SDL_GetAppState() & SDL_APPACTIVE ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
321 /* Swap out the gamma before we go inactive */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
322 X11_SwapVidModeGamma(this);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
323
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
324 /* Send an internal deactivate event */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
325 posted = SDL_PrivateAppActive(0,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
326 SDL_APPACTIVE|SDL_APPINPUTFOCUS);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
327 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
328 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
329 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
330
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
331 /* Have we been restored? */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
332 case MapNotify: {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
333 #ifdef DEBUG_XEVENTS
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
334 printf("MapNotify!\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
335 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
336 /* If we're not active, make ourselves active */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
337 if ( !(SDL_GetAppState() & SDL_APPACTIVE) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
338 /* Send an internal activate event */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
339 posted = SDL_PrivateAppActive(1, SDL_APPACTIVE);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
340
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
341 /* Now that we're active, swap the gamma back */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
342 X11_SwapVidModeGamma(this);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
343 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
344
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
345 if ( SDL_VideoSurface &&
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
346 (SDL_VideoSurface->flags & SDL_FULLSCREEN) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
347 X11_EnterFullScreen(this);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
348 } else {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
349 X11_GrabInputNoLock(this, this->input_grab);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
350 }
8
5574376c451d Fixed relative motion checking after restore under X11
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
351 X11_CheckMouseModeNoLock(this);
5574376c451d Fixed relative motion checking after restore under X11
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
352
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
353 if ( SDL_VideoSurface ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
354 X11_RefreshDisplay(this);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
355 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
356 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
357 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
358
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
359 /* Have we been resized or moved? */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
360 case ConfigureNotify: {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
361 #ifdef DEBUG_XEVENTS
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
362 printf("ConfigureNotify! (resize: %dx%d)\n", xevent.xconfigure.width, xevent.xconfigure.height);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
363 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
364 if ( SDL_VideoSurface ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
365 if ((xevent.xconfigure.width != SDL_VideoSurface->w) ||
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
366 (xevent.xconfigure.height != SDL_VideoSurface->h)) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
367 /* FIXME: Find a better fix for the bug with KDE 1.2 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
368 if ( ! ((xevent.xconfigure.width == 32) &&
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
369 (xevent.xconfigure.height == 32)) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
370 SDL_PrivateResize(xevent.xconfigure.width,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
371 xevent.xconfigure.height);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
372 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
373 } else {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
374 /* OpenGL windows need to know about the change */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
375 if ( SDL_VideoSurface->flags & SDL_OPENGL ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
376 SDL_PrivateExpose();
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
377 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
378 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
379 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
380 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
381 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
382
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
383 /* Have we been requested to quit (or another client message?) */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
384 case ClientMessage: {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
385 if ( (xevent.xclient.format == 32) &&
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
386 (xevent.xclient.data.l[0] == WM_DELETE_WINDOW) )
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
387 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
388 posted = SDL_PrivateQuit();
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
389 } else
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
390 if ( SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
391 SDL_SysWMmsg wmmsg;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
392
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
393 SDL_VERSION(&wmmsg.version);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
394 wmmsg.subsystem = SDL_SYSWM_X11;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
395 wmmsg.event.xevent = xevent;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
396 posted = SDL_PrivateSysWMEvent(&wmmsg);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
397 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
398 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
399 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
400
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
401 /* Do we need to refresh ourselves? */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
402 case Expose: {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
403 #ifdef DEBUG_XEVENTS
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
404 printf("Expose (count = %d)\n", xevent.xexpose.count);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
405 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
406 if ( SDL_VideoSurface && (xevent.xexpose.count == 0) ) {
161
eb6b76a95f2d An expose event is now sent when using XVideo output.
Sam Lantinga <slouken@libsdl.org>
parents: 111
diff changeset
407 X11_RefreshDisplay(this);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
408 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
409 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
410 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
411
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
412 default: {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
413 #ifdef DEBUG_XEVENTS
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
414 printf("Unhandled event %d\n", xevent.type);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
415 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
416 /* Only post the event if we're watching for it */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
417 if ( SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
418 SDL_SysWMmsg wmmsg;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
419
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
420 SDL_VERSION(&wmmsg.version);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
421 wmmsg.subsystem = SDL_SYSWM_X11;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
422 wmmsg.event.xevent = xevent;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
423 posted = SDL_PrivateSysWMEvent(&wmmsg);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
424 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
425 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
426 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
427 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
428 return(posted);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
429 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
430
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
431 /* Ack! XPending() actually performs a blocking read if no events available */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
432 int X11_Pending(Display *display)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
433 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
434 /* Flush the display connection and look to see if events are queued */
1168
045f186426e1 Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 1159
diff changeset
435 pXFlush(display);
045f186426e1 Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 1159
diff changeset
436 if ( pXEventsQueued(display, QueuedAlready) ) {
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
437 return(1);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
438 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
439
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
440 /* More drastic measures are required -- see if X is ready to talk */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
441 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
442 static struct timeval zero_time; /* static == 0 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
443 int x11_fd;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
444 fd_set fdset;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
445
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
446 x11_fd = ConnectionNumber(display);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
447 FD_ZERO(&fdset);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
448 FD_SET(x11_fd, &fdset);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
449 if ( select(x11_fd+1, &fdset, NULL, NULL, &zero_time) == 1 ) {
1168
045f186426e1 Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 1159
diff changeset
450 return(pXPending(display));
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
451 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
452 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
453
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
454 /* Oh well, nothing is ready .. */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
455 return(0);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
456 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
457
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
458 void X11_PumpEvents(_THIS)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
459 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
460 int pending;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
461
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
462 /* Keep processing pending events */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
463 pending = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
464 while ( X11_Pending(SDL_Display) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
465 X11_DispatchEvent(this);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
466 ++pending;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
467 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
468 if ( switch_waiting ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
469 Uint32 now;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
470
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
471 now = SDL_GetTicks();
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
472 if ( pending || !SDL_VideoSurface ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
473 /* Try again later... */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
474 if ( switch_waiting & SDL_FULLSCREEN ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
475 switch_time = now + 1500;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
476 } else {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
477 switch_time = now + 200;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
478 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
479 } else if ( now >= switch_time ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
480 Uint32 go_fullscreen;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
481
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
482 go_fullscreen = switch_waiting & SDL_FULLSCREEN;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
483 switch_waiting = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
484 if ( SDL_VideoSurface->flags & SDL_FULLSCREEN ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
485 if ( go_fullscreen ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
486 X11_EnterFullScreen(this);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
487 } else {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
488 X11_LeaveFullScreen(this);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
489 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
490 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
491 /* Handle focus in/out when grabbed */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
492 if ( go_fullscreen ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
493 X11_GrabInputNoLock(this, this->input_grab);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
494 } else {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
495 X11_GrabInputNoLock(this, SDL_GRAB_OFF);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
496 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
497 X11_CheckMouseModeNoLock(this);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
498 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
499 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
500 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
501
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
502 void X11_InitKeymap(void)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
503 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
504 int i;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
505
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
506 /* Odd keys used in international keyboards */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
507 for ( i=0; i<SDL_TABLESIZE(ODD_keymap); ++i )
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
508 ODD_keymap[i] = SDLK_UNKNOWN;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
509
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
510 #ifdef XK_dead_circumflex
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
511 /* These X keysyms have 0xFE as the high byte */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
512 ODD_keymap[XK_dead_circumflex&0xFF] = SDLK_CARET;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
513 #endif
805
df1a3218b468 Date: Wed, 04 Feb 2004 13:51:56 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
514 #ifdef XK_ISO_Level3_Shift
df1a3218b468 Date: Wed, 04 Feb 2004 13:51:56 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
515 ODD_keymap[XK_ISO_Level3_Shift&0xFF] = SDLK_MODE; /* "Alt Gr" key */
df1a3218b468 Date: Wed, 04 Feb 2004 13:51:56 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
516 #endif
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
517
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
518 /* Map the miscellaneous keys */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
519 for ( i=0; i<SDL_TABLESIZE(MISC_keymap); ++i )
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
520 MISC_keymap[i] = SDLK_UNKNOWN;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
521
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
522 /* These X keysyms have 0xFF as the high byte */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
523 MISC_keymap[XK_BackSpace&0xFF] = SDLK_BACKSPACE;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
524 MISC_keymap[XK_Tab&0xFF] = SDLK_TAB;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
525 MISC_keymap[XK_Clear&0xFF] = SDLK_CLEAR;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
526 MISC_keymap[XK_Return&0xFF] = SDLK_RETURN;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
527 MISC_keymap[XK_Pause&0xFF] = SDLK_PAUSE;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
528 MISC_keymap[XK_Escape&0xFF] = SDLK_ESCAPE;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
529 MISC_keymap[XK_Delete&0xFF] = SDLK_DELETE;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
530
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
531 MISC_keymap[XK_KP_0&0xFF] = SDLK_KP0; /* Keypad 0-9 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
532 MISC_keymap[XK_KP_1&0xFF] = SDLK_KP1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
533 MISC_keymap[XK_KP_2&0xFF] = SDLK_KP2;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
534 MISC_keymap[XK_KP_3&0xFF] = SDLK_KP3;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
535 MISC_keymap[XK_KP_4&0xFF] = SDLK_KP4;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
536 MISC_keymap[XK_KP_5&0xFF] = SDLK_KP5;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
537 MISC_keymap[XK_KP_6&0xFF] = SDLK_KP6;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
538 MISC_keymap[XK_KP_7&0xFF] = SDLK_KP7;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
539 MISC_keymap[XK_KP_8&0xFF] = SDLK_KP8;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
540 MISC_keymap[XK_KP_9&0xFF] = SDLK_KP9;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
541 MISC_keymap[XK_KP_Insert&0xFF] = SDLK_KP0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
542 MISC_keymap[XK_KP_End&0xFF] = SDLK_KP1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
543 MISC_keymap[XK_KP_Down&0xFF] = SDLK_KP2;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
544 MISC_keymap[XK_KP_Page_Down&0xFF] = SDLK_KP3;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
545 MISC_keymap[XK_KP_Left&0xFF] = SDLK_KP4;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
546 MISC_keymap[XK_KP_Begin&0xFF] = SDLK_KP5;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
547 MISC_keymap[XK_KP_Right&0xFF] = SDLK_KP6;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
548 MISC_keymap[XK_KP_Home&0xFF] = SDLK_KP7;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
549 MISC_keymap[XK_KP_Up&0xFF] = SDLK_KP8;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
550 MISC_keymap[XK_KP_Page_Up&0xFF] = SDLK_KP9;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
551 MISC_keymap[XK_KP_Delete&0xFF] = SDLK_KP_PERIOD;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
552 MISC_keymap[XK_KP_Decimal&0xFF] = SDLK_KP_PERIOD;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
553 MISC_keymap[XK_KP_Divide&0xFF] = SDLK_KP_DIVIDE;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
554 MISC_keymap[XK_KP_Multiply&0xFF] = SDLK_KP_MULTIPLY;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
555 MISC_keymap[XK_KP_Subtract&0xFF] = SDLK_KP_MINUS;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
556 MISC_keymap[XK_KP_Add&0xFF] = SDLK_KP_PLUS;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
557 MISC_keymap[XK_KP_Enter&0xFF] = SDLK_KP_ENTER;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
558 MISC_keymap[XK_KP_Equal&0xFF] = SDLK_KP_EQUALS;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
559
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
560 MISC_keymap[XK_Up&0xFF] = SDLK_UP;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
561 MISC_keymap[XK_Down&0xFF] = SDLK_DOWN;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
562 MISC_keymap[XK_Right&0xFF] = SDLK_RIGHT;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
563 MISC_keymap[XK_Left&0xFF] = SDLK_LEFT;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
564 MISC_keymap[XK_Insert&0xFF] = SDLK_INSERT;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
565 MISC_keymap[XK_Home&0xFF] = SDLK_HOME;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
566 MISC_keymap[XK_End&0xFF] = SDLK_END;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
567 MISC_keymap[XK_Page_Up&0xFF] = SDLK_PAGEUP;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
568 MISC_keymap[XK_Page_Down&0xFF] = SDLK_PAGEDOWN;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
569
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
570 MISC_keymap[XK_F1&0xFF] = SDLK_F1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
571 MISC_keymap[XK_F2&0xFF] = SDLK_F2;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
572 MISC_keymap[XK_F3&0xFF] = SDLK_F3;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
573 MISC_keymap[XK_F4&0xFF] = SDLK_F4;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
574 MISC_keymap[XK_F5&0xFF] = SDLK_F5;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
575 MISC_keymap[XK_F6&0xFF] = SDLK_F6;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
576 MISC_keymap[XK_F7&0xFF] = SDLK_F7;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
577 MISC_keymap[XK_F8&0xFF] = SDLK_F8;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
578 MISC_keymap[XK_F9&0xFF] = SDLK_F9;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
579 MISC_keymap[XK_F10&0xFF] = SDLK_F10;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
580 MISC_keymap[XK_F11&0xFF] = SDLK_F11;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
581 MISC_keymap[XK_F12&0xFF] = SDLK_F12;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
582 MISC_keymap[XK_F13&0xFF] = SDLK_F13;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
583 MISC_keymap[XK_F14&0xFF] = SDLK_F14;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
584 MISC_keymap[XK_F15&0xFF] = SDLK_F15;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
585
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
586 MISC_keymap[XK_Num_Lock&0xFF] = SDLK_NUMLOCK;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
587 MISC_keymap[XK_Caps_Lock&0xFF] = SDLK_CAPSLOCK;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
588 MISC_keymap[XK_Scroll_Lock&0xFF] = SDLK_SCROLLOCK;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
589 MISC_keymap[XK_Shift_R&0xFF] = SDLK_RSHIFT;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
590 MISC_keymap[XK_Shift_L&0xFF] = SDLK_LSHIFT;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
591 MISC_keymap[XK_Control_R&0xFF] = SDLK_RCTRL;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
592 MISC_keymap[XK_Control_L&0xFF] = SDLK_LCTRL;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
593 MISC_keymap[XK_Alt_R&0xFF] = SDLK_RALT;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
594 MISC_keymap[XK_Alt_L&0xFF] = SDLK_LALT;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
595 MISC_keymap[XK_Meta_R&0xFF] = SDLK_RMETA;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
596 MISC_keymap[XK_Meta_L&0xFF] = SDLK_LMETA;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
597 MISC_keymap[XK_Super_L&0xFF] = SDLK_LSUPER; /* Left "Windows" */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
598 MISC_keymap[XK_Super_R&0xFF] = SDLK_RSUPER; /* Right "Windows */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
599 MISC_keymap[XK_Mode_switch&0xFF] = SDLK_MODE; /* "Alt Gr" key */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
600 MISC_keymap[XK_Multi_key&0xFF] = SDLK_COMPOSE; /* Multi-key compose */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
601
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
602 MISC_keymap[XK_Help&0xFF] = SDLK_HELP;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
603 MISC_keymap[XK_Print&0xFF] = SDLK_PRINT;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
604 MISC_keymap[XK_Sys_Req&0xFF] = SDLK_SYSREQ;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
605 MISC_keymap[XK_Break&0xFF] = SDLK_BREAK;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
606 MISC_keymap[XK_Menu&0xFF] = SDLK_MENU;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
607 MISC_keymap[XK_Hyper_R&0xFF] = SDLK_MENU; /* Windows "Menu" key */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
608 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
609
1178
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
610 #ifdef X_HAVE_UTF8_STRING
1196
b81f54c3963f Fixed compile warnings with gcc 4
Sam Lantinga <slouken@libsdl.org>
parents: 1179
diff changeset
611 Uint32 Utf8ToUcs4(const unsigned char *utf8)
1178
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
612 {
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
613 Uint32 c;
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
614 int i = 1;
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
615 int noOctets = 0;
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
616 int firstOctetMask = 0;
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
617 unsigned char firstOctet = utf8[0];
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
618 if (firstOctet < 0x80) {
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
619 /*
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
620 Characters in the range:
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
621 00000000 to 01111111 (ASCII Range)
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
622 are stored in one octet:
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
623 0xxxxxxx (The same as its ASCII representation)
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
624 The least 6 significant bits of the first octet is the most 6 significant nonzero bits
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
625 of the UCS4 representation.
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
626 */
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
627 noOctets = 1;
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
628 firstOctetMask = 0x7F; /* 0(1111111) - The most significant bit is ignored */
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
629 } else if ((firstOctet & 0xE0) /* get the most 3 significant bits by AND'ing with 11100000 */
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
630 == 0xC0 ) { /* see if those 3 bits are 110. If so, the char is in this range */
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
631 /*
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
632 Characters in the range:
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
633 00000000 10000000 to 00000111 11111111
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
634 are stored in two octets:
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
635 110xxxxx 10xxxxxx
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
636 The least 5 significant bits of the first octet is the most 5 significant nonzero bits
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
637 of the UCS4 representation.
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
638 */
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
639 noOctets = 2;
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
640 firstOctetMask = 0x1F; /* 000(11111) - The most 3 significant bits are ignored */
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
641 } else if ((firstOctet & 0xF0) /* get the most 4 significant bits by AND'ing with 11110000 */
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
642 == 0xE0) { /* see if those 4 bits are 1110. If so, the char is in this range */
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
643 /*
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
644 Characters in the range:
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
645 00001000 00000000 to 11111111 11111111
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
646 are stored in three octets:
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
647 1110xxxx 10xxxxxx 10xxxxxx
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
648 The least 4 significant bits of the first octet is the most 4 significant nonzero bits
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
649 of the UCS4 representation.
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
650 */
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
651 noOctets = 3;
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
652 firstOctetMask = 0x0F; /* 0000(1111) - The most 4 significant bits are ignored */
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
653 } else if ((firstOctet & 0xF8) /* get the most 5 significant bits by AND'ing with 11111000 */
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
654 == 0xF0) { /* see if those 5 bits are 11110. If so, the char is in this range */
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
655 /*
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
656 Characters in the range:
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
657 00000001 00000000 00000000 to 00011111 11111111 11111111
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
658 are stored in four octets:
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
659 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
660 The least 3 significant bits of the first octet is the most 3 significant nonzero bits
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
661 of the UCS4 representation.
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
662 */
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
663 noOctets = 4;
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
664 firstOctetMask = 0x07; /* 11110(111) - The most 5 significant bits are ignored */
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
665 } else if ((firstOctet & 0xFC) /* get the most 6 significant bits by AND'ing with 11111100 */
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
666 == 0xF8) { /* see if those 6 bits are 111110. If so, the char is in this range */
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
667 /*
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
668 Characters in the range:
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
669 00000000 00100000 00000000 00000000 to
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
670 00000011 11111111 11111111 11111111
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
671 are stored in five octets:
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
672 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
673 The least 2 significant bits of the first octet is the most 2 significant nonzero bits
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
674 of the UCS4 representation.
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
675 */
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
676 noOctets = 5;
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
677 firstOctetMask = 0x03; /* 111110(11) - The most 6 significant bits are ignored */
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
678 } else if ((firstOctet & 0xFE) /* get the most 7 significant bits by AND'ing with 11111110 */
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
679 == 0xFC) { /* see if those 7 bits are 1111110. If so, the char is in this range */
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
680 /*
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
681 Characters in the range:
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
682 00000100 00000000 00000000 00000000 to
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
683 01111111 11111111 11111111 11111111
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
684 are stored in six octets:
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
685 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
686 The least significant bit of the first octet is the most significant nonzero bit
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
687 of the UCS4 representation.
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
688 */
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
689 noOctets = 6;
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
690 firstOctetMask = 0x01; /* 1111110(1) - The most 7 significant bits are ignored */
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
691 } else
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
692 return 0; /* The given chunk is not a valid UTF-8 encoded Unicode character */
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
693
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
694 /*
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
695 The least noOctets significant bits of the first octet is the most 2 significant nonzero bits
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
696 of the UCS4 representation.
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
697 The first 6 bits of the UCS4 representation is the least 8-noOctets-1 significant bits of
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
698 firstOctet if the character is not ASCII. If so, it's the least 7 significant bits of firstOctet.
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
699 This done by AND'ing firstOctet with its mask to trim the bits used for identifying the
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
700 number of continuing octets (if any) and leave only the free bits (the x's)
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
701 Sample:
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
702 1-octet: 0xxxxxxx & 01111111 = 0xxxxxxx
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
703 2-octets: 110xxxxx & 00011111 = 000xxxxx
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
704 */
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
705 c = firstOctet & firstOctetMask;
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
706
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
707 /* Now, start filling c.ucs4 with the bits from the continuing octets from utf8. */
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
708 for (i = 1; i < noOctets; i++) {
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
709 /* A valid continuing octet is of the form 10xxxxxx */
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
710 if ((utf8[i] & 0xC0) /* get the most 2 significant bits by AND'ing with 11000000 */
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
711 != 0x80) /* see if those 2 bits are 10. If not, the is a malformed sequence. */
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
712 /*The given chunk is a partial sequence at the end of a string that could
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
713 begin a valid character */
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
714 return 0;
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
715
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
716 /* Make room for the next 6-bits */
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
717 c <<= 6;
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
718
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
719 /*
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
720 Take only the least 6 significance bits of the current octet (utf8[i]) and fill the created room
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
721 of c.ucs4 with them.
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
722 This done by AND'ing utf8[i] with 00111111 and the OR'ing the result with c.ucs4.
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
723 */
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
724 c |= utf8[i] & 0x3F;
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
725 }
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
726 return c;
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
727 }
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
728 #endif
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
729
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
730
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
731 SDL_keysym *X11_TranslateKey(Display *display, XIC ic, XKeyEvent *xkey, KeyCode kc,
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
732 SDL_keysym *keysym)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
733 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
734 KeySym xsym;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
735
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
736 /* Get the raw keyboard scancode */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
737 keysym->scancode = kc;
1168
045f186426e1 Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 1159
diff changeset
738 xsym = pXKeycodeToKeysym(display, kc, 0);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
739 #ifdef DEBUG_KEYS
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
740 fprintf(stderr, "Translating key 0x%.4x (%d)\n", xsym, kc);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
741 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
742 /* Get the translated SDL virtual keysym */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
743 keysym->sym = SDLK_UNKNOWN;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
744 if ( xsym ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
745 switch (xsym>>8) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
746 case 0x1005FF:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
747 #ifdef SunXK_F36
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
748 if ( xsym == SunXK_F36 )
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
749 keysym->sym = SDLK_F11;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
750 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
751 #ifdef SunXK_F37
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
752 if ( xsym == SunXK_F37 )
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
753 keysym->sym = SDLK_F12;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
754 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
755 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
756 case 0x00: /* Latin 1 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
757 case 0x01: /* Latin 2 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
758 case 0x02: /* Latin 3 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
759 case 0x03: /* Latin 4 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
760 case 0x04: /* Katakana */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
761 case 0x05: /* Arabic */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
762 case 0x06: /* Cyrillic */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
763 case 0x07: /* Greek */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
764 case 0x08: /* Technical */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
765 case 0x0A: /* Publishing */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
766 case 0x0C: /* Hebrew */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
767 case 0x0D: /* Thai */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
768 keysym->sym = (SDLKey)(xsym&0xFF);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
769 /* Map capital letter syms to lowercase */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
770 if ((keysym->sym >= 'A')&&(keysym->sym <= 'Z'))
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
771 keysym->sym += ('a'-'A');
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
772 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
773 case 0xFE:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
774 keysym->sym = ODD_keymap[xsym&0xFF];
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
775 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
776 case 0xFF:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
777 keysym->sym = MISC_keymap[xsym&0xFF];
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
778 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
779 default:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
780 fprintf(stderr,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
781 "X11: Unknown xsym, sym = 0x%04x\n",
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
782 (unsigned int)xsym);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
783 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
784 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
785 } else {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
786 /* X11 doesn't know how to translate the key! */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
787 switch (kc) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
788 /* Caution:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
789 These keycodes are from the Microsoft Keyboard
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
790 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
791 case 115:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
792 keysym->sym = SDLK_LSUPER;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
793 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
794 case 116:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
795 keysym->sym = SDLK_RSUPER;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
796 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
797 case 117:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
798 keysym->sym = SDLK_MENU;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
799 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
800 default:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
801 /*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
802 * no point in an error message; happens for
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
803 * several keys when we get a keymap notify
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
804 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
805 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
806 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
807 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
808 keysym->mod = KMOD_NONE;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
809
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
810 /* If UNICODE is on, get the UNICODE value for the key */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
811 keysym->unicode = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
812 if ( SDL_TranslateUNICODE && xkey ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
813 static XComposeStatus state;
1178
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
814
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
815
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
816 #define BROKEN_XFREE86_INTERNATIONAL_KBD
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
817 /* This appears to be a magical flag that is used with AltGr on
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
818 international keyboards to signal alternate key translations.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
819 The flag doesn't show up when in fullscreen mode (?)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
820 FIXME: Check to see if this code is safe for other servers.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
821 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
822 #ifdef BROKEN_XFREE86_INTERNATIONAL_KBD
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
823 /* Work around what appears to be a bug in XFree86 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
824 if ( SDL_GetModState() & KMOD_MODE ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
825 xkey->state |= (1<<13);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
826 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
827 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
828 /* Look up the translated value for the key event */
1178
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
829
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
830 /* if there is no connection with the IM server, use the regular method */
1179
abb4267e7028 Don't use X11 unicode keys on anything but keypress events.
Ryan C. Gordon <icculus@icculus.org>
parents: 1178
diff changeset
831 if (ic == NULL || xkey->type != KeyPress) {
1178
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
832 unsigned char keybuf[32];
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
833
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
834 if ( pXLookupString(xkey, (char *)keybuf, sizeof(keybuf),
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
835 NULL, &state) ) {
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
836 /*
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
837 * FIXME,: XLookupString() may yield more than one
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
838 * character, so we need a mechanism to allow for
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
839 * this (perhaps generate null keypress events with
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
840 * a unicode value)
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
841 */
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
842 keysym->unicode = keybuf[0];
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
843 }
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
844 } else { /* else, use the IM protocol */
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
845 #ifdef X_HAVE_UTF8_STRING
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
846 /* A UTF-8 character can be at most 6 bytes */
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
847 unsigned char keybuf[6];
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
848 pXSetICFocus(ic);
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
849 if ( pXutf8LookupString(ic, (XKeyPressedEvent *)xkey, (char *)keybuf, sizeof(keybuf),
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
850 NULL, (Status *)&state) )
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
851 keysym->unicode = Utf8ToUcs4(keybuf);
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
852 pXUnsetICFocus(ic);
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
853 #endif
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
854 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
855 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
856 return(keysym);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
857 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
858
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
859 /* X11 modifier masks for various keys */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
860 static unsigned meta_l_mask, meta_r_mask, alt_l_mask, alt_r_mask;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
861 static unsigned num_mask, mode_switch_mask;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
862
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
863 static void get_modifier_masks(Display *display)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
864 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
865 static unsigned got_masks;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
866 int i, j;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
867 XModifierKeymap *xmods;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
868 unsigned n;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
869
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
870 if(got_masks)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
871 return;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
872
1168
045f186426e1 Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 1159
diff changeset
873 xmods = pXGetModifierMapping(display);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
874 n = xmods->max_keypermod;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
875 for(i = 3; i < 8; i++) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
876 for(j = 0; j < n; j++) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
877 KeyCode kc = xmods->modifiermap[i * n + j];
1168
045f186426e1 Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 1159
diff changeset
878 KeySym ks = pXKeycodeToKeysym(display, kc, 0);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
879 unsigned mask = 1 << i;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
880 switch(ks) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
881 case XK_Num_Lock:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
882 num_mask = mask; break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
883 case XK_Alt_L:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
884 alt_l_mask = mask; break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
885 case XK_Alt_R:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
886 alt_r_mask = mask; break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
887 case XK_Meta_L:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
888 meta_l_mask = mask; break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
889 case XK_Meta_R:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
890 meta_r_mask = mask; break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
891 case XK_Mode_switch:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
892 mode_switch_mask = mask; break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
893 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
894 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
895 }
1168
045f186426e1 Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 1159
diff changeset
896 pXFreeModifiermap(xmods);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
897 got_masks = 1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
898 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
899
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
900
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
901 /*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
902 * This function is semi-official; it is not officially exported and should
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
903 * not be considered part of the SDL API, but may be used by client code
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
904 * that *really* needs it (including legacy code).
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
905 * It is slow, though, and should be avoided if possible.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
906 *
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
907 * Note that it isn't completely accurate either; in particular, multi-key
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
908 * sequences (dead accents, compose key sequences) will not work since the
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
909 * state has been irrevocably lost.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
910 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
911 Uint16 X11_KeyToUnicode(SDLKey keysym, SDLMod modifiers)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
912 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
913 struct SDL_VideoDevice *this = current_video;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
914 char keybuf[32];
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
915 int i;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
916 KeySym xsym = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
917 XKeyEvent xkey;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
918 Uint16 unicode;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
919
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
920 if ( !this || !SDL_Display ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
921 return 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
922 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
923
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
924 memset(&xkey, 0, sizeof(xkey));
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
925 xkey.display = SDL_Display;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
926
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
927 xsym = keysym; /* last resort if not found */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
928 for (i = 0; i < 256; ++i) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
929 if ( MISC_keymap[i] == keysym ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
930 xsym = 0xFF00 | i;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
931 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
932 } else if ( ODD_keymap[i] == keysym ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
933 xsym = 0xFE00 | i;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
934 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
935 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
936 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
937
1168
045f186426e1 Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 1159
diff changeset
938 xkey.keycode = pXKeysymToKeycode(xkey.display, xsym);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
939
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
940 get_modifier_masks(SDL_Display);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
941 if(modifiers & KMOD_SHIFT)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
942 xkey.state |= ShiftMask;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
943 if(modifiers & KMOD_CAPS)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
944 xkey.state |= LockMask;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
945 if(modifiers & KMOD_CTRL)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
946 xkey.state |= ControlMask;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
947 if(modifiers & KMOD_MODE)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
948 xkey.state |= mode_switch_mask;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
949 if(modifiers & KMOD_LALT)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
950 xkey.state |= alt_l_mask;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
951 if(modifiers & KMOD_RALT)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
952 xkey.state |= alt_r_mask;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
953 if(modifiers & KMOD_LMETA)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
954 xkey.state |= meta_l_mask;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
955 if(modifiers & KMOD_RMETA)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
956 xkey.state |= meta_r_mask;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
957 if(modifiers & KMOD_NUM)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
958 xkey.state |= num_mask;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
959
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
960 unicode = 0;
1168
045f186426e1 Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 1159
diff changeset
961 if ( pXLookupString(&xkey, keybuf, sizeof(keybuf), NULL, NULL) )
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
962 unicode = (unsigned char)keybuf[0];
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
963 return(unicode);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
964 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
965
1178
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
966
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
967 /*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
968 * Called when focus is regained, to read the keyboard state and generate
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
969 * synthetic keypress/release events.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
970 * key_vec is a bit vector of keycodes (256 bits)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
971 */
1178
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
972 void X11_SetKeyboardState(Display *display, XIC ic, const char *key_vec)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
973 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
974 char keys_return[32];
412
ac59b067815b Fix uninitialized variable warning
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
975 int i;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
976 KeyCode xcode[SDLK_LAST];
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
977 Uint8 new_kstate[SDLK_LAST];
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
978 Uint8 *kstate = SDL_GetKeyState(NULL);
111
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
979 SDLMod modstate;
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
980 Window junk_window;
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
981 int x, y;
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
982 unsigned int mask;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
983
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
984 /* The first time the window is mapped, we initialize key state */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
985 if ( ! key_vec ) {
1168
045f186426e1 Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 1159
diff changeset
986 pXQueryKeymap(display, keys_return);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
987 key_vec = keys_return;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
988 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
989
111
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
990 /* Get the keyboard modifier state */
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
991 modstate = 0;
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
992 get_modifier_masks(display);
1168
045f186426e1 Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 1159
diff changeset
993 if ( pXQueryPointer(display, DefaultRootWindow(display),
111
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
994 &junk_window, &junk_window, &x, &y, &x, &y, &mask) ) {
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
995 if ( mask & LockMask ) {
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
996 modstate |= KMOD_CAPS;
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
997 }
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
998 if ( mask & mode_switch_mask ) {
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
999 modstate |= KMOD_MODE;
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1000 }
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1001 if ( mask & num_mask ) {
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1002 modstate |= KMOD_NUM;
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1003 }
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1004 }
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1005
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1006 /* Zero the new keyboard state and generate it */
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1007 memset(new_kstate, SDL_RELEASED, sizeof(new_kstate));
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1008 /*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1009 * An obvious optimisation is to check entire longwords at a time in
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1010 * both loops, but we can't be sure the arrays are aligned so it's not
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1011 * worth the extra complexity
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1012 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1013 for(i = 0; i < 32; i++) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1014 int j;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1015 if(!key_vec[i])
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1016 continue;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1017 for(j = 0; j < 8; j++) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1018 if(key_vec[i] & (1 << j)) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1019 SDL_keysym sk;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1020 KeyCode kc = i << 3 | j;
1178
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
1021 X11_TranslateKey(display, ic, NULL, kc, &sk);
111
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1022 new_kstate[sk.sym] = SDL_PRESSED;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1023 xcode[sk.sym] = kc;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1024 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1025 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1026 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1027 for(i = SDLK_FIRST+1; i < SDLK_LAST; i++) {
111
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1028 int state = new_kstate[i];
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1029
111
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1030 if ( state == SDL_PRESSED ) {
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1031 switch (i) {
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1032 case SDLK_LSHIFT:
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1033 modstate |= KMOD_LSHIFT;
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1034 break;
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1035 case SDLK_RSHIFT:
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1036 modstate |= KMOD_RSHIFT;
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1037 break;
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1038 case SDLK_LCTRL:
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1039 modstate |= KMOD_LCTRL;
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1040 break;
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1041 case SDLK_RCTRL:
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1042 modstate |= KMOD_RCTRL;
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1043 break;
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1044 case SDLK_LALT:
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1045 modstate |= KMOD_LALT;
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1046 break;
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1047 case SDLK_RALT:
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1048 modstate |= KMOD_RALT;
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1049 break;
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1050 case SDLK_LMETA:
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1051 modstate |= KMOD_LMETA;
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1052 break;
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1053 case SDLK_RMETA:
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1054 modstate |= KMOD_RMETA;
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1055 break;
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1056 default:
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1057 break;
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1058 }
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1059 }
412
ac59b067815b Fix uninitialized variable warning
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1060 if ( kstate[i] != state ) {
111
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1061 kstate[i] = state;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1062 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1063 }
111
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1064
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1065 /* Hack - set toggle key state */
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1066 if ( modstate & KMOD_CAPS ) {
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1067 kstate[SDLK_CAPSLOCK] = SDL_PRESSED;
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1068 } else {
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1069 kstate[SDLK_CAPSLOCK] = SDL_RELEASED;
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1070 }
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1071 if ( modstate & KMOD_NUM ) {
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1072 kstate[SDLK_NUMLOCK] = SDL_PRESSED;
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1073 } else {
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1074 kstate[SDLK_NUMLOCK] = SDL_RELEASED;
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1075 }
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1076
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1077 /* Set the final modifier state */
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1078 SDL_SetModState(modstate);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1079 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1080
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1081 void X11_InitOSKeymap(_THIS)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1082 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1083 X11_InitKeymap();
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1084 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1085