Files
nixos/apps/hyprlock/default.nix
T
2026-01-01 11:25:54 -06:00

168 lines
4.0 KiB
Nix

{ config, pkgs, ... }:
let
cacheWallpaper = "${config.home.homeDirectory}/.cache/current_wallpaper";
clockFont = "JetBrains Mono";
typewriter = pkgs.writeShellScript "hyprlock-typewriter" ''
text=""
state_file="/tmp/hyprlock_typewriter"
lock_pid="/tmp/hyprlock_pid"
blink_file="/tmp/hyprlock_blink"
# Get current hyprlock PID
current_pid=$(pgrep -x hyprlock | head -1)
# Reset if this is a new hyprlock session
if [ -f "$lock_pid" ]; then
old_pid=$(cat "$lock_pid")
if [ "$current_pid" != "$old_pid" ]; then
rm -f "$state_file" "$blink_file"
echo "$current_pid" > "$lock_pid"
fi
else
echo "$current_pid" > "$lock_pid"
fi
# Initialize position
if [ ! -f "$state_file" ]; then
echo 0 > "$state_file"
fi
pos=$(cat "$state_file")
len=''${#text}
# Increment position only if not complete
if [ "$pos" -lt "$len" ]; then
pos=$((pos + 1))
echo "$pos" > "$state_file"
echo "''${text:0:$pos}_"
else
# Blink cursor via foreground color toggle (slow blink)
if [ ! -f "$blink_file" ]; then
echo "0 0" > "$blink_file"
fi
read -r blink count < "$blink_file"
count=$((count + 1))
# Toggle every 5 updates (~600ms at 120ms interval)
if [ "$count" -ge 5 ]; then
count=0
blink=$((1 - blink))
fi
echo "$blink $count" > "$blink_file"
if [ "$blink" -eq 0 ]; then
echo "''${text}_"
else
echo "''${text}<span fgalpha=\"1\">_</span>"
fi
fi
'';
in {
programs.hyprlock = {
enable = true;
extraConfig = ''
source = ~/.config/hypr/hyprlock-colors.conf
general {
hide_cursor = true
grace = 0
}
background {
monitor =
path = ${cacheWallpaper}
blur_passes = 3
blur_size = 8
contrast = 0.9
brightness = 0.7
vibrancy = 0.2
}
# Typewriter greeting (above clock)
label {
monitor =
text = cmd[update:200] ${typewriter}
color = $on_surface_variant
font_size = 24
font_family = ${clockFont}
position = 0, 200
halign = center
valign = center
}
# Hours (top)
label {
monitor =
text = cmd[update:1000] date +%H
color = $on_surface
font_size = 140
font_family = ${clockFont} Bold
position = 0, 80
halign = center
valign = center
}
# Minutes (bottom)
label {
monitor =
text = cmd[update:1000] date +%M
color = $primary
font_size = 140
font_family = ${clockFont} Bold
position = 0, -80
halign = center
valign = center
}
# Date
label {
monitor =
text = cmd[update:60000] date '+%A, %B %d'
color = $on_surface_variant
font_size = 18
font_family = ${clockFont}
position = 0, -320
halign = center
valign = center
}
# Caps Lock indicator (above input)
label {
monitor =
text = cmd[update:100] cat /sys/class/leds/*capslock*/brightness 2>/dev/null | grep -q 1 && echo 'CAPS LOCK'
color = $tertiary
font_size = 12
font_family = ${clockFont}
position = 0, -210
halign = center
valign = center
}
input-field {
monitor =
size = 300, 50
outline_thickness = 3
dots_size = 0.33
dots_spacing = 0.15
dots_center = true
outer_color = $primary
inner_color = $surface
font_color = $on_surface
fade_on_empty = false
placeholder_text = <i>Password...</i>
hide_input = false
rounding = 15
position = 0, -250
halign = center
valign = center
# Auth feedback
check_color = $secondary
fail_color = $error
fail_text = <i>$FAIL</i> <b>($ATTEMPTS)</b>
fail_timeout = 2000
fail_transition = 300
}
'';
};
}