System: Move gamescope screensaver hack to QtHost

pull/3732/head
Stenzek 5 months ago
parent 153fa1d235
commit 85c0b4eff1
No known key found for this signature in database

@ -317,9 +317,6 @@ struct ALIGN_TO_CACHE_LINE StateVars
GameHash running_game_hash = 0;
bool running_game_custom_title = false;
// Prevent screensaver inhibits when running on platforms that don't have it (e.g. gamescope).
bool disable_screensaver_inhibit = false;
std::atomic_bool startup_cancelled{false};
std::unique_ptr<INISettingsInterface> game_settings_interface;
@ -499,17 +496,6 @@ bool System::ProcessStartup(Error* error)
SetRymlCallbacks();
#ifdef __linux__
// Disable screensaver inhibit if running on gamescope.
const char* desktop = std::getenv("XDG_CURRENT_DESKTOP");
if (!desktop)
desktop = std::getenv("XDG_SESSION_DESKTOP");
if (!desktop || std::strlen(desktop) == 0 || std::strstr(desktop, "gamescope"))
{
INFO_LOG("Missing XDG_CURRENT_DESKTOP ({}) or running under gamescope, disabling screensaver inhibit.",
desktop ? desktop : "null");
s_state.disable_screensaver_inhibit = true;
}
// Running DuckStation out of /usr is not supported and makes no sense.
if (std::memcmp(EmuFolders::AppRoot.data(), "/usr/", 5) == 0)
return false;
@ -3934,9 +3920,6 @@ PresentSkipMode System::GetEffectivePresentSkipMode()
void System::InhibitScreensaver(bool inhibit)
{
if (s_state.disable_screensaver_inhibit)
return;
Error error;
if (!Host::SetScreensaverInhibit(inhibit, &error))
{

@ -347,13 +347,21 @@ bool QtHost::IsDisplayWidgetContainerNeeded()
void QtHost::AdjustQtEnvironmentVariables()
{
const char* desktop = std::getenv("XDG_SESSION_DESKTOP");
// Disable screensaver inhibit if running on gamescope.
const char* desktop = std::getenv("XDG_CURRENT_DESKTOP");
if (!desktop)
return;
desktop = std::getenv("XDG_SESSION_DESKTOP");
std::fprintf(stderr, "XDG_SESSION_DESKTOP=%s\n", desktop ? desktop : "null");
std::fprintf(stderr, "XDG_SESSION_DESKTOP=%s\n", desktop);
if (!desktop || std::strstr(desktop, "gamescope"))
{
INFO_LOG("Missing XDG_CURRENT_DESKTOP ({}) or running under gamescope, disabling screensaver inhibit.",
desktop ? desktop : "null");
QtHost::DisableScreensaverInhibit();
}
if (std::strcmp(desktop, "KDE") == 0 || std::strcmp(desktop, "GNOME") == 0)
if (desktop && (std::strstr(desktop, "KDE") == 0 || std::strstr(desktop, "GNOME") == 0))
{
const char* platform_theme = std::getenv("QT_QPA_PLATFORMTHEME");
if (platform_theme)

@ -49,14 +49,16 @@ namespace {
struct WindowInfoLocals
{
bool screensaver_inhibited;
#if defined(__APPLE__)
IOPMAssertionID screensaver_inhibit_assertion;
#elif defined(__linux__)
u32 screensaver_inhibit_cookie;
// Prevent screensaver inhibits when running on platforms that don't have it (e.g. gamescope).
std::optional<QDBusInterface> screensaver_inhibit_interface;
u32 screensaver_inhibit_cookie = 0;
bool disable_screensaver_inhibit = false;
#endif
bool screensaver_inhibited = false;
};
} // namespace
@ -257,6 +259,13 @@ bool Host::SetScreensaverInhibit(bool inhibit, Error* error)
#elif defined(__linux__)
if (s_window_info_locals.disable_screensaver_inhibit)
{
// pretend it succeeded so the caller doesn't throw an error
s_window_info_locals.screensaver_inhibited = inhibit;
return true;
}
if (!s_window_info_locals.screensaver_inhibit_interface.has_value())
{
const QDBusConnection connection = QDBusConnection::sessionBus();
@ -330,3 +339,10 @@ bool QtUtils::SetWindowRoundedCornerState(QWidget* widget, bool enabled)
}
#endif // _WIN32
void QtHost::DisableScreensaverInhibit()
{
#ifdef __linux__
s_window_info_locals.disable_screensaver_inhibit = true;
#endif
}

@ -37,3 +37,10 @@ bool SetWindowRoundedCornerState(QWidget* widget, bool enabled);
#endif
} // namespace QtUtils
namespace QtHost {
/// Prevents the screensaver from being inhibited, if it is not supported on the current platform.
void DisableScreensaverInhibit();
} // namespace QtHost

Loading…
Cancel
Save