From 5245c86f2662caa0e1e4b20508608b11237993b3 Mon Sep 17 00:00:00 2001 From: wwylele Date: Fri, 17 Mar 2017 21:41:25 +0200 Subject: [PATCH 1/2] citra-qt: release all buttons when render window focus is lost credit to @Hawkheart for the original idea --- src/citra_qt/bootmanager.cpp | 5 +++++ src/citra_qt/bootmanager.h | 2 ++ src/input_common/keyboard.cpp | 11 +++++++++++ src/input_common/keyboard.h | 2 ++ 4 files changed, 20 insertions(+) diff --git a/src/citra_qt/bootmanager.cpp b/src/citra_qt/bootmanager.cpp index 28264df9a..e212433d9 100644 --- a/src/citra_qt/bootmanager.cpp +++ b/src/citra_qt/bootmanager.cpp @@ -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) { diff --git a/src/citra_qt/bootmanager.h b/src/citra_qt/bootmanager.h index 923a5b456..d1c00fc18 100644 --- a/src/citra_qt/bootmanager.h +++ b/src/citra_qt/bootmanager.h @@ -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); diff --git a/src/input_common/keyboard.cpp b/src/input_common/keyboard.cpp index a8fc01f2e..0f0d10f23 100644 --- a/src/input_common/keyboard.cpp +++ b/src/input_common/keyboard.cpp @@ -53,6 +53,13 @@ public: } } + void ChangeAllKeyStatus(bool pressed) { + std::lock_guard guard(mutex); + for (const KeyButtonPair& pair : list) { + pair.key_button->status.store(pressed); + } + } + private: std::mutex mutex; std::list 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 diff --git a/src/input_common/keyboard.h b/src/input_common/keyboard.h index 76359aa30..861950472 100644 --- a/src/input_common/keyboard.h +++ b/src/input_common/keyboard.h @@ -38,6 +38,8 @@ public: */ void ReleaseKey(int key_code); + void ReleaseAllKeys(); + private: std::shared_ptr key_button_list; }; From 560884336f706846545cd4c3243002ccb03cfe6d Mon Sep 17 00:00:00 2001 From: wwylele Date: Fri, 17 Mar 2017 21:45:29 +0200 Subject: [PATCH 2/2] citra-qt: remove dead code --- src/citra_qt/bootmanager.cpp | 2 -- src/citra_qt/bootmanager.h | 2 -- src/citra_qt/main.cpp | 1 - 3 files changed, 5 deletions(-) diff --git a/src/citra_qt/bootmanager.cpp b/src/citra_qt/bootmanager.cpp index e212433d9..bae576d6a 100644 --- a/src/citra_qt/bootmanager.cpp +++ b/src/citra_qt/bootmanager.cpp @@ -240,8 +240,6 @@ void GRenderWindow::focusOutEvent(QFocusEvent* event) { InputCommon::GetKeyboard()->ReleaseAllKeys(); } -void GRenderWindow::ReloadSetKeymaps() {} - void GRenderWindow::OnClientAreaResized(unsigned width, unsigned height) { NotifyClientAreaSizeChanged(std::make_pair(width, height)); } diff --git a/src/citra_qt/bootmanager.h b/src/citra_qt/bootmanager.h index d1c00fc18..9d39f1af8 100644 --- a/src/citra_qt/bootmanager.h +++ b/src/citra_qt/bootmanager.h @@ -130,8 +130,6 @@ public: void focusOutEvent(QFocusEvent* event) override; - void ReloadSetKeymaps(); - void OnClientAreaResized(unsigned width, unsigned height); void InitRenderTarget(); diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp index fd51659b9..2723a0217 100644 --- a/src/citra_qt/main.cpp +++ b/src/citra_qt/main.cpp @@ -612,7 +612,6 @@ void GMainWindow::OnConfigure() { auto result = configureDialog.exec(); if (result == QDialog::Accepted) { configureDialog.applyConfiguration(); - render_window->ReloadSetKeymaps(); config->Save(); } }