Skip to content

Commit 791aee6

Browse files
authored
Merge pull request #20612 from hrydgard/mouse-mapping-fix
SDL: Fix bug where the mouse got stuck in relative mode when mapping mouse inputs
2 parents 5072f19 + 263d0b3 commit 791aee6

File tree

9 files changed

+18
-10
lines changed

9 files changed

+18
-10
lines changed

Common/Input/InputState.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ const char *GetDeviceName(int deviceId) {
3333
}
3434
}
3535

36+
bool g_IsMappingMouseInput;
37+
3638
std::vector<InputMapping> dpadKeys;
3739
std::vector<InputMapping> confirmKeys;
3840
std::vector<InputMapping> cancelKeys;

Common/Input/InputState.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,3 +211,6 @@ void SetInfoKeys(const std::vector<InputMapping> &info);
211211
// 0 means unknown (attempt autodetect), -1 means flip, 1 means original direction.
212212
void SetAnalogFlipY(const std::unordered_map<InputDeviceID, int> &flipYByDeviceId);
213213
int GetAnalogYDirection(InputDeviceID deviceId);
214+
215+
// Gross hack unfortunately.
216+
extern bool g_IsMappingMouseInput;

Core/Config.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,6 @@ static const ConfigSetting controlSettings[] = {
936936
ConfigSetting("HideStickBackground", &g_Config.bHideStickBackground, false, CfgFlag::PER_GAME),
937937

938938
ConfigSetting("UseMouse", &g_Config.bMouseControl, false, CfgFlag::PER_GAME),
939-
ConfigSetting("MapMouse", &g_Config.bMapMouse, false, CfgFlag::PER_GAME),
940939
ConfigSetting("ConfineMap", &g_Config.bMouseConfine, false, CfgFlag::PER_GAME),
941940
ConfigSetting("MouseSensitivity", &g_Config.fMouseSensitivity, 0.1f, CfgFlag::PER_GAME),
942941
ConfigSetting("MouseSmoothing", &g_Config.fMouseSmoothing, 0.9f, CfgFlag::PER_GAME),

Core/Config.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,6 @@ struct Config {
450450
bool bStrictComboOrder;
451451

452452
bool bMouseControl;
453-
bool bMapMouse; // Workaround for mapping screen:|
454453
bool bMouseConfine; // Trap inside the window.
455454
float fMouseSensitivity;
456455
float fMouseSmoothing;

SDL/SDLMain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,7 @@ static void EmuThreadJoin() {
887887

888888
struct InputStateTracker {
889889
void MouseCaptureControl() {
890-
bool captureMouseCondition = g_Config.bMouseControl && ((GetUIState() == UISTATE_INGAME && g_Config.bMouseConfine) || g_Config.bMapMouse);
890+
bool captureMouseCondition = g_Config.bMouseControl && ((GetUIState() == UISTATE_INGAME && g_Config.bMouseConfine) || g_IsMappingMouseInput);
891891
if (mouseCaptured != captureMouseCondition) {
892892
mouseCaptured = captureMouseCondition;
893893
if (captureMouseCondition)

UI/ControlMappingScreen.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ using KeyMap::MultiInputMapping;
5757
class SingleControlMapper : public UI::LinearLayout {
5858
public:
5959
SingleControlMapper(int pspKey, std::string keyName, ScreenManager *scrm, UI::LinearLayoutParams *layoutParams = nullptr);
60-
60+
~SingleControlMapper() {
61+
g_IsMappingMouseInput = false;
62+
}
6163
int GetPspKey() const { return pspKey_; }
6264

6365
private:
@@ -196,7 +198,7 @@ void SingleControlMapper::MappedCallback(const MultiInputMapping &kdf) {
196198
break;
197199
}
198200
KeyMap::UpdateNativeMenuKeys();
199-
g_Config.bMapMouse = false;
201+
g_IsMappingMouseInput = false;
200202
}
201203

202204
UI::EventReturn SingleControlMapper::OnReplace(UI::EventParams &params) {
@@ -219,7 +221,7 @@ UI::EventReturn SingleControlMapper::OnAdd(UI::EventParams &params) {
219221
}
220222
UI::EventReturn SingleControlMapper::OnAddMouse(UI::EventParams &params) {
221223
action_ = ADD;
222-
g_Config.bMapMouse = true;
224+
g_IsMappingMouseInput = true;
223225
scrm_->push(new KeyMappingNewMouseKeyDialog(pspKey_, true, std::bind(&SingleControlMapper::MappedCallback, this, std::placeholders::_1), I18NCat::KEYMAPPING));
224226
return UI::EVENT_DONE;
225227
}
@@ -430,14 +432,14 @@ bool KeyMappingNewMouseKeyDialog::key(const KeyInput &key) {
430432
if (key.flags & KEY_DOWN) {
431433
if (key.keyCode == NKCODE_ESCAPE) {
432434
TriggerFinish(DR_OK);
433-
g_Config.bMapMouse = false;
435+
g_IsMappingMouseInput = false;
434436
return false;
435437
}
436438

437439
mapped_ = true;
438440

439441
TriggerFinish(DR_YES);
440-
g_Config.bMapMouse = false;
442+
g_IsMappingMouseInput = false;
441443
if (callback_) {
442444
MultiInputMapping kdf(InputMapping(key.deviceId, key.keyCode));
443445
callback_(kdf);

UI/ControlMappingScreen.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ class KeyMappingNewMouseKeyDialog : public PopupScreen {
9797
public:
9898
KeyMappingNewMouseKeyDialog(int btn, bool replace, std::function<void(KeyMap::MultiInputMapping)> callback, I18NCat i18n)
9999
: PopupScreen(T(i18n, "Map Mouse"), "", ""), callback_(callback) {}
100+
~KeyMappingNewMouseKeyDialog() {
101+
g_IsMappingMouseInput = false;
102+
}
100103

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

UI/NativeApp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1448,7 +1448,7 @@ static void SendMouseDeltaAxis() {
14481448
//NOTICE_LOG(Log::System, "delta: %0.2f %0.2f mx/my: %0.2f %0.2f dpi: %f sens: %f ",
14491449
// g_mouseDeltaX, g_mouseDeltaY, mx, my, g_display.dpi_scale_x, g_Config.fMouseSensitivity);
14501450

1451-
if (GetUIState() == UISTATE_INGAME || g_Config.bMapMouse) {
1451+
if (GetUIState() == UISTATE_INGAME || g_IsMappingMouseInput) {
14521452
NativeAxis(axis, 2);
14531453
}
14541454
}

Windows/RawInput.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ namespace WindowsRawInput {
340340
};
341341

342342
for (int i = 0; i < 5; i++) {
343-
if (i > 0 || (g_Config.bMouseControl && (GetUIState() == UISTATE_INGAME || g_Config.bMapMouse))) {
343+
if (i > 0 || (g_Config.bMouseControl && (GetUIState() == UISTATE_INGAME || g_IsMappingMouseInput))) {
344344
if (raw->data.mouse.usButtonFlags & rawInputDownID[i]) {
345345
key.flags = KEY_DOWN;
346346
key.keyCode = windowsTransTable[vkInputID[i]];

0 commit comments

Comments
 (0)