From 511f8fdcadec9fac32b74110af754d0cba9b14f2 Mon Sep 17 00:00:00 2001 From: Rosalie Wanders Date: Thu, 9 Oct 2025 22:46:44 +0200 Subject: [PATCH] RMG-Input: make fix for stuck buttons more robust --- .../UserInterface/Widget/ControllerWidget.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/Source/RMG-Input/UserInterface/Widget/ControllerWidget.cpp b/Source/RMG-Input/UserInterface/Widget/ControllerWidget.cpp index 9deed8b7..4ed1f516 100644 --- a/Source/RMG-Input/UserInterface/Widget/ControllerWidget.cpp +++ b/Source/RMG-Input/UserInterface/Widget/ControllerWidget.cpp @@ -1326,7 +1326,7 @@ void ControllerWidget::on_MainDialog_SdlEvent(SDL_Event* event) // more than 50%, otherwise we might detect // an accidental axis movement (due to i.e deadzone) const bool sdlAxisButtonPressed = (abs(sdlAxisValue) >= (SDL_AXIS_PEAK / 2)); - int sdlAxisDirection = (sdlAxisValue >= 0 ? 1 : 0); + int sdlAxisDirection = (sdlAxisValue > 0 ? 1 : 0); // make sure we have the right joystick if (joystickId != this->currentJoystickId) @@ -1361,12 +1361,23 @@ void ControllerWidget::on_MainDialog_SdlEvent(SDL_Event* event) break; } - // update controller button state + // update controller button state, + // we have to loop over each possible direction, + // then ensure the opposite direction is disabled + // because an axis can only be at one direction + // at a given time + const int directions[] = + { + 0, 1 + }; for (auto& button : this->buttonWidgetMappings) { - if (button.buttonWidget->HasInputData(inputType, sdlAxis, sdlAxisDirection)) + for (int direction : directions) { - this->controllerImageWidget->SetButtonState(button.button, sdlAxisButtonPressed); + if (button.buttonWidget->HasInputData(inputType, sdlAxis, direction)) + { + this->controllerImageWidget->SetButtonState(button.button, (direction == sdlAxisDirection && sdlAxisButtonPressed)); + } } }