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 79a8efb45c 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.
This commit is contained in:
Peter Harris 2022-12-29 17:45:31 -05:00
parent 96bd4e57b5
commit 361be0b5a1

View file

@ -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;