From d07bb0e679cd48bea8e98f139cf5c7eb0dbab3a7 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sat, 21 Dec 2024 04:46:37 -0800
Subject: [PATCH] Removed raw key events
They weren't adding any value over the existing keyboard events
---
include/SDL3/SDL_events.h | 19 -------------------
src/core/linux/SDL_evdev.c | 2 --
src/core/openbsd/SDL_wscons_kbd.c | 4 ----
src/events/SDL_categories.c | 2 --
src/events/SDL_events.c | 13 -------------
src/events/SDL_keyboard.c | 16 ----------------
src/events/SDL_keyboard_c.h | 3 ---
src/video/uikit/SDL_uikitevents.m | 1 -
src/video/wayland/SDL_waylandevents.c | 2 --
src/video/windows/SDL_windowsevents.c | 10 ++++------
src/video/windows/SDL_windowsgameinput.c | 5 -----
src/video/x11/SDL_x11events.c | 5 -----
12 files changed, 4 insertions(+), 78 deletions(-)
diff --git a/include/SDL3/SDL_events.h b/include/SDL3/SDL_events.h
index 27da4b4eaf9c7..3e8c052836d94 100644
--- a/include/SDL3/SDL_events.h
+++ b/include/SDL3/SDL_events.h
@@ -174,8 +174,6 @@ typedef enum SDL_EventType
SDL_EVENT_KEYBOARD_ADDED, /**< A new keyboard has been inserted into the system */
SDL_EVENT_KEYBOARD_REMOVED, /**< A keyboard has been removed */
SDL_EVENT_TEXT_EDITING_CANDIDATES, /**< Keyboard text editing candidates */
- SDL_EVENT_RAW_KEY_DOWN, /**< Key pressed (raw key press) */
- SDL_EVENT_RAW_KEY_UP, /**< Key released (raw key release) */
/* Mouse events */
SDL_EVENT_MOUSE_MOTION = 0x400, /**< Mouse moved */
@@ -368,22 +366,6 @@ typedef struct SDL_KeyboardEvent
bool repeat; /**< true if this is a key repeat */
} SDL_KeyboardEvent;
-/**
- * Raw keyboard button event structure (event.raw_key.*)
- *
- * \since This struct is available since SDL 3.1.8.
- */
-typedef struct SDL_RawKeyboardEvent
-{
- SDL_EventType type; /**< SDL_EVENT_RAW_KEY_DOWN or SDL_EVENT_RAW_KEY_UP */
- Uint32 reserved;
- Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
- SDL_KeyboardID which; /**< The keyboard instance id */
- SDL_Scancode scancode; /**< SDL physical key code */
- Uint16 raw; /**< The platform dependent scancode for this event */
- bool down; /**< true if the key is pressed */
-} SDL_RawKeyboardEvent;
-
/**
* Keyboard text editing event structure (event.edit.*)
*
@@ -1061,7 +1043,6 @@ typedef union SDL_Event
SDL_WindowEvent window; /**< Window event data */
SDL_KeyboardDeviceEvent kdevice; /**< Keyboard device change event data */
SDL_KeyboardEvent key; /**< Keyboard event data */
- SDL_RawKeyboardEvent raw_key; /**< Raw keyboard event data */
SDL_TextEditingEvent edit; /**< Text editing event data */
SDL_TextEditingCandidatesEvent edit_candidates; /**< Text editing candidates event data */
SDL_TextInputEvent text; /**< Text input event data */
diff --git a/src/core/linux/SDL_evdev.c b/src/core/linux/SDL_evdev.c
index fce82ebc3cd70..425300aa87ee9 100644
--- a/src/core/linux/SDL_evdev.c
+++ b/src/core/linux/SDL_evdev.c
@@ -373,10 +373,8 @@ void SDL_EVDEV_Poll(void)
Uint64 timestamp = SDL_EVDEV_GetEventTimestamp(event);
scancode = SDL_EVDEV_translate_keycode(event->code);
if (event->value == 0) {
- SDL_SendRawKeyboardKey(timestamp, (SDL_KeyboardID)item->fd, event->code, scancode, false);
SDL_SendKeyboardKey(timestamp, (SDL_KeyboardID)item->fd, event->code, scancode, false);
} else if (event->value == 1 || event->value == 2 /* key repeated */) {
- SDL_SendRawKeyboardKey(timestamp, (SDL_KeyboardID)item->fd, event->code, scancode, true);
SDL_SendKeyboardKey(timestamp, (SDL_KeyboardID)item->fd, event->code, scancode, true);
}
SDL_EVDEV_kbd_keycode(_this->kbd, event->code, event->value);
diff --git a/src/core/openbsd/SDL_wscons_kbd.c b/src/core/openbsd/SDL_wscons_kbd.c
index b2ce943d21320..09e41ed9cfd0b 100644
--- a/src/core/openbsd/SDL_wscons_kbd.c
+++ b/src/core/openbsd/SDL_wscons_kbd.c
@@ -573,12 +573,10 @@ static void Translate_to_keycode(SDL_WSCONS_input_data *input, int type, keysym_
}
for (i = 0; i < SDL_arraysize(conversion_table); i++) {
if (conversion_table[i].sourcekey == group[0]) {
- SDL_SendRawKeyboardKey(timestamp, input->keyboardID, group[0], conversion_table[i].targetKey, (type == WSCONS_EVENT_KEY_DOWN));
SDL_SendKeyboardKey(timestamp, input->keyboardID, group[0], conversion_table[i].targetKey, (type == WSCONS_EVENT_KEY_DOWN));
return;
}
}
- SDL_SendRawKeyboardKey(timestamp, input->keyboardID, group[0], SDL_SCANCODE_UNKNOWN, (type == WSCONS_EVENT_KEY_DOWN));
SDL_SendKeyboardKey(timestamp, input->keyboardID, group[0], SDL_SCANCODE_UNKNOWN, (type == WSCONS_EVENT_KEY_DOWN));
}
@@ -820,7 +818,6 @@ static void updateKeyboard(SDL_WSCONS_input_data *input)
} break;
case WSCONS_EVENT_ALL_KEYS_UP:
for (i = 0; i < SDL_SCANCODE_COUNT; i++) {
- SDL_SendRawKeyboardKey(timestamp, input->keyboardID, 0, (SDL_Scancode)i, false);
SDL_SendKeyboardKey(timestamp, input->keyboardID, 0, (SDL_Scancode)i, false);
}
break;
@@ -829,7 +826,6 @@ static void updateKeyboard(SDL_WSCONS_input_data *input)
}
if (input->type == WSKBD_TYPE_USB && events[i].value <= 0xE7) {
- SDL_SendRawKeyboardKey(timestamp, input->keyboardID, 0, (SDL_Scancode)events[i].value, (type == WSCONS_EVENT_KEY_DOWN));
SDL_SendKeyboardKey(timestamp, input->keyboardID, 0, (SDL_Scancode)events[i].value, (type == WSCONS_EVENT_KEY_DOWN));
} else {
Translate_to_keycode(input, type, events[i].value, timestamp);
diff --git a/src/events/SDL_categories.c b/src/events/SDL_categories.c
index 283c5e0680e9b..11e56d11058f5 100644
--- a/src/events/SDL_categories.c
+++ b/src/events/SDL_categories.c
@@ -62,8 +62,6 @@ SDL_EventCategory SDL_GetEventCategory(Uint32 type)
case SDL_EVENT_KEY_DOWN:
case SDL_EVENT_KEY_UP:
- case SDL_EVENT_RAW_KEY_DOWN:
- case SDL_EVENT_RAW_KEY_UP:
return SDL_EVENTCATEGORY_KEY;
case SDL_EVENT_TEXT_EDITING:
diff --git a/src/events/SDL_events.c b/src/events/SDL_events.c
index 33d7999e3255c..f7e16b1d2231d 100644
--- a/src/events/SDL_events.c
+++ b/src/events/SDL_events.c
@@ -535,19 +535,6 @@ static void SDL_LogEvent(const SDL_Event *event)
break;
#undef PRINT_KEY_EVENT
-#define PRINT_RAW_KEY_EVENT(event) \
- (void)SDL_snprintf(details, sizeof(details), " (timestamp=%u which=%u state=%s scancode=%u)", \
- (uint)event->raw_key.timestamp, (uint)event->raw_key.which, \
- event->raw_key.down ? "pressed" : "released", \
- (uint)event->raw_key.scancode);
- SDL_EVENT_CASE(SDL_EVENT_RAW_KEY_DOWN)
- PRINT_RAW_KEY_EVENT(event);
- break;
- SDL_EVENT_CASE(SDL_EVENT_RAW_KEY_UP)
- PRINT_RAW_KEY_EVENT(event);
- break;
-#undef PRINT_RAW_KEY_EVENT
-
SDL_EVENT_CASE(SDL_EVENT_TEXT_EDITING)
(void)SDL_snprintf(details, sizeof(details), " (timestamp=%u windowid=%u text='%s' start=%d length=%d)",
(uint)event->edit.timestamp, (uint)event->edit.windowID,
diff --git a/src/events/SDL_keyboard.c b/src/events/SDL_keyboard.c
index ea2c9e6fdeb4f..3a96d5ab21af4 100644
--- a/src/events/SDL_keyboard.c
+++ b/src/events/SDL_keyboard.c
@@ -690,22 +690,6 @@ bool SDL_SendKeyboardKeyAutoRelease(Uint64 timestamp, SDL_Scancode scancode)
return SDL_SendKeyboardKeyInternal(timestamp, KEYBOARD_AUTORELEASE, SDL_GLOBAL_KEYBOARD_ID, 0, scancode, true);
}
-void SDL_SendRawKeyboardKey(Uint64 timestamp, SDL_KeyboardID keyboardID, int rawcode, SDL_Scancode scancode, bool down)
-{
- const SDL_EventType type = down ? SDL_EVENT_RAW_KEY_DOWN : SDL_EVENT_RAW_KEY_UP;
-
- if (SDL_EventEnabled(type)) {
- SDL_Event event;
- event.type = type;
- event.common.timestamp = timestamp;
- event.raw_key.which = keyboardID;
- event.raw_key.scancode = scancode;
- event.raw_key.raw = rawcode;
- event.raw_key.down = down;
- SDL_PushEvent(&event);
- }
-}
-
void SDL_ReleaseAutoReleaseKeys(void)
{
SDL_Keyboard *keyboard = &SDL_keyboard;
diff --git a/src/events/SDL_keyboard_c.h b/src/events/SDL_keyboard_c.h
index 5bfc825fb845e..4023822facbb1 100644
--- a/src/events/SDL_keyboard_c.h
+++ b/src/events/SDL_keyboard_c.h
@@ -63,9 +63,6 @@ extern bool SDL_SendKeyboardKeyAutoRelease(Uint64 timestamp, SDL_Scancode scanco
Most platforms should prefer to optionally call SDL_SetKeymap and then use SDL_SendKeyboardKey. */
extern bool SDL_SendKeyboardKeyAndKeycode(Uint64 timestamp, SDL_KeyboardID keyboardID, int rawcode, SDL_Scancode scancode, SDL_Keycode keycode, bool down);
-// Send a raw keyboard key event
-extern void SDL_SendRawKeyboardKey(Uint64 timestamp, SDL_KeyboardID keyboardID, int rawcode, SDL_Scancode scancode, bool down);
-
// Release all the autorelease keys
extern void SDL_ReleaseAutoReleaseKeys(void);
diff --git a/src/video/uikit/SDL_uikitevents.m b/src/video/uikit/SDL_uikitevents.m
index 5d6252e1d77db..03ead1a1b220c 100644
--- a/src/video/uikit/SDL_uikitevents.m
+++ b/src/video/uikit/SDL_uikitevents.m
@@ -188,7 +188,6 @@ static void OnGCKeyboardConnected(GCKeyboard *keyboard) API_AVAILABLE(macos(11.0
keyboard.keyboardInput.keyChangedHandler = ^(GCKeyboardInput *kbrd, GCControllerButtonInput *key, GCKeyCode keyCode, BOOL pressed) {
Uint64 timestamp = SDL_GetTicksNS();
- SDL_SendRawKeyboardKey(timestamp, keyboardID, 0, (SDL_Scancode)keyCode, pressed);
SDL_SendKeyboardKey(timestamp, keyboardID, 0, (SDL_Scancode)keyCode, pressed);
};
diff --git a/src/video/wayland/SDL_waylandevents.c b/src/video/wayland/SDL_waylandevents.c
index 6a410f4c8ba7c..a32bdfe919ba5 100644
--- a/src/video/wayland/SDL_waylandevents.c
+++ b/src/video/wayland/SDL_waylandevents.c
@@ -1732,7 +1732,6 @@ static void keyboard_handle_enter(void *data, struct wl_keyboard *keyboard,
case SDLK_RGUI:
case SDLK_MODE:
Wayland_HandleModifierKeys(input, scancode, true);
- SDL_SendRawKeyboardKey(timestamp, input->keyboard_id, *key, scancode, true);
SDL_SendKeyboardKeyIgnoreModifiers(timestamp, input->keyboard_id, *key, scancode, true);
break;
default:
@@ -1870,7 +1869,6 @@ static void keyboard_handle_key(void *data, struct wl_keyboard *keyboard,
scancode = Wayland_get_scancode_from_key(input, key + 8);
Wayland_HandleModifierKeys(input, scancode, state == WL_KEYBOARD_KEY_STATE_PRESSED);
Uint64 timestamp = Wayland_GetKeyboardTimestamp(input, time);
- SDL_SendRawKeyboardKey(timestamp, input->keyboard_id, key, scancode, (state == WL_KEYBOARD_KEY_STATE_PRESSED));
SDL_SendKeyboardKeyIgnoreModifiers(timestamp, input->keyboard_id, key, scancode, (state == WL_KEYBOARD_KEY_STATE_PRESSED));
if (state == WL_KEYBOARD_KEY_STATE_PRESSED) {
diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c
index ebe987f05a3bf..8004f952a6da5 100644
--- a/src/video/windows/SDL_windowsevents.c
+++ b/src/video/windows/SDL_windowsevents.c
@@ -721,6 +721,10 @@ static void WIN_HandleRawKeyboardInput(Uint64 timestamp, SDL_VideoData *data, HA
{
SDL_KeyboardID keyboardID = (SDL_KeyboardID)(uintptr_t)hDevice;
+ if (!data->raw_keyboard_enabled) {
+ return;
+ }
+
if (rawkeyboard->Flags & RI_KEY_E1) {
// First key in a Ctrl+{key} sequence
data->pending_E1_key_sequence = true;
@@ -764,12 +768,6 @@ static void WIN_HandleRawKeyboardInput(Uint64 timestamp, SDL_VideoData *data, HA
code = windows_scancode_table[index];
}
- SDL_SendRawKeyboardKey(timestamp, keyboardID, rawcode, code, down);
-
- if (!data->raw_keyboard_enabled) {
- return;
- }
-
if (down) {
SDL_Window *focus = SDL_GetKeyboardFocus();
if (!focus || focus->text_input_active) {
diff --git a/src/video/windows/SDL_windowsgameinput.c b/src/video/windows/SDL_windowsgameinput.c
index 11dfc2e5a1f09..431951d7396c5 100644
--- a/src/video/windows/SDL_windowsgameinput.c
+++ b/src/video/windows/SDL_windowsgameinput.c
@@ -383,14 +383,12 @@ static void GAMEINPUT_InitialKeyboardReading(WIN_GameInputData *data, SDL_Window
const bool *keyboard_state = SDL_GetKeyboardState(&num_scancodes);
for (int i = 0; i < num_scancodes; ++i) {
if (keyboard_state[i] && !KeysHaveScancode(keys, num_keys, (SDL_Scancode)i)) {
- SDL_SendRawKeyboardKey(timestamp, keyboardID, keys[i].scanCode, (SDL_Scancode)i, false);
SDL_SendKeyboardKey(timestamp, keyboardID, keys[i].scanCode, (SDL_Scancode)i, false);
}
}
// Go through and send key down events for any key that's held down
for (uint32_t i = 0; i < num_keys; ++i) {
- SDL_SendRawKeyboardKey(timestamp, keyboardID, keys[i].scanCode, GetScancodeFromKeyState(&keys[i]), true);
SDL_SendKeyboardKey(timestamp, keyboardID, keys[i].scanCode, GetScancodeFromKeyState(&keys[i]), true);
}
}
@@ -436,18 +434,15 @@ static void GAMEINPUT_HandleKeyboardDelta(WIN_GameInputData *data, SDL_Window *w
++index_keys;
} else {
// This key was released
- SDL_SendRawKeyboardKey(timestamp, keyboardID, last[index_last].scanCode, GetScancodeFromKeyState(&last[index_last]), false);
SDL_SendKeyboardKey(timestamp, keyboardID, last[index_last].scanCode, GetScancodeFromKeyState(&last[index_last]), false);
++index_last;
}
} else if (index_last < num_last) {
// This key was released
- SDL_SendRawKeyboardKey(timestamp, keyboardID, last[index_last].scanCode, GetScancodeFromKeyState(&last[index_last]), false);
SDL_SendKeyboardKey(timestamp, keyboardID, last[index_last].scanCode, GetScancodeFromKeyState(&last[index_last]), false);
++index_last;
} else {
// This key was pressed
- SDL_SendRawKeyboardKey(timestamp, keyboardID, keys[index_keys].scanCode, GetScancodeFromKeyState(&keys[index_keys]), true);
SDL_SendKeyboardKey(timestamp, keyboardID, keys[index_keys].scanCode, GetScancodeFromKeyState(&keys[index_keys]), true);
++index_keys;
}
diff --git a/src/video/x11/SDL_x11events.c b/src/video/x11/SDL_x11events.c
index 8ce3005f19858..5f60d993abe80 100644
--- a/src/video/x11/SDL_x11events.c
+++ b/src/video/x11/SDL_x11events.c
@@ -827,11 +827,6 @@ void X11_HandleKeyEvent(SDL_VideoDevice *_this, SDL_WindowData *windowdata, SDL_
}
#endif // DEBUG SCANCODES
- if (keyboardID != SDL_GLOBAL_KEYBOARD_ID) {
- const bool down = (xevent->type == KeyPress);
- SDL_SendRawKeyboardKey(timestamp, keyboardID, keycode, videodata->key_layout[keycode], down);
- }
-
text[0] = '\0';
if (SDL_TextInputActive(windowdata->window)) {