all repos — mgba @ 9c5852a896f042222d6e411dd39a65b3ea58ce40

mGBA Game Boy Advance Emulator

Qt: Added a setting for pausing when the emulator is not in focus
Jeffrey Pfau jeffrey@endrift.com
Mon, 11 Jan 2016 01:11:58 -0800
commit

9c5852a896f042222d6e411dd39a65b3ea58ce40

parent

2b5da04d9c5acf7ac152c903ac73d229ae79d343

M CHANGESCHANGES

@@ -16,6 +16,7 @@ - Libretro: Settings for using BIOS and skipping intro

- 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
M src/platform/qt/SettingsView.cppsrc/platform/qt/SettingsView.cpp

@@ -39,6 +39,7 @@ loadSetting("rewindBufferCapacity", m_ui.rewindCapacity);

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 @@ saveSetting("rewindBufferCapacity", m_ui.rewindCapacity);

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");
M src/platform/qt/SettingsView.uisrc/platform/qt/SettingsView.ui

@@ -7,7 +7,7 @@ <rect>

<x>0</x> <y>0</y> <width>417</width> - <height>457</height> + <height>478</height> </rect> </property> <property name="sizePolicy">

@@ -493,14 +493,14 @@ <bool>true</bool>

</property> </widget> </item> - <item row="13" column="0"> + <item row="14" column="0"> <widget class="QLabel" name="label_15"> <property name="text"> <string>Idle loops</string> </property> </widget> </item> - <item row="13" column="1"> + <item row="14" column="1"> <widget class="QComboBox" name="idleOptimization"> <item> <property name="text">

@@ -544,6 +544,13 @@ <item row="10" column="0" colspan="2">

<widget class="Line" name="line_3"> <property name="orientation"> <enum>Qt::Horizontal</enum> + </property> + </widget> + </item> + <item row="13" column="1"> + <widget class="QCheckBox" name="pauseOnFocusLost"> + <property name="text"> + <string>Pause when inactive</string> </property> </widget> </item>
M src/platform/qt/Window.cppsrc/platform/qt/Window.cpp

@@ -72,6 +72,7 @@ , m_mruMenu(nullptr)

, m_shortcutController(new ShortcutController(this)) , m_playerId(playerId) , m_fullscreenOnStart(false) + , m_autoresume(false) { setFocusPolicy(Qt::StrongFocus); setAcceptDrops(true);

@@ -140,6 +141,7 @@ connect(this, SIGNAL(audioBufferSamplesChanged(int)), m_controller, SLOT(setAudioBufferSamples(int)));

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<QStackedLayout*>(m_screenWidget->layout())->currentWidget() == m_display) { m_screenWidget->setCursor(Qt::BlankCursor);

@@ -152,6 +154,7 @@ connect(&m_inputController, SIGNAL(profileLoaded(const QString&)), m_shortcutController, SLOT(loadProfile(const QString&)));

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 @@ #endif

m_hitUnimplementedBiosCall = false; m_fpsTimer.start(); + m_focusCheck.start(); } void Window::gameStopped() {

@@ -618,6 +622,7 @@ m_screenWidget->setPixmap(m_logo);

m_screenWidget->unsetCursor(); m_fpsTimer.stop(); + m_focusCheck.stop(); } void Window::gameCrashed(const QString& errorMessage) {

@@ -1352,6 +1357,18 @@ m_shortcutController->addAction(menu, action, name);

action->setShortcutContext(Qt::WidgetShortcut); addAction(action); 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)
M src/platform/qt/Window.hsrc/platform/qt/Window.h

@@ -123,6 +123,7 @@ void mustRestart();

void recordFrame(); void showFPS(); + void focusCheck(); private: static const int FPS_TIMER_INTERVAL = 2000;

@@ -164,6 +165,8 @@ ShortcutController* m_shortcutController;

ShaderSelector* m_shaderView; int m_playerId; bool m_fullscreenOnStart; + QTimer m_focusCheck; + bool m_autoresume; bool m_hitUnimplementedBiosCall;