Added KMOD_SCROLL to track the scroll lock state Fixes https://github.com/libsdl-org/SDL/issues/4566
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
diff --git a/include/SDL_keycode.h b/include/SDL_keycode.h
index 4fb0d39..f94fcec 100644
--- a/include/SDL_keycode.h
+++ b/include/SDL_keycode.h
@@ -338,7 +338,7 @@ typedef enum
KMOD_NUM = 0x1000,
KMOD_CAPS = 0x2000,
KMOD_MODE = 0x4000,
- KMOD_RESERVED = 0x8000,
+ KMOD_SCROLL = 0x8000,
KMOD_CTRL = KMOD_LCTRL | KMOD_RCTRL,
KMOD_SHIFT = KMOD_LSHIFT | KMOD_RSHIFT,
diff --git a/src/events/SDL_keyboard.c b/src/events/SDL_keyboard.c
index 18089af..e8f0db4 100644
--- a/src/events/SDL_keyboard.c
+++ b/src/events/SDL_keyboard.c
@@ -767,6 +767,9 @@ SDL_SendKeyboardKeyInternal(Uint8 source, Uint8 state, SDL_Scancode scancode)
case SDLK_CAPSLOCK:
keyboard->modstate ^= KMOD_CAPS;
break;
+ case SDLK_SCROLLLOCK:
+ keyboard->modstate ^= KMOD_SCROLL;
+ break;
default:
keyboard->modstate |= modifier;
break;
diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c
index 555f9b2..3fbd5a8 100644
--- a/src/video/windows/SDL_windowsevents.c
+++ b/src/video/windows/SDL_windowsevents.c
@@ -627,6 +627,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
SDL_ToggleModState(KMOD_CAPS, (GetKeyState(VK_CAPITAL) & 0x0001) != 0);
SDL_ToggleModState(KMOD_NUM, (GetKeyState(VK_NUMLOCK) & 0x0001) != 0);
+ SDL_ToggleModState(KMOD_SCROLL, (GetKeyState(VK_SCROLL) & 0x0001) != 0);
} else {
RECT rect;
diff --git a/src/video/windows/SDL_windowskeyboard.c b/src/video/windows/SDL_windowskeyboard.c
index 157ec2a..52d2bbe 100644
--- a/src/video/windows/SDL_windowskeyboard.c
+++ b/src/video/windows/SDL_windowskeyboard.c
@@ -106,6 +106,7 @@ WIN_InitKeyboard(_THIS)
/* Are system caps/num/scroll lock active? Set our state to match. */
SDL_ToggleModState(KMOD_CAPS, (GetKeyState(VK_CAPITAL) & 0x0001) != 0);
SDL_ToggleModState(KMOD_NUM, (GetKeyState(VK_NUMLOCK) & 0x0001) != 0);
+ SDL_ToggleModState(KMOD_SCROLL, (GetKeyState(VK_SCROLL) & 0x0001) != 0);
}
void
diff --git a/src/video/x11/SDL_x11events.c b/src/video/x11/SDL_x11events.c
index d3b02f5..f911313 100644
--- a/src/video/x11/SDL_x11events.c
+++ b/src/video/x11/SDL_x11events.c
@@ -353,6 +353,32 @@ X11_GetNumLockModifierMask(_THIS)
return num_mask;
}
+static unsigned
+X11_GetScrollLockModifierMask(_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_SCROLLLOCK) {
+ num_mask = 1 << i;
+ break;
+ }
+ }
+ }
+ X11_XFreeModifiermap(xmods);
+
+ return num_mask;
+}
+
static void
X11_ReconcileKeyboardState(_THIS)
{
@@ -371,6 +397,7 @@ X11_ReconcileKeyboardState(_THIS)
if (X11_XQueryPointer(display, DefaultRootWindow(display), &junk_window, &junk_window, &x, &y, &x, &y, &mask)) {
SDL_ToggleModState(KMOD_CAPS, (mask & LockMask) != 0);
SDL_ToggleModState(KMOD_NUM, (mask & X11_GetNumLockModifierMask(_this)) != 0);
+ SDL_ToggleModState(KMOD_SCROLL, (mask & X11_GetScrollLockModifierMask(_this)) != 0);
}
keyboardState = SDL_GetKeyboardState(0);
diff --git a/test/checkkeys.c b/test/checkkeys.c
index 0bfb2cb..cdf982c 100644
--- a/test/checkkeys.c
+++ b/test/checkkeys.c
@@ -86,6 +86,8 @@ print_modifiers(char **text, size_t *maxlen)
print_string(text, maxlen, " CAPS");
if (mod & KMOD_MODE)
print_string(text, maxlen, " MODE");
+ if (mod & KMOD_SCROLL)
+ print_string(text, maxlen, " SCROLL");
}
static void
diff --git a/test/checkkeysthreads.c b/test/checkkeysthreads.c
index 4019a80..fd812e2 100644
--- a/test/checkkeysthreads.c
+++ b/test/checkkeysthreads.c
@@ -86,6 +86,8 @@ print_modifiers(char **text, size_t *maxlen)
print_string(text, maxlen, " CAPS");
if (mod & KMOD_MODE)
print_string(text, maxlen, " MODE");
+ if (mod & KMOD_SCROLL)
+ print_string(text, maxlen, " SCROLL");
}
static void
diff --git a/test/testautomation_keyboard.c b/test/testautomation_keyboard.c
index dc05ff1..f415da4 100644
--- a/test/testautomation_keyboard.c
+++ b/test/testautomation_keyboard.c
@@ -305,7 +305,7 @@ keyboard_getSetModState(void *arg)
KMOD_NUM |
KMOD_CAPS |
KMOD_MODE |
- KMOD_RESERVED;
+ KMOD_SCROLL;
/* Get state, cache for later reset */
result = SDL_GetModState();