comparison src/video/x11/SDL_x11events.c @ 1662:782fd950bd46 SDL-1.3

Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API. WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid. The code is now run through a consistent indent format: indent -i4 -nut -nsc -br -ce The headers are being converted to automatically generate doxygen documentation.
author Sam Lantinga <slouken@libsdl.org>
date Sun, 28 May 2006 13:04:16 +0000
parents 14717b52abc0
children 4da1ee79c9af
comparison
equal deleted inserted replaced
1661:281d3f4870e5 1662:782fd950bd46
53 /*#define DEBUG_XEVENTS*/ 53 /*#define DEBUG_XEVENTS*/
54 54
55 /* The translation tables from an X11 keysym to a SDL keysym */ 55 /* The translation tables from an X11 keysym to a SDL keysym */
56 static SDLKey ODD_keymap[256]; 56 static SDLKey ODD_keymap[256];
57 static SDLKey MISC_keymap[256]; 57 static SDLKey MISC_keymap[256];
58 SDLKey X11_TranslateKeycode(Display *display, KeyCode kc); 58 SDLKey X11_TranslateKeycode (Display * display, KeyCode kc);
59 59
60 60
61 #ifdef X_HAVE_UTF8_STRING 61 #ifdef X_HAVE_UTF8_STRING
62 Uint32 Utf8ToUcs4(const Uint8 *utf8) 62 Uint32
63 { 63 Utf8ToUcs4 (const Uint8 * utf8)
64 Uint32 c; 64 {
65 int i = 1; 65 Uint32 c;
66 int noOctets = 0; 66 int i = 1;
67 int firstOctetMask = 0; 67 int noOctets = 0;
68 unsigned char firstOctet = utf8[0]; 68 int firstOctetMask = 0;
69 if (firstOctet < 0x80) { 69 unsigned char firstOctet = utf8[0];
70 /* 70 if (firstOctet < 0x80) {
71 Characters in the range: 71 /*
72 00000000 to 01111111 (ASCII Range) 72 Characters in the range:
73 are stored in one octet: 73 00000000 to 01111111 (ASCII Range)
74 0xxxxxxx (The same as its ASCII representation) 74 are stored in one octet:
75 The least 6 significant bits of the first octet is the most 6 significant nonzero bits 75 0xxxxxxx (The same as its ASCII representation)
76 of the UCS4 representation. 76 The least 6 significant bits of the first octet is the most 6 significant nonzero bits
77 */ 77 of the UCS4 representation.
78 noOctets = 1; 78 */
79 firstOctetMask = 0x7F; /* 0(1111111) - The most significant bit is ignored */ 79 noOctets = 1;
80 } else if ((firstOctet & 0xE0) /* get the most 3 significant bits by AND'ing with 11100000 */ 80 firstOctetMask = 0x7F; /* 0(1111111) - The most significant bit is ignored */
81 == 0xC0 ) { /* see if those 3 bits are 110. If so, the char is in this range */ 81 } else if ((firstOctet & 0xE0) /* get the most 3 significant bits by AND'ing with 11100000 */
82 /* 82 == 0xC0) { /* see if those 3 bits are 110. If so, the char is in this range */
83 Characters in the range: 83 /*
84 00000000 10000000 to 00000111 11111111 84 Characters in the range:
85 are stored in two octets: 85 00000000 10000000 to 00000111 11111111
86 110xxxxx 10xxxxxx 86 are stored in two octets:
87 The least 5 significant bits of the first octet is the most 5 significant nonzero bits 87 110xxxxx 10xxxxxx
88 of the UCS4 representation. 88 The least 5 significant bits of the first octet is the most 5 significant nonzero bits
89 */ 89 of the UCS4 representation.
90 noOctets = 2; 90 */
91 firstOctetMask = 0x1F; /* 000(11111) - The most 3 significant bits are ignored */ 91 noOctets = 2;
92 } else if ((firstOctet & 0xF0) /* get the most 4 significant bits by AND'ing with 11110000 */ 92 firstOctetMask = 0x1F; /* 000(11111) - The most 3 significant bits are ignored */
93 == 0xE0) { /* see if those 4 bits are 1110. If so, the char is in this range */ 93 } else if ((firstOctet & 0xF0) /* get the most 4 significant bits by AND'ing with 11110000 */
94 /* 94 == 0xE0) { /* see if those 4 bits are 1110. If so, the char is in this range */
95 Characters in the range: 95 /*
96 00001000 00000000 to 11111111 11111111 96 Characters in the range:
97 are stored in three octets: 97 00001000 00000000 to 11111111 11111111
98 1110xxxx 10xxxxxx 10xxxxxx 98 are stored in three octets:
99 The least 4 significant bits of the first octet is the most 4 significant nonzero bits 99 1110xxxx 10xxxxxx 10xxxxxx
100 of the UCS4 representation. 100 The least 4 significant bits of the first octet is the most 4 significant nonzero bits
101 */ 101 of the UCS4 representation.
102 noOctets = 3; 102 */
103 firstOctetMask = 0x0F; /* 0000(1111) - The most 4 significant bits are ignored */ 103 noOctets = 3;
104 } else if ((firstOctet & 0xF8) /* get the most 5 significant bits by AND'ing with 11111000 */ 104 firstOctetMask = 0x0F; /* 0000(1111) - The most 4 significant bits are ignored */
105 == 0xF0) { /* see if those 5 bits are 11110. If so, the char is in this range */ 105 } else if ((firstOctet & 0xF8) /* get the most 5 significant bits by AND'ing with 11111000 */
106 /* 106 == 0xF0) { /* see if those 5 bits are 11110. If so, the char is in this range */
107 Characters in the range: 107 /*
108 00000001 00000000 00000000 to 00011111 11111111 11111111 108 Characters in the range:
109 are stored in four octets: 109 00000001 00000000 00000000 to 00011111 11111111 11111111
110 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx 110 are stored in four octets:
111 The least 3 significant bits of the first octet is the most 3 significant nonzero bits 111 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
112 of the UCS4 representation. 112 The least 3 significant bits of the first octet is the most 3 significant nonzero bits
113 */ 113 of the UCS4 representation.
114 noOctets = 4; 114 */
115 firstOctetMask = 0x07; /* 11110(111) - The most 5 significant bits are ignored */ 115 noOctets = 4;
116 } else if ((firstOctet & 0xFC) /* get the most 6 significant bits by AND'ing with 11111100 */ 116 firstOctetMask = 0x07; /* 11110(111) - The most 5 significant bits are ignored */
117 == 0xF8) { /* see if those 6 bits are 111110. If so, the char is in this range */ 117 } else if ((firstOctet & 0xFC) /* get the most 6 significant bits by AND'ing with 11111100 */
118 /* 118 == 0xF8) { /* see if those 6 bits are 111110. If so, the char is in this range */
119 Characters in the range: 119 /*
120 00000000 00100000 00000000 00000000 to 120 Characters in the range:
121 00000011 11111111 11111111 11111111 121 00000000 00100000 00000000 00000000 to
122 are stored in five octets: 122 00000011 11111111 11111111 11111111
123 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 123 are stored in five octets:
124 The least 2 significant bits of the first octet is the most 2 significant nonzero bits 124 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
125 of the UCS4 representation. 125 The least 2 significant bits of the first octet is the most 2 significant nonzero bits
126 */ 126 of the UCS4 representation.
127 noOctets = 5; 127 */
128 firstOctetMask = 0x03; /* 111110(11) - The most 6 significant bits are ignored */ 128 noOctets = 5;
129 } else if ((firstOctet & 0xFE) /* get the most 7 significant bits by AND'ing with 11111110 */ 129 firstOctetMask = 0x03; /* 111110(11) - The most 6 significant bits are ignored */
130 == 0xFC) { /* see if those 7 bits are 1111110. If so, the char is in this range */ 130 } else if ((firstOctet & 0xFE) /* get the most 7 significant bits by AND'ing with 11111110 */
131 /* 131 == 0xFC) { /* see if those 7 bits are 1111110. If so, the char is in this range */
132 Characters in the range: 132 /*
133 00000100 00000000 00000000 00000000 to 133 Characters in the range:
134 01111111 11111111 11111111 11111111 134 00000100 00000000 00000000 00000000 to
135 are stored in six octets: 135 01111111 11111111 11111111 11111111
136 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 136 are stored in six octets:
137 The least significant bit of the first octet is the most significant nonzero bit 137 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
138 of the UCS4 representation. 138 The least significant bit of the first octet is the most significant nonzero bit
139 */ 139 of the UCS4 representation.
140 noOctets = 6; 140 */
141 firstOctetMask = 0x01; /* 1111110(1) - The most 7 significant bits are ignored */ 141 noOctets = 6;
142 } else 142 firstOctetMask = 0x01; /* 1111110(1) - The most 7 significant bits are ignored */
143 return 0; /* The given chunk is not a valid UTF-8 encoded Unicode character */ 143 } else
144 144 return 0; /* The given chunk is not a valid UTF-8 encoded Unicode character */
145 /* 145
146 The least noOctets significant bits of the first octet is the most 2 significant nonzero bits 146 /*
147 of the UCS4 representation. 147 The least noOctets significant bits of the first octet is the most 2 significant nonzero bits
148 The first 6 bits of the UCS4 representation is the least 8-noOctets-1 significant bits of 148 of the UCS4 representation.
149 firstOctet if the character is not ASCII. If so, it's the least 7 significant bits of firstOctet. 149 The first 6 bits of the UCS4 representation is the least 8-noOctets-1 significant bits of
150 This done by AND'ing firstOctet with its mask to trim the bits used for identifying the 150 firstOctet if the character is not ASCII. If so, it's the least 7 significant bits of firstOctet.
151 number of continuing octets (if any) and leave only the free bits (the x's) 151 This done by AND'ing firstOctet with its mask to trim the bits used for identifying the
152 Sample: 152 number of continuing octets (if any) and leave only the free bits (the x's)
153 1-octet: 0xxxxxxx & 01111111 = 0xxxxxxx 153 Sample:
154 2-octets: 110xxxxx & 00011111 = 000xxxxx 154 1-octet: 0xxxxxxx & 01111111 = 0xxxxxxx
155 */ 155 2-octets: 110xxxxx & 00011111 = 000xxxxx
156 c = firstOctet & firstOctetMask; 156 */
157 157 c = firstOctet & firstOctetMask;
158 /* Now, start filling c.ucs4 with the bits from the continuing octets from utf8. */ 158
159 for (i = 1; i < noOctets; i++) { 159 /* Now, start filling c.ucs4 with the bits from the continuing octets from utf8. */
160 /* A valid continuing octet is of the form 10xxxxxx */ 160 for (i = 1; i < noOctets; i++) {
161 if ((utf8[i] & 0xC0) /* get the most 2 significant bits by AND'ing with 11000000 */ 161 /* A valid continuing octet is of the form 10xxxxxx */
162 != 0x80) /* see if those 2 bits are 10. If not, the is a malformed sequence. */ 162 if ((utf8[i] & 0xC0) /* get the most 2 significant bits by AND'ing with 11000000 */
163 /*The given chunk is a partial sequence at the end of a string that could 163 !=0x80)
164 begin a valid character */ 164 /* see if those 2 bits are 10. If not, the is a malformed sequence. */
165 return 0; 165 /*The given chunk is a partial sequence at the end of a string that could
166 166 begin a valid character */
167 /* Make room for the next 6-bits */ 167 return 0;
168 c <<= 6; 168
169 169 /* Make room for the next 6-bits */
170 /* 170 c <<= 6;
171 Take only the least 6 significance bits of the current octet (utf8[i]) and fill the created room 171
172 of c.ucs4 with them. 172 /*
173 This done by AND'ing utf8[i] with 00111111 and the OR'ing the result with c.ucs4. 173 Take only the least 6 significance bits of the current octet (utf8[i]) and fill the created room
174 */ 174 of c.ucs4 with them.
175 c |= utf8[i] & 0x3F; 175 This done by AND'ing utf8[i] with 00111111 and the OR'ing the result with c.ucs4.
176 } 176 */
177 return c; 177 c |= utf8[i] & 0x3F;
178 }
179 return c;
178 } 180 }
179 #endif 181 #endif
180 182
181 /* Check to see if this is a repeated key. 183 /* Check to see if this is a repeated key.
182 (idea shamelessly lifted from GII -- thanks guys! :) 184 (idea shamelessly lifted from GII -- thanks guys! :)
183 */ 185 */
184 static int X11_KeyRepeat(Display *display, XEvent *event) 186 static int
185 { 187 X11_KeyRepeat (Display * display, XEvent * event)
186 XEvent peekevent; 188 {
187 int repeated; 189 XEvent peekevent;
188 190 int repeated;
189 repeated = 0; 191
190 if ( XPending(display) ) { 192 repeated = 0;
191 XPeekEvent(display, &peekevent); 193 if (XPending (display)) {
192 if ( (peekevent.type == KeyPress) && 194 XPeekEvent (display, &peekevent);
193 (peekevent.xkey.keycode == event->xkey.keycode) && 195 if ((peekevent.type == KeyPress) &&
194 ((peekevent.xkey.time-event->xkey.time) < 2) ) { 196 (peekevent.xkey.keycode == event->xkey.keycode) &&
195 repeated = 1; 197 ((peekevent.xkey.time - event->xkey.time) < 2)) {
196 XNextEvent(display, &peekevent); 198 repeated = 1;
197 } 199 XNextEvent (display, &peekevent);
198 } 200 }
199 return(repeated); 201 }
202 return (repeated);
200 } 203 }
201 204
202 /* Note: The X server buffers and accumulates mouse motion events, so 205 /* Note: The X server buffers and accumulates mouse motion events, so
203 the motion event generated by the warp may not appear exactly as we 206 the motion event generated by the warp may not appear exactly as we
204 expect it to. We work around this (and improve performance) by only 207 expect it to. We work around this (and improve performance) by only
205 warping the pointer when it reaches the edge, and then wait for it. 208 warping the pointer when it reaches the edge, and then wait for it.
206 */ 209 */
207 #define MOUSE_FUDGE_FACTOR 8 210 #define MOUSE_FUDGE_FACTOR 8
208 211
209 static __inline__ int X11_WarpedMotion(_THIS, XEvent *xevent) 212 static __inline__ int
210 { 213 X11_WarpedMotion (_THIS, XEvent * xevent)
211 int w, h, i; 214 {
212 int deltax, deltay; 215 int w, h, i;
213 int posted; 216 int deltax, deltay;
214 217 int posted;
215 w = SDL_VideoSurface->w; 218
216 h = SDL_VideoSurface->h; 219 w = SDL_VideoSurface->w;
217 deltax = xevent->xmotion.x - mouse_last.x; 220 h = SDL_VideoSurface->h;
218 deltay = xevent->xmotion.y - mouse_last.y; 221 deltax = xevent->xmotion.x - mouse_last.x;
222 deltay = xevent->xmotion.y - mouse_last.y;
219 #ifdef DEBUG_MOTION 223 #ifdef DEBUG_MOTION
220 printf("Warped mouse motion: %d,%d\n", deltax, deltay); 224 printf ("Warped mouse motion: %d,%d\n", deltax, deltay);
221 #endif 225 #endif
222 mouse_last.x = xevent->xmotion.x; 226 mouse_last.x = xevent->xmotion.x;
223 mouse_last.y = xevent->xmotion.y; 227 mouse_last.y = xevent->xmotion.y;
224 posted = SDL_PrivateMouseMotion(0, 1, deltax, deltay); 228 posted = SDL_PrivateMouseMotion (0, 1, deltax, deltay);
225 229
226 if ( (xevent->xmotion.x < MOUSE_FUDGE_FACTOR) || 230 if ((xevent->xmotion.x < MOUSE_FUDGE_FACTOR) ||
227 (xevent->xmotion.x > (w-MOUSE_FUDGE_FACTOR)) || 231 (xevent->xmotion.x > (w - MOUSE_FUDGE_FACTOR)) ||
228 (xevent->xmotion.y < MOUSE_FUDGE_FACTOR) || 232 (xevent->xmotion.y < MOUSE_FUDGE_FACTOR) ||
229 (xevent->xmotion.y > (h-MOUSE_FUDGE_FACTOR)) ) { 233 (xevent->xmotion.y > (h - MOUSE_FUDGE_FACTOR))) {
230 /* Get the events that have accumulated */ 234 /* Get the events that have accumulated */
231 while ( XCheckTypedEvent(SDL_Display, MotionNotify, xevent) ) { 235 while (XCheckTypedEvent (SDL_Display, MotionNotify, xevent)) {
232 deltax = xevent->xmotion.x - mouse_last.x; 236 deltax = xevent->xmotion.x - mouse_last.x;
233 deltay = xevent->xmotion.y - mouse_last.y; 237 deltay = xevent->xmotion.y - mouse_last.y;
234 #ifdef DEBUG_MOTION 238 #ifdef DEBUG_MOTION
235 printf("Extra mouse motion: %d,%d\n", deltax, deltay); 239 printf ("Extra mouse motion: %d,%d\n", deltax, deltay);
236 #endif 240 #endif
237 mouse_last.x = xevent->xmotion.x; 241 mouse_last.x = xevent->xmotion.x;
238 mouse_last.y = xevent->xmotion.y; 242 mouse_last.y = xevent->xmotion.y;
239 posted += SDL_PrivateMouseMotion(0, 1, deltax, deltay); 243 posted += SDL_PrivateMouseMotion (0, 1, deltax, deltay);
240 } 244 }
241 mouse_last.x = w/2; 245 mouse_last.x = w / 2;
242 mouse_last.y = h/2; 246 mouse_last.y = h / 2;
243 XWarpPointer(SDL_Display, None, SDL_Window, 0, 0, 0, 0, 247 XWarpPointer (SDL_Display, None, SDL_Window, 0, 0, 0, 0,
244 mouse_last.x, mouse_last.y); 248 mouse_last.x, mouse_last.y);
245 for ( i=0; i<10; ++i ) { 249 for (i = 0; i < 10; ++i) {
246 XMaskEvent(SDL_Display, PointerMotionMask, xevent); 250 XMaskEvent (SDL_Display, PointerMotionMask, xevent);
247 if ( (xevent->xmotion.x > 251 if ((xevent->xmotion.x >
248 (mouse_last.x-MOUSE_FUDGE_FACTOR)) && 252 (mouse_last.x - MOUSE_FUDGE_FACTOR)) &&
249 (xevent->xmotion.x < 253 (xevent->xmotion.x <
250 (mouse_last.x+MOUSE_FUDGE_FACTOR)) && 254 (mouse_last.x + MOUSE_FUDGE_FACTOR)) &&
251 (xevent->xmotion.y > 255 (xevent->xmotion.y >
252 (mouse_last.y-MOUSE_FUDGE_FACTOR)) && 256 (mouse_last.y - MOUSE_FUDGE_FACTOR)) &&
253 (xevent->xmotion.y < 257 (xevent->xmotion.y < (mouse_last.y + MOUSE_FUDGE_FACTOR))) {
254 (mouse_last.y+MOUSE_FUDGE_FACTOR)) ) { 258 break;
255 break; 259 }
256 } 260 #ifdef DEBUG_XEVENTS
257 #ifdef DEBUG_XEVENTS 261 printf ("Lost mouse motion: %d,%d\n", xevent->xmotion.x,
258 printf("Lost mouse motion: %d,%d\n", xevent->xmotion.x, xevent->xmotion.y); 262 xevent->xmotion.y);
259 #endif 263 #endif
260 } 264 }
261 #ifdef DEBUG_XEVENTS 265 #ifdef DEBUG_XEVENTS
262 if ( i == 10 ) { 266 if (i == 10) {
263 printf("Warning: didn't detect mouse warp motion\n"); 267 printf ("Warning: didn't detect mouse warp motion\n");
264 } 268 }
265 #endif 269 #endif
266 } 270 }
267 return(posted); 271 return (posted);
268 } 272 }
269 273
270 static int X11_DispatchEvent(_THIS) 274 static int
271 { 275 X11_DispatchEvent (_THIS)
272 int posted; 276 {
273 XEvent xevent; 277 int posted;
274 278 XEvent xevent;
275 SDL_memset(&xevent, '\0', sizeof (XEvent)); /* valgrind fix. --ryan. */ 279
276 XNextEvent(SDL_Display, &xevent); 280 SDL_memset (&xevent, '\0', sizeof (XEvent)); /* valgrind fix. --ryan. */
277 281 XNextEvent (SDL_Display, &xevent);
278 posted = 0; 282
279 switch (xevent.type) { 283 posted = 0;
280 284 switch (xevent.type) {
281 /* Gaining mouse coverage? */ 285
282 case EnterNotify: { 286 /* Gaining mouse coverage? */
283 #ifdef DEBUG_XEVENTS 287 case EnterNotify:
284 printf("EnterNotify! (%d,%d)\n", xevent.xcrossing.x, xevent.xcrossing.y); 288 {
285 if ( xevent.xcrossing.mode == NotifyGrab ) 289 #ifdef DEBUG_XEVENTS
286 printf("Mode: NotifyGrab\n"); 290 printf ("EnterNotify! (%d,%d)\n", xevent.xcrossing.x,
287 if ( xevent.xcrossing.mode == NotifyUngrab ) 291 xevent.xcrossing.y);
288 printf("Mode: NotifyUngrab\n"); 292 if (xevent.xcrossing.mode == NotifyGrab)
289 #endif 293 printf ("Mode: NotifyGrab\n");
290 if ( (xevent.xcrossing.mode != NotifyGrab) && 294 if (xevent.xcrossing.mode == NotifyUngrab)
291 (xevent.xcrossing.mode != NotifyUngrab) ) { 295 printf ("Mode: NotifyUngrab\n");
292 if ( this->input_grab == SDL_GRAB_OFF ) { 296 #endif
293 posted = SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS); 297 if ((xevent.xcrossing.mode != NotifyGrab) &&
294 } 298 (xevent.xcrossing.mode != NotifyUngrab)) {
295 posted = SDL_PrivateMouseMotion(0, 0, 299 if (SDL_CurrentWindow.input_grab == SDL_GRAB_OFF) {
296 xevent.xcrossing.x, 300 posted = SDL_PrivateAppActive (1, SDL_APPMOUSEFOCUS);
297 xevent.xcrossing.y); 301 }
298 } 302 posted = SDL_PrivateMouseMotion (0, 0,
299 } 303 xevent.xcrossing.x,
300 break; 304 xevent.xcrossing.y);
301 305 }
302 /* Losing mouse coverage? */ 306 }
303 case LeaveNotify: { 307 break;
304 #ifdef DEBUG_XEVENTS 308
305 printf("LeaveNotify! (%d,%d)\n", xevent.xcrossing.x, xevent.xcrossing.y); 309 /* Losing mouse coverage? */
306 if ( xevent.xcrossing.mode == NotifyGrab ) 310 case LeaveNotify:
307 printf("Mode: NotifyGrab\n"); 311 {
308 if ( xevent.xcrossing.mode == NotifyUngrab ) 312 #ifdef DEBUG_XEVENTS
309 printf("Mode: NotifyUngrab\n"); 313 printf ("LeaveNotify! (%d,%d)\n", xevent.xcrossing.x,
310 #endif 314 xevent.xcrossing.y);
311 if ( (xevent.xcrossing.mode != NotifyGrab) && 315 if (xevent.xcrossing.mode == NotifyGrab)
312 (xevent.xcrossing.mode != NotifyUngrab) && 316 printf ("Mode: NotifyGrab\n");
313 (xevent.xcrossing.detail != NotifyInferior) ) { 317 if (xevent.xcrossing.mode == NotifyUngrab)
314 if ( this->input_grab == SDL_GRAB_OFF ) { 318 printf ("Mode: NotifyUngrab\n");
315 posted = SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS); 319 #endif
316 } else { 320 if ((xevent.xcrossing.mode != NotifyGrab) &&
317 posted = SDL_PrivateMouseMotion(0, 0, 321 (xevent.xcrossing.mode != NotifyUngrab) &&
318 xevent.xcrossing.x, 322 (xevent.xcrossing.detail != NotifyInferior)) {
319 xevent.xcrossing.y); 323 if (SDL_CurrentWindow.input_grab == SDL_GRAB_OFF) {
320 } 324 posted = SDL_PrivateAppActive (0, SDL_APPMOUSEFOCUS);
321 } 325 } else {
322 } 326 posted = SDL_PrivateMouseMotion (0, 0,
323 break; 327 xevent.xcrossing.x,
324 328 xevent.xcrossing.y);
325 /* Gaining input focus? */ 329 }
326 case FocusIn: { 330 }
327 #ifdef DEBUG_XEVENTS 331 }
328 printf("FocusIn!\n"); 332 break;
329 #endif 333
330 posted = SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS); 334 /* Gaining input focus? */
335 case FocusIn:
336 {
337 #ifdef DEBUG_XEVENTS
338 printf ("FocusIn!\n");
339 #endif
340 posted = SDL_PrivateAppActive (1, SDL_APPINPUTFOCUS);
331 341
332 #ifdef X_HAVE_UTF8_STRING 342 #ifdef X_HAVE_UTF8_STRING
333 if ( SDL_IC != NULL ) { 343 if (SDL_IC != NULL) {
334 XSetICFocus(SDL_IC); 344 XSetICFocus (SDL_IC);
335 } 345 }
336 #endif 346 #endif
337 /* Queue entry into fullscreen mode */ 347 /* Queue entry into fullscreen mode */
338 switch_waiting = 0x01 | SDL_FULLSCREEN; 348 switch_waiting = 0x01 | SDL_FULLSCREEN;
339 switch_time = SDL_GetTicks() + 1500; 349 switch_time = SDL_GetTicks () + 1500;
340 } 350 }
341 break; 351 break;
342 352
343 /* Losing input focus? */ 353 /* Losing input focus? */
344 case FocusOut: { 354 case FocusOut:
345 #ifdef DEBUG_XEVENTS 355 {
346 printf("FocusOut!\n"); 356 #ifdef DEBUG_XEVENTS
347 #endif 357 printf ("FocusOut!\n");
348 posted = SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS); 358 #endif
359 posted = SDL_PrivateAppActive (0, SDL_APPINPUTFOCUS);
349 360
350 #ifdef X_HAVE_UTF8_STRING 361 #ifdef X_HAVE_UTF8_STRING
351 if ( SDL_IC != NULL ) { 362 if (SDL_IC != NULL) {
352 XUnsetICFocus(SDL_IC); 363 XUnsetICFocus (SDL_IC);
353 } 364 }
354 #endif 365 #endif
355 /* Queue leaving fullscreen mode */ 366 /* Queue leaving fullscreen mode */
356 switch_waiting = 0x01; 367 switch_waiting = 0x01;
357 switch_time = SDL_GetTicks() + 200; 368 switch_time = SDL_GetTicks () + 200;
358 } 369 }
359 break; 370 break;
360 371
361 /* Generated upon EnterWindow and FocusIn */ 372 /* Generated upon EnterWindow and FocusIn */
362 case KeymapNotify: { 373 case KeymapNotify:
363 #ifdef DEBUG_XEVENTS 374 {
364 printf("KeymapNotify!\n"); 375 #ifdef DEBUG_XEVENTS
365 #endif 376 printf ("KeymapNotify!\n");
366 X11_SetKeyboardState(SDL_Display, xevent.xkeymap.key_vector); 377 #endif
367 } 378 X11_SetKeyboardState (SDL_Display, xevent.xkeymap.key_vector);
368 break; 379 }
369 380 break;
370 /* Mouse motion? */ 381
371 case MotionNotify: { 382 /* Mouse motion? */
372 if ( SDL_VideoSurface ) { 383 case MotionNotify:
373 if ( mouse_relative ) { 384 {
374 if ( using_dga & DGA_MOUSE ) { 385 if (SDL_VideoSurface) {
386 if (mouse_relative) {
387 if (using_dga & DGA_MOUSE) {
375 #ifdef DEBUG_MOTION 388 #ifdef DEBUG_MOTION
376 printf("DGA motion: %d,%d\n", xevent.xmotion.x_root, xevent.xmotion.y_root); 389 printf ("DGA motion: %d,%d\n",
377 #endif 390 xevent.xmotion.x_root, xevent.xmotion.y_root);
378 posted = SDL_PrivateMouseMotion(0, 1, 391 #endif
379 xevent.xmotion.x_root, 392 posted = SDL_PrivateMouseMotion (0, 1,
380 xevent.xmotion.y_root); 393 xevent.
381 } else { 394 xmotion.
382 posted = X11_WarpedMotion(this,&xevent); 395 x_root,
383 } 396 xevent.
384 } else { 397 xmotion.y_root);
398 } else {
399 posted = X11_WarpedMotion (_this, &xevent);
400 }
401 } else {
385 #ifdef DEBUG_MOTION 402 #ifdef DEBUG_MOTION
386 printf("X11 motion: %d,%d\n", xevent.xmotion.x, xevent.xmotion.y); 403 printf ("X11 motion: %d,%d\n", xevent.xmotion.x,
387 #endif 404 xevent.xmotion.y);
388 posted = SDL_PrivateMouseMotion(0, 0, 405 #endif
389 xevent.xmotion.x, 406 posted = SDL_PrivateMouseMotion (0, 0,
390 xevent.xmotion.y); 407 xevent.xmotion.x,
391 } 408 xevent.xmotion.y);
392 } 409 }
393 } 410 }
394 break; 411 }
395 412 break;
396 /* Mouse button press? */ 413
397 case ButtonPress: { 414 /* Mouse button press? */
398 posted = SDL_PrivateMouseButton(SDL_PRESSED, 415 case ButtonPress:
399 xevent.xbutton.button, 0, 0); 416 {
400 } 417 posted = SDL_PrivateMouseButton (SDL_PRESSED,
401 break; 418 xevent.xbutton.button, 0, 0);
402 419 }
403 /* Mouse button release? */ 420 break;
404 case ButtonRelease: { 421
405 posted = SDL_PrivateMouseButton(SDL_RELEASED, 422 /* Mouse button release? */
406 xevent.xbutton.button, 0, 0); 423 case ButtonRelease:
407 } 424 {
408 break; 425 posted = SDL_PrivateMouseButton (SDL_RELEASED,
409 426 xevent.xbutton.button, 0, 0);
410 /* Key press? */ 427 }
411 case KeyPress: { 428 break;
412 static SDL_keysym saved_keysym; 429
413 SDL_keysym keysym; 430 /* Key press? */
414 KeyCode keycode = xevent.xkey.keycode; 431 case KeyPress:
415 432 {
416 #ifdef DEBUG_XEVENTS 433 static SDL_keysym saved_keysym;
417 printf("KeyPress (X11 keycode = 0x%X)\n", xevent.xkey.keycode); 434 SDL_keysym keysym;
418 #endif 435 KeyCode keycode = xevent.xkey.keycode;
419 /* Get the translated SDL virtual keysym */ 436
420 if ( keycode ) { 437 #ifdef DEBUG_XEVENTS
421 keysym.scancode = keycode; 438 printf ("KeyPress (X11 keycode = 0x%X)\n", xevent.xkey.keycode);
422 keysym.sym = X11_TranslateKeycode(SDL_Display, keycode); 439 #endif
423 keysym.mod = KMOD_NONE; 440 /* Get the translated SDL virtual keysym */
424 keysym.unicode = 0; 441 if (keycode) {
425 } else { 442 keysym.scancode = keycode;
426 keysym = saved_keysym; 443 keysym.sym = X11_TranslateKeycode (SDL_Display, keycode);
427 } 444 keysym.mod = KMOD_NONE;
428 445 keysym.unicode = 0;
429 /* If we're not doing translation, we're done! */ 446 } else {
430 if ( !SDL_TranslateUNICODE ) { 447 keysym = saved_keysym;
431 posted = SDL_PrivateKeyboard(SDL_PRESSED, &keysym); 448 }
432 break; 449
433 } 450 /* If we're not doing translation, we're done! */
434 451 if (!SDL_TranslateUNICODE) {
435 if ( XFilterEvent(&xevent, None) ) { 452 posted = SDL_PrivateKeyboard (SDL_PRESSED, &keysym);
436 if ( xevent.xkey.keycode ) { 453 break;
437 posted = SDL_PrivateKeyboard(SDL_PRESSED, &keysym); 454 }
438 } else { 455
439 /* Save event to be associated with IM text 456 if (XFilterEvent (&xevent, None)) {
440 In 1.3 we'll have a text event instead.. */ 457 if (xevent.xkey.keycode) {
441 saved_keysym = keysym; 458 posted = SDL_PrivateKeyboard (SDL_PRESSED, &keysym);
442 } 459 } else {
443 break; 460 /* Save event to be associated with IM text
444 } 461 In 1.3 we'll have a text event instead.. */
445 462 saved_keysym = keysym;
446 /* Look up the translated value for the key event */ 463 }
464 break;
465 }
466
467 /* Look up the translated value for the key event */
447 #ifdef X_HAVE_UTF8_STRING 468 #ifdef X_HAVE_UTF8_STRING
448 if ( SDL_IC != NULL ) { 469 if (SDL_IC != NULL) {
449 static Status state; 470 static Status state;
450 /* A UTF-8 character can be at most 6 bytes */ 471 /* A UTF-8 character can be at most 6 bytes */
451 char keybuf[6]; 472 char keybuf[6];
452 if ( Xutf8LookupString(SDL_IC, &xevent.xkey, 473 if (Xutf8LookupString (SDL_IC, &xevent.xkey,
453 keybuf, sizeof(keybuf), 474 keybuf, sizeof (keybuf),
454 NULL, &state) ) { 475 NULL, &state)) {
455 keysym.unicode = Utf8ToUcs4((Uint8*)keybuf); 476 keysym.unicode = Utf8ToUcs4 ((Uint8 *) keybuf);
456 } 477 }
457 } 478 } else
458 else 479 #endif
459 #endif 480 {
460 { 481 static XComposeStatus state;
461 static XComposeStatus state; 482 char keybuf[32];
462 char keybuf[32]; 483
463 484 if (XLookupString (&xevent.xkey,
464 if ( XLookupString(&xevent.xkey, 485 keybuf, sizeof (keybuf), NULL, &state)) {
465 keybuf, sizeof(keybuf), 486 /*
466 NULL, &state) ) { 487 * FIXME: XLookupString() may yield more than one
467 /* 488 * character, so we need a mechanism to allow for
468 * FIXME: XLookupString() may yield more than one 489 * this (perhaps null keypress events with a
469 * character, so we need a mechanism to allow for 490 * unicode value)
470 * this (perhaps null keypress events with a 491 */
471 * unicode value) 492 keysym.unicode = (Uint8) keybuf[0];
472 */ 493 }
473 keysym.unicode = (Uint8)keybuf[0]; 494 }
474 } 495 posted = SDL_PrivateKeyboard (SDL_PRESSED, &keysym);
475 } 496 }
476 posted = SDL_PrivateKeyboard(SDL_PRESSED, &keysym); 497 break;
477 } 498
478 break; 499 /* Key release? */
479 500 case KeyRelease:
480 /* Key release? */ 501 {
481 case KeyRelease: { 502 SDL_keysym keysym;
482 SDL_keysym keysym; 503 KeyCode keycode = xevent.xkey.keycode;
483 KeyCode keycode = xevent.xkey.keycode; 504
484 505 #ifdef DEBUG_XEVENTS
485 #ifdef DEBUG_XEVENTS 506 printf ("KeyRelease (X11 keycode = 0x%X)\n", xevent.xkey.keycode);
486 printf("KeyRelease (X11 keycode = 0x%X)\n", xevent.xkey.keycode); 507 #endif
487 #endif 508 /* Check to see if this is a repeated key */
488 /* Check to see if this is a repeated key */ 509 if (X11_KeyRepeat (SDL_Display, &xevent)) {
489 if ( X11_KeyRepeat(SDL_Display, &xevent) ) { 510 break;
490 break; 511 }
491 } 512
492 513 /* Get the translated SDL virtual keysym */
493 /* Get the translated SDL virtual keysym */ 514 keysym.scancode = keycode;
494 keysym.scancode = keycode; 515 keysym.sym = X11_TranslateKeycode (SDL_Display, keycode);
495 keysym.sym = X11_TranslateKeycode(SDL_Display, keycode); 516 keysym.mod = KMOD_NONE;
496 keysym.mod = KMOD_NONE; 517 keysym.unicode = 0;
497 keysym.unicode = 0; 518
498 519 posted = SDL_PrivateKeyboard (SDL_RELEASED, &keysym);
499 posted = SDL_PrivateKeyboard(SDL_RELEASED, &keysym); 520 }
500 } 521 break;
501 break; 522
502 523 /* Have we been iconified? */
503 /* Have we been iconified? */ 524 case UnmapNotify:
504 case UnmapNotify: { 525 {
505 #ifdef DEBUG_XEVENTS 526 #ifdef DEBUG_XEVENTS
506 printf("UnmapNotify!\n"); 527 printf ("UnmapNotify!\n");
507 #endif 528 #endif
508 /* If we're active, make ourselves inactive */ 529 /* If we're active, make ourselves inactive */
509 if ( SDL_GetAppState() & SDL_APPACTIVE ) { 530 if (SDL_GetAppState () & SDL_APPACTIVE) {
510 /* Swap out the gamma before we go inactive */ 531 /* Swap out the gamma before we go inactive */
511 X11_SwapVidModeGamma(this); 532 X11_SwapVidModeGamma (_this);
512 533
513 /* Send an internal deactivate event */ 534 /* Send an internal deactivate event */
514 posted = SDL_PrivateAppActive(0, 535 posted = SDL_PrivateAppActive (0,
515 SDL_APPACTIVE|SDL_APPINPUTFOCUS); 536 SDL_APPACTIVE |
516 } 537 SDL_APPINPUTFOCUS);
517 } 538 }
518 break; 539 }
519 540 break;
520 /* Have we been restored? */ 541
521 case MapNotify: { 542 /* Have we been restored? */
522 #ifdef DEBUG_XEVENTS 543 case MapNotify:
523 printf("MapNotify!\n"); 544 {
524 #endif 545 #ifdef DEBUG_XEVENTS
525 /* If we're not active, make ourselves active */ 546 printf ("MapNotify!\n");
526 if ( !(SDL_GetAppState() & SDL_APPACTIVE) ) { 547 #endif
527 /* Send an internal activate event */ 548 /* If we're not active, make ourselves active */
528 posted = SDL_PrivateAppActive(1, SDL_APPACTIVE); 549 if (!(SDL_GetAppState () & SDL_APPACTIVE)) {
529 550 /* Send an internal activate event */
530 /* Now that we're active, swap the gamma back */ 551 posted = SDL_PrivateAppActive (1, SDL_APPACTIVE);
531 X11_SwapVidModeGamma(this); 552
532 } 553 /* Now that we're active, swap the gamma back */
533 554 X11_SwapVidModeGamma (_this);
534 if ( SDL_VideoSurface && 555 }
535 (SDL_VideoSurface->flags & SDL_FULLSCREEN) ) { 556
536 X11_EnterFullScreen(this); 557 if (SDL_VideoSurface &&
537 } else { 558 (SDL_VideoSurface->flags & SDL_FULLSCREEN)) {
538 X11_GrabInputNoLock(this, this->input_grab); 559 X11_EnterFullScreen (_this);
539 } 560 } else {
540 X11_CheckMouseModeNoLock(this); 561 X11_GrabInputNoLock (_this, SDL_CurrentWindow.input_grab);
541 562 }
542 if ( SDL_VideoSurface ) { 563 X11_CheckMouseModeNoLock (_this);
543 X11_RefreshDisplay(this); 564
544 } 565 if (SDL_VideoSurface) {
545 } 566 X11_RefreshDisplay (_this);
546 break; 567 }
547 568 }
548 /* Have we been resized or moved? */ 569 break;
549 case ConfigureNotify: { 570
550 #ifdef DEBUG_XEVENTS 571 /* Have we been resized or moved? */
551 printf("ConfigureNotify! (resize: %dx%d)\n", xevent.xconfigure.width, xevent.xconfigure.height); 572 case ConfigureNotify:
552 #endif 573 {
553 if ( SDL_VideoSurface ) { 574 #ifdef DEBUG_XEVENTS
554 if ((xevent.xconfigure.width != SDL_VideoSurface->w) || 575 printf ("ConfigureNotify! (resize: %dx%d)\n",
555 (xevent.xconfigure.height != SDL_VideoSurface->h)) { 576 xevent.xconfigure.width, xevent.xconfigure.height);
556 /* FIXME: Find a better fix for the bug with KDE 1.2 */ 577 #endif
557 if ( ! ((xevent.xconfigure.width == 32) && 578 if (SDL_VideoSurface) {
558 (xevent.xconfigure.height == 32)) ) { 579 if ((xevent.xconfigure.width != SDL_VideoSurface->w) ||
559 SDL_PrivateResize(xevent.xconfigure.width, 580 (xevent.xconfigure.height != SDL_VideoSurface->h)) {
560 xevent.xconfigure.height); 581 /* FIXME: Find a better fix for the bug with KDE 1.2 */
561 } 582 if (!((xevent.xconfigure.width == 32) &&
562 } else { 583 (xevent.xconfigure.height == 32))) {
563 /* OpenGL windows need to know about the change */ 584 SDL_PrivateResize (xevent.xconfigure.width,
564 if ( SDL_VideoSurface->flags & SDL_INTERNALOPENGL ) { 585 xevent.xconfigure.height);
565 SDL_PrivateExpose(); 586 }
566 } 587 } else {
567 } 588 /* OpenGL windows need to know about the change */
568 } 589 if (SDL_VideoSurface->flags & SDL_INTERNALOPENGL) {
569 } 590 SDL_PrivateExpose ();
570 break; 591 }
571 592 }
572 /* Have we been requested to quit (or another client message?) */ 593 }
573 case ClientMessage: { 594 }
574 if ( (xevent.xclient.format == 32) && 595 break;
575 (xevent.xclient.data.l[0] == WM_DELETE_WINDOW) ) 596
576 { 597 /* Have we been requested to quit (or another client message?) */
577 posted = SDL_PrivateQuit(); 598 case ClientMessage:
578 } else 599 {
579 if ( SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE ) { 600 if ((xevent.xclient.format == 32) &&
580 SDL_SysWMmsg wmmsg; 601 (xevent.xclient.data.l[0] == WM_DELETE_WINDOW)) {
581 602 posted = SDL_PrivateQuit ();
582 SDL_VERSION(&wmmsg.version); 603 } else if (SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE) {
583 wmmsg.subsystem = SDL_SYSWM_X11; 604 SDL_SysWMmsg wmmsg;
584 wmmsg.event.xevent = xevent; 605
585 posted = SDL_PrivateSysWMEvent(&wmmsg); 606 SDL_VERSION (&wmmsg.version);
586 } 607 wmmsg.subsystem = SDL_SYSWM_X11;
587 } 608 wmmsg.event.xevent = xevent;
588 break; 609 posted = SDL_PrivateSysWMEvent (&wmmsg);
589 610 }
590 /* Do we need to refresh ourselves? */ 611 }
591 case Expose: { 612 break;
592 #ifdef DEBUG_XEVENTS 613
593 printf("Expose (count = %d)\n", xevent.xexpose.count); 614 /* Do we need to refresh ourselves? */
594 #endif 615 case Expose:
595 if ( SDL_VideoSurface && (xevent.xexpose.count == 0) ) { 616 {
596 X11_RefreshDisplay(this); 617 #ifdef DEBUG_XEVENTS
597 } 618 printf ("Expose (count = %d)\n", xevent.xexpose.count);
598 } 619 #endif
599 break; 620 if (SDL_VideoSurface && (xevent.xexpose.count == 0)) {
600 621 X11_RefreshDisplay (_this);
601 default: { 622 }
602 #ifdef DEBUG_XEVENTS 623 }
603 printf("Unhandled event %d\n", xevent.type); 624 break;
604 #endif 625
605 /* Only post the event if we're watching for it */ 626 default:
606 if ( SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE ) { 627 {
607 SDL_SysWMmsg wmmsg; 628 #ifdef DEBUG_XEVENTS
608 629 printf ("Unhandled event %d\n", xevent.type);
609 SDL_VERSION(&wmmsg.version); 630 #endif
610 wmmsg.subsystem = SDL_SYSWM_X11; 631 /* Only post the event if we're watching for it */
611 wmmsg.event.xevent = xevent; 632 if (SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE) {
612 posted = SDL_PrivateSysWMEvent(&wmmsg); 633 SDL_SysWMmsg wmmsg;
613 } 634
614 } 635 SDL_VERSION (&wmmsg.version);
615 break; 636 wmmsg.subsystem = SDL_SYSWM_X11;
616 } 637 wmmsg.event.xevent = xevent;
617 return(posted); 638 posted = SDL_PrivateSysWMEvent (&wmmsg);
639 }
640 }
641 break;
642 }
643 return (posted);
618 } 644 }
619 645
620 /* Ack! XPending() actually performs a blocking read if no events available */ 646 /* Ack! XPending() actually performs a blocking read if no events available */
621 int X11_Pending(Display *display) 647 int
622 { 648 X11_Pending (Display * display)
623 /* Flush the display connection and look to see if events are queued */ 649 {
624 XFlush(display); 650 /* Flush the display connection and look to see if events are queued */
625 if ( XEventsQueued(display, QueuedAlready) ) { 651 XFlush (display);
626 return(1); 652 if (XEventsQueued (display, QueuedAlready)) {
627 } 653 return (1);
628 654 }
629 /* More drastic measures are required -- see if X is ready to talk */ 655
630 { 656 /* More drastic measures are required -- see if X is ready to talk */
631 static struct timeval zero_time; /* static == 0 */ 657 {
632 int x11_fd; 658 static struct timeval zero_time; /* static == 0 */
633 fd_set fdset; 659 int x11_fd;
634 660 fd_set fdset;
635 x11_fd = ConnectionNumber(display); 661
636 FD_ZERO(&fdset); 662 x11_fd = ConnectionNumber (display);
637 FD_SET(x11_fd, &fdset); 663 FD_ZERO (&fdset);
638 if ( select(x11_fd+1, &fdset, NULL, NULL, &zero_time) == 1 ) { 664 FD_SET (x11_fd, &fdset);
639 return(XPending(display)); 665 if (select (x11_fd + 1, &fdset, NULL, NULL, &zero_time) == 1) {
640 } 666 return (XPending (display));
641 } 667 }
642 668 }
643 /* Oh well, nothing is ready .. */ 669
644 return(0); 670 /* Oh well, nothing is ready .. */
645 } 671 return (0);
646 672 }
647 void X11_PumpEvents(_THIS) 673
648 { 674 void
649 int pending; 675 X11_PumpEvents (_THIS)
650 676 {
651 /* Keep processing pending events */ 677 int pending;
652 pending = 0; 678
653 while ( X11_Pending(SDL_Display) ) { 679 /* Keep processing pending events */
654 X11_DispatchEvent(this); 680 pending = 0;
655 ++pending; 681 while (X11_Pending (SDL_Display)) {
656 } 682 X11_DispatchEvent (_this);
657 if ( switch_waiting ) { 683 ++pending;
658 Uint32 now; 684 }
659 685 if (switch_waiting) {
660 now = SDL_GetTicks(); 686 Uint32 now;
661 if ( pending || !SDL_VideoSurface ) { 687
662 /* Try again later... */ 688 now = SDL_GetTicks ();
663 if ( switch_waiting & SDL_FULLSCREEN ) { 689 if (pending || !SDL_VideoSurface) {
664 switch_time = now + 1500; 690 /* Try again later... */
665 } else { 691 if (switch_waiting & SDL_FULLSCREEN) {
666 switch_time = now + 200; 692 switch_time = now + 1500;
667 } 693 } else {
668 } else if ( (int)(switch_time-now) <= 0 ) { 694 switch_time = now + 200;
669 Uint32 go_fullscreen; 695 }
670 696 } else if ((int) (switch_time - now) <= 0) {
671 go_fullscreen = switch_waiting & SDL_FULLSCREEN; 697 Uint32 go_fullscreen;
672 switch_waiting = 0; 698
673 if ( SDL_VideoSurface->flags & SDL_FULLSCREEN ) { 699 go_fullscreen = switch_waiting & SDL_FULLSCREEN;
674 if ( go_fullscreen ) { 700 switch_waiting = 0;
675 X11_EnterFullScreen(this); 701 if (SDL_VideoSurface->flags & SDL_FULLSCREEN) {
676 } else { 702 if (go_fullscreen) {
677 X11_LeaveFullScreen(this); 703 X11_EnterFullScreen (_this);
678 } 704 } else {
679 } 705 X11_LeaveFullScreen (_this);
680 /* Handle focus in/out when grabbed */ 706 }
681 if ( go_fullscreen ) { 707 }
682 X11_GrabInputNoLock(this, this->input_grab); 708 /* Handle focus in/out when grabbed */
683 } else { 709 if (go_fullscreen) {
684 X11_GrabInputNoLock(this, SDL_GRAB_OFF); 710 X11_GrabInputNoLock (_this, SDL_CurrentWindow.input_grab);
685 } 711 } else {
686 X11_CheckMouseModeNoLock(this); 712 X11_GrabInputNoLock (_this, SDL_GRAB_OFF);
687 } 713 }
688 } 714 X11_CheckMouseModeNoLock (_this);
689 } 715 }
690 716 }
691 void X11_InitKeymap(void) 717 }
692 { 718
693 int i; 719 void
694 720 X11_InitKeymap (void)
695 /* Odd keys used in international keyboards */ 721 {
696 for ( i=0; i<SDL_arraysize(ODD_keymap); ++i ) 722 int i;
697 ODD_keymap[i] = SDLK_UNKNOWN; 723
698 724 /* Odd keys used in international keyboards */
699 /* Some of these might be mappable to an existing SDLK_ code */ 725 for (i = 0; i < SDL_arraysize (ODD_keymap); ++i)
700 ODD_keymap[XK_dead_grave&0xFF] = SDLK_COMPOSE; 726 ODD_keymap[i] = SDLK_UNKNOWN;
701 ODD_keymap[XK_dead_acute&0xFF] = SDLK_COMPOSE; 727
702 ODD_keymap[XK_dead_tilde&0xFF] = SDLK_COMPOSE; 728 /* Some of these might be mappable to an existing SDLK_ code */
703 ODD_keymap[XK_dead_macron&0xFF] = SDLK_COMPOSE; 729 ODD_keymap[XK_dead_grave & 0xFF] = SDLK_COMPOSE;
704 ODD_keymap[XK_dead_breve&0xFF] = SDLK_COMPOSE; 730 ODD_keymap[XK_dead_acute & 0xFF] = SDLK_COMPOSE;
705 ODD_keymap[XK_dead_abovedot&0xFF] = SDLK_COMPOSE; 731 ODD_keymap[XK_dead_tilde & 0xFF] = SDLK_COMPOSE;
706 ODD_keymap[XK_dead_diaeresis&0xFF] = SDLK_COMPOSE; 732 ODD_keymap[XK_dead_macron & 0xFF] = SDLK_COMPOSE;
707 ODD_keymap[XK_dead_abovering&0xFF] = SDLK_COMPOSE; 733 ODD_keymap[XK_dead_breve & 0xFF] = SDLK_COMPOSE;
708 ODD_keymap[XK_dead_doubleacute&0xFF] = SDLK_COMPOSE; 734 ODD_keymap[XK_dead_abovedot & 0xFF] = SDLK_COMPOSE;
709 ODD_keymap[XK_dead_caron&0xFF] = SDLK_COMPOSE; 735 ODD_keymap[XK_dead_diaeresis & 0xFF] = SDLK_COMPOSE;
710 ODD_keymap[XK_dead_cedilla&0xFF] = SDLK_COMPOSE; 736 ODD_keymap[XK_dead_abovering & 0xFF] = SDLK_COMPOSE;
711 ODD_keymap[XK_dead_ogonek&0xFF] = SDLK_COMPOSE; 737 ODD_keymap[XK_dead_doubleacute & 0xFF] = SDLK_COMPOSE;
712 ODD_keymap[XK_dead_iota&0xFF] = SDLK_COMPOSE; 738 ODD_keymap[XK_dead_caron & 0xFF] = SDLK_COMPOSE;
713 ODD_keymap[XK_dead_voiced_sound&0xFF] = SDLK_COMPOSE; 739 ODD_keymap[XK_dead_cedilla & 0xFF] = SDLK_COMPOSE;
714 ODD_keymap[XK_dead_semivoiced_sound&0xFF] = SDLK_COMPOSE; 740 ODD_keymap[XK_dead_ogonek & 0xFF] = SDLK_COMPOSE;
715 ODD_keymap[XK_dead_belowdot&0xFF] = SDLK_COMPOSE; 741 ODD_keymap[XK_dead_iota & 0xFF] = SDLK_COMPOSE;
742 ODD_keymap[XK_dead_voiced_sound & 0xFF] = SDLK_COMPOSE;
743 ODD_keymap[XK_dead_semivoiced_sound & 0xFF] = SDLK_COMPOSE;
744 ODD_keymap[XK_dead_belowdot & 0xFF] = SDLK_COMPOSE;
716 #ifdef XK_dead_hook 745 #ifdef XK_dead_hook
717 ODD_keymap[XK_dead_hook&0xFF] = SDLK_COMPOSE; 746 ODD_keymap[XK_dead_hook & 0xFF] = SDLK_COMPOSE;
718 #endif 747 #endif
719 #ifdef XK_dead_horn 748 #ifdef XK_dead_horn
720 ODD_keymap[XK_dead_horn&0xFF] = SDLK_COMPOSE; 749 ODD_keymap[XK_dead_horn & 0xFF] = SDLK_COMPOSE;
721 #endif 750 #endif
722 751
723 #ifdef XK_dead_circumflex 752 #ifdef XK_dead_circumflex
724 /* These X keysyms have 0xFE as the high byte */ 753 /* These X keysyms have 0xFE as the high byte */
725 ODD_keymap[XK_dead_circumflex&0xFF] = SDLK_CARET; 754 ODD_keymap[XK_dead_circumflex & 0xFF] = SDLK_CARET;
726 #endif 755 #endif
727 #ifdef XK_ISO_Level3_Shift 756 #ifdef XK_ISO_Level3_Shift
728 ODD_keymap[XK_ISO_Level3_Shift&0xFF] = SDLK_MODE; /* "Alt Gr" key */ 757 ODD_keymap[XK_ISO_Level3_Shift & 0xFF] = SDLK_MODE; /* "Alt Gr" key */
729 #endif 758 #endif
730 759
731 /* Map the miscellaneous keys */ 760 /* Map the miscellaneous keys */
732 for ( i=0; i<SDL_arraysize(MISC_keymap); ++i ) 761 for (i = 0; i < SDL_arraysize (MISC_keymap); ++i)
733 MISC_keymap[i] = SDLK_UNKNOWN; 762 MISC_keymap[i] = SDLK_UNKNOWN;
734 763
735 /* These X keysyms have 0xFF as the high byte */ 764 /* These X keysyms have 0xFF as the high byte */
736 MISC_keymap[XK_BackSpace&0xFF] = SDLK_BACKSPACE; 765 MISC_keymap[XK_BackSpace & 0xFF] = SDLK_BACKSPACE;
737 MISC_keymap[XK_Tab&0xFF] = SDLK_TAB; 766 MISC_keymap[XK_Tab & 0xFF] = SDLK_TAB;
738 MISC_keymap[XK_Clear&0xFF] = SDLK_CLEAR; 767 MISC_keymap[XK_Clear & 0xFF] = SDLK_CLEAR;
739 MISC_keymap[XK_Return&0xFF] = SDLK_RETURN; 768 MISC_keymap[XK_Return & 0xFF] = SDLK_RETURN;
740 MISC_keymap[XK_Pause&0xFF] = SDLK_PAUSE; 769 MISC_keymap[XK_Pause & 0xFF] = SDLK_PAUSE;
741 MISC_keymap[XK_Escape&0xFF] = SDLK_ESCAPE; 770 MISC_keymap[XK_Escape & 0xFF] = SDLK_ESCAPE;
742 MISC_keymap[XK_Delete&0xFF] = SDLK_DELETE; 771 MISC_keymap[XK_Delete & 0xFF] = SDLK_DELETE;
743 772
744 MISC_keymap[XK_KP_0&0xFF] = SDLK_KP0; /* Keypad 0-9 */ 773 MISC_keymap[XK_KP_0 & 0xFF] = SDLK_KP0; /* Keypad 0-9 */
745 MISC_keymap[XK_KP_1&0xFF] = SDLK_KP1; 774 MISC_keymap[XK_KP_1 & 0xFF] = SDLK_KP1;
746 MISC_keymap[XK_KP_2&0xFF] = SDLK_KP2; 775 MISC_keymap[XK_KP_2 & 0xFF] = SDLK_KP2;
747 MISC_keymap[XK_KP_3&0xFF] = SDLK_KP3; 776 MISC_keymap[XK_KP_3 & 0xFF] = SDLK_KP3;
748 MISC_keymap[XK_KP_4&0xFF] = SDLK_KP4; 777 MISC_keymap[XK_KP_4 & 0xFF] = SDLK_KP4;
749 MISC_keymap[XK_KP_5&0xFF] = SDLK_KP5; 778 MISC_keymap[XK_KP_5 & 0xFF] = SDLK_KP5;
750 MISC_keymap[XK_KP_6&0xFF] = SDLK_KP6; 779 MISC_keymap[XK_KP_6 & 0xFF] = SDLK_KP6;
751 MISC_keymap[XK_KP_7&0xFF] = SDLK_KP7; 780 MISC_keymap[XK_KP_7 & 0xFF] = SDLK_KP7;
752 MISC_keymap[XK_KP_8&0xFF] = SDLK_KP8; 781 MISC_keymap[XK_KP_8 & 0xFF] = SDLK_KP8;
753 MISC_keymap[XK_KP_9&0xFF] = SDLK_KP9; 782 MISC_keymap[XK_KP_9 & 0xFF] = SDLK_KP9;
754 MISC_keymap[XK_KP_Insert&0xFF] = SDLK_KP0; 783 MISC_keymap[XK_KP_Insert & 0xFF] = SDLK_KP0;
755 MISC_keymap[XK_KP_End&0xFF] = SDLK_KP1; 784 MISC_keymap[XK_KP_End & 0xFF] = SDLK_KP1;
756 MISC_keymap[XK_KP_Down&0xFF] = SDLK_KP2; 785 MISC_keymap[XK_KP_Down & 0xFF] = SDLK_KP2;
757 MISC_keymap[XK_KP_Page_Down&0xFF] = SDLK_KP3; 786 MISC_keymap[XK_KP_Page_Down & 0xFF] = SDLK_KP3;
758 MISC_keymap[XK_KP_Left&0xFF] = SDLK_KP4; 787 MISC_keymap[XK_KP_Left & 0xFF] = SDLK_KP4;
759 MISC_keymap[XK_KP_Begin&0xFF] = SDLK_KP5; 788 MISC_keymap[XK_KP_Begin & 0xFF] = SDLK_KP5;
760 MISC_keymap[XK_KP_Right&0xFF] = SDLK_KP6; 789 MISC_keymap[XK_KP_Right & 0xFF] = SDLK_KP6;
761 MISC_keymap[XK_KP_Home&0xFF] = SDLK_KP7; 790 MISC_keymap[XK_KP_Home & 0xFF] = SDLK_KP7;
762 MISC_keymap[XK_KP_Up&0xFF] = SDLK_KP8; 791 MISC_keymap[XK_KP_Up & 0xFF] = SDLK_KP8;
763 MISC_keymap[XK_KP_Page_Up&0xFF] = SDLK_KP9; 792 MISC_keymap[XK_KP_Page_Up & 0xFF] = SDLK_KP9;
764 MISC_keymap[XK_KP_Delete&0xFF] = SDLK_KP_PERIOD; 793 MISC_keymap[XK_KP_Delete & 0xFF] = SDLK_KP_PERIOD;
765 MISC_keymap[XK_KP_Decimal&0xFF] = SDLK_KP_PERIOD; 794 MISC_keymap[XK_KP_Decimal & 0xFF] = SDLK_KP_PERIOD;
766 MISC_keymap[XK_KP_Divide&0xFF] = SDLK_KP_DIVIDE; 795 MISC_keymap[XK_KP_Divide & 0xFF] = SDLK_KP_DIVIDE;
767 MISC_keymap[XK_KP_Multiply&0xFF] = SDLK_KP_MULTIPLY; 796 MISC_keymap[XK_KP_Multiply & 0xFF] = SDLK_KP_MULTIPLY;
768 MISC_keymap[XK_KP_Subtract&0xFF] = SDLK_KP_MINUS; 797 MISC_keymap[XK_KP_Subtract & 0xFF] = SDLK_KP_MINUS;
769 MISC_keymap[XK_KP_Add&0xFF] = SDLK_KP_PLUS; 798 MISC_keymap[XK_KP_Add & 0xFF] = SDLK_KP_PLUS;
770 MISC_keymap[XK_KP_Enter&0xFF] = SDLK_KP_ENTER; 799 MISC_keymap[XK_KP_Enter & 0xFF] = SDLK_KP_ENTER;
771 MISC_keymap[XK_KP_Equal&0xFF] = SDLK_KP_EQUALS; 800 MISC_keymap[XK_KP_Equal & 0xFF] = SDLK_KP_EQUALS;
772 801
773 MISC_keymap[XK_Up&0xFF] = SDLK_UP; 802 MISC_keymap[XK_Up & 0xFF] = SDLK_UP;
774 MISC_keymap[XK_Down&0xFF] = SDLK_DOWN; 803 MISC_keymap[XK_Down & 0xFF] = SDLK_DOWN;
775 MISC_keymap[XK_Right&0xFF] = SDLK_RIGHT; 804 MISC_keymap[XK_Right & 0xFF] = SDLK_RIGHT;
776 MISC_keymap[XK_Left&0xFF] = SDLK_LEFT; 805 MISC_keymap[XK_Left & 0xFF] = SDLK_LEFT;
777 MISC_keymap[XK_Insert&0xFF] = SDLK_INSERT; 806 MISC_keymap[XK_Insert & 0xFF] = SDLK_INSERT;
778 MISC_keymap[XK_Home&0xFF] = SDLK_HOME; 807 MISC_keymap[XK_Home & 0xFF] = SDLK_HOME;
779 MISC_keymap[XK_End&0xFF] = SDLK_END; 808 MISC_keymap[XK_End & 0xFF] = SDLK_END;
780 MISC_keymap[XK_Page_Up&0xFF] = SDLK_PAGEUP; 809 MISC_keymap[XK_Page_Up & 0xFF] = SDLK_PAGEUP;
781 MISC_keymap[XK_Page_Down&0xFF] = SDLK_PAGEDOWN; 810 MISC_keymap[XK_Page_Down & 0xFF] = SDLK_PAGEDOWN;
782 811
783 MISC_keymap[XK_F1&0xFF] = SDLK_F1; 812 MISC_keymap[XK_F1 & 0xFF] = SDLK_F1;
784 MISC_keymap[XK_F2&0xFF] = SDLK_F2; 813 MISC_keymap[XK_F2 & 0xFF] = SDLK_F2;
785 MISC_keymap[XK_F3&0xFF] = SDLK_F3; 814 MISC_keymap[XK_F3 & 0xFF] = SDLK_F3;
786 MISC_keymap[XK_F4&0xFF] = SDLK_F4; 815 MISC_keymap[XK_F4 & 0xFF] = SDLK_F4;
787 MISC_keymap[XK_F5&0xFF] = SDLK_F5; 816 MISC_keymap[XK_F5 & 0xFF] = SDLK_F5;
788 MISC_keymap[XK_F6&0xFF] = SDLK_F6; 817 MISC_keymap[XK_F6 & 0xFF] = SDLK_F6;
789 MISC_keymap[XK_F7&0xFF] = SDLK_F7; 818 MISC_keymap[XK_F7 & 0xFF] = SDLK_F7;
790 MISC_keymap[XK_F8&0xFF] = SDLK_F8; 819 MISC_keymap[XK_F8 & 0xFF] = SDLK_F8;
791 MISC_keymap[XK_F9&0xFF] = SDLK_F9; 820 MISC_keymap[XK_F9 & 0xFF] = SDLK_F9;
792 MISC_keymap[XK_F10&0xFF] = SDLK_F10; 821 MISC_keymap[XK_F10 & 0xFF] = SDLK_F10;
793 MISC_keymap[XK_F11&0xFF] = SDLK_F11; 822 MISC_keymap[XK_F11 & 0xFF] = SDLK_F11;
794 MISC_keymap[XK_F12&0xFF] = SDLK_F12; 823 MISC_keymap[XK_F12 & 0xFF] = SDLK_F12;
795 MISC_keymap[XK_F13&0xFF] = SDLK_F13; 824 MISC_keymap[XK_F13 & 0xFF] = SDLK_F13;
796 MISC_keymap[XK_F14&0xFF] = SDLK_F14; 825 MISC_keymap[XK_F14 & 0xFF] = SDLK_F14;
797 MISC_keymap[XK_F15&0xFF] = SDLK_F15; 826 MISC_keymap[XK_F15 & 0xFF] = SDLK_F15;
798 827
799 MISC_keymap[XK_Num_Lock&0xFF] = SDLK_NUMLOCK; 828 MISC_keymap[XK_Num_Lock & 0xFF] = SDLK_NUMLOCK;
800 MISC_keymap[XK_Caps_Lock&0xFF] = SDLK_CAPSLOCK; 829 MISC_keymap[XK_Caps_Lock & 0xFF] = SDLK_CAPSLOCK;
801 MISC_keymap[XK_Scroll_Lock&0xFF] = SDLK_SCROLLOCK; 830 MISC_keymap[XK_Scroll_Lock & 0xFF] = SDLK_SCROLLOCK;
802 MISC_keymap[XK_Shift_R&0xFF] = SDLK_RSHIFT; 831 MISC_keymap[XK_Shift_R & 0xFF] = SDLK_RSHIFT;
803 MISC_keymap[XK_Shift_L&0xFF] = SDLK_LSHIFT; 832 MISC_keymap[XK_Shift_L & 0xFF] = SDLK_LSHIFT;
804 MISC_keymap[XK_Control_R&0xFF] = SDLK_RCTRL; 833 MISC_keymap[XK_Control_R & 0xFF] = SDLK_RCTRL;
805 MISC_keymap[XK_Control_L&0xFF] = SDLK_LCTRL; 834 MISC_keymap[XK_Control_L & 0xFF] = SDLK_LCTRL;
806 MISC_keymap[XK_Alt_R&0xFF] = SDLK_RALT; 835 MISC_keymap[XK_Alt_R & 0xFF] = SDLK_RALT;
807 MISC_keymap[XK_Alt_L&0xFF] = SDLK_LALT; 836 MISC_keymap[XK_Alt_L & 0xFF] = SDLK_LALT;
808 MISC_keymap[XK_Meta_R&0xFF] = SDLK_RMETA; 837 MISC_keymap[XK_Meta_R & 0xFF] = SDLK_RMETA;
809 MISC_keymap[XK_Meta_L&0xFF] = SDLK_LMETA; 838 MISC_keymap[XK_Meta_L & 0xFF] = SDLK_LMETA;
810 MISC_keymap[XK_Super_L&0xFF] = SDLK_LSUPER; /* Left "Windows" */ 839 MISC_keymap[XK_Super_L & 0xFF] = SDLK_LSUPER; /* Left "Windows" */
811 MISC_keymap[XK_Super_R&0xFF] = SDLK_RSUPER; /* Right "Windows */ 840 MISC_keymap[XK_Super_R & 0xFF] = SDLK_RSUPER; /* Right "Windows */
812 MISC_keymap[XK_Mode_switch&0xFF] = SDLK_MODE; /* "Alt Gr" key */ 841 MISC_keymap[XK_Mode_switch & 0xFF] = SDLK_MODE; /* "Alt Gr" key */
813 MISC_keymap[XK_Multi_key&0xFF] = SDLK_COMPOSE; /* Multi-key compose */ 842 MISC_keymap[XK_Multi_key & 0xFF] = SDLK_COMPOSE; /* Multi-key compose */
814 843
815 MISC_keymap[XK_Help&0xFF] = SDLK_HELP; 844 MISC_keymap[XK_Help & 0xFF] = SDLK_HELP;
816 MISC_keymap[XK_Print&0xFF] = SDLK_PRINT; 845 MISC_keymap[XK_Print & 0xFF] = SDLK_PRINT;
817 MISC_keymap[XK_Sys_Req&0xFF] = SDLK_SYSREQ; 846 MISC_keymap[XK_Sys_Req & 0xFF] = SDLK_SYSREQ;
818 MISC_keymap[XK_Break&0xFF] = SDLK_BREAK; 847 MISC_keymap[XK_Break & 0xFF] = SDLK_BREAK;
819 MISC_keymap[XK_Menu&0xFF] = SDLK_MENU; 848 MISC_keymap[XK_Menu & 0xFF] = SDLK_MENU;
820 MISC_keymap[XK_Hyper_R&0xFF] = SDLK_MENU; /* Windows "Menu" key */ 849 MISC_keymap[XK_Hyper_R & 0xFF] = SDLK_MENU; /* Windows "Menu" key */
821 } 850 }
822 851
823 /* Get the translated SDL virtual keysym */ 852 /* Get the translated SDL virtual keysym */
824 SDLKey X11_TranslateKeycode(Display *display, KeyCode kc) 853 SDLKey
825 { 854 X11_TranslateKeycode (Display * display, KeyCode kc)
826 KeySym xsym; 855 {
827 SDLKey key; 856 KeySym xsym;
828 857 SDLKey key;
829 xsym = XKeycodeToKeysym(display, kc, 0); 858
859 xsym = XKeycodeToKeysym (display, kc, 0);
830 #ifdef DEBUG_KEYS 860 #ifdef DEBUG_KEYS
831 fprintf(stderr, "Translating key code %d -> 0x%.4x\n", kc, xsym); 861 fprintf (stderr, "Translating key code %d -> 0x%.4x\n", kc, xsym);
832 #endif 862 #endif
833 key = SDLK_UNKNOWN; 863 key = SDLK_UNKNOWN;
834 if ( xsym ) { 864 if (xsym) {
835 switch (xsym>>8) { 865 switch (xsym >> 8) {
836 case 0x1005FF: 866 case 0x1005FF:
837 #ifdef SunXK_F36 867 #ifdef SunXK_F36
838 if ( xsym == SunXK_F36 ) 868 if (xsym == SunXK_F36)
839 key = SDLK_F11; 869 key = SDLK_F11;
840 #endif 870 #endif
841 #ifdef SunXK_F37 871 #ifdef SunXK_F37
842 if ( xsym == SunXK_F37 ) 872 if (xsym == SunXK_F37)
843 key = SDLK_F12; 873 key = SDLK_F12;
844 #endif 874 #endif
845 break; 875 break;
846 case 0x00: /* Latin 1 */ 876 case 0x00: /* Latin 1 */
847 key = (SDLKey)(xsym & 0xFF); 877 key = (SDLKey) (xsym & 0xFF);
848 break; 878 break;
849 case 0x01: /* Latin 2 */ 879 case 0x01: /* Latin 2 */
850 case 0x02: /* Latin 3 */ 880 case 0x02: /* Latin 3 */
851 case 0x03: /* Latin 4 */ 881 case 0x03: /* Latin 4 */
852 case 0x04: /* Katakana */ 882 case 0x04: /* Katakana */
853 case 0x05: /* Arabic */ 883 case 0x05: /* Arabic */
854 case 0x06: /* Cyrillic */ 884 case 0x06: /* Cyrillic */
855 case 0x07: /* Greek */ 885 case 0x07: /* Greek */
856 case 0x08: /* Technical */ 886 case 0x08: /* Technical */
857 case 0x0A: /* Publishing */ 887 case 0x0A: /* Publishing */
858 case 0x0C: /* Hebrew */ 888 case 0x0C: /* Hebrew */
859 case 0x0D: /* Thai */ 889 case 0x0D: /* Thai */
860 /* These are wrong, but it's better than nothing */ 890 /* These are wrong, but it's better than nothing */
861 key = (SDLKey)(xsym & 0xFF); 891 key = (SDLKey) (xsym & 0xFF);
862 break; 892 break;
863 case 0xFE: 893 case 0xFE:
864 key = ODD_keymap[xsym&0xFF]; 894 key = ODD_keymap[xsym & 0xFF];
865 break; 895 break;
866 case 0xFF: 896 case 0xFF:
867 key = MISC_keymap[xsym&0xFF]; 897 key = MISC_keymap[xsym & 0xFF];
868 break; 898 break;
869 default: 899 default:
870 /* 900 /*
871 fprintf(stderr, "X11: Unhandled xsym, sym = 0x%04x\n", 901 fprintf(stderr, "X11: Unhandled xsym, sym = 0x%04x\n",
872 (unsigned int)xsym); 902 (unsigned int)xsym);
873 */ 903 */
874 break; 904 break;
875 } 905 }
876 } else { 906 } else {
877 /* X11 doesn't know how to translate the key! */ 907 /* X11 doesn't know how to translate the key! */
878 switch (kc) { 908 switch (kc) {
879 /* Caution: 909 /* Caution:
880 These keycodes are from the Microsoft Keyboard 910 These keycodes are from the Microsoft Keyboard
881 */ 911 */
882 case 115: 912 case 115:
883 key = SDLK_LSUPER; 913 key = SDLK_LSUPER;
884 break; 914 break;
885 case 116: 915 case 116:
886 key = SDLK_RSUPER; 916 key = SDLK_RSUPER;
887 break; 917 break;
888 case 117: 918 case 117:
889 key = SDLK_MENU; 919 key = SDLK_MENU;
890 break; 920 break;
891 default: 921 default:
892 /* 922 /*
893 * no point in an error message; happens for 923 * no point in an error message; happens for
894 * several keys when we get a keymap notify 924 * several keys when we get a keymap notify
895 */ 925 */
896 break; 926 break;
897 } 927 }
898 } 928 }
899 return key; 929 return key;
900 } 930 }
901 931
902 /* X11 modifier masks for various keys */ 932 /* X11 modifier masks for various keys */
903 static unsigned meta_l_mask, meta_r_mask, alt_l_mask, alt_r_mask; 933 static unsigned meta_l_mask, meta_r_mask, alt_l_mask, alt_r_mask;
904 static unsigned num_mask, mode_switch_mask; 934 static unsigned num_mask, mode_switch_mask;
905 935
906 static void get_modifier_masks(Display *display) 936 static void
907 { 937 get_modifier_masks (Display * display)
908 static unsigned got_masks; 938 {
909 int i, j; 939 static unsigned got_masks;
910 XModifierKeymap *xmods; 940 int i, j;
911 unsigned n; 941 XModifierKeymap *xmods;
912 942 unsigned n;
913 if(got_masks) 943
914 return; 944 if (got_masks)
915 945 return;
916 xmods = XGetModifierMapping(display); 946
917 n = xmods->max_keypermod; 947 xmods = XGetModifierMapping (display);
918 for(i = 3; i < 8; i++) { 948 n = xmods->max_keypermod;
919 for(j = 0; j < n; j++) { 949 for (i = 3; i < 8; i++) {
920 KeyCode kc = xmods->modifiermap[i * n + j]; 950 for (j = 0; j < n; j++) {
921 KeySym ks = XKeycodeToKeysym(display, kc, 0); 951 KeyCode kc = xmods->modifiermap[i * n + j];
922 unsigned mask = 1 << i; 952 KeySym ks = XKeycodeToKeysym (display, kc, 0);
923 switch(ks) { 953 unsigned mask = 1 << i;
924 case XK_Num_Lock: 954 switch (ks) {
925 num_mask = mask; break; 955 case XK_Num_Lock:
926 case XK_Alt_L: 956 num_mask = mask;
927 alt_l_mask = mask; break; 957 break;
928 case XK_Alt_R: 958 case XK_Alt_L:
929 alt_r_mask = mask; break; 959 alt_l_mask = mask;
930 case XK_Meta_L: 960 break;
931 meta_l_mask = mask; break; 961 case XK_Alt_R:
932 case XK_Meta_R: 962 alt_r_mask = mask;
933 meta_r_mask = mask; break; 963 break;
934 case XK_Mode_switch: 964 case XK_Meta_L:
935 mode_switch_mask = mask; break; 965 meta_l_mask = mask;
936 } 966 break;
937 } 967 case XK_Meta_R:
938 } 968 meta_r_mask = mask;
939 XFreeModifiermap(xmods); 969 break;
940 got_masks = 1; 970 case XK_Mode_switch:
971 mode_switch_mask = mask;
972 break;
973 }
974 }
975 }
976 XFreeModifiermap (xmods);
977 got_masks = 1;
941 } 978 }
942 979
943 980
944 /* 981 /*
945 * This function is semi-official; it is not officially exported and should 982 * This function is semi-official; it is not officially exported and should
949 * 986 *
950 * Note that it isn't completely accurate either; in particular, multi-key 987 * Note that it isn't completely accurate either; in particular, multi-key
951 * sequences (dead accents, compose key sequences) will not work since the 988 * sequences (dead accents, compose key sequences) will not work since the
952 * state has been irrevocably lost. 989 * state has been irrevocably lost.
953 */ 990 */
954 Uint16 X11_KeyToUnicode(SDLKey keysym, SDLMod modifiers) 991 Uint16
955 { 992 X11_KeyToUnicode (SDLKey keysym, SDLMod modifiers)
956 struct SDL_VideoDevice *this = current_video; 993 {
957 char keybuf[32]; 994 SDL_VideoDevice *_this = SDL_GetVideoDevice ();
958 int i; 995 char keybuf[32];
959 KeySym xsym = 0; 996 int i;
960 XKeyEvent xkey; 997 KeySym xsym = 0;
961 Uint16 unicode; 998 XKeyEvent xkey;
962 999 Uint16 unicode;
963 if ( !this || !SDL_Display ) { 1000
964 return 0; 1001 if (!_this || !SDL_Display) {
965 } 1002 return 0;
966 1003 }
967 SDL_memset(&xkey, 0, sizeof(xkey)); 1004
968 xkey.display = SDL_Display; 1005 SDL_memset (&xkey, 0, sizeof (xkey));
969 1006 xkey.display = SDL_Display;
970 xsym = keysym; /* last resort if not found */ 1007
971 for (i = 0; i < 256; ++i) { 1008 xsym = keysym; /* last resort if not found */
972 if ( MISC_keymap[i] == keysym ) { 1009 for (i = 0; i < 256; ++i) {
973 xsym = 0xFF00 | i; 1010 if (MISC_keymap[i] == keysym) {
974 break; 1011 xsym = 0xFF00 | i;
975 } else if ( ODD_keymap[i] == keysym ) { 1012 break;
976 xsym = 0xFE00 | i; 1013 } else if (ODD_keymap[i] == keysym) {
977 break; 1014 xsym = 0xFE00 | i;
978 } 1015 break;
979 } 1016 }
980 1017 }
981 xkey.keycode = XKeysymToKeycode(xkey.display, xsym); 1018
982 1019 xkey.keycode = XKeysymToKeycode (xkey.display, xsym);
983 get_modifier_masks(SDL_Display); 1020
984 if(modifiers & KMOD_SHIFT) 1021 get_modifier_masks (SDL_Display);
985 xkey.state |= ShiftMask; 1022 if (modifiers & KMOD_SHIFT)
986 if(modifiers & KMOD_CAPS) 1023 xkey.state |= ShiftMask;
987 xkey.state |= LockMask; 1024 if (modifiers & KMOD_CAPS)
988 if(modifiers & KMOD_CTRL) 1025 xkey.state |= LockMask;
989 xkey.state |= ControlMask; 1026 if (modifiers & KMOD_CTRL)
990 if(modifiers & KMOD_MODE) 1027 xkey.state |= ControlMask;
991 xkey.state |= mode_switch_mask; 1028 if (modifiers & KMOD_MODE)
992 if(modifiers & KMOD_LALT) 1029 xkey.state |= mode_switch_mask;
993 xkey.state |= alt_l_mask; 1030 if (modifiers & KMOD_LALT)
994 if(modifiers & KMOD_RALT) 1031 xkey.state |= alt_l_mask;
995 xkey.state |= alt_r_mask; 1032 if (modifiers & KMOD_RALT)
996 if(modifiers & KMOD_LMETA) 1033 xkey.state |= alt_r_mask;
997 xkey.state |= meta_l_mask; 1034 if (modifiers & KMOD_LMETA)
998 if(modifiers & KMOD_RMETA) 1035 xkey.state |= meta_l_mask;
999 xkey.state |= meta_r_mask; 1036 if (modifiers & KMOD_RMETA)
1000 if(modifiers & KMOD_NUM) 1037 xkey.state |= meta_r_mask;
1001 xkey.state |= num_mask; 1038 if (modifiers & KMOD_NUM)
1002 1039 xkey.state |= num_mask;
1003 unicode = 0; 1040
1004 if ( XLookupString(&xkey, keybuf, sizeof(keybuf), NULL, NULL) ) 1041 unicode = 0;
1005 unicode = (unsigned char)keybuf[0]; 1042 if (XLookupString (&xkey, keybuf, sizeof (keybuf), NULL, NULL))
1006 return(unicode); 1043 unicode = (unsigned char) keybuf[0];
1044 return (unicode);
1007 } 1045 }
1008 1046
1009 1047
1010 /* 1048 /*
1011 * Called when focus is regained, to read the keyboard state and generate 1049 * Called when focus is regained, to read the keyboard state and generate
1012 * synthetic keypress/release events. 1050 * synthetic keypress/release events.
1013 * key_vec is a bit vector of keycodes (256 bits) 1051 * key_vec is a bit vector of keycodes (256 bits)
1014 */ 1052 */
1015 void X11_SetKeyboardState(Display *display, const char *key_vec) 1053 void
1016 { 1054 X11_SetKeyboardState (Display * display, const char *key_vec)
1017 char keys_return[32]; 1055 {
1018 int i; 1056 char keys_return[32];
1019 Uint8 *kstate = SDL_GetKeyState(NULL); 1057 int i;
1020 SDLMod modstate; 1058 Uint8 *kstate = SDL_GetKeyState (NULL);
1021 Window junk_window; 1059 SDLMod modstate;
1022 int x, y; 1060 Window junk_window;
1023 unsigned int mask; 1061 int x, y;
1024 1062 unsigned int mask;
1025 /* The first time the window is mapped, we initialize key state */ 1063
1026 if ( ! key_vec ) { 1064 /* The first time the window is mapped, we initialize key state */
1027 XQueryKeymap(display, keys_return); 1065 if (!key_vec) {
1028 key_vec = keys_return; 1066 XQueryKeymap (display, keys_return);
1029 } 1067 key_vec = keys_return;
1030 1068 }
1031 /* Get the keyboard modifier state */ 1069
1032 modstate = 0; 1070 /* Get the keyboard modifier state */
1033 get_modifier_masks(display); 1071 modstate = 0;
1034 if ( XQueryPointer(display, DefaultRootWindow(display), 1072 get_modifier_masks (display);
1035 &junk_window, &junk_window, &x, &y, &x, &y, &mask) ) { 1073 if (XQueryPointer (display, DefaultRootWindow (display),
1036 if ( mask & LockMask ) { 1074 &junk_window, &junk_window, &x, &y, &x, &y, &mask)) {
1037 modstate |= KMOD_CAPS; 1075 if (mask & LockMask) {
1038 } 1076 modstate |= KMOD_CAPS;
1039 if ( mask & mode_switch_mask ) { 1077 }
1040 modstate |= KMOD_MODE; 1078 if (mask & mode_switch_mask) {
1041 } 1079 modstate |= KMOD_MODE;
1042 if ( mask & num_mask ) { 1080 }
1043 modstate |= KMOD_NUM; 1081 if (mask & num_mask) {
1044 } 1082 modstate |= KMOD_NUM;
1045 } 1083 }
1046 1084 }
1047 /* Zero the new keyboard state and generate it */ 1085
1048 SDL_memset(kstate, 0, SDLK_LAST); 1086 /* Zero the new keyboard state and generate it */
1049 /* 1087 SDL_memset (kstate, 0, SDLK_LAST);
1050 * An obvious optimisation is to check entire longwords at a time in 1088 /*
1051 * both loops, but we can't be sure the arrays are aligned so it's not 1089 * An obvious optimisation is to check entire longwords at a time in
1052 * worth the extra complexity 1090 * both loops, but we can't be sure the arrays are aligned so it's not
1053 */ 1091 * worth the extra complexity
1054 for ( i = 0; i < 32; i++ ) { 1092 */
1055 int j; 1093 for (i = 0; i < 32; i++) {
1056 if ( !key_vec[i] ) 1094 int j;
1057 continue; 1095 if (!key_vec[i])
1058 for ( j = 0; j < 8; j++ ) { 1096 continue;
1059 if ( key_vec[i] & (1 << j) ) { 1097 for (j = 0; j < 8; j++) {
1060 SDLKey key; 1098 if (key_vec[i] & (1 << j)) {
1061 KeyCode kc = (i << 3 | j); 1099 SDLKey key;
1062 key = X11_TranslateKeycode(display, kc); 1100 KeyCode kc = (i << 3 | j);
1063 if ( key == SDLK_UNKNOWN ) { 1101 key = X11_TranslateKeycode (display, kc);
1064 continue; 1102 if (key == SDLK_UNKNOWN) {
1065 } 1103 continue;
1066 kstate[key] = SDL_PRESSED; 1104 }
1067 switch (key) { 1105 kstate[key] = SDL_PRESSED;
1068 case SDLK_LSHIFT: 1106 switch (key) {
1069 modstate |= KMOD_LSHIFT; 1107 case SDLK_LSHIFT:
1070 break; 1108 modstate |= KMOD_LSHIFT;
1071 case SDLK_RSHIFT: 1109 break;
1072 modstate |= KMOD_RSHIFT; 1110 case SDLK_RSHIFT:
1073 break; 1111 modstate |= KMOD_RSHIFT;
1074 case SDLK_LCTRL: 1112 break;
1075 modstate |= KMOD_LCTRL; 1113 case SDLK_LCTRL:
1076 break; 1114 modstate |= KMOD_LCTRL;
1077 case SDLK_RCTRL: 1115 break;
1078 modstate |= KMOD_RCTRL; 1116 case SDLK_RCTRL:
1079 break; 1117 modstate |= KMOD_RCTRL;
1080 case SDLK_LALT: 1118 break;
1081 modstate |= KMOD_LALT; 1119 case SDLK_LALT:
1082 break; 1120 modstate |= KMOD_LALT;
1083 case SDLK_RALT: 1121 break;
1084 modstate |= KMOD_RALT; 1122 case SDLK_RALT:
1085 break; 1123 modstate |= KMOD_RALT;
1086 case SDLK_LMETA: 1124 break;
1087 modstate |= KMOD_LMETA; 1125 case SDLK_LMETA:
1088 break; 1126 modstate |= KMOD_LMETA;
1089 case SDLK_RMETA: 1127 break;
1090 modstate |= KMOD_RMETA; 1128 case SDLK_RMETA:
1091 break; 1129 modstate |= KMOD_RMETA;
1092 default: 1130 break;
1093 break; 1131 default:
1094 } 1132 break;
1095 } 1133 }
1096 } 1134 }
1097 } 1135 }
1098 1136 }
1099 /* Hack - set toggle key state */ 1137
1100 if ( modstate & KMOD_CAPS ) { 1138 /* Hack - set toggle key state */
1101 kstate[SDLK_CAPSLOCK] = SDL_PRESSED; 1139 if (modstate & KMOD_CAPS) {
1102 } else { 1140 kstate[SDLK_CAPSLOCK] = SDL_PRESSED;
1103 kstate[SDLK_CAPSLOCK] = SDL_RELEASED; 1141 } else {
1104 } 1142 kstate[SDLK_CAPSLOCK] = SDL_RELEASED;
1105 if ( modstate & KMOD_NUM ) { 1143 }
1106 kstate[SDLK_NUMLOCK] = SDL_PRESSED; 1144 if (modstate & KMOD_NUM) {
1107 } else { 1145 kstate[SDLK_NUMLOCK] = SDL_PRESSED;
1108 kstate[SDLK_NUMLOCK] = SDL_RELEASED; 1146 } else {
1109 } 1147 kstate[SDLK_NUMLOCK] = SDL_RELEASED;
1110 1148 }
1111 /* Set the final modifier state */ 1149
1112 SDL_SetModState(modstate); 1150 /* Set the final modifier state */
1113 } 1151 SDL_SetModState (modstate);
1114 1152 }
1115 void X11_InitOSKeymap(_THIS) 1153
1116 { 1154 void
1117 X11_InitKeymap(); 1155 X11_InitOSKeymap (_THIS)
1118 } 1156 {
1119 1157 X11_InitKeymap ();
1120 void X11_SaveScreenSaver(Display *display, int *saved_timeout, BOOL *dpms) 1158 }
1121 { 1159
1122 int timeout, interval, prefer_blank, allow_exp; 1160 void
1123 XGetScreenSaver(display, &timeout, &interval, &prefer_blank, &allow_exp); 1161 X11_SaveScreenSaver (Display * display, int *saved_timeout, BOOL * dpms)
1124 *saved_timeout = timeout; 1162 {
1163 int timeout, interval, prefer_blank, allow_exp;
1164 XGetScreenSaver (display, &timeout, &interval, &prefer_blank, &allow_exp);
1165 *saved_timeout = timeout;
1125 1166
1126 #if SDL_VIDEO_DRIVER_X11_DPMS 1167 #if SDL_VIDEO_DRIVER_X11_DPMS
1127 if ( SDL_X11_HAVE_DPMS ) { 1168 if (SDL_X11_HAVE_DPMS) {
1128 int dummy; 1169 int dummy;
1129 if ( DPMSQueryExtension(display, &dummy, &dummy) ) { 1170 if (DPMSQueryExtension (display, &dummy, &dummy)) {
1130 CARD16 state; 1171 CARD16 state;
1131 DPMSInfo(display, &state, dpms); 1172 DPMSInfo (display, &state, dpms);
1132 } 1173 }
1133 } 1174 }
1134 #else 1175 #else
1135 *dpms = 0; 1176 *dpms = 0;
1136 #endif /* SDL_VIDEO_DRIVER_X11_DPMS */ 1177 #endif /* SDL_VIDEO_DRIVER_X11_DPMS */
1137 } 1178 }
1138 1179
1139 void X11_DisableScreenSaver(Display *display) 1180 void
1140 { 1181 X11_DisableScreenSaver (Display * display)
1141 int timeout, interval, prefer_blank, allow_exp; 1182 {
1142 XGetScreenSaver(display, &timeout, &interval, &prefer_blank, &allow_exp); 1183 int timeout, interval, prefer_blank, allow_exp;
1143 timeout = 0; 1184 XGetScreenSaver (display, &timeout, &interval, &prefer_blank, &allow_exp);
1144 XSetScreenSaver(display, timeout, interval, prefer_blank, allow_exp); 1185 timeout = 0;
1186 XSetScreenSaver (display, timeout, interval, prefer_blank, allow_exp);
1145 1187
1146 #if SDL_VIDEO_DRIVER_X11_DPMS 1188 #if SDL_VIDEO_DRIVER_X11_DPMS
1147 if ( SDL_X11_HAVE_DPMS ) { 1189 if (SDL_X11_HAVE_DPMS) {
1148 int dummy; 1190 int dummy;
1149 if ( DPMSQueryExtension(display, &dummy, &dummy) ) { 1191 if (DPMSQueryExtension (display, &dummy, &dummy)) {
1150 DPMSDisable(display); 1192 DPMSDisable (display);
1151 } 1193 }
1152 } 1194 }
1153 #endif /* SDL_VIDEO_DRIVER_X11_DPMS */ 1195 #endif /* SDL_VIDEO_DRIVER_X11_DPMS */
1154 } 1196 }
1155 1197
1156 void X11_RestoreScreenSaver(Display *display, int saved_timeout, BOOL dpms) 1198 void
1157 { 1199 X11_RestoreScreenSaver (Display * display, int saved_timeout, BOOL dpms)
1158 int timeout, interval, prefer_blank, allow_exp; 1200 {
1159 XGetScreenSaver(display, &timeout, &interval, &prefer_blank, &allow_exp); 1201 int timeout, interval, prefer_blank, allow_exp;
1160 timeout = saved_timeout; 1202 XGetScreenSaver (display, &timeout, &interval, &prefer_blank, &allow_exp);
1161 XSetScreenSaver(display, timeout, interval, prefer_blank, allow_exp); 1203 timeout = saved_timeout;
1204 XSetScreenSaver (display, timeout, interval, prefer_blank, allow_exp);
1162 1205
1163 #if SDL_VIDEO_DRIVER_X11_DPMS 1206 #if SDL_VIDEO_DRIVER_X11_DPMS
1164 if ( SDL_X11_HAVE_DPMS ) { 1207 if (SDL_X11_HAVE_DPMS) {
1165 int dummy; 1208 int dummy;
1166 if ( DPMSQueryExtension(display, &dummy, &dummy) ) { 1209 if (DPMSQueryExtension (display, &dummy, &dummy)) {
1167 if ( dpms ) { 1210 if (dpms) {
1168 DPMSEnable(display); 1211 DPMSEnable (display);
1169 } 1212 }
1170 } 1213 }
1171 } 1214 }
1172 #endif /* SDL_VIDEO_DRIVER_X11_DPMS */ 1215 #endif /* SDL_VIDEO_DRIVER_X11_DPMS */
1173 } 1216 }
1217
1218 /* vi: set ts=4 sw=4 expandtab: */