Fixed X11 build, added code to print initial modifiers to checkkeys
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
diff --git a/src/video/x11/SDL_x11events.c b/src/video/x11/SDL_x11events.c
index b6ff74d..886dc43 100644
--- a/src/video/x11/SDL_x11events.c
+++ b/src/video/x11/SDL_x11events.c
@@ -334,6 +334,77 @@ static void X11_HandleGenericEvent(SDL_VideoData *videodata,XEvent event)
}
#endif /* SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS */
+static unsigned
+X11_GetNumLockModifierMask(_THIS)
+{
+ SDL_VideoData *viddata = (SDL_VideoData *) _this->driverdata;
+ Display *display = viddata->display;
+ unsigned num_mask = 0;
+ int i, j;
+ XModifierKeymap *xmods;
+ unsigned n;
+
+ xmods = X11_XGetModifierMapping(display);
+ n = xmods->max_keypermod;
+ for(i = 3; i < 8; i++) {
+ for(j = 0; j < n; j++) {
+ KeyCode kc = xmods->modifiermap[i * n + j];
+ if (viddata->key_layout[kc] == SDL_SCANCODE_NUMLOCKCLEAR) {
+ num_mask = 1 << i;
+ break;
+ }
+ }
+ }
+ X11_XFreeModifiermap(xmods);
+
+ return num_mask;
+}
+
+static void
+X11_ReconcileKeyboardState(_THIS, const SDL_WindowData *data)
+{
+ SDL_VideoData *viddata = (SDL_VideoData *) _this->driverdata;
+ Display *display = viddata->display;
+ char keys[32];
+ int keycode;
+ Window junk_window;
+ int x, y;
+ unsigned int mask;
+
+ X11_XQueryKeymap(display, keys);
+
+ /* Get the keyboard modifier state */
+ if (X11_XQueryPointer(display, DefaultRootWindow(display), &junk_window, &junk_window, &x, &y, &x, &y, &mask)) {
+ unsigned num_mask = X11_GetNumLockModifierMask(_this);
+ const Uint8 *keystate = SDL_GetKeyboardState(NULL);
+ Uint8 capslockState = keystate[SDL_SCANCODE_CAPSLOCK];
+ Uint8 numlockState = keystate[SDL_SCANCODE_NUMLOCKCLEAR];
+
+ /* Toggle key mod state if needed */
+ if (!!(mask & LockMask) != !!(SDL_GetModState() & KMOD_CAPS)) {
+ SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_CAPSLOCK);
+ if (capslockState == SDL_RELEASED) {
+ SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_CAPSLOCK);
+ }
+ }
+
+ if (!!(mask & num_mask) != !!(SDL_GetModState() & KMOD_NUM)) {
+ SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_NUMLOCKCLEAR);
+ if (numlockState == SDL_RELEASED) {
+ SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_NUMLOCKCLEAR);
+ }
+ }
+ }
+
+ for (keycode = 0; keycode < 256; ++keycode) {
+ if (keys[keycode / 8] & (1 << (keycode % 8))) {
+ SDL_SendKeyboardKey(SDL_PRESSED, viddata->key_layout[keycode]);
+ } else {
+ SDL_SendKeyboardKey(SDL_RELEASED, viddata->key_layout[keycode]);
+ }
+ }
+}
+
static void
X11_DispatchFocusIn(_THIS, SDL_WindowData *data)
@@ -342,7 +413,7 @@ X11_DispatchFocusIn(_THIS, SDL_WindowData *data)
printf("window %p: Dispatching FocusIn\n", data);
#endif
SDL_SetKeyboardFocus(data->window);
- ReconcileKeyboardState(_this, data);
+ X11_ReconcileKeyboardState(_this, data);
#ifdef X_HAVE_UTF8_STRING
if (data->ic) {
X11_XSetICFocus(data->ic);
@@ -483,77 +554,6 @@ ProcessHitTest(_THIS, const SDL_WindowData *data, const XEvent *xev)
return SDL_FALSE;
}
-static unsigned
-GetNumLockModifierMask(_THIS)
-{
- SDL_VideoData *viddata = (SDL_VideoData *) _this->driverdata;
- Display *display = viddata->display;
- unsigned num_mask = 0;
- int i, j;
- XModifierKeymap *xmods;
- unsigned n;
-
- xmods = X11_XGetModifierMapping(display);
- n = xmods->max_keypermod;
- for(i = 3; i < 8; i++) {
- for(j = 0; j < n; j++) {
- KeyCode kc = xmods->modifiermap[i * n + j];
- if (viddata->key_layout[kc] == SDL_SCANCODE_NUMLOCKCLEAR) {
- num_mask = 1 << i;
- break;
- }
- }
- }
- X11_XFreeModifiermap(xmods);
-
- return num_mask;
-}
-
-static void
-ReconcileKeyboardState(_THIS, const SDL_WindowData *data)
-{
- SDL_VideoData *viddata = (SDL_VideoData *) _this->driverdata;
- Display *display = viddata->display;
- char keys[32];
- int keycode;
- Window junk_window;
- int x, y;
- unsigned int mask;
-
- X11_XQueryKeymap(display, keys);
-
- for (keycode = 0; keycode < 256; ++keycode) {
- if (keys[keycode / 8] & (1 << (keycode % 8))) {
- SDL_SendKeyboardKey(SDL_PRESSED, viddata->key_layout[keycode]);
- } else {
- SDL_SendKeyboardKey(SDL_RELEASED, viddata->key_layout[keycode]);
- }
- }
-
- /* Get the keyboard modifier state */
- if (X11_XQueryPointer(display, DefaultRootWindow(display), &junk_window, &junk_window, &x, &y, &x, &y, &mask)) {
- unsigned num_mask = GetNumLockModifierMask(_this);
- const Uint8 *keystate = SDL_GetKeyboardState(NULL);
- Uint8 capslockState = keystate[SDL_SCANCODE_CAPSLOCK];
- Uint8 numlockState = keystate[SDL_SCANCODE_NUMLOCKCLEAR];
-
- /* Toggle key mod state if needed */
- if (!!(mask & LockMask) != !!(SDL_GetModState() & KMOD_CAPS)) {
- SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_CAPSLOCK);
- if (capslockState == SDL_RELEASED) {
- SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_CAPSLOCK);
- }
- }
-
- if (!!(mask & num_mask) != !!(SDL_GetModState() & KMOD_NUM)) {
- SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_NUMLOCKCLEAR);
- if (numlockState == SDL_RELEASED) {
- SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_NUMLOCKCLEAR);
- }
- }
- }
-}
-
static void
X11_DispatchEvent(_THIS)
{
@@ -737,7 +737,7 @@ X11_DispatchEvent(_THIS)
{
data->pending_focus = PENDING_FOCUS_NONE;
data->pending_focus_time = 0;
- X11_DispatchFocusOut(data);
+ X11_DispatchFocusOut(_this, data);
}
else
{
diff --git a/test/checkkeys.c b/test/checkkeys.c
index b4672a1..f7a4e3c 100644
--- a/test/checkkeys.c
+++ b/test/checkkeys.c
@@ -89,6 +89,20 @@ print_modifiers(char **text, size_t *maxlen)
}
static void
+PrintModifierState()
+{
+ char message[512];
+ char *spot;
+ size_t left;
+
+ spot = message;
+ left = sizeof(message);
+
+ print_modifiers(&spot, &left);
+ SDL_Log("Initial state:%s\n", message);
+}
+
+static void
PrintKey(SDL_Keysym * sym, SDL_bool pressed, SDL_bool repeat)
{
char message[512];
@@ -200,6 +214,10 @@ main(int argc, char *argv[])
SDL_StartTextInput();
+ /* Print initial modifier state */
+ SDL_PumpEvents();
+ PrintModifierState();
+
/* Watch keystrokes */
done = 0;