summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/input_common/drivers/sdl_driver.cpp4
-rw-r--r--src/yuzu/main.cpp58
-rw-r--r--src/yuzu/main.h2
3 files changed, 12 insertions, 52 deletions
diff --git a/src/input_common/drivers/sdl_driver.cpp b/src/input_common/drivers/sdl_driver.cpp
index 3cc639ba7..9f26392b1 100644
--- a/src/input_common/drivers/sdl_driver.cpp
+++ b/src/input_common/drivers/sdl_driver.cpp
@@ -487,6 +487,10 @@ void SDLDriver::CloseJoysticks() {
487} 487}
488 488
489SDLDriver::SDLDriver(std::string input_engine_) : InputEngine(std::move(input_engine_)) { 489SDLDriver::SDLDriver(std::string input_engine_) : InputEngine(std::move(input_engine_)) {
490 // Set our application name. Currently passed to DBus by SDL and visible to the user through
491 // their desktop environment.
492 SDL_SetHint(SDL_HINT_APP_NAME, "yuzu");
493
490 if (!Settings::values.enable_raw_input) { 494 if (!Settings::values.enable_raw_input) {
491 // Disable raw input. When enabled this setting causes SDL to die when a web applet opens 495 // Disable raw input. When enabled this setting causes SDL to die when a web applet opens
492 SDL_SetHint(SDL_HINT_JOYSTICK_RAWINPUT, "0"); 496 SDL_SetHint(SDL_HINT_JOYSTICK_RAWINPUT, "0");
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp
index 45a39451d..2133f7343 100644
--- a/src/yuzu/main.cpp
+++ b/src/yuzu/main.cpp
@@ -447,6 +447,14 @@ GMainWindow::GMainWindow(std::unique_ptr<Config> config_, bool has_broken_vulkan
447 447
448#if defined(HAVE_SDL2) && !defined(_WIN32) 448#if defined(HAVE_SDL2) && !defined(_WIN32)
449 SDL_InitSubSystem(SDL_INIT_VIDEO); 449 SDL_InitSubSystem(SDL_INIT_VIDEO);
450
451 // Set a screensaver inhibition reason string. Currently passed to DBus by SDL and visible to
452 // the user through their desktop environment.
453 //: TRANSLATORS: This string is shown to the user to explain why yuzu needs to prevent the
454 //: computer from sleeping
455 QByteArray wakelock_reason = tr("Running a game").toLatin1();
456 SDL_SetHint(SDL_HINT_SCREENSAVER_INHIBIT_ACTIVITY_NAME, wakelock_reason.data());
457
450 // SDL disables the screen saver by default, and setting the hint 458 // SDL disables the screen saver by default, and setting the hint
451 // SDL_HINT_VIDEO_ALLOW_SCREENSAVER doesn't seem to work, so we just enable the screen saver 459 // SDL_HINT_VIDEO_ALLOW_SCREENSAVER doesn't seem to work, so we just enable the screen saver
452 // for now. 460 // for now.
@@ -1623,45 +1631,6 @@ void GMainWindow::OnPrepareForSleep(bool prepare_sleep) {
1623} 1631}
1624 1632
1625#ifdef __unix__ 1633#ifdef __unix__
1626static std::optional<QDBusObjectPath> HoldWakeLockLinux(u32 window_id = 0) {
1627 if (!QDBusConnection::sessionBus().isConnected()) {
1628 return {};
1629 }
1630 // reference: https://flatpak.github.io/xdg-desktop-portal/#gdbus-org.freedesktop.portal.Inhibit
1631 QDBusInterface xdp(QString::fromLatin1("org.freedesktop.portal.Desktop"),
1632 QString::fromLatin1("/org/freedesktop/portal/desktop"),
1633 QString::fromLatin1("org.freedesktop.portal.Inhibit"));
1634 if (!xdp.isValid()) {
1635 LOG_WARNING(Frontend, "Couldn't connect to XDP D-Bus endpoint");
1636 return {};
1637 }
1638 QVariantMap options = {};
1639 //: TRANSLATORS: This string is shown to the user to explain why yuzu needs to prevent the
1640 //: computer from sleeping
1641 options.insert(QString::fromLatin1("reason"),
1642 QCoreApplication::translate("GMainWindow", "yuzu is running a game"));
1643 // 0x4: Suspend lock; 0x8: Idle lock
1644 QDBusReply<QDBusObjectPath> reply =
1645 xdp.call(QString::fromLatin1("Inhibit"),
1646 QString::fromLatin1("x11:") + QString::number(window_id, 16), 12U, options);
1647
1648 if (reply.isValid()) {
1649 return reply.value();
1650 }
1651 LOG_WARNING(Frontend, "Couldn't read Inhibit reply from XDP: {}",
1652 reply.error().message().toStdString());
1653 return {};
1654}
1655
1656static void ReleaseWakeLockLinux(QDBusObjectPath lock) {
1657 if (!QDBusConnection::sessionBus().isConnected()) {
1658 return;
1659 }
1660 QDBusInterface unlocker(QString::fromLatin1("org.freedesktop.portal.Desktop"), lock.path(),
1661 QString::fromLatin1("org.freedesktop.portal.Request"));
1662 unlocker.call(QString::fromLatin1("Close"));
1663}
1664
1665std::array<int, 3> GMainWindow::sig_interrupt_fds{0, 0, 0}; 1634std::array<int, 3> GMainWindow::sig_interrupt_fds{0, 0, 0};
1666 1635
1667void GMainWindow::SetupSigInterrupts() { 1636void GMainWindow::SetupSigInterrupts() {
@@ -1714,12 +1683,6 @@ void GMainWindow::PreventOSSleep() {
1714 SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED); 1683 SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED);
1715#elif defined(HAVE_SDL2) 1684#elif defined(HAVE_SDL2)
1716 SDL_DisableScreenSaver(); 1685 SDL_DisableScreenSaver();
1717#ifdef __unix__
1718 auto reply = HoldWakeLockLinux(winId());
1719 if (reply) {
1720 wake_lock = std::move(reply.value());
1721 }
1722#endif
1723#endif 1686#endif
1724} 1687}
1725 1688
@@ -1728,11 +1691,6 @@ void GMainWindow::AllowOSSleep() {
1728 SetThreadExecutionState(ES_CONTINUOUS); 1691 SetThreadExecutionState(ES_CONTINUOUS);
1729#elif defined(HAVE_SDL2) 1692#elif defined(HAVE_SDL2)
1730 SDL_EnableScreenSaver(); 1693 SDL_EnableScreenSaver();
1731#ifdef __unix__
1732 if (!wake_lock.path().isEmpty()) {
1733 ReleaseWakeLockLinux(wake_lock);
1734 }
1735#endif
1736#endif 1694#endif
1737} 1695}
1738 1696
diff --git a/src/yuzu/main.h b/src/yuzu/main.h
index e0e775d87..2cfb96257 100644
--- a/src/yuzu/main.h
+++ b/src/yuzu/main.h
@@ -504,8 +504,6 @@ private:
504#ifdef __unix__ 504#ifdef __unix__
505 QSocketNotifier* sig_interrupt_notifier; 505 QSocketNotifier* sig_interrupt_notifier;
506 static std::array<int, 3> sig_interrupt_fds; 506 static std::array<int, 3> sig_interrupt_fds;
507
508 QDBusObjectPath wake_lock{};
509#endif 507#endif
510 508
511protected: 509protected: