Skip to content

Commit

Permalink
Merge pull request #18786 from hrydgard/release-inputs-on-pause
Browse files Browse the repository at this point in the history
Release all keys on pause.
  • Loading branch information
hrydgard committed Jan 29, 2024
2 parents 26b5652 + 7920d3a commit cf1fd71
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
36 changes: 36 additions & 0 deletions Core/ControlMapper.cpp
Expand Up @@ -231,6 +231,42 @@ void ControlMapper::ForceReleaseVKey(int vkey) {
KeyMap::UnlockMappings();
}

void ControlMapper::ReleaseAll() {
std::vector<AxisInput> axes;
std::vector<KeyInput> keys;

{
std::lock_guard<std::mutex> guard(mutex_);

for (const auto &input : curInput_) {
if (input.first.IsAxis()) {
if (input.second.value != 0.0f) {
AxisInput axis;
axis.deviceId = input.first.deviceId;
int dir;
axis.axisId = (InputAxis)input.first.Axis(&dir);
axis.value = 0.0;
axes.push_back(axis);
}
} else {
if (input.second.value != 0.0) {
KeyInput key;
key.deviceId = input.first.deviceId;
key.flags = KEY_UP;
key.keyCode = (InputKeyCode)input.first.keyCode;
keys.push_back(key);
}
}
}
}

Axis(axes.data(), axes.size());;
for (const auto &key : keys) {
Key(key, nullptr);
}
}


static int RotatePSPKeyCode(int x) {
switch (x) {
case CTRL_UP: return CTRL_RIGHT;
Expand Down
3 changes: 3 additions & 0 deletions Core/ControlMapper.h
Expand Up @@ -40,6 +40,9 @@ class ControlMapper {
// Might replace this later by allowing through "key-up" and similar events to lower screens.
void ForceReleaseVKey(int vkey);

// Call when the emu screen gets pushed behind some other screen, like the pause screen, to release all "down" inputs.
void ReleaseAll();

void GetDebugString(char *buffer, size_t bufSize) const;

struct InputSample {
Expand Down
1 change: 1 addition & 0 deletions UI/EmuScreen.cpp
Expand Up @@ -496,6 +496,7 @@ void EmuScreen::focusChanged(ScreenFocusChange focusChange) {
switch (focusChange) {
case ScreenFocusChange::FOCUS_LOST_TOP:
g_Config.TimeTracker().Stop(gameID);
controlMapper_.ReleaseAll();
break;
case ScreenFocusChange::FOCUS_BECAME_TOP:
g_Config.TimeTracker().Start(gameID);
Expand Down

0 comments on commit cf1fd71

Please sign in to comment.