From 582b409f7f91cb79538eb411e4ac8fa97c5f1c6a Mon Sep 17 00:00:00 2001 From: Andrew Lanzone Date: Tue, 29 Jul 2025 19:29:20 -0700 Subject: [PATCH] Fix right stick from causing mouse to appear in controller mode --- apps/openmw/mwgui/windowbase.hpp | 2 +- apps/openmw/mwinput/controllermanager.cpp | 23 +++++++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/apps/openmw/mwgui/windowbase.hpp b/apps/openmw/mwgui/windowbase.hpp index c1f1b827a6..5a84db4a5c 100644 --- a/apps/openmw/mwgui/windowbase.hpp +++ b/apps/openmw/mwgui/windowbase.hpp @@ -82,7 +82,7 @@ namespace MWGui MyGUI::Widget* getControllerScrollWidget() { return mControllerScrollWidget; } bool isGamepadCursorAllowed() { return !mDisableGamepadCursor; } virtual bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) { return true; } - virtual bool onControllerThumbstickEvent(const SDL_ControllerAxisEvent& arg) { return true; } + virtual bool onControllerThumbstickEvent(const SDL_ControllerAxisEvent& arg) { return false; } virtual void setActiveControllerWindow(bool active) { mActiveControllerWindow = active; } protected: diff --git a/apps/openmw/mwinput/controllermanager.cpp b/apps/openmw/mwinput/controllermanager.cpp index 3b352decfc..c31fd0f3a5 100644 --- a/apps/openmw/mwinput/controllermanager.cpp +++ b/apps/openmw/mwinput/controllermanager.cpp @@ -221,7 +221,8 @@ namespace MWInput mJoystickLastUsed = true; if (MWBase::Environment::get().getWindowManager()->isGuiMode()) { - gamepadToGuiControl(arg); + if (gamepadToGuiControl(arg)) + return; } else if (mBindingsManager->actionIsActive(A_TogglePOV) && (arg.axis == SDL_CONTROLLER_AXIS_TRIGGERRIGHT || arg.axis == SDL_CONTROLLER_AXIS_TRIGGERLEFT)) @@ -354,6 +355,7 @@ namespace MWInput MWGui::WindowBase* topWin = winMgr->getActiveControllerWindow(); if (topWin) { + bool isPastDeadzone = std::abs(arg.value) > 2000; // Update cursor state mGamepadGuiCursorEnabled = topWin->isGamepadCursorAllowed(); if (!mGamepadGuiCursorEnabled) @@ -363,23 +365,36 @@ namespace MWInput && (arg.axis == SDL_CONTROLLER_AXIS_LEFTX || arg.axis == SDL_CONTROLLER_AXIS_LEFTY)) { // Treat the left stick like a cursor, which is the default behavior. - if (winMgr->getControllerTooltip() && std::abs(arg.value) > 2000) + if (isPastDeadzone && winMgr->getControllerTooltip()) { winMgr->setControllerTooltip(false); winMgr->setCursorVisible(true); } + else if (isPastDeadzone && mGamepadGuiCursorEnabled) + { + winMgr->setCursorVisible(true); + } return false; } - // On some windows, treat right stick like a scroll wheel. - if (arg.axis == SDL_CONTROLLER_AXIS_RIGHTY && topWin->getControllerScrollWidget() != nullptr) + // Some windows have a specific widget to scroll with the right stick. Move the mouse there. + if (arg.axis == SDL_CONTROLLER_AXIS_RIGHTY && isPastDeadzone + && topWin->getControllerScrollWidget() != nullptr) + { mMouseManager->warpMouseToWidget(topWin->getControllerScrollWidget()); + winMgr->setCursorVisible(false); + } if (topWin->onControllerThumbstickEvent(arg)) { // Window handled the event. return true; } + else if (arg.axis == SDL_CONTROLLER_AXIS_RIGHTX || arg.axis == SDL_CONTROLLER_AXIS_RIGHTY) + { + // Only right-stick scroll if mouse is visible or there's a widget to scroll. + return !winMgr->getCursorVisible() && topWin->getControllerScrollWidget() == nullptr; + } } }