From 07123a0fc2be3aa5938ba4961aac5bd4f316d98f Mon Sep 17 00:00:00 2001 From: Drew Haven Date: Wed, 28 May 2025 23:13:24 -0700 Subject: [PATCH] [lock,idle] Fixes the swaylock script to work for multiple monitors and fixes it's invocation --- home-manager/features/hypr/hypridle.nix | 2 +- home-manager/features/swaylock.nix | 20 +++++++++++++++++--- home-manager/features/wallpaper.nix | 1 + 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/home-manager/features/hypr/hypridle.nix b/home-manager/features/hypr/hypridle.nix index 553b36c..19f5e10 100644 --- a/home-manager/features/hypr/hypridle.nix +++ b/home-manager/features/hypr/hypridle.nix @@ -4,7 +4,7 @@ enable = true; settings = { 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. after_sleep_cmd = "hyprctl dispatch dpms on"; # to avoid having to press a key twice to turn on the display. }; diff --git a/home-manager/features/swaylock.nix b/home-manager/features/swaylock.nix index 2d5eb6a..403e373 100644 --- a/home-manager/features/swaylock.nix +++ b/home-manager/features/swaylock.nix @@ -12,12 +12,26 @@ home.file.".config/swaylock/swaylock.sh" = { 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 = '' - #!/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 ''; }; } diff --git a/home-manager/features/wallpaper.nix b/home-manager/features/wallpaper.nix index 0f167be..62dcbba 100644 --- a/home-manager/features/wallpaper.nix +++ b/home-manager/features/wallpaper.nix @@ -12,6 +12,7 @@ monitors: map (mon: { name = mon; value = { + # Each monitor gets a folder under wallpaper that containes the current images. path = "~/Pictures/Wallpaper/${mon}"; }; }) monitors