aboutsummaryrefslogtreecommitdiff
path: root/src/frontend/qt_sdl
diff options
context:
space:
mode:
authorWaluigiWare64 <68647953+WaluigiWare64@users.noreply.github.com>2021-01-22 17:35:13 +0000
committerWaluigiWare64 <68647953+WaluigiWare64@users.noreply.github.com>2021-01-22 17:35:13 +0000
commitfaf7cf752d17cda63422d80a17f9f671a8474120 (patch)
treea0d4d366db9a16ab907e0668a376e7fde48b9222 /src/frontend/qt_sdl
parent8a3a8b7c684996d2ea72a95e5abd62b1e763f344 (diff)
Add option to pause emulation when focus is lost
Fixes #875
Diffstat (limited to 'src/frontend/qt_sdl')
-rw-r--r--src/frontend/qt_sdl/InterfaceSettingsDialog.cpp3
-rw-r--r--src/frontend/qt_sdl/InterfaceSettingsDialog.ui37
-rw-r--r--src/frontend/qt_sdl/PlatformConfig.cpp5
-rw-r--r--src/frontend/qt_sdl/PlatformConfig.h1
-rw-r--r--src/frontend/qt_sdl/main.cpp18
-rw-r--r--src/frontend/qt_sdl/main.h4
6 files changed, 52 insertions, 16 deletions
diff --git a/src/frontend/qt_sdl/InterfaceSettingsDialog.cpp b/src/frontend/qt_sdl/InterfaceSettingsDialog.cpp
index 7dcb421..72bbd46 100644
--- a/src/frontend/qt_sdl/InterfaceSettingsDialog.cpp
+++ b/src/frontend/qt_sdl/InterfaceSettingsDialog.cpp
@@ -34,6 +34,8 @@ InterfaceSettingsDialog::InterfaceSettingsDialog(QWidget* parent) : QDialog(pare
ui->cbMouseHide->setChecked(Config::MouseHide != 0);
ui->spinMouseHideSeconds->setEnabled(Config::MouseHide != 0);
ui->spinMouseHideSeconds->setValue(Config::MouseHideSeconds);
+ ui->cbPauseLostFocus->setChecked(Config::PauseLostFocus != 0);
+ oldPauseLostFocusVal = ui->cbPauseLostFocus->isChecked() ? 1:0;
}
InterfaceSettingsDialog::~InterfaceSettingsDialog()
@@ -59,6 +61,7 @@ void InterfaceSettingsDialog::done(int r)
{
Config::MouseHide = ui->cbMouseHide->isChecked() ? 1:0;
Config::MouseHideSeconds = ui->spinMouseHideSeconds->value();
+ Config::PauseLostFocus = ui->cbPauseLostFocus->isChecked() ? 1:0;
Config::Save();
diff --git a/src/frontend/qt_sdl/InterfaceSettingsDialog.ui b/src/frontend/qt_sdl/InterfaceSettingsDialog.ui
index 4891da9..abaaf48 100644
--- a/src/frontend/qt_sdl/InterfaceSettingsDialog.ui
+++ b/src/frontend/qt_sdl/InterfaceSettingsDialog.ui
@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
- <width>209</width>
- <height>110</height>
+ <width>262</width>
+ <height>113</height>
</rect>
</property>
<property name="sizePolicy">
@@ -20,31 +20,31 @@
<string>Interface settings - melonDS</string>
</property>
<layout class="QGridLayout" name="gridLayout">
- <item row="0" column="0" colspan="3">
- <widget class="QCheckBox" name="cbMouseHide">
+ <item row="1" column="0" alignment="Qt::AlignLeft">
+ <widget class="QLabel" name="label">
<property name="text">
- <string>Hide mouse after inactivity</string>
+ <string>Hide after</string>
</property>
</widget>
</item>
- <item row="1" column="0">
- <widget class="QLabel" name="label">
+ <item row="2" column="0" colspan="4">
+ <widget class="QCheckBox" name="cbPauseLostFocus">
<property name="text">
- <string>Hide after</string>
+ <string>Pause emulation when window is not in focus</string>
</property>
</widget>
</item>
- <item row="1" column="1">
- <widget class="QSpinBox" name="spinMouseHideSeconds"/>
- </item>
- <item row="1" column="2">
- <widget class="QLabel" name="label_2">
+ <item row="0" column="0" colspan="5">
+ <widget class="QCheckBox" name="cbMouseHide">
<property name="text">
- <string>seconds of inactivity</string>
+ <string>Hide mouse after inactivity</string>
</property>
</widget>
</item>
- <item row="2" column="0" colspan="3">
+ <item row="1" column="1" alignment="Qt::AlignLeft">
+ <widget class="QSpinBox" name="spinMouseHideSeconds"/>
+ </item>
+ <item row="3" column="0" colspan="5">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
@@ -54,6 +54,13 @@
</property>
</widget>
</item>
+ <item row="1" column="2">
+ <widget class="QLabel" name="label_2">
+ <property name="text">
+ <string>seconds of inactivity</string>
+ </property>
+ </widget>
+ </item>
</layout>
</widget>
<resources/>
diff --git a/src/frontend/qt_sdl/PlatformConfig.cpp b/src/frontend/qt_sdl/PlatformConfig.cpp
index ac890ee..0f67b9a 100644
--- a/src/frontend/qt_sdl/PlatformConfig.cpp
+++ b/src/frontend/qt_sdl/PlatformConfig.cpp
@@ -80,6 +80,8 @@ int EnableCheats;
int MouseHide;
int MouseHideSeconds;
+int PauseLostFocus;
+
bool EnableJIT;
ConfigEntry PlatformConfigFile[] =
@@ -188,8 +190,9 @@ ConfigEntry PlatformConfigFile[] =
{"EnableCheats", 0, &EnableCheats, 0, NULL, 0},
- {"MouseHide", 0, &MouseHide, 0, NULL, 0},
+ {"MouseHide", 0, &MouseHide, 0, NULL, 0},
{"MouseHideSeconds", 0, &MouseHideSeconds, 5, NULL, 0},
+ {"PauseLostFocus", 0, &PauseLostFocus, 0, NULL, 0},
{"", -1, NULL, 0, NULL, 0}
};
diff --git a/src/frontend/qt_sdl/PlatformConfig.h b/src/frontend/qt_sdl/PlatformConfig.h
index a37411e..bf5fc60 100644
--- a/src/frontend/qt_sdl/PlatformConfig.h
+++ b/src/frontend/qt_sdl/PlatformConfig.h
@@ -94,6 +94,7 @@ extern int EnableCheats;
extern int MouseHide;
extern int MouseHideSeconds;
+extern int PauseLostFocus;
}
diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp
index c5ce692..7c7fe7d 100644
--- a/src/frontend/qt_sdl/main.cpp
+++ b/src/frontend/qt_sdl/main.cpp
@@ -1534,6 +1534,19 @@ void MainWindow::dropEvent(QDropEvent* event)
}
}
+void MainWindow::onAppStateChanged(Qt::ApplicationState state)
+{
+ if (state == Qt::ApplicationInactive)
+ {
+ if (Config::PauseLostFocus && emuThread->emuIsRunning())
+ emuThread->emuPause();
+ }
+ else if (state == Qt::ApplicationActive)
+ {
+ if (Config::PauseLostFocus && !pausedManually)
+ emuThread->emuUnpause();
+ }
+}
QString MainWindow::loadErrorStr(int error)
{
@@ -2002,11 +2015,13 @@ void MainWindow::onPause(bool checked)
{
emuThread->emuPause();
OSD::AddMessage(0, "Paused");
+ pausedManually = true;
}
else
{
emuThread->emuUnpause();
OSD::AddMessage(0, "Resumed");
+ pausedManually = false;
}
}
@@ -2152,6 +2167,7 @@ void MainWindow::onOpenInterfaceSettings()
InterfaceSettingsDialog* dlg = InterfaceSettingsDialog::openDlg(this);
connect(dlg, &InterfaceSettingsDialog::finished, this, &MainWindow::onInterfaceSettingsFinished);
connect(dlg, &InterfaceSettingsDialog::updateMouseTimer, this, &MainWindow::onUpdateMouseTimer);
+ connect(dlg, &InterfaceSettingsDialog::focusUnpauseEmu, emuThread, &EmuThread::emuUnpause);
}
void MainWindow::onUpdateMouseTimer()
@@ -2505,6 +2521,8 @@ int main(int argc, char** argv)
emuThread->start();
emuThread->emuPause();
+ QObject::connect(&melon, &QApplication::applicationStateChanged, mainWindow, &MainWindow::onAppStateChanged);
+
if (argc > 1)
{
char* file = argv[1];
diff --git a/src/frontend/qt_sdl/main.h b/src/frontend/qt_sdl/main.h
index 9ab4c2a..ec7bd74 100644
--- a/src/frontend/qt_sdl/main.h
+++ b/src/frontend/qt_sdl/main.h
@@ -184,6 +184,8 @@ public:
bool hasOGL;
QOpenGLContext* getOGLContext();
+
+ void onAppStateChanged(Qt::ApplicationState state);
protected:
void resizeEvent(QResizeEvent* event) override;
@@ -262,6 +264,8 @@ private:
void createScreenPanel();
QString loadErrorStr(int error);
+
+ bool pausedManually;
public:
QWidget* panel;