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
This commit is contained in:
Sam Lantinga 2024-09-09 09:18:02 -07:00
parent 7d1bbae6b2
commit 6fc6e3dc7e
89 changed files with 935 additions and 956 deletions

View File

@ -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 @

View File

@ -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()

View File

@ -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;
/**

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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);

View File

@ -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) {

View File

@ -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;

View File

@ -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) {

View File

@ -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);

View File

@ -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",

View File

@ -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. */

View File

@ -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;

View File

@ -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);

View File

@ -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);

View File

@ -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, input->mouseID, SDL_BUTTON_MIDDLE, true);
break;
case 2: // Right Mouse Button.
SDL_SendMouseButton(0, mouse->focus, input->mouseID, SDL_PRESSED, SDL_BUTTON_RIGHT);
SDL_SendMouseButton(0, mouse->focus, input->mouseID, SDL_BUTTON_RIGHT, true);
break;
}
} break;
@ -93,13 +93,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_RELEASED, SDL_BUTTON_LEFT);
SDL_SendMouseButton(0, mouse->focus, input->mouseID, SDL_BUTTON_LEFT, false);
break;
case 1: // Middle Mouse Button.
SDL_SendMouseButton(0, mouse->focus, input->mouseID, SDL_RELEASED, SDL_BUTTON_MIDDLE);
SDL_SendMouseButton(0, mouse->focus, input->mouseID, SDL_BUTTON_MIDDLE, false);
break;
case 2: // Right Mouse Button.
SDL_SendMouseButton(0, mouse->focus, input->mouseID, SDL_RELEASED, SDL_BUTTON_RIGHT);
SDL_SendMouseButton(0, mouse->focus, input->mouseID, SDL_BUTTON_RIGHT, false);
break;
}
} break;

View File

@ -327,7 +327,7 @@ SDL_DYNAPI_PROC(const char*,SDL_GetGamepadAppleSFSymbolsNameForButton,(SDL_Gamep
SDL_DYNAPI_PROC(Sint16,SDL_GetGamepadAxis,(SDL_Gamepad *a, SDL_GamepadAxis b),(a,b),return)
SDL_DYNAPI_PROC(SDL_GamepadAxis,SDL_GetGamepadAxisFromString,(const char *a),(a),return)
SDL_DYNAPI_PROC(SDL_GamepadBinding**,SDL_GetGamepadBindings,(SDL_Gamepad *a, int *b),(a,b),return)
SDL_DYNAPI_PROC(Uint8,SDL_GetGamepadButton,(SDL_Gamepad *a, SDL_GamepadButton b),(a,b),return)
SDL_DYNAPI_PROC(SDL_bool,SDL_GetGamepadButton,(SDL_Gamepad *a, SDL_GamepadButton b),(a,b),return)
SDL_DYNAPI_PROC(SDL_GamepadButton,SDL_GetGamepadButtonFromString,(const char *a),(a),return)
SDL_DYNAPI_PROC(SDL_GamepadButtonLabel,SDL_GetGamepadButtonLabel,(SDL_Gamepad *a, SDL_GamepadButton b),(a,b),return)
SDL_DYNAPI_PROC(SDL_GamepadButtonLabel,SDL_GetGamepadButtonLabelForType,(SDL_GamepadType a, SDL_GamepadButton b),(a,b),return)
@ -361,7 +361,7 @@ SDL_DYNAPI_PROC(Uint64,SDL_GetGamepadSteamHandle,(SDL_Gamepad *a),(a),return)
SDL_DYNAPI_PROC(const char*,SDL_GetGamepadStringForAxis,(SDL_GamepadAxis a),(a),return)
SDL_DYNAPI_PROC(const char*,SDL_GetGamepadStringForButton,(SDL_GamepadButton a),(a),return)
SDL_DYNAPI_PROC(const char*,SDL_GetGamepadStringForType,(SDL_GamepadType a),(a),return)
SDL_DYNAPI_PROC(SDL_bool,SDL_GetGamepadTouchpadFinger,(SDL_Gamepad *a, int b, int c, Uint8 *d, float *e, float *f, float *g),(a,b,c,d,e,f,g),return)
SDL_DYNAPI_PROC(SDL_bool,SDL_GetGamepadTouchpadFinger,(SDL_Gamepad *a, int b, int c, SDL_bool *d, float *e, float *f, float *g),(a,b,c,d,e,f,g),return)
SDL_DYNAPI_PROC(SDL_GamepadType,SDL_GetGamepadType,(SDL_Gamepad *a),(a),return)
SDL_DYNAPI_PROC(SDL_GamepadType,SDL_GetGamepadTypeForID,(SDL_JoystickID a),(a),return)
SDL_DYNAPI_PROC(SDL_GamepadType,SDL_GetGamepadTypeFromString,(const char *a),(a),return)
@ -386,7 +386,7 @@ SDL_DYNAPI_PROC(SDL_IOStatus,SDL_GetIOStatus,(SDL_IOStream *a),(a),return)
SDL_DYNAPI_PROC(Sint16,SDL_GetJoystickAxis,(SDL_Joystick *a, int b),(a,b),return)
SDL_DYNAPI_PROC(SDL_bool,SDL_GetJoystickAxisInitialState,(SDL_Joystick *a, int b, Sint16 *c),(a,b,c),return)
SDL_DYNAPI_PROC(SDL_bool,SDL_GetJoystickBall,(SDL_Joystick *a, int b, int *c, int *d),(a,b,c,d),return)
SDL_DYNAPI_PROC(Uint8,SDL_GetJoystickButton,(SDL_Joystick *a, int b),(a,b),return)
SDL_DYNAPI_PROC(SDL_bool,SDL_GetJoystickButton,(SDL_Joystick *a, int b),(a,b),return)
SDL_DYNAPI_PROC(SDL_JoystickConnectionState,SDL_GetJoystickConnectionState,(SDL_Joystick *a),(a),return)
SDL_DYNAPI_PROC(Uint16,SDL_GetJoystickFirmwareVersion,(SDL_Joystick *a),(a),return)
SDL_DYNAPI_PROC(SDL_Joystick*,SDL_GetJoystickFromID,(SDL_JoystickID a),(a),return)
@ -419,7 +419,7 @@ SDL_DYNAPI_PROC(SDL_Keycode,SDL_GetKeyFromScancode,(SDL_Scancode a, SDL_Keymod b
SDL_DYNAPI_PROC(const char*,SDL_GetKeyName,(SDL_Keycode a),(a),return)
SDL_DYNAPI_PROC(SDL_Window*,SDL_GetKeyboardFocus,(void),(),return)
SDL_DYNAPI_PROC(const char*,SDL_GetKeyboardNameForID,(SDL_KeyboardID a),(a),return)
SDL_DYNAPI_PROC(const Uint8*,SDL_GetKeyboardState,(int *a),(a),return)
SDL_DYNAPI_PROC(const SDL_bool*,SDL_GetKeyboardState,(int *a),(a),return)
SDL_DYNAPI_PROC(SDL_KeyboardID*,SDL_GetKeyboards,(int *a),(a),return)
SDL_DYNAPI_PROC(void,SDL_GetLogOutputFunction,(SDL_LogOutputFunction *a, void **b),(a,b),)
SDL_DYNAPI_PROC(SDL_LogPriority,SDL_GetLogPriority,(int a),(a),return)
@ -832,9 +832,9 @@ SDL_DYNAPI_PROC(SDL_bool,SDL_SetJoystickLED,(SDL_Joystick *a, Uint8 b, Uint8 c,
SDL_DYNAPI_PROC(SDL_bool,SDL_SetJoystickPlayerIndex,(SDL_Joystick *a, int b),(a,b),return)
SDL_DYNAPI_PROC(SDL_bool,SDL_SetJoystickVirtualAxis,(SDL_Joystick *a, int b, Sint16 c),(a,b,c),return)
SDL_DYNAPI_PROC(SDL_bool,SDL_SetJoystickVirtualBall,(SDL_Joystick *a, int b, Sint16 c, Sint16 d),(a,b,c,d),return)
SDL_DYNAPI_PROC(SDL_bool,SDL_SetJoystickVirtualButton,(SDL_Joystick *a, int b, Uint8 c),(a,b,c),return)
SDL_DYNAPI_PROC(SDL_bool,SDL_SetJoystickVirtualButton,(SDL_Joystick *a, int b, SDL_bool c),(a,b,c),return)
SDL_DYNAPI_PROC(SDL_bool,SDL_SetJoystickVirtualHat,(SDL_Joystick *a, int b, Uint8 c),(a,b,c),return)
SDL_DYNAPI_PROC(SDL_bool,SDL_SetJoystickVirtualTouchpad,(SDL_Joystick *a, int b, int c, Uint8 d, float e, float f, float g),(a,b,c,d,e,f,g),return)
SDL_DYNAPI_PROC(SDL_bool,SDL_SetJoystickVirtualTouchpad,(SDL_Joystick *a, int b, int c, SDL_bool d, float e, float f, float g),(a,b,c,d,e,f,g),return)
SDL_DYNAPI_PROC(SDL_bool,SDL_SetLinuxThreadPriority,(Sint64 a, int b),(a,b),return)
SDL_DYNAPI_PROC(SDL_bool,SDL_SetLinuxThreadPriorityAndPolicy,(Sint64 a, int b, int c),(a,b,c),return)
SDL_DYNAPI_PROC(void,SDL_SetLogOutputFunction,(SDL_LogOutputFunction a, void *b),(a,b),)

View File

@ -512,7 +512,7 @@ static void SDL_LogEvent(const SDL_Event *event)
#define PRINT_KEY_EVENT(event) \
(void)SDL_snprintf(details, sizeof(details), " (timestamp=%u windowid=%u which=%u state=%s repeat=%s scancode=%u keycode=%u mod=0x%x)", \
(uint)event->key.timestamp, (uint)event->key.windowID, (uint)event->key.which, \
event->key.state == SDL_PRESSED ? "pressed" : "released", \
event->key.down ? "pressed" : "released", \
event->key.repeat ? "true" : "false", \
(uint)event->key.scancode, \
(uint)event->key.key, \
@ -562,7 +562,7 @@ static void SDL_LogEvent(const SDL_Event *event)
(void)SDL_snprintf(details, sizeof(details), " (timestamp=%u windowid=%u which=%u button=%u state=%s clicks=%u x=%g y=%g)", \
(uint)event->button.timestamp, (uint)event->button.windowID, \
(uint)event->button.which, (uint)event->button.button, \
event->button.state == SDL_PRESSED ? "pressed" : "released", \
event->button.down ? "pressed" : "released", \
(uint)event->button.clicks, event->button.x, event->button.y)
SDL_EVENT_CASE(SDL_EVENT_MOUSE_BUTTON_DOWN)
PRINT_MBUTTON_EVENT(event);
@ -600,7 +600,7 @@ static void SDL_LogEvent(const SDL_Event *event)
#define PRINT_JBUTTON_EVENT(event) \
(void)SDL_snprintf(details, sizeof(details), " (timestamp=%u which=%d button=%u state=%s)", \
(uint)event->jbutton.timestamp, (int)event->jbutton.which, \
(uint)event->jbutton.button, event->jbutton.state == SDL_PRESSED ? "pressed" : "released")
(uint)event->jbutton.button, event->jbutton.down ? "pressed" : "released")
SDL_EVENT_CASE(SDL_EVENT_JOYSTICK_BUTTON_DOWN)
PRINT_JBUTTON_EVENT(event);
break;
@ -636,7 +636,7 @@ static void SDL_LogEvent(const SDL_Event *event)
#define PRINT_CBUTTON_EVENT(event) \
(void)SDL_snprintf(details, sizeof(details), " (timestamp=%u which=%d button=%u state=%s)", \
(uint)event->gbutton.timestamp, (int)event->gbutton.which, \
(uint)event->gbutton.button, event->gbutton.state == SDL_PRESSED ? "pressed" : "released")
(uint)event->gbutton.button, event->gbutton.down ? "pressed" : "released")
SDL_EVENT_CASE(SDL_EVENT_GAMEPAD_BUTTON_DOWN)
PRINT_CBUTTON_EVENT(event);
break;
@ -704,7 +704,7 @@ static void SDL_LogEvent(const SDL_Event *event)
#define PRINT_PTOUCH_EVENT(event) \
(void)SDL_snprintf(details, sizeof(details), " (timestamp=%u windowid=%u which=%u pen_state=%u x=%g y=%g eraser=%s state=%s)", \
(uint)event->ptouch.timestamp, (uint)event->ptouch.windowID, (uint)event->ptouch.which, (uint)event->ptouch.pen_state, event->ptouch.x, event->ptouch.y, \
event->ptouch.eraser ? "yes" : "no", event->ptouch.state == SDL_PRESSED ? "down" : "up");
event->ptouch.eraser ? "yes" : "no", event->ptouch.down ? "down" : "up");
SDL_EVENT_CASE(SDL_EVENT_PEN_DOWN)
PRINT_PTOUCH_EVENT(event);
break;
@ -738,7 +738,7 @@ static void SDL_LogEvent(const SDL_Event *event)
#define PRINT_PBUTTON_EVENT(event) \
(void)SDL_snprintf(details, sizeof(details), " (timestamp=%u windowid=%u which=%u pen_state=%u x=%g y=%g button=%u state=%s)", \
(uint)event->pbutton.timestamp, (uint)event->pbutton.windowID, (uint)event->pbutton.which, (uint)event->pbutton.pen_state, event->pbutton.x, event->pbutton.y, \
(uint)event->pbutton.button, event->pbutton.state == SDL_PRESSED ? "down" : "up");
(uint)event->pbutton.button, event->pbutton.down ? "down" : "up");
SDL_EVENT_CASE(SDL_EVENT_PEN_BUTTON_DOWN)
PRINT_PBUTTON_EVENT(event);
break;

View File

@ -54,7 +54,7 @@ typedef struct SDL_Keyboard
SDL_Window *focus;
SDL_Keymod modstate;
Uint8 keysource[SDL_NUM_SCANCODES];
Uint8 keystate[SDL_NUM_SCANCODES];
SDL_bool keystate[SDL_NUM_SCANCODES];
SDL_Keymap *keymap;
bool french_numbers;
bool latin_letters;
@ -220,8 +220,8 @@ void SDL_ResetKeyboard(void)
printf("Resetting keyboard\n");
#endif
for (scancode = SDL_SCANCODE_UNKNOWN; scancode < SDL_NUM_SCANCODES; ++scancode) {
if (keyboard->keystate[scancode] == SDL_PRESSED) {
SDL_SendKeyboardKey(0, SDL_GLOBAL_KEYBOARD_ID, 0, (SDL_Scancode)scancode, SDL_RELEASED);
if (keyboard->keystate[scancode]) {
SDL_SendKeyboardKey(0, SDL_GLOBAL_KEYBOARD_ID, 0, (SDL_Scancode)scancode, false);
}
}
}
@ -490,36 +490,29 @@ SDL_Scancode SDL_GetScancodeFromKey(SDL_Keycode key, SDL_Keymod *modstate)
return SDL_GetKeymapScancode(keyboard->keymap, key, modstate);
}
static bool SDL_SendKeyboardKeyInternal(Uint64 timestamp, Uint32 flags, SDL_KeyboardID keyboardID, int rawcode, SDL_Scancode scancode, Uint8 state)
static bool SDL_SendKeyboardKeyInternal(Uint64 timestamp, Uint32 flags, SDL_KeyboardID keyboardID, int rawcode, SDL_Scancode scancode, bool down)
{
SDL_Keyboard *keyboard = &SDL_keyboard;
bool posted = false;
SDL_Keycode keycode = SDLK_UNKNOWN;
Uint32 type;
Uint8 repeat = false;
bool repeat = false;
const Uint8 source = flags & KEYBOARD_SOURCE_MASK;
#ifdef DEBUG_KEYBOARD
printf("The '%s' key has been %s\n", SDL_GetScancodeName(scancode),
state == SDL_PRESSED ? "pressed" : "released");
printf("The '%s' key has been %s\n", SDL_GetScancodeName(scancode), down ? "pressed" : "released");
#endif
// Figure out what type of event this is
switch (state) {
case SDL_PRESSED:
if (down) {
type = SDL_EVENT_KEY_DOWN;
break;
case SDL_RELEASED:
} else {
type = SDL_EVENT_KEY_UP;
break;
default:
// Invalid state -- bail
return false;
}
if (scancode > SDL_SCANCODE_UNKNOWN && scancode < SDL_NUM_SCANCODES) {
// Drop events that don't change state
if (state) {
if (down) {
if (keyboard->keystate[scancode]) {
if (!(keyboard->keysource[scancode] & source)) {
keyboard->keysource[scancode] |= source;
@ -536,7 +529,7 @@ static bool SDL_SendKeyboardKeyInternal(Uint64 timestamp, Uint32 flags, SDL_Keyb
}
// Update internal keyboard state
keyboard->keystate[scancode] = state;
keyboard->keystate[scancode] = down;
keycode = SDL_GetKeyFromScancode(scancode, keyboard->modstate, true);
@ -616,7 +609,7 @@ static bool SDL_SendKeyboardKeyInternal(Uint64 timestamp, Uint32 flags, SDL_Keyb
event.key.key = keycode;
event.key.mod = keyboard->modstate;
event.key.raw = (Uint16)rawcode;
event.key.state = state;
event.key.down = down;
event.key.repeat = repeat;
event.key.windowID = keyboard->focus ? keyboard->focus->id : 0;
event.key.which = keyboardID;
@ -626,8 +619,7 @@ static bool SDL_SendKeyboardKeyInternal(Uint64 timestamp, Uint32 flags, SDL_Keyb
/* If the keyboard is grabbed and the grabbed window is in full-screen,
minimize the window when we receive Alt+Tab, unless the application
has explicitly opted out of this behavior. */
if (keycode == SDLK_TAB &&
state == SDL_PRESSED &&
if (keycode == SDLK_TAB && down &&
(keyboard->modstate & SDL_KMOD_ALT) &&
keyboard->focus &&
(keyboard->focus->flags & SDL_WINDOW_KEYBOARD_GRABBED) &&
@ -655,42 +647,42 @@ void SDL_SendKeyboardUnicodeKey(Uint64 timestamp, Uint32 ch)
if (modstate & SDL_KMOD_SHIFT) {
// If the character uses shift, press shift down
SDL_SendKeyboardKeyInternal(timestamp, KEYBOARD_VIRTUAL, SDL_GLOBAL_KEYBOARD_ID, 0, SDL_SCANCODE_LSHIFT, SDL_PRESSED);
SDL_SendKeyboardKeyInternal(timestamp, KEYBOARD_VIRTUAL, SDL_GLOBAL_KEYBOARD_ID, 0, SDL_SCANCODE_LSHIFT, true);
}
// Send a keydown and keyup for the character
SDL_SendKeyboardKeyInternal(timestamp, KEYBOARD_VIRTUAL, SDL_GLOBAL_KEYBOARD_ID, 0, scancode, SDL_PRESSED);
SDL_SendKeyboardKeyInternal(timestamp, KEYBOARD_VIRTUAL, SDL_GLOBAL_KEYBOARD_ID, 0, scancode, SDL_RELEASED);
SDL_SendKeyboardKeyInternal(timestamp, KEYBOARD_VIRTUAL, SDL_GLOBAL_KEYBOARD_ID, 0, scancode, true);
SDL_SendKeyboardKeyInternal(timestamp, KEYBOARD_VIRTUAL, SDL_GLOBAL_KEYBOARD_ID, 0, scancode, false);
if (modstate & SDL_KMOD_SHIFT) {
// If the character uses shift, release shift
SDL_SendKeyboardKeyInternal(timestamp, KEYBOARD_VIRTUAL, SDL_GLOBAL_KEYBOARD_ID, 0, SDL_SCANCODE_LSHIFT, SDL_RELEASED);
SDL_SendKeyboardKeyInternal(timestamp, KEYBOARD_VIRTUAL, SDL_GLOBAL_KEYBOARD_ID, 0, SDL_SCANCODE_LSHIFT, false);
}
}
bool SDL_SendKeyboardKey(Uint64 timestamp, SDL_KeyboardID keyboardID, int rawcode, SDL_Scancode scancode, Uint8 state)
bool SDL_SendKeyboardKey(Uint64 timestamp, SDL_KeyboardID keyboardID, int rawcode, SDL_Scancode scancode, bool down)
{
return SDL_SendKeyboardKeyInternal(timestamp, KEYBOARD_HARDWARE, keyboardID, rawcode, scancode, state);
return SDL_SendKeyboardKeyInternal(timestamp, KEYBOARD_HARDWARE, keyboardID, rawcode, scancode, down);
}
bool SDL_SendKeyboardKeyAndKeycode(Uint64 timestamp, SDL_KeyboardID keyboardID, int rawcode, SDL_Scancode scancode, SDL_Keycode keycode, Uint8 state)
bool SDL_SendKeyboardKeyAndKeycode(Uint64 timestamp, SDL_KeyboardID keyboardID, int rawcode, SDL_Scancode scancode, SDL_Keycode keycode, bool down)
{
if (state == SDL_PRESSED) {
if (down) {
// Make sure we have this keycode in our keymap
SetKeymapEntry(scancode, SDL_GetModState(), keycode);
}
return SDL_SendKeyboardKeyInternal(timestamp, KEYBOARD_HARDWARE, keyboardID, rawcode, scancode, state);
return SDL_SendKeyboardKeyInternal(timestamp, KEYBOARD_HARDWARE, keyboardID, rawcode, scancode, down);
}
bool SDL_SendKeyboardKeyIgnoreModifiers(Uint64 timestamp, SDL_KeyboardID keyboardID, int rawcode, SDL_Scancode scancode, Uint8 state)
bool SDL_SendKeyboardKeyIgnoreModifiers(Uint64 timestamp, SDL_KeyboardID keyboardID, int rawcode, SDL_Scancode scancode, bool down)
{
return SDL_SendKeyboardKeyInternal(timestamp, KEYBOARD_HARDWARE | KEYBOARD_IGNOREMODIFIERS, keyboardID, rawcode, scancode, state);
return SDL_SendKeyboardKeyInternal(timestamp, KEYBOARD_HARDWARE | KEYBOARD_IGNOREMODIFIERS, keyboardID, rawcode, scancode, down);
}
bool SDL_SendKeyboardKeyAutoRelease(Uint64 timestamp, SDL_Scancode scancode)
{
return SDL_SendKeyboardKeyInternal(timestamp, KEYBOARD_AUTORELEASE, SDL_GLOBAL_KEYBOARD_ID, 0, scancode, SDL_PRESSED);
return SDL_SendKeyboardKeyInternal(timestamp, KEYBOARD_AUTORELEASE, SDL_GLOBAL_KEYBOARD_ID, 0, scancode, false);
}
void SDL_ReleaseAutoReleaseKeys(void)
@ -701,7 +693,7 @@ void SDL_ReleaseAutoReleaseKeys(void)
if (keyboard->autorelease_pending) {
for (scancode = SDL_SCANCODE_UNKNOWN; scancode < SDL_NUM_SCANCODES; ++scancode) {
if (keyboard->keysource[scancode] == KEYBOARD_AUTORELEASE) {
SDL_SendKeyboardKeyInternal(0, KEYBOARD_AUTORELEASE, SDL_GLOBAL_KEYBOARD_ID, 0, (SDL_Scancode)scancode, SDL_RELEASED);
SDL_SendKeyboardKeyInternal(0, KEYBOARD_AUTORELEASE, SDL_GLOBAL_KEYBOARD_ID, 0, (SDL_Scancode)scancode, false);
}
}
keyboard->autorelease_pending = false;
@ -871,7 +863,7 @@ void SDL_QuitKeyboard(void)
SDL_KeycodeOptionsChanged, &SDL_keyboard);
}
const Uint8 *SDL_GetKeyboardState(int *numkeys)
const SDL_bool *SDL_GetKeyboardState(int *numkeys)
{
SDL_Keyboard *keyboard = &SDL_keyboard;

View File

@ -55,13 +55,13 @@ extern bool SDL_SetKeyboardFocus(SDL_Window *window);
extern void SDL_SendKeyboardUnicodeKey(Uint64 timestamp, Uint32 ch);
// Send a keyboard key event
extern bool SDL_SendKeyboardKey(Uint64 timestamp, SDL_KeyboardID keyboardID, int rawcode, SDL_Scancode scancode, Uint8 state);
extern bool SDL_SendKeyboardKeyIgnoreModifiers(Uint64 timestamp, SDL_KeyboardID keyboardID, int rawcode, SDL_Scancode scancode, Uint8 state);
extern bool SDL_SendKeyboardKey(Uint64 timestamp, SDL_KeyboardID keyboardID, int rawcode, SDL_Scancode scancode, bool down);
extern bool SDL_SendKeyboardKeyIgnoreModifiers(Uint64 timestamp, SDL_KeyboardID keyboardID, int rawcode, SDL_Scancode scancode, bool down);
extern bool SDL_SendKeyboardKeyAutoRelease(Uint64 timestamp, SDL_Scancode scancode);
/* This is for platforms that don't know the keymap but can report scancode and keycode directly.
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, Uint8 state);
extern bool SDL_SendKeyboardKeyAndKeycode(Uint64 timestamp, SDL_KeyboardID keyboardID, int rawcode, SDL_Scancode scancode, SDL_Keycode keycode, bool down);
// Release all the autorelease keys
extern void SDL_ReleaseAutoReleaseKeys(void);

View File

@ -486,7 +486,7 @@ void SDL_ResetMouse(void)
for (i = 1; i <= sizeof(buttonState)*8; ++i) {
if (buttonState & SDL_BUTTON(i)) {
SDL_SendMouseButton(0, mouse->focus, mouse->mouseID, SDL_RELEASED, i);
SDL_SendMouseButton(0, mouse->focus, mouse->mouseID, i, false);
}
}
SDL_assert(SDL_GetMouseButtonState(mouse, SDL_GLOBAL_MOUSE_ID, false) == 0);
@ -863,7 +863,7 @@ static void SDL_PrivateSendMouseMotion(Uint64 timestamp, SDL_Window *window, SDL
}
}
static SDL_MouseInputSource *GetMouseInputSource(SDL_Mouse *mouse, SDL_MouseID mouseID, Uint8 state, Uint8 button)
static SDL_MouseInputSource *GetMouseInputSource(SDL_Mouse *mouse, SDL_MouseID mouseID, bool down, Uint8 button)
{
SDL_MouseInputSource *source, *match = NULL, *sources;
int i;
@ -876,7 +876,7 @@ static SDL_MouseInputSource *GetMouseInputSource(SDL_Mouse *mouse, SDL_MouseID m
}
}
if (!state && (!match || !(match->buttonstate & SDL_BUTTON(button)))) {
if (!down && (!match || !(match->buttonstate & SDL_BUTTON(button)))) {
/* This might be a button release from a transition between mouse messages and raw input.
* See if there's another mouse source that already has that button down and use that.
*/
@ -922,7 +922,7 @@ static SDL_MouseClickState *GetMouseClickState(SDL_Mouse *mouse, Uint8 button)
return &mouse->clickstate[button];
}
static void SDL_PrivateSendMouseButton(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button, int clicks)
static void SDL_PrivateSendMouseButton(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, Uint8 button, bool down, int clicks)
{
SDL_Mouse *mouse = SDL_GetMouse();
Uint32 type;
@ -934,7 +934,7 @@ static void SDL_PrivateSendMouseButton(Uint64 timestamp, SDL_Window *window, SDL
mouseID = SDL_GLOBAL_MOUSE_ID;
}
source = GetMouseInputSource(mouse, mouseID, state, button);
source = GetMouseInputSource(mouse, mouseID, down, button);
if (!source) {
return;
}
@ -943,7 +943,7 @@ static void SDL_PrivateSendMouseButton(Uint64 timestamp, SDL_Window *window, SDL
// SDL_HINT_MOUSE_TOUCH_EVENTS: controlling whether mouse events should generate synthetic touch events
if (mouse->mouse_touch_events) {
if (mouseID != SDL_TOUCH_MOUSEID && button == SDL_BUTTON_LEFT) {
if (state == SDL_PRESSED) {
if (down) {
track_mouse_down = true;
} else {
track_mouse_down = false;
@ -964,22 +964,16 @@ static void SDL_PrivateSendMouseButton(Uint64 timestamp, SDL_Window *window, SDL
}
// Figure out which event to perform
switch (state) {
case SDL_PRESSED:
if (down) {
type = SDL_EVENT_MOUSE_BUTTON_DOWN;
buttonstate |= SDL_BUTTON(button);
break;
case SDL_RELEASED:
} else {
type = SDL_EVENT_MOUSE_BUTTON_UP;
buttonstate &= ~SDL_BUTTON(button);
break;
default:
// Invalid state -- bail
return;
}
// We do this after calculating buttonstate so button presses gain focus
if (window && state == SDL_PRESSED) {
if (window && down) {
SDL_UpdateMouseFocus(window, mouse->x, mouse->y, buttonstate, true);
}
@ -992,7 +986,7 @@ static void SDL_PrivateSendMouseButton(Uint64 timestamp, SDL_Window *window, SDL
if (clicks < 0) {
SDL_MouseClickState *clickstate = GetMouseClickState(mouse, button);
if (clickstate) {
if (state == SDL_PRESSED) {
if (down) {
Uint64 now = SDL_GetTicks();
if (now >= (clickstate->last_timestamp + mouse->double_click_time) ||
@ -1020,7 +1014,7 @@ static void SDL_PrivateSendMouseButton(Uint64 timestamp, SDL_Window *window, SDL
event.common.timestamp = timestamp;
event.button.windowID = mouse->focus ? mouse->focus->id : 0;
event.button.which = source->mouseID;
event.button.state = state;
event.button.down = down;
event.button.button = button;
event.button.clicks = (Uint8)SDL_min(clicks, 255);
event.button.x = mouse->x;
@ -1029,7 +1023,7 @@ static void SDL_PrivateSendMouseButton(Uint64 timestamp, SDL_Window *window, SDL
}
// We do this after dispatching event so button releases can lose focus
if (window && state == SDL_RELEASED) {
if (window && !down) {
SDL_UpdateMouseFocus(window, mouse->x, mouse->y, buttonstate, true);
}
@ -1039,15 +1033,15 @@ static void SDL_PrivateSendMouseButton(Uint64 timestamp, SDL_Window *window, SDL
}
}
void SDL_SendMouseButtonClicks(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button, int clicks)
void SDL_SendMouseButtonClicks(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, Uint8 button, bool down, int clicks)
{
clicks = SDL_max(clicks, 0);
SDL_PrivateSendMouseButton(timestamp, window, mouseID, state, button, clicks);
SDL_PrivateSendMouseButton(timestamp, window, mouseID, button, down, clicks);
}
void SDL_SendMouseButton(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button)
void SDL_SendMouseButton(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, Uint8 button, bool down)
{
SDL_PrivateSendMouseButton(timestamp, window, mouseID, state, button, -1);
SDL_PrivateSendMouseButton(timestamp, window, mouseID, button, down, -1);
}
void SDL_SendMouseWheel(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, float x, float y, SDL_MouseWheelDirection direction)

View File

@ -169,10 +169,10 @@ extern bool SDL_SetMouseSystemScale(int num_values, const float *values);
extern void SDL_SendMouseMotion(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, bool relative, float x, float y);
// Send a mouse button event
extern void SDL_SendMouseButton(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button);
extern void SDL_SendMouseButton(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, Uint8 button, bool down);
// Send a mouse button event with a click count
extern void SDL_SendMouseButtonClicks(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button, int clicks);
extern void SDL_SendMouseButtonClicks(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, Uint8 button, bool down, int clicks);
// Send a mouse wheel event
extern void SDL_SendMouseWheel(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, float x, float y, SDL_MouseWheelDirection direction);

View File

@ -309,7 +309,7 @@ void SDL_RemoveAllPenDevices(void (*callback)(SDL_PenID instance_id, void *handl
SDL_UnlockRWLock(pen_device_rwlock);
}
void SDL_SendPenTouch(Uint64 timestamp, SDL_PenID instance_id, const SDL_Window *window, Uint8 state, Uint8 eraser)
void SDL_SendPenTouch(Uint64 timestamp, SDL_PenID instance_id, const SDL_Window *window, bool eraser, bool down)
{
bool send_event = false;
SDL_PenInputFlags input_state = 0;
@ -327,10 +327,10 @@ void SDL_SendPenTouch(Uint64 timestamp, SDL_PenID instance_id, const SDL_Window
x = pen->x;
y = pen->y;
if (state && ((input_state & SDL_PEN_INPUT_DOWN) == 0)) {
if (down && ((input_state & SDL_PEN_INPUT_DOWN) == 0)) {
input_state |= SDL_PEN_INPUT_DOWN;
send_event = true;
} else if (!state && (input_state & SDL_PEN_INPUT_DOWN)) {
} else if (!down && (input_state & SDL_PEN_INPUT_DOWN)) {
input_state &= ~SDL_PEN_INPUT_DOWN;
send_event = true;
}
@ -338,7 +338,7 @@ void SDL_SendPenTouch(Uint64 timestamp, SDL_PenID instance_id, const SDL_Window
if (eraser && ((input_state & SDL_PEN_INPUT_ERASER_TIP) == 0)) {
input_state |= SDL_PEN_INPUT_ERASER_TIP;
send_event = true;
} else if (!state && (input_state & SDL_PEN_INPUT_ERASER_TIP)) {
} else if (!down && (input_state & SDL_PEN_INPUT_ERASER_TIP)) {
input_state &= ~SDL_PEN_INPUT_ERASER_TIP;
send_event = true;
}
@ -348,7 +348,7 @@ void SDL_SendPenTouch(Uint64 timestamp, SDL_PenID instance_id, const SDL_Window
SDL_UnlockRWLock(pen_device_rwlock);
if (send_event) {
const SDL_EventType evtype = state ? SDL_EVENT_PEN_DOWN : SDL_EVENT_PEN_UP;
const SDL_EventType evtype = down ? SDL_EVENT_PEN_DOWN : SDL_EVENT_PEN_UP;
if (send_event && SDL_EventEnabled(evtype)) {
SDL_Event event;
SDL_zero(event);
@ -359,8 +359,8 @@ void SDL_SendPenTouch(Uint64 timestamp, SDL_PenID instance_id, const SDL_Window
event.ptouch.pen_state = input_state;
event.ptouch.x = x;
event.ptouch.y = y;
event.ptouch.eraser = eraser ? 1 : 0;
event.ptouch.state = state ? SDL_PRESSED : SDL_RELEASED;
event.ptouch.eraser = eraser;
event.ptouch.down = down;
SDL_PushEvent(&event);
}
}
@ -443,7 +443,7 @@ void SDL_SendPenMotion(Uint64 timestamp, SDL_PenID instance_id, const SDL_Window
}
}
void SDL_SendPenButton(Uint64 timestamp, SDL_PenID instance_id, const SDL_Window *window, Uint8 state, Uint8 button)
void SDL_SendPenButton(Uint64 timestamp, SDL_PenID instance_id, const SDL_Window *window, Uint8 button, bool down)
{
bool send_event = false;
SDL_PenInputFlags input_state = 0;
@ -463,13 +463,13 @@ void SDL_SendPenButton(Uint64 timestamp, SDL_PenID instance_id, const SDL_Window
if (pen) {
input_state = pen->input_state;
const Uint32 flag = (Uint32) (1u << button);
const Uint8 current = (input_state & flag) ? 1 : 0;
const bool current = ((input_state & flag) != 0);
x = pen->x;
y = pen->y;
if (state && !current) {
if (down && !current) {
input_state |= flag;
send_event = true;
} else if (!state && current) {
} else if (!down && current) {
input_state &= ~flag;
send_event = true;
}
@ -478,7 +478,7 @@ void SDL_SendPenButton(Uint64 timestamp, SDL_PenID instance_id, const SDL_Window
SDL_UnlockRWLock(pen_device_rwlock);
if (send_event) {
const SDL_EventType evtype = state ? SDL_EVENT_PEN_BUTTON_DOWN : SDL_EVENT_PEN_BUTTON_UP;
const SDL_EventType evtype = down ? SDL_EVENT_PEN_BUTTON_DOWN : SDL_EVENT_PEN_BUTTON_UP;
if (SDL_EventEnabled(evtype)) {
SDL_Event event;
SDL_zero(event);
@ -490,7 +490,7 @@ void SDL_SendPenButton(Uint64 timestamp, SDL_PenID instance_id, const SDL_Window
event.pbutton.x = x;
event.pbutton.y = y;
event.pbutton.button = button;
event.pbutton.state = state ? SDL_PRESSED : SDL_RELEASED;
event.pbutton.down = down;
SDL_PushEvent(&event);
}
}

View File

@ -68,7 +68,7 @@ extern void SDL_RemovePenDevice(Uint64 timestamp, SDL_PenID instance_id);
extern void SDL_RemoveAllPenDevices(void (*callback)(SDL_PenID instance_id, void *handle, void *userdata), void *userdata);
// Backend calls this when a pen's button changes, to generate events and update state.
extern void SDL_SendPenTouch(Uint64 timestamp, SDL_PenID instance_id, const SDL_Window *window, Uint8 state, Uint8 eraser);
extern void SDL_SendPenTouch(Uint64 timestamp, SDL_PenID instance_id, const SDL_Window *window, bool eraser, bool down);
// Backend calls this when a pen moves on the tablet, to generate events and update state.
extern void SDL_SendPenMotion(Uint64 timestamp, SDL_PenID instance_id, const SDL_Window *window, float x, float y);
@ -77,7 +77,7 @@ extern void SDL_SendPenMotion(Uint64 timestamp, SDL_PenID instance_id, const SDL
extern void SDL_SendPenAxis(Uint64 timestamp, SDL_PenID instance_id, const SDL_Window *window, SDL_PenAxis axis, float value);
// Backend calls this when a pen's button changes, to generate events and update state.
extern void SDL_SendPenButton(Uint64 timestamp, SDL_PenID instance_id, const SDL_Window *window, Uint8 state, Uint8 button);
extern void SDL_SendPenButton(Uint64 timestamp, SDL_PenID instance_id, const SDL_Window *window, Uint8 button, bool down);
// Backend can optionally use this to find the SDL_PenID for the `handle` that was passed to SDL_AddPenDevice.
extern SDL_PenID SDL_FindPenByHandle(void *handle);

View File

@ -295,11 +295,11 @@ void SDL_SendTouch(Uint64 timestamp, SDL_TouchID id, SDL_FingerID fingerid, SDL_
pos_y = (float)(window->h - 1);
}
SDL_SendMouseMotion(timestamp, window, SDL_TOUCH_MOUSEID, false, pos_x, pos_y);
SDL_SendMouseButton(timestamp, window, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT);
SDL_SendMouseButton(timestamp, window, SDL_TOUCH_MOUSEID, SDL_BUTTON_LEFT, true);
}
} else {
if (finger_touching == true && track_touchid == id && track_fingerid == fingerid) {
SDL_SendMouseButton(timestamp, window, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT);
SDL_SendMouseButton(timestamp, window, SDL_TOUCH_MOUSEID, SDL_BUTTON_LEFT, false);
}
}
}

View File

@ -154,7 +154,7 @@ static GamepadMapping_t *SDL_PrivateAddMappingForGUID(SDL_GUID jGUID, const char
static void SDL_PrivateLoadButtonMapping(SDL_Gamepad *gamepad, GamepadMapping_t *pGamepadMapping);
static GamepadMapping_t *SDL_PrivateGetGamepadMapping(SDL_JoystickID instance_id, bool create_mapping);
static void SDL_SendGamepadAxis(Uint64 timestamp, SDL_Gamepad *gamepad, SDL_GamepadAxis axis, Sint16 value);
static void SDL_SendGamepadButton(Uint64 timestamp, SDL_Gamepad *gamepad, SDL_GamepadButton button, Uint8 state);
static void SDL_SendGamepadButton(Uint64 timestamp, SDL_Gamepad *gamepad, SDL_GamepadButton button, bool down);
static bool HasSameOutput(SDL_GamepadBinding *a, SDL_GamepadBinding *b)
{
@ -174,7 +174,7 @@ static void ResetOutput(Uint64 timestamp, SDL_Gamepad *gamepad, SDL_GamepadBindi
if (bind->output_type == SDL_GAMEPAD_BINDTYPE_AXIS) {
SDL_SendGamepadAxis(timestamp, gamepad, bind->output.axis.axis, 0);
} else {
SDL_SendGamepadButton(timestamp, gamepad, bind->output.button, SDL_RELEASED);
SDL_SendGamepadButton(timestamp, gamepad, bind->output.button, false);
}
}
@ -220,20 +220,20 @@ static void HandleJoystickAxis(Uint64 timestamp, SDL_Gamepad *gamepad, int axis,
}
SDL_SendGamepadAxis(timestamp, gamepad, match->output.axis.axis, (Sint16)value);
} else {
Uint8 state;
bool down;
int threshold = match->input.axis.axis_min + (match->input.axis.axis_max - match->input.axis.axis_min) / 2;
if (match->input.axis.axis_max < match->input.axis.axis_min) {
state = (value <= threshold) ? SDL_PRESSED : SDL_RELEASED;
down = (value <= threshold);
} else {
state = (value >= threshold) ? SDL_PRESSED : SDL_RELEASED;
down = (value >= threshold);
}
SDL_SendGamepadButton(timestamp, gamepad, match->output.button, state);
SDL_SendGamepadButton(timestamp, gamepad, match->output.button, down);
}
}
gamepad->last_match_axis[axis] = match;
}
static void HandleJoystickButton(Uint64 timestamp, SDL_Gamepad *gamepad, int button, Uint8 state)
static void HandleJoystickButton(Uint64 timestamp, SDL_Gamepad *gamepad, int button, bool down)
{
int i;
@ -244,10 +244,10 @@ static void HandleJoystickButton(Uint64 timestamp, SDL_Gamepad *gamepad, int but
if (binding->input_type == SDL_GAMEPAD_BINDTYPE_BUTTON &&
button == binding->input.button) {
if (binding->output_type == SDL_GAMEPAD_BINDTYPE_AXIS) {
int value = state ? binding->output.axis.axis_max : binding->output.axis.axis_min;
int value = down ? binding->output.axis.axis_max : binding->output.axis.axis_min;
SDL_SendGamepadAxis(timestamp, gamepad, binding->output.axis.axis, (Sint16)value);
} else {
SDL_SendGamepadButton(timestamp, gamepad, binding->output.button, state);
SDL_SendGamepadButton(timestamp, gamepad, binding->output.button, down);
}
break;
}
@ -271,7 +271,7 @@ static void HandleJoystickHat(Uint64 timestamp, SDL_Gamepad *gamepad, int hat, U
if (binding->output_type == SDL_GAMEPAD_BINDTYPE_AXIS) {
SDL_SendGamepadAxis(timestamp, gamepad, binding->output.axis.axis, (Sint16)binding->output.axis.axis_max);
} else {
SDL_SendGamepadButton(timestamp, gamepad, binding->output.button, SDL_PRESSED);
SDL_SendGamepadButton(timestamp, gamepad, binding->output.button, true);
}
} else {
ResetOutput(timestamp, gamepad, binding);
@ -296,7 +296,7 @@ static void RecenterGamepad(SDL_Gamepad *gamepad)
for (i = 0; i < SDL_GAMEPAD_BUTTON_MAX; ++i) {
SDL_GamepadButton button = (SDL_GamepadButton)i;
if (SDL_GetGamepadButton(gamepad, button)) {
SDL_SendGamepadButton(timestamp, gamepad, button, SDL_RELEASED);
SDL_SendGamepadButton(timestamp, gamepad, button, false);
}
}
@ -386,7 +386,7 @@ static SDL_bool SDLCALL SDL_GamepadEventWatcher(void *userdata, SDL_Event *event
for (gamepad = SDL_gamepads; gamepad; gamepad = gamepad->next) {
if (gamepad->joystick->instance_id == event->jbutton.which) {
HandleJoystickButton(event->common.timestamp, gamepad, event->jbutton.button, event->jbutton.state);
HandleJoystickButton(event->common.timestamp, gamepad, event->jbutton.button, event->jbutton.down);
break;
}
}
@ -2810,8 +2810,7 @@ Sint16 SDL_GetGamepadAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis)
value = 0;
}
} else if (binding->input_type == SDL_GAMEPAD_BINDTYPE_BUTTON) {
value = SDL_GetJoystickButton(gamepad->joystick, binding->input.button);
if (value == SDL_PRESSED) {
if (SDL_GetJoystickButton(gamepad->joystick, binding->input.button)) {
value = binding->output.axis.axis_max;
}
} else if (binding->input_type == SDL_GAMEPAD_BINDTYPE_HAT) {
@ -2868,15 +2867,15 @@ SDL_bool SDL_GamepadHasButton(SDL_Gamepad *gamepad, SDL_GamepadButton button)
/*
* Get the current state of a button on a gamepad
*/
Uint8 SDL_GetGamepadButton(SDL_Gamepad *gamepad, SDL_GamepadButton button)
SDL_bool SDL_GetGamepadButton(SDL_Gamepad *gamepad, SDL_GamepadButton button)
{
Uint8 result = SDL_RELEASED;
bool result = false;
SDL_LockJoysticks();
{
int i;
CHECK_GAMEPAD_MAGIC(gamepad, 0);
CHECK_GAMEPAD_MAGIC(gamepad, false);
for (i = 0; i < gamepad->num_bindings; ++i) {
SDL_GamepadBinding *binding = &gamepad->bindings[i];
@ -2889,13 +2888,13 @@ Uint8 SDL_GetGamepadButton(SDL_Gamepad *gamepad, SDL_GamepadButton button)
if (binding->input.axis.axis_min < binding->input.axis.axis_max) {
valid_input_range = (value >= binding->input.axis.axis_min && value <= binding->input.axis.axis_max);
if (valid_input_range) {
result = (value >= threshold) ? SDL_PRESSED : SDL_RELEASED;
result = (value >= threshold);
break;
}
} else {
valid_input_range = (value >= binding->input.axis.axis_max && value <= binding->input.axis.axis_min);
if (valid_input_range) {
result = (value <= threshold) ? SDL_PRESSED : SDL_RELEASED;
result = (value <= threshold);
break;
}
}
@ -2904,7 +2903,7 @@ Uint8 SDL_GetGamepadButton(SDL_Gamepad *gamepad, SDL_GamepadButton button)
break;
} else if (binding->input_type == SDL_GAMEPAD_BINDTYPE_HAT) {
int hat_mask = SDL_GetJoystickHat(gamepad->joystick, binding->input.hat.hat);
result = (hat_mask & binding->input.hat.hat_mask) ? SDL_PRESSED : SDL_RELEASED;
result = ((hat_mask & binding->input.hat.hat_mask) != 0);
break;
}
}
@ -3054,7 +3053,7 @@ int SDL_GetNumGamepadTouchpadFingers(SDL_Gamepad *gamepad, int touchpad)
/**
* Get the current state of a finger on a touchpad on a gamepad.
*/
SDL_bool SDL_GetGamepadTouchpadFinger(SDL_Gamepad *gamepad, int touchpad, int finger, Uint8 *state, float *x, float *y, float *pressure)
SDL_bool SDL_GetGamepadTouchpadFinger(SDL_Gamepad *gamepad, int touchpad, int finger, SDL_bool *down, float *x, float *y, float *pressure)
{
bool result = false;
@ -3067,8 +3066,8 @@ SDL_bool SDL_GetGamepadTouchpadFinger(SDL_Gamepad *gamepad, int touchpad, int fi
if (finger >= 0 && finger < touchpad_info->nfingers) {
SDL_JoystickTouchpadFingerInfo *info = &touchpad_info->fingers[finger];
if (state) {
*state = info->state;
if (down) {
*down = info->down;
}
if (x) {
*x = info->x;
@ -3732,7 +3731,7 @@ static void SDL_SendGamepadAxis(Uint64 timestamp, SDL_Gamepad *gamepad, SDL_Game
}
}
static void SDL_SendGamepadButton(Uint64 timestamp, SDL_Gamepad *gamepad, SDL_GamepadButton button, Uint8 state)
static void SDL_SendGamepadButton(Uint64 timestamp, SDL_Gamepad *gamepad, SDL_GamepadButton button, bool down)
{
SDL_Event event;
@ -3742,21 +3741,15 @@ static void SDL_SendGamepadButton(Uint64 timestamp, SDL_Gamepad *gamepad, SDL_Ga
return;
}
switch (state) {
case SDL_PRESSED:
if (down) {
event.type = SDL_EVENT_GAMEPAD_BUTTON_DOWN;
break;
case SDL_RELEASED:
} else {
event.type = SDL_EVENT_GAMEPAD_BUTTON_UP;
break;
default:
// Invalid state -- bail
return;
}
if (button == SDL_GAMEPAD_BUTTON_GUIDE) {
Uint64 now = SDL_GetTicks();
if (state == SDL_PRESSED) {
if (down) {
gamepad->guide_button_down = now;
if (gamepad->joystick->delayed_guide_button) {
@ -3777,7 +3770,7 @@ static void SDL_SendGamepadButton(Uint64 timestamp, SDL_Gamepad *gamepad, SDL_Ga
event.common.timestamp = timestamp;
event.gbutton.which = gamepad->joystick->instance_id;
event.gbutton.button = button;
event.gbutton.state = state;
event.gbutton.down = down;
SDL_PushEvent(&event);
}
}
@ -3826,7 +3819,7 @@ void SDL_GamepadHandleDelayedGuideButton(SDL_Joystick *joystick)
for (gamepad = SDL_gamepads; gamepad; gamepad = gamepad->next) {
if (gamepad->joystick == joystick) {
SDL_SendGamepadButton(0, gamepad, SDL_GAMEPAD_BUTTON_GUIDE, SDL_RELEASED);
SDL_SendGamepadButton(0, gamepad, SDL_GAMEPAD_BUTTON_GUIDE, false);
// Make sure we send an update complete event for this change
if (!gamepad->joystick->update_complete) {

View File

@ -1127,7 +1127,7 @@ SDL_Joystick *SDL_OpenJoystick(SDL_JoystickID instance_id)
joystick->hats = (Uint8 *)SDL_calloc(joystick->nhats, sizeof(*joystick->hats));
}
if (joystick->nbuttons > 0) {
joystick->buttons = (Uint8 *)SDL_calloc(joystick->nbuttons, sizeof(*joystick->buttons));
joystick->buttons = (SDL_bool *)SDL_calloc(joystick->nbuttons, sizeof(*joystick->buttons));
}
if (((joystick->naxes > 0) && !joystick->axes) ||
((joystick->nballs > 0) && !joystick->balls) ||
@ -1259,7 +1259,7 @@ SDL_bool SDL_SetJoystickVirtualBall(SDL_Joystick *joystick, int ball, Sint16 xre
return result;
}
SDL_bool SDL_SetJoystickVirtualButton(SDL_Joystick *joystick, int button, Uint8 value)
SDL_bool SDL_SetJoystickVirtualButton(SDL_Joystick *joystick, int button, SDL_bool down)
{
bool result;
@ -1268,7 +1268,7 @@ SDL_bool SDL_SetJoystickVirtualButton(SDL_Joystick *joystick, int button, Uint8
CHECK_JOYSTICK_MAGIC(joystick, false);
#ifdef SDL_JOYSTICK_VIRTUAL
result = SDL_SetJoystickVirtualButtonInner(joystick, button, value);
result = SDL_SetJoystickVirtualButtonInner(joystick, button, down);
#else
result = SDL_SetError("SDL not built with virtual-joystick support");
#endif
@ -1297,7 +1297,7 @@ SDL_bool SDL_SetJoystickVirtualHat(SDL_Joystick *joystick, int hat, Uint8 value)
return result;
}
SDL_bool SDL_SetJoystickVirtualTouchpad(SDL_Joystick *joystick, int touchpad, int finger, Uint8 state, float x, float y, float pressure)
SDL_bool SDL_SetJoystickVirtualTouchpad(SDL_Joystick *joystick, int touchpad, int finger, SDL_bool down, float x, float y, float pressure)
{
bool result;
@ -1306,7 +1306,7 @@ SDL_bool SDL_SetJoystickVirtualTouchpad(SDL_Joystick *joystick, int touchpad, in
CHECK_JOYSTICK_MAGIC(joystick, false);
#ifdef SDL_JOYSTICK_VIRTUAL
result = SDL_SetJoystickVirtualTouchpadInner(joystick, touchpad, finger, state, x, y, pressure);
result = SDL_SetJoystickVirtualTouchpadInner(joystick, touchpad, finger, down, x, y, pressure);
#else
result = SDL_SetError("SDL not built with virtual-joystick support");
#endif
@ -1528,24 +1528,23 @@ SDL_bool SDL_GetJoystickBall(SDL_Joystick *joystick, int ball, int *dx, int *dy)
/*
* Get the current state of a button on a joystick
*/
Uint8 SDL_GetJoystickButton(SDL_Joystick *joystick, int button)
SDL_bool SDL_GetJoystickButton(SDL_Joystick *joystick, int button)
{
Uint8 state;
bool down = false;
SDL_LockJoysticks();
{
CHECK_JOYSTICK_MAGIC(joystick, 0);
CHECK_JOYSTICK_MAGIC(joystick, false);
if (button < joystick->nbuttons) {
state = joystick->buttons[button];
down = joystick->buttons[button];
} else {
SDL_SetError("Joystick only has %d buttons", joystick->nbuttons);
state = 0;
}
}
SDL_UnlockJoysticks();
return state;
return down;
}
/*
@ -2113,7 +2112,7 @@ void SDL_PrivateJoystickForceRecentering(SDL_Joystick *joystick)
}
for (i = 0; i < joystick->nbuttons; i++) {
SDL_SendJoystickButton(timestamp, joystick, i, SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, i, false);
}
for (i = 0; i < joystick->nhats; i++) {
@ -2124,7 +2123,7 @@ void SDL_PrivateJoystickForceRecentering(SDL_Joystick *joystick)
SDL_JoystickTouchpadInfo *touchpad = &joystick->touchpads[i];
for (j = 0; j < touchpad->nfingers; ++j) {
SDL_SendJoystickTouchpad(timestamp, joystick, i, j, SDL_RELEASED, 0.0f, 0.0f, 0.0f);
SDL_SendJoystickTouchpad(timestamp, joystick, i, j, false, 0.0f, 0.0f, 0.0f);
}
}
}
@ -2297,43 +2296,37 @@ void SDL_SendJoystickHat(Uint64 timestamp, SDL_Joystick *joystick, Uint8 hat, Ui
}
}
void SDL_SendJoystickButton(Uint64 timestamp, SDL_Joystick *joystick, Uint8 button, Uint8 state)
void SDL_SendJoystickButton(Uint64 timestamp, SDL_Joystick *joystick, Uint8 button, bool down)
{
SDL_Event event;
SDL_AssertJoysticksLocked();
switch (state) {
case SDL_PRESSED:
if (down) {
event.type = SDL_EVENT_JOYSTICK_BUTTON_DOWN;
break;
case SDL_RELEASED:
} else {
event.type = SDL_EVENT_JOYSTICK_BUTTON_UP;
break;
default:
// Invalid state -- bail
return;
}
// Make sure we're not getting garbage or duplicate events
if (button >= joystick->nbuttons) {
return;
}
if (state == joystick->buttons[button]) {
if (down == joystick->buttons[button]) {
return;
}
/* We ignore events if we don't have keyboard focus, except for button
* release. */
if (SDL_PrivateJoystickShouldIgnoreEvent()) {
if (state == SDL_PRESSED) {
if (down) {
return;
}
}
// Update internal joystick state
SDL_assert(timestamp != 0);
joystick->buttons[button] = state;
joystick->buttons[button] = down;
joystick->update_complete = timestamp;
// Post the event, if desired
@ -2341,7 +2334,7 @@ void SDL_SendJoystickButton(Uint64 timestamp, SDL_Joystick *joystick, Uint8 butt
event.common.timestamp = timestamp;
event.jbutton.which = joystick->instance_id;
event.jbutton.button = button;
event.jbutton.state = state;
event.jbutton.down = down;
SDL_PushEvent(&event);
}
}
@ -3515,7 +3508,7 @@ SDL_PowerState SDL_GetJoystickPowerInfo(SDL_Joystick *joystick, int *percent)
return result;
}
void SDL_SendJoystickTouchpad(Uint64 timestamp, SDL_Joystick *joystick, int touchpad, int finger, Uint8 state, float x, float y, float pressure)
void SDL_SendJoystickTouchpad(Uint64 timestamp, SDL_Joystick *joystick, int touchpad, int finger, bool down, float x, float y, float pressure)
{
SDL_JoystickTouchpadInfo *touchpad_info;
SDL_JoystickTouchpadFingerInfo *finger_info;
@ -3534,7 +3527,7 @@ void SDL_SendJoystickTouchpad(Uint64 timestamp, SDL_Joystick *joystick, int touc
finger_info = &touchpad_info->fingers[finger];
if (!state) {
if (!down) {
if (x == 0.0f && y == 0.0f) {
x = finger_info->x;
y = finger_info->y;
@ -3558,16 +3551,16 @@ void SDL_SendJoystickTouchpad(Uint64 timestamp, SDL_Joystick *joystick, int touc
pressure = 1.0f;
}
if (state == finger_info->state) {
if (!state ||
if (down == finger_info->down) {
if (!down ||
(x == finger_info->x && y == finger_info->y && pressure == finger_info->pressure)) {
return;
}
}
if (state == finger_info->state) {
if (down == finger_info->down) {
event_type = SDL_EVENT_GAMEPAD_TOUCHPAD_MOTION;
} else if (state) {
} else if (down) {
event_type = SDL_EVENT_GAMEPAD_TOUCHPAD_DOWN;
} else {
event_type = SDL_EVENT_GAMEPAD_TOUCHPAD_UP;
@ -3582,7 +3575,7 @@ void SDL_SendJoystickTouchpad(Uint64 timestamp, SDL_Joystick *joystick, int touc
// Update internal joystick state
SDL_assert(timestamp != 0);
finger_info->state = state;
finger_info->down = down;
finger_info->x = x;
finger_info->y = y;
finger_info->pressure = pressure;

View File

@ -164,8 +164,8 @@ extern void SDL_PrivateJoystickForceRecentering(SDL_Joystick *joystick);
extern void SDL_SendJoystickAxis(Uint64 timestamp, SDL_Joystick *joystick, Uint8 axis, Sint16 value);
extern void SDL_SendJoystickBall(Uint64 timestamp, SDL_Joystick *joystick, Uint8 ball, Sint16 xrel, Sint16 yrel);
extern void SDL_SendJoystickHat(Uint64 timestamp, SDL_Joystick *joystick, Uint8 hat, Uint8 value);
extern void SDL_SendJoystickButton(Uint64 timestamp, SDL_Joystick *joystick, Uint8 button, Uint8 state);
extern void SDL_SendJoystickTouchpad(Uint64 timestamp, SDL_Joystick *joystick, int touchpad, int finger, Uint8 state, float x, float y, float pressure);
extern void SDL_SendJoystickButton(Uint64 timestamp, SDL_Joystick *joystick, Uint8 button, bool down);
extern void SDL_SendJoystickTouchpad(Uint64 timestamp, SDL_Joystick *joystick, int touchpad, int finger, bool down, float x, float y, float pressure);
extern void SDL_SendJoystickSensor(Uint64 timestamp, SDL_Joystick *joystick, SDL_SensorType type, Uint64 sensor_timestamp, const float *data, int num_values);
extern void SDL_SendJoystickPowerInfo(SDL_Joystick *joystick, SDL_PowerState state, int percent);

View File

@ -52,7 +52,7 @@ typedef struct SDL_JoystickBallData
typedef struct SDL_JoystickTouchpadFingerInfo
{
Uint8 state;
bool down;
float x;
float y;
float pressure;
@ -94,7 +94,7 @@ struct SDL_Joystick
Uint8 *hats _guarded; // Current hat states
int nbuttons _guarded; // Number of buttons on the joystick
Uint8 *buttons _guarded; // Current button states
bool *buttons _guarded; // Current button states
int ntouchpads _guarded; // Number of touchpads on the joystick
SDL_JoystickTouchpadInfo *touchpads _guarded; // Current touchpad states

View File

@ -203,9 +203,9 @@ bool Android_OnPadDown(int device_id, int keycode)
SDL_LockJoysticks();
item = JoystickByDeviceId(device_id);
if (item && item->joystick) {
SDL_SendJoystickButton(timestamp, item->joystick, button, SDL_PRESSED);
SDL_SendJoystickButton(timestamp, item->joystick, button, true);
} else {
SDL_SendKeyboardKey(timestamp, SDL_GLOBAL_KEYBOARD_ID, keycode, button_to_scancode(button), SDL_PRESSED);
SDL_SendKeyboardKey(timestamp, SDL_GLOBAL_KEYBOARD_ID, keycode, button_to_scancode(button), true);
}
SDL_UnlockJoysticks();
return true;
@ -223,9 +223,9 @@ bool Android_OnPadUp(int device_id, int keycode)
SDL_LockJoysticks();
item = JoystickByDeviceId(device_id);
if (item && item->joystick) {
SDL_SendJoystickButton(timestamp, item->joystick, button, SDL_RELEASED);
SDL_SendJoystickButton(timestamp, item->joystick, button, false);
} else {
SDL_SendKeyboardKey(timestamp, SDL_GLOBAL_KEYBOARD_ID, keycode, button_to_scancode(button), SDL_RELEASED);
SDL_SendKeyboardKey(timestamp, SDL_GLOBAL_KEYBOARD_ID, keycode, button_to_scancode(button), false);
}
SDL_UnlockJoysticks();
return true;
@ -280,16 +280,20 @@ bool Android_OnHat(int device_id, int hat_id, int x, int y)
dpad_delta = (dpad_state ^ item->dpad_state);
if (dpad_delta) {
if (dpad_delta & DPAD_UP_MASK) {
SDL_SendJoystickButton(timestamp, item->joystick, SDL_GAMEPAD_BUTTON_DPAD_UP, (dpad_state & DPAD_UP_MASK) ? SDL_PRESSED : SDL_RELEASED);
bool down = ((dpad_state & DPAD_UP_MASK) != 0);
SDL_SendJoystickButton(timestamp, item->joystick, SDL_GAMEPAD_BUTTON_DPAD_UP, down);
}
if (dpad_delta & DPAD_DOWN_MASK) {
SDL_SendJoystickButton(timestamp, item->joystick, SDL_GAMEPAD_BUTTON_DPAD_DOWN, (dpad_state & DPAD_DOWN_MASK) ? SDL_PRESSED : SDL_RELEASED);
bool down = ((dpad_state & DPAD_DOWN_MASK) != 0);
SDL_SendJoystickButton(timestamp, item->joystick, SDL_GAMEPAD_BUTTON_DPAD_DOWN, down);
}
if (dpad_delta & DPAD_LEFT_MASK) {
SDL_SendJoystickButton(timestamp, item->joystick, SDL_GAMEPAD_BUTTON_DPAD_LEFT, (dpad_state & DPAD_LEFT_MASK) ? SDL_PRESSED : SDL_RELEASED);
bool down = ((dpad_state & DPAD_LEFT_MASK) != 0);
SDL_SendJoystickButton(timestamp, item->joystick, SDL_GAMEPAD_BUTTON_DPAD_LEFT, down);
}
if (dpad_delta & DPAD_RIGHT_MASK) {
SDL_SendJoystickButton(timestamp, item->joystick, SDL_GAMEPAD_BUTTON_DPAD_RIGHT, (dpad_state & DPAD_RIGHT_MASK) ? SDL_PRESSED : SDL_RELEASED);
bool down = ((dpad_state & DPAD_RIGHT_MASK) != 0);
SDL_SendJoystickButton(timestamp, item->joystick, SDL_GAMEPAD_BUTTON_DPAD_RIGHT, down);
}
item->dpad_state = dpad_state;
}

View File

@ -1105,13 +1105,13 @@ static void IOS_MFIJoystickUpdate(SDL_Joystick *joystick)
int button = 0;
for (id key in device->buttons) {
Uint8 value;
bool down;
if (button == device->pause_button_index) {
value = (device->pause_button_pressed > 0);
down = (device->pause_button_pressed > 0);
} else {
value = buttons[key].isPressed;
down = buttons[key].isPressed;
}
SDL_SendJoystickButton(timestamp, joystick, button++, value);
SDL_SendJoystickButton(timestamp, joystick, button++, down);
}
} else
#endif
@ -1130,7 +1130,7 @@ static void IOS_MFIJoystickUpdate(SDL_Joystick *joystick)
};
// Button order matches the XInput Windows mappings.
Uint8 *buttons = SDL_small_alloc(Uint8, joystick->nbuttons, &isstack);
bool *buttons = SDL_small_alloc(bool, joystick->nbuttons, &isstack);
int button_count = 0;
if (buttons == NULL) {
@ -1186,7 +1186,7 @@ static void IOS_MFIJoystickUpdate(SDL_Joystick *joystick)
GCGamepad *gamepad = controller.gamepad;
// Button order matches the XInput Windows mappings.
Uint8 *buttons = SDL_small_alloc(Uint8, joystick->nbuttons, &isstack);
bool *buttons = SDL_small_alloc(bool, joystick->nbuttons, &isstack);
int button_count = 0;
if (buttons == NULL) {
@ -1222,7 +1222,7 @@ static void IOS_MFIJoystickUpdate(SDL_Joystick *joystick)
SDL_SendJoystickAxis(timestamp, joystick, i, axes[i]);
}
Uint8 buttons[joystick->nbuttons];
bool buttons[joystick->nbuttons];
int button_count = 0;
buttons[button_count++] = gamepad.buttonA.isPressed;
buttons[button_count++] = gamepad.buttonX.isPressed;
@ -1253,16 +1253,16 @@ static void IOS_MFIJoystickUpdate(SDL_Joystick *joystick)
dpad = controller.physicalInputProfile.dpads[GCInputDualShockTouchpadOne];
if (dpad.xAxis.value != 0.f || dpad.yAxis.value != 0.f) {
SDL_SendJoystickTouchpad(timestamp, joystick, 0, 0, SDL_PRESSED, (1.0f + dpad.xAxis.value) * 0.5f, 1.0f - (1.0f + dpad.yAxis.value) * 0.5f, 1.0f);
SDL_SendJoystickTouchpad(timestamp, joystick, 0, 0, true, (1.0f + dpad.xAxis.value) * 0.5f, 1.0f - (1.0f + dpad.yAxis.value) * 0.5f, 1.0f);
} else {
SDL_SendJoystickTouchpad(timestamp, joystick, 0, 0, SDL_RELEASED, 0.0f, 0.0f, 1.0f);
SDL_SendJoystickTouchpad(timestamp, joystick, 0, 0, false, 0.0f, 0.0f, 1.0f);
}
dpad = controller.physicalInputProfile.dpads[GCInputDualShockTouchpadTwo];
if (dpad.xAxis.value != 0.f || dpad.yAxis.value != 0.f) {
SDL_SendJoystickTouchpad(timestamp, joystick, 0, 1, SDL_PRESSED, (1.0f + dpad.xAxis.value) * 0.5f, 1.0f - (1.0f + dpad.yAxis.value) * 0.5f, 1.0f);
SDL_SendJoystickTouchpad(timestamp, joystick, 0, 1, true, (1.0f + dpad.xAxis.value) * 0.5f, 1.0f - (1.0f + dpad.yAxis.value) * 0.5f, 1.0f);
} else {
SDL_SendJoystickTouchpad(timestamp, joystick, 0, 1, SDL_RELEASED, 0.0f, 0.0f, 1.0f);
SDL_SendJoystickTouchpad(timestamp, joystick, 0, 1, false, 0.0f, 0.0f, 1.0f);
}
}
}

View File

@ -650,8 +650,8 @@ static void BSD_JoystickUpdate(SDL_Joystick *joy)
v = (((SDL_JOYSTICK_AXIS_MAX - SDL_JOYSTICK_AXIS_MIN) * ((Sint32)y - ymin)) / (ymax - ymin)) + SDL_JOYSTICK_AXIS_MIN;
SDL_SendJoystickAxis(timestamp, joy, 1, v);
}
SDL_SendJoystickButton(timestamp, joy, 0, gameport.b1);
SDL_SendJoystickButton(timestamp, joy, 1, gameport.b2);
SDL_SendJoystickButton(timestamp, joy, 0, (gameport.b1 != 0));
SDL_SendJoystickButton(timestamp, joy, 1, (gameport.b2 != 0));
}
return;
}
@ -720,7 +720,7 @@ static void BSD_JoystickUpdate(SDL_Joystick *joy)
case HUP_BUTTON:
v = (Sint32)hid_get_data(REP_BUF_DATA(rep), &hitem);
nbutton = HID_USAGE(hitem.usage) - 1; // SDL buttons are zero-based
SDL_SendJoystickButton(timestamp, joy, nbutton, v);
SDL_SendJoystickButton(timestamp, joy, nbutton, (v != 0));
break;
default:
continue;

View File

@ -967,10 +967,7 @@ static void DARWIN_JoystickUpdate(SDL_Joystick *joystick)
while (element) {
goodRead = GetHIDElementState(device, element, &value);
if (goodRead) {
if (value > 1) { // handle pressure-sensitive buttons
value = 1;
}
SDL_SendJoystickButton(timestamp, joystick, i, value);
SDL_SendJoystickButton(timestamp, joystick, i, (value != 0));
}
element = element->pNext;

View File

@ -325,7 +325,7 @@ static void EMSCRIPTEN_JoystickUpdate(SDL_Joystick *joystick)
{
EmscriptenGamepadEvent gamepadState;
SDL_joylist_item *item = (SDL_joylist_item *)joystick->hwdata;
int i, result, buttonState;
int i, result;
Uint64 timestamp = SDL_GetTicksNS();
emscripten_sample_gamepad_data();
@ -336,8 +336,8 @@ static void EMSCRIPTEN_JoystickUpdate(SDL_Joystick *joystick)
if (gamepadState.timestamp == 0 || gamepadState.timestamp != item->timestamp) {
for (i = 0; i < item->nbuttons; i++) {
if (item->digitalButton[i] != gamepadState.digitalButton[i]) {
buttonState = gamepadState.digitalButton[i] ? SDL_PRESSED : SDL_RELEASED;
SDL_SendJoystickButton(timestamp, item->joystick, i, buttonState);
bool down = (gamepadState.digitalButton[i] != 0);
SDL_SendJoystickButton(timestamp, item->joystick, i, down);
}
// store values to compare them in the next update

View File

@ -419,10 +419,12 @@ static void CALLBACK GAMEINPUT_InternalSystemButtonCallback(
SDL_LockJoysticks();
if (changedButtons & GameInputSystemButtonGuide) {
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, (currentButtons & GameInputSystemButtonGuide) ? SDL_PRESSED : SDL_RELEASED);
bool down = ((currentButtons & GameInputSystemButtonGuide) != 0);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, down);
}
if (changedButtons & GameInputSystemButtonShare) {
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GAMEINPUT_SHARE, (currentButtons & GameInputSystemButtonShare) ? SDL_PRESSED : SDL_RELEASED);
bool down = ((currentButtons & GameInputSystemButtonShare) != 0);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GAMEINPUT_SHARE, down);
}
SDL_UnlockJoysticks();
}
@ -567,7 +569,7 @@ static void GAMEINPUT_JoystickUpdate(SDL_Joystick *joystick)
GameInputGamepadLeftShoulder, // SDL_GAMEPAD_BUTTON_LEFT_SHOULDER
GameInputGamepadRightShoulder, // SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER
};
Uint8 btnidx = 0, btnstate = 0, hat = 0;
Uint8 btnidx = 0, hat = 0;
if (IGameInputReading_GetGamepadState(reading, &state)) {
for (btnidx = 0; btnidx < SDL_arraysize(s_XInputButtons); ++btnidx) {
@ -575,8 +577,8 @@ static void GAMEINPUT_JoystickUpdate(SDL_Joystick *joystick)
if (!button_mask) {
continue;
}
btnstate = (state.buttons & button_mask) ? SDL_PRESSED : SDL_RELEASED;
SDL_SendJoystickButton(timestamp, joystick, btnidx, btnstate);
bool down = ((state.buttons & button_mask) != 0);
SDL_SendJoystickButton(timestamp, joystick, btnidx, down);
}
if (state.buttons & GameInputGamepadDPadUp) {
@ -637,7 +639,7 @@ static void GAMEINPUT_JoystickUpdate(SDL_Joystick *joystick)
for (i = 0; i < touch_count; ++i) {
GameInputTouchState *touch = &touch_state[i];
// FIXME: We should use touch->touchId to track fingers instead of using i below
SDL_SendJoystickTouchpad(timestamp, joystick, 0, i, SDL_PRESSED, touch->positionX * info->touchSensorInfo[i].resolutionX, touch->positionY * info->touchSensorInfo[0].resolutionY, touch->pressure);
SDL_SendJoystickTouchpad(timestamp, joystick, 0, i, true, touch->positionX * info->touchSensorInfo[i].resolutionX, touch->positionY * info->touchSensorInfo[0].resolutionY, touch->pressure);
}
SDL_stack_free(touch_state);
}

View File

@ -212,7 +212,8 @@ extern "C"
// Generate button events
for (i = 0; i < joystick->nbuttons; ++i) {
SDL_SendJoystickButton(timestamp, joystick, i, (buttons & 0x01));
bool down = ((buttons & 0x01) != 0);
SDL_SendJoystickButton(timestamp, joystick, i, down);
buttons >>= 1;
}
}

View File

@ -231,7 +231,7 @@ static void HIDAPI_DriverGameCube_HandleJoystickPacket(SDL_HIDAPI_Device *device
timestamp, \
joystick, \
button, \
(packet[off] & flag) ? SDL_PRESSED : SDL_RELEASED);
((packet[off] & flag) != 0));
READ_BUTTON(1, 0x02, 0) // A
READ_BUTTON(1, 0x04, 1) // B
READ_BUTTON(1, 0x08, 3) // Y
@ -314,7 +314,7 @@ static void HIDAPI_DriverGameCube_HandleNintendoPacket(SDL_HIDAPI_Device *device
timestamp, \
joystick, \
button, \
(curSlot[off] & flag) ? SDL_PRESSED : SDL_RELEASED);
((curSlot[off] & flag) != 0));
READ_BUTTON(1, 0x01, 0) // A
READ_BUTTON(1, 0x02, 1) // B
READ_BUTTON(1, 0x04, 2) // X

View File

@ -168,20 +168,20 @@ static void HIDAPI_DriverLuna_HandleUSBStatePacket(SDL_Joystick *joystick, SDL_D
Uint64 timestamp = SDL_GetTicksNS();
if (ctx->last_state[1] != data[1]) {
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SOUTH, (data[1] & 0x01) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_EAST, (data[1] & 0x02) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_WEST, (data[1] & 0x04) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_NORTH, (data[1] & 0x08) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, (data[1] & 0x10) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, (data[1] & 0x20) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK, (data[1] & 0x40) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, (data[1] & 0x80) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SOUTH, ((data[1] & 0x01) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_EAST, ((data[1] & 0x02) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_WEST, ((data[1] & 0x04) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_NORTH, ((data[1] & 0x08) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, ((data[1] & 0x10) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, ((data[1] & 0x20) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK, ((data[1] & 0x40) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, ((data[1] & 0x80) != 0));
}
if (ctx->last_state[2] != data[2]) {
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, (data[2] & 0x01) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LUNA_MICROPHONE, (data[2] & 0x02) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, (data[2] & 0x04) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK, (data[2] & 0x08) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, ((data[2] & 0x01) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LUNA_MICROPHONE, ((data[2] & 0x02) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, ((data[2] & 0x04) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK, ((data[2] & 0x08) != 0));
}
if (ctx->last_state[3] != data[3]) {
@ -252,7 +252,7 @@ static void HIDAPI_DriverLuna_HandleBluetoothStatePacket(SDL_Joystick *joystick,
if (size >= 2 && data[0] == 0x02) {
// Home button has dedicated report
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, (data[1] & 0x1) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, ((data[1] & 0x1) != 0));
return;
}
@ -304,21 +304,21 @@ static void HIDAPI_DriverLuna_HandleBluetoothStatePacket(SDL_Joystick *joystick,
}
if (ctx->last_state[14] != data[14]) {
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SOUTH, (data[14] & 0x01) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_EAST, (data[14] & 0x02) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_WEST, (data[14] & 0x08) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_NORTH, (data[14] & 0x10) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, (data[14] & 0x40) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, (data[14] & 0x80) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SOUTH, ((data[14] & 0x01) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_EAST, ((data[14] & 0x02) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_WEST, ((data[14] & 0x08) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_NORTH, ((data[14] & 0x10) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, ((data[14] & 0x40) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, ((data[14] & 0x80) != 0));
}
if (ctx->last_state[15] != data[15]) {
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, (data[15] & 0x08) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, (data[15] & 0x20) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK, (data[15] & 0x40) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, ((data[15] & 0x08) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, ((data[15] & 0x20) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK, ((data[15] & 0x40) != 0));
}
if (ctx->last_state[16] != data[16]) {
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK, (data[16] & 0x01) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LUNA_MICROPHONE, (data[16] & 0x02) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK, ((data[16] & 0x01) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LUNA_MICROPHONE, ((data[16] & 0x02) != 0));
}
#define READ_STICK_AXIS(offset) \

View File

@ -388,21 +388,21 @@ static void HIDAPI_DriverPS3_HandleMiniStatePacket(SDL_Joystick *joystick, SDL_D
}
SDL_SendJoystickHat(timestamp, joystick, 0, hat);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_NORTH, (data[4] & 0x10) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_EAST, (data[4] & 0x20) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SOUTH, (data[4] & 0x40) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_WEST, (data[4] & 0x80) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_NORTH, ((data[4] & 0x10) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_EAST, ((data[4] & 0x20) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SOUTH, ((data[4] & 0x40) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_WEST, ((data[4] & 0x80) != 0));
}
if (ctx->last_state[5] != data[5]) {
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, (data[5] & 0x01) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, (data[5] & 0x02) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, ((data[5] & 0x01) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, ((data[5] & 0x02) != 0));
SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFT_TRIGGER, (data[5] & 0x04) ? SDL_JOYSTICK_AXIS_MAX : SDL_JOYSTICK_AXIS_MIN);
SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHT_TRIGGER, (data[5] & 0x08) ? SDL_JOYSTICK_AXIS_MAX : SDL_JOYSTICK_AXIS_MIN);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK, (data[5] & 0x10) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, (data[5] & 0x20) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, (data[5] & 0x40) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK, (data[5] & 0x80) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK, ((data[5] & 0x10) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, ((data[5] & 0x20) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, ((data[5] & 0x40) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK, ((data[5] & 0x80) != 0));
}
axis = ((int)data[2] * 257) - 32768;
@ -425,10 +425,10 @@ static void HIDAPI_DriverPS3_HandleStatePacket(SDL_Joystick *joystick, SDL_Drive
if (ctx->last_state[2] != data[2]) {
Uint8 hat = 0;
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK, (data[2] & 0x01) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, (data[2] & 0x02) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK, (data[2] & 0x04) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, (data[2] & 0x08) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK, ((data[2] & 0x01) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, ((data[2] & 0x02) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK, ((data[2] & 0x04) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, ((data[2] & 0x08) != 0));
if (data[2] & 0x10) {
hat |= SDL_HAT_UP;
@ -446,16 +446,16 @@ static void HIDAPI_DriverPS3_HandleStatePacket(SDL_Joystick *joystick, SDL_Drive
}
if (ctx->last_state[3] != data[3]) {
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, (data[3] & 0x04) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, (data[3] & 0x08) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_NORTH, (data[3] & 0x10) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_EAST, (data[3] & 0x20) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SOUTH, (data[3] & 0x40) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_WEST, (data[3] & 0x80) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, ((data[3] & 0x04) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, ((data[3] & 0x08) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_NORTH, ((data[3] & 0x10) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_EAST, ((data[3] & 0x20) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SOUTH, ((data[3] & 0x40) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_WEST, ((data[3] & 0x80) != 0));
}
if (ctx->last_state[4] != data[4]) {
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, (data[4] & 0x01) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, ((data[4] & 0x01) != 0));
}
axis = ((int)data[18] * 257) - 32768;
@ -744,21 +744,21 @@ static void HIDAPI_DriverPS3ThirdParty_HandleStatePacket18(SDL_Joystick *joystic
Uint64 timestamp = SDL_GetTicksNS();
if (ctx->last_state[0] != data[0]) {
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_WEST, (data[0] & 0x01) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SOUTH, (data[0] & 0x02) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_EAST, (data[0] & 0x04) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_NORTH, (data[0] & 0x08) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, (data[0] & 0x10) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, (data[0] & 0x20) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_WEST, ((data[0] & 0x01) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SOUTH, ((data[0] & 0x02) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_EAST, ((data[0] & 0x04) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_NORTH, ((data[0] & 0x08) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, ((data[0] & 0x10) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, ((data[0] & 0x20) != 0));
}
if (ctx->last_state[1] != data[1]) {
Uint8 hat;
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK, (data[1] & 0x01) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, (data[1] & 0x02) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, (data[1] & 0x04) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK, (data[1] & 0x08) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK, ((data[1] & 0x01) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, ((data[1] & 0x02) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, ((data[1] & 0x04) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK, ((data[1] & 0x08) != 0));
switch (data[1] >> 4) {
case 0:
@ -848,20 +848,20 @@ static void HIDAPI_DriverPS3ThirdParty_HandleStatePacket19(SDL_Joystick *joystic
Uint64 timestamp = SDL_GetTicksNS();
if (ctx->last_state[0] != data[0]) {
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_WEST, (data[0] & 0x01) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SOUTH, (data[0] & 0x02) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_EAST, (data[0] & 0x04) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_NORTH, (data[0] & 0x08) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, (data[0] & 0x10) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, (data[0] & 0x20) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_WEST, ((data[0] & 0x01) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SOUTH, ((data[0] & 0x02) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_EAST, ((data[0] & 0x04) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_NORTH, ((data[0] & 0x08) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, ((data[0] & 0x10) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, ((data[0] & 0x20) != 0));
}
if (ctx->last_state[1] != data[1]) {
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK, (data[1] & 0x01) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, (data[1] & 0x02) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, (data[1] & 0x04) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK, (data[1] & 0x08) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, (data[1] & 0x10) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK, ((data[1] & 0x01) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, ((data[1] & 0x02) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, ((data[1] & 0x04) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK, ((data[1] & 0x08) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, ((data[1] & 0x10) != 0));
}
if (ctx->device->vendor_id == USB_VENDOR_SAITEK && ctx->device->product_id == USB_PRODUCT_SAITEK_CYBORG_V3) {
@ -1227,10 +1227,10 @@ static void HIDAPI_DriverPS3SonySixaxis_HandleStatePacket(SDL_Joystick *joystick
if (ctx->last_state[2] != data[2]) {
Uint8 hat = 0;
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK, (data[2] & 0x01) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, (data[2] & 0x02) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK, (data[2] & 0x04) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, (data[2] & 0x08) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK, ((data[2] & 0x01) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, ((data[2] & 0x02) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK, ((data[2] & 0x04) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, ((data[2] & 0x08) != 0));
if (data[2] & 0x10) {
hat |= SDL_HAT_UP;
@ -1248,16 +1248,16 @@ static void HIDAPI_DriverPS3SonySixaxis_HandleStatePacket(SDL_Joystick *joystick
}
if (ctx->last_state[3] != data[3]) {
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, (data[3] & 0x04) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, (data[3] & 0x08) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_NORTH, (data[3] & 0x10) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_EAST, (data[3] & 0x20) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SOUTH, (data[3] & 0x40) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_WEST, (data[3] & 0x80) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, ((data[3] & 0x04) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, ((data[3] & 0x08) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_NORTH, ((data[3] & 0x10) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_EAST, ((data[3] & 0x20) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SOUTH, ((data[3] & 0x40) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_WEST, ((data[3] & 0x80) != 0));
}
if (ctx->last_state[4] != data[4]) {
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, (data[4] & 0x01) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, ((data[4] & 0x01) != 0));
}
axis = ((int)data[18] * 257) - 32768;

View File

@ -1010,7 +1010,7 @@ static void HIDAPI_DriverPS4_HandleStatePacket(SDL_Joystick *joystick, SDL_hid_d
static const float TOUCHPAD_SCALEX = 1.0f / 1920;
static const float TOUCHPAD_SCALEY = 1.0f / 920; // This is noted as being 944 resolution, but 920 feels better
Sint16 axis;
Uint8 touchpad_state;
bool touchpad_down;
int touchpad_x, touchpad_y;
Uint64 timestamp = SDL_GetTicksNS();
@ -1018,10 +1018,10 @@ static void HIDAPI_DriverPS4_HandleStatePacket(SDL_Joystick *joystick, SDL_hid_d
{
Uint8 data = (packet->rgucButtonsHatAndCounter[0] >> 4);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_WEST, (data & 0x01) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SOUTH, (data & 0x02) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_EAST, (data & 0x04) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_NORTH, (data & 0x08) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_WEST, ((data & 0x01) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SOUTH, ((data & 0x02) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_EAST, ((data & 0x04) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_NORTH, ((data & 0x08) != 0));
}
{
Uint8 hat;
@ -1063,12 +1063,12 @@ static void HIDAPI_DriverPS4_HandleStatePacket(SDL_Joystick *joystick, SDL_hid_d
if (ctx->last_state.rgucButtonsHatAndCounter[1] != packet->rgucButtonsHatAndCounter[1]) {
Uint8 data = packet->rgucButtonsHatAndCounter[1];
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, (data & 0x01) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, (data & 0x02) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK, (data & 0x10) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, (data & 0x20) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, (data & 0x40) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK, (data & 0x80) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, ((data & 0x01) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, ((data & 0x02) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK, ((data & 0x10) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, ((data & 0x20) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, ((data & 0x40) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK, ((data & 0x80) != 0));
}
/* Some fightsticks, ex: Victrix FS Pro will only this these digital trigger bits and not the analog values so this needs to run whenever the
@ -1083,8 +1083,8 @@ static void HIDAPI_DriverPS4_HandleStatePacket(SDL_Joystick *joystick, SDL_hid_d
if (ctx->last_state.rgucButtonsHatAndCounter[2] != packet->rgucButtonsHatAndCounter[2]) {
Uint8 data = (packet->rgucButtonsHatAndCounter[2] & 0x03);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, (data & 0x01) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_PS4_TOUCHPAD, (data & 0x02) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, ((data & 0x01) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_PS4_TOUCHPAD, ((data & 0x02) != 0));
}
axis = ((int)packet->ucTriggerLeft * 257) - 32768;
@ -1124,15 +1124,15 @@ static void HIDAPI_DriverPS4_HandleStatePacket(SDL_Joystick *joystick, SDL_hid_d
}
if (size > 9 && ctx->report_touchpad && ctx->enhanced_reports) {
touchpad_state = !(packet->ucTouchpadCounter1 & 0x80) ? SDL_PRESSED : SDL_RELEASED;
touchpad_down = ((packet->ucTouchpadCounter1 & 0x80) == 0);
touchpad_x = packet->rgucTouchpadData1[0] | (((int)packet->rgucTouchpadData1[1] & 0x0F) << 8);
touchpad_y = (packet->rgucTouchpadData1[1] >> 4) | ((int)packet->rgucTouchpadData1[2] << 4);
SDL_SendJoystickTouchpad(timestamp, joystick, 0, 0, touchpad_state, touchpad_x * TOUCHPAD_SCALEX, touchpad_y * TOUCHPAD_SCALEY, touchpad_state ? 1.0f : 0.0f);
SDL_SendJoystickTouchpad(timestamp, joystick, 0, 0, touchpad_down, touchpad_x * TOUCHPAD_SCALEX, touchpad_y * TOUCHPAD_SCALEY, touchpad_down ? 1.0f : 0.0f);
touchpad_state = !(packet->ucTouchpadCounter2 & 0x80) ? SDL_PRESSED : SDL_RELEASED;
touchpad_down = ((packet->ucTouchpadCounter2 & 0x80) == 0);
touchpad_x = packet->rgucTouchpadData2[0] | (((int)packet->rgucTouchpadData2[1] & 0x0F) << 8);
touchpad_y = (packet->rgucTouchpadData2[1] >> 4) | ((int)packet->rgucTouchpadData2[2] << 4);
SDL_SendJoystickTouchpad(timestamp, joystick, 0, 1, touchpad_state, touchpad_x * TOUCHPAD_SCALEX, touchpad_y * TOUCHPAD_SCALEY, touchpad_state ? 1.0f : 0.0f);
SDL_SendJoystickTouchpad(timestamp, joystick, 0, 1, touchpad_down, touchpad_x * TOUCHPAD_SCALEX, touchpad_y * TOUCHPAD_SCALEY, touchpad_down ? 1.0f : 0.0f);
}
if (size > 9 && ctx->report_sensors) {

View File

@ -1137,10 +1137,10 @@ static void HIDAPI_DriverPS5_HandleSimpleStatePacket(SDL_Joystick *joystick, SDL
{
Uint8 data = (packet->rgucButtonsHatAndCounter[0] >> 4);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_WEST, (data & 0x01) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SOUTH, (data & 0x02) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_EAST, (data & 0x04) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_NORTH, (data & 0x08) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_WEST, ((data & 0x01) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SOUTH, ((data & 0x02) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_EAST, ((data & 0x04) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_NORTH, ((data & 0x08) != 0));
}
{
Uint8 data = (packet->rgucButtonsHatAndCounter[0] & 0x0F);
@ -1182,19 +1182,19 @@ static void HIDAPI_DriverPS5_HandleSimpleStatePacket(SDL_Joystick *joystick, SDL
if (ctx->last_state.simple.rgucButtonsHatAndCounter[1] != packet->rgucButtonsHatAndCounter[1]) {
Uint8 data = packet->rgucButtonsHatAndCounter[1];
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, (data & 0x01) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, (data & 0x02) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK, (data & 0x10) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, (data & 0x20) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, (data & 0x40) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK, (data & 0x80) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, ((data & 0x01) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, ((data & 0x02) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK, ((data & 0x10) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, ((data & 0x20) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, ((data & 0x40) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK, ((data & 0x80) != 0));
}
if (ctx->last_state.simple.rgucButtonsHatAndCounter[2] != packet->rgucButtonsHatAndCounter[2]) {
Uint8 data = (packet->rgucButtonsHatAndCounter[2] & 0x03);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, (data & 0x01) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_PS5_TOUCHPAD, (data & 0x02) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, ((data & 0x01) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_PS5_TOUCHPAD, ((data & 0x02) != 0));
}
if (packet->ucTriggerLeft == 0 && (packet->rgucButtonsHatAndCounter[1] & 0x04)) {
@ -1229,10 +1229,10 @@ static void HIDAPI_DriverPS5_HandleStatePacketCommon(SDL_Joystick *joystick, SDL
{
Uint8 data = (packet->rgucButtonsAndHat[0] >> 4);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_WEST, (data & 0x01) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SOUTH, (data & 0x02) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_EAST, (data & 0x04) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_NORTH, (data & 0x08) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_WEST, ((data & 0x01) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SOUTH, ((data & 0x02) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_EAST, ((data & 0x04) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_NORTH, ((data & 0x08) != 0));
}
{
Uint8 data = (packet->rgucButtonsAndHat[0] & 0x0F);
@ -1274,24 +1274,24 @@ static void HIDAPI_DriverPS5_HandleStatePacketCommon(SDL_Joystick *joystick, SDL
if (ctx->last_state.state.rgucButtonsAndHat[1] != packet->rgucButtonsAndHat[1]) {
Uint8 data = packet->rgucButtonsAndHat[1];
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, (data & 0x01) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, (data & 0x02) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK, (data & 0x10) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, (data & 0x20) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, (data & 0x40) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK, (data & 0x80) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, ((data & 0x01) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, ((data & 0x02) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK, ((data & 0x10) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, ((data & 0x20) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, ((data & 0x40) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK, ((data & 0x80) != 0));
}
if (ctx->last_state.state.rgucButtonsAndHat[2] != packet->rgucButtonsAndHat[2]) {
Uint8 data = packet->rgucButtonsAndHat[2];
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, (data & 0x01) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_PS5_TOUCHPAD, (data & 0x02) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_PS5_MICROPHONE, (data & 0x04) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_PS5_LEFT_FUNCTION, (data & 0x10) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_PS5_RIGHT_FUNCTION, (data & 0x20) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_PS5_LEFT_PADDLE, (data & 0x40) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_PS5_RIGHT_PADDLE, (data & 0x80) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, ((data & 0x01) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_PS5_TOUCHPAD, ((data & 0x02) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_PS5_MICROPHONE, ((data & 0x04) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_PS5_LEFT_FUNCTION, ((data & 0x10) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_PS5_RIGHT_FUNCTION, ((data & 0x20) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_PS5_LEFT_PADDLE, ((data & 0x40) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_PS5_RIGHT_PADDLE, ((data & 0x80) != 0));
}
if (packet->ucTriggerLeft == 0 && (packet->rgucButtonsAndHat[1] & 0x04)) {
@ -1369,19 +1369,19 @@ static void HIDAPI_DriverPS5_HandleStatePacket(SDL_Joystick *joystick, SDL_hid_d
{
static const float TOUCHPAD_SCALEX = 1.0f / 1920;
static const float TOUCHPAD_SCALEY = 1.0f / 1070;
Uint8 touchpad_state;
bool touchpad_down;
int touchpad_x, touchpad_y;
if (ctx->report_touchpad) {
touchpad_state = !(packet->ucTouchpadCounter1 & 0x80) ? SDL_PRESSED : SDL_RELEASED;
touchpad_down = ((packet->ucTouchpadCounter1 & 0x80) == 0);
touchpad_x = packet->rgucTouchpadData1[0] | (((int)packet->rgucTouchpadData1[1] & 0x0F) << 8);
touchpad_y = (packet->rgucTouchpadData1[1] >> 4) | ((int)packet->rgucTouchpadData1[2] << 4);
SDL_SendJoystickTouchpad(timestamp, joystick, 0, 0, touchpad_state, touchpad_x * TOUCHPAD_SCALEX, touchpad_y * TOUCHPAD_SCALEY, touchpad_state ? 1.0f : 0.0f);
SDL_SendJoystickTouchpad(timestamp, joystick, 0, 0, touchpad_down, touchpad_x * TOUCHPAD_SCALEX, touchpad_y * TOUCHPAD_SCALEY, touchpad_down ? 1.0f : 0.0f);
touchpad_state = !(packet->ucTouchpadCounter2 & 0x80) ? SDL_PRESSED : SDL_RELEASED;
touchpad_down = ((packet->ucTouchpadCounter2 & 0x80) == 0);
touchpad_x = packet->rgucTouchpadData2[0] | (((int)packet->rgucTouchpadData2[1] & 0x0F) << 8);
touchpad_y = (packet->rgucTouchpadData2[1] >> 4) | ((int)packet->rgucTouchpadData2[2] << 4);
SDL_SendJoystickTouchpad(timestamp, joystick, 0, 1, touchpad_state, touchpad_x * TOUCHPAD_SCALEX, touchpad_y * TOUCHPAD_SCALEY, touchpad_state ? 1.0f : 0.0f);
SDL_SendJoystickTouchpad(timestamp, joystick, 0, 1, touchpad_down, touchpad_x * TOUCHPAD_SCALEX, touchpad_y * TOUCHPAD_SCALEY, touchpad_down ? 1.0f : 0.0f);
}
if (ctx->report_battery) {
@ -1418,19 +1418,19 @@ static void HIDAPI_DriverPS5_HandleStatePacketAlt(SDL_Joystick *joystick, SDL_hi
{
static const float TOUCHPAD_SCALEX = 1.0f / 1920;
static const float TOUCHPAD_SCALEY = 1.0f / 1070;
Uint8 touchpad_state;
bool touchpad_down;
int touchpad_x, touchpad_y;
if (ctx->report_touchpad) {
touchpad_state = !(packet->ucTouchpadCounter1 & 0x80) ? SDL_PRESSED : SDL_RELEASED;
touchpad_down = ((packet->ucTouchpadCounter1 & 0x80) == 0);
touchpad_x = packet->rgucTouchpadData1[0] | (((int)packet->rgucTouchpadData1[1] & 0x0F) << 8);
touchpad_y = (packet->rgucTouchpadData1[1] >> 4) | ((int)packet->rgucTouchpadData1[2] << 4);
SDL_SendJoystickTouchpad(timestamp, joystick, 0, 0, touchpad_state, touchpad_x * TOUCHPAD_SCALEX, touchpad_y * TOUCHPAD_SCALEY, touchpad_state ? 1.0f : 0.0f);
SDL_SendJoystickTouchpad(timestamp, joystick, 0, 0, touchpad_down, touchpad_x * TOUCHPAD_SCALEX, touchpad_y * TOUCHPAD_SCALEY, touchpad_down ? 1.0f : 0.0f);
touchpad_state = !(packet->ucTouchpadCounter2 & 0x80) ? SDL_PRESSED : SDL_RELEASED;
touchpad_down = ((packet->ucTouchpadCounter2 & 0x80) == 0);
touchpad_x = packet->rgucTouchpadData2[0] | (((int)packet->rgucTouchpadData2[1] & 0x0F) << 8);
touchpad_y = (packet->rgucTouchpadData2[1] >> 4) | ((int)packet->rgucTouchpadData2[2] << 4);
SDL_SendJoystickTouchpad(timestamp, joystick, 0, 1, touchpad_state, touchpad_x * TOUCHPAD_SCALEX, touchpad_y * TOUCHPAD_SCALEY, touchpad_state ? 1.0f : 0.0f);
SDL_SendJoystickTouchpad(timestamp, joystick, 0, 1, touchpad_down, touchpad_x * TOUCHPAD_SCALEX, touchpad_y * TOUCHPAD_SCALEY, touchpad_down ? 1.0f : 0.0f);
}
SDL_memcpy(&ctx->last_state, packet, sizeof(ctx->last_state));

View File

@ -326,23 +326,23 @@ static void HIDAPI_DriverShield_HandleStatePacketV103(SDL_Joystick *joystick, SD
}
if (ctx->last_state[1] != data[1]) {
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SOUTH, (data[1] & 0x01) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_EAST, (data[1] & 0x02) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_WEST, (data[1] & 0x04) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_NORTH, (data[1] & 0x08) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, (data[1] & 0x10) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, (data[1] & 0x20) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, (data[1] & 0x40) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK, (data[1] & 0x80) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SOUTH, ((data[1] & 0x01) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_EAST, ((data[1] & 0x02) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_WEST, ((data[1] & 0x04) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_NORTH, ((data[1] & 0x08) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, ((data[1] & 0x10) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, ((data[1] & 0x20) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, ((data[1] & 0x40) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK, ((data[1] & 0x80) != 0));
}
if (ctx->last_state[2] != data[2]) {
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, (data[2] & 0x02) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SHIELD_V103_PLUS, (data[2] & 0x08) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SHIELD_V103_MINUS, (data[2] & 0x10) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, (data[2] & 0x20) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK, (data[2] & 0x40) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SHIELD_SHARE, (data[2] & 0x80) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, ((data[2] & 0x02) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SHIELD_V103_PLUS, ((data[2] & 0x08) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SHIELD_V103_MINUS, ((data[2] & 0x10) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, ((data[2] & 0x20) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK, ((data[2] & 0x40) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SHIELD_SHARE, ((data[2] & 0x80) != 0));
}
SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFTX, SDL_Swap16LE(*(Sint16 *)&data[4]) - 0x8000);
@ -362,17 +362,17 @@ static void HIDAPI_DriverShield_HandleStatePacketV103(SDL_Joystick *joystick, SD
static void HIDAPI_DriverShield_HandleTouchPacketV103(SDL_Joystick *joystick, SDL_DriverShield_Context *ctx, const Uint8 *data, int size)
{
Uint8 touchpad_state;
bool touchpad_down;
float touchpad_x, touchpad_y;
Uint64 timestamp = SDL_GetTicksNS();
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SHIELD_V103_TOUCHPAD, (data[1] & 0x01) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SHIELD_V103_TOUCHPAD, ((data[1] & 0x01) != 0));
// It's a triangular pad, but just use the center as the usable touch area
touchpad_state = !(data[1] & 0x80) ? SDL_PRESSED : SDL_RELEASED;
touchpad_down = ((data[1] & 0x80) == 0);
touchpad_x = clamp((float)(data[2] - 0x70) / 0x50, 0.0f, 1.0f);
touchpad_y = clamp((float)(data[4] - 0x40) / 0x15, 0.0f, 1.0f);
SDL_SendJoystickTouchpad(timestamp, joystick, 0, 0, touchpad_state, touchpad_x, touchpad_y, touchpad_state ? 1.0f : 0.0f);
SDL_SendJoystickTouchpad(timestamp, joystick, 0, 0, touchpad_down, touchpad_x, touchpad_y, touchpad_down ? 1.0f : 0.0f);
}
static void HIDAPI_DriverShield_HandleStatePacketV104(SDL_Joystick *joystick, SDL_DriverShield_Context *ctx, Uint8 *data, int size)
@ -419,18 +419,18 @@ static void HIDAPI_DriverShield_HandleStatePacketV104(SDL_Joystick *joystick, SD
}
if (ctx->last_state[3] != data[3]) {
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SOUTH, (data[3] & 0x01) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_EAST, (data[3] & 0x02) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_WEST, (data[3] & 0x04) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_NORTH, (data[3] & 0x08) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, (data[3] & 0x10) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, (data[3] & 0x20) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, (data[3] & 0x40) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK, (data[3] & 0x80) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SOUTH, ((data[3] & 0x01) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_EAST, ((data[3] & 0x02) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_WEST, ((data[3] & 0x04) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_NORTH, ((data[3] & 0x08) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, ((data[3] & 0x10) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, ((data[3] & 0x20) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, ((data[3] & 0x40) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK, ((data[3] & 0x80) != 0));
}
if (ctx->last_state[4] != data[4]) {
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, (data[4] & 0x01) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, ((data[4] & 0x01) != 0));
}
SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFTX, SDL_Swap16LE(*(Sint16 *)&data[9]) - 0x8000);
@ -443,9 +443,9 @@ static void HIDAPI_DriverShield_HandleStatePacketV104(SDL_Joystick *joystick, SD
SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHT_TRIGGER, SDL_Swap16LE(*(Sint16 *)&data[21]) - 0x8000);
if (ctx->last_state[17] != data[17]) {
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SHIELD_SHARE, (data[17] & 0x01) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK, (data[17] & 0x02) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, (data[17] & 0x04) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SHIELD_SHARE, ((data[17] & 0x01) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK, ((data[17] & 0x02) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, ((data[17] & 0x04) != 0));
}
SDL_memcpy(ctx->last_state, data, SDL_min(size, sizeof(ctx->last_state)));

View File

@ -213,22 +213,22 @@ static void HIDAPI_DriverStadia_HandleStatePacket(SDL_Joystick *joystick, SDL_Dr
}
if (ctx->last_state[2] != data[2]) {
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK, (data[2] & 0x40) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, (data[2] & 0x10) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, (data[2] & 0x20) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK, (data[2] & 0x80) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_STADIA_CAPTURE, (data[2] & 0x01) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_STADIA_GOOGLE_ASSISTANT, (data[2] & 0x02) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK, ((data[2] & 0x40) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, ((data[2] & 0x10) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, ((data[2] & 0x20) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK, ((data[2] & 0x80) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_STADIA_CAPTURE, ((data[2] & 0x01) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_STADIA_GOOGLE_ASSISTANT, ((data[2] & 0x02) != 0));
}
if (ctx->last_state[3] != data[3]) {
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SOUTH, (data[3] & 0x40) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_EAST, (data[3] & 0x20) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_WEST, (data[3] & 0x10) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_NORTH, (data[3] & 0x08) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, (data[3] & 0x04) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, (data[3] & 0x02) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, (data[3] & 0x01) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SOUTH, ((data[3] & 0x40) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_EAST, ((data[3] & 0x20) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_WEST, ((data[3] & 0x10) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_NORTH, ((data[3] & 0x08) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, ((data[3] & 0x04) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, ((data[3] & 0x02) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, ((data[3] & 0x01) != 0));
}
#define READ_STICK_AXIS(offset) \

View File

@ -1121,38 +1121,38 @@ static bool HIDAPI_DriverSteam_UpdateDevice(SDL_HIDAPI_Device *device)
Uint8 hat = 0;
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SOUTH,
(ctx->m_state.ulButtons & STEAM_BUTTON_SOUTH_MASK) ? SDL_PRESSED : SDL_RELEASED);
((ctx->m_state.ulButtons & STEAM_BUTTON_SOUTH_MASK) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_EAST,
(ctx->m_state.ulButtons & STEAM_BUTTON_EAST_MASK) ? SDL_PRESSED : SDL_RELEASED);
((ctx->m_state.ulButtons & STEAM_BUTTON_EAST_MASK) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_WEST,
(ctx->m_state.ulButtons & STEAM_BUTTON_WEST_MASK) ? SDL_PRESSED : SDL_RELEASED);
((ctx->m_state.ulButtons & STEAM_BUTTON_WEST_MASK) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_NORTH,
(ctx->m_state.ulButtons & STEAM_BUTTON_NORTH_MASK) ? SDL_PRESSED : SDL_RELEASED);
((ctx->m_state.ulButtons & STEAM_BUTTON_NORTH_MASK) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER,
(ctx->m_state.ulButtons & STEAM_LEFT_BUMPER_MASK) ? SDL_PRESSED : SDL_RELEASED);
((ctx->m_state.ulButtons & STEAM_LEFT_BUMPER_MASK) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER,
(ctx->m_state.ulButtons & STEAM_RIGHT_BUMPER_MASK) ? SDL_PRESSED : SDL_RELEASED);
((ctx->m_state.ulButtons & STEAM_RIGHT_BUMPER_MASK) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK,
(ctx->m_state.ulButtons & STEAM_BUTTON_MENU_MASK) ? SDL_PRESSED : SDL_RELEASED);
((ctx->m_state.ulButtons & STEAM_BUTTON_MENU_MASK) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START,
(ctx->m_state.ulButtons & STEAM_BUTTON_ESCAPE_MASK) ? SDL_PRESSED : SDL_RELEASED);
((ctx->m_state.ulButtons & STEAM_BUTTON_ESCAPE_MASK) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE,
(ctx->m_state.ulButtons & STEAM_BUTTON_STEAM_MASK) ? SDL_PRESSED : SDL_RELEASED);
((ctx->m_state.ulButtons & STEAM_BUTTON_STEAM_MASK) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK,
(ctx->m_state.ulButtons & STEAM_JOYSTICK_BUTTON_MASK) ? SDL_PRESSED : SDL_RELEASED);
((ctx->m_state.ulButtons & STEAM_JOYSTICK_BUTTON_MASK) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_STEAM_LEFT_PADDLE,
(ctx->m_state.ulButtons & STEAM_BUTTON_BACK_LEFT_MASK) ? SDL_PRESSED : SDL_RELEASED);
((ctx->m_state.ulButtons & STEAM_BUTTON_BACK_LEFT_MASK) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_STEAM_RIGHT_PADDLE,
(ctx->m_state.ulButtons & STEAM_BUTTON_BACK_RIGHT_MASK) ? SDL_PRESSED : SDL_RELEASED);
((ctx->m_state.ulButtons & STEAM_BUTTON_BACK_RIGHT_MASK) != 0));
if (ctx->m_state.ulButtons & STEAM_DPAD_UP_MASK) {
hat |= SDL_HAT_UP;

View File

@ -155,41 +155,41 @@ static void HIDAPI_DriverSteamDeck_HandleState(SDL_HIDAPI_Device *device,
Uint8 hat = 0;
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SOUTH,
(pInReport->payload.deckState.ulButtonsL & STEAMDECK_LBUTTON_A) ? SDL_PRESSED : SDL_RELEASED);
((pInReport->payload.deckState.ulButtonsL & STEAMDECK_LBUTTON_A) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_EAST,
(pInReport->payload.deckState.ulButtonsL & STEAMDECK_LBUTTON_B) ? SDL_PRESSED : SDL_RELEASED);
((pInReport->payload.deckState.ulButtonsL & STEAMDECK_LBUTTON_B) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_WEST,
(pInReport->payload.deckState.ulButtonsL & STEAMDECK_LBUTTON_X) ? SDL_PRESSED : SDL_RELEASED);
((pInReport->payload.deckState.ulButtonsL & STEAMDECK_LBUTTON_X) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_NORTH,
(pInReport->payload.deckState.ulButtonsL & STEAMDECK_LBUTTON_Y) ? SDL_PRESSED : SDL_RELEASED);
((pInReport->payload.deckState.ulButtonsL & STEAMDECK_LBUTTON_Y) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER,
(pInReport->payload.deckState.ulButtonsL & STEAMDECK_LBUTTON_L) ? SDL_PRESSED : SDL_RELEASED);
((pInReport->payload.deckState.ulButtonsL & STEAMDECK_LBUTTON_L) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER,
(pInReport->payload.deckState.ulButtonsL & STEAMDECK_LBUTTON_R) ? SDL_PRESSED : SDL_RELEASED);
((pInReport->payload.deckState.ulButtonsL & STEAMDECK_LBUTTON_R) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK,
(pInReport->payload.deckState.ulButtonsL & STEAMDECK_LBUTTON_VIEW) ? SDL_PRESSED : SDL_RELEASED);
((pInReport->payload.deckState.ulButtonsL & STEAMDECK_LBUTTON_VIEW) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START,
(pInReport->payload.deckState.ulButtonsL & STEAMDECK_LBUTTON_MENU) ? SDL_PRESSED : SDL_RELEASED);
((pInReport->payload.deckState.ulButtonsL & STEAMDECK_LBUTTON_MENU) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE,
(pInReport->payload.deckState.ulButtonsL & STEAMDECK_LBUTTON_STEAM) ? SDL_PRESSED : SDL_RELEASED);
((pInReport->payload.deckState.ulButtonsL & STEAMDECK_LBUTTON_STEAM) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_STEAM_DECK_QAM,
(pInReport->payload.deckState.ulButtonsH & STEAMDECK_HBUTTON_QAM) ? SDL_PRESSED : SDL_RELEASED);
((pInReport->payload.deckState.ulButtonsH & STEAMDECK_HBUTTON_QAM) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK,
(pInReport->payload.deckState.ulButtonsL & STEAMDECK_LBUTTON_L3) ? SDL_PRESSED : SDL_RELEASED);
((pInReport->payload.deckState.ulButtonsL & STEAMDECK_LBUTTON_L3) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK,
(pInReport->payload.deckState.ulButtonsL & STEAMDECK_LBUTTON_R3) ? SDL_PRESSED : SDL_RELEASED);
((pInReport->payload.deckState.ulButtonsL & STEAMDECK_LBUTTON_R3) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_STEAM_DECK_RIGHT_PADDLE1,
(pInReport->payload.deckState.ulButtonsH & STEAMDECK_HBUTTON_R4) ? SDL_PRESSED : SDL_RELEASED);
((pInReport->payload.deckState.ulButtonsH & STEAMDECK_HBUTTON_R4) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_STEAM_DECK_LEFT_PADDLE1,
(pInReport->payload.deckState.ulButtonsH & STEAMDECK_HBUTTON_L4) ? SDL_PRESSED : SDL_RELEASED);
((pInReport->payload.deckState.ulButtonsH & STEAMDECK_HBUTTON_L4) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_STEAM_DECK_RIGHT_PADDLE2,
(pInReport->payload.deckState.ulButtonsL & STEAMDECK_LBUTTON_R5) ? SDL_PRESSED : SDL_RELEASED);
((pInReport->payload.deckState.ulButtonsL & STEAMDECK_LBUTTON_R5) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_STEAM_DECK_LEFT_PADDLE2,
(pInReport->payload.deckState.ulButtonsL & STEAMDECK_LBUTTON_L5) ? SDL_PRESSED : SDL_RELEASED);
((pInReport->payload.deckState.ulButtonsL & STEAMDECK_LBUTTON_L5) != 0));
if (pInReport->payload.deckState.ulButtonsL & STEAMDECK_LBUTTON_DPAD_UP) {
hat |= SDL_HAT_UP;

View File

@ -1718,22 +1718,22 @@ static void HandleInputOnlyControllerState(SDL_Joystick *joystick, SDL_DriverSwi
if (packet->rgucButtons[0] != ctx->m_lastInputOnlyState.rgucButtons[0]) {
Uint8 data = packet->rgucButtons[0];
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_SOUTH), (data & 0x02) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_EAST), (data & 0x04) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_WEST), (data & 0x01) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_NORTH), (data & 0x08) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, (data & 0x10) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, (data & 0x20) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_SOUTH), ((data & 0x02) != 0));
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_EAST), ((data & 0x04) != 0));
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_WEST), ((data & 0x01) != 0));
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_NORTH), ((data & 0x08) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, ((data & 0x10) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, ((data & 0x20) != 0));
}
if (packet->rgucButtons[1] != ctx->m_lastInputOnlyState.rgucButtons[1]) {
Uint8 data = packet->rgucButtons[1];
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK, (data & 0x01) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, (data & 0x02) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, (data & 0x04) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK, (data & 0x08) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, (data & 0x10) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH_SHARE, (data & 0x20) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK, ((data & 0x01) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, ((data & 0x02) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, ((data & 0x04) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK, ((data & 0x08) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, ((data & 0x10) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH_SHARE, ((data & 0x20) != 0));
}
if (packet->ucStickHat != ctx->m_lastInputOnlyState.ucStickHat) {
@ -1820,16 +1820,16 @@ static void HandleCombinedSimpleControllerStateL(Uint64 timestamp, SDL_Joystick
}
SDL_SendJoystickHat(timestamp, joystick, 0, hat);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH_LEFT_PADDLE1, (data & 0x10) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH_LEFT_PADDLE2, (data & 0x20) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH_LEFT_PADDLE1, ((data & 0x10) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH_LEFT_PADDLE2, ((data & 0x20) != 0));
}
if (packet->rgucButtons[1] != ctx->m_lastSimpleState.rgucButtons[1]) {
Uint8 data = packet->rgucButtons[1];
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK, (data & 0x01) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, (data & 0x04) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH_SHARE, (data & 0x20) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, (data & 0x40) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK, ((data & 0x01) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, ((data & 0x04) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH_SHARE, ((data & 0x20) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, ((data & 0x40) != 0));
}
Sint16 axis = (packet->rgucButtons[1] & 0x80) ? 32767 : -32768;
@ -1881,20 +1881,20 @@ static void HandleCombinedSimpleControllerStateR(Uint64 timestamp, SDL_Joystick
{
if (packet->rgucButtons[0] != ctx->m_lastSimpleState.rgucButtons[0]) {
Uint8 data = packet->rgucButtons[0];
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_EAST), (data & 0x01) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_NORTH), (data & 0x02) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_SOUTH), (data & 0x04) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_WEST), (data & 0x08) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH_RIGHT_PADDLE2, (data & 0x10) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH_RIGHT_PADDLE1, (data & 0x20) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_EAST), ((data & 0x01) != 0));
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_NORTH), ((data & 0x02) != 0));
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_SOUTH), ((data & 0x04) != 0));
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_WEST), ((data & 0x08) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH_RIGHT_PADDLE2, ((data & 0x10) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH_RIGHT_PADDLE1, ((data & 0x20) != 0));
}
if (packet->rgucButtons[1] != ctx->m_lastSimpleState.rgucButtons[1]) {
Uint8 data = packet->rgucButtons[1];
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, (data & 0x02) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK, (data & 0x08) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, (data & 0x10) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, (data & 0x40) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, ((data & 0x02) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK, ((data & 0x08) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, ((data & 0x10) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, ((data & 0x40) != 0));
}
Sint16 axis = (packet->rgucButtons[1] & 0x80) ? 32767 : -32768;
@ -1946,21 +1946,21 @@ static void HandleMiniSimpleControllerStateL(Uint64 timestamp, SDL_Joystick *joy
{
if (packet->rgucButtons[0] != ctx->m_lastSimpleState.rgucButtons[0]) {
Uint8 data = packet->rgucButtons[0];
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_SOUTH), (data & 0x01) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_EAST), (data & 0x02) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_WEST), (data & 0x04) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_NORTH), (data & 0x08) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, (data & 0x10) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, (data & 0x20) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_SOUTH), ((data & 0x01) != 0));
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_EAST), ((data & 0x02) != 0));
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_WEST), ((data & 0x04) != 0));
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_NORTH), ((data & 0x08) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, ((data & 0x10) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, ((data & 0x20) != 0));
}
if (packet->rgucButtons[1] != ctx->m_lastSimpleState.rgucButtons[1]) {
Uint8 data = packet->rgucButtons[1];
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, (data & 0x01) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, (data & 0x04) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, (data & 0x20) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH_LEFT_PADDLE1, (data & 0x40) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH_LEFT_PADDLE2, (data & 0x80) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, ((data & 0x01) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, ((data & 0x04) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, ((data & 0x20) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH_LEFT_PADDLE1, ((data & 0x40) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH_LEFT_PADDLE2, ((data & 0x80) != 0));
}
if (packet->ucStickHat != ctx->m_lastSimpleState.ucStickHat) {
@ -2009,22 +2009,22 @@ static void HandleMiniSimpleControllerStateR(Uint64 timestamp, SDL_Joystick *joy
{
if (packet->rgucButtons[0] != ctx->m_lastSimpleState.rgucButtons[0]) {
Uint8 data = packet->rgucButtons[0];
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_SOUTH), (data & 0x01) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_EAST), (data & 0x02) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_WEST), (data & 0x04) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_NORTH), (data & 0x08) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, (data & 0x10) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, (data & 0x20) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_SOUTH), ((data & 0x01) != 0));
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_EAST), ((data & 0x02) != 0));
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_WEST), ((data & 0x04) != 0));
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_NORTH), ((data & 0x08) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, ((data & 0x10) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, ((data & 0x20) != 0));
}
if (packet->rgucButtons[1] != ctx->m_lastSimpleState.rgucButtons[1]) {
Uint8 data = packet->rgucButtons[1];
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, (data & 0x02) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, (data & 0x08) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, (data & 0x10) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH_SHARE, (data & 0x20) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH_RIGHT_PADDLE1, (data & 0x40) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH_RIGHT_PADDLE2, (data & 0x80) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, ((data & 0x02) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, ((data & 0x08) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, ((data & 0x10) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH_SHARE, ((data & 0x20) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH_RIGHT_PADDLE1, ((data & 0x40) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH_RIGHT_PADDLE2, ((data & 0x80) != 0));
}
if (packet->ucStickHat != ctx->m_lastSimpleState.ucStickHat) {
@ -2090,22 +2090,22 @@ static void HandleSimpleControllerState(SDL_Joystick *joystick, SDL_DriverSwitch
if (packet->rgucButtons[0] != ctx->m_lastSimpleState.rgucButtons[0]) {
Uint8 data = packet->rgucButtons[0];
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_SOUTH), (data & 0x01) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_EAST), (data & 0x02) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_WEST), (data & 0x04) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_NORTH), (data & 0x08) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, (data & 0x10) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, (data & 0x20) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_SOUTH), ((data & 0x01) != 0));
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_EAST), ((data & 0x02) != 0));
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_WEST), ((data & 0x04) != 0));
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_NORTH), ((data & 0x08) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, ((data & 0x10) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, ((data & 0x20) != 0));
}
if (packet->rgucButtons[1] != ctx->m_lastSimpleState.rgucButtons[1]) {
Uint8 data = packet->rgucButtons[1];
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK, (data & 0x01) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, (data & 0x02) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, (data & 0x04) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK, (data & 0x08) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, (data & 0x10) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH_SHARE, (data & 0x20) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK, ((data & 0x01) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, ((data & 0x02) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, ((data & 0x04) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK, ((data & 0x08) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, ((data & 0x10) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH_SHARE, ((data & 0x20) != 0));
}
if (packet->ucStickHat != ctx->m_lastSimpleState.ucStickHat) {
@ -2214,9 +2214,9 @@ static void HandleCombinedControllerStateL(Uint64 timestamp, SDL_Joystick *joyst
if (packet->controllerState.rgucButtons[1] != ctx->m_lastFullState.controllerState.rgucButtons[1]) {
Uint8 data = packet->controllerState.rgucButtons[1];
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK, (data & 0x01) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, (data & 0x08) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH_SHARE, (data & 0x20) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK, ((data & 0x01) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, ((data & 0x08) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH_SHARE, ((data & 0x20) != 0));
}
if (packet->controllerState.rgucButtons[2] != ctx->m_lastFullState.controllerState.rgucButtons[2]) {
@ -2237,9 +2237,9 @@ static void HandleCombinedControllerStateL(Uint64 timestamp, SDL_Joystick *joyst
}
SDL_SendJoystickHat(timestamp, joystick, 0, hat);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH_LEFT_PADDLE2, (data & 0x10) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH_LEFT_PADDLE1, (data & 0x20) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, (data & 0x40) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH_LEFT_PADDLE2, ((data & 0x10) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH_LEFT_PADDLE1, ((data & 0x20) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, ((data & 0x40) != 0));
axis = (data & 0x80) ? 32767 : -32768;
SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFT_TRIGGER, axis);
}
@ -2259,22 +2259,22 @@ static void HandleCombinedControllerStateR(Uint64 timestamp, SDL_Joystick *joyst
if (packet->controllerState.rgucButtons[0] != ctx->m_lastFullState.controllerState.rgucButtons[0]) {
Uint8 data = packet->controllerState.rgucButtons[0];
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_SOUTH), (data & 0x04) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_EAST), (data & 0x08) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_WEST), (data & 0x01) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_NORTH), (data & 0x02) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH_RIGHT_PADDLE1, (data & 0x10) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH_RIGHT_PADDLE2, (data & 0x20) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, (data & 0x40) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_SOUTH), ((data & 0x04) != 0));
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_EAST), ((data & 0x08) != 0));
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_WEST), ((data & 0x01) != 0));
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_NORTH), ((data & 0x02) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH_RIGHT_PADDLE1, ((data & 0x10) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH_RIGHT_PADDLE2, ((data & 0x20) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, ((data & 0x40) != 0));
axis = (data & 0x80) ? 32767 : -32768;
SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHT_TRIGGER, axis);
}
if (packet->controllerState.rgucButtons[1] != ctx->m_lastFullState.controllerState.rgucButtons[1]) {
Uint8 data = packet->controllerState.rgucButtons[1];
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, (data & 0x02) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK, (data & 0x04) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, (data & 0x10) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, ((data & 0x02) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK, ((data & 0x04) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, ((data & 0x10) != 0));
}
axis = packet->controllerState.rgucJoystickRight[0] | ((packet->controllerState.rgucJoystickRight[1] & 0xF) << 8);
@ -2292,21 +2292,21 @@ static void HandleMiniControllerStateL(Uint64 timestamp, SDL_Joystick *joystick,
if (packet->controllerState.rgucButtons[1] != ctx->m_lastFullState.controllerState.rgucButtons[1]) {
Uint8 data = packet->controllerState.rgucButtons[1];
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, (data & 0x01) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, (data & 0x08) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, (data & 0x20) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, ((data & 0x01) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, ((data & 0x08) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, ((data & 0x20) != 0));
}
if (packet->controllerState.rgucButtons[2] != ctx->m_lastFullState.controllerState.rgucButtons[2]) {
Uint8 data = packet->controllerState.rgucButtons[2];
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_SOUTH), (data & 0x08) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_EAST), (data & 0x01) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_WEST), (data & 0x02) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_NORTH), (data & 0x04) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, (data & 0x10) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, (data & 0x20) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH_LEFT_PADDLE1, (data & 0x40) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH_LEFT_PADDLE2, (data & 0x80) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_SOUTH), ((data & 0x08) != 0));
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_EAST), ((data & 0x01) != 0));
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_WEST), ((data & 0x02) != 0));
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_NORTH), ((data & 0x04) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, ((data & 0x10) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, ((data & 0x20) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH_LEFT_PADDLE1, ((data & 0x40) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH_LEFT_PADDLE2, ((data & 0x80) != 0));
}
axis = packet->controllerState.rgucJoystickLeft[0] | ((packet->controllerState.rgucJoystickLeft[1] & 0xF) << 8);
@ -2324,21 +2324,21 @@ static void HandleMiniControllerStateR(Uint64 timestamp, SDL_Joystick *joystick,
if (packet->controllerState.rgucButtons[0] != ctx->m_lastFullState.controllerState.rgucButtons[0]) {
Uint8 data = packet->controllerState.rgucButtons[0];
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_SOUTH), (data & 0x08) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_EAST), (data & 0x02) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_WEST), (data & 0x04) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_NORTH), (data & 0x01) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, (data & 0x10) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, (data & 0x20) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH_RIGHT_PADDLE1, (data & 0x40) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH_RIGHT_PADDLE2, (data & 0x80) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_SOUTH), ((data & 0x08) != 0));
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_EAST), ((data & 0x02) != 0));
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_WEST), ((data & 0x04) != 0));
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_NORTH), ((data & 0x01) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, ((data & 0x10) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, ((data & 0x20) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH_RIGHT_PADDLE1, ((data & 0x40) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH_RIGHT_PADDLE2, ((data & 0x80) != 0));
}
if (packet->controllerState.rgucButtons[1] != ctx->m_lastFullState.controllerState.rgucButtons[1]) {
Uint8 data = packet->controllerState.rgucButtons[1];
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, (data & 0x02) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, (data & 0x04) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, (data & 0x10) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, ((data & 0x02) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, ((data & 0x04) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, ((data & 0x10) != 0));
}
axis = packet->controllerState.rgucJoystickRight[0] | ((packet->controllerState.rgucJoystickRight[1] & 0xF) << 8);
@ -2371,22 +2371,22 @@ static void HandleFullControllerState(SDL_Joystick *joystick, SDL_DriverSwitch_C
if (packet->controllerState.rgucButtons[0] != ctx->m_lastFullState.controllerState.rgucButtons[0]) {
Uint8 data = packet->controllerState.rgucButtons[0];
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_SOUTH), (data & 0x04) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_EAST), (data & 0x08) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_WEST), (data & 0x01) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_NORTH), (data & 0x02) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, (data & 0x40) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_SOUTH), ((data & 0x04) != 0));
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_EAST), ((data & 0x08) != 0));
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_WEST), ((data & 0x01) != 0));
SDL_SendJoystickButton(timestamp, joystick, RemapButton(ctx, SDL_GAMEPAD_BUTTON_NORTH), ((data & 0x02) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, ((data & 0x40) != 0));
}
if (packet->controllerState.rgucButtons[1] != ctx->m_lastFullState.controllerState.rgucButtons[1]) {
Uint8 data = packet->controllerState.rgucButtons[1];
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK, (data & 0x01) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, (data & 0x02) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK, (data & 0x04) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, (data & 0x08) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK, ((data & 0x01) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, ((data & 0x02) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK, ((data & 0x04) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, ((data & 0x08) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, (data & 0x10) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH_SHARE, (data & 0x20) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, ((data & 0x10) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH_SHARE, ((data & 0x20) != 0));
}
if (packet->controllerState.rgucButtons[2] != ctx->m_lastFullState.controllerState.rgucButtons[2]) {
@ -2407,7 +2407,7 @@ static void HandleFullControllerState(SDL_Joystick *joystick, SDL_DriverSwitch_C
}
SDL_SendJoystickHat(timestamp, joystick, 0, hat);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, (data & 0x40) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, ((data & 0x40) != 0));
}
axis = (packet->controllerState.rgucButtons[0] & 0x80) ? 32767 : -32768;

View File

@ -919,7 +919,7 @@ static void PostStickCalibrated(Uint64 timestamp, SDL_Joystick *joystick, StickC
*`on` is the joystick value to be sent if a bit is on
*`off` is the joystick value to be sent if a bit is off
*/
static void PostPackedButtonData(Uint64 timestamp, SDL_Joystick *joystick, const Uint8 defs[][8], const Uint8 *data, int size, Uint8 on, Uint8 off)
static void PostPackedButtonData(Uint64 timestamp, SDL_Joystick *joystick, const Uint8 defs[][8], const Uint8 *data, int size, bool on, bool off)
{
int i, j;
@ -927,8 +927,8 @@ static void PostPackedButtonData(Uint64 timestamp, SDL_Joystick *joystick, const
for (j = 0; j < 8; j++) {
Uint8 button = defs[i][j];
if (button != 0xFF) {
Uint8 state = (data[i] >> j) & 1 ? on : off;
SDL_SendJoystickButton(timestamp, joystick, button, state);
bool down = (data[i] >> j) & 1 ? on : off;
SDL_SendJoystickButton(timestamp, joystick, button, down);
}
}
}
@ -1035,7 +1035,7 @@ static void HandleWiiUProButtonData(SDL_DriverWii_Context *ctx, SDL_Joystick *jo
}
// Buttons
PostPackedButtonData(ctx->timestamp, joystick, buttons, data->rgucExtension + 8, 3, SDL_RELEASED, SDL_PRESSED);
PostPackedButtonData(ctx->timestamp, joystick, buttons, data->rgucExtension + 8, 3, false, true);
// Triggers
zl = data->rgucExtension[9] & 0x80;
@ -1063,9 +1063,9 @@ static void HandleGamepadControllerButtonData(SDL_DriverWii_Context *ctx, SDL_Jo
}
// Buttons
PostPackedButtonData(ctx->timestamp, joystick, buttons, data->rgucExtension + 4, 2, SDL_RELEASED, SDL_PRESSED);
PostPackedButtonData(ctx->timestamp, joystick, buttons, data->rgucExtension + 4, 2, false, true);
if (ctx->m_ucMotionPlusMode == WII_MOTIONPLUS_MODE_GAMEPAD) {
PostPackedButtonData(ctx->timestamp, joystick, MP_FIXUP_DPAD_BUTTON_DEFS, data->rgucExtension, 2, SDL_RELEASED, SDL_PRESSED);
PostPackedButtonData(ctx->timestamp, joystick, MP_FIXUP_DPAD_BUTTON_DEFS, data->rgucExtension, 2, false, true);
}
// Triggers
@ -1115,7 +1115,7 @@ static void HandleWiiRemoteButtonData(SDL_DriverWii_Context *ctx, SDL_Joystick *
}
};
if (data->hasBaseButtons) {
PostPackedButtonData(ctx->timestamp, joystick, buttons, data->rgucBaseButtons, 2, SDL_PRESSED, SDL_RELEASED);
PostPackedButtonData(ctx->timestamp, joystick, buttons, data->rgucBaseButtons, 2, true, false);
}
}
@ -1148,24 +1148,24 @@ static void HandleWiiRemoteButtonDataAsMainController(SDL_DriverWii_Context *ctx
}
};
if (data->hasBaseButtons) {
PostPackedButtonData(ctx->timestamp, joystick, buttons, data->rgucBaseButtons, 2, SDL_PRESSED, SDL_RELEASED);
PostPackedButtonData(ctx->timestamp, joystick, buttons, data->rgucBaseButtons, 2, true, false);
}
}
static void HandleNunchuckButtonData(SDL_DriverWii_Context *ctx, SDL_Joystick *joystick, const WiiButtonData *data)
{
Uint8 c_button, z_button;
bool c_button, z_button;
if (data->ucNExtensionBytes < 6) {
return;
}
if (ctx->m_ucMotionPlusMode == WII_MOTIONPLUS_MODE_NUNCHUK) {
c_button = (data->rgucExtension[5] & 0x08) ? SDL_RELEASED : SDL_PRESSED;
z_button = (data->rgucExtension[5] & 0x04) ? SDL_RELEASED : SDL_PRESSED;
c_button = (data->rgucExtension[5] & 0x08) ? false : true;
z_button = (data->rgucExtension[5] & 0x04) ? false : true;
} else {
c_button = (data->rgucExtension[5] & 0x02) ? SDL_RELEASED : SDL_PRESSED;
z_button = (data->rgucExtension[5] & 0x01) ? SDL_RELEASED : SDL_PRESSED;
c_button = (data->rgucExtension[5] & 0x02) ? false : true;
z_button = (data->rgucExtension[5] & 0x01) ? false : true;
}
SDL_SendJoystickButton(ctx->timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, c_button);
SDL_SendJoystickAxis(ctx->timestamp, joystick, SDL_GAMEPAD_AXIS_LEFT_TRIGGER, z_button ? SDL_JOYSTICK_AXIS_MAX : SDL_JOYSTICK_AXIS_MIN);

View File

@ -291,20 +291,20 @@ static void HIDAPI_DriverXbox360_HandleStatePacket(SDL_Joystick *joystick, SDL_D
}
SDL_SendJoystickHat(timestamp, joystick, 0, hat);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, (data[2] & 0x10) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK, (data[2] & 0x20) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, (data[2] & 0x40) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK, (data[2] & 0x80) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, ((data[2] & 0x10) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK, ((data[2] & 0x20) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, ((data[2] & 0x40) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK, ((data[2] & 0x80) != 0));
}
if (ctx->last_state[3] != data[3]) {
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, (data[3] & 0x01) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, (data[3] & 0x02) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, (data[3] & 0x04) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SOUTH, (data[3] & 0x10) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_EAST, (data[3] & 0x20) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_WEST, (data[3] & 0x40) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_NORTH, (data[3] & 0x80) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, ((data[3] & 0x01) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, ((data[3] & 0x02) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, ((data[3] & 0x04) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SOUTH, ((data[3] & 0x10) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_EAST, ((data[3] & 0x20) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_WEST, ((data[3] & 0x40) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_NORTH, ((data[3] & 0x80) != 0));
}
axis = ((int)data[4] * 257) - 32768;

View File

@ -248,20 +248,20 @@ static void HIDAPI_DriverXbox360W_HandleStatePacket(SDL_Joystick *joystick, SDL_
}
SDL_SendJoystickHat(timestamp, joystick, 0, hat);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, (data[2] & 0x10) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK, (data[2] & 0x20) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, (data[2] & 0x40) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK, (data[2] & 0x80) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, ((data[2] & 0x10) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK, ((data[2] & 0x20) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, ((data[2] & 0x40) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK, ((data[2] & 0x80) != 0));
}
if (ctx->last_state[3] != data[3]) {
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, (data[3] & 0x01) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, (data[3] & 0x02) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, (data[3] & 0x04) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SOUTH, (data[3] & 0x10) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_EAST, (data[3] & 0x20) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_WEST, (data[3] & 0x40) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_NORTH, (data[3] & 0x80) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, ((data[3] & 0x01) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, ((data[3] & 0x02) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, ((data[3] & 0x04) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SOUTH, ((data[3] & 0x10) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_EAST, ((data[3] & 0x20) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_WEST, ((data[3] & 0x40) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_NORTH, ((data[3] & 0x80) != 0));
}
axis = ((int)data[4] * 257) - 32768;

View File

@ -633,10 +633,10 @@ static void HIDAPI_DriverXboxOne_HandleUnmappedStatePacket(SDL_Joystick *joystic
if (ctx->last_paddle_state != data[paddle_index]) {
Uint8 nButton = (Uint8)(SDL_GAMEPAD_BUTTON_XBOX_SHARE_BUTTON + ctx->has_share_button); // Next available button
SDL_SendJoystickButton(timestamp, joystick, nButton++, (data[paddle_index] & button1_bit) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, nButton++, (data[paddle_index] & button2_bit) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, nButton++, (data[paddle_index] & button3_bit) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, nButton++, (data[paddle_index] & button4_bit) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, nButton++, ((data[paddle_index] & button1_bit) != 0));
SDL_SendJoystickButton(timestamp, joystick, nButton++, ((data[paddle_index] & button2_bit) != 0));
SDL_SendJoystickButton(timestamp, joystick, nButton++, ((data[paddle_index] & button3_bit) != 0));
SDL_SendJoystickButton(timestamp, joystick, nButton++, ((data[paddle_index] & button4_bit) != 0));
ctx->last_paddle_state = data[paddle_index];
}
ctx->has_unmapped_state = true;
@ -658,12 +658,12 @@ static void HIDAPI_DriverXboxOne_HandleStatePacket(SDL_Joystick *joystick, SDL_D
}
if (ctx->last_state[0] != data[0]) {
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, (data[0] & 0x04) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK, (data[0] & 0x08) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SOUTH, (data[0] & 0x10) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_EAST, (data[0] & 0x20) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_WEST, (data[0] & 0x40) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_NORTH, (data[0] & 0x80) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, ((data[0] & 0x04) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK, ((data[0] & 0x08) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SOUTH, ((data[0] & 0x10) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_EAST, ((data[0] & 0x20) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_WEST, ((data[0] & 0x40) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_NORTH, ((data[0] & 0x80) != 0));
}
if (ctx->last_state[1] != data[1]) {
@ -685,14 +685,14 @@ static void HIDAPI_DriverXboxOne_HandleStatePacket(SDL_Joystick *joystick, SDL_D
if (ctx->vendor_id == USB_VENDOR_RAZER && ctx->product_id == USB_PRODUCT_RAZER_ATROX) {
// The Razer Atrox has the right and left shoulder bits reversed
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, (data[1] & 0x20) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, (data[1] & 0x10) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, ((data[1] & 0x20) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, ((data[1] & 0x10) != 0));
} else {
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, (data[1] & 0x10) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, (data[1] & 0x20) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, ((data[1] & 0x10) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, ((data[1] & 0x20) != 0));
}
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, (data[1] & 0x40) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK, (data[1] & 0x80) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, ((data[1] & 0x40) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK, ((data[1] & 0x80) != 0));
}
if (ctx->has_share_button) {
@ -704,19 +704,19 @@ static void HIDAPI_DriverXboxOne_HandleStatePacket(SDL_Joystick *joystick, SDL_D
*/
if (size < 44) {
if (ctx->last_state[14] != data[14]) {
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_XBOX_SHARE_BUTTON, (data[14] & 0x01) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_XBOX_SHARE_BUTTON, ((data[14] & 0x01) != 0));
}
} else if (size == 44) {
if (ctx->last_state[18] != data[18]) {
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_XBOX_SHARE_BUTTON, (data[18] & 0x01) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_XBOX_SHARE_BUTTON, ((data[18] & 0x01) != 0));
}
} else if (size == 46) {
if (ctx->last_state[28] != data[28]) {
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_XBOX_SHARE_BUTTON, (data[28] & 0x01) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_XBOX_SHARE_BUTTON, ((data[28] & 0x01) != 0));
}
} else if (size == 60) {
if (ctx->last_state[42] != data[42]) {
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_XBOX_SHARE_BUTTON, (data[42] & 0x01) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_XBOX_SHARE_BUTTON, ((data[42] & 0x01) != 0));
}
}
}
@ -800,10 +800,10 @@ static void HIDAPI_DriverXboxOne_HandleStatePacket(SDL_Joystick *joystick, SDL_D
if (ctx->last_paddle_state != data[paddle_index]) {
Uint8 nButton = (Uint8)(SDL_GAMEPAD_BUTTON_XBOX_SHARE_BUTTON + ctx->has_share_button); // Next available button
SDL_SendJoystickButton(timestamp, joystick, nButton++, (data[paddle_index] & button1_bit) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, nButton++, (data[paddle_index] & button2_bit) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, nButton++, (data[paddle_index] & button3_bit) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, nButton++, (data[paddle_index] & button4_bit) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, nButton++, ((data[paddle_index] & button1_bit) != 0));
SDL_SendJoystickButton(timestamp, joystick, nButton++, ((data[paddle_index] & button2_bit) != 0));
SDL_SendJoystickButton(timestamp, joystick, nButton++, ((data[paddle_index] & button3_bit) != 0));
SDL_SendJoystickButton(timestamp, joystick, nButton++, ((data[paddle_index] & button4_bit) != 0));
ctx->last_paddle_state = data[paddle_index];
}
}
@ -852,7 +852,7 @@ static void HIDAPI_DriverXboxOne_HandleModePacket(SDL_Joystick *joystick, SDL_Dr
{
Uint64 timestamp = SDL_GetTicksNS();
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, (data[0] & 0x01) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, ((data[0] & 0x01) != 0));
}
/*
@ -861,19 +861,19 @@ static void HIDAPI_DriverXboxOne_HandleModePacket(SDL_Joystick *joystick, SDL_Dr
static void HIDAPI_DriverXboxOneBluetooth_HandleButtons16(Uint64 timestamp, SDL_Joystick *joystick, SDL_DriverXboxOne_Context *ctx, const Uint8 *data, int size)
{
if (ctx->last_state[14] != data[14]) {
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SOUTH, (data[14] & 0x01) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_EAST, (data[14] & 0x02) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_WEST, (data[14] & 0x04) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_NORTH, (data[14] & 0x08) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, (data[14] & 0x10) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, (data[14] & 0x20) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK, (data[14] & 0x40) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, (data[14] & 0x80) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SOUTH, ((data[14] & 0x01) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_EAST, ((data[14] & 0x02) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_WEST, ((data[14] & 0x04) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_NORTH, ((data[14] & 0x08) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, ((data[14] & 0x10) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, ((data[14] & 0x20) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK, ((data[14] & 0x40) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, ((data[14] & 0x80) != 0));
}
if (ctx->last_state[15] != data[15]) {
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, (data[15] & 0x01) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK, (data[15] & 0x02) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, ((data[15] & 0x01) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK, ((data[15] & 0x02) != 0));
}
}
@ -888,28 +888,28 @@ static void HIDAPI_DriverXboxOneBluetooth_HandleButtons16(Uint64 timestamp, SDL_
static void HIDAPI_DriverXboxOneBluetooth_HandleButtons(Uint64 timestamp, SDL_Joystick *joystick, SDL_DriverXboxOne_Context *ctx, Uint8 *data, int size)
{
if (ctx->last_state[14] != data[14]) {
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SOUTH, (data[14] & 0x01) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_EAST, (data[14] & 0x02) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_WEST, (data[14] & 0x08) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_NORTH, (data[14] & 0x10) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, (data[14] & 0x40) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, (data[14] & 0x80) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SOUTH, ((data[14] & 0x01) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_EAST, ((data[14] & 0x02) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_WEST, ((data[14] & 0x08) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_NORTH, ((data[14] & 0x10) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, ((data[14] & 0x40) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, ((data[14] & 0x80) != 0));
}
if (ctx->last_state[15] != data[15]) {
if (!ctx->has_guide_packet) {
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, (data[15] & 0x10) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, ((data[15] & 0x10) != 0));
}
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, (data[15] & 0x08) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, (data[15] & 0x20) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK, (data[15] & 0x40) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, ((data[15] & 0x08) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, ((data[15] & 0x20) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK, ((data[15] & 0x40) != 0));
}
if (ctx->has_share_button) {
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK, (data[15] & 0x04) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_XBOX_SHARE_BUTTON, (data[16] & 0x01) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK, ((data[15] & 0x04) != 0));
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_XBOX_SHARE_BUTTON, ((data[16] & 0x01) != 0));
} else {
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK, ((data[15] & 0x04) || (data[16] & 0x01)) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK, ((data[15] & 0x04) || ((data[16] & 0x01)) != 0));
}
/*
@ -967,10 +967,10 @@ static void HIDAPI_DriverXboxOneBluetooth_HandleButtons(Uint64 timestamp, SDL_Jo
if (ctx->last_paddle_state != data[paddle_index]) {
Uint8 nButton = SDL_GAMEPAD_BUTTON_XBOX_SHARE_BUTTON; // Next available button
SDL_SendJoystickButton(timestamp, joystick, nButton++, (data[paddle_index] & button1_bit) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, nButton++, (data[paddle_index] & button2_bit) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, nButton++, (data[paddle_index] & button3_bit) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, nButton++, (data[paddle_index] & button4_bit) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, nButton++, ((data[paddle_index] & button1_bit) != 0));
SDL_SendJoystickButton(timestamp, joystick, nButton++, ((data[paddle_index] & button2_bit) != 0));
SDL_SendJoystickButton(timestamp, joystick, nButton++, ((data[paddle_index] & button3_bit) != 0));
SDL_SendJoystickButton(timestamp, joystick, nButton++, ((data[paddle_index] & button4_bit) != 0));
ctx->last_paddle_state = data[paddle_index];
}
}
@ -1057,7 +1057,7 @@ static void HIDAPI_DriverXboxOneBluetooth_HandleGuidePacket(SDL_Joystick *joysti
Uint64 timestamp = SDL_GetTicksNS();
ctx->has_guide_packet = true;
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, (data[1] & 0x01) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, ((data[1] & 0x01) != 0));
}
static void HIDAPI_DriverXboxOneBluetooth_HandleBatteryPacket(SDL_Joystick *joystick, SDL_DriverXboxOne_Context *ctx, const Uint8 *data, int size)

View File

@ -1894,13 +1894,13 @@ static void PollAllValues(Uint64 timestamp, SDL_Joystick *joystick)
if (ioctl(joystick->hwdata->fd, EVIOCGKEY(sizeof(keyinfo)), keyinfo) >= 0) {
for (i = 0; i < KEY_MAX; i++) {
if (joystick->hwdata->has_key[i]) {
const Uint8 value = test_bit(i, keyinfo) ? SDL_PRESSED : SDL_RELEASED;
bool down = test_bit(i, keyinfo);
#ifdef DEBUG_INPUT_EVENTS
SDL_Log("Joystick : Re-read Button %d (%d) val= %d\n",
joystick->hwdata->key_map[i], i, value);
joystick->hwdata->key_map[i], i, down);
#endif
SDL_SendJoystickButton(timestamp, joystick,
joystick->hwdata->key_map[i], value);
joystick->hwdata->key_map[i], down);
}
}
}
@ -1982,7 +1982,7 @@ static void HandleInputEvents(SDL_Joystick *joystick)
#endif
SDL_SendJoystickButton(SDL_EVDEV_GetEventTimestamp(event), joystick,
joystick->hwdata->key_map[code],
event->value);
(event->value != 0));
break;
case EV_ABS:
switch (code) {
@ -2163,8 +2163,8 @@ static void HandleClassicEvents(SDL_Joystick *joystick)
case JS_EVENT_BUTTON:
code = joystick->hwdata->key_pam[events[i].number];
SDL_SendJoystickButton(timestamp, joystick,
joystick->hwdata->key_map[code],
events[i].value);
joystick->hwdata->key_map[code],
(events[i].value != 0));
break;
case JS_EVENT_AXIS:
code = joystick->hwdata->abs_pam[events[i].number];

View File

@ -120,7 +120,7 @@ static void UpdateN3DSPressedButtons(Uint64 timestamp, SDL_Joystick *joystick)
if (updated_down) {
for (Uint8 i = 0; i < joystick->nbuttons; i++) {
if (current_state & BIT(i) & updated_down) {
SDL_SendJoystickButton(timestamp, joystick, i, SDL_PRESSED);
SDL_SendJoystickButton(timestamp, joystick, i, true);
}
}
}
@ -136,7 +136,7 @@ static void UpdateN3DSReleasedButtons(Uint64 timestamp, SDL_Joystick *joystick)
if (updated_up) {
for (Uint8 i = 0; i < joystick->nbuttons; i++) {
if (current_state & BIT(i) & updated_up) {
SDL_SendJoystickButton(timestamp, joystick, i, SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, i, false);
}
}
}

View File

@ -294,7 +294,7 @@ static void PS2_JoystickUpdate(SDL_Joystick *joystick)
previous = info->btns & mask;
current = pressed_buttons & mask;
if (previous != current) {
SDL_SendJoystickButton(timestamp, joystick, i, current ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, i, (current != 0));
}
}
}

View File

@ -227,9 +227,9 @@ static void PSP_JoystickUpdate(SDL_Joystick *joystick)
if (changed) {
for (i = 0; i < SDL_arraysize(button_map); i++) {
if (changed & button_map[i]) {
bool down = ((buttons & button_map[i]) != 0);
SDL_SendJoystickButton(timestamp,
joystick, i,
(buttons & button_map[i]) ? SDL_PRESSED : SDL_RELEASED);
joystick, i, down);
}
}
}

View File

@ -99,7 +99,7 @@ static void VIRTUAL_FreeHWData(joystick_hwdata *hwdata)
hwdata->axes = NULL;
}
if (hwdata->buttons) {
SDL_free((void *)hwdata->buttons);
SDL_free(hwdata->buttons);
hwdata->buttons = NULL;
}
if (hwdata->hats) {
@ -250,7 +250,7 @@ SDL_JoystickID SDL_JoystickAttachVirtualInner(const SDL_VirtualJoystickDesc *des
}
}
if (hwdata->desc.nbuttons > 0) {
hwdata->buttons = (Uint8 *)SDL_calloc(hwdata->desc.nbuttons, sizeof(*hwdata->buttons));
hwdata->buttons = (SDL_bool *)SDL_calloc(hwdata->desc.nbuttons, sizeof(*hwdata->buttons));
if (!hwdata->buttons) {
VIRTUAL_FreeHWData(hwdata);
return 0;
@ -383,7 +383,7 @@ bool SDL_SetJoystickVirtualBallInner(SDL_Joystick *joystick, int ball, Sint16 xr
return true;
}
bool SDL_SetJoystickVirtualButtonInner(SDL_Joystick *joystick, int button, Uint8 value)
bool SDL_SetJoystickVirtualButtonInner(SDL_Joystick *joystick, int button, bool down)
{
joystick_hwdata *hwdata;
@ -398,7 +398,7 @@ bool SDL_SetJoystickVirtualButtonInner(SDL_Joystick *joystick, int button, Uint8
return SDL_SetError("Invalid button index");
}
hwdata->buttons[button] = value;
hwdata->buttons[button] = down;
hwdata->changes |= BUTTONS_CHANGED;
return true;
@ -425,7 +425,7 @@ bool SDL_SetJoystickVirtualHatInner(SDL_Joystick *joystick, int hat, Uint8 value
return true;
}
bool SDL_SetJoystickVirtualTouchpadInner(SDL_Joystick *joystick, int touchpad, int finger, Uint8 state, float x, float y, float pressure)
bool SDL_SetJoystickVirtualTouchpadInner(SDL_Joystick *joystick, int touchpad, int finger, bool down, float x, float y, float pressure)
{
joystick_hwdata *hwdata;
@ -444,7 +444,7 @@ bool SDL_SetJoystickVirtualTouchpadInner(SDL_Joystick *joystick, int touchpad, i
}
SDL_JoystickTouchpadFingerInfo *info = &hwdata->touchpads[touchpad].fingers[finger];
info->state = state;
info->down = down;
info->x = x;
info->y = y;
info->pressure = pressure;
@ -754,7 +754,7 @@ static void VIRTUAL_JoystickUpdate(SDL_Joystick *joystick)
const SDL_JoystickTouchpadInfo *touchpad = &hwdata->touchpads[i];
for (int j = 0; j < touchpad->nfingers; ++j) {
const SDL_JoystickTouchpadFingerInfo *finger = &touchpad->fingers[j];
SDL_SendJoystickTouchpad(timestamp, joystick, i, j, finger->state, finger->x, finger->y, finger->pressure);
SDL_SendJoystickTouchpad(timestamp, joystick, i, j, finger->down, finger->x, finger->y, finger->pressure);
}
}
}

View File

@ -54,7 +54,7 @@ typedef struct joystick_hwdata
SDL_VirtualJoystickDesc desc;
Uint32 changes;
Sint16 *axes;
Uint8 *buttons;
bool *buttons;
Uint8 *hats;
SDL_JoystickBallData *balls;
SDL_JoystickTouchpadInfo *touchpads;
@ -74,9 +74,9 @@ extern bool SDL_JoystickDetachVirtualInner(SDL_JoystickID instance_id);
extern bool SDL_SetJoystickVirtualAxisInner(SDL_Joystick *joystick, int axis, Sint16 value);
extern bool SDL_SetJoystickVirtualBallInner(SDL_Joystick *joystick, int ball, Sint16 xrel, Sint16 yrel);
extern bool SDL_SetJoystickVirtualButtonInner(SDL_Joystick *joystick, int button, Uint8 value);
extern bool SDL_SetJoystickVirtualButtonInner(SDL_Joystick *joystick, int button, bool down);
extern bool SDL_SetJoystickVirtualHatInner(SDL_Joystick *joystick, int hat, Uint8 value);
extern bool SDL_SetJoystickVirtualTouchpadInner(SDL_Joystick *joystick, int touchpad, int finger, Uint8 state, float x, float y, float pressure);
extern bool SDL_SetJoystickVirtualTouchpadInner(SDL_Joystick *joystick, int touchpad, int finger, bool down, float x, float y, float pressure);
extern bool SDL_SendJoystickVirtualSensorDataInner(SDL_Joystick *joystick, SDL_SensorType type, Uint64 sensor_timestamp, const float *data, int num_values);
#endif // SDL_JOYSTICK_VIRTUAL

View File

@ -300,9 +300,8 @@ static void VITA_JoystickUpdate(SDL_Joystick *joystick)
if (changed) {
for (i = 0; i < SDL_arraysize(ext_button_map); i++) {
if (changed & ext_button_map[i]) {
SDL_SendJoystickButton(timestamp,
joystick, i,
(buttons & ext_button_map[i]) ? SDL_PRESSED : SDL_RELEASED);
bool down = ((buttons & ext_button_map[i]) != 0);
SDL_SendJoystickButton(timestamp, joystick, i, down);
}
}
}

View File

@ -1033,7 +1033,7 @@ static void UpdateDINPUTJoystickState_Polled(SDL_Joystick *joystick)
case BUTTON:
SDL_SendJoystickButton(timestamp, joystick, in->num,
(Uint8)(state.rgbButtons[in->ofs - DIJOFS_BUTTON0] ? SDL_PRESSED : SDL_RELEASED));
(state.rgbButtons[in->ofs - DIJOFS_BUTTON0] != 0));
break;
case HAT:
{
@ -1087,7 +1087,7 @@ static void UpdateDINPUTJoystickState_Buffered(SDL_Joystick *joystick)
break;
case BUTTON:
SDL_SendJoystickButton(timestamp, joystick, in->num,
(Uint8)(evtbuf[i].dwData ? SDL_PRESSED : SDL_RELEASED));
(evtbuf[i].dwData != 0));
break;
case HAT:
{

View File

@ -1093,7 +1093,7 @@ static void RAWINPUT_PostUpdate(void)
if (ctx->guide_hack) {
int guide_button = joystick->nbuttons - 1;
SDL_SendJoystickButton(SDL_GetTicksNS(), guide_button_candidate.joystick, (Uint8)guide_button, SDL_PRESSED);
SDL_SendJoystickButton(SDL_GetTicksNS(), guide_button_candidate.joystick, (Uint8)guide_button, true);
}
guide_button_candidate.last_joystick = guide_button_candidate.joystick;
}
@ -1103,7 +1103,7 @@ static void RAWINPUT_PostUpdate(void)
if (ctx->guide_hack) {
int guide_button = joystick->nbuttons - 1;
SDL_SendJoystickButton(SDL_GetTicksNS(), joystick, (Uint8)guide_button, SDL_RELEASED);
SDL_SendJoystickButton(SDL_GetTicksNS(), joystick, (Uint8)guide_button, false);
}
guide_button_candidate.last_joystick = NULL;
}
@ -1591,12 +1591,12 @@ static void RAWINPUT_HandleStatePacket(SDL_Joystick *joystick, Uint8 *data, int
};
Uint64 match_state = ctx->match_state;
// Update match_state with button bit, then fall through
#define SDL_SendJoystickButton(timestamp, joystick, button, state) \
#define SDL_SendJoystickButton(timestamp, joystick, button, down) \
if (button < SDL_arraysize(button_map)) { \
Uint64 button_bit = 1ull << button_map[button]; \
match_state = (match_state & ~button_bit) | (button_bit * (state)); \
match_state = (match_state & ~button_bit) | (button_bit * (down)); \
} \
SDL_SendJoystickButton(timestamp, joystick, button, state)
SDL_SendJoystickButton(timestamp, joystick, button, down)
#ifdef SDL_JOYSTICK_RAWINPUT_MATCH_AXES
// Grab high 4 bits of value, then fall through
#define AddAxisToMatchState(axis, value) \
@ -1629,7 +1629,7 @@ static void RAWINPUT_HandleStatePacket(SDL_Joystick *joystick, Uint8 *data, int
}
}
for (i = 0; i < nbuttons; ++i) {
SDL_SendJoystickButton(timestamp, joystick, (Uint8)i, (button_mask & (1 << i)) ? SDL_PRESSED : SDL_RELEASED);
SDL_SendJoystickButton(timestamp, joystick, (Uint8)i, ((button_mask & (1 << i)) != 0));
}
for (i = 0; i < naxes; ++i) {
@ -1786,7 +1786,7 @@ static void RAWINPUT_UpdateOtherAPIs(SDL_Joystick *joystick)
/* It gets left down if we were actually correlated incorrectly and it was released on the WindowsGamingInput
device but we didn't get a state packet. */
if (ctx->guide_hack) {
SDL_SendJoystickButton(0, joystick, (Uint8)guide_button, SDL_RELEASED);
SDL_SendJoystickButton(0, joystick, (Uint8)guide_button, false);
}
}
}
@ -1882,7 +1882,7 @@ static void RAWINPUT_UpdateOtherAPIs(SDL_Joystick *joystick)
/* It gets left down if we were actually correlated incorrectly and it was released on the XInput
device but we didn't get a state packet. */
if (ctx->guide_hack) {
SDL_SendJoystickButton(0, joystick, (Uint8)guide_button, SDL_RELEASED);
SDL_SendJoystickButton(0, joystick, (Uint8)guide_button, false);
}
}
}
@ -1955,7 +1955,8 @@ static void RAWINPUT_UpdateOtherAPIs(SDL_Joystick *joystick)
}
if (ctx->guide_hack) {
SDL_SendJoystickButton(timestamp, joystick, (Uint8)guide_button, (xinput_state[ctx->xinput_slot].state.Gamepad.wButtons & XINPUT_GAMEPAD_GUIDE) ? SDL_PRESSED : SDL_RELEASED);
bool down = ((xinput_state[ctx->xinput_slot].state.Gamepad.wButtons & XINPUT_GAMEPAD_GUIDE) != 0);
SDL_SendJoystickButton(timestamp, joystick, (Uint8)guide_button, down);
}
if (ctx->trigger_hack) {
SDL_SendJoystickAxis(timestamp, joystick, (Uint8)left_trigger, ((int)xinput_state[ctx->xinput_slot].state.Gamepad.bLeftTrigger * 257) - 32768);
@ -2012,7 +2013,8 @@ static void RAWINPUT_UpdateOtherAPIs(SDL_Joystick *joystick)
}
if (ctx->guide_hack) {
SDL_SendJoystickButton(timestamp, joystick, (Uint8)guide_button, (state->Buttons & GamepadButtons_GUIDE) ? SDL_PRESSED : SDL_RELEASED);
bool down = ((state->Buttons & GamepadButtons_GUIDE) != 0);
SDL_SendJoystickButton(timestamp, joystick, (Uint8)guide_button, down);
}
if (ctx->trigger_hack) {
SDL_SendJoystickAxis(timestamp, joystick, (Uint8)left_trigger, (Sint16)(((int)(state->LeftTrigger * SDL_MAX_UINT16)) - 32768));

View File

@ -344,7 +344,8 @@ static void UpdateXInputJoystickState(SDL_Joystick *joystick, XINPUT_STATE *pXIn
SDL_SendJoystickAxis(timestamp, joystick, 5, ((int)pXInputState->Gamepad.bRightTrigger * 257) - 32768);
for (button = 0; button < (Uint8)SDL_arraysize(s_XInputButtons); ++button) {
SDL_SendJoystickButton(timestamp, joystick, button, (wButtons & s_XInputButtons[button]) ? SDL_PRESSED : SDL_RELEASED);
bool down = ((wButtons & s_XInputButtons[button]) != 0);
SDL_SendJoystickButton(timestamp, joystick, button, down);
}
if (wButtons & XINPUT_GAMEPAD_DPAD_UP) {

View File

@ -370,12 +370,12 @@ static SDL_Scancode TranslateKeycode(int keycode)
void Android_OnKeyDown(int keycode)
{
SDL_SendKeyboardKey(0, SDL_DEFAULT_KEYBOARD_ID, keycode, TranslateKeycode(keycode), SDL_PRESSED);
SDL_SendKeyboardKey(0, SDL_DEFAULT_KEYBOARD_ID, keycode, TranslateKeycode(keycode), true);
}
void Android_OnKeyUp(int keycode)
{
SDL_SendKeyboardKey(0, SDL_DEFAULT_KEYBOARD_ID, keycode, TranslateKeycode(keycode), SDL_RELEASED);
SDL_SendKeyboardKey(0, SDL_DEFAULT_KEYBOARD_ID, keycode, TranslateKeycode(keycode), false);
}
bool Android_HasScreenKeyboardSupport(SDL_VideoDevice *_this)

View File

@ -221,7 +221,7 @@ void Android_OnMouse(SDL_Window *window, int state, int action, float x, float y
button = TranslateButton(changes);
last_state = state;
SDL_SendMouseMotion(0, window, SDL_DEFAULT_MOUSE_ID, relative, x, y);
SDL_SendMouseButton(0, window, SDL_DEFAULT_MOUSE_ID, SDL_PRESSED, button);
SDL_SendMouseButton(0, window, SDL_DEFAULT_MOUSE_ID, button, true);
break;
case ACTION_UP:
@ -229,7 +229,7 @@ void Android_OnMouse(SDL_Window *window, int state, int action, float x, float y
button = TranslateButton(changes);
last_state = state;
SDL_SendMouseMotion(0, window, SDL_DEFAULT_MOUSE_ID, relative, x, y);
SDL_SendMouseButton(0, window, SDL_DEFAULT_MOUSE_ID, SDL_RELEASED, button);
SDL_SendMouseButton(0, window, SDL_DEFAULT_MOUSE_ID, button, false);
break;
case ACTION_MOVE:

View File

@ -209,7 +209,7 @@
return;
}
SDL_SendKeyboardKey(_pendingTimestamp, SDL_DEFAULT_KEYBOARD_ID, _pendingRawCode, _pendingScancode, SDL_PRESSED);
SDL_SendKeyboardKey(_pendingTimestamp, SDL_DEFAULT_KEYBOARD_ID, _pendingRawCode, _pendingScancode, true);
[self clearPendingKey];
}
@ -268,9 +268,9 @@ static void HandleModifiers(SDL_VideoDevice *_this, SDL_Scancode code, unsigned
}
if (pressed) {
SDL_SendKeyboardKey(0, SDL_DEFAULT_KEYBOARD_ID, 0, code, SDL_PRESSED);
SDL_SendKeyboardKey(0, SDL_DEFAULT_KEYBOARD_ID, 0, code, true);
} else {
SDL_SendKeyboardKey(0, SDL_DEFAULT_KEYBOARD_ID, 0, code, SDL_RELEASED);
SDL_SendKeyboardKey(0, SDL_DEFAULT_KEYBOARD_ID, 0, code, false);
}
}
@ -471,11 +471,11 @@ void Cocoa_HandleKeyEvent(SDL_VideoDevice *_this, NSEvent *event)
[data.fieldEdit interpretKeyEvents:[NSArray arrayWithObject:event]];
[data.fieldEdit sendPendingKey];
} else {
SDL_SendKeyboardKey(Cocoa_GetEventTimestamp([event timestamp]), SDL_DEFAULT_KEYBOARD_ID, scancode, code, SDL_PRESSED);
SDL_SendKeyboardKey(Cocoa_GetEventTimestamp([event timestamp]), SDL_DEFAULT_KEYBOARD_ID, scancode, code, true);
}
break;
case NSEventTypeKeyUp:
SDL_SendKeyboardKey(Cocoa_GetEventTimestamp([event timestamp]), SDL_DEFAULT_KEYBOARD_ID, scancode, code, SDL_RELEASED);
SDL_SendKeyboardKey(Cocoa_GetEventTimestamp([event timestamp]), SDL_DEFAULT_KEYBOARD_ID, scancode, code, false);
break;
case NSEventTypeFlagsChanged: {
// see if the new modifierFlags mean any existing keys should be pressed/released...

View File

@ -128,10 +128,10 @@ static void Cocoa_HandlePenPointEvent(SDL_CocoaWindowData *_data, NSEvent *event
const bool is_touching = (buttons & NSEventButtonMaskPenTip) != 0;
SDL_Window *window = _data.window;
SDL_SendPenTouch(timestamp, pen, window, is_touching, handle->is_eraser ? 1 : 0);
SDL_SendPenTouch(timestamp, pen, window, handle->is_eraser, is_touching);
SDL_SendPenMotion(timestamp, pen, window, (float) point.x, (float) (window->h - point.y));
SDL_SendPenButton(timestamp, pen, window, (buttons & NSEventButtonMaskPenLowerSide) ? SDL_PRESSED : SDL_RELEASED, 1);
SDL_SendPenButton(timestamp, pen, window, (buttons & NSEventButtonMaskPenUpperSide) ? SDL_PRESSED : SDL_RELEASED, 2);
SDL_SendPenButton(timestamp, pen, window, 1, ((buttons & NSEventButtonMaskPenLowerSide) != 0));
SDL_SendPenButton(timestamp, pen, window, 2, ((buttons & NSEventButtonMaskPenUpperSide) != 0));
SDL_SendPenAxis(timestamp, pen, window, SDL_PEN_AXIS_PRESSURE, [event pressure]);
SDL_SendPenAxis(timestamp, pen, window, SDL_PEN_AXIS_ROTATION, [event rotation]);
SDL_SendPenAxis(timestamp, pen, window, SDL_PEN_AXIS_XTILT, ((float) tilt.x) * 90.0f);

View File

@ -1466,8 +1466,8 @@ static NSCursor *Cocoa_GetDesiredCursor(void)
const bool osenabled = ([theEvent modifierFlags] & NSEventModifierFlagCapsLock) ? true : false;
const bool sdlenabled = (SDL_GetModState() & SDL_KMOD_CAPS) ? true : false;
if (osenabled ^ sdlenabled) {
SDL_SendKeyboardKey(0, SDL_DEFAULT_KEYBOARD_ID, 0, SDL_SCANCODE_CAPSLOCK, SDL_PRESSED);
SDL_SendKeyboardKey(0, SDL_DEFAULT_KEYBOARD_ID, 0, SDL_SCANCODE_CAPSLOCK, SDL_RELEASED);
SDL_SendKeyboardKey(0, SDL_DEFAULT_KEYBOARD_ID, 0, SDL_SCANCODE_CAPSLOCK, true);
SDL_SendKeyboardKey(0, SDL_DEFAULT_KEYBOARD_ID, 0, SDL_SCANCODE_CAPSLOCK, false);
}
}
- (void)keyDown:(NSEvent *)theEvent
@ -1538,7 +1538,7 @@ static NSCursor *Cocoa_GetDesiredCursor(void)
return NO; // not a special area, carry on.
}
static void Cocoa_SendMouseButtonClicks(SDL_Mouse *mouse, NSEvent *theEvent, SDL_Window *window, const Uint8 state, const Uint8 button)
static void Cocoa_SendMouseButtonClicks(SDL_Mouse *mouse, NSEvent *theEvent, SDL_Window *window, Uint8 button, SDL_bool down)
{
SDL_MouseID mouseID = SDL_DEFAULT_MOUSE_ID;
const int clicks = (int)[theEvent clickCount];
@ -1550,14 +1550,14 @@ static void Cocoa_SendMouseButtonClicks(SDL_Mouse *mouse, NSEvent *theEvent, SDL
// event for the background window, this just makes sure the button is reported at the
// correct position in its own event.
if (focus && ([theEvent window] == ((__bridge SDL_CocoaWindowData *)focus->internal).nswindow)) {
SDL_SendMouseButtonClicks(Cocoa_GetEventTimestamp([theEvent timestamp]), window, mouseID, state, button, clicks);
SDL_SendMouseButtonClicks(Cocoa_GetEventTimestamp([theEvent timestamp]), window, mouseID, button, down, clicks);
} else {
const float orig_x = mouse->x;
const float orig_y = mouse->y;
const NSPoint point = [theEvent locationInWindow];
mouse->x = (int)point.x;
mouse->y = (int)(window->h - point.y);
SDL_SendMouseButtonClicks(Cocoa_GetEventTimestamp([theEvent timestamp]), window, mouseID, state, button, clicks);
SDL_SendMouseButtonClicks(Cocoa_GetEventTimestamp([theEvent timestamp]), window, mouseID, button, down, clicks);
mouse->x = orig_x;
mouse->y = orig_y;
}
@ -1611,7 +1611,7 @@ static void Cocoa_SendMouseButtonClicks(SDL_Mouse *mouse, NSEvent *theEvent, SDL
break;
}
Cocoa_SendMouseButtonClicks(mouse, theEvent, _data.window, SDL_PRESSED, button);
Cocoa_SendMouseButtonClicks(mouse, theEvent, _data.window, button, true);
}
- (void)rightMouseDown:(NSEvent *)theEvent
@ -1662,7 +1662,7 @@ static void Cocoa_SendMouseButtonClicks(SDL_Mouse *mouse, NSEvent *theEvent, SDL
break;
}
Cocoa_SendMouseButtonClicks(mouse, theEvent, _data.window, SDL_RELEASED, button);
Cocoa_SendMouseButtonClicks(mouse, theEvent, _data.window, button, false);
}
- (void)rightMouseUp:(NSEvent *)theEvent

View File

@ -295,8 +295,7 @@ static EM_BOOL Emscripten_HandleMouseButton(int eventType, const EmscriptenMouse
{
SDL_WindowData *window_data = userData;
Uint8 sdl_button;
Uint8 sdl_button_state;
SDL_EventType sdl_event_type;
bool sdl_button_state;
double css_w, css_h;
bool prevent_default = false; // needed for iframe implementation in Chrome-based browsers.
@ -318,14 +317,12 @@ static EM_BOOL Emscripten_HandleMouseButton(int eventType, const EmscriptenMouse
if (SDL_GetMouse()->relative_mode && !window_data->has_pointer_lock) {
emscripten_request_pointerlock(window_data->canvas_id, 0); // try to regrab lost pointer lock.
}
sdl_button_state = SDL_PRESSED;
sdl_event_type = SDL_EVENT_MOUSE_BUTTON_DOWN;
sdl_button_state = true;
} else {
sdl_button_state = SDL_RELEASED;
sdl_event_type = SDL_EVENT_MOUSE_BUTTON_UP;
prevent_default = SDL_EventEnabled(sdl_event_type);
sdl_button_state = false;
prevent_default = SDL_EventEnabled(SDL_EVENT_MOUSE_BUTTON_UP);
}
SDL_SendMouseButton(0, window_data->window, SDL_DEFAULT_MOUSE_ID, sdl_button_state, sdl_button);
SDL_SendMouseButton(0, window_data->window, SDL_DEFAULT_MOUSE_ID, sdl_button, sdl_button_state);
// Do not consume the event if the mouse is outside of the canvas.
emscripten_get_element_css_size(window_data->canvas_id, &css_w, &css_h);
@ -511,9 +508,9 @@ static EM_BOOL Emscripten_HandleKey(int eventType, const EmscriptenKeyboardEvent
}
if (keycode != SDLK_UNKNOWN) {
prevent_default = SDL_SendKeyboardKeyAndKeycode(0, SDL_DEFAULT_KEYBOARD_ID, 0, scancode, keycode, eventType == EMSCRIPTEN_EVENT_KEYDOWN ? SDL_PRESSED : SDL_RELEASED);
prevent_default = SDL_SendKeyboardKeyAndKeycode(0, SDL_DEFAULT_KEYBOARD_ID, 0, scancode, keycode, (eventType == EMSCRIPTEN_EVENT_KEYDOWN));
} else {
prevent_default = SDL_SendKeyboardKey(0, SDL_DEFAULT_KEYBOARD_ID, 0, scancode, eventType == EMSCRIPTEN_EVENT_KEYDOWN ? SDL_PRESSED : SDL_RELEASED);
prevent_default = SDL_SendKeyboardKey(0, SDL_DEFAULT_KEYBOARD_ID, 0, scancode, (eventType == EMSCRIPTEN_EVENT_KEYDOWN));
}
/* if TEXTINPUT events are enabled we can't prevent keydown or we won't get keypress
@ -681,13 +678,17 @@ static void Emscripten_UpdatePointerFromEvent(SDL_WindowData *window_data, const
SDL_SendPenMotion(0, pen, window_data->window, mx, my);
if (event->button == 0) { // pen touch
SDL_SendPenTouch(0, pen, window_data->window, (event->buttons & 1) ? SDL_PRESSED : SDL_RELEASED, 0);
bool down = ((event->buttons & 1) != 0);
SDL_SendPenTouch(0, pen, window_data->window, false, down);
} else if (event->button == 5) { // eraser touch...? Not sure if this is right...
SDL_SendPenTouch(0, pen, window_data->window, (event->buttons & 32) ? SDL_PRESSED : SDL_RELEASED, 1);
bool down = ((event->buttons & 32) != 0);
SDL_SendPenTouch(0, pen, window_data->window, true, down);
} else if (event->button == 1) {
SDL_SendPenButton(0, pen, window_data->window, (event->buttons & 4) ? SDL_PRESSED : SDL_RELEASED, 2);
bool down = ((event->buttons & 4) != 0);
SDL_SendPenButton(0, pen, window_data->window, 2, down);
} else if (event->button == 2) {
SDL_SendPenButton(0, pen, window_data->window, (event->buttons & 2) ? SDL_PRESSED : SDL_RELEASED, 1);
bool down = ((event->buttons & 2) != 0);
SDL_SendPenButton(0, pen, window_data->window, 1, down);
}
SDL_SendPenAxis(0, pen, window_data->window, SDL_PEN_AXIS_PRESSURE, event->pressure);

View File

@ -337,13 +337,13 @@ class SDL_BWin : public BWindow
case B_MOUSE_DOWN:
if (msg->FindInt32("buttons", &buttons) == B_OK) {
_MouseButtonEvent(buttons, SDL_PRESSED);
_MouseButtonEvent(buttons, true);
}
break;
case B_MOUSE_UP:
if (msg->FindInt32("buttons", &buttons) == B_OK) {
_MouseButtonEvent(buttons, SDL_RELEASED);
_MouseButtonEvent(buttons, false);
}
break;
@ -364,20 +364,20 @@ class SDL_BWin : public BWindow
i++;
}
if (msg->FindInt32("key", &key) == B_OK) {
_KeyEvent((SDL_Scancode)key, &bytes[0], i, SDL_PRESSED);
_KeyEvent((SDL_Scancode)key, &bytes[0], i, true);
}
} break;
case B_UNMAPPED_KEY_DOWN: // modifier keys are unmapped
if (msg->FindInt32("key", &key) == B_OK) {
_KeyEvent((SDL_Scancode)key, NULL, 0, SDL_PRESSED);
_KeyEvent((SDL_Scancode)key, NULL, 0, true);
}
break;
case B_KEY_UP:
case B_UNMAPPED_KEY_UP: // modifier keys are unmapped
if (msg->FindInt32("key", &key) == B_OK) {
_KeyEvent(key, NULL, 0, SDL_RELEASED);
_KeyEvent(key, NULL, 0, false);
}
break;
@ -532,28 +532,28 @@ class SDL_BWin : public BWindow
if true: SDL_SetCursor(NULL); */
}
void _MouseButtonEvent(int32 buttons, Uint8 state)
void _MouseButtonEvent(int32 buttons, bool down)
{
int32 buttonStateChange = buttons ^ _last_buttons;
if (buttonStateChange & B_PRIMARY_MOUSE_BUTTON) {
_SendMouseButton(SDL_BUTTON_LEFT, state);
_SendMouseButton(SDL_BUTTON_LEFT, down);
}
if (buttonStateChange & B_SECONDARY_MOUSE_BUTTON) {
_SendMouseButton(SDL_BUTTON_RIGHT, state);
_SendMouseButton(SDL_BUTTON_RIGHT, down);
}
if (buttonStateChange & B_TERTIARY_MOUSE_BUTTON) {
_SendMouseButton(SDL_BUTTON_MIDDLE, state);
_SendMouseButton(SDL_BUTTON_MIDDLE, down);
}
_last_buttons = buttons;
}
void _SendMouseButton(int32 button, int32 state)
void _SendMouseButton(int32 button, bool down)
{
BMessage msg(BAPP_MOUSE_BUTTON);
msg.AddInt32("button-id", button);
msg.AddInt32("button-state", state);
msg.AddBool("button-down", down);
_PostWindowEvent(msg);
}
@ -566,15 +566,15 @@ class SDL_BWin : public BWindow
_PostWindowEvent(msg);
}
void _KeyEvent(int32 keyCode, const int8 *keyUtf8, const ssize_t &len, int32 keyState)
void _KeyEvent(int32 keyCode, const int8 *keyUtf8, const ssize_t &len, bool down)
{
// Create a message to pass along to the BeApp thread
BMessage msg(BAPP_KEY);
msg.AddInt32("key-state", keyState);
msg.AddInt32("key-scancode", keyCode);
if (keyUtf8 != NULL) {
msg.AddData("key-utf8", B_INT8_TYPE, (const void *)keyUtf8, len);
}
msg.AddBool("key-down", down);
SDL_Looper->PostMessage(&msg);
}

View File

@ -153,10 +153,10 @@ static void HandleWsEvent(SDL_VideoDevice *_this, const TWsEvent &aWsEvent)
switch (aWsEvent.Type()) {
case EEventKeyDown: // Key events
SDL_SendKeyboardKey(0, SDL_GLOBAL_KEYBOARD_ID, aWsEvent.Key()->iScanCode, ConvertScancode(_this, aWsEvent.Key()->iScanCode), SDL_PRESSED);
SDL_SendKeyboardKey(0, SDL_GLOBAL_KEYBOARD_ID, aWsEvent.Key()->iScanCode, ConvertScancode(_this, aWsEvent.Key()->iScanCode), true);
break;
case EEventKeyUp: // Key events
SDL_SendKeyboardKey(0, SDL_GLOBAL_KEYBOARD_ID, aWsEvent.Key()->iScanCode, ConvertScancode(_this, aWsEvent.Key()->iScanCode), SDL_RELEASED);
SDL_SendKeyboardKey(0, SDL_GLOBAL_KEYBOARD_ID, aWsEvent.Key()->iScanCode, ConvertScancode(_this, aWsEvent.Key()->iScanCode), false);
break;
case EEventFocusGained: // SDL window got focus
data->NGAGE_IsWindowFocused = ETrue;

View File

@ -90,7 +90,8 @@ void PSP_PumpEvents(SDL_VideoDevice *_this)
if (changed) {
for (i = 0; i < sizeof(keymap_psp) / sizeof(keymap_psp[0]); i++) {
if (changed & keymap_psp[i].id) {
SDL_SendKeyboardKey(0, SDL_GLOBAL_KEYBOARD_ID, keymap_psp[i].id, keymap_psp[i].scancode, (keys & keymap_psp[i].id) ? SDL_PRESSED : SDL_RELEASED);
bool down = ((keys & keymap_psp[i].id) != 0);
SDL_SendKeyboardKey(0, SDL_GLOBAL_KEYBOARD_ID, keymap_psp[i].id, keymap_psp[i].scancode, down);
}
}
}
@ -105,11 +106,12 @@ void PSP_PumpEvents(SDL_VideoDevice *_this)
if ((length % sizeof(SIrKeybScanCodeData)) == 0) {
count = length / sizeof(SIrKeybScanCodeData);
for (i = 0; i < count; i++) {
unsigned char raw, pressed;
unsigned char raw;
SDL_bool down;
scanData = (SIrKeybScanCodeData *)buffer + i;
raw = scanData->raw;
pressed = scanData->pressed;
SDL_SendKeyboardKey(0, SDL_GLOBAL_KEYBOARD_ID, raw, keymap[raw], pressed ? SDL_PRESSED : SDL_RELEASED);
down = (scanData->pressed != 0);
SDL_SendKeyboardKey(0, SDL_GLOBAL_KEYBOARD_ID, raw, keymap[raw], down);
}
}
}

View File

@ -125,8 +125,8 @@ void handleKeyboardEvent(screen_event_t event)
// FIXME:
// Need to handle more key states (such as key combinations).
if (val & KEY_DOWN) {
SDL_SendKeyboardKey(0, SDL_DEFAULT_KEYBOARD_ID, val, scancode, SDL_PRESSED);
SDL_SendKeyboardKey(0, SDL_DEFAULT_KEYBOARD_ID, val, scancode, true);
} else {
SDL_SendKeyboardKey(0, SDL_DEFAULT_KEYBOARD_ID, val, scancode, SDL_RELEASED);
SDL_SendKeyboardKey(0, SDL_DEFAULT_KEYBOARD_ID, val, scancode, false);
}
}

View File

@ -58,7 +58,7 @@ void RISCOS_PollKeyboard(SDL_VideoDevice *_this)
for (i = 0; i < RISCOS_MAX_KEYS_PRESSED; i++) {
if (internal->key_pressed[i] != 255) {
if ((_kernel_osbyte(129, internal->key_pressed[i] ^ 0xff, 0xff) & 0xff) != 255) {
SDL_SendKeyboardKey(0, SDL_DEFAULT_KEYBOARD_ID, internal->key_pressed[i], SDL_RISCOS_translate_keycode(internal->key_pressed[i]), SDL_RELEASED);
SDL_SendKeyboardKey(0, SDL_DEFAULT_KEYBOARD_ID, internal->key_pressed[i], SDL_RISCOS_translate_keycode(internal->key_pressed[i]), false);
internal->key_pressed[i] = 255;
}
}
@ -81,7 +81,7 @@ void RISCOS_PollKeyboard(SDL_VideoDevice *_this)
break;
default:
SDL_SendKeyboardKey(0, SDL_DEFAULT_KEYBOARD_ID, key, SDL_RISCOS_translate_keycode(key), SDL_PRESSED);
SDL_SendKeyboardKey(0, SDL_DEFAULT_KEYBOARD_ID, key, SDL_RISCOS_translate_keycode(key), true);
// Record the press so we can detect release later.
for (i = 0; i < RISCOS_MAX_KEYS_PRESSED; i++) {
@ -131,7 +131,8 @@ void RISCOS_PollMouse(SDL_VideoDevice *_this)
if (internal->last_mouse_buttons != buttons) {
for (i = 0; i < SDL_arraysize(mouse_button_map); i++) {
SDL_SendMouseButton(0, mouse->focus, SDL_DEFAULT_MOUSE_ID, (buttons & (1 << i)) ? SDL_PRESSED : SDL_RELEASED, mouse_button_map[i]);
bool down = ((buttons & (1 << i)) != 0);
SDL_SendMouseButton(0, mouse->focus, SDL_DEFAULT_MOUSE_ID, mouse_button_map[i], down);
}
internal->last_mouse_buttons = buttons;
}

View File

@ -187,7 +187,7 @@ static void OnGCKeyboardConnected(GCKeyboard *keyboard) API_AVAILABLE(macos(11.0
SDL_AddKeyboard(keyboardID, NULL, true);
keyboard.keyboardInput.keyChangedHandler = ^(GCKeyboardInput *kbrd, GCControllerButtonInput *key, GCKeyCode keyCode, BOOL pressed) {
SDL_SendKeyboardKey(0, keyboardID, 0, (SDL_Scancode)keyCode, pressed ? SDL_PRESSED : SDL_RELEASED);
SDL_SendKeyboardKey(0, keyboardID, 0, (SDL_Scancode)keyCode, pressed);
};
dispatch_queue_t queue = dispatch_queue_create("org.libsdl.input.keyboard", DISPATCH_QUEUE_SERIAL);
@ -318,7 +318,7 @@ static bool SetGCMouseRelativeMode(bool enabled)
static void OnGCMouseButtonChanged(SDL_MouseID mouseID, Uint8 button, BOOL pressed)
{
SDL_SendMouseButton(0, SDL_GetMouseFocus(), mouseID, pressed ? SDL_PRESSED : SDL_RELEASED, button);
SDL_SendMouseButton(0, SDL_GetMouseFocus(), mouseID, button, pressed);
}
static void OnGCMouseConnected(GCMouse *mouse) API_AVAILABLE(macos(11.0), ios(14.0), tvos(14.0))

View File

@ -255,7 +255,7 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick;
button = (Uint8)i;
break;
}
SDL_SendMouseButton(UIKit_GetEventTimestamp([event timestamp]), sdlwindow, SDL_GLOBAL_MOUSE_ID, SDL_PRESSED, button);
SDL_SendMouseButton(UIKit_GetEventTimestamp([event timestamp]), sdlwindow, SDL_GLOBAL_MOUSE_ID, button, true);
}
}
}
@ -311,7 +311,7 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick;
button = (Uint8)i;
break;
}
SDL_SendMouseButton(UIKit_GetEventTimestamp([event timestamp]), sdlwindow, SDL_GLOBAL_MOUSE_ID, SDL_RELEASED, button);
SDL_SendMouseButton(UIKit_GetEventTimestamp([event timestamp]), sdlwindow, SDL_GLOBAL_MOUSE_ID, button, false);
}
}
}
@ -431,7 +431,7 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick;
if (!SDL_HasKeyboard()) {
for (UIPress *press in presses) {
SDL_Scancode scancode = [self scancodeFromPress:press];
SDL_SendKeyboardKey(UIKit_GetEventTimestamp([event timestamp]), SDL_GLOBAL_KEYBOARD_ID, 0, scancode, SDL_PRESSED);
SDL_SendKeyboardKey(UIKit_GetEventTimestamp([event timestamp]), SDL_GLOBAL_KEYBOARD_ID, 0, scancode, true);
}
}
if (SDL_TextInputActive(sdlwindow)) {
@ -444,7 +444,7 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick;
if (!SDL_HasKeyboard()) {
for (UIPress *press in presses) {
SDL_Scancode scancode = [self scancodeFromPress:press];
SDL_SendKeyboardKey(UIKit_GetEventTimestamp([event timestamp]), SDL_GLOBAL_KEYBOARD_ID, 0, scancode, SDL_RELEASED);
SDL_SendKeyboardKey(UIKit_GetEventTimestamp([event timestamp]), SDL_GLOBAL_KEYBOARD_ID, 0, scancode, false);
}
}
if (SDL_TextInputActive(sdlwindow)) {
@ -457,7 +457,7 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick;
if (!SDL_HasKeyboard()) {
for (UIPress *press in presses) {
SDL_Scancode scancode = [self scancodeFromPress:press];
SDL_SendKeyboardKey(UIKit_GetEventTimestamp([event timestamp]), SDL_GLOBAL_KEYBOARD_ID, 0, scancode, SDL_RELEASED);
SDL_SendKeyboardKey(UIKit_GetEventTimestamp([event timestamp]), SDL_GLOBAL_KEYBOARD_ID, 0, scancode, false);
}
}
if (SDL_TextInputActive(sdlwindow)) {

View File

@ -575,8 +575,8 @@ static void SDLCALL SDL_HideHomeIndicatorHintChanged(void *userdata, const char
size_t deleteLength = SDL_utf8strlen([[committedText substringFromIndex:matchLength] UTF8String]);
while (deleteLength > 0) {
// Send distinct down and up events for each backspace action
SDL_SendKeyboardKey(0, SDL_GLOBAL_KEYBOARD_ID, 0, SDL_SCANCODE_BACKSPACE, SDL_PRESSED);
SDL_SendKeyboardKey(0, SDL_GLOBAL_KEYBOARD_ID, 0, SDL_SCANCODE_BACKSPACE, SDL_RELEASED);
SDL_SendKeyboardKey(0, SDL_GLOBAL_KEYBOARD_ID, 0, SDL_SCANCODE_BACKSPACE, true);
SDL_SendKeyboardKey(0, SDL_GLOBAL_KEYBOARD_ID, 0, SDL_SCANCODE_BACKSPACE, false);
--deleteLength;
}
}

View File

@ -63,44 +63,44 @@ void VITA_PollKeyboard(void)
if (numReports < 0) {
keyboard_hid_handle = 0;
} else if (numReports) {
// Numlock and Capslock state changes only on a SDL_PRESSED event
// Numlock and Capslock state changes only on a pressed event
// The k_report only reports the state of the LED
if (k_reports[numReports - 1].modifiers[1] & 0x1) {
if (!(locks & 0x1)) {
SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_NUMLOCKCLEAR, SDL_PRESSED);
SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_NUMLOCKCLEAR, true);
locks |= 0x1;
}
} else {
if (locks & 0x1) {
SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_NUMLOCKCLEAR, SDL_RELEASED);
SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_NUMLOCKCLEAR, SDL_PRESSED);
SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_NUMLOCKCLEAR, SDL_RELEASED);
SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_NUMLOCKCLEAR, false);
SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_NUMLOCKCLEAR, true);
SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_NUMLOCKCLEAR, false);
locks &= ~0x1;
}
}
if (k_reports[numReports - 1].modifiers[1] & 0x2) {
if (!(locks & 0x2)) {
SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_CAPSLOCK, SDL_PRESSED);
SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_CAPSLOCK, true);
locks |= 0x2;
}
} else {
if (locks & 0x2) {
SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_CAPSLOCK, SDL_RELEASED);
SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_CAPSLOCK, SDL_PRESSED);
SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_CAPSLOCK, SDL_RELEASED);
SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_CAPSLOCK, false);
SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_CAPSLOCK, true);
SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_CAPSLOCK, false);
locks &= ~0x2;
}
}
if (k_reports[numReports - 1].modifiers[1] & 0x4) {
if (!(locks & 0x4)) {
SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_SCROLLLOCK, SDL_PRESSED);
SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_SCROLLLOCK, true);
locks |= 0x4;
}
} else {
if (locks & 0x4) {
SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_SCROLLLOCK, SDL_RELEASED);
SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_SCROLLLOCK, false);
locks &= ~0x4;
}
}
@ -110,58 +110,58 @@ void VITA_PollKeyboard(void)
if (changed_modifiers & 0x01) {
if (prev_modifiers & 0x01) {
SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_LCTRL, SDL_RELEASED);
SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_LCTRL, false);
} else {
SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_LCTRL, SDL_PRESSED);
SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_LCTRL, true);
}
}
if (changed_modifiers & 0x02) {
if (prev_modifiers & 0x02) {
SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_LSHIFT, SDL_RELEASED);
SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_LSHIFT, false);
} else {
SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_LSHIFT, SDL_PRESSED);
SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_LSHIFT, true);
}
}
if (changed_modifiers & 0x04) {
if (prev_modifiers & 0x04) {
SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_LALT, SDL_RELEASED);
SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_LALT, false);
} else {
SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_LALT, SDL_PRESSED);
SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_LALT, true);
}
}
if (changed_modifiers & 0x08) {
if (prev_modifiers & 0x08) {
SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_LGUI, SDL_RELEASED);
SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_LGUI, false);
} else {
SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_LGUI, SDL_PRESSED);
SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_LGUI, true);
}
}
if (changed_modifiers & 0x10) {
if (prev_modifiers & 0x10) {
SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_RCTRL, SDL_RELEASED);
SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_RCTRL, false);
} else {
SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_RCTRL, SDL_PRESSED);
SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_RCTRL, true);
}
}
if (changed_modifiers & 0x20) {
if (prev_modifiers & 0x20) {
SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_RSHIFT, SDL_RELEASED);
SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_RSHIFT, false);
} else {
SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_RSHIFT, SDL_PRESSED);
SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_RSHIFT, true);
}
}
if (changed_modifiers & 0x40) {
if (prev_modifiers & 0x40) {
SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_RALT, SDL_RELEASED);
SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_RALT, false);
} else {
SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_RALT, SDL_PRESSED);
SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_RALT, true);
}
}
if (changed_modifiers & 0x80) {
if (prev_modifiers & 0x80) {
SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_RGUI, SDL_RELEASED);
SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_RGUI, false);
} else {
SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_RGUI, SDL_PRESSED);
SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_RGUI, true);
}
}
}
@ -175,10 +175,10 @@ void VITA_PollKeyboard(void)
if (keyCode != prev_keys[i]) {
if (prev_keys[i]) {
SDL_SendKeyboardKey(0, keyboardID, 0, prev_keys[i], SDL_RELEASED);
SDL_SendKeyboardKey(0, keyboardID, 0, prev_keys[i], false);
}
if (keyCode) {
SDL_SendKeyboardKey(0, keyboardID, 0, keyCode, SDL_PRESSED);
SDL_SendKeyboardKey(0, keyboardID, 0, keyCode, true);
}
prev_keys[i] = keyCode;
}

View File

@ -59,21 +59,21 @@ void VITA_PollMouse(void)
if (changed_buttons & 0x1) {
if (prev_buttons & 0x1)
SDL_SendMouseButton(0, Vita_Window, mouseID, SDL_RELEASED, SDL_BUTTON_LEFT);
SDL_SendMouseButton(0, Vita_Window, mouseID, SDL_BUTTON_LEFT, false);
else
SDL_SendMouseButton(0, Vita_Window, mouseID, SDL_PRESSED, SDL_BUTTON_LEFT);
SDL_SendMouseButton(0, Vita_Window, mouseID, SDL_BUTTON_LEFT, true);
}
if (changed_buttons & 0x2) {
if (prev_buttons & 0x2)
SDL_SendMouseButton(0, Vita_Window, mouseID, SDL_RELEASED, SDL_BUTTON_RIGHT);
SDL_SendMouseButton(0, Vita_Window, mouseID, SDL_BUTTON_RIGHT, false);
else
SDL_SendMouseButton(0, Vita_Window, mouseID, SDL_PRESSED, SDL_BUTTON_RIGHT);
SDL_SendMouseButton(0, Vita_Window, mouseID, SDL_BUTTON_RIGHT, true);
}
if (changed_buttons & 0x4) {
if (prev_buttons & 0x4)
SDL_SendMouseButton(0, Vita_Window, mouseID, SDL_RELEASED, SDL_BUTTON_MIDDLE);
SDL_SendMouseButton(0, Vita_Window, mouseID, SDL_BUTTON_MIDDLE, false);
else
SDL_SendMouseButton(0, Vita_Window, mouseID, SDL_PRESSED, SDL_BUTTON_MIDDLE);
SDL_SendMouseButton(0, Vita_Window, mouseID, SDL_BUTTON_MIDDLE, true);
}
prev_buttons = m_reports[i].buttons;

View File

@ -268,7 +268,7 @@ static bool keyboard_repeat_handle(SDL_WaylandKeyboardRepeat *repeat_info, Uint6
while (elapsed >= repeat_info->next_repeat_ns) {
if (repeat_info->scancode != SDL_SCANCODE_UNKNOWN) {
const Uint64 timestamp = repeat_info->wl_press_time_ns + repeat_info->next_repeat_ns;
SDL_SendKeyboardKeyIgnoreModifiers(Wayland_GetEventTimestamp(timestamp), repeat_info->keyboard_id, repeat_info->key, repeat_info->scancode, SDL_PRESSED);
SDL_SendKeyboardKeyIgnoreModifiers(Wayland_GetEventTimestamp(timestamp), repeat_info->keyboard_id, repeat_info->key, repeat_info->scancode, true);
}
if (repeat_info->text[0]) {
SDL_SendKeyboardText(repeat_info->text);
@ -593,11 +593,11 @@ static void pointer_handle_leave(void *data, struct wl_pointer *pointer,
// Clear the capture flag and raise all buttons
wind->sdlwindow->flags &= ~SDL_WINDOW_MOUSE_CAPTURE;
SDL_SendMouseButton(Wayland_GetPointerTimestamp(input, 0), wind->sdlwindow, input->pointer_id, SDL_RELEASED, SDL_BUTTON_LEFT);
SDL_SendMouseButton(Wayland_GetPointerTimestamp(input, 0), wind->sdlwindow, input->pointer_id, SDL_RELEASED, SDL_BUTTON_RIGHT);
SDL_SendMouseButton(Wayland_GetPointerTimestamp(input, 0), wind->sdlwindow, input->pointer_id, SDL_RELEASED, SDL_BUTTON_MIDDLE);
SDL_SendMouseButton(Wayland_GetPointerTimestamp(input, 0), wind->sdlwindow, input->pointer_id, SDL_RELEASED, SDL_BUTTON_X1);
SDL_SendMouseButton(Wayland_GetPointerTimestamp(input, 0), wind->sdlwindow, input->pointer_id, SDL_RELEASED, SDL_BUTTON_X2);
SDL_SendMouseButton(Wayland_GetPointerTimestamp(input, 0), wind->sdlwindow, input->pointer_id, SDL_BUTTON_LEFT, false);
SDL_SendMouseButton(Wayland_GetPointerTimestamp(input, 0), wind->sdlwindow, input->pointer_id, SDL_BUTTON_RIGHT, false);
SDL_SendMouseButton(Wayland_GetPointerTimestamp(input, 0), wind->sdlwindow, input->pointer_id, SDL_BUTTON_MIDDLE, false);
SDL_SendMouseButton(Wayland_GetPointerTimestamp(input, 0), wind->sdlwindow, input->pointer_id, SDL_BUTTON_X1, false);
SDL_SendMouseButton(Wayland_GetPointerTimestamp(input, 0), wind->sdlwindow, input->pointer_id, SDL_BUTTON_X2, false);
}
@ -760,7 +760,7 @@ static void pointer_handle_button_common(struct SDL_WaylandInput *input, uint32_
if (!ignore_click) {
SDL_SendMouseButton(Wayland_GetPointerTimestamp(input, time), window->sdlwindow, input->pointer_id,
state ? SDL_PRESSED : SDL_RELEASED, sdl_button);
sdl_button, (state != 0));
}
}
}
@ -1549,7 +1549,7 @@ static void keyboard_handle_enter(void *data, struct wl_keyboard *keyboard,
case SDLK_RGUI:
case SDLK_MODE:
Wayland_HandleModifierKeys(input, scancode, true);
SDL_SendKeyboardKeyIgnoreModifiers(0, input->keyboard_id, *key, scancode, SDL_PRESSED);
SDL_SendKeyboardKeyIgnoreModifiers(0, input->keyboard_id, *key, scancode, true);
break;
default:
break;
@ -1600,7 +1600,7 @@ static void keyboard_handle_leave(void *data, struct wl_keyboard *keyboard,
}
}
static bool keyboard_input_get_text(char text[8], const struct SDL_WaylandInput *input, uint32_t key, Uint8 state, bool *handled_by_ime)
static bool keyboard_input_get_text(char text[8], const struct SDL_WaylandInput *input, uint32_t key, bool down, bool *handled_by_ime)
{
SDL_WindowData *window = input->keyboard_focus;
const xkb_keysym_t *syms;
@ -1617,7 +1617,7 @@ static bool keyboard_input_get_text(char text[8], const struct SDL_WaylandInput
sym = syms[0];
#ifdef SDL_USE_IME
if (SDL_IME_ProcessKeyEvent(sym, key + 8, state)) {
if (SDL_IME_ProcessKeyEvent(sym, key + 8, down)) {
if (handled_by_ime) {
*handled_by_ime = true;
}
@ -1625,7 +1625,7 @@ static bool keyboard_input_get_text(char text[8], const struct SDL_WaylandInput
}
#endif
if (state == SDL_RELEASED) {
if (!down) {
return false;
}
@ -1668,7 +1668,7 @@ static void keyboard_handle_key(void *data, struct wl_keyboard *keyboard,
if (state == WL_KEYBOARD_KEY_STATE_PRESSED) {
SDL_Window *keyboard_focus = SDL_GetKeyboardFocus();
if (keyboard_focus && SDL_TextInputActive(keyboard_focus)) {
has_text = keyboard_input_get_text(text, input, key, SDL_PRESSED, &handled_by_ime);
has_text = keyboard_input_get_text(text, input, key, true, &handled_by_ime);
}
} else {
if (keyboard_repeat_key_is_set(&input->keyboard_repeat, key)) {
@ -1680,12 +1680,12 @@ static void keyboard_handle_key(void *data, struct wl_keyboard *keyboard,
keyboard_repeat_handle(&input->keyboard_repeat, timestamp_raw_ns - input->keyboard_repeat.wl_press_time_ns);
keyboard_repeat_clear(&input->keyboard_repeat);
}
keyboard_input_get_text(text, input, key, SDL_RELEASED, &handled_by_ime);
keyboard_input_get_text(text, input, key, false, &handled_by_ime);
}
scancode = Wayland_get_scancode_from_key(input, key + 8);
Wayland_HandleModifierKeys(input, scancode, state == WL_KEYBOARD_KEY_STATE_PRESSED);
SDL_SendKeyboardKeyIgnoreModifiers(Wayland_GetKeyboardTimestamp(input, time), input->keyboard_id, key, scancode, state == WL_KEYBOARD_KEY_STATE_PRESSED ? SDL_PRESSED : SDL_RELEASED);
SDL_SendKeyboardKeyIgnoreModifiers(Wayland_GetKeyboardTimestamp(input, time), input->keyboard_id, key, scancode, (state == WL_KEYBOARD_KEY_STATE_PRESSED));
if (state == WL_KEYBOARD_KEY_STATE_PRESSED) {
if (has_text && !(SDL_GetModState() & SDL_KMOD_CTRL)) {
@ -1725,7 +1725,7 @@ static void keyboard_handle_modifiers(void *data, struct wl_keyboard *keyboard,
char text[8];
const uint32_t key = keyboard_repeat_get_key(&input->keyboard_repeat);
if (keyboard_input_get_text(text, input, key, SDL_PRESSED, NULL)) {
if (keyboard_input_get_text(text, input, key, true, NULL)) {
keyboard_repeat_set_text(&input->keyboard_repeat, text);
}
}
@ -2690,14 +2690,14 @@ static void tablet_tool_handle_frame(void *data, struct zwp_tablet_tool_v2 *tool
if (sdltool->frame_motion_set && (sdltool->frame_pen_down != -1)) {
if (sdltool->frame_pen_down) {
SDL_SendPenMotion(timestamp, instance_id, window, sdltool->x, sdltool->y);
SDL_SendPenTouch(timestamp, instance_id, window, SDL_PRESSED, 0); // !!! FIXME: how do we know what tip is in use?
SDL_SendPenTouch(timestamp, instance_id, window, false, true); // !!! FIXME: how do we know what tip is in use?
} else {
SDL_SendPenTouch(timestamp, instance_id, window, SDL_RELEASED, 0); // !!! FIXME: how do we know what tip is in use?
SDL_SendPenTouch(timestamp, instance_id, window, false, false); // !!! FIXME: how do we know what tip is in use?
SDL_SendPenMotion(timestamp, instance_id, window, sdltool->x, sdltool->y);
}
} else {
if (sdltool->frame_pen_down != -1) {
SDL_SendPenTouch(timestamp, instance_id, window, sdltool->frame_pen_down ? SDL_PRESSED : SDL_RELEASED, 0); // !!! FIXME: how do we know what tip is in use?
SDL_SendPenTouch(timestamp, instance_id, window, false, (sdltool->frame_pen_down != 0)); // !!! FIXME: how do we know what tip is in use?
}
if (sdltool->frame_motion_set) {
@ -2714,7 +2714,7 @@ static void tablet_tool_handle_frame(void *data, struct zwp_tablet_tool_v2 *tool
for (int i = 0; i < SDL_arraysize(sdltool->frame_buttons); i++) {
const int state = sdltool->frame_buttons[i];
if (state != -1) {
SDL_SendPenButton(timestamp, instance_id, window, state ? SDL_PRESSED : SDL_RELEASED, (Uint8) (i + 1));
SDL_SendPenButton(timestamp, instance_id, window, (Uint8)(i + 1), (state != 0));
sdltool->frame_buttons[i] = -1;
}
}

View File

@ -232,9 +232,9 @@ static void WIN_CheckWParamMouseButton(Uint64 timestamp, bool bwParamMousePresse
}
if (bwParamMousePressed && !(mouseFlags & SDL_BUTTON(button))) {
SDL_SendMouseButton(timestamp, data->window, mouseID, SDL_PRESSED, button);
SDL_SendMouseButton(timestamp, data->window, mouseID, button, true);
} else if (!bwParamMousePressed && (mouseFlags & SDL_BUTTON(button))) {
SDL_SendMouseButton(timestamp, data->window, mouseID, SDL_RELEASED, button);
SDL_SendMouseButton(timestamp, data->window, mouseID, button, false);
}
}
@ -492,11 +492,11 @@ WIN_KeyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam)
if (wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN) {
if (!data->raw_keyboard_enabled) {
SDL_SendKeyboardKey(0, SDL_GLOBAL_KEYBOARD_ID, hookData->scanCode, scanCode, SDL_PRESSED);
SDL_SendKeyboardKey(0, SDL_GLOBAL_KEYBOARD_ID, hookData->scanCode, scanCode, true);
}
} else {
if (!data->raw_keyboard_enabled) {
SDL_SendKeyboardKey(0, SDL_GLOBAL_KEYBOARD_ID, hookData->scanCode, scanCode, SDL_RELEASED);
SDL_SendKeyboardKey(0, SDL_GLOBAL_KEYBOARD_ID, hookData->scanCode, scanCode, false);
}
/* If the key was down prior to our hook being installed, allow the
@ -622,24 +622,24 @@ static void WIN_HandleRawMouseInput(Uint64 timestamp, SDL_VideoData *data, HANDL
static struct {
USHORT usButtonFlags;
Uint8 button;
Uint8 state;
bool down;
} raw_buttons[] = {
{ RI_MOUSE_LEFT_BUTTON_DOWN, SDL_BUTTON_LEFT, SDL_PRESSED },
{ RI_MOUSE_LEFT_BUTTON_UP, SDL_BUTTON_LEFT, SDL_RELEASED },
{ RI_MOUSE_RIGHT_BUTTON_DOWN, SDL_BUTTON_RIGHT, SDL_PRESSED },
{ RI_MOUSE_RIGHT_BUTTON_UP, SDL_BUTTON_RIGHT, SDL_RELEASED },
{ RI_MOUSE_MIDDLE_BUTTON_DOWN, SDL_BUTTON_MIDDLE, SDL_PRESSED },
{ RI_MOUSE_MIDDLE_BUTTON_UP, SDL_BUTTON_MIDDLE, SDL_RELEASED },
{ RI_MOUSE_BUTTON_4_DOWN, SDL_BUTTON_X1, SDL_PRESSED },
{ RI_MOUSE_BUTTON_4_UP, SDL_BUTTON_X1, SDL_RELEASED },
{ RI_MOUSE_BUTTON_5_DOWN, SDL_BUTTON_X2, SDL_PRESSED },
{ RI_MOUSE_BUTTON_5_UP, SDL_BUTTON_X2, SDL_RELEASED }
{ RI_MOUSE_LEFT_BUTTON_DOWN, SDL_BUTTON_LEFT, true },
{ RI_MOUSE_LEFT_BUTTON_UP, SDL_BUTTON_LEFT, false },
{ RI_MOUSE_RIGHT_BUTTON_DOWN, SDL_BUTTON_RIGHT, true },
{ RI_MOUSE_RIGHT_BUTTON_UP, SDL_BUTTON_RIGHT, false },
{ RI_MOUSE_MIDDLE_BUTTON_DOWN, SDL_BUTTON_MIDDLE, true },
{ RI_MOUSE_MIDDLE_BUTTON_UP, SDL_BUTTON_MIDDLE, false },
{ RI_MOUSE_BUTTON_4_DOWN, SDL_BUTTON_X1, true },
{ RI_MOUSE_BUTTON_4_UP, SDL_BUTTON_X1, false },
{ RI_MOUSE_BUTTON_5_DOWN, SDL_BUTTON_X2, true },
{ RI_MOUSE_BUTTON_5_UP, SDL_BUTTON_X2, false }
};
for (int i = 0; i < SDL_arraysize(raw_buttons); ++i) {
if (rawmouse->usButtonFlags & raw_buttons[i].usButtonFlags) {
Uint8 button = raw_buttons[i].button;
Uint8 state = raw_buttons[i].state;
bool down = raw_buttons[i].down;
if (button == SDL_BUTTON_LEFT) {
if (WIN_SwapButtons(hDevice)) {
@ -653,7 +653,7 @@ static void WIN_HandleRawMouseInput(Uint64 timestamp, SDL_VideoData *data, HANDL
if (windowdata->focus_click_pending & SDL_BUTTON(button)) {
// Ignore the button click for activation
if (!state) {
if (!down) {
windowdata->focus_click_pending &= ~SDL_BUTTON(button);
WIN_UpdateClipCursor(window);
}
@ -662,7 +662,7 @@ static void WIN_HandleRawMouseInput(Uint64 timestamp, SDL_VideoData *data, HANDL
}
}
SDL_SendMouseButton(timestamp, window, mouseID, state, button);
SDL_SendMouseButton(timestamp, window, mouseID, button, down);
}
}
@ -706,7 +706,7 @@ static void WIN_HandleRawKeyboardInput(Uint64 timestamp, SDL_VideoData *data, HA
return;
}
Uint8 state = (rawkeyboard->Flags & RI_KEY_BREAK) ? SDL_RELEASED : SDL_PRESSED;
bool down = ((rawkeyboard->Flags & RI_KEY_BREAK) != 0);
SDL_Scancode code;
USHORT rawcode = rawkeyboard->MakeCode;
if (data->pending_E1_key_sequence) {
@ -728,14 +728,14 @@ static void WIN_HandleRawKeyboardInput(Uint64 timestamp, SDL_VideoData *data, HA
}
code = windows_scancode_table[index];
}
if (state) {
if (down) {
SDL_Window *focus = SDL_GetKeyboardFocus();
if (!focus || focus->text_input_active) {
return;
}
}
SDL_SendKeyboardKey(timestamp, keyboardID, rawcode, code, state);
SDL_SendKeyboardKey(timestamp, keyboardID, rawcode, code, down);
}
void WIN_PollRawInput(SDL_VideoDevice *_this)
@ -1260,7 +1260,7 @@ LRESULT CALLBACK WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara
}
if (virtual_key || !data->videodata->raw_keyboard_enabled || data->window->text_input_active) {
SDL_SendKeyboardKey(WIN_GetEventTimestamp(), SDL_GLOBAL_KEYBOARD_ID, rawcode, code, SDL_PRESSED);
SDL_SendKeyboardKey(WIN_GetEventTimestamp(), SDL_GLOBAL_KEYBOARD_ID, rawcode, code, true);
}
}
@ -1278,14 +1278,13 @@ LRESULT CALLBACK WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara
bool virtual_key = false;
Uint16 rawcode = 0;
SDL_Scancode code = WindowsScanCodeToSDLScanCode(lParam, wParam, &rawcode, &virtual_key);
const Uint8 *keyboardState = SDL_GetKeyboardState(NULL);
const SDL_bool *keyboardState = SDL_GetKeyboardState(NULL);
if (virtual_key || !data->videodata->raw_keyboard_enabled || data->window->text_input_active) {
if (code == SDL_SCANCODE_PRINTSCREEN &&
keyboardState[code] == SDL_RELEASED) {
SDL_SendKeyboardKey(WIN_GetEventTimestamp(), SDL_GLOBAL_KEYBOARD_ID, rawcode, code, SDL_PRESSED);
if (code == SDL_SCANCODE_PRINTSCREEN && !keyboardState[code]) {
SDL_SendKeyboardKey(WIN_GetEventTimestamp(), SDL_GLOBAL_KEYBOARD_ID, rawcode, code, true);
}
SDL_SendKeyboardKey(WIN_GetEventTimestamp(), SDL_GLOBAL_KEYBOARD_ID, rawcode, code, SDL_RELEASED);
SDL_SendKeyboardKey(WIN_GetEventTimestamp(), SDL_GLOBAL_KEYBOARD_ID, rawcode, code, false);
}
}
returnCode = 0;
@ -2138,13 +2137,21 @@ static void WIN_UpdateMouseCapture(void)
SDL_MouseID mouseID = SDL_GLOBAL_MOUSE_ID;
SDL_SendMouseMotion(WIN_GetEventTimestamp(), data->window, mouseID, false, (float)cursorPos.x, (float)cursorPos.y);
SDL_SendMouseButton(WIN_GetEventTimestamp(), data->window, mouseID, GetAsyncKeyState(VK_LBUTTON) & 0x8000 ? SDL_PRESSED : SDL_RELEASED,
!swapButtons ? SDL_BUTTON_LEFT : SDL_BUTTON_RIGHT);
SDL_SendMouseButton(WIN_GetEventTimestamp(), data->window, mouseID, GetAsyncKeyState(VK_RBUTTON) & 0x8000 ? SDL_PRESSED : SDL_RELEASED,
!swapButtons ? SDL_BUTTON_RIGHT : SDL_BUTTON_LEFT);
SDL_SendMouseButton(WIN_GetEventTimestamp(), data->window, mouseID, GetAsyncKeyState(VK_MBUTTON) & 0x8000 ? SDL_PRESSED : SDL_RELEASED, SDL_BUTTON_MIDDLE);
SDL_SendMouseButton(WIN_GetEventTimestamp(), data->window, mouseID, GetAsyncKeyState(VK_XBUTTON1) & 0x8000 ? SDL_PRESSED : SDL_RELEASED, SDL_BUTTON_X1);
SDL_SendMouseButton(WIN_GetEventTimestamp(), data->window, mouseID, GetAsyncKeyState(VK_XBUTTON2) & 0x8000 ? SDL_PRESSED : SDL_RELEASED, SDL_BUTTON_X2);
SDL_SendMouseButton(WIN_GetEventTimestamp(), data->window, mouseID,
!swapButtons ? SDL_BUTTON_LEFT : SDL_BUTTON_RIGHT,
(GetAsyncKeyState(VK_LBUTTON) & 0x8000) != 0);
SDL_SendMouseButton(WIN_GetEventTimestamp(), data->window, mouseID,
!swapButtons ? SDL_BUTTON_RIGHT : SDL_BUTTON_LEFT,
(GetAsyncKeyState(VK_RBUTTON) & 0x8000) != 0);
SDL_SendMouseButton(WIN_GetEventTimestamp(), data->window, mouseID,
SDL_BUTTON_MIDDLE,
(GetAsyncKeyState(VK_MBUTTON) & 0x8000) != 0);
SDL_SendMouseButton(WIN_GetEventTimestamp(), data->window, mouseID,
SDL_BUTTON_X1,
(GetAsyncKeyState(VK_XBUTTON1) & 0x8000) != 0);
SDL_SendMouseButton(WIN_GetEventTimestamp(), data->window, mouseID,
SDL_BUTTON_X2,
(GetAsyncKeyState(VK_XBUTTON2) & 0x8000) != 0);
}
}
}
@ -2229,7 +2236,7 @@ void WIN_PumpEvents(SDL_VideoDevice *_this)
#endif
int new_messages = 0;
#if !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES)
const Uint8 *keystate;
const SDL_bool *keystate;
SDL_Window *focusWindow;
#endif
@ -2288,11 +2295,11 @@ void WIN_PumpEvents(SDL_VideoDevice *_this)
key you released. Take heroic measures and check the keystate as of the last handled event,
and if we think a key is pressed when Windows doesn't, unstick it in SDL's state. */
keystate = SDL_GetKeyboardState(NULL);
if ((keystate[SDL_SCANCODE_LSHIFT] == SDL_PRESSED) && !(GetKeyState(VK_LSHIFT) & 0x8000)) {
SDL_SendKeyboardKey(0, SDL_GLOBAL_KEYBOARD_ID, 0, SDL_SCANCODE_LSHIFT, SDL_RELEASED);
if (keystate[SDL_SCANCODE_LSHIFT] && !(GetKeyState(VK_LSHIFT) & 0x8000)) {
SDL_SendKeyboardKey(0, SDL_GLOBAL_KEYBOARD_ID, 0, SDL_SCANCODE_LSHIFT, false);
}
if ((keystate[SDL_SCANCODE_RSHIFT] == SDL_PRESSED) && !(GetKeyState(VK_RSHIFT) & 0x8000)) {
SDL_SendKeyboardKey(0, SDL_GLOBAL_KEYBOARD_ID, 0, SDL_SCANCODE_RSHIFT, SDL_RELEASED);
if (keystate[SDL_SCANCODE_RSHIFT] && !(GetKeyState(VK_RSHIFT) & 0x8000)) {
SDL_SendKeyboardKey(0, SDL_GLOBAL_KEYBOARD_ID, 0, SDL_SCANCODE_RSHIFT, false);
}
/* The Windows key state gets lost when using Windows+Space or Windows+G shortcuts and
@ -2300,11 +2307,11 @@ void WIN_PumpEvents(SDL_VideoDevice *_this)
will return inaccurate results for VK_LWIN and VK_RWIN but we don't need it anyway. */
focusWindow = SDL_GetKeyboardFocus();
if (!focusWindow || !(focusWindow->flags & SDL_WINDOW_KEYBOARD_GRABBED)) {
if ((keystate[SDL_SCANCODE_LGUI] == SDL_PRESSED) && !(GetKeyState(VK_LWIN) & 0x8000)) {
SDL_SendKeyboardKey(0, SDL_GLOBAL_KEYBOARD_ID, 0, SDL_SCANCODE_LGUI, SDL_RELEASED);
if (keystate[SDL_SCANCODE_LGUI] && !(GetKeyState(VK_LWIN) & 0x8000)) {
SDL_SendKeyboardKey(0, SDL_GLOBAL_KEYBOARD_ID, 0, SDL_SCANCODE_LGUI, false);
}
if ((keystate[SDL_SCANCODE_RGUI] == SDL_PRESSED) && !(GetKeyState(VK_RWIN) & 0x8000)) {
SDL_SendKeyboardKey(0, SDL_GLOBAL_KEYBOARD_ID, 0, SDL_SCANCODE_RGUI, SDL_RELEASED);
if (keystate[SDL_SCANCODE_RGUI] && !(GetKeyState(VK_RWIN) & 0x8000)) {
SDL_SendKeyboardKey(0, SDL_GLOBAL_KEYBOARD_ID, 0, SDL_SCANCODE_RGUI, false);
}
}

View File

@ -287,7 +287,8 @@ static void GAMEINPUT_InitialMouseReading(WIN_GameInputData *data, SDL_Window *w
for (int i = 0; i < MAX_GAMEINPUT_BUTTONS; ++i) {
const GameInputMouseButtons mask = (1 << i);
SDL_SendMouseButton(timestamp, window, mouseID, (state.buttons & mask) ? SDL_PRESSED : SDL_RELEASED, GAMEINPUT_button_map[i]);
bool down = ((state.buttons & mask) != 0);
SDL_SendMouseButton(timestamp, window, mouseID, GAMEINPUT_button_map[i], down);
}
}
}
@ -315,7 +316,8 @@ static void GAMEINPUT_HandleMouseDelta(WIN_GameInputData *data, SDL_Window *wind
for (int i = 0; i < MAX_GAMEINPUT_BUTTONS; ++i) {
const GameInputMouseButtons mask = (1 << i);
if (delta.buttons & mask) {
SDL_SendMouseButton(timestamp, window, mouseID, (state.buttons & mask) ? SDL_PRESSED : SDL_RELEASED, GAMEINPUT_button_map[i]);
bool down = ((state.buttons & mask) != 0);
SDL_SendMouseButton(timestamp, window, mouseID, GAMEINPUT_button_map[i], down);
}
}
}
@ -366,16 +368,16 @@ static void GAMEINPUT_InitialKeyboardReading(WIN_GameInputData *data, SDL_Window
// Go through and send key up events for any key that's not held down
int num_scancodes;
const Uint8 *keyboard_state = SDL_GetKeyboardState(&num_scancodes);
const SDL_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_SendKeyboardKey(timestamp, keyboardID, keys[i].scanCode, (SDL_Scancode)i, SDL_RELEASED);
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_SendKeyboardKey(timestamp, keyboardID, keys[i].scanCode, GetScancodeFromKeyState(&keys[i]), SDL_PRESSED);
SDL_SendKeyboardKey(timestamp, keyboardID, keys[i].scanCode, GetScancodeFromKeyState(&keys[i]), true);
}
}
@ -420,16 +422,16 @@ static void GAMEINPUT_HandleKeyboardDelta(WIN_GameInputData *data, SDL_Window *w
++index_keys;
} else {
// This key was released
SDL_SendKeyboardKey(timestamp, keyboardID, last[index_last].scanCode, GetScancodeFromKeyState(&last[index_last]), SDL_RELEASED);
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_SendKeyboardKey(timestamp, keyboardID, last[index_last].scanCode, GetScancodeFromKeyState(&last[index_last]), SDL_RELEASED);
SDL_SendKeyboardKey(timestamp, keyboardID, last[index_last].scanCode, GetScancodeFromKeyState(&last[index_last]), false);
++index_last;
} else {
// This key was pressed
SDL_SendKeyboardKey(timestamp, keyboardID, keys[index_keys].scanCode, GetScancodeFromKeyState(&keys[index_keys]), SDL_PRESSED);
SDL_SendKeyboardKey(timestamp, keyboardID, keys[index_keys].scanCode, GetScancodeFromKeyState(&keys[index_keys]), true);
++index_keys;
}
}

View File

@ -304,7 +304,7 @@ void X11_ReconcileKeyboardState(SDL_VideoDevice *_this)
Window junk_window;
int x, y;
unsigned int mask;
const Uint8 *keyboardState;
const SDL_bool *keyboardState;
X11_XQueryKeymap(display, keys);
@ -319,7 +319,7 @@ void X11_ReconcileKeyboardState(SDL_VideoDevice *_this)
for (keycode = 0; keycode < SDL_arraysize(videodata->key_layout); ++keycode) {
SDL_Scancode scancode = videodata->key_layout[keycode];
bool x11KeyPressed = (keys[keycode / 8] & (1 << (keycode % 8))) != 0;
bool sdlKeyPressed = keyboardState[scancode] == SDL_PRESSED;
bool sdlKeyPressed = keyboardState[scancode];
if (x11KeyPressed && !sdlKeyPressed) {
// Only update modifier state for keys that are pressed in another application
@ -333,13 +333,13 @@ void X11_ReconcileKeyboardState(SDL_VideoDevice *_this)
case SDLK_LGUI:
case SDLK_RGUI:
case SDLK_MODE:
SDL_SendKeyboardKey(0, SDL_GLOBAL_KEYBOARD_ID, keycode, scancode, SDL_PRESSED);
SDL_SendKeyboardKey(0, SDL_GLOBAL_KEYBOARD_ID, keycode, scancode, true);
break;
default:
break;
}
} else if (!x11KeyPressed && sdlKeyPressed) {
SDL_SendKeyboardKey(0, SDL_GLOBAL_KEYBOARD_ID, keycode, scancode, SDL_RELEASED);
SDL_SendKeyboardKey(0, SDL_GLOBAL_KEYBOARD_ID, keycode, scancode, false);
}
}
}
@ -802,9 +802,9 @@ void X11_HandleKeyEvent(SDL_VideoDevice *_this, SDL_WindowData *windowdata, SDL_
videodata->filter_time = xevent->xkey.time;
if (orig_event_type == KeyPress) {
SDL_SendKeyboardKey(0, keyboardID, orig_keycode, scancode, SDL_PRESSED);
SDL_SendKeyboardKey(0, keyboardID, orig_keycode, scancode, true);
} else {
SDL_SendKeyboardKey(0, keyboardID, orig_keycode, scancode, SDL_RELEASED);
SDL_SendKeyboardKey(0, keyboardID, orig_keycode, scancode, false);
}
#endif
return;
@ -822,7 +822,7 @@ void X11_HandleKeyEvent(SDL_VideoDevice *_this, SDL_WindowData *windowdata, SDL_
#endif
#ifdef SDL_USE_IME
handled_by_ime = SDL_IME_ProcessKeyEvent(keysym, keycode, (xevent->type == KeyPress ? SDL_PRESSED : SDL_RELEASED));
handled_by_ime = SDL_IME_ProcessKeyEvent(keysym, keycode, (xevent->type == KeyPress));
#endif
}
@ -830,7 +830,7 @@ void X11_HandleKeyEvent(SDL_VideoDevice *_this, SDL_WindowData *windowdata, SDL_
if (xevent->type == KeyPress) {
// Don't send the key if it looks like a duplicate of a filtered key sent by an IME
if (xevent->xkey.keycode != videodata->filter_code || xevent->xkey.time != videodata->filter_time) {
SDL_SendKeyboardKey(0, keyboardID, keycode, videodata->key_layout[keycode], SDL_PRESSED);
SDL_SendKeyboardKey(0, keyboardID, keycode, videodata->key_layout[keycode], true);
}
if (*text) {
text[text_length] = '\0';
@ -841,7 +841,7 @@ void X11_HandleKeyEvent(SDL_VideoDevice *_this, SDL_WindowData *windowdata, SDL_
// We're about to get a repeated key down, ignore the key up
return;
}
SDL_SendKeyboardKey(0, keyboardID, keycode, videodata->key_layout[keycode], SDL_RELEASED);
SDL_SendKeyboardKey(0, keyboardID, keycode, videodata->key_layout[keycode], false);
}
}
@ -881,7 +881,7 @@ void X11_HandleButtonPress(SDL_VideoDevice *_this, SDL_WindowData *windowdata, S
windowdata->last_focus_event_time = 0;
}
if (!ignore_click) {
SDL_SendMouseButton(0, window, mouseID, SDL_PRESSED, button);
SDL_SendMouseButton(0, window, mouseID, button, true);
}
}
X11_UpdateUserTime(windowdata, time);
@ -902,7 +902,7 @@ void X11_HandleButtonRelease(SDL_VideoDevice *_this, SDL_WindowData *windowdata,
// see explanation at case ButtonPress
button -= (8 - SDL_BUTTON_X1);
}
SDL_SendMouseButton(0, window, mouseID, SDL_RELEASED, button);
SDL_SendMouseButton(0, window, mouseID, button, false);
}
}

View File

@ -407,15 +407,15 @@ void X11_HandleXinput2Event(SDL_VideoDevice *_this, XGenericEventCookie *cookie)
const XIDeviceEvent *xev = (const XIDeviceEvent *)cookie->data;
X11_PenHandle *pen = X11_FindPenByDeviceID(xev->deviceid);
const int button = xev->detail;
const bool pressed = (cookie->evtype == XI_ButtonPress) ? true : false;
const bool down = (cookie->evtype == XI_ButtonPress);
if (pen) {
// Only report button event; if there was also pen movement / pressure changes, we expect an XI_Motion event first anyway.
SDL_Window *window = xinput2_get_sdlwindow(videodata, xev->event);
if (button == 1) { // button 1 is the pen tip
SDL_SendPenTouch(0, pen->pen, window, pressed ? SDL_PRESSED : SDL_RELEASED, pen->is_eraser);
SDL_SendPenTouch(0, pen->pen, window, pen->is_eraser, down);
} else {
SDL_SendPenButton(0, pen->pen, window, pressed ? SDL_PRESSED : SDL_RELEASED, button - 1);
SDL_SendPenButton(0, pen->pen, window, button - 1, down);
}
} else {
// Otherwise assume a regular mouse
@ -426,7 +426,7 @@ void X11_HandleXinput2Event(SDL_VideoDevice *_this, XGenericEventCookie *cookie)
break;
}
if (pressed) {
if (down) {
X11_HandleButtonPress(_this, windowdata, (SDL_MouseID)xev->sourceid, button,
(float)xev->event_x, (float)xev->event_y, xev->time);
} else {

View File

@ -198,7 +198,7 @@ static void PrintKey(SDL_KeyboardEvent *event)
if (event->key) {
print_string(&spot, &left,
"Key %s: raw 0x%.2x, scancode %d = %s, keycode 0x%08X = %s ",
event->state ? "pressed " : "released",
event->down ? "pressed " : "released",
event->raw,
event->scancode,
event->scancode == SDL_SCANCODE_UNKNOWN ? "UNKNOWN" : SDL_GetScancodeName(event->scancode),
@ -209,7 +209,7 @@ static void PrintKey(SDL_KeyboardEvent *event)
event->raw,
event->scancode,
event->scancode == SDL_SCANCODE_UNKNOWN ? "UNKNOWN" : SDL_GetScancodeName(event->scancode),
event->state ? "pressed " : "released");
event->down ? "pressed " : "released");
}
print_modifiers(&spot, &left, event->mod);
if (event->repeat) {
@ -234,7 +234,7 @@ static void PrintText(const char *eventtype, const char *text)
static void CountKeysDown(void)
{
int i, count = 0, max_keys = 0;
const Uint8 *keystate = SDL_GetKeyboardState(&max_keys);
const SDL_bool *keystate = SDL_GetKeyboardState(&max_keys);
for (i = 0; i < max_keys; ++i) {
if (keystate[i]) {

View File

@ -81,7 +81,7 @@ static SDL_FRect touchpad_area = {
typedef struct
{
Uint8 state;
SDL_bool down;
float x;
float y;
float pressure;
@ -428,11 +428,7 @@ void UpdateGamepadImageFromGamepad(GamepadImage *ctx, SDL_Gamepad *gamepad)
for (i = 0; i < SDL_GAMEPAD_BUTTON_TOUCHPAD; ++i) {
const SDL_GamepadButton button = (SDL_GamepadButton)i;
if (SDL_GetGamepadButton(gamepad, button) == SDL_PRESSED) {
SetGamepadImageElement(ctx, button, SDL_TRUE);
} else {
SetGamepadImageElement(ctx, button, SDL_FALSE);
}
SetGamepadImageElement(ctx, button, SDL_GetGamepadButton(gamepad, button));
}
for (i = 0; i < SDL_GAMEPAD_AXIS_MAX; ++i) {
@ -483,7 +479,7 @@ void UpdateGamepadImageFromGamepad(GamepadImage *ctx, SDL_Gamepad *gamepad)
for (i = 0; i < num_fingers; ++i) {
GamepadTouchpadFinger *finger = &ctx->fingers[i];
SDL_GetGamepadTouchpadFinger(gamepad, 0, i, &finger->state, &finger->x, &finger->y, &finger->pressure);
SDL_GetGamepadTouchpadFinger(gamepad, 0, i, &finger->down, &finger->x, &finger->y, &finger->pressure);
}
ctx->showing_touchpad = SDL_TRUE;
} else {
@ -614,7 +610,7 @@ void RenderGamepadImage(GamepadImage *ctx)
for (i = 0; i < ctx->num_fingers; ++i) {
GamepadTouchpadFinger *finger = &ctx->fingers[i];
if (finger->state) {
if (finger->down) {
dst.x = ctx->x + (ctx->gamepad_width - ctx->touchpad_width) / 2;
dst.x += touchpad_area.x + finger->x * touchpad_area.w;
dst.x -= ctx->button_width / 2;
@ -1220,17 +1216,17 @@ void RenderGamepadDisplay(GamepadDisplay *ctx, SDL_Gamepad *gamepad)
if (SDL_GetNumGamepadTouchpads(gamepad) > 0) {
int num_fingers = SDL_GetNumGamepadTouchpadFingers(gamepad, 0);
for (i = 0; i < num_fingers; ++i) {
Uint8 state;
SDL_bool down;
float finger_x, finger_y, finger_pressure;
if (!SDL_GetGamepadTouchpadFinger(gamepad, 0, i, &state, &finger_x, &finger_y, &finger_pressure)) {
if (!SDL_GetGamepadTouchpadFinger(gamepad, 0, i, &down, &finger_x, &finger_y, &finger_pressure)) {
continue;
}
SDL_snprintf(text, sizeof(text), "Touch finger %d:", i);
SDLTest_DrawString(ctx->renderer, x + center - SDL_strlen(text) * FONT_CHARACTER_SIZE, y, text);
if (state) {
if (down) {
SDL_SetTextureColorMod(ctx->button_texture, 10, 255, 21);
} else {
SDL_SetTextureColorMod(ctx->button_texture, 255, 255, 255);
@ -1242,7 +1238,7 @@ void RenderGamepadDisplay(GamepadDisplay *ctx, SDL_Gamepad *gamepad)
dst.h = ctx->button_height;
SDL_RenderTexture(ctx->renderer, ctx->button_texture, NULL, &dst);
if (state) {
if (down) {
SDL_snprintf(text, sizeof(text), "(%.2f,%.2f)", finger_x, finger_y);
SDLTest_DrawString(ctx->renderer, x + center + ctx->button_width + 4.0f, y, text);
}

View File

@ -86,13 +86,13 @@ static int SDLCALL TestVirtualJoystick(void *arg)
SDLTest_AssertCheck(nbuttons == desc.nbuttons, "SDL_GetNumJoystickButtons() -> %d (expected %d)", nbuttons, desc.nbuttons);
}
SDLTest_AssertCheck(SDL_SetJoystickVirtualButton(joystick, SDL_GAMEPAD_BUTTON_SOUTH, SDL_PRESSED), "SDL_SetJoystickVirtualButton(SDL_GAMEPAD_BUTTON_SOUTH, SDL_PRESSED)");
SDLTest_AssertCheck(SDL_SetJoystickVirtualButton(joystick, SDL_GAMEPAD_BUTTON_SOUTH, SDL_TRUE), "SDL_SetJoystickVirtualButton(SDL_GAMEPAD_BUTTON_SOUTH, SDL_TRUE)");
SDL_UpdateJoysticks();
SDLTest_AssertCheck(SDL_GetJoystickButton(joystick, SDL_GAMEPAD_BUTTON_SOUTH) == SDL_PRESSED, "SDL_GetJoystickButton(SDL_GAMEPAD_BUTTON_SOUTH) == SDL_PRESSED");
SDLTest_AssertCheck(SDL_GetJoystickButton(joystick, SDL_GAMEPAD_BUTTON_SOUTH) == SDL_TRUE, "SDL_GetJoystickButton(SDL_GAMEPAD_BUTTON_SOUTH) == SDL_TRUE");
SDLTest_AssertCheck(SDL_SetJoystickVirtualButton(joystick, SDL_GAMEPAD_BUTTON_SOUTH, SDL_RELEASED), "SDL_SetJoystickVirtualButton(SDL_GAMEPAD_BUTTON_SOUTH, SDL_RELEASED)");
SDLTest_AssertCheck(SDL_SetJoystickVirtualButton(joystick, SDL_GAMEPAD_BUTTON_SOUTH, SDL_FALSE), "SDL_SetJoystickVirtualButton(SDL_GAMEPAD_BUTTON_SOUTH, SDL_FALSE)");
SDL_UpdateJoysticks();
SDLTest_AssertCheck(SDL_GetJoystickButton(joystick, SDL_GAMEPAD_BUTTON_SOUTH) == SDL_RELEASED, "SDL_GetJoystickButton(SDL_GAMEPAD_BUTTON_SOUTH) == SDL_RELEASED");
SDLTest_AssertCheck(SDL_GetJoystickButton(joystick, SDL_GAMEPAD_BUTTON_SOUTH) == SDL_FALSE, "SDL_GetJoystickButton(SDL_GAMEPAD_BUTTON_SOUTH) == SDL_FALSE");
gamepad = SDL_OpenGamepad(SDL_GetJoystickID(joystick));
SDLTest_AssertCheck(gamepad != NULL, "SDL_OpenGamepad() succeeded");
@ -124,13 +124,13 @@ static int SDLCALL TestVirtualJoystick(void *arg)
SDLTest_AssertCheck(SDL_GetGamepadButtonLabel(gamepad, SDL_GAMEPAD_BUTTON_SOUTH) == SDL_GAMEPAD_BUTTON_LABEL_A, "SDL_GetGamepadButtonLabel(SDL_GAMEPAD_BUTTON_SOUTH) == SDL_GAMEPAD_BUTTON_LABEL_A");
/* Set the south button and verify that the gamepad responds */
SDLTest_AssertCheck(SDL_SetJoystickVirtualButton(joystick, SDL_GAMEPAD_BUTTON_SOUTH, SDL_PRESSED), "SDL_SetJoystickVirtualButton(SDL_GAMEPAD_BUTTON_SOUTH, SDL_PRESSED)");
SDLTest_AssertCheck(SDL_SetJoystickVirtualButton(joystick, SDL_GAMEPAD_BUTTON_SOUTH, SDL_TRUE), "SDL_SetJoystickVirtualButton(SDL_GAMEPAD_BUTTON_SOUTH, SDL_TRUE)");
SDL_UpdateJoysticks();
SDLTest_AssertCheck(SDL_GetGamepadButton(gamepad, SDL_GAMEPAD_BUTTON_SOUTH) == SDL_PRESSED, "SDL_GetGamepadButton(SDL_GAMEPAD_BUTTON_SOUTH) == SDL_PRESSED");
SDLTest_AssertCheck(SDL_GetGamepadButton(gamepad, SDL_GAMEPAD_BUTTON_SOUTH) == SDL_TRUE, "SDL_GetGamepadButton(SDL_GAMEPAD_BUTTON_SOUTH) == SDL_TRUE");
SDLTest_AssertCheck(SDL_SetJoystickVirtualButton(joystick, SDL_GAMEPAD_BUTTON_SOUTH, SDL_RELEASED), "SDL_SetJoystickVirtualButton(SDL_GAMEPAD_BUTTON_SOUTH, SDL_RELEASED)");
SDLTest_AssertCheck(SDL_SetJoystickVirtualButton(joystick, SDL_GAMEPAD_BUTTON_SOUTH, SDL_FALSE), "SDL_SetJoystickVirtualButton(SDL_GAMEPAD_BUTTON_SOUTH, SDL_FALSE)");
SDL_UpdateJoysticks();
SDLTest_AssertCheck(SDL_GetGamepadButton(gamepad, SDL_GAMEPAD_BUTTON_SOUTH) == SDL_RELEASED, "SDL_GetGamepadButton(SDL_GAMEPAD_BUTTON_SOUTH) == SDL_RELEASED");
SDLTest_AssertCheck(SDL_GetGamepadButton(gamepad, SDL_GAMEPAD_BUTTON_SOUTH) == SDL_FALSE, "SDL_GetGamepadButton(SDL_GAMEPAD_BUTTON_SOUTH) == SDL_FALSE");
/* Set an explicit mapping with legacy Nintendo style buttons */
SDL_SetGamepadMapping(SDL_GetJoystickID(joystick), "ff0013db5669727475616c2043007601,Virtual Nintendo Gamepad,a:b1,b:b0,x:b3,y:b2,back:b4,guide:b5,start:b6,leftstick:b7,rightstick:b8,leftshoulder:b9,rightshoulder:b10,dpup:b11,dpdown:b12,dpleft:b13,dpright:b14,misc1:b15,paddle1:b16,paddle2:b17,paddle3:b18,paddle4:b19,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,hint:SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,");
@ -141,13 +141,13 @@ static int SDLCALL TestVirtualJoystick(void *arg)
SDLTest_AssertCheck(SDL_GetGamepadButtonLabel(gamepad, SDL_GAMEPAD_BUTTON_SOUTH) == SDL_GAMEPAD_BUTTON_LABEL_B, "SDL_GetGamepadButtonLabel(SDL_GAMEPAD_BUTTON_SOUTH) == SDL_GAMEPAD_BUTTON_LABEL_B");
/* Set the south button and verify that the gamepad responds */
SDLTest_AssertCheck(SDL_SetJoystickVirtualButton(joystick, SDL_GAMEPAD_BUTTON_SOUTH, SDL_PRESSED), "SDL_SetJoystickVirtualButton(SDL_GAMEPAD_BUTTON_SOUTH, SDL_PRESSED)");
SDLTest_AssertCheck(SDL_SetJoystickVirtualButton(joystick, SDL_GAMEPAD_BUTTON_SOUTH, SDL_TRUE), "SDL_SetJoystickVirtualButton(SDL_GAMEPAD_BUTTON_SOUTH, SDL_TRUE)");
SDL_UpdateJoysticks();
SDLTest_AssertCheck(SDL_GetGamepadButton(gamepad, SDL_GAMEPAD_BUTTON_SOUTH) == SDL_PRESSED, "SDL_GetGamepadButton(SDL_GAMEPAD_BUTTON_SOUTH) == SDL_PRESSED");
SDLTest_AssertCheck(SDL_GetGamepadButton(gamepad, SDL_GAMEPAD_BUTTON_SOUTH) == SDL_TRUE, "SDL_GetGamepadButton(SDL_GAMEPAD_BUTTON_SOUTH) == SDL_TRUE");
SDLTest_AssertCheck(SDL_SetJoystickVirtualButton(joystick, SDL_GAMEPAD_BUTTON_SOUTH, SDL_RELEASED), "SDL_SetJoystickVirtualButton(SDL_GAMEPAD_BUTTON_SOUTH, SDL_RELEASED)");
SDLTest_AssertCheck(SDL_SetJoystickVirtualButton(joystick, SDL_GAMEPAD_BUTTON_SOUTH, SDL_FALSE), "SDL_SetJoystickVirtualButton(SDL_GAMEPAD_BUTTON_SOUTH, SDL_FALSE)");
SDL_UpdateJoysticks();
SDLTest_AssertCheck(SDL_GetGamepadButton(gamepad, SDL_GAMEPAD_BUTTON_SOUTH) == SDL_RELEASED, "SDL_GetGamepadButton(SDL_GAMEPAD_BUTTON_SOUTH) == SDL_RELEASED");
SDLTest_AssertCheck(SDL_GetGamepadButton(gamepad, SDL_GAMEPAD_BUTTON_SOUTH) == SDL_FALSE, "SDL_GetGamepadButton(SDL_GAMEPAD_BUTTON_SOUTH) == SDL_FALSE");
/* Set an explicit mapping with PS4 style buttons */
SDL_SetGamepadMapping(SDL_GetJoystickID(joystick), "ff0013db5669727475616c2043007601,Virtual PS4 Gamepad,type:ps4,a:b0,b:b1,x:b2,y:b3,back:b4,guide:b5,start:b6,leftstick:b7,rightstick:b8,leftshoulder:b9,rightshoulder:b10,dpup:b11,dpdown:b12,dpleft:b13,dpright:b14,misc1:b15,paddle1:b16,paddle2:b17,paddle3:b18,paddle4:b19,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,");
@ -158,13 +158,13 @@ static int SDLCALL TestVirtualJoystick(void *arg)
SDLTest_AssertCheck(SDL_GetGamepadButtonLabel(gamepad, SDL_GAMEPAD_BUTTON_SOUTH) == SDL_GAMEPAD_BUTTON_LABEL_CROSS, "SDL_GetGamepadButtonLabel(SDL_GAMEPAD_BUTTON_SOUTH) == SDL_GAMEPAD_BUTTON_LABEL_CROSS");
/* Set the south button and verify that the gamepad responds */
SDLTest_AssertCheck(SDL_SetJoystickVirtualButton(joystick, SDL_GAMEPAD_BUTTON_SOUTH, SDL_PRESSED), "SDL_SetJoystickVirtualButton(SDL_GAMEPAD_BUTTON_SOUTH, SDL_PRESSED)");
SDLTest_AssertCheck(SDL_SetJoystickVirtualButton(joystick, SDL_GAMEPAD_BUTTON_SOUTH, SDL_TRUE), "SDL_SetJoystickVirtualButton(SDL_GAMEPAD_BUTTON_SOUTH, SDL_TRUE)");
SDL_UpdateJoysticks();
SDLTest_AssertCheck(SDL_GetGamepadButton(gamepad, SDL_GAMEPAD_BUTTON_SOUTH) == SDL_PRESSED, "SDL_GetGamepadButton(SDL_GAMEPAD_BUTTON_SOUTH) == SDL_PRESSED");
SDLTest_AssertCheck(SDL_GetGamepadButton(gamepad, SDL_GAMEPAD_BUTTON_SOUTH) == SDL_TRUE, "SDL_GetGamepadButton(SDL_GAMEPAD_BUTTON_SOUTH) == SDL_TRUE");
SDLTest_AssertCheck(SDL_SetJoystickVirtualButton(joystick, SDL_GAMEPAD_BUTTON_SOUTH, SDL_RELEASED), "SDL_SetJoystickVirtualButton(SDL_GAMEPAD_BUTTON_SOUTH, SDL_RELEASED)");
SDLTest_AssertCheck(SDL_SetJoystickVirtualButton(joystick, SDL_GAMEPAD_BUTTON_SOUTH, SDL_FALSE), "SDL_SetJoystickVirtualButton(SDL_GAMEPAD_BUTTON_SOUTH, SDL_FALSE)");
SDL_UpdateJoysticks();
SDLTest_AssertCheck(SDL_GetGamepadButton(gamepad, SDL_GAMEPAD_BUTTON_SOUTH) == SDL_RELEASED, "SDL_GetGamepadButton(SDL_GAMEPAD_BUTTON_SOUTH) == SDL_RELEASED");
SDLTest_AssertCheck(SDL_GetGamepadButton(gamepad, SDL_GAMEPAD_BUTTON_SOUTH) == SDL_FALSE, "SDL_GetGamepadButton(SDL_GAMEPAD_BUTTON_SOUTH) == SDL_FALSE");
SDL_CloseGamepad(gamepad);
}

View File

@ -18,7 +18,7 @@
static int SDLCALL keyboard_getKeyboardState(void *arg)
{
int numkeys;
const Uint8 *state;
const SDL_bool *state;
/* Case where numkeys pointer is NULL */
state = SDL_GetKeyboardState(NULL);

View File

@ -1113,7 +1113,7 @@ static SDL_bool ShowingFront(void)
/* Show the back of the gamepad if the paddles are being held or bound */
for (i = SDL_GAMEPAD_BUTTON_RIGHT_PADDLE1; i <= SDL_GAMEPAD_BUTTON_LEFT_PADDLE2; ++i) {
if (SDL_GetGamepadButton(controller->gamepad, (SDL_GamepadButton)i) == SDL_PRESSED ||
if (SDL_GetGamepadButton(controller->gamepad, (SDL_GamepadButton)i) ||
binding_element == i) {
showing_front = SDL_FALSE;
break;
@ -1210,7 +1210,7 @@ static void VirtualGamepadMouseMotion(float x, float y)
const float MOVING_DISTANCE = 2.0f;
if (SDL_fabs(x - virtual_axis_start_x) >= MOVING_DISTANCE ||
SDL_fabs(y - virtual_axis_start_y) >= MOVING_DISTANCE) {
SDL_SetJoystickVirtualButton(virtual_joystick, virtual_button_active, SDL_RELEASED);
SDL_SetJoystickVirtualButton(virtual_joystick, virtual_button_active, SDL_FALSE);
virtual_button_active = SDL_GAMEPAD_BUTTON_INVALID;
}
}
@ -1248,7 +1248,7 @@ static void VirtualGamepadMouseMotion(float x, float y)
GetGamepadTouchpadArea(image, &touchpad);
virtual_touchpad_x = (x - touchpad.x) / touchpad.w;
virtual_touchpad_y = (y - touchpad.y) / touchpad.h;
SDL_SetJoystickVirtualTouchpad(virtual_joystick, 0, 0, SDL_PRESSED, virtual_touchpad_x, virtual_touchpad_y, 1.0f);
SDL_SetJoystickVirtualTouchpad(virtual_joystick, 0, 0, SDL_TRUE, virtual_touchpad_x, virtual_touchpad_y, 1.0f);
}
}
@ -1264,14 +1264,14 @@ static void VirtualGamepadMouseDown(float x, float y)
virtual_touchpad_active = SDL_TRUE;
virtual_touchpad_x = (x - touchpad.x) / touchpad.w;
virtual_touchpad_y = (y - touchpad.y) / touchpad.h;
SDL_SetJoystickVirtualTouchpad(virtual_joystick, 0, 0, SDL_PRESSED, virtual_touchpad_x, virtual_touchpad_y, 1.0f);
SDL_SetJoystickVirtualTouchpad(virtual_joystick, 0, 0, SDL_TRUE, virtual_touchpad_x, virtual_touchpad_y, 1.0f);
}
return;
}
if (element < SDL_GAMEPAD_BUTTON_MAX) {
virtual_button_active = (SDL_GamepadButton)element;
SDL_SetJoystickVirtualButton(virtual_joystick, virtual_button_active, SDL_PRESSED);
SDL_SetJoystickVirtualButton(virtual_joystick, virtual_button_active, SDL_TRUE);
} else {
switch (element) {
case SDL_GAMEPAD_ELEMENT_AXIS_LEFTX_NEGATIVE:
@ -1301,7 +1301,7 @@ static void VirtualGamepadMouseDown(float x, float y)
static void VirtualGamepadMouseUp(float x, float y)
{
if (virtual_button_active != SDL_GAMEPAD_BUTTON_INVALID) {
SDL_SetJoystickVirtualButton(virtual_joystick, virtual_button_active, SDL_RELEASED);
SDL_SetJoystickVirtualButton(virtual_joystick, virtual_button_active, SDL_FALSE);
virtual_button_active = SDL_GAMEPAD_BUTTON_INVALID;
}
@ -1317,7 +1317,7 @@ static void VirtualGamepadMouseUp(float x, float y)
}
if (virtual_touchpad_active) {
SDL_SetJoystickVirtualTouchpad(virtual_joystick, 0, 0, SDL_RELEASED, virtual_touchpad_x, virtual_touchpad_y, 0.0f);
SDL_SetJoystickVirtualTouchpad(virtual_joystick, 0, 0, SDL_FALSE, virtual_touchpad_x, virtual_touchpad_y, 0.0f);
virtual_touchpad_active = SDL_FALSE;
}
}
@ -1772,7 +1772,7 @@ static void loop(void *arg)
if (virtual_joystick && controller && controller->joystick == virtual_joystick) {
VirtualGamepadMouseDown(event.button.x, event.button.y);
}
UpdateButtonHighlights(event.button.x, event.button.y, event.button.state ? SDL_TRUE : SDL_FALSE);
UpdateButtonHighlights(event.button.x, event.button.y, event.button.down);
break;
case SDL_EVENT_MOUSE_BUTTON_UP:
@ -1833,7 +1833,7 @@ static void loop(void *arg)
}
}
}
UpdateButtonHighlights(event.button.x, event.button.y, event.button.state ? SDL_TRUE : SDL_FALSE);
UpdateButtonHighlights(event.button.x, event.button.y, event.button.down);
break;
case SDL_EVENT_MOUSE_MOTION:

View File

@ -285,7 +285,7 @@ static void HandleMouseButton(SDL_MouseButtonEvent *event)
continue;
}
if (event->which == mouse_state->instance_id) {
if (event->state) {
if (event->down) {
mouse_state->button_state |= SDL_BUTTON(event->button);
} else {
mouse_state->button_state &= ~SDL_BUTTON(event->button);

View File

@ -228,7 +228,7 @@ static void loop(void *arg)
case SDL_EVENT_KEY_UP:
switch (event.key.key) {
case SDLK_LSHIFT:
isRect = (event.key.state == SDL_PRESSED);
isRect = event.key.down;
if (active) {
active->isRect = isRect;
}