swaywm / swaybg

Wallpaper tool for Wayland compositors
MIT License
490 stars 31 forks source link

Support reloading image via SIGUSR? #64

Open ieugen opened 7 months ago

ieugen commented 7 months ago

Hello,

Would it make sense to support reloading the image / reset swaybg via sending a SIGUSR signal?

Currently I use a process like this:

Inspired by https://sylvaindurand.org/dynamic-wallpapers-with-sway/

#!/bin/sh
PID=`pidof swaybg`
swaybg -i $HOME/.config/sway/background-image -m fill &
sleep 1
kill -9 $PID

I have another script that randomly replaces, every hour, the symbolic link that I have at $HOME/.config/sway/background-image .

The issue with the above solution is that it sometimes fails and I get a grey screen. Don't know why.

ieugen commented 7 months ago

I think I found a solution using systemd to manage the process instead.

save this as ~/.config/systemd/user/swaybg.service

[Unit]
Description=Display swaywm background image

[Service]
ExecStart=swaybg -i /home/ieugen/.config/sway/background-image -m fill

[Install]
WantedBy=default.target
# Then install the service
systemct --user enable swaybg.service
# And then to reload, sympli restart the service
systemct --user restart swaybg.service

Feel free to use the text above, add it to docs if you think it's valuable. Or I could send a PR.

For completion, this is what I use to randomly choose an image from my collection: ~/.local/bin/random-background-image.sh

#!/bin/sh

export NEW_IMG="$(find $HOME/Poze/Imagini.fundal -type f | shuf -n1)"
echo "Using new backgruond image $NEW_IMG"
ln -sf "$NEW_IMG" /home/ieugen/.config/sway/background-image