From 361be0b5a161eb9f5a4d34d993243daae92c13c0 Mon Sep 17 00:00:00 2001 From: Peter Harris Date: Thu, 29 Dec 2022 17:45:31 -0500 Subject: [PATCH] client-conf: Check XDG_SESSION_TYPE If systemd is in use, the XDG_SESSION_TYPE will probably be set (usually to "wayland", "x11", or "tty"). If XDG_SESSION_TYPE is set to something other than "wayland", connect to the X11 server to request properties. Commit 79a8efb45cb8304967baa2e8c6d6156478ce19d9 stopped connecting to the X server unless SSH_CONNECTION is set in the environment, to avoid launching a useless xwayland process. However, there are many more circumstances in which a remote X server may be in use. For example, XDMCP or VNC. This does not completely fix #1412, but it does improve the situation. --- src/pulse/client-conf-x11.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/pulse/client-conf-x11.c b/src/pulse/client-conf-x11.c index e0c985e80..65d0ca896 100644 --- a/src/pulse/client-conf-x11.c +++ b/src/pulse/client-conf-x11.c @@ -43,14 +43,22 @@ int pa_client_conf_from_x11(pa_client_conf *c) { pa_assert(c); - /* Local connections will have configuration and X root window - * properties match 1:1, these paths are only strictly necessary - * for remote clients, so check for SSH_CONNECTION to make sure - * this is a remote session with X forwarding. + /* Xwayland is expensive to start. Do not check for X11 properties + * if the session is primarily a Wayland session */ - if (!getenv("SSH_CONNECTION")) + const char *xdg_session_type = getenv("XDG_SESSION_TYPE"); + if (xdg_session_type && !strcmp(xdg_session_type, "wayland")) goto finish; + if (!xdg_session_type) { + /* If XDG_SESSION_TYPE is not set, it might still be a wayland session + * running under an older systemd (or not running under systemd at all). + * Only check X11 properties if we're running under ssh. + */ + if (!getenv("SSH_CONNECTION")) + goto finish; + } + if (!(dname = getenv("DISPLAY"))) goto finish;