dotfiles/home-manager/modules/screenlocker/default.nix
Magic_RB dd559bfcf0 Fix imagemagick's convert not behaving exactly like feh
Signed-off-by: Magic_RB <magic_rb@redalder.org>
2023-06-16 16:08:09 +02:00

55 lines
1.3 KiB
Nix

{ config, pkgs, lib, ... }:
let
inherit (lib)
singleton
getExe
makeBinPath;
locker = pkgs.writeShellScript "i3lock-dynamic-image" ''
export PATH=${makeBinPath (with pkgs; [ gnugrep coreutils xorg.xdpyinfo imagemagick i3lock ])}:$PATH
WALLPAPER_CACHE="$HOME/.local/tmp/wallpaper_cache"
mkdir -p $WALLPAPER_CACHE
SCREEN_RESOLUTION="$(xdpyinfo | grep dimensions | cut -d' ' -f7)"
IMAGEFILE="$WALLPAPER_CACHE/$(sha256sum $HOME/.config/wallpaper | tr -s ' ' | cut -f 1 -d' ').png"
I3LOCK="i3lock -d -c 000000 -i $IMAGEFILE"
if ! [[ -e "$IMAGEFILE" ]]
then
convert "$HOME/.config/wallpaper" -gravity Center -background "#000000" -resize "$SCREEN_RESOLUTION^" -extent "$SCREEN_RESOLUTION" "$IMAGEFILE"
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;
};
}