annotate src/video/x11/SDL_x11events.c @ 4139:568c9b3c0167 SDL-1.2

* Added configure option --enable-screensaver, to allow enabling the screensaver by default. * Use XResetScreenSaver() instead of disabling screensaver entirely. Full discussion summary from Erik on the SDL mailing list: Current behaviour ================= SDL changes the user's display power management settings without permission from the user and without telling the user. The interface that it uses to do so is DPMSDisable/DPMSEnable, which should only ever be used by configuration utilities like KControl, never by normal application programs, let alone by the libraries that they use. Using an interface that is not at all intended for what SDL tries to achieve means that it will not work as it should. Firstly, the power management is completely disabled during the whole lifetime of the SDL program, not only when it should be. Secondly, it makes SDL non-reentrant, meaning that things will break when multiple SDL programs are clients of the same X server simultaneously. Thirdly, no cleanup mechanism ensures that the setting is restored if the client does not do that (for example if it crashes). In addition to that, this interface is broken on xorg, [http://bugs.freedesktop.org/show_bug.cgi?id=13962], so what SDL tries to do does not work at all on that implementation of the X Window System. (The reason that the DPMSEnable works in KControl is that it calls DPMSSetTimeout immediately after, [http://websvn.kde.org/tags/KDE/3.5.9/kdebase/kcontrol/energy/energy.cpp?annotate=774532#l343]). The problems that the current behaviour causes ============================================== 1. Information leak. When the user is away, someone might see what the user has on the display when the user counts on the screensaver preventing this. This does not even require physical access to the workstation, it is enough to see it from a distance. 2. Draining battery. An SDL program that runs on a laptop will quickly drain the battery while the user is away. The system will soon shut down and require recharging before being usable again, while it should in fact have consumed very little energy if the user's settings would have been obeyed. 3. Wasting energy. Even if battery issues are not considered, energy as such is wasted. 4. Display wear. The display may be worn out. The problems that the current behaviour tries to solve ====================================================== 1. Preventing screensaver while playing movies. Many SDL applications are media players. They have reasons to prevent screensavers from being activated while a movie is being played. When a user clicks on the play button it can be interpreted as saying "play this movie, but do not turn off the display while playing it, because I will watch it even though I do not interact with the system". 2. Preventing screensaver when some input bypasses X. Sometimes SDL uses input from another source than the X server, so that the X server is bypassed. This obviously breaks the screensaver handling. SDL tries to work around that. 3. Preventing screensaver when all input bypasses X. There is something called Direct Graphics Access mode, where a program takes control of both the display and the input devices from the X server. This obviously means that the X server can not handle the screensaver alone, since screensaver handling depends on input handling. SDL does not do what it should to help the X server to handle the screensaver. Nor does SDL take care of screeensaver handling itself. SDL simply disables the screensaver completely. How the problems should be solved ================================= The correct way for an application program to prevent the screensaver under X is to call XResetScreenSaver. This was recently discovered and implemented by the mplayer developers, [http://svn.mplayerhq.hu/mplayer?view=rev&revision=25637]. SDL needs to wrap this in an API call (SDL_ResetScreenSaver) and implement it for the other video targets (if they do not have a corresponding call, SDL should do what it takes on that particular target, for example sending fake key events). 1. When a movie is played, the player should reset the screensaver when the animation is advanced to a new frame. The same applies to anything similar, like slideshows. 2. When the X server is handling input, it must handle all input (keyboards, mice, gamepads, ...). This is necessary, not only to be able to handle the screensaver, but also so that it can send the events to the correct (the currently active) client. If there is an input device that the X server can not handle for some reason (such as lack of Plug and Play capability), the program that handles the device as a workaround must simulate what would happen if the X server would have handled the device, by calling XResetScreenSaver when input is received from the device. 3. When the X server is not handling the input, it depends on the program that does to call XResetScreenSaver whenever an input event occurs. Alternatively the program must handle the screensaver countdown internally and call XActivateScreenSaver.
author Sam Lantinga <slouken@libsdl.org>
date Fri, 29 Feb 2008 13:55:44 +0000
parents dbb5f9556796
children a1b03ba2fcd0
rev   line source
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1 /*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1196
diff changeset
3 Copyright (C) 1997-2006 Sam Lantinga
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
4
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1196
diff changeset
6 modify it under the terms of the GNU Lesser General Public
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1196
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
9
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1196
diff changeset
13 Lesser General Public License for more details.
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
14
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1196
diff changeset
15 You should have received a copy of the GNU Lesser General Public
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1196
diff changeset
16 License along with this library; if not, write to the Free Software
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1196
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
18
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
19 Sam Lantinga
252
e8157fcb3114 Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents: 161
diff changeset
20 slouken@libsdl.org
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
21 */
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
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
23
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
24 /* Handle the event stream, converting X11 events into SDL events */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
25
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
26 #include <setjmp.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
27 #include <X11/Xlib.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
28 #include <X11/Xutil.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
29 #include <X11/keysym.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
30 #ifdef __SVR4
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
31 #include <X11/Sunkeysym.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
32 #endif
75
b0ae59d0f3ee Added patches from FreeBSD ports
Sam Lantinga <slouken@lokigames.com>
parents: 14
diff changeset
33 #include <sys/types.h>
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
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
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
36
1359
1e4ba2e063b4 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
37 #include "SDL_timer.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
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
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
42 #include "SDL_x11video.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
43 #include "SDL_x11dga_c.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
44 #include "SDL_x11modes_c.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
45 #include "SDL_x11image_c.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
46 #include "SDL_x11gamma_c.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
47 #include "SDL_x11wm_c.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
48 #include "SDL_x11mouse_c.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
49 #include "SDL_x11events_c.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
50
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
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
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
55 /* The translation tables from an X11 keysym to a SDL keysym */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
56 static SDLKey ODD_keymap[256];
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
57 static SDLKey MISC_keymap[256];
1327
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
58 SDLKey X11_TranslateKeycode(Display *display, KeyCode kc);
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
59
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
60
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
61 #ifdef X_HAVE_UTF8_STRING
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
62 Uint32 Utf8ToUcs4(const Uint8 *utf8)
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
63 {
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
64 Uint32 c;
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
65 int i = 1;
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
66 int noOctets = 0;
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
67 int firstOctetMask = 0;
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
68 unsigned char firstOctet = utf8[0];
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
69 if (firstOctet < 0x80) {
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
70 /*
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
71 Characters in the range:
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
72 00000000 to 01111111 (ASCII Range)
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
73 are stored in one octet:
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
74 0xxxxxxx (The same as its ASCII representation)
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
75 The least 6 significant bits of the first octet is the most 6 significant nonzero bits
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
76 of the UCS4 representation.
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
77 */
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
78 noOctets = 1;
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
79 firstOctetMask = 0x7F; /* 0(1111111) - The most significant bit is ignored */
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
80 } else if ((firstOctet & 0xE0) /* get the most 3 significant bits by AND'ing with 11100000 */
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
81 == 0xC0 ) { /* see if those 3 bits are 110. If so, the char is in this range */
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
82 /*
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
83 Characters in the range:
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
84 00000000 10000000 to 00000111 11111111
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
85 are stored in two octets:
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
86 110xxxxx 10xxxxxx
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
87 The least 5 significant bits of the first octet is the most 5 significant nonzero bits
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
88 of the UCS4 representation.
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
89 */
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
90 noOctets = 2;
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
91 firstOctetMask = 0x1F; /* 000(11111) - The most 3 significant bits are ignored */
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
92 } else if ((firstOctet & 0xF0) /* get the most 4 significant bits by AND'ing with 11110000 */
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
93 == 0xE0) { /* see if those 4 bits are 1110. If so, the char is in this range */
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
94 /*
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
95 Characters in the range:
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
96 00001000 00000000 to 11111111 11111111
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
97 are stored in three octets:
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
98 1110xxxx 10xxxxxx 10xxxxxx
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
99 The least 4 significant bits of the first octet is the most 4 significant nonzero bits
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
100 of the UCS4 representation.
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
101 */
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
102 noOctets = 3;
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
103 firstOctetMask = 0x0F; /* 0000(1111) - The most 4 significant bits are ignored */
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
104 } else if ((firstOctet & 0xF8) /* get the most 5 significant bits by AND'ing with 11111000 */
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
105 == 0xF0) { /* see if those 5 bits are 11110. If so, the char is in this range */
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
106 /*
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
107 Characters in the range:
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
108 00000001 00000000 00000000 to 00011111 11111111 11111111
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
109 are stored in four octets:
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
110 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
111 The least 3 significant bits of the first octet is the most 3 significant nonzero bits
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
112 of the UCS4 representation.
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
113 */
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
114 noOctets = 4;
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
115 firstOctetMask = 0x07; /* 11110(111) - The most 5 significant bits are ignored */
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
116 } else if ((firstOctet & 0xFC) /* get the most 6 significant bits by AND'ing with 11111100 */
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
117 == 0xF8) { /* see if those 6 bits are 111110. If so, the char is in this range */
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
118 /*
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
119 Characters in the range:
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
120 00000000 00100000 00000000 00000000 to
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
121 00000011 11111111 11111111 11111111
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
122 are stored in five octets:
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
123 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
124 The least 2 significant bits of the first octet is the most 2 significant nonzero bits
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
125 of the UCS4 representation.
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
126 */
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
127 noOctets = 5;
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
128 firstOctetMask = 0x03; /* 111110(11) - The most 6 significant bits are ignored */
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
129 } else if ((firstOctet & 0xFE) /* get the most 7 significant bits by AND'ing with 11111110 */
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
130 == 0xFC) { /* see if those 7 bits are 1111110. If so, the char is in this range */
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
131 /*
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
132 Characters in the range:
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
133 00000100 00000000 00000000 00000000 to
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
134 01111111 11111111 11111111 11111111
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
135 are stored in six octets:
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
136 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
137 The least significant bit of the first octet is the most significant nonzero bit
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
138 of the UCS4 representation.
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
139 */
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
140 noOctets = 6;
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
141 firstOctetMask = 0x01; /* 1111110(1) - The most 7 significant bits are ignored */
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
142 } else
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
143 return 0; /* The given chunk is not a valid UTF-8 encoded Unicode character */
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
144
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
145 /*
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
146 The least noOctets significant bits of the first octet is the most 2 significant nonzero bits
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
147 of the UCS4 representation.
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
148 The first 6 bits of the UCS4 representation is the least 8-noOctets-1 significant bits of
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
149 firstOctet if the character is not ASCII. If so, it's the least 7 significant bits of firstOctet.
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
150 This done by AND'ing firstOctet with its mask to trim the bits used for identifying the
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
151 number of continuing octets (if any) and leave only the free bits (the x's)
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
152 Sample:
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
153 1-octet: 0xxxxxxx & 01111111 = 0xxxxxxx
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
154 2-octets: 110xxxxx & 00011111 = 000xxxxx
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
155 */
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
156 c = firstOctet & firstOctetMask;
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
157
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
158 /* Now, start filling c.ucs4 with the bits from the continuing octets from utf8. */
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
159 for (i = 1; i < noOctets; i++) {
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
160 /* A valid continuing octet is of the form 10xxxxxx */
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
161 if ((utf8[i] & 0xC0) /* get the most 2 significant bits by AND'ing with 11000000 */
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
162 != 0x80) /* see if those 2 bits are 10. If not, the is a malformed sequence. */
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
163 /*The given chunk is a partial sequence at the end of a string that could
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
164 begin a valid character */
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
165 return 0;
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
166
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
167 /* Make room for the next 6-bits */
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
168 c <<= 6;
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
169
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
170 /*
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
171 Take only the least 6 significance bits of the current octet (utf8[i]) and fill the created room
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
172 of c.ucs4 with them.
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
173 This done by AND'ing utf8[i] with 00111111 and the OR'ing the result with c.ucs4.
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
174 */
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
175 c |= utf8[i] & 0x3F;
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
176 }
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
177 return c;
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
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) {
4094
ca992789c798 ANSI C fix (all variables need to be defined at start of block).
Ryan C. Gordon <icculus@icculus.org>
parents: 3999
diff changeset
238 Uint8 const c = *utf8;
3978
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
239 if (p >= max_ptr) {
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
240 /* No more output space. */
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
241 return -1;
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
242 }
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
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
297 #endif
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
298
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
299 /* Check to see if this is a repeated key.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
300 (idea shamelessly lifted from GII -- thanks guys! :)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
301 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
302 static int X11_KeyRepeat(Display *display, XEvent *event)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
303 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
304 XEvent peekevent;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
305 int repeated;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
306
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
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
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
310 if ( (peekevent.type == KeyPress) &&
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
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
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
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
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
315 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
316 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
317 return(repeated);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
318 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
319
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
320 /* Note: The X server buffers and accumulates mouse motion events, so
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
321 the motion event generated by the warp may not appear exactly as we
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
322 expect it to. We work around this (and improve performance) by only
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
323 warping the pointer when it reaches the edge, and then wait for it.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
324 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
325 #define MOUSE_FUDGE_FACTOR 8
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
326
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
327 static __inline__ int X11_WarpedMotion(_THIS, XEvent *xevent)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
328 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
329 int w, h, i;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
330 int deltax, deltay;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
331 int posted;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
332
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
333 w = SDL_VideoSurface->w;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
334 h = SDL_VideoSurface->h;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
335 deltax = xevent->xmotion.x - mouse_last.x;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
336 deltay = xevent->xmotion.y - mouse_last.y;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
337 #ifdef DEBUG_MOTION
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
338 printf("Warped mouse motion: %d,%d\n", deltax, deltay);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
339 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
340 mouse_last.x = xevent->xmotion.x;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
341 mouse_last.y = xevent->xmotion.y;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
342 posted = SDL_PrivateMouseMotion(0, 1, deltax, deltay);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
343
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
344 if ( (xevent->xmotion.x < MOUSE_FUDGE_FACTOR) ||
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
345 (xevent->xmotion.x > (w-MOUSE_FUDGE_FACTOR)) ||
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
346 (xevent->xmotion.y < MOUSE_FUDGE_FACTOR) ||
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
347 (xevent->xmotion.y > (h-MOUSE_FUDGE_FACTOR)) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
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
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
350 deltax = xevent->xmotion.x - mouse_last.x;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
351 deltay = xevent->xmotion.y - mouse_last.y;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
352 #ifdef DEBUG_MOTION
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
353 printf("Extra mouse motion: %d,%d\n", deltax, deltay);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
354 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
355 mouse_last.x = xevent->xmotion.x;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
356 mouse_last.y = xevent->xmotion.y;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
357 posted += SDL_PrivateMouseMotion(0, 1, deltax, deltay);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
358 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
359 mouse_last.x = w/2;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
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
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
362 mouse_last.x, mouse_last.y);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
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
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
365 if ( (xevent->xmotion.x >
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
366 (mouse_last.x-MOUSE_FUDGE_FACTOR)) &&
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
367 (xevent->xmotion.x <
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
368 (mouse_last.x+MOUSE_FUDGE_FACTOR)) &&
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
369 (xevent->xmotion.y >
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
370 (mouse_last.y-MOUSE_FUDGE_FACTOR)) &&
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
371 (xevent->xmotion.y <
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
372 (mouse_last.y+MOUSE_FUDGE_FACTOR)) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
373 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
374 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
375 #ifdef DEBUG_XEVENTS
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
376 printf("Lost mouse motion: %d,%d\n", xevent->xmotion.x, xevent->xmotion.y);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
377 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
378 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
379 #ifdef DEBUG_XEVENTS
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
380 if ( i == 10 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
381 printf("Warning: didn't detect mouse warp motion\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
382 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
383 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
384 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
385 return(posted);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
386 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
387
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
388 static int X11_DispatchEvent(_THIS)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
389 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
390 int posted;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
391 XEvent xevent;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
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
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
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
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
414 posted = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
415 switch (xevent.type) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
416
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
417 /* Gaining mouse coverage? */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
418 case EnterNotify: {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
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
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
421 if ( xevent.xcrossing.mode == NotifyGrab )
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
422 printf("Mode: NotifyGrab\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
423 if ( xevent.xcrossing.mode == NotifyUngrab )
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
424 printf("Mode: NotifyUngrab\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
425 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
426 if ( (xevent.xcrossing.mode != NotifyGrab) &&
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
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
01313c1a2bbe Fixed bug #104
Sam Lantinga <slouken@libsdl.org>
parents: 1784
diff changeset
431 posted = SDL_PrivateMouseMotion(0, 0,
01313c1a2bbe Fixed bug #104
Sam Lantinga <slouken@libsdl.org>
parents: 1784
diff changeset
432 xevent.xcrossing.x,
01313c1a2bbe Fixed bug #104
Sam Lantinga <slouken@libsdl.org>
parents: 1784
diff changeset
433 xevent.xcrossing.y);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
434 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
435 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
436 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
437
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
438 /* Losing mouse coverage? */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
439 case LeaveNotify: {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
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
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
442 if ( xevent.xcrossing.mode == NotifyGrab )
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
443 printf("Mode: NotifyGrab\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
444 if ( xevent.xcrossing.mode == NotifyUngrab )
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
445 printf("Mode: NotifyUngrab\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
446 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
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
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
457 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
458 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
459 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
460
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
461 /* Gaining input focus? */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
462 case FocusIn: {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
463 #ifdef DEBUG_XEVENTS
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
464 printf("FocusIn!\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
465 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
466 posted = SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
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
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
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
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
471 }
1328
27ddb06a0bca Date: Sat, 04 Feb 2006 19:47:23 +0900
Sam Lantinga <slouken@libsdl.org>
parents: 1327
diff changeset
472 #endif
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
473 /* Queue entry into fullscreen mode */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
474 switch_waiting = 0x01 | SDL_FULLSCREEN;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
475 switch_time = SDL_GetTicks() + 1500;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
476 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
477 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
478
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
479 /* Losing input focus? */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
480 case FocusOut: {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
481 #ifdef DEBUG_XEVENTS
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
482 printf("FocusOut!\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
483 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
484 posted = SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
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
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
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
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
489 }
1328
27ddb06a0bca Date: Sat, 04 Feb 2006 19:47:23 +0900
Sam Lantinga <slouken@libsdl.org>
parents: 1327
diff changeset
490 #endif
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
491 /* Queue leaving fullscreen mode */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
492 switch_waiting = 0x01;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
493 switch_time = SDL_GetTicks() + 200;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
494 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
495 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
496
4117
dbb5f9556796 Fixed bug #502
Sam Lantinga <slouken@libsdl.org>
parents: 4094
diff changeset
497 #ifdef X_HAVE_UTF8_STRING
3978
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
498 /* Some IM requires MappingNotify to be passed to
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
499 XRefreshKeyboardMapping by the app. */
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
500 case MappingNotify: {
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
501 XRefreshKeyboardMapping(&xevent.xmapping);
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
502 }
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
503 break;
4117
dbb5f9556796 Fixed bug #502
Sam Lantinga <slouken@libsdl.org>
parents: 4094
diff changeset
504 #endif /* X_HAVE_UTF8_STRING */
3978
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
505
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
506 /* Generated upon EnterWindow and FocusIn */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
507 case KeymapNotify: {
14
c3e9d4a623c1 Fixed stuck keys when changing the video mode
Sam Lantinga <slouken@lokigames.com>
parents: 12
diff changeset
508 #ifdef DEBUG_XEVENTS
c3e9d4a623c1 Fixed stuck keys when changing the video mode
Sam Lantinga <slouken@lokigames.com>
parents: 12
diff changeset
509 printf("KeymapNotify!\n");
c3e9d4a623c1 Fixed stuck keys when changing the video mode
Sam Lantinga <slouken@lokigames.com>
parents: 12
diff changeset
510 #endif
1327
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
511 X11_SetKeyboardState(SDL_Display, xevent.xkeymap.key_vector);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
512 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
513 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
514
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
515 /* Mouse motion? */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
516 case MotionNotify: {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
517 if ( SDL_VideoSurface ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
518 if ( mouse_relative ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
519 if ( using_dga & DGA_MOUSE ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
520 #ifdef DEBUG_MOTION
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
521 printf("DGA motion: %d,%d\n", xevent.xmotion.x_root, xevent.xmotion.y_root);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
522 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
523 posted = SDL_PrivateMouseMotion(0, 1,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
524 xevent.xmotion.x_root,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
525 xevent.xmotion.y_root);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
526 } else {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
527 posted = X11_WarpedMotion(this,&xevent);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
528 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
529 } else {
82
2bddc38a9f5d When the mouse is grabbed, send the application the motion associated with
Sam Lantinga <slouken@lokigames.com>
parents: 75
diff changeset
530 #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
531 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
532 #endif
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
533 posted = SDL_PrivateMouseMotion(0, 0,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
534 xevent.xmotion.x,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
535 xevent.xmotion.y);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
536 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
537 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
538 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
539 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
540
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
541 /* Mouse button press? */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
542 case ButtonPress: {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
543 posted = SDL_PrivateMouseButton(SDL_PRESSED,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
544 xevent.xbutton.button, 0, 0);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
545 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
546 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
547
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
548 /* Mouse button release? */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
549 case ButtonRelease: {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
550 posted = SDL_PrivateMouseButton(SDL_RELEASED,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
551 xevent.xbutton.button, 0, 0);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
552 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
553 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
554
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
555 /* Key press? */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
556 case KeyPress: {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
557 SDL_keysym keysym;
1327
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
558 KeyCode keycode = xevent.xkey.keycode;
14
c3e9d4a623c1 Fixed stuck keys when changing the video mode
Sam Lantinga <slouken@lokigames.com>
parents: 12
diff changeset
559
c3e9d4a623c1 Fixed stuck keys when changing the video mode
Sam Lantinga <slouken@lokigames.com>
parents: 12
diff changeset
560 #ifdef DEBUG_XEVENTS
c3e9d4a623c1 Fixed stuck keys when changing the video mode
Sam Lantinga <slouken@lokigames.com>
parents: 12
diff changeset
561 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
562 #endif
3978
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
563 /* If we're not doing translation, we're done! */
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
564 if ( !SDL_TranslateUNICODE ) {
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
565 /* Get the translated SDL virtual keysym and put it on the queue.*/
1327
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
566 keysym.scancode = keycode;
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
567 keysym.sym = X11_TranslateKeycode(SDL_Display, keycode);
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
568 keysym.mod = KMOD_NONE;
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
569 keysym.unicode = 0;
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
570 posted = SDL_PrivateKeyboard(SDL_PRESSED, &keysym);
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
571 break;
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
572 }
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
573
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
574 /* Look up the translated value for the key event */
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
575 #ifdef X_HAVE_UTF8_STRING
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
576 if ( SDL_IC != NULL ) {
3978
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
577 Status status;
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
578 KeySym xkeysym;
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
579 int i;
1327
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
580 /* 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
581 /* ... It's true, but Xutf8LookupString can
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
582 return more than one characters. Moreover,
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
583 the spec. put no upper bound, so we should
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
584 be ready for longer strings. */
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
585 char keybuf[32];
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
586 char *keydata = keybuf;
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
587 int count;
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
588 Uint16 utf16buf[32];
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
589 Uint16 *utf16data = utf16buf;
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
590 int utf16size;
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
591 int utf16length;
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
592
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
593 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
594 if (XBufferOverflow == status) {
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
595 /* The IM has just generated somewhat long
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
596 string. We need a longer buffer in this
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
597 case. */
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
598 keydata = SDL_malloc(count);
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
599 if ( keydata == NULL ) {
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
600 SDL_OutOfMemory();
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
601 break;
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 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
604 }
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 switch (status) {
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
607
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
608 case XBufferOverflow: {
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
609 /* Oops! We have allocated the bytes as
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
610 requested by Xutf8LookupString, so the
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
611 length of the buffer must be
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
612 sufficient. This case should never
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
613 happen! */
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
614 SDL_SetError("Xutf8LookupString indicated a double buffer overflow!");
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
615 break;
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
616 }
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
617
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
618 case XLookupChars:
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
619 case XLookupBoth: {
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
620 if (0 == count) {
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
621 break;
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
622 }
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
623
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
624 /* We got a converted string from IM. Make
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
625 sure to deliver all characters to the
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
626 application as SDL events. Note that
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
627 an SDL event can only carry one UTF-16
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
628 encoding unit, and a surrogate pair is
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
629 delivered as two SDL events. I guess
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
630 this behaviour is probably _imported_
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
631 from Windows or MacOS. To do so, we need
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
632 to convert the UTF-8 data into UTF-16
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
633 data (not UCS4/UTF-32!). We need an
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
634 estimate of the number of UTF-16 encoding
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
635 units here. The worst case is pure ASCII
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
636 string. Assume so. */
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
637 /* 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
638 carries the whole UTF-8 string with it. */
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
639 utf16size = count * sizeof(Uint16);
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
640 if (utf16size > sizeof(utf16buf)) {
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
641 utf16data = (Uint16 *) SDL_malloc(utf16size);
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
642 if (utf16data == NULL) {
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
643 SDL_OutOfMemory();
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
644 break;
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
645 }
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
646 }
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
647 utf16length = Utf8ToUtf16((Uint8 *)keydata, count, utf16data, utf16size);
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
648 if (utf16length < 0) {
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
649 /* The keydata contained an invalid byte
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
650 sequence. It should be a bug of the IM
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
651 or Xlib... */
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
652 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
653 break;
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
654 }
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
655
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
656 /* Deliver all UTF-16 encoding units. At
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
657 this moment, SDL event queue has a
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
658 fixed size (128 events), and an SDL
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
659 event can hold just one UTF-16 encoding
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
660 unit. So, if we receive more than 128
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
661 UTF-16 encoding units from a commit,
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
662 exceeded characters will be lost. */
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
663 for (i = 0; i < utf16length - 1; i++) {
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
664 keysym.scancode = 0;
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
665 keysym.sym = SDLK_UNKNOWN;
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
666 keysym.mod = KMOD_NONE;
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
667 keysym.unicode = utf16data[i];
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
668 posted = SDL_PrivateKeyboard(SDL_PRESSED, &keysym);
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
669 }
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
670 /* The keysym for the last character carries the
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
671 scancode and symbol that corresponds to the X11
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
672 keycode. */
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
673 if (utf16length > 0) {
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
674 keysym.scancode = keycode;
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
675 keysym.sym = (keycode ? X11_TranslateKeycode(SDL_Display, keycode) : 0);
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
676 keysym.mod = KMOD_NONE;
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
677 keysym.unicode = utf16data[utf16length - 1];
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
678 posted = SDL_PrivateKeyboard(SDL_PRESSED, &keysym);
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 break;
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
681 }
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
682
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
683 case XLookupKeySym: {
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
684 /* I'm not sure whether it is possible that
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
685 a zero keycode makes XLookupKeySym
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
686 status. What I'm sure is that a
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
687 combination of a zero scan code and a non
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
688 zero sym makes SDL_PrivateKeyboard
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
689 strange state... So, just discard it.
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
690 If this doesn't work, I'm receiving bug
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
691 reports, and I can know under what
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
692 condition this case happens. */
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
693 if (keycode) {
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
694 keysym.scancode = keycode;
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
695 keysym.sym = X11_TranslateKeycode(SDL_Display, keycode);
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
696 keysym.mod = KMOD_NONE;
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
697 keysym.unicode = 0;
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
698 posted = SDL_PrivateKeyboard(SDL_PRESSED, &keysym);
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 break;
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
701 }
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
702
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
703 case XLookupNone: {
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
704 /* IM has eaten the event. */
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
705 break;
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
706 }
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
707
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
708 default:
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
709 /* An unknown status from Xutf8LookupString. */
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
710 SDL_SetError("Oops! Xutf8LookupStringreturned an unknown status");
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
711 }
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
712
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
713 /* Release dynamic buffers if allocated. */
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
714 if (keydata != NULL && keybuf != keydata) {
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
715 SDL_free(keydata);
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
716 }
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
717 if (utf16data != NULL && utf16buf != utf16data) {
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
718 SDL_free(utf16data);
1327
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
719 }
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
720 }
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
721 else
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
722 #endif
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
723 {
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
724 static XComposeStatus state;
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
725 char keybuf[32];
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
726
3999
f61a20d195f7 Fixed bug #450
Sam Lantinga <slouken@libsdl.org>
parents: 3978
diff changeset
727 keysym.scancode = keycode;
f61a20d195f7 Fixed bug #450
Sam Lantinga <slouken@libsdl.org>
parents: 3978
diff changeset
728 keysym.sym = X11_TranslateKeycode(SDL_Display, keycode);
f61a20d195f7 Fixed bug #450
Sam Lantinga <slouken@libsdl.org>
parents: 3978
diff changeset
729 keysym.mod = KMOD_NONE;
f61a20d195f7 Fixed bug #450
Sam Lantinga <slouken@libsdl.org>
parents: 3978
diff changeset
730 keysym.unicode = 0;
1575
3ba88cb7eb1b Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
731 if ( XLookupString(&xevent.xkey,
1327
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
732 keybuf, sizeof(keybuf),
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
733 NULL, &state) ) {
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
734 /*
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
735 * FIXME: XLookupString() may yield more than one
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
736 * character, so we need a mechanism to allow for
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
737 * this (perhaps null keypress events with a
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
738 * unicode value)
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
739 */
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
740 keysym.unicode = (Uint8)keybuf[0];
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
741 }
3978
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
742
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
743 posted = SDL_PrivateKeyboard(SDL_PRESSED, &keysym);
1327
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
744 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
745 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
746 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
747
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
748 /* Key release? */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
749 case KeyRelease: {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
750 SDL_keysym keysym;
1327
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
751 KeyCode keycode = xevent.xkey.keycode;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
752
3978
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
753 if (keycode == 0) {
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
754 /* There should be no KeyRelease for keycode == 0,
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
755 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
756 keystroke. */
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
757 /* We need to emit some diagnostic message here. */
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
758 break;
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
759 }
b966761fef6c Significantly improved XIM support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3936
diff changeset
760
14
c3e9d4a623c1 Fixed stuck keys when changing the video mode
Sam Lantinga <slouken@lokigames.com>
parents: 12
diff changeset
761 #ifdef DEBUG_XEVENTS
c3e9d4a623c1 Fixed stuck keys when changing the video mode
Sam Lantinga <slouken@lokigames.com>
parents: 12
diff changeset
762 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
763 #endif
1327
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
764
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
765 /* Get the translated SDL virtual keysym */
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
766 keysym.scancode = keycode;
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
767 keysym.sym = X11_TranslateKeycode(SDL_Display, keycode);
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
768 keysym.mod = KMOD_NONE;
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
769 keysym.unicode = 0;
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
770
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
771 posted = SDL_PrivateKeyboard(SDL_RELEASED, &keysym);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
772 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
773 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
774
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
775 /* Have we been iconified? */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
776 case UnmapNotify: {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
777 #ifdef DEBUG_XEVENTS
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
778 printf("UnmapNotify!\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
779 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
780 /* If we're active, make ourselves inactive */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
781 if ( SDL_GetAppState() & SDL_APPACTIVE ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
782 /* Swap out the gamma before we go inactive */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
783 X11_SwapVidModeGamma(this);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
784
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
785 /* Send an internal deactivate event */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
786 posted = SDL_PrivateAppActive(0,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
787 SDL_APPACTIVE|SDL_APPINPUTFOCUS);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
788 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
789 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
790 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
791
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
792 /* Have we been restored? */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
793 case MapNotify: {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
794 #ifdef DEBUG_XEVENTS
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
795 printf("MapNotify!\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
796 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
797 /* If we're not active, make ourselves active */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
798 if ( !(SDL_GetAppState() & SDL_APPACTIVE) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
799 /* Send an internal activate event */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
800 posted = SDL_PrivateAppActive(1, SDL_APPACTIVE);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
801
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
802 /* Now that we're active, swap the gamma back */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
803 X11_SwapVidModeGamma(this);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
804 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
805
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
806 if ( SDL_VideoSurface &&
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
807 (SDL_VideoSurface->flags & SDL_FULLSCREEN) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
808 X11_EnterFullScreen(this);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
809 } else {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
810 X11_GrabInputNoLock(this, this->input_grab);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
811 }
8
5574376c451d Fixed relative motion checking after restore under X11
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
812 X11_CheckMouseModeNoLock(this);
5574376c451d Fixed relative motion checking after restore under X11
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
813
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
814 if ( SDL_VideoSurface ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
815 X11_RefreshDisplay(this);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
816 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
817 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
818 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
819
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
820 /* Have we been resized or moved? */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
821 case ConfigureNotify: {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
822 #ifdef DEBUG_XEVENTS
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
823 printf("ConfigureNotify! (resize: %dx%d)\n", xevent.xconfigure.width, xevent.xconfigure.height);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
824 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
825 if ( SDL_VideoSurface ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
826 if ((xevent.xconfigure.width != SDL_VideoSurface->w) ||
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
827 (xevent.xconfigure.height != SDL_VideoSurface->h)) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
828 /* FIXME: Find a better fix for the bug with KDE 1.2 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
829 if ( ! ((xevent.xconfigure.width == 32) &&
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
830 (xevent.xconfigure.height == 32)) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
831 SDL_PrivateResize(xevent.xconfigure.width,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
832 xevent.xconfigure.height);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
833 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
834 } else {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
835 /* OpenGL windows need to know about the change */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
836 if ( SDL_VideoSurface->flags & SDL_OPENGL ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
837 SDL_PrivateExpose();
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
838 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
839 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
840 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
841 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
842 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
843
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
844 /* Have we been requested to quit (or another client message?) */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
845 case ClientMessage: {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
846 if ( (xevent.xclient.format == 32) &&
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
847 (xevent.xclient.data.l[0] == WM_DELETE_WINDOW) )
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
848 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
849 posted = SDL_PrivateQuit();
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
850 } else
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
851 if ( SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
852 SDL_SysWMmsg wmmsg;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
853
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
854 SDL_VERSION(&wmmsg.version);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
855 wmmsg.subsystem = SDL_SYSWM_X11;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
856 wmmsg.event.xevent = xevent;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
857 posted = SDL_PrivateSysWMEvent(&wmmsg);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
858 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
859 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
860 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
861
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
862 /* Do we need to refresh ourselves? */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
863 case Expose: {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
864 #ifdef DEBUG_XEVENTS
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
865 printf("Expose (count = %d)\n", xevent.xexpose.count);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
866 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
867 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
868 X11_RefreshDisplay(this);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
869 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
870 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
871 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
872
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
873 default: {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
874 #ifdef DEBUG_XEVENTS
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
875 printf("Unhandled event %d\n", xevent.type);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
876 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
877 /* Only post the event if we're watching for it */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
878 if ( SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
879 SDL_SysWMmsg wmmsg;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
880
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
881 SDL_VERSION(&wmmsg.version);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
882 wmmsg.subsystem = SDL_SYSWM_X11;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
883 wmmsg.event.xevent = xevent;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
884 posted = SDL_PrivateSysWMEvent(&wmmsg);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
885 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
886 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
887 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
888 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
889 return(posted);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
890 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
891
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
892 /* Ack! XPending() actually performs a blocking read if no events available */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
893 int X11_Pending(Display *display)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
894 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
895 /* 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
896 XFlush(display);
3ba88cb7eb1b Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
897 if ( XEventsQueued(display, QueuedAlready) ) {
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
898 return(1);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
899 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
900
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
901 /* More drastic measures are required -- see if X is ready to talk */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
902 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
903 static struct timeval zero_time; /* static == 0 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
904 int x11_fd;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
905 fd_set fdset;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
906
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
907 x11_fd = ConnectionNumber(display);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
908 FD_ZERO(&fdset);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
909 FD_SET(x11_fd, &fdset);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
910 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
911 return(XPending(display));
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
912 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
913 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
914
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
915 /* Oh well, nothing is ready .. */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
916 return(0);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
917 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
918
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
919 void X11_PumpEvents(_THIS)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
920 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
921 int pending;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
922
4139
568c9b3c0167 * Added configure option --enable-screensaver, to allow enabling the screensaver by default.
Sam Lantinga <slouken@libsdl.org>
parents: 4117
diff changeset
923 /* Update activity every five seconds to prevent screensaver. --ryan. */
568c9b3c0167 * Added configure option --enable-screensaver, to allow enabling the screensaver by default.
Sam Lantinga <slouken@libsdl.org>
parents: 4117
diff changeset
924 if (!allow_screensaver) {
568c9b3c0167 * Added configure option --enable-screensaver, to allow enabling the screensaver by default.
Sam Lantinga <slouken@libsdl.org>
parents: 4117
diff changeset
925 static Uint32 screensaverTicks;
568c9b3c0167 * Added configure option --enable-screensaver, to allow enabling the screensaver by default.
Sam Lantinga <slouken@libsdl.org>
parents: 4117
diff changeset
926 Uint32 nowTicks = SDL_GetTicks();
568c9b3c0167 * Added configure option --enable-screensaver, to allow enabling the screensaver by default.
Sam Lantinga <slouken@libsdl.org>
parents: 4117
diff changeset
927 if ((nowTicks - screensaverTicks) > 5000) {
568c9b3c0167 * Added configure option --enable-screensaver, to allow enabling the screensaver by default.
Sam Lantinga <slouken@libsdl.org>
parents: 4117
diff changeset
928 XResetScreenSaver(SDL_Display);
568c9b3c0167 * Added configure option --enable-screensaver, to allow enabling the screensaver by default.
Sam Lantinga <slouken@libsdl.org>
parents: 4117
diff changeset
929 screensaverTicks = nowTicks;
568c9b3c0167 * Added configure option --enable-screensaver, to allow enabling the screensaver by default.
Sam Lantinga <slouken@libsdl.org>
parents: 4117
diff changeset
930 }
568c9b3c0167 * Added configure option --enable-screensaver, to allow enabling the screensaver by default.
Sam Lantinga <slouken@libsdl.org>
parents: 4117
diff changeset
931 }
568c9b3c0167 * Added configure option --enable-screensaver, to allow enabling the screensaver by default.
Sam Lantinga <slouken@libsdl.org>
parents: 4117
diff changeset
932
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
933 /* Keep processing pending events */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
934 pending = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
935 while ( X11_Pending(SDL_Display) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
936 X11_DispatchEvent(this);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
937 ++pending;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
938 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
939 if ( switch_waiting ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
940 Uint32 now;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
941
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
942 now = SDL_GetTicks();
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
943 if ( pending || !SDL_VideoSurface ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
944 /* Try again later... */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
945 if ( switch_waiting & SDL_FULLSCREEN ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
946 switch_time = now + 1500;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
947 } else {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
948 switch_time = now + 200;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
949 }
1740
db7e15a99cb3 Fixed bug #101
Sam Lantinga <slouken@libsdl.org>
parents: 1575
diff changeset
950 } else if ( (int)(switch_time-now) <= 0 ) {
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
951 Uint32 go_fullscreen;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
952
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
953 go_fullscreen = switch_waiting & SDL_FULLSCREEN;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
954 switch_waiting = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
955 if ( SDL_VideoSurface->flags & SDL_FULLSCREEN ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
956 if ( go_fullscreen ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
957 X11_EnterFullScreen(this);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
958 } else {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
959 X11_LeaveFullScreen(this);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
960 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
961 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
962 /* Handle focus in/out when grabbed */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
963 if ( go_fullscreen ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
964 X11_GrabInputNoLock(this, this->input_grab);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
965 } else {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
966 X11_GrabInputNoLock(this, SDL_GRAB_OFF);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
967 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
968 X11_CheckMouseModeNoLock(this);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
969 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
970 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
971 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
972
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
973 void X11_InitKeymap(void)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
974 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
975 int i;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
976
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
977 /* Odd keys used in international keyboards */
1379
c0a74f199ecf Use only safe string functions
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
978 for ( i=0; i<SDL_arraysize(ODD_keymap); ++i )
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
979 ODD_keymap[i] = SDLK_UNKNOWN;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
980
1327
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
981 /* Some of these might be mappable to an existing SDLK_ code */
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
982 ODD_keymap[XK_dead_grave&0xFF] = SDLK_COMPOSE;
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
983 ODD_keymap[XK_dead_acute&0xFF] = SDLK_COMPOSE;
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
984 ODD_keymap[XK_dead_tilde&0xFF] = SDLK_COMPOSE;
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
985 ODD_keymap[XK_dead_macron&0xFF] = SDLK_COMPOSE;
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
986 ODD_keymap[XK_dead_breve&0xFF] = SDLK_COMPOSE;
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
987 ODD_keymap[XK_dead_abovedot&0xFF] = SDLK_COMPOSE;
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
988 ODD_keymap[XK_dead_diaeresis&0xFF] = SDLK_COMPOSE;
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
989 ODD_keymap[XK_dead_abovering&0xFF] = SDLK_COMPOSE;
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
990 ODD_keymap[XK_dead_doubleacute&0xFF] = SDLK_COMPOSE;
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
991 ODD_keymap[XK_dead_caron&0xFF] = SDLK_COMPOSE;
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
992 ODD_keymap[XK_dead_cedilla&0xFF] = SDLK_COMPOSE;
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
993 ODD_keymap[XK_dead_ogonek&0xFF] = SDLK_COMPOSE;
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
994 ODD_keymap[XK_dead_iota&0xFF] = SDLK_COMPOSE;
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
995 ODD_keymap[XK_dead_voiced_sound&0xFF] = SDLK_COMPOSE;
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
996 ODD_keymap[XK_dead_semivoiced_sound&0xFF] = SDLK_COMPOSE;
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
997 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
998 #ifdef XK_dead_hook
1327
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
999 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
1000 #endif
27ddb06a0bca Date: Sat, 04 Feb 2006 19:47:23 +0900
Sam Lantinga <slouken@libsdl.org>
parents: 1327
diff changeset
1001 #ifdef XK_dead_horn
1327
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1002 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
1003 #endif
1327
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1004
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1005 #ifdef XK_dead_circumflex
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1006 /* These X keysyms have 0xFE as the high byte */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1007 ODD_keymap[XK_dead_circumflex&0xFF] = SDLK_CARET;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1008 #endif
805
df1a3218b468 Date: Wed, 04 Feb 2004 13:51:56 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
1009 #ifdef XK_ISO_Level3_Shift
df1a3218b468 Date: Wed, 04 Feb 2004 13:51:56 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
1010 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
1011 #endif
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1012
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1013 /* Map the miscellaneous keys */
1379
c0a74f199ecf Use only safe string functions
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
1014 for ( i=0; i<SDL_arraysize(MISC_keymap); ++i )
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1015 MISC_keymap[i] = SDLK_UNKNOWN;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1016
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1017 /* These X keysyms have 0xFF as the high byte */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1018 MISC_keymap[XK_BackSpace&0xFF] = SDLK_BACKSPACE;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1019 MISC_keymap[XK_Tab&0xFF] = SDLK_TAB;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1020 MISC_keymap[XK_Clear&0xFF] = SDLK_CLEAR;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1021 MISC_keymap[XK_Return&0xFF] = SDLK_RETURN;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1022 MISC_keymap[XK_Pause&0xFF] = SDLK_PAUSE;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1023 MISC_keymap[XK_Escape&0xFF] = SDLK_ESCAPE;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1024 MISC_keymap[XK_Delete&0xFF] = SDLK_DELETE;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1025
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1026 MISC_keymap[XK_KP_0&0xFF] = SDLK_KP0; /* Keypad 0-9 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1027 MISC_keymap[XK_KP_1&0xFF] = SDLK_KP1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1028 MISC_keymap[XK_KP_2&0xFF] = SDLK_KP2;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1029 MISC_keymap[XK_KP_3&0xFF] = SDLK_KP3;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1030 MISC_keymap[XK_KP_4&0xFF] = SDLK_KP4;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1031 MISC_keymap[XK_KP_5&0xFF] = SDLK_KP5;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1032 MISC_keymap[XK_KP_6&0xFF] = SDLK_KP6;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1033 MISC_keymap[XK_KP_7&0xFF] = SDLK_KP7;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1034 MISC_keymap[XK_KP_8&0xFF] = SDLK_KP8;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1035 MISC_keymap[XK_KP_9&0xFF] = SDLK_KP9;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1036 MISC_keymap[XK_KP_Insert&0xFF] = SDLK_KP0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1037 MISC_keymap[XK_KP_End&0xFF] = SDLK_KP1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1038 MISC_keymap[XK_KP_Down&0xFF] = SDLK_KP2;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1039 MISC_keymap[XK_KP_Page_Down&0xFF] = SDLK_KP3;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1040 MISC_keymap[XK_KP_Left&0xFF] = SDLK_KP4;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1041 MISC_keymap[XK_KP_Begin&0xFF] = SDLK_KP5;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1042 MISC_keymap[XK_KP_Right&0xFF] = SDLK_KP6;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1043 MISC_keymap[XK_KP_Home&0xFF] = SDLK_KP7;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1044 MISC_keymap[XK_KP_Up&0xFF] = SDLK_KP8;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1045 MISC_keymap[XK_KP_Page_Up&0xFF] = SDLK_KP9;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1046 MISC_keymap[XK_KP_Delete&0xFF] = SDLK_KP_PERIOD;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1047 MISC_keymap[XK_KP_Decimal&0xFF] = SDLK_KP_PERIOD;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1048 MISC_keymap[XK_KP_Divide&0xFF] = SDLK_KP_DIVIDE;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1049 MISC_keymap[XK_KP_Multiply&0xFF] = SDLK_KP_MULTIPLY;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1050 MISC_keymap[XK_KP_Subtract&0xFF] = SDLK_KP_MINUS;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1051 MISC_keymap[XK_KP_Add&0xFF] = SDLK_KP_PLUS;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1052 MISC_keymap[XK_KP_Enter&0xFF] = SDLK_KP_ENTER;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1053 MISC_keymap[XK_KP_Equal&0xFF] = SDLK_KP_EQUALS;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1054
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1055 MISC_keymap[XK_Up&0xFF] = SDLK_UP;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1056 MISC_keymap[XK_Down&0xFF] = SDLK_DOWN;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1057 MISC_keymap[XK_Right&0xFF] = SDLK_RIGHT;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1058 MISC_keymap[XK_Left&0xFF] = SDLK_LEFT;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1059 MISC_keymap[XK_Insert&0xFF] = SDLK_INSERT;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1060 MISC_keymap[XK_Home&0xFF] = SDLK_HOME;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1061 MISC_keymap[XK_End&0xFF] = SDLK_END;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1062 MISC_keymap[XK_Page_Up&0xFF] = SDLK_PAGEUP;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1063 MISC_keymap[XK_Page_Down&0xFF] = SDLK_PAGEDOWN;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1064
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1065 MISC_keymap[XK_F1&0xFF] = SDLK_F1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1066 MISC_keymap[XK_F2&0xFF] = SDLK_F2;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1067 MISC_keymap[XK_F3&0xFF] = SDLK_F3;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1068 MISC_keymap[XK_F4&0xFF] = SDLK_F4;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1069 MISC_keymap[XK_F5&0xFF] = SDLK_F5;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1070 MISC_keymap[XK_F6&0xFF] = SDLK_F6;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1071 MISC_keymap[XK_F7&0xFF] = SDLK_F7;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1072 MISC_keymap[XK_F8&0xFF] = SDLK_F8;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1073 MISC_keymap[XK_F9&0xFF] = SDLK_F9;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1074 MISC_keymap[XK_F10&0xFF] = SDLK_F10;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1075 MISC_keymap[XK_F11&0xFF] = SDLK_F11;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1076 MISC_keymap[XK_F12&0xFF] = SDLK_F12;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1077 MISC_keymap[XK_F13&0xFF] = SDLK_F13;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1078 MISC_keymap[XK_F14&0xFF] = SDLK_F14;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1079 MISC_keymap[XK_F15&0xFF] = SDLK_F15;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1080
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1081 MISC_keymap[XK_Num_Lock&0xFF] = SDLK_NUMLOCK;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1082 MISC_keymap[XK_Caps_Lock&0xFF] = SDLK_CAPSLOCK;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1083 MISC_keymap[XK_Scroll_Lock&0xFF] = SDLK_SCROLLOCK;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1084 MISC_keymap[XK_Shift_R&0xFF] = SDLK_RSHIFT;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1085 MISC_keymap[XK_Shift_L&0xFF] = SDLK_LSHIFT;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1086 MISC_keymap[XK_Control_R&0xFF] = SDLK_RCTRL;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1087 MISC_keymap[XK_Control_L&0xFF] = SDLK_LCTRL;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1088 MISC_keymap[XK_Alt_R&0xFF] = SDLK_RALT;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1089 MISC_keymap[XK_Alt_L&0xFF] = SDLK_LALT;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1090 MISC_keymap[XK_Meta_R&0xFF] = SDLK_RMETA;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1091 MISC_keymap[XK_Meta_L&0xFF] = SDLK_LMETA;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1092 MISC_keymap[XK_Super_L&0xFF] = SDLK_LSUPER; /* Left "Windows" */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1093 MISC_keymap[XK_Super_R&0xFF] = SDLK_RSUPER; /* Right "Windows */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1094 MISC_keymap[XK_Mode_switch&0xFF] = SDLK_MODE; /* "Alt Gr" key */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1095 MISC_keymap[XK_Multi_key&0xFF] = SDLK_COMPOSE; /* Multi-key compose */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1096
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1097 MISC_keymap[XK_Help&0xFF] = SDLK_HELP;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1098 MISC_keymap[XK_Print&0xFF] = SDLK_PRINT;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1099 MISC_keymap[XK_Sys_Req&0xFF] = SDLK_SYSREQ;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1100 MISC_keymap[XK_Break&0xFF] = SDLK_BREAK;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1101 MISC_keymap[XK_Menu&0xFF] = SDLK_MENU;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1102 MISC_keymap[XK_Hyper_R&0xFF] = SDLK_MENU; /* Windows "Menu" key */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1103 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1104
1327
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1105 /* Get the translated SDL virtual keysym */
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1106 SDLKey X11_TranslateKeycode(Display *display, KeyCode kc)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1107 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1108 KeySym xsym;
1327
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1109 SDLKey key;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1110
1575
3ba88cb7eb1b Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
1111 xsym = XKeycodeToKeysym(display, kc, 0);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1112 #ifdef DEBUG_KEYS
1327
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1113 fprintf(stderr, "Translating key code %d -> 0x%.4x\n", kc, xsym);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1114 #endif
1327
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1115 key = SDLK_UNKNOWN;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1116 if ( xsym ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1117 switch (xsym>>8) {
1327
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1118 case 0x1005FF:
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1119 #ifdef SunXK_F36
1327
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1120 if ( xsym == SunXK_F36 )
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1121 key = SDLK_F11;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1122 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1123 #ifdef SunXK_F37
1327
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1124 if ( xsym == SunXK_F37 )
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1125 key = SDLK_F12;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1126 #endif
1327
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1127 break;
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1128 case 0x00: /* Latin 1 */
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1129 key = (SDLKey)(xsym & 0xFF);
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1130 break;
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1131 case 0x01: /* Latin 2 */
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1132 case 0x02: /* Latin 3 */
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1133 case 0x03: /* Latin 4 */
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1134 case 0x04: /* Katakana */
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1135 case 0x05: /* Arabic */
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1136 case 0x06: /* Cyrillic */
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1137 case 0x07: /* Greek */
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1138 case 0x08: /* Technical */
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1139 case 0x0A: /* Publishing */
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1140 case 0x0C: /* Hebrew */
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1141 case 0x0D: /* Thai */
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1142 /* These are wrong, but it's better than nothing */
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1143 key = (SDLKey)(xsym & 0xFF);
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1144 break;
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1145 case 0xFE:
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1146 key = ODD_keymap[xsym&0xFF];
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1147 break;
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1148 case 0xFF:
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1149 key = MISC_keymap[xsym&0xFF];
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1150 break;
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1151 default:
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1152 /*
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1153 fprintf(stderr, "X11: Unhandled xsym, sym = 0x%04x\n",
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1154 (unsigned int)xsym);
1327
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1155 */
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1156 break;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1157 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1158 } else {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1159 /* X11 doesn't know how to translate the key! */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1160 switch (kc) {
1327
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1161 /* Caution:
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1162 These keycodes are from the Microsoft Keyboard
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1163 */
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1164 case 115:
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1165 key = SDLK_LSUPER;
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1166 break;
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1167 case 116:
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1168 key = SDLK_RSUPER;
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1169 break;
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1170 case 117:
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1171 key = SDLK_MENU;
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1172 break;
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1173 default:
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1174 /*
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1175 * no point in an error message; happens for
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1176 * several keys when we get a keymap notify
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1177 */
1327
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1178 break;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1179 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1180 }
1327
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1181 return key;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1182 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1183
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1184 /* X11 modifier masks for various keys */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1185 static unsigned meta_l_mask, meta_r_mask, alt_l_mask, alt_r_mask;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1186 static unsigned num_mask, mode_switch_mask;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1187
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1188 static void get_modifier_masks(Display *display)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1189 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1190 static unsigned got_masks;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1191 int i, j;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1192 XModifierKeymap *xmods;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1193 unsigned n;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1194
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1195 if(got_masks)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1196 return;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1197
1575
3ba88cb7eb1b Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
1198 xmods = XGetModifierMapping(display);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1199 n = xmods->max_keypermod;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1200 for(i = 3; i < 8; i++) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1201 for(j = 0; j < n; j++) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1202 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
1203 KeySym ks = XKeycodeToKeysym(display, kc, 0);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1204 unsigned mask = 1 << i;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1205 switch(ks) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1206 case XK_Num_Lock:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1207 num_mask = mask; break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1208 case XK_Alt_L:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1209 alt_l_mask = mask; break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1210 case XK_Alt_R:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1211 alt_r_mask = mask; break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1212 case XK_Meta_L:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1213 meta_l_mask = mask; break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1214 case XK_Meta_R:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1215 meta_r_mask = mask; break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1216 case XK_Mode_switch:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1217 mode_switch_mask = mask; break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1218 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1219 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1220 }
1575
3ba88cb7eb1b Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
1221 XFreeModifiermap(xmods);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1222 got_masks = 1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1223 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1224
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1225
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1226 /*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1227 * This function is semi-official; it is not officially exported and should
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1228 * not be considered part of the SDL API, but may be used by client code
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1229 * that *really* needs it (including legacy code).
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1230 * It is slow, though, and should be avoided if possible.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1231 *
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1232 * Note that it isn't completely accurate either; in particular, multi-key
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1233 * sequences (dead accents, compose key sequences) will not work since the
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1234 * state has been irrevocably lost.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1235 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1236 Uint16 X11_KeyToUnicode(SDLKey keysym, SDLMod modifiers)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1237 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1238 struct SDL_VideoDevice *this = current_video;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1239 char keybuf[32];
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1240 int i;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1241 KeySym xsym = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1242 XKeyEvent xkey;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1243 Uint16 unicode;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1244
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1245 if ( !this || !SDL_Display ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1246 return 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1247 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1248
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1328
diff changeset
1249 SDL_memset(&xkey, 0, sizeof(xkey));
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1250 xkey.display = SDL_Display;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1251
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1252 xsym = keysym; /* last resort if not found */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1253 for (i = 0; i < 256; ++i) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1254 if ( MISC_keymap[i] == keysym ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1255 xsym = 0xFF00 | i;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1256 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1257 } else if ( ODD_keymap[i] == keysym ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1258 xsym = 0xFE00 | i;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1259 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1260 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1261 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1262
1575
3ba88cb7eb1b Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
1263 xkey.keycode = XKeysymToKeycode(xkey.display, xsym);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1264
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1265 get_modifier_masks(SDL_Display);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1266 if(modifiers & KMOD_SHIFT)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1267 xkey.state |= ShiftMask;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1268 if(modifiers & KMOD_CAPS)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1269 xkey.state |= LockMask;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1270 if(modifiers & KMOD_CTRL)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1271 xkey.state |= ControlMask;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1272 if(modifiers & KMOD_MODE)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1273 xkey.state |= mode_switch_mask;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1274 if(modifiers & KMOD_LALT)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1275 xkey.state |= alt_l_mask;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1276 if(modifiers & KMOD_RALT)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1277 xkey.state |= alt_r_mask;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1278 if(modifiers & KMOD_LMETA)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1279 xkey.state |= meta_l_mask;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1280 if(modifiers & KMOD_RMETA)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1281 xkey.state |= meta_r_mask;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1282 if(modifiers & KMOD_NUM)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1283 xkey.state |= num_mask;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1284
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1285 unicode = 0;
1575
3ba88cb7eb1b Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
1286 if ( XLookupString(&xkey, keybuf, sizeof(keybuf), NULL, NULL) )
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1287 unicode = (unsigned char)keybuf[0];
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1288 return(unicode);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1289 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1290
1178
9867f3d86e44 Real Unicode support for X11. Based on updated version of this patch:
Ryan C. Gordon <icculus@icculus.org>
parents: 1168
diff changeset
1291
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1292 /*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1293 * Called when focus is regained, to read the keyboard state and generate
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1294 * synthetic keypress/release events.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1295 * key_vec is a bit vector of keycodes (256 bits)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1296 */
1327
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1297 void X11_SetKeyboardState(Display *display, const char *key_vec)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1298 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1299 char keys_return[32];
412
ac59b067815b Fix uninitialized variable warning
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
1300 int i;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1301 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
1302 SDLMod modstate;
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1303 Window junk_window;
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1304 int x, y;
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1305 unsigned int mask;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1306
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1307 /* The first time the window is mapped, we initialize key state */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1308 if ( ! key_vec ) {
1575
3ba88cb7eb1b Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
1309 XQueryKeymap(display, keys_return);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1310 key_vec = keys_return;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1311 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1312
111
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1313 /* 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
1314 modstate = 0;
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1315 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
1316 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
1317 &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
1318 if ( mask & LockMask ) {
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1319 modstate |= KMOD_CAPS;
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1320 }
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1321 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
1322 modstate |= KMOD_MODE;
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1323 }
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1324 if ( mask & num_mask ) {
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1325 modstate |= KMOD_NUM;
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1326 }
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1327 }
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1328
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1329 /* 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
1330 SDL_memset(kstate, 0, SDLK_LAST);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1331 /*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1332 * An obvious optimisation is to check entire longwords at a time in
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1333 * both loops, but we can't be sure the arrays are aligned so it's not
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1334 * worth the extra complexity
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1335 */
1327
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1336 for ( i = 0; i < 32; i++ ) {
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1337 int j;
1327
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1338 if ( !key_vec[i] )
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1339 continue;
1327
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1340 for ( j = 0; j < 8; j++ ) {
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1341 if ( key_vec[i] & (1 << j) ) {
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1342 SDLKey key;
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1343 KeyCode kc = (i << 3 | j);
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1344 key = X11_TranslateKeycode(display, kc);
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1345 if ( key == SDLK_UNKNOWN ) {
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1346 continue;
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1347 }
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1348 kstate[key] = SDL_PRESSED;
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1349 switch (key) {
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1350 case SDLK_LSHIFT:
111
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1351 modstate |= KMOD_LSHIFT;
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1352 break;
1327
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1353 case SDLK_RSHIFT:
111
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1354 modstate |= KMOD_RSHIFT;
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1355 break;
1327
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1356 case SDLK_LCTRL:
111
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1357 modstate |= KMOD_LCTRL;
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1358 break;
1327
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1359 case SDLK_RCTRL:
111
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1360 modstate |= KMOD_RCTRL;
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1361 break;
1327
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1362 case SDLK_LALT:
111
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1363 modstate |= KMOD_LALT;
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1364 break;
1327
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1365 case SDLK_RALT:
111
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1366 modstate |= KMOD_RALT;
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1367 break;
1327
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1368 case SDLK_LMETA:
111
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1369 modstate |= KMOD_LMETA;
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1370 break;
1327
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1371 case SDLK_RMETA:
111
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1372 modstate |= KMOD_RMETA;
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1373 break;
1327
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1374 default:
111
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1375 break;
1327
d12a63a8d95a Resolved bug #130
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
1376 }
111
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1377 }
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1378 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1379 }
111
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1380
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1381 /* 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
1382 if ( modstate & KMOD_CAPS ) {
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1383 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
1384 } else {
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1385 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
1386 }
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1387 if ( modstate & KMOD_NUM ) {
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1388 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
1389 } else {
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1390 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
1391 }
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1392
53e3d8ba4321 Now gets correct keyboard state when starting up on X11
Sam Lantinga <slouken@lokigames.com>
parents: 88
diff changeset
1393 /* 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
1394 SDL_SetModState(modstate);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1395 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1396
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1397 void X11_InitOSKeymap(_THIS)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1398 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1399 X11_InitKeymap();
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1400 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1401