Mercurial > sdl-ios-xcode
annotate src/video/x11/SDL_x11events.c @ 3996:5f463dddee36 SDL-1.2
Fixed yasm/nasm warning.
Fixes Bugzilla #446.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Tue, 03 Jul 2007 09:53:26 +0000 |
parents | b966761fef6c |
children | f61a20d195f7 |
rev | line source |
---|---|
0 | 1 /* |
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 | 4 |
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 | 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 | 9 |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
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 | 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 | 18 |
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 | 21 */ |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1379
diff
changeset
|
22 #include "SDL_config.h" |
0 | 23 |
24 /* Handle the event stream, converting X11 events into SDL events */ | |
25 | |
26 #include <setjmp.h> | |
27 #include <X11/Xlib.h> | |
28 #include <X11/Xutil.h> | |
29 #include <X11/keysym.h> | |
30 #ifdef __SVR4 | |
31 #include <X11/Sunkeysym.h> | |
32 #endif | |
75
b0ae59d0f3ee
Added patches from FreeBSD ports
Sam Lantinga <slouken@lokigames.com>
parents:
14
diff
changeset
|
33 #include <sys/types.h> |
0 | 34 #include <sys/time.h> |
75
b0ae59d0f3ee
Added patches from FreeBSD ports
Sam Lantinga <slouken@lokigames.com>
parents:
14
diff
changeset
|
35 #include <unistd.h> |
0 | 36 |
1359
1e4ba2e063b4
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
37 #include "SDL_timer.h" |
0 | 38 #include "SDL_syswm.h" |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1359
diff
changeset
|
39 #include "../SDL_sysvideo.h" |
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1359
diff
changeset
|
40 #include "../../events/SDL_sysevents.h" |
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1359
diff
changeset
|
41 #include "../../events/SDL_events_c.h" |
0 | 42 #include "SDL_x11video.h" |
43 #include "SDL_x11dga_c.h" | |
44 #include "SDL_x11modes_c.h" | |
45 #include "SDL_x11image_c.h" | |
46 #include "SDL_x11gamma_c.h" | |
47 #include "SDL_x11wm_c.h" | |
48 #include "SDL_x11mouse_c.h" | |
49 #include "SDL_x11events_c.h" | |
50 | |
51 | |
14
c3e9d4a623c1
Fixed stuck keys when changing the video mode
Sam Lantinga <slouken@lokigames.com>
parents:
12
diff
changeset
|
52 /* 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
|
53 /*#define DEBUG_XEVENTS*/ |
c3e9d4a623c1
Fixed stuck keys when changing the video mode
Sam Lantinga <slouken@lokigames.com>
parents:
12
diff
changeset
|
54 |
0 | 55 /* The translation tables from an X11 keysym to a SDL keysym */ |
56 static SDLKey ODD_keymap[256]; | |
57 static SDLKey MISC_keymap[256]; | |
1327 | 58 SDLKey X11_TranslateKeycode(Display *display, KeyCode kc); |
59 | |
60 | |
61 #ifdef X_HAVE_UTF8_STRING | |
62 Uint32 Utf8ToUcs4(const Uint8 *utf8) | |
63 { | |
64 Uint32 c; | |
65 int i = 1; | |
66 int noOctets = 0; | |
67 int firstOctetMask = 0; | |
68 unsigned char firstOctet = utf8[0]; | |
69 if (firstOctet < 0x80) { | |
70 /* | |
71 Characters in the range: | |
72 00000000 to 01111111 (ASCII Range) | |
73 are stored in one octet: | |
74 0xxxxxxx (The same as its ASCII representation) | |
75 The least 6 significant bits of the first octet is the most 6 significant nonzero bits | |
76 of the UCS4 representation. | |
77 */ | |
78 noOctets = 1; | |
79 firstOctetMask = 0x7F; /* 0(1111111) - The most significant bit is ignored */ | |
80 } else if ((firstOctet & 0xE0) /* get the most 3 significant bits by AND'ing with 11100000 */ | |
81 == 0xC0 ) { /* see if those 3 bits are 110. If so, the char is in this range */ | |
82 /* | |
83 Characters in the range: | |
84 00000000 10000000 to 00000111 11111111 | |
85 are stored in two octets: | |
86 110xxxxx 10xxxxxx | |
87 The least 5 significant bits of the first octet is the most 5 significant nonzero bits | |
88 of the UCS4 representation. | |
89 */ | |
90 noOctets = 2; | |
91 firstOctetMask = 0x1F; /* 000(11111) - The most 3 significant bits are ignored */ | |
92 } else if ((firstOctet & 0xF0) /* get the most 4 significant bits by AND'ing with 11110000 */ | |
93 == 0xE0) { /* see if those 4 bits are 1110. If so, the char is in this range */ | |
94 /* | |
95 Characters in the range: | |
96 00001000 00000000 to 11111111 11111111 | |
97 are stored in three octets: | |
98 1110xxxx 10xxxxxx 10xxxxxx | |
99 The least 4 significant bits of the first octet is the most 4 significant nonzero bits | |
100 of the UCS4 representation. | |
101 */ | |
102 noOctets = 3; | |
103 firstOctetMask = 0x0F; /* 0000(1111) - The most 4 significant bits are ignored */ | |
104 } else if ((firstOctet & 0xF8) /* get the most 5 significant bits by AND'ing with 11111000 */ | |
105 == 0xF0) { /* see if those 5 bits are 11110. If so, the char is in this range */ | |
106 /* | |
107 Characters in the range: | |
108 00000001 00000000 00000000 to 00011111 11111111 11111111 | |
109 are stored in four octets: | |
110 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx | |
111 The least 3 significant bits of the first octet is the most 3 significant nonzero bits | |
112 of the UCS4 representation. | |
113 */ | |
114 noOctets = 4; | |
115 firstOctetMask = 0x07; /* 11110(111) - The most 5 significant bits are ignored */ | |
116 } else if ((firstOctet & 0xFC) /* get the most 6 significant bits by AND'ing with 11111100 */ | |
117 == 0xF8) { /* see if those 6 bits are 111110. If so, the char is in this range */ | |
118 /* | |
119 Characters in the range: | |
120 00000000 00100000 00000000 00000000 to | |
121 00000011 11111111 11111111 11111111 | |
122 are stored in five octets: | |
123 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx | |
124 The least 2 significant bits of the first octet is the most 2 significant nonzero bits | |
125 of the UCS4 representation. | |
126 */ | |
127 noOctets = 5; | |
128 firstOctetMask = 0x03; /* 111110(11) - The most 6 significant bits are ignored */ | |
129 } else if ((firstOctet & 0xFE) /* get the most 7 significant bits by AND'ing with 11111110 */ | |
130 == 0xFC) { /* see if those 7 bits are 1111110. If so, the char is in this range */ | |
131 /* | |
132 Characters in the range: | |
133 00000100 00000000 00000000 00000000 to | |
134 01111111 11111111 11111111 11111111 | |
135 are stored in six octets: | |
136 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx | |
137 The least significant bit of the first octet is the most significant nonzero bit | |
138 of the UCS4 representation. | |
139 */ | |
140 noOctets = 6; | |
141 firstOctetMask = 0x01; /* 1111110(1) - The most 7 significant bits are ignored */ | |
142 } else | |
143 return 0; /* The given chunk is not a valid UTF-8 encoded Unicode character */ | |
144 | |
145 /* | |
146 The least noOctets significant bits of the first octet is the most 2 significant nonzero bits | |
147 of the UCS4 representation. | |
148 The first 6 bits of the UCS4 representation is the least 8-noOctets-1 significant bits of | |
149 firstOctet if the character is not ASCII. If so, it's the least 7 significant bits of firstOctet. | |
150 This done by AND'ing firstOctet with its mask to trim the bits used for identifying the | |
151 number of continuing octets (if any) and leave only the free bits (the x's) | |
152 Sample: | |
153 1-octet: 0xxxxxxx & 01111111 = 0xxxxxxx | |
154 2-octets: 110xxxxx & 00011111 = 000xxxxx | |
155 */ | |
156 c = firstOctet & firstOctetMask; | |
157 | |
158 /* Now, start filling c.ucs4 with the bits from the continuing octets from utf8. */ | |
159 for (i = 1; i < noOctets; i++) { | |
160 /* A valid continuing octet is of the form 10xxxxxx */ | |
161 if ((utf8[i] & 0xC0) /* get the most 2 significant bits by AND'ing with 11000000 */ | |
162 != 0x80) /* see if those 2 bits are 10. If not, the is a malformed sequence. */ | |
163 /*The given chunk is a partial sequence at the end of a string that could | |
164 begin a valid character */ | |
165 return 0; | |
166 | |
167 /* Make room for the next 6-bits */ | |
168 c <<= 6; | |
169 | |
170 /* | |
171 Take only the least 6 significance bits of the current octet (utf8[i]) and fill the created room | |
172 of c.ucs4 with them. | |
173 This done by AND'ing utf8[i] with 00111111 and the OR'ing the result with c.ucs4. | |
174 */ | |
175 c |= utf8[i] & 0x3F; | |
176 } | |
177 return c; | |
178 } | |
3978
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
179 |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
180 /* Given a UTF-8 encoded string pointed to by utf8 of length length in |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
181 bytes, returns the corresponding UTF-16 encoded string in the |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
182 buffer pointed to by utf16. The maximum number of UTF-16 encoding |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
183 units (i.e., Unit16s) allowed in the buffer is specified in |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
184 utf16_max_length. The return value is the number of UTF-16 |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
185 encoding units placed in the output buffer pointed to by utf16. |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
186 |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
187 In case of an error, -1 is returned, leaving some unusable partial |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
188 results in the output buffer. |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
189 |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
190 The caller must estimate the size of utf16 buffer by itself before |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
191 calling this function. Insufficient output buffer is considered as |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
192 an error, and once an error occured, this function doesn't give any |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
193 clue how large the result will be. |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
194 |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
195 The error cases include following: |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
196 |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
197 - Invalid byte sequences were in the input UTF-8 bytes. The caller |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
198 has no way to know what point in the input buffer was the |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
199 errornous byte. |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
200 |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
201 - The input contained a character (a valid UTF-8 byte sequence) |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
202 whose scalar value exceeded the range that UTF-16 can represent |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
203 (i.e., characters whose Unicode scalar value above 0x110000). |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
204 |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
205 - The output buffer has no enough space to hold entire utf16 data. |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
206 |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
207 Please note: |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
208 |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
209 - '\0'-termination is not assumed both on the input UTF-8 string |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
210 and on the output UTF-16 string; any legal zero byte in the input |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
211 UTF-8 string will be converted to a 16-bit zero in output. As a |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
212 side effect, the last UTF-16 encoding unit stored in the output |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
213 buffer will have a non-zero value if the input UTF-8 was not |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
214 '\0'-terminated. |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
215 |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
216 - UTF-8 aliases are *not* considered as an error. They are |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
217 converted to UTF-16. For example, 0xC0 0xA0, 0xE0 0x80 0xA0, |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
218 and 0xF0 0x80 0x80 0xA0 are all mapped to a single UTF-16 |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
219 encoding unit 0x0020. |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
220 |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
221 - Three byte UTF-8 sequences whose value corresponds to a surrogate |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
222 code or other reserved scalar value are not considered as an |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
223 error either. They may cause an invalid UTF-16 data (e.g., those |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
224 containing unpaired surrogates). |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
225 |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
226 */ |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
227 |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
228 static int Utf8ToUtf16(const Uint8 *utf8, const int utf8_length, Uint16 *utf16, const int utf16_max_length) { |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
229 |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
230 /* p moves over the output buffer. max_ptr points to the next to the last slot of the buffer. */ |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
231 Uint16 *p = utf16; |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
232 Uint16 const *const max_ptr = utf16 + utf16_max_length; |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
233 |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
234 /* end_of_input points to the last byte of input as opposed to the next to the last byte. */ |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
235 Uint8 const *const end_of_input = utf8 + utf8_length - 1; |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
236 |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
237 while (utf8 <= end_of_input) { |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
238 if (p >= max_ptr) { |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
239 /* No more output space. */ |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
240 return -1; |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
241 } |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
242 Uint8 const c = *utf8; |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
243 if (c < 0x80) { |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
244 /* One byte ASCII. */ |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
245 *p++ = c; |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
246 utf8 += 1; |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
247 } else if (c < 0xC0) { |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
248 /* Follower byte without preceeding leader bytes. */ |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
249 return -1; |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
250 } else if (c < 0xE0) { |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
251 /* Two byte sequence. We need one follower byte. */ |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
252 if (end_of_input - utf8 < 1 || (((utf8[1] ^ 0x80)) & 0xC0)) { |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
253 return -1; |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
254 } |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
255 *p++ = (Uint16)(0xCF80 + (c << 6) + utf8[1]); |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
256 utf8 += 2; |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
257 } else if (c < 0xF0) { |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
258 /* Three byte sequence. We need two follower byte. */ |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
259 if (end_of_input - utf8 < 2 || (((utf8[1] ^ 0x80) | (utf8[2] ^ 0x80)) & 0xC0)) { |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
260 return -1; |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
261 } |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
262 *p++ = (Uint16)(0xDF80 + (c << 12) + (utf8[1] << 6) + utf8[2]); |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
263 utf8 += 3; |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
264 } else if (c < 0xF8) { |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
265 int plane; |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
266 /* Four byte sequence. We need three follower bytes. */ |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
267 if (end_of_input - utf8 < 3 || (((utf8[1] ^ 0x80) | (utf8[2] ^0x80) | (utf8[3] ^ 0x80)) & 0xC0)) { |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
268 return -1; |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
269 } |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
270 plane = (-0xC8 + (c << 2) + (utf8[1] >> 4)); |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
271 if (plane == 0) { |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
272 /* This four byte sequence is an alias that |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
273 corresponds to a Unicode scalar value in BMP. |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
274 It fits in an UTF-16 encoding unit. */ |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
275 *p++ = (Uint16)(0xDF80 + (utf8[1] << 12) + (utf8[2] << 6) + utf8[3]); |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
276 } else if (plane <= 16) { |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
277 /* This is a legal four byte sequence that corresponds to a surrogate pair. */ |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
278 if (p + 1 >= max_ptr) { |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
279 /* No enough space on the output buffer for the pair. */ |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
280 return -1; |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
281 } |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
282 *p++ = (Uint16)(0xE5B8 + (c << 8) + (utf8[1] << 2) + (utf8[2] >> 4)); |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
283 *p++ = (Uint16)(0xDB80 + ((utf8[2] & 0x0F) << 6) + utf8[3]); |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
284 } else { |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
285 /* This four byte sequence is out of UTF-16 code space. */ |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
286 return -1; |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
287 } |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
288 utf8 += 4; |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
289 } else { |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
290 /* Longer sequence or unused byte. */ |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
291 return -1; |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
292 } |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
293 } |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
294 return p - utf16; |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
295 } |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
296 |
1327 | 297 #endif |
0 | 298 |
299 /* Check to see if this is a repeated key. | |
300 (idea shamelessly lifted from GII -- thanks guys! :) | |
301 */ | |
302 static int X11_KeyRepeat(Display *display, XEvent *event) | |
303 { | |
304 XEvent peekevent; | |
305 int repeated; | |
306 | |
307 repeated = 0; | |
1575
3ba88cb7eb1b
Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
308 if ( XPending(display) ) { |
3ba88cb7eb1b
Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
309 XPeekEvent(display, &peekevent); |
0 | 310 if ( (peekevent.type == KeyPress) && |
311 (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
|
312 ((peekevent.xkey.time-event->xkey.time) < 2) ) { |
0 | 313 repeated = 1; |
1575
3ba88cb7eb1b
Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
314 XNextEvent(display, &peekevent); |
0 | 315 } |
316 } | |
317 return(repeated); | |
318 } | |
319 | |
320 /* Note: The X server buffers and accumulates mouse motion events, so | |
321 the motion event generated by the warp may not appear exactly as we | |
322 expect it to. We work around this (and improve performance) by only | |
323 warping the pointer when it reaches the edge, and then wait for it. | |
324 */ | |
325 #define MOUSE_FUDGE_FACTOR 8 | |
326 | |
327 static __inline__ int X11_WarpedMotion(_THIS, XEvent *xevent) | |
328 { | |
329 int w, h, i; | |
330 int deltax, deltay; | |
331 int posted; | |
332 | |
333 w = SDL_VideoSurface->w; | |
334 h = SDL_VideoSurface->h; | |
335 deltax = xevent->xmotion.x - mouse_last.x; | |
336 deltay = xevent->xmotion.y - mouse_last.y; | |
337 #ifdef DEBUG_MOTION | |
338 printf("Warped mouse motion: %d,%d\n", deltax, deltay); | |
339 #endif | |
340 mouse_last.x = xevent->xmotion.x; | |
341 mouse_last.y = xevent->xmotion.y; | |
342 posted = SDL_PrivateMouseMotion(0, 1, deltax, deltay); | |
343 | |
344 if ( (xevent->xmotion.x < MOUSE_FUDGE_FACTOR) || | |
345 (xevent->xmotion.x > (w-MOUSE_FUDGE_FACTOR)) || | |
346 (xevent->xmotion.y < MOUSE_FUDGE_FACTOR) || | |
347 (xevent->xmotion.y > (h-MOUSE_FUDGE_FACTOR)) ) { | |
348 /* Get the events that have accumulated */ | |
1575
3ba88cb7eb1b
Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
349 while ( XCheckTypedEvent(SDL_Display, MotionNotify, xevent) ) { |
0 | 350 deltax = xevent->xmotion.x - mouse_last.x; |
351 deltay = xevent->xmotion.y - mouse_last.y; | |
352 #ifdef DEBUG_MOTION | |
353 printf("Extra mouse motion: %d,%d\n", deltax, deltay); | |
354 #endif | |
355 mouse_last.x = xevent->xmotion.x; | |
356 mouse_last.y = xevent->xmotion.y; | |
357 posted += SDL_PrivateMouseMotion(0, 1, deltax, deltay); | |
358 } | |
359 mouse_last.x = w/2; | |
360 mouse_last.y = h/2; | |
1575
3ba88cb7eb1b
Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
361 XWarpPointer(SDL_Display, None, SDL_Window, 0, 0, 0, 0, |
0 | 362 mouse_last.x, mouse_last.y); |
363 for ( i=0; i<10; ++i ) { | |
1575
3ba88cb7eb1b
Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
364 XMaskEvent(SDL_Display, PointerMotionMask, xevent); |
0 | 365 if ( (xevent->xmotion.x > |
366 (mouse_last.x-MOUSE_FUDGE_FACTOR)) && | |
367 (xevent->xmotion.x < | |
368 (mouse_last.x+MOUSE_FUDGE_FACTOR)) && | |
369 (xevent->xmotion.y > | |
370 (mouse_last.y-MOUSE_FUDGE_FACTOR)) && | |
371 (xevent->xmotion.y < | |
372 (mouse_last.y+MOUSE_FUDGE_FACTOR)) ) { | |
373 break; | |
374 } | |
375 #ifdef DEBUG_XEVENTS | |
376 printf("Lost mouse motion: %d,%d\n", xevent->xmotion.x, xevent->xmotion.y); | |
377 #endif | |
378 } | |
379 #ifdef DEBUG_XEVENTS | |
380 if ( i == 10 ) { | |
381 printf("Warning: didn't detect mouse warp motion\n"); | |
382 } | |
383 #endif | |
384 } | |
385 return(posted); | |
386 } | |
387 | |
388 static int X11_DispatchEvent(_THIS) | |
389 { | |
390 int posted; | |
391 XEvent xevent; | |
392 | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1328
diff
changeset
|
393 SDL_memset(&xevent, '\0', sizeof (XEvent)); /* valgrind fix. --ryan. */ |
1575
3ba88cb7eb1b
Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
394 XNextEvent(SDL_Display, &xevent); |
0 | 395 |
3978
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
396 /* Discard KeyRelease and KeyPress events generated by auto-repeat. |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
397 We need to do it before passing event to XFilterEvent. Otherwise, |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
398 KeyRelease aware IMs are confused... */ |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
399 if ( xevent.type == KeyRelease |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
400 && X11_KeyRepeat(SDL_Display, &xevent) ) { |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
401 return 0; |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
402 } |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
403 |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
404 #ifdef X_HAVE_UTF8_STRING |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
405 /* If we are translating with IM, we need to pass all events |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
406 to XFilterEvent, and discard those filtered events immediately. */ |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
407 if ( SDL_TranslateUNICODE |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
408 && SDL_IM != NULL |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
409 && XFilterEvent(&xevent, None) ) { |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
410 return 0; |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
411 } |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
412 #endif |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
413 |
0 | 414 posted = 0; |
415 switch (xevent.type) { | |
416 | |
417 /* Gaining mouse coverage? */ | |
418 case EnterNotify: { | |
419 #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
|
420 printf("EnterNotify! (%d,%d)\n", xevent.xcrossing.x, xevent.xcrossing.y); |
0 | 421 if ( xevent.xcrossing.mode == NotifyGrab ) |
422 printf("Mode: NotifyGrab\n"); | |
423 if ( xevent.xcrossing.mode == NotifyUngrab ) | |
424 printf("Mode: NotifyUngrab\n"); | |
425 #endif | |
426 if ( (xevent.xcrossing.mode != NotifyGrab) && | |
427 (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
|
428 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
|
429 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
|
430 } |
1789 | 431 posted = SDL_PrivateMouseMotion(0, 0, |
432 xevent.xcrossing.x, | |
433 xevent.xcrossing.y); | |
0 | 434 } |
435 } | |
436 break; | |
437 | |
438 /* Losing mouse coverage? */ | |
439 case LeaveNotify: { | |
440 #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
|
441 printf("LeaveNotify! (%d,%d)\n", xevent.xcrossing.x, xevent.xcrossing.y); |
0 | 442 if ( xevent.xcrossing.mode == NotifyGrab ) |
443 printf("Mode: NotifyGrab\n"); | |
444 if ( xevent.xcrossing.mode == NotifyUngrab ) | |
445 printf("Mode: NotifyUngrab\n"); | |
446 #endif | |
447 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
|
448 (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
|
449 (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
|
450 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
|
451 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
|
452 } else { |
2bddc38a9f5d
When the mouse is grabbed, send the application the motion associated with
Sam Lantinga <slouken@lokigames.com>
parents:
75
diff
changeset
|
453 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
|
454 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
|
455 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
|
456 } |
0 | 457 } |
458 } | |
459 break; | |
460 | |
461 /* Gaining input focus? */ | |
462 case FocusIn: { | |
463 #ifdef DEBUG_XEVENTS | |
464 printf("FocusIn!\n"); | |
465 #endif | |
466 posted = SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS); | |
467 | |
1328
27ddb06a0bca
Date: Sat, 04 Feb 2006 19:47:23 +0900
Sam Lantinga <slouken@libsdl.org>
parents:
1327
diff
changeset
|
468 #ifdef X_HAVE_UTF8_STRING |
1327 | 469 if ( SDL_IC != NULL ) { |
1575
3ba88cb7eb1b
Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
470 XSetICFocus(SDL_IC); |
1327 | 471 } |
1328
27ddb06a0bca
Date: Sat, 04 Feb 2006 19:47:23 +0900
Sam Lantinga <slouken@libsdl.org>
parents:
1327
diff
changeset
|
472 #endif |
0 | 473 /* Queue entry into fullscreen mode */ |
474 switch_waiting = 0x01 | SDL_FULLSCREEN; | |
475 switch_time = SDL_GetTicks() + 1500; | |
476 } | |
477 break; | |
478 | |
479 /* Losing input focus? */ | |
480 case FocusOut: { | |
481 #ifdef DEBUG_XEVENTS | |
482 printf("FocusOut!\n"); | |
483 #endif | |
484 posted = SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS); | |
485 | |
1328
27ddb06a0bca
Date: Sat, 04 Feb 2006 19:47:23 +0900
Sam Lantinga <slouken@libsdl.org>
parents:
1327
diff
changeset
|
486 #ifdef X_HAVE_UTF8_STRING |
1327 | 487 if ( SDL_IC != NULL ) { |
1575
3ba88cb7eb1b
Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
488 XUnsetICFocus(SDL_IC); |
1327 | 489 } |
1328
27ddb06a0bca
Date: Sat, 04 Feb 2006 19:47:23 +0900
Sam Lantinga <slouken@libsdl.org>
parents:
1327
diff
changeset
|
490 #endif |
0 | 491 /* Queue leaving fullscreen mode */ |
492 switch_waiting = 0x01; | |
493 switch_time = SDL_GetTicks() + 200; | |
494 } | |
495 break; | |
496 | |
3978
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
497 /* Some IM requires MappingNotify to be passed to |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
498 XRefreshKeyboardMapping by the app. */ |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
499 case MappingNotify: { |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
500 XRefreshKeyboardMapping(&xevent.xmapping); |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
501 } |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
502 break; |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
503 |
0 | 504 /* Generated upon EnterWindow and FocusIn */ |
505 case KeymapNotify: { | |
14
c3e9d4a623c1
Fixed stuck keys when changing the video mode
Sam Lantinga <slouken@lokigames.com>
parents:
12
diff
changeset
|
506 #ifdef DEBUG_XEVENTS |
c3e9d4a623c1
Fixed stuck keys when changing the video mode
Sam Lantinga <slouken@lokigames.com>
parents:
12
diff
changeset
|
507 printf("KeymapNotify!\n"); |
c3e9d4a623c1
Fixed stuck keys when changing the video mode
Sam Lantinga <slouken@lokigames.com>
parents:
12
diff
changeset
|
508 #endif |
1327 | 509 X11_SetKeyboardState(SDL_Display, xevent.xkeymap.key_vector); |
0 | 510 } |
511 break; | |
512 | |
513 /* Mouse motion? */ | |
514 case MotionNotify: { | |
515 if ( SDL_VideoSurface ) { | |
516 if ( mouse_relative ) { | |
517 if ( using_dga & DGA_MOUSE ) { | |
518 #ifdef DEBUG_MOTION | |
519 printf("DGA motion: %d,%d\n", xevent.xmotion.x_root, xevent.xmotion.y_root); | |
520 #endif | |
521 posted = SDL_PrivateMouseMotion(0, 1, | |
522 xevent.xmotion.x_root, | |
523 xevent.xmotion.y_root); | |
524 } else { | |
525 posted = X11_WarpedMotion(this,&xevent); | |
526 } | |
527 } else { | |
82
2bddc38a9f5d
When the mouse is grabbed, send the application the motion associated with
Sam Lantinga <slouken@lokigames.com>
parents:
75
diff
changeset
|
528 #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
|
529 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
|
530 #endif |
0 | 531 posted = SDL_PrivateMouseMotion(0, 0, |
532 xevent.xmotion.x, | |
533 xevent.xmotion.y); | |
534 } | |
535 } | |
536 } | |
537 break; | |
538 | |
539 /* Mouse button press? */ | |
540 case ButtonPress: { | |
541 posted = SDL_PrivateMouseButton(SDL_PRESSED, | |
542 xevent.xbutton.button, 0, 0); | |
543 } | |
544 break; | |
545 | |
546 /* Mouse button release? */ | |
547 case ButtonRelease: { | |
548 posted = SDL_PrivateMouseButton(SDL_RELEASED, | |
549 xevent.xbutton.button, 0, 0); | |
550 } | |
551 break; | |
552 | |
553 /* Key press? */ | |
554 case KeyPress: { | |
555 SDL_keysym keysym; | |
1327 | 556 KeyCode keycode = xevent.xkey.keycode; |
14
c3e9d4a623c1
Fixed stuck keys when changing the video mode
Sam Lantinga <slouken@lokigames.com>
parents:
12
diff
changeset
|
557 |
c3e9d4a623c1
Fixed stuck keys when changing the video mode
Sam Lantinga <slouken@lokigames.com>
parents:
12
diff
changeset
|
558 #ifdef DEBUG_XEVENTS |
c3e9d4a623c1
Fixed stuck keys when changing the video mode
Sam Lantinga <slouken@lokigames.com>
parents:
12
diff
changeset
|
559 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
|
560 #endif |
3978
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
561 /* If we're not doing translation, we're done! */ |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
562 if ( !SDL_TranslateUNICODE ) { |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
563 /* Get the translated SDL virtual keysym and put it on the queue.*/ |
1327 | 564 keysym.scancode = keycode; |
565 keysym.sym = X11_TranslateKeycode(SDL_Display, keycode); | |
566 keysym.mod = KMOD_NONE; | |
567 keysym.unicode = 0; | |
568 posted = SDL_PrivateKeyboard(SDL_PRESSED, &keysym); | |
569 break; | |
570 } | |
571 | |
572 /* Look up the translated value for the key event */ | |
573 #ifdef X_HAVE_UTF8_STRING | |
574 if ( SDL_IC != NULL ) { | |
3978
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
575 Status status; |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
576 KeySym xkeysym; |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
577 int i; |
1327 | 578 /* A UTF-8 character can be at most 6 bytes */ |
3978
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
579 /* ... It's true, but Xutf8LookupString can |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
580 return more than one characters. Moreover, |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
581 the spec. put no upper bound, so we should |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
582 be ready for longer strings. */ |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
583 char keybuf[32]; |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
584 char *keydata = keybuf; |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
585 int count; |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
586 Uint16 utf16buf[32]; |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
587 Uint16 *utf16data = utf16buf; |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
588 int utf16size; |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
589 int utf16length; |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
590 |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
591 count = Xutf8LookupString(SDL_IC, &xevent.xkey, keydata, sizeof(keybuf), &xkeysym, &status); |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
592 if (XBufferOverflow == status) { |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
593 /* The IM has just generated somewhat long |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
594 string. We need a longer buffer in this |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
595 case. */ |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
596 keydata = SDL_malloc(count); |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
597 if ( keydata == NULL ) { |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
598 SDL_OutOfMemory(); |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
599 break; |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
600 } |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
601 count = Xutf8LookupString(SDL_IC, &xevent.xkey, keydata, count, &xkeysym, &status); |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
602 } |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
603 |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
604 switch (status) { |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
605 |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
606 case XBufferOverflow: { |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
607 /* Oops! We have allocated the bytes as |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
608 requested by Xutf8LookupString, so the |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
609 length of the buffer must be |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
610 sufficient. This case should never |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
611 happen! */ |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
612 SDL_SetError("Xutf8LookupString indicated a double buffer overflow!"); |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
613 break; |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
614 } |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
615 |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
616 case XLookupChars: |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
617 case XLookupBoth: { |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
618 if (0 == count) { |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
619 break; |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
620 } |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
621 |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
622 /* We got a converted string from IM. Make |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
623 sure to deliver all characters to the |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
624 application as SDL events. Note that |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
625 an SDL event can only carry one UTF-16 |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
626 encoding unit, and a surrogate pair is |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
627 delivered as two SDL events. I guess |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
628 this behaviour is probably _imported_ |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
629 from Windows or MacOS. To do so, we need |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
630 to convert the UTF-8 data into UTF-16 |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
631 data (not UCS4/UTF-32!). We need an |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
632 estimate of the number of UTF-16 encoding |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
633 units here. The worst case is pure ASCII |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
634 string. Assume so. */ |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
635 /* In 1.3 SDL may have a text event instead, that |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
636 carries the whole UTF-8 string with it. */ |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
637 utf16size = count * sizeof(Uint16); |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
638 if (utf16size > sizeof(utf16buf)) { |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
639 utf16data = (Uint16 *) SDL_malloc(utf16size); |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
640 if (utf16data == NULL) { |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
641 SDL_OutOfMemory(); |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
642 break; |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
643 } |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
644 } |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
645 utf16length = Utf8ToUtf16((Uint8 *)keydata, count, utf16data, utf16size); |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
646 if (utf16length < 0) { |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
647 /* The keydata contained an invalid byte |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
648 sequence. It should be a bug of the IM |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
649 or Xlib... */ |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
650 SDL_SetError("Oops! Xutf8LookupString returned an invalid UTF-8 sequence!"); |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
651 break; |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
652 } |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
653 |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
654 /* Deliver all UTF-16 encoding units. At |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
655 this moment, SDL event queue has a |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
656 fixed size (128 events), and an SDL |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
657 event can hold just one UTF-16 encoding |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
658 unit. So, if we receive more than 128 |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
659 UTF-16 encoding units from a commit, |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
660 exceeded characters will be lost. */ |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
661 for (i = 0; i < utf16length - 1; i++) { |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
662 keysym.scancode = 0; |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
663 keysym.sym = SDLK_UNKNOWN; |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
664 keysym.mod = KMOD_NONE; |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
665 keysym.unicode = utf16data[i]; |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
666 posted = SDL_PrivateKeyboard(SDL_PRESSED, &keysym); |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
667 } |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
668 /* The keysym for the last character carries the |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
669 scancode and symbol that corresponds to the X11 |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
670 keycode. */ |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
671 if (utf16length > 0) { |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
672 keysym.scancode = keycode; |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
673 keysym.sym = (keycode ? X11_TranslateKeycode(SDL_Display, keycode) : 0); |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
674 keysym.mod = KMOD_NONE; |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
675 keysym.unicode = utf16data[utf16length - 1]; |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
676 posted = SDL_PrivateKeyboard(SDL_PRESSED, &keysym); |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
677 } |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
678 break; |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
679 } |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
680 |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
681 case XLookupKeySym: { |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
682 /* I'm not sure whether it is possible that |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
683 a zero keycode makes XLookupKeySym |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
684 status. What I'm sure is that a |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
685 combination of a zero scan code and a non |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
686 zero sym makes SDL_PrivateKeyboard |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
687 strange state... So, just discard it. |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
688 If this doesn't work, I'm receiving bug |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
689 reports, and I can know under what |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
690 condition this case happens. */ |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
691 if (keycode) { |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
692 keysym.scancode = keycode; |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
693 keysym.sym = X11_TranslateKeycode(SDL_Display, keycode); |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
694 keysym.mod = KMOD_NONE; |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
695 keysym.unicode = 0; |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
696 posted = SDL_PrivateKeyboard(SDL_PRESSED, &keysym); |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
697 } |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
698 break; |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
699 } |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
700 |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
701 case XLookupNone: { |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
702 /* IM has eaten the event. */ |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
703 break; |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
704 } |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
705 |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
706 default: |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
707 /* An unknown status from Xutf8LookupString. */ |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
708 SDL_SetError("Oops! Xutf8LookupStringreturned an unknown status"); |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
709 } |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
710 |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
711 /* Release dynamic buffers if allocated. */ |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
712 if (keydata != NULL && keybuf != keydata) { |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
713 SDL_free(keydata); |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
714 } |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
715 if (utf16data != NULL && utf16buf != utf16data) { |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
716 SDL_free(utf16data); |
1327 | 717 } |
718 } | |
719 else | |
720 #endif | |
721 { | |
722 static XComposeStatus state; | |
723 char keybuf[32]; | |
724 | |
1575
3ba88cb7eb1b
Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
725 if ( XLookupString(&xevent.xkey, |
1327 | 726 keybuf, sizeof(keybuf), |
727 NULL, &state) ) { | |
728 /* | |
729 * FIXME: XLookupString() may yield more than one | |
730 * character, so we need a mechanism to allow for | |
731 * this (perhaps null keypress events with a | |
732 * unicode value) | |
733 */ | |
734 keysym.unicode = (Uint8)keybuf[0]; | |
735 } | |
3978
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
736 |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
737 posted = SDL_PrivateKeyboard(SDL_PRESSED, &keysym); |
1327 | 738 } |
0 | 739 } |
740 break; | |
741 | |
742 /* Key release? */ | |
743 case KeyRelease: { | |
744 SDL_keysym keysym; | |
1327 | 745 KeyCode keycode = xevent.xkey.keycode; |
0 | 746 |
3978
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
747 if (keycode == 0) { |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
748 /* There should be no KeyRelease for keycode == 0, |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
749 since it is a notification from IM but a real |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
750 keystroke. */ |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
751 /* We need to emit some diagnostic message here. */ |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
752 break; |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
753 } |
b966761fef6c
Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents:
3936
diff
changeset
|
754 |
14
c3e9d4a623c1
Fixed stuck keys when changing the video mode
Sam Lantinga <slouken@lokigames.com>
parents:
12
diff
changeset
|
755 #ifdef DEBUG_XEVENTS |
c3e9d4a623c1
Fixed stuck keys when changing the video mode
Sam Lantinga <slouken@lokigames.com>
parents:
12
diff
changeset
|
756 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
|
757 #endif |
1327 | 758 |
759 /* Get the translated SDL virtual keysym */ | |
760 keysym.scancode = keycode; | |
761 keysym.sym = X11_TranslateKeycode(SDL_Display, keycode); | |
762 keysym.mod = KMOD_NONE; | |
763 keysym.unicode = 0; | |
764 | |
765 posted = SDL_PrivateKeyboard(SDL_RELEASED, &keysym); | |
0 | 766 } |
767 break; | |
768 | |
769 /* Have we been iconified? */ | |
770 case UnmapNotify: { | |
771 #ifdef DEBUG_XEVENTS | |
772 printf("UnmapNotify!\n"); | |
773 #endif | |
774 /* If we're active, make ourselves inactive */ | |
775 if ( SDL_GetAppState() & SDL_APPACTIVE ) { | |
776 /* Swap out the gamma before we go inactive */ | |
777 X11_SwapVidModeGamma(this); | |
778 | |
779 /* Send an internal deactivate event */ | |
780 posted = SDL_PrivateAppActive(0, | |
781 SDL_APPACTIVE|SDL_APPINPUTFOCUS); | |
782 } | |
783 } | |
784 break; | |
785 | |
786 /* Have we been restored? */ | |
787 case MapNotify: { | |
788 #ifdef DEBUG_XEVENTS | |
789 printf("MapNotify!\n"); | |
790 #endif | |
791 /* If we're not active, make ourselves active */ | |
792 if ( !(SDL_GetAppState() & SDL_APPACTIVE) ) { | |
793 /* Send an internal activate event */ | |
794 posted = SDL_PrivateAppActive(1, SDL_APPACTIVE); | |
795 | |
796 /* Now that we're active, swap the gamma back */ | |
797 X11_SwapVidModeGamma(this); | |
798 } | |
799 | |
800 if ( SDL_VideoSurface && | |
801 (SDL_VideoSurface->flags & SDL_FULLSCREEN) ) { | |
802 X11_EnterFullScreen(this); | |
803 } else { | |
804 X11_GrabInputNoLock(this, this->input_grab); | |
805 } | |
8
5574376c451d
Fixed relative motion checking after restore under X11
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
806 X11_CheckMouseModeNoLock(this); |
5574376c451d
Fixed relative motion checking after restore under X11
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
807 |
0 | 808 if ( SDL_VideoSurface ) { |
809 X11_RefreshDisplay(this); | |
810 } | |
811 } | |
812 break; | |
813 | |
814 /* Have we been resized or moved? */ | |
815 case ConfigureNotify: { | |
816 #ifdef DEBUG_XEVENTS | |
817 printf("ConfigureNotify! (resize: %dx%d)\n", xevent.xconfigure.width, xevent.xconfigure.height); | |
818 #endif | |
819 if ( SDL_VideoSurface ) { | |
820 if ((xevent.xconfigure.width != SDL_VideoSurface->w) || | |
821 (xevent.xconfigure.height != SDL_VideoSurface->h)) { | |
822 /* FIXME: Find a better fix for the bug with KDE 1.2 */ | |
823 if ( ! ((xevent.xconfigure.width == 32) && | |
824 (xevent.xconfigure.height == 32)) ) { | |
825 SDL_PrivateResize(xevent.xconfigure.width, | |
826 xevent.xconfigure.height); | |
827 } | |
828 } else { | |
829 /* OpenGL windows need to know about the change */ | |
830 if ( SDL_VideoSurface->flags & SDL_OPENGL ) { | |
831 SDL_PrivateExpose(); | |
832 } | |
833 } | |
834 } | |
835 } | |
836 break; | |
837 | |
838 /* Have we been requested to quit (or another client message?) */ | |
839 case ClientMessage: { | |
840 if ( (xevent.xclient.format == 32) && | |
841 (xevent.xclient.data.l[0] == WM_DELETE_WINDOW) ) | |
842 { | |
843 posted = SDL_PrivateQuit(); | |
844 } else | |
845 if ( SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE ) { | |
846 SDL_SysWMmsg wmmsg; | |
847 | |
848 SDL_VERSION(&wmmsg.version); | |
849 wmmsg.subsystem = SDL_SYSWM_X11; | |
850 wmmsg.event.xevent = xevent; | |
851 posted = SDL_PrivateSysWMEvent(&wmmsg); | |
852 } | |
853 } | |
854 break; | |
855 | |
856 /* Do we need to refresh ourselves? */ | |
857 case Expose: { | |
858 #ifdef DEBUG_XEVENTS | |
859 printf("Expose (count = %d)\n", xevent.xexpose.count); | |
860 #endif | |
861 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
|
862 X11_RefreshDisplay(this); |
0 | 863 } |
864 } | |
865 break; | |
866 | |
867 default: { | |
868 #ifdef DEBUG_XEVENTS | |
869 printf("Unhandled event %d\n", xevent.type); | |
870 #endif | |
871 /* Only post the event if we're watching for it */ | |
872 if ( SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE ) { | |
873 SDL_SysWMmsg wmmsg; | |
874 | |
875 SDL_VERSION(&wmmsg.version); | |
876 wmmsg.subsystem = SDL_SYSWM_X11; | |
877 wmmsg.event.xevent = xevent; | |
878 posted = SDL_PrivateSysWMEvent(&wmmsg); | |
879 } | |
880 } | |
881 break; | |
882 } | |
883 return(posted); | |
884 } | |
885 | |
886 /* Ack! XPending() actually performs a blocking read if no events available */ | |
887 int X11_Pending(Display *display) | |
888 { | |
889 /* Flush the display connection and look to see if events are queued */ | |
1575
3ba88cb7eb1b
Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
890 XFlush(display); |
3ba88cb7eb1b
Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
891 if ( XEventsQueued(display, QueuedAlready) ) { |
0 | 892 return(1); |
893 } | |
894 | |
895 /* More drastic measures are required -- see if X is ready to talk */ | |
896 { | |
897 static struct timeval zero_time; /* static == 0 */ | |
898 int x11_fd; | |
899 fd_set fdset; | |
900 | |
901 x11_fd = ConnectionNumber(display); | |
902 FD_ZERO(&fdset); | |
903 FD_SET(x11_fd, &fdset); | |
904 if ( select(x11_fd+1, &fdset, NULL, NULL, &zero_time) == 1 ) { | |
1575
3ba88cb7eb1b
Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
905 return(XPending(display)); |
0 | 906 } |
907 } | |
908 | |
909 /* Oh well, nothing is ready .. */ | |
910 return(0); | |
911 } | |
912 | |
913 void X11_PumpEvents(_THIS) | |
914 { | |
915 int pending; | |
916 | |
917 /* Keep processing pending events */ | |
918 pending = 0; | |
919 while ( X11_Pending(SDL_Display) ) { | |
920 X11_DispatchEvent(this); | |
921 ++pending; | |
922 } | |
923 if ( switch_waiting ) { | |
924 Uint32 now; | |
925 | |
926 now = SDL_GetTicks(); | |
927 if ( pending || !SDL_VideoSurface ) { | |
928 /* Try again later... */ | |
929 if ( switch_waiting & SDL_FULLSCREEN ) { | |
930 switch_time = now + 1500; | |
931 } else { | |
932 switch_time = now + 200; | |
933 } | |
1740 | 934 } else if ( (int)(switch_time-now) <= 0 ) { |
0 | 935 Uint32 go_fullscreen; |
936 | |
937 go_fullscreen = switch_waiting & SDL_FULLSCREEN; | |
938 switch_waiting = 0; | |
939 if ( SDL_VideoSurface->flags & SDL_FULLSCREEN ) { | |
940 if ( go_fullscreen ) { | |
941 X11_EnterFullScreen(this); | |
942 } else { | |
943 X11_LeaveFullScreen(this); | |
944 } | |
945 } | |
946 /* Handle focus in/out when grabbed */ | |
947 if ( go_fullscreen ) { | |
948 X11_GrabInputNoLock(this, this->input_grab); | |
949 } else { | |
950 X11_GrabInputNoLock(this, SDL_GRAB_OFF); | |
951 } | |
952 X11_CheckMouseModeNoLock(this); | |
953 } | |
954 } | |
955 } | |
956 | |
957 void X11_InitKeymap(void) | |
958 { | |
959 int i; | |
960 | |
961 /* Odd keys used in international keyboards */ | |
1379
c0a74f199ecf
Use only safe string functions
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
962 for ( i=0; i<SDL_arraysize(ODD_keymap); ++i ) |
0 | 963 ODD_keymap[i] = SDLK_UNKNOWN; |
964 | |
1327 | 965 /* Some of these might be mappable to an existing SDLK_ code */ |
966 ODD_keymap[XK_dead_grave&0xFF] = SDLK_COMPOSE; | |
967 ODD_keymap[XK_dead_acute&0xFF] = SDLK_COMPOSE; | |
968 ODD_keymap[XK_dead_tilde&0xFF] = SDLK_COMPOSE; | |
969 ODD_keymap[XK_dead_macron&0xFF] = SDLK_COMPOSE; | |
970 ODD_keymap[XK_dead_breve&0xFF] = SDLK_COMPOSE; | |
971 ODD_keymap[XK_dead_abovedot&0xFF] = SDLK_COMPOSE; | |
972 ODD_keymap[XK_dead_diaeresis&0xFF] = SDLK_COMPOSE; | |
973 ODD_keymap[XK_dead_abovering&0xFF] = SDLK_COMPOSE; | |
974 ODD_keymap[XK_dead_doubleacute&0xFF] = SDLK_COMPOSE; | |
975 ODD_keymap[XK_dead_caron&0xFF] = SDLK_COMPOSE; | |
976 ODD_keymap[XK_dead_cedilla&0xFF] = SDLK_COMPOSE; | |
977 ODD_keymap[XK_dead_ogonek&0xFF] = SDLK_COMPOSE; | |
978 ODD_keymap[XK_dead_iota&0xFF] = SDLK_COMPOSE; | |
979 ODD_keymap[XK_dead_voiced_sound&0xFF] = SDLK_COMPOSE; | |
980 ODD_keymap[XK_dead_semivoiced_sound&0xFF] = SDLK_COMPOSE; | |
981 ODD_keymap[XK_dead_belowdot&0xFF] = SDLK_COMPOSE; | |
1328
27ddb06a0bca
Date: Sat, 04 Feb 2006 19:47:23 +0900
Sam Lantinga <slouken@libsdl.org>
parents:
1327
diff
changeset
|
982 #ifdef XK_dead_hook |
1327 | 983 ODD_keymap[XK_dead_hook&0xFF] = SDLK_COMPOSE; |
1328
27ddb06a0bca
Date: Sat, 04 Feb 2006 19:47:23 +0900
Sam Lantinga <slouken@libsdl.org>
parents:
1327
diff
changeset
|
984 #endif |
27ddb06a0bca
Date: Sat, 04 Feb 2006 19:47:23 +0900
Sam Lantinga <slouken@libsdl.org>
parents:
1327
diff
changeset
|
985 #ifdef XK_dead_horn |
1327 | 986 ODD_keymap[XK_dead_horn&0xFF] = SDLK_COMPOSE; |
1328
27ddb06a0bca
Date: Sat, 04 Feb 2006 19:47:23 +0900
Sam Lantinga <slouken@libsdl.org>
parents:
1327
diff
changeset
|
987 #endif |
1327 | 988 |
0 | 989 #ifdef XK_dead_circumflex |
990 /* These X keysyms have 0xFE as the high byte */ | |
991 ODD_keymap[XK_dead_circumflex&0xFF] = SDLK_CARET; | |
992 #endif | |
805
df1a3218b468
Date: Wed, 04 Feb 2004 13:51:56 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
993 #ifdef XK_ISO_Level3_Shift |
df1a3218b468
Date: Wed, 04 Feb 2004 13:51:56 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
994 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
|
995 #endif |
0 | 996 |
997 /* Map the miscellaneous keys */ | |
1379
c0a74f199ecf
Use only safe string functions
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
998 for ( i=0; i<SDL_arraysize(MISC_keymap); ++i ) |
0 | 999 MISC_keymap[i] = SDLK_UNKNOWN; |
1000 | |
1001 /* These X keysyms have 0xFF as the high byte */ | |
1002 MISC_keymap[XK_BackSpace&0xFF] = SDLK_BACKSPACE; | |
1003 MISC_keymap[XK_Tab&0xFF] = SDLK_TAB; | |
1004 MISC_keymap[XK_Clear&0xFF] = SDLK_CLEAR; | |
1005 MISC_keymap[XK_Return&0xFF] = SDLK_RETURN; | |
1006 MISC_keymap[XK_Pause&0xFF] = SDLK_PAUSE; | |
1007 MISC_keymap[XK_Escape&0xFF] = SDLK_ESCAPE; | |
1008 MISC_keymap[XK_Delete&0xFF] = SDLK_DELETE; | |
1009 | |
1010 MISC_keymap[XK_KP_0&0xFF] = SDLK_KP0; /* Keypad 0-9 */ | |
1011 MISC_keymap[XK_KP_1&0xFF] = SDLK_KP1; | |
1012 MISC_keymap[XK_KP_2&0xFF] = SDLK_KP2; | |
1013 MISC_keymap[XK_KP_3&0xFF] = SDLK_KP3; | |
1014 MISC_keymap[XK_KP_4&0xFF] = SDLK_KP4; | |
1015 MISC_keymap[XK_KP_5&0xFF] = SDLK_KP5; | |
1016 MISC_keymap[XK_KP_6&0xFF] = SDLK_KP6; | |
1017 MISC_keymap[XK_KP_7&0xFF] = SDLK_KP7; | |
1018 MISC_keymap[XK_KP_8&0xFF] = SDLK_KP8; | |
1019 MISC_keymap[XK_KP_9&0xFF] = SDLK_KP9; | |
1020 MISC_keymap[XK_KP_Insert&0xFF] = SDLK_KP0; | |
1021 MISC_keymap[XK_KP_End&0xFF] = SDLK_KP1; | |
1022 MISC_keymap[XK_KP_Down&0xFF] = SDLK_KP2; | |
1023 MISC_keymap[XK_KP_Page_Down&0xFF] = SDLK_KP3; | |
1024 MISC_keymap[XK_KP_Left&0xFF] = SDLK_KP4; | |
1025 MISC_keymap[XK_KP_Begin&0xFF] = SDLK_KP5; | |
1026 MISC_keymap[XK_KP_Right&0xFF] = SDLK_KP6; | |
1027 MISC_keymap[XK_KP_Home&0xFF] = SDLK_KP7; | |
1028 MISC_keymap[XK_KP_Up&0xFF] = SDLK_KP8; | |
1029 MISC_keymap[XK_KP_Page_Up&0xFF] = SDLK_KP9; | |
1030 MISC_keymap[XK_KP_Delete&0xFF] = SDLK_KP_PERIOD; | |
1031 MISC_keymap[XK_KP_Decimal&0xFF] = SDLK_KP_PERIOD; | |
1032 MISC_keymap[XK_KP_Divide&0xFF] = SDLK_KP_DIVIDE; | |
1033 MISC_keymap[XK_KP_Multiply&0xFF] = SDLK_KP_MULTIPLY; | |
1034 MISC_keymap[XK_KP_Subtract&0xFF] = SDLK_KP_MINUS; | |
1035 MISC_keymap[XK_KP_Add&0xFF] = SDLK_KP_PLUS; | |
1036 MISC_keymap[XK_KP_Enter&0xFF] = SDLK_KP_ENTER; | |
1037 MISC_keymap[XK_KP_Equal&0xFF] = SDLK_KP_EQUALS; | |
1038 | |
1039 MISC_keymap[XK_Up&0xFF] = SDLK_UP; | |
1040 MISC_keymap[XK_Down&0xFF] = SDLK_DOWN; | |
1041 MISC_keymap[XK_Right&0xFF] = SDLK_RIGHT; | |
1042 MISC_keymap[XK_Left&0xFF] = SDLK_LEFT; | |
1043 MISC_keymap[XK_Insert&0xFF] = SDLK_INSERT; | |
1044 MISC_keymap[XK_Home&0xFF] = SDLK_HOME; | |
1045 MISC_keymap[XK_End&0xFF] = SDLK_END; | |
1046 MISC_keymap[XK_Page_Up&0xFF] = SDLK_PAGEUP; | |
1047 MISC_keymap[XK_Page_Down&0xFF] = SDLK_PAGEDOWN; | |
1048 | |
1049 MISC_keymap[XK_F1&0xFF] = SDLK_F1; | |
1050 MISC_keymap[XK_F2&0xFF] = SDLK_F2; | |
1051 MISC_keymap[XK_F3&0xFF] = SDLK_F3; | |
1052 MISC_keymap[XK_F4&0xFF] = SDLK_F4; | |
1053 MISC_keymap[XK_F5&0xFF] = SDLK_F5; | |
1054 MISC_keymap[XK_F6&0xFF] = SDLK_F6; | |
1055 MISC_keymap[XK_F7&0xFF] = SDLK_F7; | |
1056 MISC_keymap[XK_F8&0xFF] = SDLK_F8; | |
1057 MISC_keymap[XK_F9&0xFF] = SDLK_F9; | |
1058 MISC_keymap[XK_F10&0xFF] = SDLK_F10; | |
1059 MISC_keymap[XK_F11&0xFF] = SDLK_F11; | |
1060 MISC_keymap[XK_F12&0xFF] = SDLK_F12; | |
1061 MISC_keymap[XK_F13&0xFF] = SDLK_F13; | |
1062 MISC_keymap[XK_F14&0xFF] = SDLK_F14; | |
1063 MISC_keymap[XK_F15&0xFF] = SDLK_F15; | |
1064 | |
1065 MISC_keymap[XK_Num_Lock&0xFF] = SDLK_NUMLOCK; | |
1066 MISC_keymap[XK_Caps_Lock&0xFF] = SDLK_CAPSLOCK; | |
1067 MISC_keymap[XK_Scroll_Lock&0xFF] = SDLK_SCROLLOCK; | |
1068 MISC_keymap[XK_Shift_R&0xFF] = SDLK_RSHIFT; | |
1069 MISC_keymap[XK_Shift_L&0xFF] = SDLK_LSHIFT; | |
1070 MISC_keymap[XK_Control_R&0xFF] = SDLK_RCTRL; | |
1071 MISC_keymap[XK_Control_L&0xFF] = SDLK_LCTRL; | |
1072 MISC_keymap[XK_Alt_R&0xFF] = SDLK_RALT; | |
1073 MISC_keymap[XK_Alt_L&0xFF] = SDLK_LALT; | |
1074 MISC_keymap[XK_Meta_R&0xFF] = SDLK_RMETA; | |
1075 MISC_keymap[XK_Meta_L&0xFF] = SDLK_LMETA; | |
1076 MISC_keymap[XK_Super_L&0xFF] = SDLK_LSUPER; /* Left "Windows" */ | |
1077 MISC_keymap[XK_Super_R&0xFF] = SDLK_RSUPER; /* Right "Windows */ | |
1078 MISC_keymap[XK_Mode_switch&0xFF] = SDLK_MODE; /* "Alt Gr" key */ | |
1079 MISC_keymap[XK_Multi_key&0xFF] = SDLK_COMPOSE; /* Multi-key compose */ | |
1080 | |
1081 MISC_keymap[XK_Help&0xFF] = SDLK_HELP; | |
1082 MISC_keymap[XK_Print&0xFF] = SDLK_PRINT; | |
1083 MISC_keymap[XK_Sys_Req&0xFF] = SDLK_SYSREQ; | |
1084 MISC_keymap[XK_Break&0xFF] = SDLK_BREAK; | |
1085 MISC_keymap[XK_Menu&0xFF] = SDLK_MENU; | |
1086 MISC_keymap[XK_Hyper_R&0xFF] = SDLK_MENU; /* Windows "Menu" key */ | |
1087 } | |
1088 | |
1327 | 1089 /* Get the translated SDL virtual keysym */ |
1090 SDLKey X11_TranslateKeycode(Display *display, KeyCode kc) | |
0 | 1091 { |
1092 KeySym xsym; | |
1327 | 1093 SDLKey key; |
0 | 1094 |
1575
3ba88cb7eb1b
Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
1095 xsym = XKeycodeToKeysym(display, kc, 0); |
0 | 1096 #ifdef DEBUG_KEYS |
1327 | 1097 fprintf(stderr, "Translating key code %d -> 0x%.4x\n", kc, xsym); |
0 | 1098 #endif |
1327 | 1099 key = SDLK_UNKNOWN; |
0 | 1100 if ( xsym ) { |
1101 switch (xsym>>8) { | |
1327 | 1102 case 0x1005FF: |
0 | 1103 #ifdef SunXK_F36 |
1327 | 1104 if ( xsym == SunXK_F36 ) |
1105 key = SDLK_F11; | |
0 | 1106 #endif |
1107 #ifdef SunXK_F37 | |
1327 | 1108 if ( xsym == SunXK_F37 ) |
1109 key = SDLK_F12; | |
0 | 1110 #endif |
1327 | 1111 break; |
1112 case 0x00: /* Latin 1 */ | |
1113 key = (SDLKey)(xsym & 0xFF); | |
1114 break; | |
1115 case 0x01: /* Latin 2 */ | |
1116 case 0x02: /* Latin 3 */ | |
1117 case 0x03: /* Latin 4 */ | |
1118 case 0x04: /* Katakana */ | |
1119 case 0x05: /* Arabic */ | |
1120 case 0x06: /* Cyrillic */ | |
1121 case 0x07: /* Greek */ | |
1122 case 0x08: /* Technical */ | |
1123 case 0x0A: /* Publishing */ | |
1124 case 0x0C: /* Hebrew */ | |
1125 case 0x0D: /* Thai */ | |
1126 /* These are wrong, but it's better than nothing */ | |
1127 key = (SDLKey)(xsym & 0xFF); | |
1128 break; | |
1129 case 0xFE: | |
1130 key = ODD_keymap[xsym&0xFF]; | |
1131 break; | |
1132 case 0xFF: | |
1133 key = MISC_keymap[xsym&0xFF]; | |
1134 break; | |
1135 default: | |
1136 /* | |
1137 fprintf(stderr, "X11: Unhandled xsym, sym = 0x%04x\n", | |
0 | 1138 (unsigned int)xsym); |
1327 | 1139 */ |
1140 break; | |
0 | 1141 } |
1142 } else { | |
1143 /* X11 doesn't know how to translate the key! */ | |
1144 switch (kc) { | |
1327 | 1145 /* Caution: |
1146 These keycodes are from the Microsoft Keyboard | |
1147 */ | |
1148 case 115: | |
1149 key = SDLK_LSUPER; | |
1150 break; | |
1151 case 116: | |
1152 key = SDLK_RSUPER; | |
1153 break; | |
1154 case 117: | |
1155 key = SDLK_MENU; | |
1156 break; | |
1157 default: | |
1158 /* | |
1159 * no point in an error message; happens for | |
1160 * several keys when we get a keymap notify | |
0 | 1161 */ |
1327 | 1162 break; |
0 | 1163 } |
1164 } | |
1327 | 1165 return key; |
0 | 1166 } |
1167 | |
1168 /* X11 modifier masks for various keys */ | |
1169 static unsigned meta_l_mask, meta_r_mask, alt_l_mask, alt_r_mask; | |
1170 static unsigned num_mask, mode_switch_mask; | |
1171 | |
1172 static void get_modifier_masks(Display *display) | |
1173 { | |
1174 static unsigned got_masks; | |
1175 int i, j; | |
1176 XModifierKeymap *xmods; | |
1177 unsigned n; | |
1178 | |
1179 if(got_masks) | |
1180 return; | |
1181 | |
1575
3ba88cb7eb1b
Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
1182 xmods = XGetModifierMapping(display); |
0 | 1183 n = xmods->max_keypermod; |
1184 for(i = 3; i < 8; i++) { | |
1185 for(j = 0; j < n; j++) { | |
1186 KeyCode kc = xmods->modifiermap[i * n + j]; | |
1575
3ba88cb7eb1b
Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
1187 KeySym ks = XKeycodeToKeysym(display, kc, 0); |
0 | 1188 unsigned mask = 1 << i; |
1189 switch(ks) { | |
1190 case XK_Num_Lock: | |
1191 num_mask = mask; break; | |
1192 case XK_Alt_L: | |
1193 alt_l_mask = mask; break; | |
1194 case XK_Alt_R: | |
1195 alt_r_mask = mask; break; | |
1196 case XK_Meta_L: | |
1197 meta_l_mask = mask; break; | |
1198 case XK_Meta_R: | |
1199 meta_r_mask = mask; break; | |
1200 case XK_Mode_switch: | |
1201 mode_switch_mask = mask; break; | |
1202 } | |
1203 } | |
1204 } | |
1575
3ba88cb7eb1b
Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
1205 XFreeModifiermap(xmods); |
0 | 1206 got_masks = 1; |
1207 } | |
1208 | |
1209 | |
1210 /* | |
1211 * This function is semi-official; it is not officially exported and should | |
1212 * not be considered part of the SDL API, but may be used by client code | |
1213 * that *really* needs it (including legacy code). | |
1214 * It is slow, though, and should be avoided if possible. | |
1215 * | |
1216 * Note that it isn't completely accurate either; in particular, multi-key | |
1217 * sequences (dead accents, compose key sequences) will not work since the | |
1218 * state has been irrevocably lost. | |
1219 */ | |
1220 Uint16 X11_KeyToUnicode(SDLKey keysym, SDLMod modifiers) | |
1221 { | |
1222 struct SDL_VideoDevice *this = current_video; | |
1223 char keybuf[32]; | |
1224 int i; | |
1225 KeySym xsym = 0; | |
1226 XKeyEvent xkey; | |
1227 Uint16 unicode; | |
1228 | |
1229 if ( !this || !SDL_Display ) { | |
1230 return 0; | |
1231 } | |
1232 | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1328
diff
changeset
|
1233 SDL_memset(&xkey, 0, sizeof(xkey)); |
0 | 1234 xkey.display = SDL_Display; |
1235 | |
1236 xsym = keysym; /* last resort if not found */ | |
1237 for (i = 0; i < 256; ++i) { | |
1238 if ( MISC_keymap[i] == keysym ) { | |
1239 xsym = 0xFF00 | i; | |
1240 break; | |
1241 } else if ( ODD_keymap[i] == keysym ) { | |
1242 xsym = 0xFE00 | i; | |
1243 break; | |
1244 } | |
1245 } | |
1246 | |
1575
3ba88cb7eb1b
Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
1247 xkey.keycode = XKeysymToKeycode(xkey.display, xsym); |
0 | 1248 |
1249 get_modifier_masks(SDL_Display); | |
1250 if(modifiers & KMOD_SHIFT) | |
1251 xkey.state |= ShiftMask; | |
1252 if(modifiers & KMOD_CAPS) | |
1253 xkey.state |= LockMask; | |
1254 if(modifiers & KMOD_CTRL) | |
1255 xkey.state |= ControlMask; | |
1256 if(modifiers & KMOD_MODE) | |
1257 xkey.state |= mode_switch_mask; | |
1258 if(modifiers & KMOD_LALT) | |
1259 xkey.state |= alt_l_mask; | |
1260 if(modifiers & KMOD_RALT) | |
1261 xkey.state |= alt_r_mask; | |
1262 if(modifiers & KMOD_LMETA) | |
1263 xkey.state |= meta_l_mask; | |
1264 if(modifiers & KMOD_RMETA) | |
1265 xkey.state |= meta_r_mask; | |
1266 if(modifiers & KMOD_NUM) | |
1267 xkey.state |= num_mask; | |
1268 | |
1269 unicode = 0; | |
1575
3ba88cb7eb1b
Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
1270 if ( XLookupString(&xkey, keybuf, sizeof(keybuf), NULL, NULL) ) |
0 | 1271 unicode = (unsigned char)keybuf[0]; |
1272 return(unicode); | |
1273 } | |
1274 | |
1178
9867f3d86e44
Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents:
1168
diff
changeset
|
1275 |
0 | 1276 /* |
1277 * Called when focus is regained, to read the keyboard state and generate | |
1278 * synthetic keypress/release events. | |
1279 * key_vec is a bit vector of keycodes (256 bits) | |
1280 */ | |
1327 | 1281 void X11_SetKeyboardState(Display *display, const char *key_vec) |
0 | 1282 { |
1283 char keys_return[32]; | |
412
ac59b067815b
Fix uninitialized variable warning
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
1284 int i; |
0 | 1285 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
|
1286 SDLMod modstate; |
53e3d8ba4321
Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents:
88
diff
changeset
|
1287 Window junk_window; |
53e3d8ba4321
Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents:
88
diff
changeset
|
1288 int x, y; |
53e3d8ba4321
Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents:
88
diff
changeset
|
1289 unsigned int mask; |
0 | 1290 |
1291 /* The first time the window is mapped, we initialize key state */ | |
1292 if ( ! key_vec ) { | |
1575
3ba88cb7eb1b
Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
1293 XQueryKeymap(display, keys_return); |
0 | 1294 key_vec = keys_return; |
1295 } | |
1296 | |
111
53e3d8ba4321
Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents:
88
diff
changeset
|
1297 /* 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
|
1298 modstate = 0; |
53e3d8ba4321
Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents:
88
diff
changeset
|
1299 get_modifier_masks(display); |
1575
3ba88cb7eb1b
Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
1300 if ( XQueryPointer(display, DefaultRootWindow(display), |
111
53e3d8ba4321
Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents:
88
diff
changeset
|
1301 &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
|
1302 if ( mask & LockMask ) { |
53e3d8ba4321
Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents:
88
diff
changeset
|
1303 modstate |= KMOD_CAPS; |
53e3d8ba4321
Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents:
88
diff
changeset
|
1304 } |
53e3d8ba4321
Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents:
88
diff
changeset
|
1305 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
|
1306 modstate |= KMOD_MODE; |
53e3d8ba4321
Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents:
88
diff
changeset
|
1307 } |
53e3d8ba4321
Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents:
88
diff
changeset
|
1308 if ( mask & num_mask ) { |
53e3d8ba4321
Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents:
88
diff
changeset
|
1309 modstate |= KMOD_NUM; |
53e3d8ba4321
Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents:
88
diff
changeset
|
1310 } |
53e3d8ba4321
Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents:
88
diff
changeset
|
1311 } |
53e3d8ba4321
Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents:
88
diff
changeset
|
1312 |
53e3d8ba4321
Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents:
88
diff
changeset
|
1313 /* Zero the new keyboard state and generate it */ |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1328
diff
changeset
|
1314 SDL_memset(kstate, 0, SDLK_LAST); |
0 | 1315 /* |
1316 * An obvious optimisation is to check entire longwords at a time in | |
1317 * both loops, but we can't be sure the arrays are aligned so it's not | |
1318 * worth the extra complexity | |
1319 */ | |
1327 | 1320 for ( i = 0; i < 32; i++ ) { |
0 | 1321 int j; |
1327 | 1322 if ( !key_vec[i] ) |
0 | 1323 continue; |
1327 | 1324 for ( j = 0; j < 8; j++ ) { |
1325 if ( key_vec[i] & (1 << j) ) { | |
1326 SDLKey key; | |
1327 KeyCode kc = (i << 3 | j); | |
1328 key = X11_TranslateKeycode(display, kc); | |
1329 if ( key == SDLK_UNKNOWN ) { | |
1330 continue; | |
1331 } | |
1332 kstate[key] = SDL_PRESSED; | |
1333 switch (key) { | |
1334 case SDLK_LSHIFT: | |
111
53e3d8ba4321
Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents:
88
diff
changeset
|
1335 modstate |= KMOD_LSHIFT; |
53e3d8ba4321
Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents:
88
diff
changeset
|
1336 break; |
1327 | 1337 case SDLK_RSHIFT: |
111
53e3d8ba4321
Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents:
88
diff
changeset
|
1338 modstate |= KMOD_RSHIFT; |
53e3d8ba4321
Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents:
88
diff
changeset
|
1339 break; |
1327 | 1340 case SDLK_LCTRL: |
111
53e3d8ba4321
Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents:
88
diff
changeset
|
1341 modstate |= KMOD_LCTRL; |
53e3d8ba4321
Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents:
88
diff
changeset
|
1342 break; |
1327 | 1343 case SDLK_RCTRL: |
111
53e3d8ba4321
Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents:
88
diff
changeset
|
1344 modstate |= KMOD_RCTRL; |
53e3d8ba4321
Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents:
88
diff
changeset
|
1345 break; |
1327 | 1346 case SDLK_LALT: |
111
53e3d8ba4321
Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents:
88
diff
changeset
|
1347 modstate |= KMOD_LALT; |
53e3d8ba4321
Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents:
88
diff
changeset
|
1348 break; |
1327 | 1349 case SDLK_RALT: |
111
53e3d8ba4321
Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents:
88
diff
changeset
|
1350 modstate |= KMOD_RALT; |
53e3d8ba4321
Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents:
88
diff
changeset
|
1351 break; |
1327 | 1352 case SDLK_LMETA: |
111
53e3d8ba4321
Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents:
88
diff
changeset
|
1353 modstate |= KMOD_LMETA; |
53e3d8ba4321
Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents:
88
diff
changeset
|
1354 break; |
1327 | 1355 case SDLK_RMETA: |
111
53e3d8ba4321
Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents:
88
diff
changeset
|
1356 modstate |= KMOD_RMETA; |
53e3d8ba4321
Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents:
88
diff
changeset
|
1357 break; |
1327 | 1358 default: |
111
53e3d8ba4321
Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents:
88
diff
changeset
|
1359 break; |
1327 | 1360 } |
111
53e3d8ba4321
Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents:
88
diff
changeset
|
1361 } |
53e3d8ba4321
Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents:
88
diff
changeset
|
1362 } |
0 | 1363 } |
111
53e3d8ba4321
Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents:
88
diff
changeset
|
1364 |
53e3d8ba4321
Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents:
88
diff
changeset
|
1365 /* 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
|
1366 if ( modstate & KMOD_CAPS ) { |
53e3d8ba4321
Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents:
88
diff
changeset
|
1367 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
|
1368 } else { |
53e3d8ba4321
Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents:
88
diff
changeset
|
1369 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
|
1370 } |
53e3d8ba4321
Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents:
88
diff
changeset
|
1371 if ( modstate & KMOD_NUM ) { |
53e3d8ba4321
Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents:
88
diff
changeset
|
1372 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
|
1373 } else { |
53e3d8ba4321
Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents:
88
diff
changeset
|
1374 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
|
1375 } |
53e3d8ba4321
Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents:
88
diff
changeset
|
1376 |
53e3d8ba4321
Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents:
88
diff
changeset
|
1377 /* 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
|
1378 SDL_SetModState(modstate); |
0 | 1379 } |
1380 | |
1381 void X11_InitOSKeymap(_THIS) | |
1382 { | |
1383 X11_InitKeymap(); | |
1384 } | |
1385 | |
1784
45669d4efd02
Disable the screensaver in DGA mode, which is even more important than X11...
Sam Lantinga <slouken@libsdl.org>
parents:
1783
diff
changeset
|
1386 void X11_SaveScreenSaver(Display *display, int *saved_timeout, BOOL *dpms) |
1783 | 1387 { |
1388 int timeout, interval, prefer_blank, allow_exp; | |
1784
45669d4efd02
Disable the screensaver in DGA mode, which is even more important than X11...
Sam Lantinga <slouken@libsdl.org>
parents:
1783
diff
changeset
|
1389 XGetScreenSaver(display, &timeout, &interval, &prefer_blank, &allow_exp); |
45669d4efd02
Disable the screensaver in DGA mode, which is even more important than X11...
Sam Lantinga <slouken@libsdl.org>
parents:
1783
diff
changeset
|
1390 *saved_timeout = timeout; |
1783 | 1391 |
1392 #if SDL_VIDEO_DRIVER_X11_DPMS | |
1393 if ( SDL_X11_HAVE_DPMS ) { | |
1394 int dummy; | |
1784
45669d4efd02
Disable the screensaver in DGA mode, which is even more important than X11...
Sam Lantinga <slouken@libsdl.org>
parents:
1783
diff
changeset
|
1395 if ( DPMSQueryExtension(display, &dummy, &dummy) ) { |
1783 | 1396 CARD16 state; |
1784
45669d4efd02
Disable the screensaver in DGA mode, which is even more important than X11...
Sam Lantinga <slouken@libsdl.org>
parents:
1783
diff
changeset
|
1397 DPMSInfo(display, &state, dpms); |
1783 | 1398 } |
1399 } | |
1792
409974dedf2e
More compile fixes for systems without the DPMS extension
Sam Lantinga <slouken@libsdl.org>
parents:
1789
diff
changeset
|
1400 #else |
409974dedf2e
More compile fixes for systems without the DPMS extension
Sam Lantinga <slouken@libsdl.org>
parents:
1789
diff
changeset
|
1401 *dpms = 0; |
1783 | 1402 #endif /* SDL_VIDEO_DRIVER_X11_DPMS */ |
1403 } | |
1404 | |
3936
c5c3c772f5aa
Let app set SDL_VIDEO_ALLOW_SCREENSAVER environment variable to override SDL's
Ryan C. Gordon <icculus@icculus.org>
parents:
1792
diff
changeset
|
1405 void X11_DisableScreenSaver(_THIS, Display *display) |
1783 | 1406 { |
1407 int timeout, interval, prefer_blank, allow_exp; | |
3936
c5c3c772f5aa
Let app set SDL_VIDEO_ALLOW_SCREENSAVER environment variable to override SDL's
Ryan C. Gordon <icculus@icculus.org>
parents:
1792
diff
changeset
|
1408 |
c5c3c772f5aa
Let app set SDL_VIDEO_ALLOW_SCREENSAVER environment variable to override SDL's
Ryan C. Gordon <icculus@icculus.org>
parents:
1792
diff
changeset
|
1409 if (this->hidden->allow_screensaver) { |
c5c3c772f5aa
Let app set SDL_VIDEO_ALLOW_SCREENSAVER environment variable to override SDL's
Ryan C. Gordon <icculus@icculus.org>
parents:
1792
diff
changeset
|
1410 return; |
c5c3c772f5aa
Let app set SDL_VIDEO_ALLOW_SCREENSAVER environment variable to override SDL's
Ryan C. Gordon <icculus@icculus.org>
parents:
1792
diff
changeset
|
1411 } |
c5c3c772f5aa
Let app set SDL_VIDEO_ALLOW_SCREENSAVER environment variable to override SDL's
Ryan C. Gordon <icculus@icculus.org>
parents:
1792
diff
changeset
|
1412 |
1784
45669d4efd02
Disable the screensaver in DGA mode, which is even more important than X11...
Sam Lantinga <slouken@libsdl.org>
parents:
1783
diff
changeset
|
1413 XGetScreenSaver(display, &timeout, &interval, &prefer_blank, &allow_exp); |
1783 | 1414 timeout = 0; |
1784
45669d4efd02
Disable the screensaver in DGA mode, which is even more important than X11...
Sam Lantinga <slouken@libsdl.org>
parents:
1783
diff
changeset
|
1415 XSetScreenSaver(display, timeout, interval, prefer_blank, allow_exp); |
1783 | 1416 |
1417 #if SDL_VIDEO_DRIVER_X11_DPMS | |
1418 if ( SDL_X11_HAVE_DPMS ) { | |
1419 int dummy; | |
1784
45669d4efd02
Disable the screensaver in DGA mode, which is even more important than X11...
Sam Lantinga <slouken@libsdl.org>
parents:
1783
diff
changeset
|
1420 if ( DPMSQueryExtension(display, &dummy, &dummy) ) { |
45669d4efd02
Disable the screensaver in DGA mode, which is even more important than X11...
Sam Lantinga <slouken@libsdl.org>
parents:
1783
diff
changeset
|
1421 DPMSDisable(display); |
1783 | 1422 } |
1423 } | |
1424 #endif /* SDL_VIDEO_DRIVER_X11_DPMS */ | |
1425 } | |
1426 | |
3936
c5c3c772f5aa
Let app set SDL_VIDEO_ALLOW_SCREENSAVER environment variable to override SDL's
Ryan C. Gordon <icculus@icculus.org>
parents:
1792
diff
changeset
|
1427 void X11_RestoreScreenSaver(_THIS, Display *display, int saved_timeout, BOOL dpms) |
1783 | 1428 { |
1429 int timeout, interval, prefer_blank, allow_exp; | |
3936
c5c3c772f5aa
Let app set SDL_VIDEO_ALLOW_SCREENSAVER environment variable to override SDL's
Ryan C. Gordon <icculus@icculus.org>
parents:
1792
diff
changeset
|
1430 |
c5c3c772f5aa
Let app set SDL_VIDEO_ALLOW_SCREENSAVER environment variable to override SDL's
Ryan C. Gordon <icculus@icculus.org>
parents:
1792
diff
changeset
|
1431 if (this->hidden->allow_screensaver) { |
c5c3c772f5aa
Let app set SDL_VIDEO_ALLOW_SCREENSAVER environment variable to override SDL's
Ryan C. Gordon <icculus@icculus.org>
parents:
1792
diff
changeset
|
1432 return; |
c5c3c772f5aa
Let app set SDL_VIDEO_ALLOW_SCREENSAVER environment variable to override SDL's
Ryan C. Gordon <icculus@icculus.org>
parents:
1792
diff
changeset
|
1433 } |
c5c3c772f5aa
Let app set SDL_VIDEO_ALLOW_SCREENSAVER environment variable to override SDL's
Ryan C. Gordon <icculus@icculus.org>
parents:
1792
diff
changeset
|
1434 |
1784
45669d4efd02
Disable the screensaver in DGA mode, which is even more important than X11...
Sam Lantinga <slouken@libsdl.org>
parents:
1783
diff
changeset
|
1435 XGetScreenSaver(display, &timeout, &interval, &prefer_blank, &allow_exp); |
45669d4efd02
Disable the screensaver in DGA mode, which is even more important than X11...
Sam Lantinga <slouken@libsdl.org>
parents:
1783
diff
changeset
|
1436 timeout = saved_timeout; |
45669d4efd02
Disable the screensaver in DGA mode, which is even more important than X11...
Sam Lantinga <slouken@libsdl.org>
parents:
1783
diff
changeset
|
1437 XSetScreenSaver(display, timeout, interval, prefer_blank, allow_exp); |
1783 | 1438 |
1439 #if SDL_VIDEO_DRIVER_X11_DPMS | |
1440 if ( SDL_X11_HAVE_DPMS ) { | |
1441 int dummy; | |
1784
45669d4efd02
Disable the screensaver in DGA mode, which is even more important than X11...
Sam Lantinga <slouken@libsdl.org>
parents:
1783
diff
changeset
|
1442 if ( DPMSQueryExtension(display, &dummy, &dummy) ) { |
45669d4efd02
Disable the screensaver in DGA mode, which is even more important than X11...
Sam Lantinga <slouken@libsdl.org>
parents:
1783
diff
changeset
|
1443 if ( dpms ) { |
45669d4efd02
Disable the screensaver in DGA mode, which is even more important than X11...
Sam Lantinga <slouken@libsdl.org>
parents:
1783
diff
changeset
|
1444 DPMSEnable(display); |
1783 | 1445 } |
1446 } | |
1447 } | |
1448 #endif /* SDL_VIDEO_DRIVER_X11_DPMS */ | |
1449 } |