implement pause on system suspend

This commit is contained in:
Gus Caplan
2022-07-14 23:07:02 -07:00
parent caaf2368b6
commit 2a3857f178
2 changed files with 42 additions and 0 deletions
+39
View File
@@ -377,6 +377,8 @@ GMainWindow::GMainWindow()
SDL_EnableScreenSaver();
#endif
SetupPrepareForSleep();
Common::Log::Start();
QStringList args = QApplication::arguments();
@@ -1286,6 +1288,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()) {
+3
View File
@@ -200,6 +200,8 @@ private:
void ConnectMenuEvents();
void UpdateMenuState();
void SetupPrepareForSleep();
void PreventOSSleep();
void AllowOSSleep();
@@ -253,6 +255,7 @@ private slots:
void OnPauseGame();
void OnPauseContinueGame();
void OnStopGame();
void OnPrepareForSleep(bool prepare_sleep);
void OnMenuReportCompatibility();
void OnOpenModsPage();
void OnOpenQuickstartGuide();