From 447d57634c281b63cf2df3704b3f07da42e406c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 10 Jul 2025 20:49:26 +0200 Subject: [PATCH] Merge pull request #20612 from hrydgard/mouse-mapping-fix SDL: Fix bug where the mouse got stuck in relative mode when mapping mouse inputs --- Common/Input/InputState.cpp | 2 ++ Common/Input/InputState.h | 3 +++ Core/Config.cpp | 1 - Core/Config.h | 1 - SDL/SDLMain.cpp | 2 +- UI/ControlMappingScreen.cpp | 12 +++++++----- UI/ControlMappingScreen.h | 3 +++ UI/NativeApp.cpp | 2 +- Windows/RawInput.cpp | 2 +- 9 files changed, 18 insertions(+), 10 deletions(-) diff --git a/Common/Input/InputState.cpp b/Common/Input/InputState.cpp index 1586bedce0..9e7ad463ca 100644 --- a/Common/Input/InputState.cpp +++ b/Common/Input/InputState.cpp @@ -33,6 +33,8 @@ const char *GetDeviceName(int deviceId) { } } +bool g_IsMappingMouseInput; + std::vector dpadKeys; std::vector confirmKeys; std::vector cancelKeys; diff --git a/Common/Input/InputState.h b/Common/Input/InputState.h index d476498211..4d4dfe7e35 100644 --- a/Common/Input/InputState.h +++ b/Common/Input/InputState.h @@ -211,3 +211,6 @@ void SetInfoKeys(const std::vector &info); // 0 means unknown (attempt autodetect), -1 means flip, 1 means original direction. void SetAnalogFlipY(const std::unordered_map &flipYByDeviceId); int GetAnalogYDirection(InputDeviceID deviceId); + +// Gross hack unfortunately. +extern bool g_IsMappingMouseInput; diff --git a/Core/Config.cpp b/Core/Config.cpp index 840986788e..e492fb6c46 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -942,7 +942,6 @@ static const ConfigSetting controlSettings[] = { ConfigSetting("HideStickBackground", &g_Config.bHideStickBackground, false, CfgFlag::PER_GAME), ConfigSetting("UseMouse", &g_Config.bMouseControl, false, CfgFlag::PER_GAME), - ConfigSetting("MapMouse", &g_Config.bMapMouse, false, CfgFlag::PER_GAME), ConfigSetting("ConfineMap", &g_Config.bMouseConfine, false, CfgFlag::PER_GAME), ConfigSetting("MouseSensitivity", &g_Config.fMouseSensitivity, 0.1f, CfgFlag::PER_GAME), ConfigSetting("MouseSmoothing", &g_Config.fMouseSmoothing, 0.9f, CfgFlag::PER_GAME), diff --git a/Core/Config.h b/Core/Config.h index 8a9f5cf097..b3d32bfcf1 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -451,7 +451,6 @@ public: bool bStrictComboOrder; bool bMouseControl; - bool bMapMouse; // Workaround for mapping screen:| bool bMouseConfine; // Trap inside the window. float fMouseSensitivity; float fMouseSmoothing; diff --git a/SDL/SDLMain.cpp b/SDL/SDLMain.cpp index 7a2d836c07..50e53393cf 100644 --- a/SDL/SDLMain.cpp +++ b/SDL/SDLMain.cpp @@ -881,7 +881,7 @@ static void EmuThreadJoin() { struct InputStateTracker { void MouseCaptureControl() { - bool captureMouseCondition = g_Config.bMouseControl && ((GetUIState() == UISTATE_INGAME && g_Config.bMouseConfine) || g_Config.bMapMouse); + bool captureMouseCondition = g_Config.bMouseControl && ((GetUIState() == UISTATE_INGAME && g_Config.bMouseConfine) || g_IsMappingMouseInput); if (mouseCaptured != captureMouseCondition) { mouseCaptured = captureMouseCondition; if (captureMouseCondition) diff --git a/UI/ControlMappingScreen.cpp b/UI/ControlMappingScreen.cpp index acd1abcffe..842e894f6f 100644 --- a/UI/ControlMappingScreen.cpp +++ b/UI/ControlMappingScreen.cpp @@ -57,7 +57,9 @@ using KeyMap::MultiInputMapping; class SingleControlMapper : public UI::LinearLayout { public: SingleControlMapper(int pspKey, std::string keyName, ScreenManager *scrm, UI::LinearLayoutParams *layoutParams = nullptr); - + ~SingleControlMapper() { + g_IsMappingMouseInput = false; + } int GetPspKey() const { return pspKey_; } private: @@ -196,7 +198,7 @@ void SingleControlMapper::MappedCallback(const MultiInputMapping &kdf) { break; } KeyMap::UpdateNativeMenuKeys(); - g_Config.bMapMouse = false; + g_IsMappingMouseInput = false; } UI::EventReturn SingleControlMapper::OnReplace(UI::EventParams ¶ms) { @@ -219,7 +221,7 @@ UI::EventReturn SingleControlMapper::OnAdd(UI::EventParams ¶ms) { } UI::EventReturn SingleControlMapper::OnAddMouse(UI::EventParams ¶ms) { action_ = ADD; - g_Config.bMapMouse = true; + g_IsMappingMouseInput = true; scrm_->push(new KeyMappingNewMouseKeyDialog(pspKey_, true, std::bind(&SingleControlMapper::MappedCallback, this, std::placeholders::_1), I18NCat::KEYMAPPING)); return UI::EVENT_DONE; } @@ -430,14 +432,14 @@ bool KeyMappingNewMouseKeyDialog::key(const KeyInput &key) { if (key.flags & KEY_DOWN) { if (key.keyCode == NKCODE_ESCAPE) { TriggerFinish(DR_OK); - g_Config.bMapMouse = false; + g_IsMappingMouseInput = false; return false; } mapped_ = true; TriggerFinish(DR_YES); - g_Config.bMapMouse = false; + g_IsMappingMouseInput = false; if (callback_) { MultiInputMapping kdf(InputMapping(key.deviceId, key.keyCode)); callback_(kdf); diff --git a/UI/ControlMappingScreen.h b/UI/ControlMappingScreen.h index 8820cc727b..ce373aabaf 100644 --- a/UI/ControlMappingScreen.h +++ b/UI/ControlMappingScreen.h @@ -97,6 +97,9 @@ class KeyMappingNewMouseKeyDialog : public PopupScreen { public: KeyMappingNewMouseKeyDialog(int btn, bool replace, std::function callback, I18NCat i18n) : PopupScreen(T(i18n, "Map Mouse"), "", ""), callback_(callback) {} + ~KeyMappingNewMouseKeyDialog() { + g_IsMappingMouseInput = false; + } const char *tag() const override { return "KeyMappingNewMouseKey"; } diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index e99cfc4ca1..67231f2d5f 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -1420,7 +1420,7 @@ static void SendMouseDeltaAxis() { //NOTICE_LOG(Log::System, "delta: %0.2f %0.2f mx/my: %0.2f %0.2f dpi: %f sens: %f ", // g_mouseDeltaX, g_mouseDeltaY, mx, my, g_display.dpi_scale_x, g_Config.fMouseSensitivity); - if (GetUIState() == UISTATE_INGAME || g_Config.bMapMouse) { + if (GetUIState() == UISTATE_INGAME || g_IsMappingMouseInput) { NativeAxis(axis, 2); } } diff --git a/Windows/RawInput.cpp b/Windows/RawInput.cpp index 21082ae555..a565ea4b28 100644 --- a/Windows/RawInput.cpp +++ b/Windows/RawInput.cpp @@ -341,7 +341,7 @@ namespace WindowsRawInput { }; for (int i = 0; i < 5; i++) { - if (i > 0 || (g_Config.bMouseControl && (GetUIState() == UISTATE_INGAME || g_Config.bMapMouse))) { + if (i > 0 || (g_Config.bMouseControl && (GetUIState() == UISTATE_INGAME || g_IsMappingMouseInput))) { if (raw->data.mouse.usButtonFlags & rawInputDownID[i]) { key.flags = KEY_DOWN; key.keyCode = windowsTransTable[vkInputID[i]];