Set pause when emulator lost focus

This commit is contained in:
LittleWhite 2016-03-12 12:38:22 +01:00 committed by Alexandre LittleWhite Laurent
parent 3c3a6cb2af
commit e64114f6a6
7 changed files with 43 additions and 1 deletions

View File

@ -9,6 +9,7 @@
#endif #endif
#include "citra_qt/bootmanager.h" #include "citra_qt/bootmanager.h"
#include "citra_qt/ui_settings.h"
#include "common/key_map.h" #include "common/key_map.h"
#include "common/microprofile.h" #include "common/microprofile.h"
@ -285,6 +286,14 @@ void GRenderWindow::OnMinimalClientAreaChangeRequest(const std::pair<unsigned,un
setMinimumSize(minimal_size.first, minimal_size.second); setMinimumSize(minimal_size.first, minimal_size.second);
} }
void GRenderWindow::focusInEvent(QFocusEvent*) {
if (emu_thread && UISettings::values.pause_onfocuslost) emit gotFocus();
}
void GRenderWindow::focusOutEvent(QFocusEvent*) {
if (emu_thread && UISettings::values.pause_onfocuslost) emit lostFocus();
}
void GRenderWindow::OnEmulationStarting(EmuThread* emu_thread) { void GRenderWindow::OnEmulationStarting(EmuThread* emu_thread) {
this->emu_thread = emu_thread; this->emu_thread = emu_thread;
child->DisablePainting(); child->DisablePainting();

View File

@ -136,10 +136,26 @@ public slots:
signals: signals:
/// Emitted when the window is closed /// Emitted when the window is closed
void Closed(); void Closed();
/// Emitted when the window got focus
void gotFocus();
/// Emitted when the window lost focus
void lostFocus();
private: private:
void OnMinimalClientAreaChangeRequest(const std::pair<unsigned,unsigned>& minimal_size) override; void OnMinimalClientAreaChangeRequest(const std::pair<unsigned,unsigned>& 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; GGLWidgetInternal* child;
QByteArray geometry; QByteArray geometry;

View File

@ -116,6 +116,7 @@ void Config::ReadValues() {
UISettings::values.single_window_mode = qt_config->value("singleWindowMode", true).toBool(); UISettings::values.single_window_mode = qt_config->value("singleWindowMode", true).toBool();
UISettings::values.display_titlebar = qt_config->value("displayTitleBars", 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.confirm_before_closing = qt_config->value("confirmClose",true).toBool();
UISettings::values.first_start = qt_config->value("firstStart", 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("singleWindowMode", UISettings::values.single_window_mode);
qt_config->setValue("displayTitleBars", UISettings::values.display_titlebar); 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("confirmClose", UISettings::values.confirm_before_closing);
qt_config->setValue("firstStart", UISettings::values.first_start); qt_config->setValue("firstStart", UISettings::values.first_start);

View File

@ -21,6 +21,7 @@ ConfigureGeneral::~ConfigureGeneral() {
void ConfigureGeneral::setConfiguration() { void ConfigureGeneral::setConfiguration() {
ui->toogle_deepscan->setChecked(UISettings::values.gamedir_deepscan); 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->toogle_check_exit->setChecked(UISettings::values.confirm_before_closing);
ui->region_combobox->setCurrentIndex(Settings::values.region_value); ui->region_combobox->setCurrentIndex(Settings::values.region_value);
ui->toogle_hw_renderer->setChecked(Settings::values.use_hw_renderer); ui->toogle_hw_renderer->setChecked(Settings::values.use_hw_renderer);
@ -30,6 +31,7 @@ void ConfigureGeneral::setConfiguration() {
void ConfigureGeneral::applyConfiguration() { void ConfigureGeneral::applyConfiguration() {
UISettings::values.gamedir_deepscan = ui->toogle_deepscan->isChecked(); 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(); UISettings::values.confirm_before_closing = ui->toogle_check_exit->isChecked();
Settings::values.region_value = ui->region_combobox->currentIndex(); Settings::values.region_value = ui->region_combobox->currentIndex();
Settings::values.use_hw_renderer = ui->toogle_hw_renderer->isChecked(); Settings::values.use_hw_renderer = ui->toogle_hw_renderer->isChecked();

View File

@ -31,6 +31,13 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QCheckBox" name="toogle_pause_onfocuslost">
<property name="text">
<string>Pause on focus lost</string>
</property>
</widget>
</item>
<item> <item>
<widget class="QCheckBox" name="toogle_check_exit"> <widget class="QCheckBox" name="toogle_check_exit">
<property name="text"> <property name="text">

View File

@ -186,6 +186,8 @@ GMainWindow::GMainWindow() : config(new Config()), emu_thread(nullptr)
connect(this, SIGNAL(EmulationStarting(EmuThread*)), graphicsTracingWidget, SLOT(OnEmulationStarting(EmuThread*))); connect(this, SIGNAL(EmulationStarting(EmuThread*)), graphicsTracingWidget, SLOT(OnEmulationStarting(EmuThread*)));
connect(this, SIGNAL(EmulationStopping()), graphicsTracingWidget, SLOT(OnEmulationStopping())); 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 // Setup hotkeys
RegisterHotkey("Main Window", "Load File", QKeySequence::Open); RegisterHotkey("Main Window", "Load File", QKeySequence::Open);
@ -468,6 +470,8 @@ void GMainWindow::OnStartGame() {
ui.action_Pause->setEnabled(true); ui.action_Pause->setEnabled(true);
ui.action_Stop->setEnabled(true); ui.action_Stop->setEnabled(true);
render_window->setFocus();
} }
void GMainWindow::OnPauseGame() { void GMainWindow::OnPauseGame() {
@ -487,7 +491,7 @@ void GMainWindow::ToggleWindowMode() {
// Render in the main window... // Render in the main window...
render_window->BackupGeometry(); render_window->BackupGeometry();
ui.horizontalLayout->addWidget(render_window); ui.horizontalLayout->addWidget(render_window);
render_window->setFocusPolicy(Qt::ClickFocus); render_window->setFocusPolicy(Qt::StrongFocus);
if (emulation_running) { if (emulation_running) {
render_window->setVisible(true); render_window->setVisible(true);
render_window->setFocus(); render_window->setFocus();
@ -505,6 +509,7 @@ void GMainWindow::ToggleWindowMode() {
game_list->show(); game_list->show();
} }
} }
render_window->setFocus();
} }
void GMainWindow::OnConfigure() { void GMainWindow::OnConfigure() {

View File

@ -29,6 +29,7 @@ struct Values {
bool single_window_mode; bool single_window_mode;
bool display_titlebar; bool display_titlebar;
bool pause_onfocuslost;
bool confirm_before_closing; bool confirm_before_closing;
bool first_start; bool first_start;