Skip to content

Commit 71a1398

Browse files
committed
(X11) Probe for xdg-screensaver/xset before invoking suspend
xdg-screensaver's X11 backend shells out to xset internally. On systems without x11-xserver-utils installed (minimal installs, containers, some WMs) the resulting failures surface as confusing stderr spam: /usr/bin/xdg-screensaver: 885: xset: not found /usr/bin/xdg-screensaver: 893: [: Illegal number: /usr/bin/xdg-screensaver: 632: xset: not found with no indication that the missing dependency is xset rather than something in RetroArch itself. Probe once on first use via 'command -v' (POSIX shell builtin, no extra deps) for both xdg-screensaver and xset, with output silenced. If either is missing, flip xdg_screensaver_available to false and log a single explanatory line; subsequent calls short-circuit out cleanly. Probe is gated behind a static bool so it runs at most once per process, and only when we'd actually invoke xdg-screensaver -- the DBus inhibit path still returns early before we ever get here.
1 parent 8ea17a0 commit 71a1398

1 file changed

Lines changed: 31 additions & 5 deletions

File tree

gfx/common/x11_common.c

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,13 +252,31 @@ static bool xss_screensaver_inhibit(Display *dpy, bool enable)
252252
return true;
253253
}
254254
#else
255-
static bool xss_screensaver_inhibit(Display *dpy, bool enable)
256-
{
257-
(void) dpy;
258-
return false;
259-
}
255+
static bool xss_screensaver_inhibit(Display *dpy, bool enable) { return false; }
260256
#endif
261257

258+
/* Probe once for xdg-screensaver and its xset backend dependency.
259+
* xdg-screensaver's "X11" backend shells out to xset; if xset is missing
260+
* (common on minimal installs / containers / some WMs without
261+
* x11-xserver-utils), invoking xdg-screensaver spams stderr with
262+
* "xset: not found" and "Illegal number" without us ever knowing why.
263+
* Check up front so we can silently no-op instead. */
264+
static bool xdg_screensaver_probe(void)
265+
{
266+
/* Both are needed: xdg-screensaver itself, and xset which it execs.
267+
* `command -v` is a POSIX shell builtin so this works under /bin/sh
268+
* on every platform that has system(). Redirecting both streams
269+
* keeps the probe silent. */
270+
int ret = system("command -v xdg-screensaver >/dev/null 2>&1 && "
271+
"command -v xset >/dev/null 2>&1");
272+
if (ret == -1 || WEXITSTATUS(ret) != 0)
273+
{
274+
RARCH_LOG("[X11] xdg-screensaver or xset not available; screensaver suspension disabled.\n");
275+
return false;
276+
}
277+
return true;
278+
}
279+
262280
static void xdg_screensaver_inhibit(Window wnd)
263281
{
264282
int ret;
@@ -312,6 +330,14 @@ bool x11_suspend_screensaver(void *data, bool enable)
312330
{
313331
if (xdg_screensaver_available)
314332
{
333+
static bool probed = false;
334+
if (!probed)
335+
{
336+
xdg_screensaver_available = xdg_screensaver_probe();
337+
probed = true;
338+
}
339+
if (!xdg_screensaver_available)
340+
return true;
315341
xdg_screensaver_inhibit(wnd);
316342
return xdg_screensaver_available;
317343
}

0 commit comments

Comments
 (0)