From 1cfb9522a338661bb72e45af40792688522485ba Mon Sep 17 00:00:00 2001 From: Kelvin Oliveira Date: Sat, 10 Oct 2026 14:20:34 -0300 Subject: [PATCH] controller: use Back as the touchpad click on pads without a touchpad (#1355) * controller: use Back as the touchpad click on pads without a touchpad Gamepads without a touchpad (Switch, Xbox, 8BitDo, ...) cannot click it, so games that require the touchpad can't be played with them. The keyboard already emulates it (Backspace/Tab); gamepads had nothing. For SDL_GAMEPAD_BUTTON_BACK on a pad that reports no touchpads, report PAD_BUTTON_TOUCH_PAD plus a finger at the centre of the touchpad. Pads with a real touchpad are unchanged. Fixes #1298 * controller: establish touch before fallback click --------- Co-authored-by: nmzik --- src/graphics/presentation/window/window.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/graphics/presentation/window/window.cpp b/src/graphics/presentation/window/window.cpp index 1a1f366cf..a68e22342 100644 --- a/src/graphics/presentation/window/window.cpp +++ b/src/graphics/presentation/window/window.cpp @@ -326,6 +326,19 @@ static void GameEventController([[maybe_unused]] const EventController& f) { const auto button = ControllerButtonToPadButton(f.button); if (button != 0) { Controller::SetButton(f.id, button, f.down); + } else if (f.button == SDL_GAMEPAD_BUTTON_BACK) { + // Pads without a touchpad (Switch, Xbox, ...) have no way to click it, which + // blocks games that require it. Use their Back/Select button as a centered click. + auto* pad = SDL_GetGamepadFromID(f.id); + if (pad != nullptr && SDL_GetNumGamepadTouchpads(pad) == 0) { + if (f.down) { + Controller::SetTouchPad(f.id, 0, true, 0.5f, 0.5f); + } + Controller::SetButton(f.id, Controller::PAD_BUTTON_TOUCH_PAD, f.down); + if (f.up) { + Controller::SetTouchPad(f.id, 0, false, 0.5f, 0.5f); + } + } } }