Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions data/man/man1/wal.1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
44 changes: 33 additions & 11 deletions pywal/wallpaper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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"):
Expand Down Expand Up @@ -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


Expand Down