Skip to content

Commit

Permalink
Removed raw key events
Browse files Browse the repository at this point in the history
They weren't adding any value over the existing keyboard events
  • Loading branch information
slouken committed Dec 21, 2024
1 parent 5d05caa commit c1c39be
Show file tree
Hide file tree
Showing 12 changed files with 4 additions and 78 deletions.
19 changes: 0 additions & 19 deletions include/SDL3/SDL_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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.*)
*
Expand Down Expand Up @@ -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 */
Expand Down
2 changes: 0 additions & 2 deletions src/core/linux/SDL_evdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 0 additions & 4 deletions src/core/openbsd/SDL_wscons_kbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions src/events/SDL_categories.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
13 changes: 0 additions & 13 deletions src/events/SDL_events.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 0 additions & 16 deletions src/events/SDL_keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 0 additions & 3 deletions src/events/SDL_keyboard_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
1 change: 0 additions & 1 deletion src/video/uikit/SDL_uikitevents.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down
2 changes: 0 additions & 2 deletions src/video/wayland/SDL_waylandevents.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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) {
Expand Down
10 changes: 4 additions & 6 deletions src/video/windows/SDL_windowsevents.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
5 changes: 0 additions & 5 deletions src/video/windows/SDL_windowsgameinput.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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;
}
Expand Down
5 changes: 0 additions & 5 deletions src/video/x11/SDL_x11events.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit c1c39be

Please sign in to comment.