Compare commits

...

3 Commits

Author SHA1 Message Date
snek
9510446280 e 2022-07-25 15:54:27 -07:00
snek
a7a6e86e5d Merge branch 'master' into pause-suspend 2022-07-25 15:49:53 -07:00
Gus Caplan
2a3857f178 implement pause on system suspend 2022-07-18 12:40:59 -07:00
2 changed files with 43 additions and 1 deletions

View File

@@ -379,6 +379,8 @@ GMainWindow::GMainWindow(bool has_broken_vulkan)
SDL_EnableScreenSaver();
#endif
SetupPrepareForSleep();
Common::Log::Start();
QStringList args = QApplication::arguments();
@@ -1314,6 +1316,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()) {

View File

@@ -203,7 +203,7 @@ private:
void ConnectMenuEvents();
void UpdateMenuState();
MultiplayerState* multiplayer_state = nullptr;
void SetupPrepareForSleep();
void PreventOSSleep();
void AllowOSSleep();
@@ -258,6 +258,7 @@ private slots:
void OnPauseGame();
void OnPauseContinueGame();
void OnStopGame();
void OnPrepareForSleep(bool prepare_sleep);
void OnMenuReportCompatibility();
void OnOpenModsPage();
void OnOpenQuickstartGuide();
@@ -348,6 +349,8 @@ private:
std::unique_ptr<DiscordRPC::DiscordInterface> discord_rpc;
std::shared_ptr<InputCommon::InputSubsystem> input_subsystem;
MultiplayerState* multiplayer_state = nullptr;
GRenderWindow* render_window;
GameList* game_list;
LoadingScreen* loading_screen;