WIP SDL3 compatibility

This commit is contained in:
Cameron Gutman
2025-01-31 01:13:17 -06:00
parent 5290305944
commit 231a67946d
34 changed files with 772 additions and 497 deletions

View File

@@ -82,13 +82,13 @@ void SdlInputHandler::handleAbsoluteFingerEvent(SDL_TouchFingerEvent* event)
uint8_t eventType;
switch (event->type) {
case SDL_FINGERDOWN:
case SDL_EVENT_FINGER_DOWN :
eventType = LI_TOUCH_EVENT_DOWN;
break;
case SDL_FINGERMOTION:
case SDL_EVENT_FINGER_MOTION :
eventType = LI_TOUCH_EVENT_MOVE;
break;
case SDL_FINGERUP:
case SDL_EVENT_FINGER_UP :
eventType = LI_TOUCH_EVENT_UP;
break;
default:
@@ -98,16 +98,16 @@ void SdlInputHandler::handleAbsoluteFingerEvent(SDL_TouchFingerEvent* event)
uint32_t pointerId;
// If the pointer ID is larger than we can fit, just CRC it and use that as the ID.
if ((uint64_t)event->fingerId > UINT32_MAX) {
if ((uint64_t) event->fingerID > UINT32_MAX) {
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
QByteArrayView bav((char*)&event->fingerId, sizeof(event->fingerId));
QByteArrayView bav((char*)&event->fingerID, sizeof(event->fingerID));
pointerId = qChecksum(bav);
#else
pointerId = qChecksum((char*)&event->fingerId, sizeof(event->fingerId));
pointerId = qChecksum((char*)&event->fingerID, sizeof(event->fingerID));
#endif
}
else {
pointerId = (uint32_t)event->fingerId;
pointerId = (uint32_t) event->fingerID;
}
// Try to send it as a native pen/touch event, otherwise fall back to our touch emulation
@@ -117,7 +117,7 @@ void SdlInputHandler::handleAbsoluteFingerEvent(SDL_TouchFingerEvent* event)
int numTouchDevices = SDL_GetNumTouchDevices();
for (int i = 0; i < numTouchDevices; i++) {
if (event->touchId == SDL_GetTouchDevice(i)) {
if (event->touchID == SDL_GetTouchDevice(i)) {
const char* touchName = SDL_GetTouchName(i);
// SDL will report "pen" as the name of pen input devices on Windows.
@@ -158,12 +158,12 @@ void SdlInputHandler::emulateAbsoluteFingerEvent(SDL_TouchFingerEvent* event)
// dx and dy are deltas from the last touch event, not the first touch down.
// Ignore touch down events with more than one finger
if (event->type == SDL_FINGERDOWN && SDL_GetNumTouchFingers(event->touchId) > 1) {
if (event->type == SDL_EVENT_FINGER_DOWN && SDL_GetNumTouchFingers(event->touchID) > 1) {
return;
}
// Ignore touch move and touch up events from the non-primary finger
if (event->type != SDL_FINGERDOWN && event->fingerId != m_LastTouchDownEvent.fingerId) {
if (event->type != SDL_EVENT_FINGER_DOWN && event->fingerID != m_LastTouchDownEvent.fingerID) {
return;
}
@@ -190,7 +190,7 @@ void SdlInputHandler::emulateAbsoluteFingerEvent(SDL_TouchFingerEvent* event)
}
// Don't reposition for finger down events within the deadzone. This makes double-clicking easier.
if (event->type != SDL_FINGERDOWN ||
if (event->type != SDL_EVENT_FINGER_DOWN ||
event->timestamp - m_LastTouchUpEvent.timestamp > DOUBLE_TAP_DEAD_ZONE_DELAY ||
qSqrt(qPow(event->x - m_LastTouchUpEvent.x, 2) + qPow(event->y - m_LastTouchUpEvent.y, 2)) > DOUBLE_TAP_DEAD_ZONE_DELTA) {
// Scale window-relative events to be video-relative and clamp to video region
@@ -201,7 +201,7 @@ void SdlInputHandler::emulateAbsoluteFingerEvent(SDL_TouchFingerEvent* event)
LiSendMousePositionEvent(x - dst.x, y - dst.y, dst.w, dst.h);
}
if (event->type == SDL_FINGERDOWN) {
if (event->type == SDL_EVENT_FINGER_DOWN) {
m_LastTouchDownEvent = *event;
// Start/restart the long press timer
@@ -213,7 +213,7 @@ void SdlInputHandler::emulateAbsoluteFingerEvent(SDL_TouchFingerEvent* event)
// Left button down on finger down
LiSendMouseButtonEvent(BUTTON_ACTION_PRESS, BUTTON_LEFT);
}
else if (event->type == SDL_FINGERUP) {
else if (event->type == SDL_EVENT_FINGER_UP) {
m_LastTouchUpEvent = *event;
// Cancel the long press timer

View File

@@ -188,7 +188,7 @@ Uint32 SdlInputHandler::mouseEmulationTimerCallback(Uint32 interval, void *param
return interval;
}
void SdlInputHandler::handleControllerAxisEvent(SDL_ControllerAxisEvent* event)
void SdlInputHandler::handleControllerAxisEvent(SDL_GamepadAxisEvent * event)
{
SDL_JoystickID gameControllerId = event->which;
GamepadState* state = findStateForGamepad(gameControllerId);
@@ -201,10 +201,10 @@ void SdlInputHandler::handleControllerAxisEvent(SDL_ControllerAxisEvent* event)
for (;;) {
switch (event->axis)
{
case SDL_CONTROLLER_AXIS_LEFTX:
case SDL_GAMEPAD_AXIS_LEFTX :
state->lsX = event->value;
break;
case SDL_CONTROLLER_AXIS_LEFTY:
case SDL_GAMEPAD_AXIS_LEFTY :
// Signed values have one more negative value than
// positive value, so inverting the sign on -32768
// could actually cause the value to overflow and
@@ -212,16 +212,16 @@ void SdlInputHandler::handleControllerAxisEvent(SDL_ControllerAxisEvent* event)
// capping the value at 32767.
state->lsY = -qMax(event->value, (short)-32767);
break;
case SDL_CONTROLLER_AXIS_RIGHTX:
case SDL_GAMEPAD_AXIS_RIGHTX :
state->rsX = event->value;
break;
case SDL_CONTROLLER_AXIS_RIGHTY:
case SDL_GAMEPAD_AXIS_RIGHTY :
state->rsY = -qMax(event->value, (short)-32767);
break;
case SDL_CONTROLLER_AXIS_TRIGGERLEFT:
case SDL_GAMEPAD_AXIS_LEFT_TRIGGER :
state->lt = (unsigned char)(event->value * 255UL / 32767);
break;
case SDL_CONTROLLER_AXIS_TRIGGERRIGHT:
case SDL_GAMEPAD_AXIS_RIGHT_TRIGGER :
state->rt = (unsigned char)(event->value * 255UL / 32767);
break;
default:
@@ -232,18 +232,18 @@ void SdlInputHandler::handleControllerAxisEvent(SDL_ControllerAxisEvent* event)
}
// Check for another event to batch with
if (SDL_PeepEvents(&nextEvent, 1, SDL_PEEKEVENT, SDL_CONTROLLERAXISMOTION, SDL_CONTROLLERAXISMOTION) <= 0) {
if (SDL_PeepEvents(&nextEvent, 1, SDL_PEEKEVENT, SDL_EVENT_GAMEPAD_AXIS_MOTION, SDL_EVENT_GAMEPAD_AXIS_MOTION) <= 0) {
break;
}
event = &nextEvent.caxis;
event = &nextEvent.gaxis;
if (event->which != gameControllerId) {
// Stop batching if a different gamepad interrupts us
break;
}
// Remove the next event to batch
SDL_PeepEvents(&nextEvent, 1, SDL_GETEVENT, SDL_CONTROLLERAXISMOTION, SDL_CONTROLLERAXISMOTION);
SDL_PeepEvents(&nextEvent, 1, SDL_GETEVENT, SDL_EVENT_GAMEPAD_AXIS_MOTION, SDL_EVENT_GAMEPAD_AXIS_MOTION);
}
// Only send the gamepad state to the host if it's not in mouse emulation mode
@@ -252,7 +252,7 @@ void SdlInputHandler::handleControllerAxisEvent(SDL_ControllerAxisEvent* event)
}
}
void SdlInputHandler::handleControllerButtonEvent(SDL_ControllerButtonEvent* event)
void SdlInputHandler::handleControllerButtonEvent(SDL_GamepadButtonEvent * event)
{
if (event->button >= SDL_arraysize(k_ButtonMap)) {
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
@@ -268,53 +268,53 @@ void SdlInputHandler::handleControllerButtonEvent(SDL_ControllerButtonEvent* eve
if (m_SwapFaceButtons) {
switch (event->button) {
case SDL_CONTROLLER_BUTTON_A:
event->button = SDL_CONTROLLER_BUTTON_B;
case SDL_GAMEPAD_BUTTON_SOUTH :
event->button = SDL_GAMEPAD_BUTTON_EAST;
break;
case SDL_CONTROLLER_BUTTON_B:
event->button = SDL_CONTROLLER_BUTTON_A;
case SDL_GAMEPAD_BUTTON_EAST :
event->button = SDL_GAMEPAD_BUTTON_SOUTH;
break;
case SDL_CONTROLLER_BUTTON_X:
event->button = SDL_CONTROLLER_BUTTON_Y;
case SDL_GAMEPAD_BUTTON_WEST :
event->button = SDL_GAMEPAD_BUTTON_NORTH;
break;
case SDL_CONTROLLER_BUTTON_Y:
event->button = SDL_CONTROLLER_BUTTON_X;
case SDL_GAMEPAD_BUTTON_NORTH :
event->button = SDL_GAMEPAD_BUTTON_WEST;
break;
}
}
if (event->state == SDL_PRESSED) {
if (event->state == true) {
state->buttons |= k_ButtonMap[event->button];
if (event->button == SDL_CONTROLLER_BUTTON_START) {
if (event->button == SDL_GAMEPAD_BUTTON_START) {
state->lastStartDownTime = SDL_GetTicks();
}
else if (state->mouseEmulationTimer != 0) {
if (event->button == SDL_CONTROLLER_BUTTON_A) {
if (event->button == SDL_GAMEPAD_BUTTON_SOUTH) {
LiSendMouseButtonEvent(BUTTON_ACTION_PRESS, BUTTON_LEFT);
}
else if (event->button == SDL_CONTROLLER_BUTTON_B) {
else if (event->button == SDL_GAMEPAD_BUTTON_EAST) {
LiSendMouseButtonEvent(BUTTON_ACTION_PRESS, BUTTON_RIGHT);
}
else if (event->button == SDL_CONTROLLER_BUTTON_X) {
else if (event->button == SDL_GAMEPAD_BUTTON_WEST) {
LiSendMouseButtonEvent(BUTTON_ACTION_PRESS, BUTTON_MIDDLE);
}
else if (event->button == SDL_CONTROLLER_BUTTON_LEFTSHOULDER) {
else if (event->button == SDL_GAMEPAD_BUTTON_LEFT_SHOULDER) {
LiSendMouseButtonEvent(BUTTON_ACTION_PRESS, BUTTON_X1);
}
else if (event->button == SDL_CONTROLLER_BUTTON_RIGHTSHOULDER) {
else if (event->button == SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER) {
LiSendMouseButtonEvent(BUTTON_ACTION_PRESS, BUTTON_X2);
}
else if (event->button == SDL_CONTROLLER_BUTTON_DPAD_UP) {
else if (event->button == SDL_GAMEPAD_BUTTON_DPAD_UP) {
LiSendScrollEvent(1);
}
else if (event->button == SDL_CONTROLLER_BUTTON_DPAD_DOWN) {
else if (event->button == SDL_GAMEPAD_BUTTON_DPAD_DOWN) {
LiSendScrollEvent(-1);
}
else if (event->button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT) {
else if (event->button == SDL_GAMEPAD_BUTTON_DPAD_RIGHT) {
LiSendHScrollEvent(1);
}
else if (event->button == SDL_CONTROLLER_BUTTON_DPAD_LEFT) {
else if (event->button == SDL_GAMEPAD_BUTTON_DPAD_LEFT) {
LiSendHScrollEvent(-1);
}
}
@@ -322,7 +322,7 @@ void SdlInputHandler::handleControllerButtonEvent(SDL_ControllerButtonEvent* eve
else {
state->buttons &= ~k_ButtonMap[event->button];
if (event->button == SDL_CONTROLLER_BUTTON_START) {
if (event->button == SDL_GAMEPAD_BUTTON_START) {
if (SDL_GetTicks() - state->lastStartDownTime > MOUSE_EMULATION_LONG_PRESS_TIME) {
if (state->mouseEmulationTimer != 0) {
SDL_RemoveTimer(state->mouseEmulationTimer);
@@ -345,19 +345,19 @@ void SdlInputHandler::handleControllerButtonEvent(SDL_ControllerButtonEvent* eve
}
}
else if (state->mouseEmulationTimer != 0) {
if (event->button == SDL_CONTROLLER_BUTTON_A) {
if (event->button == SDL_GAMEPAD_BUTTON_SOUTH) {
LiSendMouseButtonEvent(BUTTON_ACTION_RELEASE, BUTTON_LEFT);
}
else if (event->button == SDL_CONTROLLER_BUTTON_B) {
else if (event->button == SDL_GAMEPAD_BUTTON_EAST) {
LiSendMouseButtonEvent(BUTTON_ACTION_RELEASE, BUTTON_RIGHT);
}
else if (event->button == SDL_CONTROLLER_BUTTON_X) {
else if (event->button == SDL_GAMEPAD_BUTTON_WEST) {
LiSendMouseButtonEvent(BUTTON_ACTION_RELEASE, BUTTON_MIDDLE);
}
else if (event->button == SDL_CONTROLLER_BUTTON_LEFTSHOULDER) {
else if (event->button == SDL_GAMEPAD_BUTTON_LEFT_SHOULDER) {
LiSendMouseButtonEvent(BUTTON_ACTION_RELEASE, BUTTON_X1);
}
else if (event->button == SDL_CONTROLLER_BUTTON_RIGHTSHOULDER) {
else if (event->button == SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER) {
LiSendMouseButtonEvent(BUTTON_ACTION_RELEASE, BUTTON_X2);
}
}
@@ -370,7 +370,7 @@ void SdlInputHandler::handleControllerButtonEvent(SDL_ControllerButtonEvent* eve
// Push a quit event to the main loop
SDL_Event event;
event.type = SDL_QUIT;
event.type = SDL_EVENT_QUIT;
event.quit.timestamp = SDL_GetTicks();
SDL_PushEvent(&event);
@@ -403,7 +403,7 @@ void SdlInputHandler::handleControllerButtonEvent(SDL_ControllerButtonEvent* eve
#if SDL_VERSION_ATLEAST(2, 0, 14)
void SdlInputHandler::handleControllerSensorEvent(SDL_ControllerSensorEvent* event)
void SdlInputHandler::handleControllerSensorEvent(SDL_GamepadSensorEvent * event)
{
GamepadState* state = findStateForGamepad(event->which);
if (state == NULL) {
@@ -438,7 +438,7 @@ void SdlInputHandler::handleControllerSensorEvent(SDL_ControllerSensorEvent* eve
}
}
void SdlInputHandler::handleControllerTouchpadEvent(SDL_ControllerTouchpadEvent* event)
void SdlInputHandler::handleControllerTouchpadEvent(SDL_GamepadTouchpadEvent * event)
{
GamepadState* state = findStateForGamepad(event->which);
if (state == NULL) {
@@ -447,13 +447,13 @@ void SdlInputHandler::handleControllerTouchpadEvent(SDL_ControllerTouchpadEvent*
uint8_t eventType;
switch (event->type) {
case SDL_CONTROLLERTOUCHPADDOWN:
case SDL_EVENT_GAMEPAD_TOUCHPAD_DOWN :
eventType = LI_TOUCH_EVENT_DOWN;
break;
case SDL_CONTROLLERTOUCHPADUP:
case SDL_EVENT_GAMEPAD_TOUCHPAD_UP :
eventType = LI_TOUCH_EVENT_UP;
break;
case SDL_CONTROLLERTOUCHPADMOTION:
case SDL_EVENT_GAMEPAD_TOUCHPAD_MOTION :
eventType = LI_TOUCH_EVENT_MOVE;
break;
default:
@@ -479,18 +479,21 @@ void SdlInputHandler::handleJoystickBatteryEvent(SDL_JoyBatteryEvent* event)
#endif
void SdlInputHandler::handleControllerDeviceEvent(SDL_ControllerDeviceEvent* event)
void SdlInputHandler::handleControllerDeviceEvent(SDL_GamepadDeviceEvent * event)
{
GamepadState* state;
if (event->type == SDL_CONTROLLERDEVICEADDED) {
if (event->type == SDL_EVENT_GAMEPAD_ADDED) {
int i;
const char* name;
SDL_GameController* controller;
SDL_Gamepad * controller;
const char* mapping;
char guidStr[33];
uint32_t hapticCaps;
#if SDL_VERSION_ATLEAST(3, 0, 0)
controller = SDL_OpenGamepad(event->which);
#else
controller = SDL_GameControllerOpen(event->which);
if (controller == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
@@ -500,7 +503,7 @@ void SdlInputHandler::handleControllerDeviceEvent(SDL_ControllerDeviceEvent* eve
}
// SDL_CONTROLLERDEVICEADDED can be reported multiple times for the same
// gamepad in rare cases, because SDL doesn't fixup the device index in
// gamepad in rare cases, because SDL2 doesn't fixup the device index in
// the SDL_CONTROLLERDEVICEADDED event if an unopened gamepad disappears
// before we've processed the add event.
for (int i = 0; i < MAX_GAMEPADS; i++) {
@@ -508,10 +511,11 @@ void SdlInputHandler::handleControllerDeviceEvent(SDL_ControllerDeviceEvent* eve
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
"Received duplicate add event for controller index: %d",
event->which);
SDL_GameControllerClose(controller);
SDL_CloseGamepad(controller);
return;
}
}
#endif
// We used to use SDL_GameControllerGetPlayerIndex() here but that
// can lead to strange issues due to bugs in Windows where an Xbox
@@ -531,18 +535,18 @@ void SdlInputHandler::handleControllerDeviceEvent(SDL_ControllerDeviceEvent* eve
if (i == MAX_GAMEPADS) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"No open gamepad slots found!");
SDL_GameControllerClose(controller);
SDL_CloseGamepad(controller);
return;
}
SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(SDL_GameControllerGetJoystick(controller)),
SDL_JoystickGetGUIDString(SDL_GetJoystickGUID(SDL_GetGamepadJoystick(controller)),
guidStr, sizeof(guidStr));
if (m_IgnoreDeviceGuids.contains(guidStr, Qt::CaseInsensitive))
{
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
"Skipping ignored device with GUID: %s",
guidStr);
SDL_GameControllerClose(controller);
SDL_CloseGamepad(controller);
return;
}
@@ -554,7 +558,7 @@ void SdlInputHandler::handleControllerDeviceEvent(SDL_ControllerDeviceEvent* eve
// This will change indicators on the controller to show the assigned
// player index. For Xbox 360 controllers, that means updating the LED
// ring to light up the corresponding quadrant for this player.
SDL_GameControllerSetPlayerIndex(controller, state->index);
SDL_SetGamepadPlayerIndex(controller, state->index);
#endif
}
else {
@@ -563,7 +567,7 @@ void SdlInputHandler::handleControllerDeviceEvent(SDL_ControllerDeviceEvent* eve
}
state->controller = controller;
state->jsId = SDL_JoystickInstanceID(SDL_GameControllerGetJoystick(state->controller));
state->jsId = SDL_GetJoystickID(SDL_GetGamepadJoystick(state->controller));
hapticCaps = 0;
#if SDL_VERSION_ATLEAST(2, 0, 18)
@@ -573,9 +577,9 @@ void SdlInputHandler::handleControllerDeviceEvent(SDL_ControllerDeviceEvent* eve
// Perform a tiny rumbles to see if haptics are supported.
// NB: We cannot use zeros for rumble intensity or SDL will not actually call the JS driver
// and we'll get a (potentially false) success value returned.
hapticCaps |= SDL_GameControllerRumble(controller, 1, 1, 1) == 0 ? ML_HAPTIC_GC_RUMBLE : 0;
hapticCaps |= SDL_RumbleGamepad(controller, 1, 1, 1) ? ML_HAPTIC_GC_RUMBLE : 0;
#if SDL_VERSION_ATLEAST(2, 0, 14)
hapticCaps |= SDL_GameControllerRumbleTriggers(controller, 1, 1, 1) == 0 ? ML_HAPTIC_GC_TRIGGER_RUMBLE : 0;
hapticCaps |= SDL_RumbleGamepadTriggers(controller, 1, 1, 1) ? ML_HAPTIC_GC_TRIGGER_RUMBLE : 0;
#endif
#else
state->haptic = SDL_HapticOpenFromJoystick(SDL_GameControllerGetJoystick(state->controller));
@@ -606,11 +610,11 @@ void SdlInputHandler::handleControllerDeviceEvent(SDL_ControllerDeviceEvent* eve
}
#endif
mapping = SDL_GameControllerMapping(state->controller);
name = SDL_GameControllerName(state->controller);
mapping = SDL_GetGamepadMapping(state->controller);
name = SDL_GetGamepadName(state->controller);
uint16_t vendorId = SDL_GameControllerGetVendor(state->controller);
uint16_t productId = SDL_GameControllerGetProduct(state->controller);
uint16_t vendorId = SDL_GetGamepadVendor(state->controller);
uint16_t productId = SDL_GetGamepadProduct(state->controller);
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
"Gamepad %d (player %d) is: %s (VID/PID: 0x%.4x/0x%.4x) (haptic capabilities: 0x%x) (mapping: %s -> %s)",
i,
@@ -636,21 +640,21 @@ void SdlInputHandler::handleControllerDeviceEvent(SDL_ControllerDeviceEvent* eve
SDL_assert(m_GamepadMask == 0x1);
}
SDL_JoystickPowerLevel powerLevel = SDL_JoystickCurrentPowerLevel(SDL_GameControllerGetJoystick(state->controller));
SDL_JoystickPowerLevel powerLevel = SDL_GetJoystickPowerLevel(SDL_GetGamepadJoystick(state->controller));
#if SDL_VERSION_ATLEAST(2, 0, 14)
// On SDL 2.0.14 and later, we can provide enhanced controller information to the host PC
// for it to use as a hint for the type of controller to emulate.
uint32_t supportedButtonFlags = 0;
for (int i = 0; i < (int)SDL_arraysize(k_ButtonMap); i++) {
if (SDL_GameControllerHasButton(state->controller, (SDL_GameControllerButton)i)) {
if (SDL_GamepadHasButton(state->controller, (SDL_GamepadButton)i)) {
supportedButtonFlags |= k_ButtonMap[i];
}
}
uint32_t capabilities = 0;
if (SDL_GameControllerGetBindForAxis(state->controller, SDL_CONTROLLER_AXIS_TRIGGERLEFT).bindType == SDL_CONTROLLER_BINDTYPE_AXIS ||
SDL_GameControllerGetBindForAxis(state->controller, SDL_CONTROLLER_AXIS_TRIGGERRIGHT).bindType == SDL_CONTROLLER_BINDTYPE_AXIS) {
if (SDL_GameControllerGetBindForAxis(state->controller, SDL_GAMEPAD_AXIS_LEFT_TRIGGER).bindType == SDL_GAMEPAD_BINDTYPE_AXIS ||
SDL_GameControllerGetBindForAxis(state->controller, SDL_GAMEPAD_AXIS_RIGHT_TRIGGER).bindType == SDL_GAMEPAD_BINDTYPE_AXIS) {
// We assume these are analog triggers if the binding is to an axis rather than a button
capabilities |= LI_CCAP_ANALOG_TRIGGERS;
}
@@ -660,13 +664,13 @@ void SdlInputHandler::handleControllerDeviceEvent(SDL_ControllerDeviceEvent* eve
if (hapticCaps & ML_HAPTIC_GC_TRIGGER_RUMBLE) {
capabilities |= LI_CCAP_TRIGGER_RUMBLE;
}
if (SDL_GameControllerGetNumTouchpads(state->controller) > 0) {
if (SDL_GetNumGamepadTouchpads(state->controller) > 0) {
capabilities |= LI_CCAP_TOUCHPAD;
}
if (SDL_GameControllerHasSensor(state->controller, SDL_SENSOR_ACCEL)) {
if (SDL_GamepadHasSensor(state->controller, SDL_SENSOR_ACCEL)) {
capabilities |= LI_CCAP_ACCEL;
}
if (SDL_GameControllerHasSensor(state->controller, SDL_SENSOR_GYRO)) {
if (SDL_GamepadHasSensor(state->controller, SDL_SENSOR_GYRO)) {
capabilities |= LI_CCAP_GYRO;
}
if (powerLevel != SDL_JOYSTICK_POWER_UNKNOWN || SDL_VERSION_ATLEAST(2, 24, 0)) {
@@ -677,21 +681,21 @@ void SdlInputHandler::handleControllerDeviceEvent(SDL_ControllerDeviceEvent* eve
}
uint8_t type;
switch (SDL_GameControllerGetType(state->controller)) {
case SDL_CONTROLLER_TYPE_XBOX360:
case SDL_CONTROLLER_TYPE_XBOXONE:
switch (SDL_GetGamepadType(state->controller)) {
case SDL_GAMEPAD_TYPE_XBOX360 :
case SDL_GAMEPAD_TYPE_XBOXONE :
type = LI_CTYPE_XBOX;
break;
case SDL_CONTROLLER_TYPE_PS3:
case SDL_CONTROLLER_TYPE_PS4:
case SDL_CONTROLLER_TYPE_PS5:
case SDL_GAMEPAD_TYPE_PS3 :
case SDL_GAMEPAD_TYPE_PS4 :
case SDL_GAMEPAD_TYPE_PS5 :
type = LI_CTYPE_PS;
break;
case SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO:
case SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_PRO :
#if SDL_VERSION_ATLEAST(2, 24, 0)
case SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_JOYCON_LEFT:
case SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_JOYCON_RIGHT:
case SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_JOYCON_PAIR:
case SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_LEFT :
case SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_RIGHT :
case SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_PAIR :
#endif
type = LI_CTYPE_NINTENDO;
break;
@@ -704,7 +708,7 @@ void SdlInputHandler::handleControllerDeviceEvent(SDL_ControllerDeviceEvent* eve
// we'll allow the Select+PS button combo to act as the touchpad.
state->clickpadButtonEmulationEnabled =
#if SDL_VERSION_ATLEAST(2, 0, 14)
SDL_GameControllerGetBindForButton(state->controller, SDL_CONTROLLER_BUTTON_TOUCHPAD).bindType == SDL_CONTROLLER_BINDTYPE_NONE &&
SDL_GameControllerGetBindForButton(state->controller, SDL_GAMEPAD_BUTTON_TOUCHPAD).bindType == SDL_GAMEPAD_BINDTYPE_NONE &&
#endif
type == LI_CTYPE_PS;
@@ -720,7 +724,7 @@ void SdlInputHandler::handleControllerDeviceEvent(SDL_ControllerDeviceEvent* eve
sendGamepadBatteryState(state, powerLevel);
}
}
else if (event->type == SDL_CONTROLLERDEVICEREMOVED) {
else if (event->type == SDL_EVENT_GAMEPAD_REMOVED) {
state = findStateForGamepad(event->which);
if (state != NULL) {
if (state->mouseEmulationTimer != 0) {
@@ -728,7 +732,7 @@ void SdlInputHandler::handleControllerDeviceEvent(SDL_ControllerDeviceEvent* eve
SDL_RemoveTimer(state->mouseEmulationTimer);
}
SDL_GameControllerClose(state->controller);
SDL_CloseGamepad(state->controller);
#if !SDL_VERSION_ATLEAST(2, 0, 9)
if (state->haptic != nullptr) {
@@ -761,24 +765,23 @@ void SdlInputHandler::handleControllerDeviceEvent(SDL_ControllerDeviceEvent* eve
void SdlInputHandler::handleJoystickArrivalEvent(SDL_JoyDeviceEvent* event)
{
SDL_assert(event->type == SDL_JOYDEVICEADDED);
SDL_assert(event->type == SDL_EVENT_JOYSTICK_ADDED);
if (!SDL_IsGameController(event->which)) {
char guidStr[33];
SDL_JoystickGetGUIDString(SDL_JoystickGetDeviceGUID(event->which),
guidStr, sizeof(guidStr));
const char* name = SDL_JoystickNameForIndex(event->which);
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
"Joystick discovered with no mapping: %s %s",
name ? name : "<UNKNOWN>",
guidStr);
SDL_Joystick* joy = SDL_JoystickOpen(event->which);
if (!SDL_IsGamepad(event->which)) {
SDL_Joystick* joy = SDL_OpenJoystick(event->which);
if (joy != nullptr) {
char guidStr[33];
SDL_GUIDToString(SDL_JoystickGetGUID(joy), guidStr, sizeof(guidStr));
const char* name = SDL_JoystickName(joy);
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
"Unmapped joystick: %s %s",
name ? name : "<UNKNOWN>",
guidStr);
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
"Number of axes: %d | Number of buttons: %d | Number of hats: %d",
SDL_JoystickNumAxes(joy), SDL_JoystickNumButtons(joy),
SDL_JoystickNumHats(joy));
SDL_JoystickClose(joy);
SDL_GetNumJoystickAxes(joy), SDL_GetNumJoystickButtons(joy),
SDL_GetNumJoystickHats(joy));
SDL_CloseJoystick(joy);
}
else {
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
@@ -797,7 +800,7 @@ void SdlInputHandler::rumble(unsigned short controllerNumber, unsigned short low
#if SDL_VERSION_ATLEAST(2, 0, 9)
if (m_GamepadState[controllerNumber].controller != nullptr) {
SDL_GameControllerRumble(m_GamepadState[controllerNumber].controller, lowFreqMotor, highFreqMotor, 30000);
SDL_RumbleGamepad(m_GamepadState[controllerNumber].controller, lowFreqMotor, highFreqMotor, 30000);
}
#else
// Check if the controller supports haptics (and if the controller exists at all)
@@ -855,7 +858,7 @@ void SdlInputHandler::rumbleTriggers(uint16_t controllerNumber, uint16_t leftTri
#if SDL_VERSION_ATLEAST(2, 0, 14)
if (m_GamepadState[controllerNumber].controller != nullptr) {
SDL_GameControllerRumbleTriggers(m_GamepadState[controllerNumber].controller, leftTrigger, rightTrigger, 30000);
SDL_RumbleGamepadTriggers(m_GamepadState[controllerNumber].controller, leftTrigger, rightTrigger, 30000);
}
#endif
}
@@ -874,12 +877,12 @@ void SdlInputHandler::setMotionEventState(uint16_t controllerNumber, uint8_t mot
switch (motionType) {
case LI_MOTION_TYPE_ACCEL:
m_GamepadState[controllerNumber].accelReportPeriodMs = reportPeriodMs;
SDL_GameControllerSetSensorEnabled(m_GamepadState[controllerNumber].controller, SDL_SENSOR_ACCEL, reportRateHz ? SDL_TRUE : SDL_FALSE);
SDL_SetGamepadSensorEnabled(m_GamepadState[controllerNumber].controller, SDL_SENSOR_ACCEL, reportRateHz ? SDL_TRUE : SDL_FALSE);
break;
case LI_MOTION_TYPE_GYRO:
m_GamepadState[controllerNumber].gyroReportPeriodMs = reportPeriodMs;
SDL_GameControllerSetSensorEnabled(m_GamepadState[controllerNumber].controller, SDL_SENSOR_GYRO, reportRateHz ? SDL_TRUE : SDL_FALSE);
SDL_SetGamepadSensorEnabled(m_GamepadState[controllerNumber].controller, SDL_SENSOR_GYRO, reportRateHz ? SDL_TRUE : SDL_FALSE);
break;
}
}
@@ -895,7 +898,7 @@ void SdlInputHandler::setControllerLED(uint16_t controllerNumber, uint8_t r, uin
#if SDL_VERSION_ATLEAST(2, 0, 14)
if (m_GamepadState[controllerNumber].controller != nullptr) {
SDL_GameControllerSetLED(m_GamepadState[controllerNumber].controller, r, g, b);
SDL_SetGamepadLED(m_GamepadState[controllerNumber].controller, r, g, b);
}
#endif
}
@@ -904,31 +907,32 @@ QString SdlInputHandler::getUnmappedGamepads()
{
QString ret;
if (SDLC_FAILURE(SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER))) {
if (SDLC_FAILURE(SDL_InitSubSystem(SDL_INIT_GAMEPAD))) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER) failed: %s",
"SDL_InitSubSystem(SDL_INIT_GAMEPAD) failed: %s",
SDL_GetError());
}
MappingManager mappingManager;
mappingManager.applyMappings();
int numJoysticks = SDL_NumJoysticks();
int numJoysticks = 0;
SDL_JoystickID* joysticks = SDL_GetJoysticks(&numJoysticks);
for (int i = 0; i < numJoysticks; i++) {
if (!SDL_IsGameController(i)) {
char guidStr[33];
SDL_JoystickGetGUIDString(SDL_JoystickGetDeviceGUID(i),
guidStr, sizeof(guidStr));
const char* name = SDL_JoystickNameForIndex(i);
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
"Unmapped joystick: %s %s",
name ? name : "<UNKNOWN>",
guidStr);
SDL_Joystick* joy = SDL_JoystickOpen(i);
if (!SDL_IsGamepad(joysticks[i])) {
SDL_Joystick* joy = SDL_OpenJoystick(joysticks[i]);
if (joy != nullptr) {
int numButtons = SDL_JoystickNumButtons(joy);
int numHats = SDL_JoystickNumHats(joy);
int numAxes = SDL_JoystickNumAxes(joy);
char guidStr[33];
SDL_GUIDToString(SDL_JoystickGetGUID(joy), guidStr, sizeof(guidStr));
const char* name = SDL_JoystickName(joy);
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
"Unmapped joystick: %s %s",
name ? name : "<UNKNOWN>",
guidStr);
int numButtons = SDL_GetNumJoystickButtons(joy);
int numHats = SDL_GetNumJoystickHats(joy);
int numAxes = SDL_GetNumJoystickAxes(joy);
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
"Number of axes: %d | Number of buttons: %d | Number of hats: %d",
@@ -944,7 +948,7 @@ QString SdlInputHandler::getUnmappedGamepads()
ret += name;
}
SDL_JoystickClose(joy);
SDL_CloseJoystick(joy);
}
else {
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
@@ -953,12 +957,13 @@ QString SdlInputHandler::getUnmappedGamepads()
}
}
}
SDL_free(joysticks);
SDL_QuitSubSystem(SDL_INIT_GAMECONTROLLER);
SDL_QuitSubSystem(SDL_INIT_GAMEPAD);
// Flush stale events so they aren't processed by the main session event loop
SDL_FlushEvents(SDL_JOYDEVICEADDED, SDL_JOYDEVICEREMOVED);
SDL_FlushEvents(SDL_CONTROLLERDEVICEADDED, SDL_CONTROLLERDEVICEREMAPPED);
SDL_FlushEvents(SDL_EVENT_JOYSTICK_ADDED, SDL_EVENT_JOYSTICK_REMOVED);
SDL_FlushEvents(SDL_EVENT_GAMEPAD_ADDED, SDL_EVENT_GAMEPAD_REMAPPED);
return ret;
}
@@ -974,19 +979,17 @@ int SdlInputHandler::getAttachedGamepadMask()
}
count = mask = 0;
int numJoysticks = SDL_NumJoysticks();
for (int i = 0; i < numJoysticks; i++) {
if (SDL_IsGameController(i)) {
char guidStr[33];
SDL_JoystickGetGUIDString(SDL_JoystickGetDeviceGUID(i),
guidStr, sizeof(guidStr));
int numGamepads = 0;
SDL_JoystickID *gamepads = SDL_GetGamepads(&numGamepads);
for (int i = 0; i < numGamepads; i++) {
char guidStr[33];
SDL_GUIDToString(SDL_GetJoystickGUIDForID(i), guidStr, sizeof(guidStr));
if (!m_IgnoreDeviceGuids.contains(guidStr, Qt::CaseInsensitive))
{
mask |= (1 << count++);
}
if (!m_IgnoreDeviceGuids.contains(guidStr, Qt::CaseInsensitive)) {
mask |= (1 << count++);
}
}
SDL_free(gamepads);
return mask;
}

View File

@@ -165,10 +165,10 @@ SdlInputHandler::SdlInputHandler(StreamingPreferences& prefs, int streamWidth, i
// We need to reinit this each time, since you only get
// an initial set of gamepad arrival events once per init.
SDL_assert(!SDL_WasInit(SDL_INIT_GAMECONTROLLER));
if (SDLC_FAILURE(SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER))) {
SDL_assert(!SDL_WasInit(SDL_INIT_GAMEPAD));
if (SDLC_FAILURE(SDL_InitSubSystem(SDL_INIT_GAMEPAD))) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER) failed: %s",
"SDL_InitSubSystem(SDL_INIT_GAMEPAD) failed: %s",
SDL_GetError());
}
@@ -219,8 +219,8 @@ SdlInputHandler::~SdlInputHandler()
SDL_assert(!SDL_WasInit(SDL_INIT_HAPTIC));
#endif
SDL_QuitSubSystem(SDL_INIT_GAMECONTROLLER);
SDL_assert(!SDL_WasInit(SDL_INIT_GAMECONTROLLER));
SDL_QuitSubSystem(SDL_INIT_GAMEPAD);
SDL_assert(!SDL_WasInit(SDL_INIT_GAMEPAD));
SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
SDL_assert(!SDL_WasInit(SDL_INIT_JOYSTICK));
@@ -275,7 +275,7 @@ void SdlInputHandler::notifyMouseLeave()
// NB: Not using SDL_GetGlobalMouseState() because we want our state not the system's
Uint32 mouseState = SDL_GetMouseState(nullptr, nullptr);
for (Uint32 button = SDL_BUTTON_LEFT; button <= SDL_BUTTON_X2; button++) {
if (mouseState & SDL_BUTTON(button)) {
if (mouseState & SDL_BUTTON_MASK(button)) {
SDL_CaptureMouse(SDL_TRUE);
break;
}
@@ -388,7 +388,7 @@ void SdlInputHandler::setCaptureActive(bool active)
if (isMouseInVideoRegion(mouseX, mouseY)) {
// Synthesize a mouse event to synchronize the cursor
SDL_MouseMotionEvent motionEvent = {};
motionEvent.type = SDL_MOUSEMOTION;
motionEvent.type = SDL_EVENT_MOUSE_MOTION;
motionEvent.timestamp = SDL_GetTicks();
motionEvent.windowID = SDL_GetWindowID(m_Window);
motionEvent.x = mouseX;
@@ -418,7 +418,7 @@ void SdlInputHandler::setCaptureActive(bool active)
void SdlInputHandler::handleTouchFingerEvent(SDL_TouchFingerEvent* event)
{
#if SDL_VERSION_ATLEAST(2, 0, 10)
if (SDL_GetTouchDeviceType(event->touchId) != SDL_TOUCH_DEVICE_DIRECT) {
if (SDL_GetTouchDeviceType(event->touchID) != SDL_TOUCH_DEVICE_DIRECT) {
// Ignore anything that isn't a touchscreen. We may get callbacks
// for trackpads, but we want to handle those in the mouse path.
return;

View File

@@ -6,7 +6,7 @@
#include "SDL_compat.h"
struct GamepadState {
SDL_GameController* controller;
SDL_Gamepad * controller;
SDL_JoystickID jsId;
short index;
@@ -24,11 +24,11 @@ struct GamepadState {
#if SDL_VERSION_ATLEAST(2, 0, 14)
uint8_t gyroReportPeriodMs;
float lastGyroEventData[SDL_arraysize(SDL_ControllerSensorEvent::data)];
float lastGyroEventData[SDL_arraysize(SDL_GamepadSensorEvent::data)];
uint32_t lastGyroEventTime;
uint8_t accelReportPeriodMs;
float lastAccelEventData[SDL_arraysize(SDL_ControllerSensorEvent::data)];
float lastAccelEventData[SDL_arraysize(SDL_GamepadSensorEvent::data)];
uint32_t lastAccelEventTime;
#endif
@@ -67,16 +67,16 @@ public:
void handleMouseWheelEvent(SDL_MouseWheelEvent* event);
void handleControllerAxisEvent(SDL_ControllerAxisEvent* event);
void handleControllerAxisEvent(SDL_GamepadAxisEvent* event);
void handleControllerButtonEvent(SDL_ControllerButtonEvent* event);
void handleControllerButtonEvent(SDL_GamepadButtonEvent* event);
void handleControllerDeviceEvent(SDL_ControllerDeviceEvent* event);
void handleControllerDeviceEvent(SDL_GamepadDeviceEvent* event);
#if SDL_VERSION_ATLEAST(2, 0, 14)
void handleControllerSensorEvent(SDL_ControllerSensorEvent* event);
void handleControllerSensorEvent(SDL_GamepadSensorEvent* event);
void handleControllerTouchpadEvent(SDL_ControllerTouchpadEvent* event);
void handleControllerTouchpadEvent(SDL_GamepadTouchpadEvent* event);
#endif
#if SDL_VERSION_ATLEAST(2, 24, 0)

View File

@@ -1,6 +1,7 @@
#include "streaming/session.h"
#include <Limelight.h>
#include "SDL_compat.h"
#define VK_0 0x30
@@ -22,7 +23,7 @@ void SdlInputHandler::performSpecialKeyCombo(KeyCombo combo)
// Push a quit event to the main loop
SDL_Event event;
event.type = SDL_QUIT;
event.type = SDL_EVENT_QUIT;
event.quit.timestamp = SDL_GetTicks();
SDL_PushEvent(&event);
break;
@@ -151,15 +152,15 @@ void SdlInputHandler::handleKeyEvent(SDL_KeyboardEvent* event)
if (event->repeat) {
// Ignore repeat key down events
SDL_assert(event->state == SDL_PRESSED);
SDL_assert(event->state == true);
return;
}
// Check for our special key combos
if ((event->state == SDL_PRESSED) &&
(event->keysym.mod & KMOD_CTRL) &&
(event->keysym.mod & KMOD_ALT) &&
(event->keysym.mod & KMOD_SHIFT)) {
if ((event->state == true) &&
(KEY_MOD(event) & SDL_KMOD_CTRL) &&
(KEY_MOD(event) & SDL_KMOD_ALT) &&
(KEY_MOD(event) & SDL_KMOD_SHIFT)) {
// First we test the SDLK combos for matches,
// that way we ensure that latin keyboard users
// can match to the key they see on their keyboards.
@@ -172,14 +173,14 @@ void SdlInputHandler::handleKeyEvent(SDL_KeyboardEvent* event)
// the scancode of another.
for (int i = 0; i < KeyComboMax; i++) {
if (m_SpecialKeyCombos[i].enabled && event->keysym.sym == m_SpecialKeyCombos[i].keyCode) {
if (m_SpecialKeyCombos[i].enabled && KEY_KEY(event) == m_SpecialKeyCombos[i].keyCode) {
performSpecialKeyCombo(m_SpecialKeyCombos[i].keyCombo);
return;
}
}
for (int i = 0; i < KeyComboMax; i++) {
if (m_SpecialKeyCombos[i].enabled && event->keysym.scancode == m_SpecialKeyCombos[i].scanCode) {
if (m_SpecialKeyCombos[i].enabled && KEY_SCANCODE(event) == m_SpecialKeyCombos[i].scanCode) {
performSpecialKeyCombo(m_SpecialKeyCombos[i].keyCombo);
return;
}
@@ -188,16 +189,16 @@ void SdlInputHandler::handleKeyEvent(SDL_KeyboardEvent* event)
// Set modifier flags
modifiers = 0;
if (event->keysym.mod & KMOD_CTRL) {
if (KEY_MOD(event) & SDL_KMOD_CTRL) {
modifiers |= MODIFIER_CTRL;
}
if (event->keysym.mod & KMOD_ALT) {
if (KEY_MOD(event) & SDL_KMOD_ALT) {
modifiers |= MODIFIER_ALT;
}
if (event->keysym.mod & KMOD_SHIFT) {
if (KEY_MOD(event) & SDL_KMOD_SHIFT) {
modifiers |= MODIFIER_SHIFT;
}
if (event->keysym.mod & KMOD_GUI) {
if (KEY_MOD(event) & SDL_KMOD_GUI) {
if (isSystemKeyCaptureActive()) {
modifiers |= MODIFIER_META;
}
@@ -206,25 +207,25 @@ void SdlInputHandler::handleKeyEvent(SDL_KeyboardEvent* event)
// Set keycode. We explicitly use scancode here because GFE will try to correct
// for AZERTY layouts on the host but it depends on receiving VK_ values matching
// a QWERTY layout to work.
if (event->keysym.scancode >= SDL_SCANCODE_1 && event->keysym.scancode <= SDL_SCANCODE_9) {
if (KEY_SCANCODE(event) >= SDL_SCANCODE_1 && KEY_SCANCODE(event) <= SDL_SCANCODE_9) {
// SDL defines SDL_SCANCODE_0 > SDL_SCANCODE_9, so we need to handle that manually
keyCode = (event->keysym.scancode - SDL_SCANCODE_1) + VK_0 + 1;
keyCode = (KEY_SCANCODE(event) - SDL_SCANCODE_1) + VK_0 + 1;
}
else if (event->keysym.scancode >= SDL_SCANCODE_A && event->keysym.scancode <= SDL_SCANCODE_Z) {
keyCode = (event->keysym.scancode - SDL_SCANCODE_A) + VK_A;
else if (KEY_SCANCODE(event) >= SDL_SCANCODE_A && KEY_SCANCODE(event) <= SDL_SCANCODE_Z) {
keyCode = (KEY_SCANCODE(event) - SDL_SCANCODE_A) + VK_A;
}
else if (event->keysym.scancode >= SDL_SCANCODE_F1 && event->keysym.scancode <= SDL_SCANCODE_F12) {
keyCode = (event->keysym.scancode - SDL_SCANCODE_F1) + VK_F1;
else if (KEY_SCANCODE(event) >= SDL_SCANCODE_F1 && KEY_SCANCODE(event) <= SDL_SCANCODE_F12) {
keyCode = (KEY_SCANCODE(event) - SDL_SCANCODE_F1) + VK_F1;
}
else if (event->keysym.scancode >= SDL_SCANCODE_F13 && event->keysym.scancode <= SDL_SCANCODE_F24) {
keyCode = (event->keysym.scancode - SDL_SCANCODE_F13) + VK_F13;
else if (KEY_SCANCODE(event) >= SDL_SCANCODE_F13 && KEY_SCANCODE(event) <= SDL_SCANCODE_F24) {
keyCode = (KEY_SCANCODE(event) - SDL_SCANCODE_F13) + VK_F13;
}
else if (event->keysym.scancode >= SDL_SCANCODE_KP_1 && event->keysym.scancode <= SDL_SCANCODE_KP_9) {
else if (KEY_SCANCODE(event) >= SDL_SCANCODE_KP_1 && KEY_SCANCODE(event) <= SDL_SCANCODE_KP_9) {
// SDL defines SDL_SCANCODE_KP_0 > SDL_SCANCODE_KP_9, so we need to handle that manually
keyCode = (event->keysym.scancode - SDL_SCANCODE_KP_1) + VK_NUMPAD0 + 1;
keyCode = (KEY_SCANCODE(event) - SDL_SCANCODE_KP_1) + VK_NUMPAD0 + 1;
}
else {
switch (event->keysym.scancode) {
switch (KEY_SCANCODE(event)) {
case SDL_SCANCODE_BACKSPACE:
keyCode = 0x08;
break;
@@ -417,13 +418,13 @@ void SdlInputHandler::handleKeyEvent(SDL_KeyboardEvent* event)
default:
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
"Unhandled button event: %d",
event->keysym.scancode);
KEY_SCANCODE(event));
return;
}
}
// Track the key state so we always know which keys are down
if (event->state == SDL_PRESSED) {
if (event->state == true) {
m_KeysDown.insert(keyCode);
}
else {
@@ -431,7 +432,7 @@ void SdlInputHandler::handleKeyEvent(SDL_KeyboardEvent* event)
}
LiSendKeyboardEvent(0x8000 | keyCode,
event->state == SDL_PRESSED ?
KEY_ACTION_DOWN : KEY_ACTION_UP,
event->state == true ?
KEY_ACTION_DOWN : KEY_ACTION_UP,
modifiers);
}

View File

@@ -13,7 +13,7 @@ void SdlInputHandler::handleMouseButtonEvent(SDL_MouseButtonEvent* event)
return;
}
else if (!isCaptureActive()) {
if (event->button == SDL_BUTTON_LEFT && event->state == SDL_RELEASED &&
if (event->button == SDL_BUTTON_LEFT && event->state == false &&
isMouseInVideoRegion(event->x, event->y)) {
// Capture the mouse again if clicked when unbound.
// We start capture on left button released instead of
@@ -26,7 +26,7 @@ void SdlInputHandler::handleMouseButtonEvent(SDL_MouseButtonEvent* event)
// Not capturing
return;
}
else if (m_AbsoluteMouseMode && !isMouseInVideoRegion(event->x, event->y) && event->state == SDL_PRESSED) {
else if (m_AbsoluteMouseMode && !isMouseInVideoRegion(event->x, event->y) && event->state == true) {
// Ignore button presses outside the video region, but allow button releases
return;
}
@@ -62,7 +62,7 @@ void SdlInputHandler::handleMouseButtonEvent(SDL_MouseButtonEvent* event)
button = BUTTON_RIGHT;
}
LiSendMouseButtonEvent(event->state == SDL_PRESSED ?
LiSendMouseButtonEvent(event->state == true ?
BUTTON_ACTION_PRESS :
BUTTON_ACTION_RELEASE,
button);
@@ -82,7 +82,7 @@ void SdlInputHandler::handleMouseMotionEvent(SDL_MouseMotionEvent* event)
// Batch all pending mouse motion events to save CPU time
Sint32 x = event->x, y = event->y, xrel = event->xrel, yrel = event->yrel;
SDL_Event nextEvent;
while (SDL_PeepEvents(&nextEvent, 1, SDL_GETEVENT, SDL_MOUSEMOTION, SDL_MOUSEMOTION) > 0) {
while (SDL_PeepEvents(&nextEvent, 1, SDL_GETEVENT, SDL_EVENT_MOUSE_MOTION, SDL_EVENT_MOUSE_MOTION) > 0) {
event = &nextEvent.motion;
// Ignore synthetic mouse events
@@ -175,34 +175,34 @@ void SdlInputHandler::handleMouseWheelEvent(SDL_MouseWheelEvent* event)
}
#if SDL_VERSION_ATLEAST(2, 0, 18)
if (event->preciseY != 0.0f) {
if (event->y != 0.0f) {
// Invert the scroll direction if needed
if (m_ReverseScrollDirection) {
event->preciseY = -event->preciseY;
event->y = -event->y;
}
#ifdef Q_OS_DARWIN
// HACK: Clamp the scroll values on macOS to prevent OS scroll acceleration
// from generating wild scroll deltas when scrolling quickly.
event->preciseY = SDL_clamp(event->preciseY, -1.0f, 1.0f);
event->y = SDL_clamp(event->y, -1.0f, 1.0f);
#endif
LiSendHighResScrollEvent((short)(event->preciseY * 120)); // WHEEL_DELTA
LiSendHighResScrollEvent((short)(event->y * 120)); // WHEEL_DELTA
}
if (event->preciseX != 0.0f) {
if (event->x != 0.0f) {
// Invert the scroll direction if needed
if (m_ReverseScrollDirection) {
event->preciseX = -event->preciseY;
event->x = -event->y;
}
#ifdef Q_OS_DARWIN
// HACK: Clamp the scroll values on macOS to prevent OS scroll acceleration
// from generating wild scroll deltas when scrolling quickly.
event->preciseX = SDL_clamp(event->preciseX, -1.0f, 1.0f);
event->x = SDL_clamp(event->x, -1.0f, 1.0f);
#endif
LiSendHighResHScrollEvent((short)(event->preciseX * 120)); // WHEEL_DELTA
LiSendHighResHScrollEvent((short)(event->x * 120)); // WHEEL_DELTA
}
#else
if (event->y != 0) {

View File

@@ -59,9 +59,9 @@ void SdlInputHandler::handleRelativeFingerEvent(SDL_TouchFingerEvent* event)
// This is also required to handle finger up which
// where the finger will not be in SDL_GetTouchFinger()
// anymore.
if (event->type != SDL_FINGERDOWN) {
if (event->type != SDL_EVENT_FINGER_DOWN) {
for (int i = 0; i < MAX_FINGERS; i++) {
if (event->fingerId == m_TouchDownEvent[i].fingerId) {
if (event->fingerID == m_TouchDownEvent[i].fingerID) {
fingerIndex = i;
break;
}
@@ -70,12 +70,12 @@ void SdlInputHandler::handleRelativeFingerEvent(SDL_TouchFingerEvent* event)
else {
// Resolve the new finger by determining the ID of each
// finger on the display.
int numTouchFingers = SDL_GetNumTouchFingers(event->touchId);
int numTouchFingers = SDL_GetNumTouchFingers(event->touchID);
for (int i = 0; i < numTouchFingers; i++) {
SDL_Finger* finger = SDL_GetTouchFinger(event->touchId, i);
SDL_Finger* finger = SDL_GetTouchFinger(event->touchID, i);
SDL_assert(finger != nullptr);
if (finger != nullptr) {
if (finger->id == event->fingerId) {
if (finger->id == event->fingerID) {
fingerIndex = i;
break;
}
@@ -106,7 +106,7 @@ void SdlInputHandler::handleRelativeFingerEvent(SDL_TouchFingerEvent* event)
// Start a drag timer when primary or secondary
// fingers go down
if (event->type == SDL_FINGERDOWN &&
if (event->type == SDL_EVENT_FINGER_DOWN &&
(fingerIndex == 0 || fingerIndex == 1)) {
SDL_RemoveTimer(m_DragTimer);
m_DragTimer = SDL_AddTimer(DRAG_ACTIVATION_DELAY,
@@ -114,7 +114,7 @@ void SdlInputHandler::handleRelativeFingerEvent(SDL_TouchFingerEvent* event)
this);
}
if (event->type == SDL_FINGERMOTION) {
if (event->type == SDL_EVENT_FINGER_MOTION) {
// If it's outside the deadzone delta, cancel drags and taps
if (qSqrt(qPow(event->x - m_TouchDownEvent[fingerIndex].x, 2) +
qPow(event->y - m_TouchDownEvent[fingerIndex].y, 2)) > DEAD_ZONE_DELTA) {
@@ -126,7 +126,7 @@ void SdlInputHandler::handleRelativeFingerEvent(SDL_TouchFingerEvent* event)
}
}
if (event->type == SDL_FINGERUP) {
if (event->type == SDL_EVENT_FINGER_UP) {
// Cancel the drag timer on finger up
SDL_RemoveTimer(m_DragTimer);
m_DragTimer = 0;
@@ -164,12 +164,12 @@ void SdlInputHandler::handleRelativeFingerEvent(SDL_TouchFingerEvent* event)
}
}
m_NumFingersDown = SDL_GetNumTouchFingers(event->touchId);
m_NumFingersDown = SDL_GetNumTouchFingers(event->touchID);
if (event->type == SDL_FINGERDOWN) {
if (event->type == SDL_EVENT_FINGER_DOWN) {
m_TouchDownEvent[fingerIndex] = *event;
}
else if (event->type == SDL_FINGERUP) {
else if (event->type == SDL_EVENT_FINGER_UP) {
m_TouchDownEvent[fingerIndex] = {};
}
}