summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt2
-rw-r--r--src/yuzu/CMakeLists.txt3
-rw-r--r--src/yuzu/main.cpp51
-rw-r--r--src/yuzu/main.h9
4 files changed, 64 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7d9056aa3..d1ad55c9c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -249,7 +249,7 @@ if(ENABLE_QT)
249 # Check for system Qt on Linux, fallback to bundled Qt 249 # Check for system Qt on Linux, fallback to bundled Qt
250 if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux") 250 if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
251 if (NOT YUZU_USE_BUNDLED_QT) 251 if (NOT YUZU_USE_BUNDLED_QT)
252 find_package(Qt5 ${QT_VERSION} COMPONENTS Widgets) 252 find_package(Qt5 ${QT_VERSION} COMPONENTS Widgets DBus)
253 endif() 253 endif()
254 if (NOT Qt5_FOUND OR YUZU_USE_BUNDLED_QT) 254 if (NOT Qt5_FOUND OR YUZU_USE_BUNDLED_QT)
255 # Check for dependencies, then enable bundled Qt download 255 # Check for dependencies, then enable bundled Qt download
diff --git a/src/yuzu/CMakeLists.txt b/src/yuzu/CMakeLists.txt
index 732e8c276..30902101d 100644
--- a/src/yuzu/CMakeLists.txt
+++ b/src/yuzu/CMakeLists.txt
@@ -251,6 +251,9 @@ target_include_directories(yuzu PRIVATE ../../externals/Vulkan-Headers/include)
251if (NOT WIN32) 251if (NOT WIN32)
252 target_include_directories(yuzu PRIVATE ${Qt5Gui_PRIVATE_INCLUDE_DIRS}) 252 target_include_directories(yuzu PRIVATE ${Qt5Gui_PRIVATE_INCLUDE_DIRS})
253endif() 253endif()
254if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
255 target_link_libraries(yuzu PRIVATE Qt5::DBus)
256endif()
254 257
255target_compile_definitions(yuzu PRIVATE 258target_compile_definitions(yuzu PRIVATE
256 # Use QStringBuilder for string concatenation to reduce 259 # Use QStringBuilder for string concatenation to reduce
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp
index a7271e075..975f6dd11 100644
--- a/src/yuzu/main.cpp
+++ b/src/yuzu/main.cpp
@@ -1236,11 +1236,57 @@ void GMainWindow::OnDisplayTitleBars(bool show) {
1236 } 1236 }
1237} 1237}
1238 1238
1239#ifdef __linux__
1240static std::optional<QDBusObjectPath> HoldWakeLockLinux(u32 window_id = 0) {
1241 if (!QDBusConnection::sessionBus().isConnected()) {
1242 return {};
1243 }
1244 // reference: https://flatpak.github.io/xdg-desktop-portal/#gdbus-org.freedesktop.portal.Inhibit
1245 QDBusInterface xdp(QString::fromLatin1("org.freedesktop.portal.Desktop"),
1246 QString::fromLatin1("/org/freedesktop/portal/desktop"),
1247 QString::fromLatin1("org.freedesktop.portal.Inhibit"));
1248 if (!xdp.isValid()) {
1249 LOG_WARNING(Frontend, "Couldn't connect to XDP D-Bus endpoint");
1250 return {};
1251 }
1252 QVariantMap options = {};
1253 //: TRANSLATORS: This string is shown to the user to explain why yuzu needs to prevent the computer from sleeping
1254 options.insert(QString::fromLatin1("reason"),
1255 QCoreApplication::translate("GMainWindow", "yuzu is emulating a game"));
1256 // 0x4: Suspend lock; 0x8: Idle lock
1257 QDBusReply<QDBusObjectPath> reply =
1258 xdp.call(QString::fromLatin1("Inhibit"),
1259 QString::fromLatin1("x11:") + QString::number(window_id, 16), 12U, options);
1260
1261 if (reply.isValid()) {
1262 return reply.value();
1263 }
1264 LOG_WARNING(Frontend, "Couldn't read Inhibit reply from XDP: {}",
1265 reply.error().message().toStdString());
1266 return {};
1267}
1268
1269static void ReleaseWakeLockLinux(QDBusObjectPath lock) {
1270 if (!QDBusConnection::sessionBus().isConnected()) {
1271 return;
1272 }
1273 QDBusInterface unlocker(QString::fromLatin1("org.freedesktop.portal.Desktop"), lock.path(),
1274 QString::fromLatin1("org.freedesktop.portal.Request"));
1275 unlocker.call(QString::fromLatin1("Close"));
1276}
1277#endif // __linux__
1278
1239void GMainWindow::PreventOSSleep() { 1279void GMainWindow::PreventOSSleep() {
1240#ifdef _WIN32 1280#ifdef _WIN32
1241 SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED); 1281 SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED);
1242#elif defined(HAVE_SDL2) 1282#elif defined(HAVE_SDL2)
1243 SDL_DisableScreenSaver(); 1283 SDL_DisableScreenSaver();
1284#ifdef __linux__
1285 auto reply = HoldWakeLockLinux(winId());
1286 if (reply) {
1287 wake_lock = std::move(reply.value());
1288 }
1289#endif
1244#endif 1290#endif
1245} 1291}
1246 1292
@@ -1249,6 +1295,11 @@ void GMainWindow::AllowOSSleep() {
1249 SetThreadExecutionState(ES_CONTINUOUS); 1295 SetThreadExecutionState(ES_CONTINUOUS);
1250#elif defined(HAVE_SDL2) 1296#elif defined(HAVE_SDL2)
1251 SDL_EnableScreenSaver(); 1297 SDL_EnableScreenSaver();
1298#ifdef __linux__
1299 if (!wake_lock.path().isEmpty()) {
1300 ReleaseWakeLockLinux(wake_lock);
1301 }
1302#endif
1252#endif 1303#endif
1253} 1304}
1254 1305
diff --git a/src/yuzu/main.h b/src/yuzu/main.h
index 0fd41ed4f..7870bb963 100644
--- a/src/yuzu/main.h
+++ b/src/yuzu/main.h
@@ -17,6 +17,12 @@
17#include "yuzu/compatibility_list.h" 17#include "yuzu/compatibility_list.h"
18#include "yuzu/hotkeys.h" 18#include "yuzu/hotkeys.h"
19 19
20#ifdef __linux__
21#include <QVariant>
22#include <QtDBus/QDBusInterface>
23#include <QtDBus/QtDBus>
24#endif
25
20class Config; 26class Config;
21class EmuThread; 27class EmuThread;
22class GameList; 28class GameList;
@@ -394,6 +400,9 @@ private:
394 400
395 // Applets 401 // Applets
396 QtSoftwareKeyboardDialog* software_keyboard = nullptr; 402 QtSoftwareKeyboardDialog* software_keyboard = nullptr;
403#ifdef __linux__
404 QDBusObjectPath wake_lock{};
405#endif
397 406
398protected: 407protected:
399 void dropEvent(QDropEvent* event) override; 408 void dropEvent(QDropEvent* event) override;