aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/wallp.bats25
-rw-r--r--wallp28
2 files changed, 53 insertions, 0 deletions
diff --git a/tests/wallp.bats b/tests/wallp.bats
index 52e6706..f8ea2d7 100644
--- a/tests/wallp.bats
+++ b/tests/wallp.bats
@@ -154,3 +154,28 @@ teardown() {
[ "$status" -eq 1 ]
[[ "$output" == *"Z="* ]]
}
+
+@test "apply_output skips missing file without writing pid" {
+ CONF_OUTPUT_H="DP-1"
+ run apply_output H "$HOME/nope.png"
+ [ "$status" -eq 1 ]
+ [ ! -e "$HOME/.cache/wallp/H.pid" ]
+}
+
+@test "apply_output sets swaybg and persists path" {
+ CONF_OUTPUT_H="DP-1"
+ : > "$HOME/real.png"
+ apply_output H "$HOME/real.png"
+ [ "$?" -eq 0 ]
+ [ "$(cat "$HOME/.config/wallp/wall_h")" = "$HOME/real.png" ]
+ [ -f "$HOME/.cache/wallp/H.pid" ]
+ grep -q "swaybg -o DP-1 -i $HOME/real.png" "$HOME/calls.log"
+}
+
+@test "apply_output on V does not touch H pid" {
+ CONF_OUTPUT_H="DP-1"; CONF_OUTPUT_V="DP-3"
+ mkdir -p "$HOME/.cache/wallp"; echo 99999 > "$HOME/.cache/wallp/H.pid"
+ : > "$HOME/v.png"
+ apply_output V "$HOME/v.png"
+ [ "$(cat "$HOME/.cache/wallp/H.pid")" = "99999" ]
+}
diff --git a/wallp b/wallp
index 128a155..4d22e8a 100644
--- a/wallp
+++ b/wallp
@@ -135,6 +135,34 @@ parse_set_args() {
return 0
}
+# Kill the swaybg recorded for a logical output, if its PID is still alive.
+kill_output() {
+ local logical="$1" pf pid; pf="$(pid_file_for "$logical")"
+ [ -f "$pf" ] || return 0
+ pid="$(cat "$pf")"
+ if [ -n "$pid" ] && kill -0 "$pid" 2>/dev/null; then
+ kill "$pid" 2>/dev/null
+ fi
+ rm -f "$pf"
+}
+
+# apply_output <H|V> <file>: set wallpaper for one output. rc1 = skipped.
+apply_output() {
+ local logical="$1" file="$2" output pf wf
+ if [ ! -f "$file" ]; then
+ echo "wallp: file not found, skipping $logical: $file" >&2
+ return 1
+ fi
+ output="$(output_for "$logical")" || return 1
+ kill_output "$logical"
+ swaybg -o "$output" -i "$file" -m fill &
+ pf="$(pid_file_for "$logical")"; mkdir -p "$(dirname "$pf")"
+ printf '%s\n' "$!" > "$pf"
+ wf="$(wall_file_for "$logical")"; mkdir -p "$(dirname "$wf")"
+ printf '%s\n' "$file" > "$wf"
+ return 0
+}
+
main() {
return 0
}