Better dead zone handling

This commit is contained in:
Andrew Lanzone 2025-08-02 09:00:59 -07:00
parent 2e5836a748
commit 3147aea0ed
2 changed files with 8 additions and 7 deletions

View File

@ -511,8 +511,7 @@ namespace MWGui
{ {
if (arg.axis == SDL_CONTROLLER_AXIS_RIGHTX) if (arg.axis == SDL_CONTROLLER_AXIS_RIGHTX)
{ {
if (arg.value < -1000 || arg.value > 1000) onPreviewScroll(nullptr, arg.value < 0 ? 1 : -1);
onPreviewScroll(nullptr, arg.value < 0 ? 1 : -1);
return true; return true;
} }

View File

@ -355,22 +355,25 @@ namespace MWInput
MWGui::WindowBase* topWin = winMgr->getActiveControllerWindow(); MWGui::WindowBase* topWin = winMgr->getActiveControllerWindow();
if (topWin) if (topWin)
{ {
bool isPastDeadzone = std::abs(arg.value) > 2000;
// Update cursor state // Update cursor state
mGamepadGuiCursorEnabled = topWin->isGamepadCursorAllowed(); mGamepadGuiCursorEnabled = topWin->isGamepadCursorAllowed();
if (!mGamepadGuiCursorEnabled) if (!mGamepadGuiCursorEnabled)
winMgr->setCursorActive(false); winMgr->setCursorActive(false);
// Deadzone check
if (std::abs(arg.value) < 2000)
return !mGamepadGuiCursorEnabled;
if (mGamepadGuiCursorEnabled if (mGamepadGuiCursorEnabled
&& (arg.axis == SDL_CONTROLLER_AXIS_LEFTX || arg.axis == SDL_CONTROLLER_AXIS_LEFTY)) && (arg.axis == SDL_CONTROLLER_AXIS_LEFTX || arg.axis == SDL_CONTROLLER_AXIS_LEFTY))
{ {
// Treat the left stick like a cursor, which is the default behavior. // Treat the left stick like a cursor, which is the default behavior.
if (isPastDeadzone && winMgr->getControllerTooltip()) if (winMgr->getControllerTooltip())
{ {
winMgr->setControllerTooltip(false); winMgr->setControllerTooltip(false);
winMgr->setCursorVisible(true); winMgr->setCursorVisible(true);
} }
else if (isPastDeadzone && mGamepadGuiCursorEnabled) else if (mGamepadGuiCursorEnabled)
{ {
winMgr->setCursorVisible(true); winMgr->setCursorVisible(true);
} }
@ -378,8 +381,7 @@ namespace MWInput
} }
// Some windows have a specific widget to scroll with the right stick. Move the mouse there. // Some windows have a specific widget to scroll with the right stick. Move the mouse there.
if (arg.axis == SDL_CONTROLLER_AXIS_RIGHTY && isPastDeadzone if (arg.axis == SDL_CONTROLLER_AXIS_RIGHTY && topWin->getControllerScrollWidget() != nullptr)
&& topWin->getControllerScrollWidget() != nullptr)
{ {
mMouseManager->warpMouseToWidget(topWin->getControllerScrollWidget()); mMouseManager->warpMouseToWidget(topWin->getControllerScrollWidget());
winMgr->setCursorVisible(false); winMgr->setCursorVisible(false);