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.value < -1000 || arg.value > 1000)
onPreviewScroll(nullptr, arg.value < 0 ? 1 : -1);
onPreviewScroll(nullptr, arg.value < 0 ? 1 : -1);
return true;
}

View File

@ -355,22 +355,25 @@ namespace MWInput
MWGui::WindowBase* topWin = winMgr->getActiveControllerWindow();
if (topWin)
{
bool isPastDeadzone = std::abs(arg.value) > 2000;
// Update cursor state
mGamepadGuiCursorEnabled = topWin->isGamepadCursorAllowed();
if (!mGamepadGuiCursorEnabled)
winMgr->setCursorActive(false);
// Deadzone check
if (std::abs(arg.value) < 2000)
return !mGamepadGuiCursorEnabled;
if (mGamepadGuiCursorEnabled
&& (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 (isPastDeadzone && winMgr->getControllerTooltip())
if (winMgr->getControllerTooltip())
{
winMgr->setControllerTooltip(false);
winMgr->setCursorVisible(true);
}
else if (isPastDeadzone && mGamepadGuiCursorEnabled)
else if (mGamepadGuiCursorEnabled)
{
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.
if (arg.axis == SDL_CONTROLLER_AXIS_RIGHTY && isPastDeadzone
&& topWin->getControllerScrollWidget() != nullptr)
if (arg.axis == SDL_CONTROLLER_AXIS_RIGHTY && topWin->getControllerScrollWidget() != nullptr)
{
mMouseManager->warpMouseToWidget(topWin->getControllerScrollWidget());
winMgr->setCursorVisible(false);