From 6fc6e3dc7eb55da70281f945bc11ee382c24e245 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Mon, 9 Sep 2024 09:18:02 -0700
Subject: [PATCH] Use SDL_bool where appropriate in SDL events
This involved changing button state from Uint8 to SDL_bool, and made SDL_PRESSED and SDL_RELEASED unnecessary.
Fixes https://github.com/libsdl-org/SDL/issues/10069
---
build-scripts/SDL_migration.cocci | 8 +
docs/README-migration.md | 6 +
include/SDL3/SDL_events.h | 37 +--
include/SDL3/SDL_gamepad.h | 19 +-
include/SDL3/SDL_joystick.h | 12 +-
include/SDL3/SDL_keyboard.h | 6 +-
src/audio/SDL_audio.c | 2 +-
src/core/haiku/SDL_BApp.h | 18 +-
src/core/linux/SDL_evdev.c | 10 +-
src/core/linux/SDL_fcitx.c | 4 +-
src/core/linux/SDL_fcitx.h | 2 +-
src/core/linux/SDL_ibus.c | 4 +-
src/core/linux/SDL_ibus.h | 2 +-
src/core/linux/SDL_ime.c | 6 +-
src/core/linux/SDL_ime.h | 2 +-
src/core/openbsd/SDL_wscons_kbd.c | 12 +-
src/core/openbsd/SDL_wscons_mouse.c | 12 +-
src/dynapi/SDL_dynapi_procs.h | 12 +-
src/events/SDL_events.c | 12 +-
src/events/SDL_keyboard.c | 60 +++--
src/events/SDL_keyboard_c.h | 6 +-
src/events/SDL_mouse.c | 38 ++--
src/events/SDL_mouse_c.h | 4 +-
src/events/SDL_pen.c | 26 +--
src/events/SDL_pen_c.h | 4 +-
src/events/SDL_touch.c | 4 +-
src/joystick/SDL_gamepad.c | 63 +++---
src/joystick/SDL_joystick.c | 59 +++--
src/joystick/SDL_joystick_c.h | 4 +-
src/joystick/SDL_sysjoystick.h | 4 +-
src/joystick/android/SDL_sysjoystick.c | 20 +-
src/joystick/apple/SDL_mfijoystick.m | 22 +-
src/joystick/bsd/SDL_bsdjoystick.c | 6 +-
src/joystick/darwin/SDL_iokitjoystick.c | 5 +-
src/joystick/emscripten/SDL_sysjoystick.c | 6 +-
src/joystick/gdk/SDL_gameinputjoystick.c | 14 +-
src/joystick/haiku/SDL_haikujoystick.cc | 3 +-
src/joystick/hidapi/SDL_hidapi_gamecube.c | 4 +-
src/joystick/hidapi/SDL_hidapi_luna.c | 48 ++--
src/joystick/hidapi/SDL_hidapi_ps3.c | 106 ++++-----
src/joystick/hidapi/SDL_hidapi_ps4.c | 34 +--
src/joystick/hidapi/SDL_hidapi_ps5.c | 78 +++----
src/joystick/hidapi/SDL_hidapi_shield.c | 60 ++---
src/joystick/hidapi/SDL_hidapi_stadia.c | 26 +--
src/joystick/hidapi/SDL_hidapi_steam.c | 24 +-
src/joystick/hidapi/SDL_hidapi_steamdeck.c | 32 +--
src/joystick/hidapi/SDL_hidapi_switch.c | 226 +++++++++----------
src/joystick/hidapi/SDL_hidapi_wii.c | 26 +--
src/joystick/hidapi/SDL_hidapi_xbox360.c | 22 +-
src/joystick/hidapi/SDL_hidapi_xbox360w.c | 22 +-
src/joystick/hidapi/SDL_hidapi_xboxone.c | 106 ++++-----
src/joystick/linux/SDL_sysjoystick.c | 12 +-
src/joystick/n3ds/SDL_sysjoystick.c | 4 +-
src/joystick/ps2/SDL_sysjoystick.c | 2 +-
src/joystick/psp/SDL_sysjoystick.c | 4 +-
src/joystick/virtual/SDL_virtualjoystick.c | 14 +-
src/joystick/virtual/SDL_virtualjoystick_c.h | 6 +-
src/joystick/vita/SDL_sysjoystick.c | 5 +-
src/joystick/windows/SDL_dinputjoystick.c | 4 +-
src/joystick/windows/SDL_rawinputjoystick.c | 22 +-
src/joystick/windows/SDL_xinputjoystick.c | 3 +-
src/video/android/SDL_androidkeyboard.c | 4 +-
src/video/android/SDL_androidmouse.c | 4 +-
src/video/cocoa/SDL_cocoakeyboard.m | 10 +-
src/video/cocoa/SDL_cocoapen.m | 6 +-
src/video/cocoa/SDL_cocoawindow.m | 14 +-
src/video/emscripten/SDL_emscriptenevents.c | 29 +--
src/video/haiku/SDL_BWin.h | 26 +--
src/video/ngage/SDL_ngageevents.cpp | 4 +-
src/video/psp/SDL_pspevents.c | 10 +-
src/video/qnx/SDL_qnxkeyboard.c | 4 +-
src/video/riscos/SDL_riscosevents.c | 7 +-
src/video/uikit/SDL_uikitevents.m | 4 +-
src/video/uikit/SDL_uikitview.m | 10 +-
src/video/uikit/SDL_uikitviewcontroller.m | 4 +-
src/video/vita/SDL_vitakeyboard.c | 58 ++---
src/video/vita/SDL_vitamouse.c | 12 +-
src/video/wayland/SDL_waylandevents.c | 38 ++--
src/video/windows/SDL_windowsevents.c | 93 ++++----
src/video/windows/SDL_windowsgameinput.c | 18 +-
src/video/x11/SDL_x11events.c | 22 +-
src/video/x11/SDL_x11xinput2.c | 8 +-
test/checkkeys.c | 6 +-
test/gamepadutils.c | 20 +-
test/testautomation_joystick.c | 32 +--
test/testautomation_keyboard.c | 2 +-
test/testcontroller.c | 18 +-
test/testmanymouse.c | 2 +-
test/testmouse.c | 2 +-
89 files changed, 935 insertions(+), 956 deletions(-)
diff --git a/build-scripts/SDL_migration.cocci b/build-scripts/SDL_migration.cocci
index 95f252f383910..f5b9554ba3076 100644
--- a/build-scripts/SDL_migration.cocci
+++ b/build-scripts/SDL_migration.cocci
@@ -3614,6 +3614,14 @@ typedef SDL_JoystickGUID, SDL_GUID;
- SDL_size_add_overflow
+ SDL_size_add_check_overflow
(...)
+@@
+@@
+- SDL_PRESSED
++ SDL_TRUE
+@@
+@@
+- SDL_RELEASED
++ SDL_FALSE
// This should be the last rule in the file, since it works on SDL3 functions and previous rules may have renamed old functions.
@ bool_return_type @
diff --git a/docs/README-migration.md b/docs/README-migration.md
index 4be0642b92c01..805a295dcaa9a 100644
--- a/docs/README-migration.md
+++ b/docs/README-migration.md
@@ -360,6 +360,8 @@ The following functions have been removed:
## SDL_events.h
+SDL_PRESSED and SDL_RELEASED have been removed. For the most part you can replace uses of these with SDL_TRUE and SDL_FALSE respectively. Events which had a field `state` to represent these values have had those fields changed to SDL_bool `down`, e.g. `event.key.state` is now `event.key.down`.
+
The timestamp member of the SDL_Event structure now represents nanoseconds, and is populated with SDL_GetTicksNS()
The timestamp_us member of the sensor events has been renamed sensor_timestamp and now represents nanoseconds. This value is filled in from the hardware, if available, and may not be synchronized with values returned from SDL_GetTicksNS().
@@ -596,6 +598,8 @@ SDL_bool SDL_IsJoystickNVIDIASHIELDController(Uint16 vendor_id, Uint16 product_i
The inputType and outputType fields of SDL_GamepadBinding have been renamed input_type and output_type.
+SDL_GetGamepadTouchpadFinger() takes a pointer to SDL_bool for the finger state instead of a pointer to Uint8.
+
The following enums have been renamed:
* SDL_GameControllerAxis => SDL_GamepadAxis
* SDL_GameControllerBindType => SDL_GamepadBindingType
@@ -1002,6 +1006,8 @@ The text input state hase been changed to be window-specific. SDL_StartTextInput
SDL_GetDefaultKeyFromScancode(), SDL_GetKeyFromScancode(), and SDL_GetScancodeFromKey() take an SDL_Keymod parameter and use that to provide the correct result based on keyboard modifier state.
+SDL_GetKeyboardState() returns a pointer to SDL_bool instead of Uint8.
+
The following functions have been renamed:
* SDL_IsScreenKeyboardShown() => SDL_ScreenKeyboardShown()
* SDL_IsTextInputActive() => SDL_TextInputActive()
diff --git a/include/SDL3/SDL_events.h b/include/SDL3/SDL_events.h
index 0ed78c4e2cc82..252b284ec7959 100644
--- a/include/SDL3/SDL_events.h
+++ b/include/SDL3/SDL_events.h
@@ -52,25 +52,6 @@ extern "C" {
/* General keyboard/mouse/pen state definitions */
-/**
- * A value that signifies a button is no longer pressed.
- *
- * \since This macro is available since SDL 3.0.0.
- *
- * \sa SDL_PRESSED
- */
-#define SDL_RELEASED 0
-
-/**
- * A value that signifies a button has been pressed down.
- *
- * \since This macro is available since SDL 3.0.0.
- *
- * \sa SDL_RELEASED
- */
-#define SDL_PRESSED 1
-
-
/**
* The types of events that can be delivered.
*
@@ -346,8 +327,8 @@ typedef struct SDL_KeyboardEvent
SDL_Keycode key; /**< SDL virtual key code */
SDL_Keymod mod; /**< current key modifiers */
Uint16 raw; /**< The platform dependent scancode for this event */
- Uint8 state; /**< SDL_PRESSED or SDL_RELEASED */
- Uint8 repeat; /**< Non-zero if this is a key repeat */
+ SDL_bool down; /**< SDL_TRUE if the key is pressed */
+ SDL_bool repeat; /**< SDL_TRUE if this is a key repeat */
} SDL_KeyboardEvent;
/**
@@ -455,7 +436,7 @@ typedef struct SDL_MouseButtonEvent
SDL_WindowID windowID; /**< The window with mouse focus, if any */
SDL_MouseID which; /**< The mouse instance id, SDL_TOUCH_MOUSEID */
Uint8 button; /**< The mouse button index */
- Uint8 state; /**< SDL_PRESSED or SDL_RELEASED */
+ SDL_bool down; /**< SDL_TRUE if the button is pressed */
Uint8 clicks; /**< 1 for single-click, 2 for double-click, etc. */
Uint8 padding;
float x; /**< X coordinate, relative to window */
@@ -554,7 +535,7 @@ typedef struct SDL_JoyButtonEvent
Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
SDL_JoystickID which; /**< The joystick instance id */
Uint8 button; /**< The joystick button index */
- Uint8 state; /**< SDL_PRESSED or SDL_RELEASED */
+ SDL_bool down; /**< SDL_TRUE if the button is pressed */
Uint8 padding1;
Uint8 padding2;
} SDL_JoyButtonEvent;
@@ -619,7 +600,7 @@ typedef struct SDL_GamepadButtonEvent
Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
SDL_JoystickID which; /**< The joystick instance id */
Uint8 button; /**< The gamepad button (SDL_GamepadButton) */
- Uint8 state; /**< SDL_PRESSED or SDL_RELEASED */
+ SDL_bool down; /**< SDL_TRUE if the button is pressed */
Uint8 padding1;
Uint8 padding2;
} SDL_GamepadButtonEvent;
@@ -683,7 +664,7 @@ typedef struct SDL_AudioDeviceEvent
Uint32 reserved;
Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
SDL_AudioDeviceID which; /**< SDL_AudioDeviceID for the device being added or removed or changing */
- Uint8 recording; /**< zero if a playback device, non-zero if a recording device. */
+ SDL_bool recording; /**< SDL_FALSE if a playback device, SDL_TRUE if a recording device. */
Uint8 padding1;
Uint8 padding2;
Uint8 padding3;
@@ -787,8 +768,8 @@ typedef struct SDL_PenTouchEvent
SDL_PenInputFlags pen_state; /**< Complete pen input state at time of event */
float x; /**< X position of pen on tablet */
float y; /**< Y position of pen on tablet */
- Uint8 eraser; /**< Non-zero if eraser end is used (not all pens support this). */
- Uint8 state; /**< SDL_PRESSED (pen is touching) or SDL_RELEASED (pen is lifted off) */
+ SDL_bool eraser; /**< SDL_TRUE if eraser end is used (not all pens support this). */
+ SDL_bool down; /**< SDL_TRUE if the pen is touching or SDL_FALSE if the pen is lifted off */
} SDL_PenTouchEvent;
/**
@@ -810,7 +791,7 @@ typedef struct SDL_PenButtonEvent
float x; /**< X position of pen on tablet */
float y; /**< Y position of pen on tablet */
Uint8 button; /**< The pen button index (first button is 1). */
- Uint8 state; /**< SDL_PRESSED or SDL_RELEASED */
+ SDL_bool down; /**< SDL_TRUE if the button is pressed */
} SDL_PenButtonEvent;
/**
diff --git a/include/SDL3/SDL_gamepad.h b/include/SDL3/SDL_gamepad.h
index bf0f7777b3b62..c1015a46dbb21 100644
--- a/include/SDL3/SDL_gamepad.h
+++ b/include/SDL3/SDL_gamepad.h
@@ -1184,15 +1184,14 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GamepadHasButton(SDL_Gamepad *gamepad,
*
* \param gamepad a gamepad.
* \param button a button index (one of the SDL_GamepadButton values).
- * \returns 1 for pressed state or 0 for not pressed state or failure; call
- * SDL_GetError() for more information.
+ * \returns SDL_TRUE if the button is pressed, SDL_FALSE otherwise.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_GamepadHasButton
* \sa SDL_GetGamepadAxis
*/
-extern SDL_DECLSPEC Uint8 SDLCALL SDL_GetGamepadButton(SDL_Gamepad *gamepad, SDL_GamepadButton button);
+extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetGamepadButton(SDL_Gamepad *gamepad, SDL_GamepadButton button);
/**
* Get the label of a button on a gamepad.
@@ -1253,12 +1252,12 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetNumGamepadTouchpadFingers(SDL_Gamepad *ga
* \param gamepad a gamepad.
* \param touchpad a touchpad.
* \param finger a finger.
- * \param state filled with state.
- * \param x filled with x position, normalized 0 to 1, with the origin in the
- * upper left.
- * \param y filled with y position, normalized 0 to 1, with the origin in the
- * upper left.
- * \param pressure filled with pressure value.
+ * \param down a pointer filled with SDL_TRUE if the finger is down, SDL_FALSE otherwise, may be NULL.
+ * \param x a pointer filled with the x position, normalized 0 to 1, with the origin in the
+ * upper left, may be NULL.
+ * \param y a pointer filled with the y position, normalized 0 to 1, with the origin in the
+ * upper left, may be NULL.
+ * \param pressure a pointer filled with pressure value, may be NULL.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
*
@@ -1266,7 +1265,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetNumGamepadTouchpadFingers(SDL_Gamepad *ga
*
* \sa SDL_GetNumGamepadTouchpadFingers
*/
-extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetGamepadTouchpadFinger(SDL_Gamepad *gamepad, int touchpad, int finger, Uint8 *state, float *x, float *y, float *pressure);
+extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetGamepadTouchpadFinger(SDL_Gamepad *gamepad, int touchpad, int finger, SDL_bool *down, float *x, float *y, float *pressure);
/**
* Return whether a gamepad has a particular sensor.
diff --git a/include/SDL3/SDL_joystick.h b/include/SDL3/SDL_joystick.h
index 8f68b24d1be7a..1b1b734a07d1d 100644
--- a/include/SDL3/SDL_joystick.h
+++ b/include/SDL3/SDL_joystick.h
@@ -558,13 +558,13 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetJoystickVirtualBall(SDL_Joystick *jo
*
* \param joystick the virtual joystick on which to set state.
* \param button the index of the button on the virtual joystick to update.
- * \param value the new value for the specified button.
+ * \param down SDL_TRUE if the button is pressed, SDL_FALSE otherwise.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
*
* \since This function is available since SDL 3.0.0.
*/
-extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetJoystickVirtualButton(SDL_Joystick *joystick, int button, Uint8 value);
+extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetJoystickVirtualButton(SDL_Joystick *joystick, int button, SDL_bool down);
/**
* Set the state of a hat on an opened virtual joystick.
@@ -598,7 +598,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetJoystickVirtualHat(SDL_Joystick *joy
* \param touchpad the index of the touchpad on the virtual joystick to
* update.
* \param finger the index of the finger on the touchpad to set.
- * \param state `SDL_PRESSED` if the finger is pressed, `SDL_RELEASED` if the
+ * \param down SDL_TRUE if the finger is pressed, SDL_FALSE if the
* finger is released.
* \param x the x coordinate of the finger on the touchpad, normalized 0 to 1,
* with the origin in the upper left.
@@ -610,7 +610,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetJoystickVirtualHat(SDL_Joystick *joy
*
* \since This function is available since SDL 3.0.0.
*/
-extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetJoystickVirtualTouchpad(SDL_Joystick *joystick, int touchpad, int finger, Uint8 state, float x, float y, float pressure);
+extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetJoystickVirtualTouchpad(SDL_Joystick *joystick, int touchpad, int finger, SDL_bool down, float x, float y, float pressure);
/**
* Send a sensor update for an opened virtual joystick.
@@ -1065,13 +1065,13 @@ extern SDL_DECLSPEC Uint8 SDLCALL SDL_GetJoystickHat(SDL_Joystick *joystick, int
* \param joystick an SDL_Joystick structure containing joystick information.
* \param button the button index to get the state from; indices start at
* index 0.
- * \returns 1 if the specified button is pressed, 0 otherwise.
+ * \returns SDL_TRUE if the button is pressed, SDL_FALSE otherwise.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_GetNumJoystickButtons
*/
-extern SDL_DECLSPEC Uint8 SDLCALL SDL_GetJoystickButton(SDL_Joystick *joystick, int button);
+extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetJoystickButton(SDL_Joystick *joystick, int button);
/**
* Start a rumble effect.
diff --git a/include/SDL3/SDL_keyboard.h b/include/SDL3/SDL_keyboard.h
index d48c9a14c7e22..a7d65d6cab163 100644
--- a/include/SDL3/SDL_keyboard.h
+++ b/include/SDL3/SDL_keyboard.h
@@ -119,8 +119,8 @@ extern SDL_DECLSPEC SDL_Window * SDLCALL SDL_GetKeyboardFocus(void);
* valid for the whole lifetime of the application and should not be freed by
* the caller.
*
- * A array element with a value of 1 means that the key is pressed and a value
- * of 0 means that it is not. Indexes into this array are obtained by using
+ * A array element with a value of SDL_TRUE means that the key is pressed and a value
+ * of SDL_FALSE means that it is not. Indexes into this array are obtained by using
* SDL_Scancode values.
*
* Use SDL_PumpEvents() to update the state array.
@@ -141,7 +141,7 @@ extern SDL_DECLSPEC SDL_Window * SDLCALL SDL_GetKeyboardFocus(void);
* \sa SDL_PumpEvents
* \sa SDL_ResetKeyboard
*/
-extern SDL_DECLSPEC const Uint8 * SDLCALL SDL_GetKeyboardState(int *numkeys);
+extern SDL_DECLSPEC const SDL_bool * SDLCALL SDL_GetKeyboardState(int *numkeys);
/**
* Clear the state of the keyboard.
diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c
index 92bb8e5ecd578..409e74fca0a7d 100644
--- a/src/audio/SDL_audio.c
+++ b/src/audio/SDL_audio.c
@@ -2474,7 +2474,7 @@ void SDL_UpdateAudio(void)
SDL_zero(event);
event.type = i->type;
event.adevice.which = (Uint32) i->devid;
- event.adevice.recording = (i->devid & (1<<0)) ? 0 : 1; // bit #0 of devid is set for playback devices and unset for recording.
+ event.adevice.recording = ((i->devid & (1<<0)) != 0); // bit #0 of devid is set for playback devices and unset for recording.
SDL_PushEvent(&event);
}
SDL_free(i);
diff --git a/src/core/haiku/SDL_BApp.h b/src/core/haiku/SDL_BApp.h
index 8b9275598e4a6..14b69055a6698 100644
--- a/src/core/haiku/SDL_BApp.h
+++ b/src/core/haiku/SDL_BApp.h
@@ -264,15 +264,16 @@ class SDL_BLooper : public BLooper
{
SDL_Window *win;
int32 winID;
- int32 button, state; // left/middle/right, pressed/released
+ int32 button;
+ bool down;
if (
!_GetWinID(msg, &winID) ||
msg->FindInt32("button-id", &button) != B_OK ||
- msg->FindInt32("button-state", &state) != B_OK) {
+ msg->FindBool("button-down", &down) != B_OK) {
return;
}
win = GetSDLWindow(winID);
- SDL_SendMouseButton(0, win, SDL_DEFAULT_MOUSE_ID, state, button);
+ SDL_SendMouseButton(0, win, SDL_DEFAULT_MOUSE_ID, button, down);
}
void _HandleMouseWheel(BMessage *msg)
@@ -294,18 +295,19 @@ class SDL_BLooper : public BLooper
{
SDL_Window *win;
int32 winID;
- int32 scancode, state; // scancode, pressed/released
+ int32 scancode;
+ bool down;
if (
!_GetWinID(msg, &winID) ||
- msg->FindInt32("key-state", &state) != B_OK ||
- msg->FindInt32("key-scancode", &scancode) != B_OK) {
+ msg->FindInt32("key-scancode", &scancode) != B_OK ||
+ msg->FindBool("key-down", &down) != B_OK) {
return;
}
- SDL_SendKeyboardKey(0, SDL_DEFAULT_KEYBOARD_ID, scancode, HAIKU_GetScancodeFromBeKey(scancode), state);
+ SDL_SendKeyboardKey(0, SDL_DEFAULT_KEYBOARD_ID, scancode, HAIKU_GetScancodeFromBeKey(scancode), down);
win = GetSDLWindow(winID);
- if (state == SDL_PRESSED && SDL_TextInputActive(win)) {
+ if (down && SDL_TextInputActive(win)) {
const int8 *keyUtf8;
ssize_t count;
if (msg->FindData("key-utf8", B_INT8_TYPE, (const void **)&keyUtf8, &count) == B_OK) {
diff --git a/src/core/linux/SDL_evdev.c b/src/core/linux/SDL_evdev.c
index 758377d4febd1..0419ca147dac9 100644
--- a/src/core/linux/SDL_evdev.c
+++ b/src/core/linux/SDL_evdev.c
@@ -347,11 +347,7 @@ void SDL_EVDEV_Poll(void)
case EV_KEY:
if (event->code >= BTN_MOUSE && event->code < BTN_MOUSE + SDL_arraysize(EVDEV_MouseButtons)) {
mouse_button = event->code - BTN_MOUSE;
- if (event->value == 0) {
- SDL_SendMouseButton(SDL_EVDEV_GetEventTimestamp(event), mouse->focus, (SDL_MouseID)item->fd, SDL_RELEASED, EVDEV_MouseButtons[mouse_button]);
- } else if (event->value == 1) {
- SDL_SendMouseButton(SDL_EVDEV_GetEventTimestamp(event), mouse->focus, (SDL_MouseID)item->fd, SDL_PRESSED, EVDEV_MouseButtons[mouse_button]);
- }
+ SDL_SendMouseButton(SDL_EVDEV_GetEventTimestamp(event), mouse->focus, (SDL_MouseID)item->fd, EVDEV_MouseButtons[mouse_button], (event->value != 0));
break;
}
@@ -373,9 +369,9 @@ void SDL_EVDEV_Poll(void)
// Probably keyboard
scancode = SDL_EVDEV_translate_keycode(event->code);
if (event->value == 0) {
- SDL_SendKeyboardKey(SDL_EVDEV_GetEventTimestamp(event), (SDL_KeyboardID)item->fd, event->code, scancode, SDL_RELEASED);
+ SDL_SendKeyboardKey(SDL_EVDEV_GetEventTimestamp(event), (SDL_KeyboardID)item->fd, event->code, scancode, false);
} else if (event->value == 1 || event->value == 2 /* key repeated */) {
- SDL_SendKeyboardKey(SDL_EVDEV_GetEventTimestamp(event), (SDL_KeyboardID)item->fd, event->code, scancode, SDL_PRESSED);
+ SDL_SendKeyboardKey(SDL_EVDEV_GetEventTimestamp(event), (SDL_KeyboardID)item->fd, event->code, scancode, true);
}
SDL_EVDEV_kbd_keycode(_this->kbd, event->code, event->value);
break;
diff --git a/src/core/linux/SDL_fcitx.c b/src/core/linux/SDL_fcitx.c
index 1ab49e38d01d7..72451e038840b 100644
--- a/src/core/linux/SDL_fcitx.c
+++ b/src/core/linux/SDL_fcitx.c
@@ -379,11 +379,11 @@ void SDL_Fcitx_Reset(void)
FcitxClientICCallMethod(&fcitx_client, "Reset");
}
-bool SDL_Fcitx_ProcessKeyEvent(Uint32 keysym, Uint32 keycode, Uint8 state)
+bool SDL_Fcitx_ProcessKeyEvent(Uint32 keysym, Uint32 keycode, bool down)
{
Uint32 mod_state = Fcitx_ModState();
Uint32 handled = false;
- Uint32 is_release = (state == SDL_RELEASED);
+ Uint32 is_release = !down;
Uint32 event_time = 0;
if (!fcitx_client.ic_path) {
diff --git a/src/core/linux/SDL_fcitx.h b/src/core/linux/SDL_fcitx.h
index 5788baaca6a96..59dc91353da6c 100644
--- a/src/core/linux/SDL_fcitx.h
+++ b/src/core/linux/SDL_fcitx.h
@@ -28,7 +28,7 @@ extern bool SDL_Fcitx_Init(void);
extern void SDL_Fcitx_Quit(void);
extern void SDL_Fcitx_SetFocus(bool focused);
extern void SDL_Fcitx_Reset(void);
-extern bool SDL_Fcitx_ProcessKeyEvent(Uint32 keysym, Uint32 keycode, Uint8 state);
+extern bool SDL_Fcitx_ProcessKeyEvent(Uint32 keysym, Uint32 keycode, bool down);
extern void SDL_Fcitx_UpdateTextInputArea(SDL_Window *window);
extern void SDL_Fcitx_PumpEvents(void);
diff --git a/src/core/linux/SDL_ibus.c b/src/core/linux/SDL_ibus.c
index a6f0730aa9463..dbbc3e1740e41 100644
--- a/src/core/linux/SDL_ibus.c
+++ b/src/core/linux/SDL_ibus.c
@@ -660,7 +660,7 @@ void SDL_IBus_Reset(void)
IBus_SimpleMessage("Reset");
}
-bool SDL_IBus_ProcessKeyEvent(Uint32 keysym, Uint32 keycode, Uint8 state)
+bool SDL_IBus_ProcessKeyEvent(Uint32 keysym, Uint32 keycode, bool down)
{
Uint32 result = 0;
SDL_DBusContext *dbus = SDL_DBus_GetContext();
@@ -668,7 +668,7 @@ bool SDL_IBus_ProcessKeyEvent(Uint32 keysym, Uint32 keycode, Uint8 state)
if (IBus_CheckConnection(dbus)) {
Uint32 mods = IBus_ModState();
Uint32 ibus_keycode = keycode - 8;
- if (state == SDL_RELEASED) {
+ if (!down) {
mods |= (1 << 30); // IBUS_RELEASE_MASK
}
if (!SDL_DBus_CallMethodOnConnection(ibus_conn, ibus_service, input_ctx_path, ibus_input_interface, "ProcessKeyEvent",
diff --git a/src/core/linux/SDL_ibus.h b/src/core/linux/SDL_ibus.h
index 26349f9769ce6..ffd7e8e5e7be4 100644
--- a/src/core/linux/SDL_ibus.h
+++ b/src/core/linux/SDL_ibus.h
@@ -40,7 +40,7 @@ extern void SDL_IBus_Reset(void);
/* Sends a keypress event to IBus, returns true if IBus used this event to
update its candidate list or change input methods. PumpEvents should be
called some time after this, to receive the TextInput / TextEditing event back. */
-extern bool SDL_IBus_ProcessKeyEvent(Uint32 keysym, Uint32 keycode, Uint8 state);
+extern bool SDL_IBus_ProcessKeyEvent(Uint32 keysym, Uint32 keycode, bool down);
/* Update the position of IBus' candidate list. If rect is NULL then this will
just reposition it relative to the focused window's new position. */
diff --git a/src/core/linux/SDL_ime.c b/src/core/linux/SDL_ime.c
index 2904f020f95be..a853618bb41c7 100644
--- a/src/core/linux/SDL_ime.c
+++ b/src/core/linux/SDL_ime.c
@@ -28,7 +28,7 @@ typedef bool (*SDL_IME_Init_t)(void);
typedef void (*SDL_IME_Quit_t)(void);
typedef void (*SDL_IME_SetFocus_t)(bool);
typedef void (*SDL_IME_Reset_t)(void);
-typedef bool (*SDL_IME_ProcessKeyEvent_t)(Uint32, Uint32, Uint8 state);
+typedef bool (*SDL_IME_ProcessKeyEvent_t)(Uint32, Uint32, bool down);
typedef void (*SDL_IME_UpdateTextInputArea_t)(SDL_Window *window);
typedef void (*SDL_IME_PumpEvents_t)(void);
@@ -126,10 +126,10 @@ void SDL_IME_Reset(void)
}
}
-bool SDL_IME_ProcessKeyEvent(Uint32 keysym, Uint32 keycode, Uint8 state)
+bool SDL_IME_ProcessKeyEvent(Uint32 keysym, Uint32 keycode, bool down)
{
if (SDL_IME_ProcessKeyEvent_Real) {
- return SDL_IME_ProcessKeyEvent_Real(keysym, keycode, state);
+ return SDL_IME_ProcessKeyEvent_Real(keysym, keycode, down);
}
return false;
diff --git a/src/core/linux/SDL_ime.h b/src/core/linux/SDL_ime.h
index 907676325c024..2b75cdd37b157 100644
--- a/src/core/linux/SDL_ime.h
+++ b/src/core/linux/SDL_ime.h
@@ -28,7 +28,7 @@ extern bool SDL_IME_Init(void);
extern void SDL_IME_Quit(void);
extern void SDL_IME_SetFocus(bool focused);
extern void SDL_IME_Reset(void);
-extern bool SDL_IME_ProcessKeyEvent(Uint32 keysym, Uint32 keycode, Uint8 state);
+extern bool SDL_IME_ProcessKeyEvent(Uint32 keysym, Uint32 keycode, bool down);
extern void SDL_IME_UpdateTextInputArea(SDL_Window *window);
extern void SDL_IME_PumpEvents(void);
diff --git a/src/core/openbsd/SDL_wscons_kbd.c b/src/core/openbsd/SDL_wscons_kbd.c
index f23574c4df0eb..9dcf94df0e192 100644
--- a/src/core/openbsd/SDL_wscons_kbd.c
+++ b/src/core/openbsd/SDL_wscons_kbd.c
@@ -560,22 +560,22 @@ static void Translate_to_keycode(SDL_WSCONS_input_data *input, int type, keysym_
switch (keyDesc.command) {
case KS_Cmd_ScrollBack:
{
- SDL_SendKeyboardKey(0, input->keyboardID, 0, SDL_SCANCODE_PAGEUP, type == WSCONS_EVENT_KEY_DOWN ? SDL_PRESSED : SDL_RELEASED);
+ SDL_SendKeyboardKey(0, input->keyboardID, 0, SDL_SCANCODE_PAGEUP, (type == WSCONS_EVENT_KEY_DOWN));
return;
}
case KS_Cmd_ScrollFwd:
{
- SDL_SendKeyboardKey(0, input->keyboardID, 0, SDL_SCANCODE_PAGEDOWN, type == WSCONS_EVENT_KEY_DOWN ? SDL_PRESSED : SDL_RELEASED);
+ SDL_SendKeyboardKey(0, input->keyboardID, 0, SDL_SCANCODE_PAGEDOWN, (type == WSCONS_EVENT_KEY_DOWN));
return;
}
}
for (i = 0; i < sizeof(conversion_table) / sizeof(struct wscons_keycode_to_SDL); i++) {
if (conversion_table[i].sourcekey == group[0]) {
- SDL_SendKeyboardKey(0, input->keyboardID, group[0], conversion_table[i].targetKey, type == WSCONS_EVENT_KEY_DOWN ? SDL_PRESSED : SDL_RELEASED);
+ SDL_SendKeyboardKey(0, input->keyboardID, group[0], conversion_table[i].targetKey, (type == WSCONS_EVENT_KEY_DOWN));
return;
}
}
- SDL_SendKeyboardKey(0, input->keyboardID, group[0], SDL_SCANCODE_UNKNOWN, type == WSCONS_EVENT_KEY_DOWN ? SDL_PRESSED : SDL_RELEASED);
+ SDL_SendKeyboardKey(0, input->keyboardID, group[0], SDL_SCANCODE_UNKNOWN, (type == WSCONS_EVENT_KEY_DOWN));
}
static void updateKeyboard(SDL_WSCONS_input_data *input)
@@ -809,13 +809,13 @@ static void updateKeyboard(SDL_WSCONS_input_data *input)
} break;
case WSCONS_EVENT_ALL_KEYS_UP:
for (i = 0; i < SDL_NUM_SCANCODES; i++) {
- SDL_SendKeyboardKey(0, input->keyboardID, 0, (SDL_Scancode)i, SDL_RELEASED);
+ SDL_SendKeyboardKey(0, input->keyboardID, 0, (SDL_Scancode)i, false);
}
break;
}
if (input->type == WSKBD_TYPE_USB && events[i].value <= 0xE7)
- SDL_SendKeyboardKey(0, input->keyboardID, 0, (SDL_Scancode)events[i].value, type == WSCONS_EVENT_KEY_DOWN ? SDL_PRESSED : SDL_RELEASED);
+ SDL_SendKeyboardKey(0, input->keyboardID, 0, (SDL_Scancode)events[i].value, (type == WSCONS_EVENT_KEY_DOWN));
else
Translate_to_keycode(input, type, events[i].value);
diff --git a/src/core/openbsd/SDL_wscons_mouse.c b/src/core/openbsd/SDL_wscons_mouse.c
index 03b0f7de24aec..5ba7a5007bb12 100644
--- a/src/core/openbsd/SDL_wscons_mouse.c
+++ b/src/core/openbsd/SDL_wscons_mouse.c
@@ -79,13 +79,13 @@ void updateMouse(SDL_WSCONS_mouse_input_data *input)
{
switch (events[i].value) {
case 0: // Left Mouse Button.
- SDL_SendMouseButton(0, mouse->focus, input->mouseID, SDL_PRESSED, SDL_BUTTON_LEFT);
+ SDL_SendMouseButton(0, mouse->focus, input->mouseID, SDL_BUTTON_LEFT, true);
break;
case 1: // Middle Mouse Button.
- SDL_SendMouseButton(0, mouse->focus, input->mouseID, SDL_PRESSED, SDL_BUTTON_MIDDLE);
+ SDL_SendMouseButton(0, mouse->focus, in
(Patch may be truncated, please check the link at the top of this post.)