Skip to content

Commit d35f1c6

Browse files
committed
gui: lock mouse only when mouse axis/button is bound
1 parent 709c21f commit d35f1c6

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

src/platform/windows/input/sdl_input_manager.cpp

+21-5
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void SdlInputManager::vibrationThreadFunc() {
4646
}
4747

4848
void SdlInputManager::onVibrationEvent(Event::Controller::Vibration e) {
49-
// Vibration output is choosen by DPAD_UP mapped game controller
49+
// Vibration output is chosen by DPAD_UP mapped game controller
5050
std::string keyName = config.controller[e.port - 1].keys["dpad_up"];
5151
Key key(keyName);
5252

@@ -62,6 +62,18 @@ void SdlInputManager::onVibrationEvent(Event::Controller::Vibration e) {
6262
}
6363
}
6464

65+
bool SdlInputManager::isMouseBound() {
66+
// Check if mouse axis is bound anywhere
67+
for (auto& c : config.controller) {
68+
for (auto& k : c.keys) {
69+
if (k.second.rfind("mouse", 0) == 0) {
70+
return true;
71+
}
72+
}
73+
}
74+
return false;
75+
}
76+
6577
bool SdlInputManager::handleKey(Key key, AnalogValue value) {
6678
if (waitingForKeyPress) {
6779
waitingForKeyPress = false;
@@ -104,6 +116,12 @@ void SdlInputManager::newFrame() {
104116
mouseX = 0;
105117
mouseY = 0;
106118

119+
#ifdef ANDROID
120+
shouldCaptureMouse = false;
121+
#else
122+
shouldCaptureMouse = isMouseBound();
123+
#endif
124+
107125
if (waitingForKeyPress) return;
108126

109127
Key key;
@@ -126,10 +144,8 @@ bool SdlInputManager::handleEvent(SDL_Event& event) {
126144
auto type = event.type;
127145

128146
if ((!mouseCaptured || waitingForKeyPress) && event.type == SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_LEFT
129-
&& event.button.clicks == 2) {
130-
#ifndef ANDROID
147+
&& event.button.clicks == 2 && shouldCaptureMouse) {
131148
mouseLocked = true;
132-
#endif
133149
return true;
134150
}
135151

@@ -235,4 +251,4 @@ bool SdlInputManager::handleEvent(SDL_Event& event) {
235251
}
236252

237253
return false;
238-
}
254+
}

src/platform/windows/input/sdl_input_manager.h

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class SdlInputManager : public InputManager {
1313
std::unordered_map<int, SDL_GameController*> controllers;
1414
int32_t mouseX = 0; // Track mouse movement in frame
1515
int32_t mouseY = 0;
16+
bool shouldCaptureMouse = false;
1617

1718
bool handleKey(Key key, AnalogValue value);
1819
void fixControllerId(SDL_Event& event);
@@ -32,6 +33,8 @@ class SdlInputManager : public InputManager {
3233
void vibrationThreadFunc();
3334
void onVibrationEvent(Event::Controller::Vibration e);
3435

36+
bool isMouseBound();
37+
3538
public:
3639
bool mouseCaptured = false;
3740
bool keyboardCaptured = false;

0 commit comments

Comments
 (0)