Qt: Add option to pause on minimizing window (closes #1379)

This commit is contained in:
Vicki Pfau 2019-06-18 11:14:05 -07:00
parent a9e96c7d00
commit ecc6141c67
5 changed files with 39 additions and 8 deletions

View File

@ -55,6 +55,7 @@ Misc:
- Vita: L2/R2 and L3/R3 can now be mapped on PSTV (fixes mgba.io/i/1292)
- mGUI: Remember name and position of last loaded game
- Core: Create game-related paths if they don't exist (fixes mgba.io/i/1446)
- Qt: Add option to pause on minimizing window (closes mgba.io/i/1379)
0.7.2: (2019-05-25)
Emulation fixes:

View File

@ -387,6 +387,7 @@ void SettingsView::updateConfig() {
saveSetting("allowOpposingDirections", m_ui.allowOpposingDirections);
saveSetting("suspendScreensaver", m_ui.suspendScreensaver);
saveSetting("pauseOnFocusLost", m_ui.pauseOnFocusLost);
saveSetting("pauseOnMinimize", m_ui.pauseOnMinimize);
saveSetting("savegamePath", m_ui.savegamePath);
saveSetting("savestatePath", m_ui.savestatePath);
saveSetting("screenshotPath", m_ui.screenshotPath);
@ -550,6 +551,7 @@ void SettingsView::reloadConfig() {
loadSetting("allowOpposingDirections", m_ui.allowOpposingDirections);
loadSetting("suspendScreensaver", m_ui.suspendScreensaver);
loadSetting("pauseOnFocusLost", m_ui.pauseOnFocusLost);
loadSetting("pauseOnMinimize", m_ui.pauseOnMinimize);
loadSetting("savegamePath", m_ui.savegamePath);
loadSetting("savestatePath", m_ui.savestatePath);
loadSetting("screenshotPath", m_ui.screenshotPath);

View File

@ -562,7 +562,7 @@
</property>
</widget>
</item>
<item row="9" column="1">
<item row="10" column="1">
<widget class="QCheckBox" name="showFps">
<property name="text">
<string>Show FPS in title bar</string>
@ -572,21 +572,21 @@
</property>
</widget>
</item>
<item row="11" column="0" colspan="2">
<item row="12" column="0" colspan="2">
<widget class="Line" name="line_13">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="14" column="0" colspan="2">
<item row="15" column="0" colspan="2">
<widget class="Line" name="line_16">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="15" column="1">
<item row="16" column="1">
<widget class="QCheckBox" name="cheatAutosave">
<property name="text">
<string>Automatically save cheats</string>
@ -596,7 +596,7 @@
</property>
</widget>
</item>
<item row="16" column="1">
<item row="17" column="1">
<widget class="QCheckBox" name="cheatAutoload">
<property name="text">
<string>Automatically load cheats</string>
@ -606,7 +606,7 @@
</property>
</widget>
</item>
<item row="12" column="1">
<item row="13" column="1">
<widget class="QCheckBox" name="autosave">
<property name="text">
<string>Automatically save state</string>
@ -616,7 +616,7 @@
</property>
</widget>
</item>
<item row="13" column="1">
<item row="14" column="1">
<widget class="QCheckBox" name="autoload">
<property name="text">
<string>Automatically load state</string>
@ -626,13 +626,20 @@
</property>
</widget>
</item>
<item row="10" column="1">
<item row="11" column="1">
<widget class="QCheckBox" name="useDiscordPresence">
<property name="text">
<string>Enable Discord Rich Presence</string>
</property>
</widget>
</item>
<item row="9" column="1">
<widget class="QCheckBox" name="pauseOnMinimize">
<property name="text">
<string>Pause when minimized</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="emulation">

View File

@ -602,6 +602,13 @@ void Window::resizeEvent(QResizeEvent* event) {
void Window::showEvent(QShowEvent* event) {
if (m_wasOpened) {
if (event->spontaneous() && m_config->getOption("pauseOnMinimize").toInt() && m_controller) {
focusCheck();
if (m_autoresume) {
m_controller->setPaused(false);
m_autoresume = false;
}
}
return;
}
m_wasOpened = true;
@ -623,6 +630,19 @@ void Window::showEvent(QShowEvent* event) {
setFocus();
}
void Window::hideEvent(QHideEvent* event) {
if (!event->spontaneous()) {
return;
}
if (!m_config->getOption("pauseOnMinimize").toInt() || !m_controller) {
return;
}
if (!m_controller->isPaused()) {
m_autoresume = true;
m_controller->setPaused(true);
}
}
void Window::closeEvent(QCloseEvent* event) {
emit shutdown();
m_config->setQtOption("windowPos", pos());

View File

@ -116,6 +116,7 @@ protected:
virtual void keyReleaseEvent(QKeyEvent* event) override;
virtual void resizeEvent(QResizeEvent*) override;
virtual void showEvent(QShowEvent*) override;
virtual void hideEvent(QHideEvent*) override;
virtual void closeEvent(QCloseEvent*) override;
virtual void focusInEvent(QFocusEvent*) override;
virtual void focusOutEvent(QFocusEvent*) override;