Skip to content

SDL: Fix bug where the mouse got stuck in relative mode when mapping mouse inputs #20612

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Common/Input/InputState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ const char *GetDeviceName(int deviceId) {
}
}

bool g_IsMappingMouseInput;

std::vector<InputMapping> dpadKeys;
std::vector<InputMapping> confirmKeys;
std::vector<InputMapping> cancelKeys;
Expand Down
3 changes: 3 additions & 0 deletions Common/Input/InputState.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,6 @@ void SetInfoKeys(const std::vector<InputMapping> &info);
// 0 means unknown (attempt autodetect), -1 means flip, 1 means original direction.
void SetAnalogFlipY(const std::unordered_map<InputDeviceID, int> &flipYByDeviceId);
int GetAnalogYDirection(InputDeviceID deviceId);

// Gross hack unfortunately.
extern bool g_IsMappingMouseInput;
1 change: 0 additions & 1 deletion Core/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,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),
Expand Down
1 change: 0 additions & 1 deletion Core/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,6 @@ struct Config {
bool bStrictComboOrder;

bool bMouseControl;
bool bMapMouse; // Workaround for mapping screen:|
bool bMouseConfine; // Trap inside the window.
float fMouseSensitivity;
float fMouseSmoothing;
Expand Down
2 changes: 1 addition & 1 deletion SDL/SDLMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,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)
Expand Down
12 changes: 7 additions & 5 deletions UI/ControlMappingScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 &params) {
Expand All @@ -219,7 +221,7 @@ UI::EventReturn SingleControlMapper::OnAdd(UI::EventParams &params) {
}
UI::EventReturn SingleControlMapper::OnAddMouse(UI::EventParams &params) {
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;
}
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions UI/ControlMappingScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ class KeyMappingNewMouseKeyDialog : public PopupScreen {
public:
KeyMappingNewMouseKeyDialog(int btn, bool replace, std::function<void(KeyMap::MultiInputMapping)> callback, I18NCat i18n)
: PopupScreen(T(i18n, "Map Mouse"), "", ""), callback_(callback) {}
~KeyMappingNewMouseKeyDialog() {
g_IsMappingMouseInput = false;
}

const char *tag() const override { return "KeyMappingNewMouseKey"; }

Expand Down
2 changes: 1 addition & 1 deletion UI/NativeApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1448,7 +1448,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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion Windows/RawInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,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]];
Expand Down
Loading