From e64114f6a6a6fec5838391acfd7a17021d92586d Mon Sep 17 00:00:00 2001 From: LittleWhite Date: Sat, 12 Mar 2016 12:38:22 +0100 Subject: [PATCH] Set pause when emulator lost focus --- src/citra_qt/bootmanager.cpp | 9 +++++++++ src/citra_qt/bootmanager.h | 16 ++++++++++++++++ src/citra_qt/config.cpp | 2 ++ src/citra_qt/configure_general.cpp | 2 ++ src/citra_qt/configure_general.ui | 7 +++++++ src/citra_qt/main.cpp | 7 ++++++- src/citra_qt/ui_settings.h | 1 + 7 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/citra_qt/bootmanager.cpp b/src/citra_qt/bootmanager.cpp index 414b2f8af..55a30d839 100644 --- a/src/citra_qt/bootmanager.cpp +++ b/src/citra_qt/bootmanager.cpp @@ -9,6 +9,7 @@ #endif #include "citra_qt/bootmanager.h" +#include "citra_qt/ui_settings.h" #include "common/key_map.h" #include "common/microprofile.h" @@ -285,6 +286,14 @@ void GRenderWindow::OnMinimalClientAreaChangeRequest(const std::pairemu_thread = emu_thread; child->DisablePainting(); diff --git a/src/citra_qt/bootmanager.h b/src/citra_qt/bootmanager.h index 0dcf3e5eb..c6113837e 100644 --- a/src/citra_qt/bootmanager.h +++ b/src/citra_qt/bootmanager.h @@ -136,10 +136,26 @@ public slots: signals: /// Emitted when the window is closed void Closed(); + /// Emitted when the window got focus + void gotFocus(); + /// Emitted when the window lost focus + void lostFocus(); private: void OnMinimalClientAreaChangeRequest(const std::pair& minimal_size) override; + /** + * Capture focus gain to unset pause + * @param event + */ + void focusInEvent(QFocusEvent*) override; + + /** + * Capture focus lost to set pause + * @param event + */ + void focusOutEvent(QFocusEvent*) override; + GGLWidgetInternal* child; QByteArray geometry; diff --git a/src/citra_qt/config.cpp b/src/citra_qt/config.cpp index 0e5f285c0..48fb636ed 100644 --- a/src/citra_qt/config.cpp +++ b/src/citra_qt/config.cpp @@ -116,6 +116,7 @@ void Config::ReadValues() { UISettings::values.single_window_mode = qt_config->value("singleWindowMode", true).toBool(); UISettings::values.display_titlebar = qt_config->value("displayTitleBars", true).toBool(); + UISettings::values.pause_onfocuslost = qt_config->value("pauseOnFocusLost",false).toBool(); UISettings::values.confirm_before_closing = qt_config->value("confirmClose",true).toBool(); UISettings::values.first_start = qt_config->value("firstStart", true).toBool(); @@ -196,6 +197,7 @@ void Config::SaveValues() { qt_config->setValue("singleWindowMode", UISettings::values.single_window_mode); qt_config->setValue("displayTitleBars", UISettings::values.display_titlebar); + qt_config->setValue("pauseOnFocusLost", UISettings::values.pause_onfocuslost); qt_config->setValue("confirmClose", UISettings::values.confirm_before_closing); qt_config->setValue("firstStart", UISettings::values.first_start); diff --git a/src/citra_qt/configure_general.cpp b/src/citra_qt/configure_general.cpp index 62648e665..2e11a3a62 100644 --- a/src/citra_qt/configure_general.cpp +++ b/src/citra_qt/configure_general.cpp @@ -21,6 +21,7 @@ ConfigureGeneral::~ConfigureGeneral() { void ConfigureGeneral::setConfiguration() { ui->toogle_deepscan->setChecked(UISettings::values.gamedir_deepscan); + ui->toogle_pause_onfocuslost->setChecked(UISettings::values.pause_onfocuslost); ui->toogle_check_exit->setChecked(UISettings::values.confirm_before_closing); ui->region_combobox->setCurrentIndex(Settings::values.region_value); ui->toogle_hw_renderer->setChecked(Settings::values.use_hw_renderer); @@ -30,6 +31,7 @@ void ConfigureGeneral::setConfiguration() { void ConfigureGeneral::applyConfiguration() { UISettings::values.gamedir_deepscan = ui->toogle_deepscan->isChecked(); + UISettings::values.pause_onfocuslost = ui->toogle_pause_onfocuslost->isChecked(); UISettings::values.confirm_before_closing = ui->toogle_check_exit->isChecked(); Settings::values.region_value = ui->region_combobox->currentIndex(); Settings::values.use_hw_renderer = ui->toogle_hw_renderer->isChecked(); diff --git a/src/citra_qt/configure_general.ui b/src/citra_qt/configure_general.ui index 5eb309793..b7996cc31 100644 --- a/src/citra_qt/configure_general.ui +++ b/src/citra_qt/configure_general.ui @@ -31,6 +31,13 @@ + + + + Pause on focus lost + + + diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp index 68a936087..a59553e40 100644 --- a/src/citra_qt/main.cpp +++ b/src/citra_qt/main.cpp @@ -186,6 +186,8 @@ GMainWindow::GMainWindow() : config(new Config()), emu_thread(nullptr) connect(this, SIGNAL(EmulationStarting(EmuThread*)), graphicsTracingWidget, SLOT(OnEmulationStarting(EmuThread*))); connect(this, SIGNAL(EmulationStopping()), graphicsTracingWidget, SLOT(OnEmulationStopping())); + connect(render_window, SIGNAL(gotFocus()), this, SLOT(OnStartGame())); + connect(render_window, SIGNAL(lostFocus()), this, SLOT(OnPauseGame())); // Setup hotkeys RegisterHotkey("Main Window", "Load File", QKeySequence::Open); @@ -468,6 +470,8 @@ void GMainWindow::OnStartGame() { ui.action_Pause->setEnabled(true); ui.action_Stop->setEnabled(true); + + render_window->setFocus(); } void GMainWindow::OnPauseGame() { @@ -487,7 +491,7 @@ void GMainWindow::ToggleWindowMode() { // Render in the main window... render_window->BackupGeometry(); ui.horizontalLayout->addWidget(render_window); - render_window->setFocusPolicy(Qt::ClickFocus); + render_window->setFocusPolicy(Qt::StrongFocus); if (emulation_running) { render_window->setVisible(true); render_window->setFocus(); @@ -505,6 +509,7 @@ void GMainWindow::ToggleWindowMode() { game_list->show(); } } + render_window->setFocus(); } void GMainWindow::OnConfigure() { diff --git a/src/citra_qt/ui_settings.h b/src/citra_qt/ui_settings.h index 62db4a73e..c5ca32595 100644 --- a/src/citra_qt/ui_settings.h +++ b/src/citra_qt/ui_settings.h @@ -29,6 +29,7 @@ struct Values { bool single_window_mode; bool display_titlebar; + bool pause_onfocuslost; bool confirm_before_closing; bool first_start;