summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsinanmohd <sinan@firemail.cc>2023-05-10 23:12:18 +0530
committersinanmohd <sinan@firemail.cc>2023-05-10 23:12:18 +0530
commitb878cc923fe7132f667a73c19e8db628869ceb8d (patch)
tree370ef3984b34aaba9946d9a6497d3bd52abddd44
parentef2f0f53c8f60e9329508fb89e195a3ba72075c9 (diff)
cwall: initial commit
a helper script for swaybg
-rwxr-xr-x.config/wayland/winit3
-rwxr-xr-x.local/bin/cwall67
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 "$@"