[lock,idle] Fixes the swaylock script to work for multiple monitors and fixes it's invocation

This commit is contained in:
2025-05-28 23:13:24 -07:00
parent 5299c6d72c
commit 07123a0fc2
3 changed files with 19 additions and 4 deletions

View File

@@ -4,7 +4,7 @@
enable = true; enable = true;
settings = { settings = {
general = { general = {
lock_cmd = "pidof swaylock || swaylock"; # avoid starting multiple lock instances. lock_cmd = "pidof swaylock || ~/.config/swaylock/swaylock.sh"; # avoid starting multiple lock instances.
before_sleep_cmd = "loginctl lock-session"; # lock before suspend. before_sleep_cmd = "loginctl lock-session"; # lock before suspend.
after_sleep_cmd = "hyprctl dispatch dpms on"; # to avoid having to press a key twice to turn on the display. after_sleep_cmd = "hyprctl dispatch dpms on"; # to avoid having to press a key twice to turn on the display.
}; };

View File

@@ -12,12 +12,26 @@
home.file.".config/swaylock/swaylock.sh" = { home.file.".config/swaylock/swaylock.sh" = {
executable = true; executable = true;
# A script that will take the wallpaper folder for each monitor (see
# wallpaper.nix) and use a random image as the background on each monitor.
text = '' text = ''
#!/bin/env bash #!/usr/bin/env sh
image=`fd . ~/Pictures/Wallpaper --type f | sort -R | tail -1` wallpaper_dir="$HOME/Pictures/Wallpaper"
cmd="swaylock"
swaylock --image "$image" for monitor in $(hyprctl monitors | awk '/^Monitor/ { print $2 }'); do
dir="$wallpaper_dir/$monitor"
if [ -d "$dir" ]; then
image=$(find "$dir" -type f | shuf -n 1)
if [ -n "$image" ]; then
cmd="$cmd --image \"$monitor:$image\""
fi
fi
done
# Eval to handle the quoted image paths correctly
eval $cmd
''; '';
}; };
} }

View File

@@ -12,6 +12,7 @@ monitors:
map (mon: { map (mon: {
name = mon; name = mon;
value = { value = {
# Each monitor gets a folder under wallpaper that containes the current images.
path = "~/Pictures/Wallpaper/${mon}"; path = "~/Pictures/Wallpaper/${mon}";
}; };
}) monitors }) monitors