diff options
author | snek <me@gus.host> | 2022-07-28 01:46:03 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-28 01:46:03 +0200 |
commit | b7642cff361176161e848b004143da4777d0971d (patch) | |
tree | 04bfe8b7914f7f71cb67af0d7be078a3ca91db44 /src | |
parent | Merge pull request #8542 from Morph1984/gpu-use-old-q (diff) | |
download | yuzu-b7642cff361176161e848b004143da4777d0971d.tar yuzu-b7642cff361176161e848b004143da4777d0971d.tar.gz yuzu-b7642cff361176161e848b004143da4777d0971d.tar.bz2 yuzu-b7642cff361176161e848b004143da4777d0971d.tar.lz yuzu-b7642cff361176161e848b004143da4777d0971d.tar.xz yuzu-b7642cff361176161e848b004143da4777d0971d.tar.zst yuzu-b7642cff361176161e848b004143da4777d0971d.zip |
Diffstat (limited to 'src')
-rw-r--r-- | src/yuzu/main.cpp | 39 | ||||
-rw-r--r-- | src/yuzu/main.h | 5 |
2 files changed, 43 insertions, 1 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()) { diff --git a/src/yuzu/main.h b/src/yuzu/main.h index 509bb91df..23b67a14e 100644 --- a/src/yuzu/main.h +++ b/src/yuzu/main.h @@ -204,7 +204,7 @@ private: void ConnectMenuEvents(); void UpdateMenuState(); - MultiplayerState* multiplayer_state = nullptr; + void SetupPrepareForSleep(); void PreventOSSleep(); void AllowOSSleep(); @@ -265,6 +265,7 @@ private slots: void OnPauseGame(); void OnPauseContinueGame(); void OnStopGame(); + void OnPrepareForSleep(bool prepare_sleep); void OnMenuReportCompatibility(); void OnOpenModsPage(); void OnOpenQuickstartGuide(); @@ -355,6 +356,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; |