#!/bin/sh
# Rikkiti lock screen — a thin chooser. Prefer our native Skald locker
# (rikkiti-locker: ext-session-lock-v1 + PAM, themed from the live accent); fall
# back to accent-themed swaylock if it's not installed or fails to take the lock.
# swayidle / loginctl lock-session / the panel Lock button all run THIS script.
if command -v rikkiti-locker >/dev/null 2>&1; then
	# A non-zero exit means it couldn't acquire the lock (e.g. another locker is
	# already active) — in that case do NOT fall through to swaylock, the screen
	# is already guarded. Only fall back when the binary is genuinely missing.
	rikkiti-locker
	exit 0
fi

# ---- fallback: swaylock themed from the Rikkiti accent (appearance.conf) -----
ap="$HOME/.config/rikkiti/appearance.conf"
accent="3399ff"; dark=1
if [ -f "$ap" ]; then
	a=$(grep -E '^[[:space:]]*accent[[:space:]]*=' "$ap" | tail -1 | sed 's/.*=//; s/[[:space:]]//g; s/^#//')
	[ -n "$a" ] && accent="$a"
	grep -qiE '^[[:space:]]*dark[[:space:]]*=[[:space:]]*(false|0|no)' "$ap" && dark=0
fi
if [ "$dark" = 1 ]; then bg=1e1e2e; txt=cdd6f4; else bg=eff1f5; txt=4c4f69; fi
exec swaylock -f \
	--color "$bg" \
	--inside-color "${bg}cc" \
	--ring-color "$accent" \
	--key-hl-color "$accent" \
	--bs-hl-color ff5555 \
	--line-color 00000000 \
	--separator-color 00000000 \
	--text-color "$txt" \
	--ring-ver-color "$accent" \
	--ring-wrong-color ff5555 \
	--indicator-radius 90 \
	--indicator-thickness 8 \
	"$@"
