citra-qt: release all buttons when render window focus is lost

credit to @Hawkheart for the original idea
This commit is contained in:
wwylele 2017-03-17 21:41:25 +02:00
parent 423ab5e2bc
commit 5245c86f26
4 changed files with 20 additions and 0 deletions

View file

@ -235,6 +235,11 @@ void GRenderWindow::mouseReleaseEvent(QMouseEvent* event) {
motion_emu->EndTilt();
}
void GRenderWindow::focusOutEvent(QFocusEvent* event) {
QWidget::focusOutEvent(event);
InputCommon::GetKeyboard()->ReleaseAllKeys();
}
void GRenderWindow::ReloadSetKeymaps() {}
void GRenderWindow::OnClientAreaResized(unsigned width, unsigned height) {

View file

@ -128,6 +128,8 @@ public:
void mouseMoveEvent(QMouseEvent* event) override;
void mouseReleaseEvent(QMouseEvent* event) override;
void focusOutEvent(QFocusEvent* event) override;
void ReloadSetKeymaps();
void OnClientAreaResized(unsigned width, unsigned height);

View file

@ -53,6 +53,13 @@ public:
}
}
void ChangeAllKeyStatus(bool pressed) {
std::lock_guard<std::mutex> guard(mutex);
for (const KeyButtonPair& pair : list) {
pair.key_button->status.store(pressed);
}
}
private:
std::mutex mutex;
std::list<KeyButtonPair> list;
@ -79,4 +86,8 @@ void Keyboard::ReleaseKey(int key_code) {
key_button_list->ChangeKeyStatus(key_code, false);
}
void Keyboard::ReleaseAllKeys() {
key_button_list->ChangeAllKeyStatus(false);
}
} // namespace InputCommon

View file

@ -38,6 +38,8 @@ public:
*/
void ReleaseKey(int key_code);
void ReleaseAllKeys();
private:
std::shared_ptr<KeyButtonList> key_button_list;
};