2023-06-12 00:43:16 +02:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
let
|
|
|
|
inherit (lib)
|
|
|
|
singleton
|
|
|
|
getExe
|
|
|
|
makeBinPath;
|
|
|
|
|
|
|
|
locker = pkgs.writeShellScript "i3lock-dynamic-image" ''
|
2023-06-12 14:30:04 +02:00
|
|
|
export PATH=${makeBinPath (with pkgs; [ xorg.xrandr gnugrep coreutils imagemagick i3lock ])}:$PATH
|
2023-06-12 00:43:16 +02:00
|
|
|
|
|
|
|
WALLPAPER_CACHE="$HOME/.local/tmp/wallpaper_cache"
|
|
|
|
|
|
|
|
mkdir -p $WALLPAPER_CACHE
|
|
|
|
|
2023-06-12 14:30:04 +02:00
|
|
|
SCREEN_RESOLUTION="$(xrandr --current | grep '*' | uniq | tr -s ' ' | cut -f2 -d' ' | sort -nr | head -n 1)"
|
2023-06-12 00:43:16 +02:00
|
|
|
IMAGEFILE="$WALLPAPER_CACHE/$(sha256sum $HOME/.config/wallpaper | tr -s ' ' | cut -f 1 -d' ').png"
|
2023-06-12 14:30:04 +02:00
|
|
|
I3LOCK="i3lock -t -d -c 000000 -i $IMAGEFILE"
|
2023-06-12 00:43:16 +02:00
|
|
|
|
|
|
|
if ! [[ -e "$IMAGEFILE" ]]
|
|
|
|
then
|
2023-06-12 01:06:16 +02:00
|
|
|
convert "$HOME/.config/wallpaper" -gravity Center -background "#000000" -resize "$SCREEN_RESOLUTION^" -extent "$SCREEN_RESOLUTION" "$IMAGEFILE"
|
2023-06-12 00:43:16 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -e /dev/fd/''${XSS_SLEEP_LOCK_FD:--1} ]]; then
|
|
|
|
kill_i3lock() {
|
|
|
|
pkill -xu $EUID "$@" i3lock
|
|
|
|
}
|
|
|
|
|
|
|
|
trap kill_i3lock TERM INT
|
|
|
|
|
|
|
|
$I3LOCK {XSS_SLEEP_LOCK_FD}<&-
|
|
|
|
|
|
|
|
exec {XSS_SLEEP_LOCK_FD}<&-
|
|
|
|
|
|
|
|
while kill_i3lock -0; do
|
|
|
|
sleep 0.5
|
|
|
|
done
|
|
|
|
else
|
|
|
|
trap 'kill %%' TERM INT
|
|
|
|
$I3LOCK
|
|
|
|
wait
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
in
|
|
|
|
{
|
|
|
|
services.screen-locker = {
|
|
|
|
enable = true;
|
|
|
|
inactiveInterval = 5;
|
|
|
|
|
|
|
|
xss-lock.extraOptions = singleton "--transfer-sleep-lock";
|
|
|
|
|
|
|
|
lockCmd = toString locker;
|
|
|
|
};
|
|
|
|
}
|