From 843c816fc2a4db43856d5af7266c81c22c1fccbf Mon Sep 17 00:00:00 2001 From: rofl0r Date: Sun, 16 Jun 2024 16:53:31 +0000 Subject: [PATCH] x11: add support for Xss screensaver disabling in case xdg-screensaver isn't installed. --- Makefile.common | 3 +++ gfx/common/x11_common.c | 28 ++++++++++++++++++++++++++-- qb/config.libs.sh | 1 + qb/config.params.sh | 1 + 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/Makefile.common b/Makefile.common index 2a715f4786..17c5e40185 100644 --- a/Makefile.common +++ b/Makefile.common @@ -1305,6 +1305,9 @@ ifeq ($(HAVE_X11), 1) ifeq ($(HAVE_XCB),1) LIBS += -lX11-xcb endif + ifeq ($(HAVE_XSCRNSAVER),1) + LIBS += -lXss + endif ifneq ($(HAVE_OPENGLES), 1) OBJ += gfx/drivers_context/x_ctx.o endif diff --git a/gfx/common/x11_common.c b/gfx/common/x11_common.c index 5d1a3b18c6..9b500ca951 100644 --- a/gfx/common/x11_common.c +++ b/gfx/common/x11_common.c @@ -204,6 +204,28 @@ void x11_set_window_attr(Display *dpy, Window win) x11_set_window_pid(dpy, win); } +#ifdef HAVE_XSCRNSAVER +#include +static bool xss_screensaver_inhibit(Display *dpy, bool enable) +{ + int dummy, min, maj; + if (!XScreenSaverQueryExtension(dpy, &dummy, &dummy) || + !XScreenSaverQueryVersion(dpy, &maj, &min) || + maj < 1 || (maj == 1 && min < 1)) { + return false; + } + XScreenSaverSuspend(dpy, enable); + XResetScreenSaver(dpy); + return true; +} +#else +static bool xss_screensaver_inhibit(Display *dpy, bool enable) +{ + (void) dpy; + return false; +} +#endif + static void xdg_screensaver_inhibit(Window wnd) { int ret; @@ -253,9 +275,11 @@ bool x11_suspend_screensaver(void *data, bool enable) if (dbus_suspend_screensaver(enable)) return true; #endif - if (enable) - if (xdg_screensaver_available) + if (!xss_screensaver_inhibit(g_x11_dpy, enable) && enable) + if (xdg_screensaver_available) { xdg_screensaver_inhibit(wnd); + return xdg_screensaver_available; + } return true; } diff --git a/qb/config.libs.sh b/qb/config.libs.sh index 39092b5e6c..1c84537518 100644 --- a/qb/config.libs.sh +++ b/qb/config.libs.sh @@ -505,6 +505,7 @@ if [ "$HAVE_X11" != 'no' ]; then check_val '' XCB -lxcb '' xcb '' '' false check_val '' XEXT -lXext '' xext '' '' false check_val '' XF86VM -lXxf86vm '' xxf86vm '' '' false + check_val '' XSCRNSAVER -lXss '' xscrnsaver '' '' false else die : 'Notice: X11 not present. Skipping X11 code paths.' fi diff --git a/qb/config.params.sh b/qb/config.params.sh index d261c8f6f3..f0de7db563 100644 --- a/qb/config.params.sh +++ b/qb/config.params.sh @@ -92,6 +92,7 @@ HAVE_OPENGLES3_1=no # OpenGLES3.1 support HAVE_OPENGLES3_2=no # OpenGLES3.2 support HAVE_X11=auto # everything X11. HAVE_XRANDR=auto # Xrandr support. +HAVE_XSCRNSAVER=auto # Xss support. HAVE_OMAP=no # OMAP video support HAVE_XINERAMA=auto # Xinerama support. HAVE_KMS=auto # KMS context support