summaryrefslogtreecommitdiff
path: root/src/yuzu/main.cpp
diff options
context:
space:
mode:
authorsnek <me@gus.host>2022-07-27 16:46:03 -0700
committerGitHub <noreply@github.com>2022-07-27 19:46:03 -0400
commitb7642cff361176161e848b004143da4777d0971d (patch)
tree04bfe8b7914f7f71cb67af0d7be078a3ca91db44 /src/yuzu/main.cpp
parentea861cc1c43e3c4079e80b6cbf3e81f992996574 (diff)
implement pause on system suspend (#8585)
Diffstat (limited to 'src/yuzu/main.cpp')
-rw-r--r--src/yuzu/main.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp
index ef91ef19c..e8a57f4b4 100644
--- a/src/yuzu/main.cpp
+++ b/src/yuzu/main.cpp
@@ -386,6 +386,8 @@ GMainWindow::GMainWindow(bool has_broken_vulkan)
SDL_EnableScreenSaver();
#endif
+ SetupPrepareForSleep();
+
Common::Log::Start();
QStringList args = QApplication::arguments();
@@ -1327,6 +1329,43 @@ void GMainWindow::OnDisplayTitleBars(bool show) {
}
}
+void GMainWindow::SetupPrepareForSleep() {
+#ifdef __linux__
+ auto bus = QDBusConnection::systemBus();
+ if (bus.isConnected()) {
+ const bool success = bus.connect(
+ QStringLiteral("org.freedesktop.login1"), QStringLiteral("/org/freedesktop/login1"),
+ QStringLiteral("org.freedesktop.login1.Manager"), QStringLiteral("PrepareForSleep"),
+ QStringLiteral("b"), this, SLOT(OnPrepareForSleep(bool)));
+
+ if (!success) {
+ LOG_WARNING(Frontend, "Couldn't register PrepareForSleep signal");
+ }
+ } else {
+ LOG_WARNING(Frontend, "QDBusConnection system bus is not connected");
+ }
+#endif // __linux__
+}
+
+void GMainWindow::OnPrepareForSleep(bool prepare_sleep) {
+ if (emu_thread == nullptr) {
+ return;
+ }
+
+ if (prepare_sleep) {
+ if (emu_thread->IsRunning()) {
+ auto_paused = true;
+ OnPauseGame();
+ }
+ } else {
+ if (!emu_thread->IsRunning() && auto_paused) {
+ auto_paused = false;
+ RequestGameResume();
+ OnStartGame();
+ }
+ }
+}
+
#ifdef __linux__
static std::optional<QDBusObjectPath> HoldWakeLockLinux(u32 window_id = 0) {
if (!QDBusConnection::sessionBus().isConnected()) {