From 9c5852a896f042222d6e411dd39a65b3ea58ce40 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Mon, 11 Jan 2016 01:11:58 -0800 Subject: [PATCH] Qt: Added a setting for pausing when the emulator is not in focus --- CHANGES | 1 + src/platform/qt/SettingsView.cpp | 2 ++ src/platform/qt/SettingsView.ui | 13 ++++++++++--- src/platform/qt/Window.cpp | 17 +++++++++++++++++ src/platform/qt/Window.h | 3 +++ 5 files changed, 33 insertions(+), 3 deletions(-) diff --git a/CHANGES b/CHANGES index 60cb54149..6404363a1 100644 --- a/CHANGES +++ b/CHANGES @@ -16,6 +16,7 @@ Features: - Libretro: Customizable idle loop removal - Implemented cycle counting for sprite rendering - Cleaner, unified settings window + - Added a setting for pausing when the emulator is not in focus Bugfixes: - Util: Fix PowerPC PNG read/write pixel order - VFS: Fix VFileReadline and remove _vfdReadline diff --git a/src/platform/qt/SettingsView.cpp b/src/platform/qt/SettingsView.cpp index 8737d92f5..e5110f7e4 100644 --- a/src/platform/qt/SettingsView.cpp +++ b/src/platform/qt/SettingsView.cpp @@ -39,6 +39,7 @@ SettingsView::SettingsView(ConfigController* controller, InputController* inputC loadSetting("resampleVideo", m_ui.resampleVideo); loadSetting("allowOpposingDirections", m_ui.allowOpposingDirections); loadSetting("suspendScreensaver", m_ui.suspendScreensaver); + loadSetting("pauseOnFocusLost", m_ui.pauseOnFocusLost); double fastForwardRatio = loadSetting("fastForwardRatio").toDouble(); if (fastForwardRatio <= 0) { @@ -142,6 +143,7 @@ void SettingsView::updateConfig() { saveSetting("resampleVideo", m_ui.resampleVideo); saveSetting("allowOpposingDirections", m_ui.allowOpposingDirections); saveSetting("suspendScreensaver", m_ui.suspendScreensaver); + saveSetting("pauseOnFocusLost", m_ui.pauseOnFocusLost); if (m_ui.fastForwardUnbounded->isChecked()) { saveSetting("fastForwardRatio", "-1"); diff --git a/src/platform/qt/SettingsView.ui b/src/platform/qt/SettingsView.ui index 33ca8fa89..1e5088096 100644 --- a/src/platform/qt/SettingsView.ui +++ b/src/platform/qt/SettingsView.ui @@ -7,7 +7,7 @@ 0 0 417 - 457 + 478 @@ -493,14 +493,14 @@ - + Idle loops - + @@ -547,6 +547,13 @@ + + + + Pause when inactive + + + diff --git a/src/platform/qt/Window.cpp b/src/platform/qt/Window.cpp index 5d6f3a53b..0bdfbeb21 100644 --- a/src/platform/qt/Window.cpp +++ b/src/platform/qt/Window.cpp @@ -72,6 +72,7 @@ Window::Window(ConfigController* config, int playerId, QWidget* parent) , m_shortcutController(new ShortcutController(this)) , m_playerId(playerId) , m_fullscreenOnStart(false) + , m_autoresume(false) { setFocusPolicy(Qt::StrongFocus); setAcceptDrops(true); @@ -140,6 +141,7 @@ Window::Window(ConfigController* config, int playerId, QWidget* parent) connect(this, SIGNAL(sampleRateChanged(unsigned)), m_controller, SLOT(setAudioSampleRate(unsigned))); connect(this, SIGNAL(fpsTargetChanged(float)), m_controller, SLOT(setFPSTarget(float))); connect(&m_fpsTimer, SIGNAL(timeout()), this, SLOT(showFPS())); + connect(&m_focusCheck, SIGNAL(timeout()), this, SLOT(focusCheck())); connect(m_display, &Display::hideCursor, [this]() { if (static_cast(m_screenWidget->layout())->currentWidget() == m_display) { m_screenWidget->setCursor(Qt::BlankCursor); @@ -152,6 +154,7 @@ Window::Window(ConfigController* config, int playerId, QWidget* parent) m_log.setLevels(GBA_LOG_WARN | GBA_LOG_ERROR | GBA_LOG_FATAL | GBA_LOG_STATUS); m_fpsTimer.setInterval(FPS_TIMER_INTERVAL); + m_focusCheck.setInterval(200); m_shortcutController->setConfigController(m_config); setupMenu(menuBar()); @@ -604,6 +607,7 @@ void Window::gameStarted(GBAThread* context) { m_hitUnimplementedBiosCall = false; m_fpsTimer.start(); + m_focusCheck.start(); } void Window::gameStopped() { @@ -618,6 +622,7 @@ void Window::gameStopped() { m_screenWidget->unsetCursor(); m_fpsTimer.stop(); + m_focusCheck.stop(); } void Window::gameCrashed(const QString& errorMessage) { @@ -1354,6 +1359,18 @@ QAction* Window::addHiddenAction(QMenu* menu, QAction* action, const QString& na return action; } +void Window::focusCheck() { + if (!m_config->getOption("pauseOnFocusLost").toInt()) { + return; + } + if (QGuiApplication::focusWindow() && m_autoresume) { + m_controller->setPaused(false); + } else if (!QGuiApplication::focusWindow() && !m_controller->isPaused()) { + m_autoresume = true; + m_controller->setPaused(true); + } +} + WindowBackground::WindowBackground(QWidget* parent) : QLabel(parent) { diff --git a/src/platform/qt/Window.h b/src/platform/qt/Window.h index ab0d7e99e..c13c8d941 100644 --- a/src/platform/qt/Window.h +++ b/src/platform/qt/Window.h @@ -123,6 +123,7 @@ private slots: void recordFrame(); void showFPS(); + void focusCheck(); private: static const int FPS_TIMER_INTERVAL = 2000; @@ -164,6 +165,8 @@ private: ShaderSelector* m_shaderView; int m_playerId; bool m_fullscreenOnStart; + QTimer m_focusCheck; + bool m_autoresume; bool m_hitUnimplementedBiosCall;