diff --git a/data/man/man1/wal.1 b/data/man/man1/wal.1 index 7a2919d..d42fc11 100644 --- a/data/man/man1/wal.1 +++ b/data/man/man1/wal.1 @@ -219,8 +219,27 @@ under the same name. Using this feature you can also overwrite the default expor The section for other important information to using pywal16 that does not fit a specific section. .TP -.B "XDG_SESSION_TYPE" -This env var is needed to set the wallpaper when running an environment consisting of a standalone x11 window manager or wayland compositor, ie not a full blown desktop environment, for example something like the i3 window manager or the sway compositor, this is because some setup may have the packages for (in this example) BOTH i3 and sway, so in previous releases swaybg would be ran as wallpaper setter regardless of the user running i3 or sway, now we check this env var and follow the corresponding chain of possible wallpaper setters. +.B "XDG_SESSION_TYPE, DISPLAY, WAYLAND_DISPLAY" +The +.B XDG_SESSION_TYPE +env var is needed to set the wallpaper when running an environment consisting of a standalone x11 window manager or wayland compositor (i.e. not a full desktop environment). +If +.B XDG_SESSION_TYPE +is not available the +.B DISPLAY +and +.B WAYLAND_DISPLAY +vars are used as fallback to detect the active display protocol. This avoids relying only on +.B XDG_SESSION_TYPE +which may be set to "tty" on some setups (for example when starting X manually with startx) or not set at all. If +.B WAYLAND_DISPLAY +is set, the session is treated as Wayland. If +.B DISPLAY +is set (and +.B WAYLAND_DISPLAY +is not), the session is treated as X11. + +This is necessary because some setup may have the packages for (example) BOTH i3 and sway, so in previous releases swaybg had priority over feh and would be ran as wallpaper setter regardless of the user currently running i3 or sway, these checks allow us to follow the corresponding chain of possible wallpaper setters. .TP .B "ImageMagick 7 Policy" diff --git a/pywal/wallpaper.py b/pywal/wallpaper.py index 11c1762..99fca99 100644 --- a/pywal/wallpaper.py +++ b/pywal/wallpaper.py @@ -44,6 +44,17 @@ def get_desktop_env(): return None +def detect_display_protocol(): + """Detect the active display protocol (X11 or Wayland).""" + if os.environ.get("WAYLAND_DISPLAY"): + return "wayland" + + if os.environ.get("DISPLAY") and not os.environ.get("WAYLAND_DISPLAY"): + return "x11" + + return None + + def xfconf(img): """Call xfconf to set the wallpaper on XFCE.""" xfconf_re = re.compile( @@ -73,6 +84,21 @@ def xfconf(img): def set_wm_wallpaper(img): """Set the wallpaper for non desktop environments.""" session_type = os.getenv('XDG_SESSION_TYPE') + if not session_type: + logging.error( + "The XDG_SESSION_TYPE env var is not set " + "falling back to Display protocol detection." + ) + session_type = detect_display_protocol() + + if not session_type: + logging.error( + "Display protocol could not be determined. " + "Detection requires either WAYLAND_DISPLAY (for Wayland) " + "or DISPLAY (for X11) environment variables to be set. " + "Only x11 and wayland display protocols are supported." + ) + if session_type == "x11": # setters for x11 if shutil.which("feh"): @@ -117,18 +143,14 @@ def set_wm_wallpaper(img): logging.error("No wallpaper setter found.") return - else: - if session_type: - logging.error( - "Wallpaper setting not supported for" - f" '{session_type}' session type." - ) - else: - logging.error("Cannot set wallpaper for this session.") + elif session_type: logging.error( - "Check XDG_SESSION_TYPE is set correctly" - " only x11 and wayland session types are supported." - ) + "Wallpaper setting not supported for" + f" '{session_type}' session type." + ) + else: + logging.error("Cannot set wallpaper for this session.") + return