Qt: Added a setting for pausing when the emulator is not in focus

This commit is contained in:
Jeffrey Pfau 2016-01-11 01:11:58 -08:00
parent 2b5da04d9c
commit 9c5852a896
5 changed files with 33 additions and 3 deletions

View File

@ -16,6 +16,7 @@ Features:
- Libretro: Customizable idle loop removal - Libretro: Customizable idle loop removal
- Implemented cycle counting for sprite rendering - Implemented cycle counting for sprite rendering
- Cleaner, unified settings window - Cleaner, unified settings window
- Added a setting for pausing when the emulator is not in focus
Bugfixes: Bugfixes:
- Util: Fix PowerPC PNG read/write pixel order - Util: Fix PowerPC PNG read/write pixel order
- VFS: Fix VFileReadline and remove _vfdReadline - VFS: Fix VFileReadline and remove _vfdReadline

View File

@ -39,6 +39,7 @@ SettingsView::SettingsView(ConfigController* controller, InputController* inputC
loadSetting("resampleVideo", m_ui.resampleVideo); loadSetting("resampleVideo", m_ui.resampleVideo);
loadSetting("allowOpposingDirections", m_ui.allowOpposingDirections); loadSetting("allowOpposingDirections", m_ui.allowOpposingDirections);
loadSetting("suspendScreensaver", m_ui.suspendScreensaver); loadSetting("suspendScreensaver", m_ui.suspendScreensaver);
loadSetting("pauseOnFocusLost", m_ui.pauseOnFocusLost);
double fastForwardRatio = loadSetting("fastForwardRatio").toDouble(); double fastForwardRatio = loadSetting("fastForwardRatio").toDouble();
if (fastForwardRatio <= 0) { if (fastForwardRatio <= 0) {
@ -142,6 +143,7 @@ void SettingsView::updateConfig() {
saveSetting("resampleVideo", m_ui.resampleVideo); saveSetting("resampleVideo", m_ui.resampleVideo);
saveSetting("allowOpposingDirections", m_ui.allowOpposingDirections); saveSetting("allowOpposingDirections", m_ui.allowOpposingDirections);
saveSetting("suspendScreensaver", m_ui.suspendScreensaver); saveSetting("suspendScreensaver", m_ui.suspendScreensaver);
saveSetting("pauseOnFocusLost", m_ui.pauseOnFocusLost);
if (m_ui.fastForwardUnbounded->isChecked()) { if (m_ui.fastForwardUnbounded->isChecked()) {
saveSetting("fastForwardRatio", "-1"); saveSetting("fastForwardRatio", "-1");

View File

@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>417</width> <width>417</width>
<height>457</height> <height>478</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
@ -493,14 +493,14 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="13" column="0"> <item row="14" column="0">
<widget class="QLabel" name="label_15"> <widget class="QLabel" name="label_15">
<property name="text"> <property name="text">
<string>Idle loops</string> <string>Idle loops</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="13" column="1"> <item row="14" column="1">
<widget class="QComboBox" name="idleOptimization"> <widget class="QComboBox" name="idleOptimization">
<item> <item>
<property name="text"> <property name="text">
@ -547,6 +547,13 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="13" column="1">
<widget class="QCheckBox" name="pauseOnFocusLost">
<property name="text">
<string>Pause when inactive</string>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</widget> </widget>

View File

@ -72,6 +72,7 @@ Window::Window(ConfigController* config, int playerId, QWidget* parent)
, m_shortcutController(new ShortcutController(this)) , m_shortcutController(new ShortcutController(this))
, m_playerId(playerId) , m_playerId(playerId)
, m_fullscreenOnStart(false) , m_fullscreenOnStart(false)
, m_autoresume(false)
{ {
setFocusPolicy(Qt::StrongFocus); setFocusPolicy(Qt::StrongFocus);
setAcceptDrops(true); 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(sampleRateChanged(unsigned)), m_controller, SLOT(setAudioSampleRate(unsigned)));
connect(this, SIGNAL(fpsTargetChanged(float)), m_controller, SLOT(setFPSTarget(float))); connect(this, SIGNAL(fpsTargetChanged(float)), m_controller, SLOT(setFPSTarget(float)));
connect(&m_fpsTimer, SIGNAL(timeout()), this, SLOT(showFPS())); connect(&m_fpsTimer, SIGNAL(timeout()), this, SLOT(showFPS()));
connect(&m_focusCheck, SIGNAL(timeout()), this, SLOT(focusCheck()));
connect(m_display, &Display::hideCursor, [this]() { connect(m_display, &Display::hideCursor, [this]() {
if (static_cast<QStackedLayout*>(m_screenWidget->layout())->currentWidget() == m_display) { if (static_cast<QStackedLayout*>(m_screenWidget->layout())->currentWidget() == m_display) {
m_screenWidget->setCursor(Qt::BlankCursor); 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_log.setLevels(GBA_LOG_WARN | GBA_LOG_ERROR | GBA_LOG_FATAL | GBA_LOG_STATUS);
m_fpsTimer.setInterval(FPS_TIMER_INTERVAL); m_fpsTimer.setInterval(FPS_TIMER_INTERVAL);
m_focusCheck.setInterval(200);
m_shortcutController->setConfigController(m_config); m_shortcutController->setConfigController(m_config);
setupMenu(menuBar()); setupMenu(menuBar());
@ -604,6 +607,7 @@ void Window::gameStarted(GBAThread* context) {
m_hitUnimplementedBiosCall = false; m_hitUnimplementedBiosCall = false;
m_fpsTimer.start(); m_fpsTimer.start();
m_focusCheck.start();
} }
void Window::gameStopped() { void Window::gameStopped() {
@ -618,6 +622,7 @@ void Window::gameStopped() {
m_screenWidget->unsetCursor(); m_screenWidget->unsetCursor();
m_fpsTimer.stop(); m_fpsTimer.stop();
m_focusCheck.stop();
} }
void Window::gameCrashed(const QString& errorMessage) { void Window::gameCrashed(const QString& errorMessage) {
@ -1354,6 +1359,18 @@ QAction* Window::addHiddenAction(QMenu* menu, QAction* action, const QString& na
return 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) WindowBackground::WindowBackground(QWidget* parent)
: QLabel(parent) : QLabel(parent)
{ {

View File

@ -123,6 +123,7 @@ private slots:
void recordFrame(); void recordFrame();
void showFPS(); void showFPS();
void focusCheck();
private: private:
static const int FPS_TIMER_INTERVAL = 2000; static const int FPS_TIMER_INTERVAL = 2000;
@ -164,6 +165,8 @@ private:
ShaderSelector* m_shaderView; ShaderSelector* m_shaderView;
int m_playerId; int m_playerId;
bool m_fullscreenOnStart; bool m_fullscreenOnStart;
QTimer m_focusCheck;
bool m_autoresume;
bool m_hitUnimplementedBiosCall; bool m_hitUnimplementedBiosCall;