Skip to content
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

Release all keys on pause. #18786

Merged
merged 1 commit into from
Jan 29, 2024
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
36 changes: 36 additions & 0 deletions Core/ControlMapper.cpp
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading