Qt: Add options to mute on minimize or focus lost

This commit is contained in:
Vicki Pfau 2021-06-24 17:57:49 -07:00
parent fee40bc74d
commit 14419282f4
3 changed files with 91 additions and 23 deletions

View File

@ -421,6 +421,8 @@ void SettingsView::updateConfig() {
saveSetting("suspendScreensaver", m_ui.suspendScreensaver);
saveSetting("pauseOnFocusLost", m_ui.pauseOnFocusLost);
saveSetting("pauseOnMinimize", m_ui.pauseOnMinimize);
saveSetting("muteOnFocusLost", m_ui.muteOnFocusLost);
saveSetting("muteOnMinimize", m_ui.muteOnMinimize);
saveSetting("savegamePath", m_ui.savegamePath);
saveSetting("savestatePath", m_ui.savestatePath);
saveSetting("screenshotPath", m_ui.screenshotPath);

View File

@ -556,18 +556,22 @@
</widget>
</item>
<item row="8" column="1">
<widget class="QCheckBox" name="pauseOnFocusLost">
<property name="text">
<string>Pause when inactive</string>
</property>
</widget>
</item>
<item row="9" column="1">
<widget class="QCheckBox" name="pauseOnMinimize">
<property name="text">
<string>Pause when minimized</string>
</property>
</widget>
<layout class="QHBoxLayout" name="horizontalLayout_21">
<item>
<widget class="QCheckBox" name="pauseOnFocusLost">
<property name="text">
<string>Pause</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="muteOnFocusLost">
<property name="text">
<string>Mute</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="10" column="0" colspan="2">
<widget class="Line" name="line_17">
@ -684,6 +688,38 @@
</property>
</widget>
</item>
<item row="9" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_24">
<item>
<widget class="QCheckBox" name="pauseOnMinimize">
<property name="text">
<string>Pause</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="muteOnMinimize">
<property name="text">
<string>Mute</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="8" column="0">
<widget class="QLabel" name="label_41">
<property name="text">
<string>When inactive:</string>
</property>
</widget>
</item>
<item row="9" column="0">
<widget class="QLabel" name="label_42">
<property name="text">
<string>When minimized:</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="emulation">

View File

@ -656,12 +656,21 @@ void Window::resizeEvent(QResizeEvent*) {
void Window::showEvent(QShowEvent* event) {
if (m_wasOpened) {
if (event->spontaneous() && m_config->getOption("pauseOnMinimize").toInt() && m_controller) {
if (event->spontaneous() && m_controller) {
focusCheck();
if (m_autoresume) {
if (m_config->getOption("pauseOnMinimize").toInt() && m_autoresume) {
m_controller->setPaused(false);
m_autoresume = false;
}
if (m_config->getOption("muteOnMinimize").toInt()) {
CoreController::Interrupter interrupter(m_controller);
mCore* core = m_controller->thread()->core;
int fakeBool = 0;
mCoreConfigGetIntValue(&core->config, "mute", &fakeBool);
core->opts.mute = fakeBool;
core->reloadConfigOption(core, NULL, NULL);
}
}
return;
}
@ -692,13 +701,20 @@ void Window::hideEvent(QHideEvent* event) {
if (!event->spontaneous()) {
return;
}
if (!m_config->getOption("pauseOnMinimize").toInt() || !m_controller) {
if (!m_controller) {
return;
}
if (!m_controller->isPaused()) {
if (m_config->getOption("pauseOnMinimize").toInt() && !m_controller->isPaused()) {
m_autoresume = true;
m_controller->setPaused(true);
}
if (m_config->getOption("muteOnMinimize").toInt()) {
CoreController::Interrupter interrupter(m_controller);
mCore* core = m_controller->thread()->core;
core->opts.mute = true;
core->reloadConfigOption(core, NULL, NULL);
}
}
void Window::closeEvent(QCloseEvent* event) {
@ -1832,15 +1848,29 @@ Action* Window::addGameAction(const QString& visibleName, const QString& name, A
}
void Window::focusCheck() {
if (!m_config->getOption("pauseOnFocusLost").toInt() || !m_controller) {
if (!m_controller) {
return;
}
if (QGuiApplication::focusWindow() && m_autoresume) {
m_controller->setPaused(false);
m_autoresume = false;
} else if (!QGuiApplication::focusWindow() && !m_controller->isPaused()) {
m_autoresume = true;
m_controller->setPaused(true);
if (m_config->getOption("pauseOnFocusLost").toInt()) {
if (QGuiApplication::focusWindow() && m_autoresume) {
m_controller->setPaused(false);
m_autoresume = false;
} else if (!QGuiApplication::focusWindow() && !m_controller->isPaused()) {
m_autoresume = true;
m_controller->setPaused(true);
}
}
if (m_config->getOption("muteOnFocusLost").toInt()) {
CoreController::Interrupter interrupter(m_controller);
mCore* core = m_controller->thread()->core;
if (QGuiApplication::focusWindow()) {
int fakeBool = 0;
mCoreConfigGetIntValue(&core->config, "mute", &fakeBool);
core->opts.mute = fakeBool;
} else {
core->opts.mute = true;
}
core->reloadConfigOption(core, NULL, NULL);
}
}