From 53c2c612c9e06a84b4d8fcac56181a64e1fa8154 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sat, 14 Oct 2023 01:46:50 -0500 Subject: [PATCH] Add Share+PS combo for clickpad button emulation on PS4/5 controllers --- app/streaming/input/gamepad.cpp | 24 +++++++++++++++++++++++- app/streaming/input/input.h | 3 +++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/app/streaming/input/gamepad.cpp b/app/streaming/input/gamepad.cpp index 80529717..ba255c2e 100644 --- a/app/streaming/input/gamepad.cpp +++ b/app/streaming/input/gamepad.cpp @@ -54,9 +54,23 @@ SdlInputHandler::findStateForGamepad(SDL_JoystickID id) void SdlInputHandler::sendGamepadState(GamepadState* state) { SDL_assert(m_GamepadMask == 0x1 || m_MultiController); + + // Handle Select+PS as the clickpad button on PS4/5 controllers without a clickpad mapping + int buttons = state->buttons; + if (state->clickpadButtonEmulationEnabled) { + if (state->buttons == (BACK_FLAG | SPECIAL_FLAG)) { + buttons = MISC_FLAG; + state->emulatedClickpadButtonDown = true; + } + else if (state->emulatedClickpadButtonDown) { + buttons &= ~MISC_FLAG; + state->emulatedClickpadButtonDown = false; + } + } + LiSendMultiControllerEvent(state->index, m_GamepadMask, - state->buttons, + buttons, state->lt, state->rt, state->lsX, @@ -639,6 +653,14 @@ void SdlInputHandler::handleControllerDeviceEvent(SDL_ControllerDeviceEvent* eve break; } + // If this is a PlayStation controller that doesn't have a touchpad button mapped, + // 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 && +#endif + type == LI_CTYPE_PS; + LiSendControllerArrivalEvent(state->index, m_GamepadMask, type, supportedButtonFlags, capabilities); #else diff --git a/app/streaming/input/input.h b/app/streaming/input/input.h index 65bd4f9a..ec24070a 100644 --- a/app/streaming/input/input.h +++ b/app/streaming/input/input.h @@ -19,6 +19,9 @@ struct GamepadState { SDL_TimerID mouseEmulationTimer; uint32_t lastStartDownTime; + bool clickpadButtonEmulationEnabled; + bool emulatedClickpadButtonDown; + #if SDL_VERSION_ATLEAST(2, 0, 14) uint8_t gyroReportPeriodMs; float lastGyroEventData[SDL_arraysize(SDL_ControllerSensorEvent::data)];