annotate src/video/x11/SDL_x11events.c @ 1336:3692456e7b0f

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