diff options
-rwxr-xr-x | .config/wayland/winit | 3 | ||||
-rwxr-xr-x | .local/bin/cwall | 67 |
2 files changed, 69 insertions, 1 deletions
diff --git a/.config/wayland/winit b/.config/wayland/winit index 1423d45..42f2c19 100755 --- a/.config/wayland/winit +++ b/.config/wayland/winit @@ -1,7 +1,8 @@ #!/bin/sh # background -swaybg -m fill -i "${XDG_DATA_HOME:-$HOME/.local/share}/wall" & +swaybg -m fill -i "${XDG_DATA_HOME:-$HOME/.local/share}/wallpaper" & +echo $! > "${XDG_RUNTIME_DIR:-${TMPDIR:-/tmp}}/swaybg.pid" & # notification deamon mako & diff --git a/.local/bin/cwall b/.local/bin/cwall new file mode 100755 index 0000000..49c11de --- /dev/null +++ b/.local/bin/cwall @@ -0,0 +1,67 @@ +#!/bin/sh + +bgpid="${XDG_RUNTIME_DIR:-${TMPDIR:-/tmp}}/swaybg.pid" +bgroot="${XDG_DATA_HOME:-$HOME/.local/share}" +bgimg="${bgroot}/wallpaper" + +die() +{ + printf "\033[31;1merr: %b\033[0m\n" "${1:-no args for die()}" 1>&2 + exit "${2:-1}" +} + +usage() +{ + cat <<- EOF + Usage: ${0##*/} [wallpaper.img] + A helper script for swaybg + + EOF +} + +dep_check() +{ + # usage: cmd_check cmd_1 ... + : "${1:?}" + + for dep; do + command -v "$dep" 1>/dev/null || + die "${dep}: command not found" 127 + done + + unset dep +} + +updatewall() +{ + : "${1:?}" + + rm -f "$bgimg" + cp "$1" "$bgimg" + + [ -s "$bgpid" ] && + kill "$(cat "$bgpid")" + swaybg --mode fill --image "$bgimg" > /dev/null 2>&1 & + echo $! > "$bgpid" +} + +main() +{ + [ ! -r "$1" ] && + usage && exit 1; + [ ! -d "$bgroot" ] && + mkdir -p "$bgroot" + + dep_check swaybg file + + case "$(file --brief --dereference --mime-type "$1")" in + "image/"*) + updatewall "$1" + ;; + *) + die "invalid image file" + ;; + esac +} + +main "$@" |