feat: ask which lock screen to use on hyprland and niri

This commit is contained in:
Felitendo committed 2026-09-26 19:37:06 +02:00
1 parent 5699158bb1
commit 1da82f21fc
34 files changed
+5319 -1609

No files matched your search

+123
View File
@@ -193,6 +193,129 @@ fu_gnome_extension_disable() {
gsettings set org.gnome.shell enabled-extensions "$list" > /dev/null 2>&1 || true
}
# ---------------------------------------------------------------------------
# The lock screen where it is a program of its own (Hyprland, Niri)
# ---------------------------------------------------------------------------
# Either face-unlock's (`face-unlock lock`, with the bubble), or the user's
# own program. hyprlock then shows what the bubble would as a line of text: a
# label in its config reads a file the agent writes (see
# src/agent/locktext.h). Asked once in a window, and under Settings.
FU_HYPRLOCK_SNIPPET="$FU_XDG_CONFIG/$FU_NAME/hyprlock.conf"
FU_HYPRLOCK_MARK="# $FU_NAME: what face unlock is doing, at the top"
fu_own_lock_here() {
[[ $FU_DESKTOP != plasma && $FU_DESKTOP != gnome ]]
}
# fu_hyprlock_text_on
# 0 done, 1 could not write, 2 no hyprlock, 3 hyprlock has no config here.
fu_hyprlock_text_on() {
local conf="$FU_XDG_CONFIG/hypr/hyprlock.conf"
fu_have hyprlock || return 2
[[ -f $conf ]] || return 3
mkdir -p "${FU_HYPRLOCK_SNIPPET%/*}" || return 1
cat > "$FU_HYPRLOCK_SNIPPET" <<- EOF || return 1
# Written by $FU_NAME: what face unlock is doing, as a line at the top of
# hyprlock. Picking $FU_NAME's lock screen in its menu takes it out again.
label {
monitor =
text = cmd[update:0:1] cat "\$XDG_RUNTIME_DIR/$FU_NAME/lock-text" 2>/dev/null
color = rgba(255, 255, 255, 0.95)
font_size = 20
shadow_passes = 2
shadow_size = 3
halign = center
valign = top
position = 0, -48
zindex = 10
}
EOF
grep -qxF "$FU_HYPRLOCK_MARK" "$conf" && return 0
# With ~ where it can, like a hand-written config. hyprlock expands it.
local snippet="$FU_HYPRLOCK_SNIPPET"
# shellcheck disable=SC2088 # for hyprlock, not for the shell
[[ $snippet == "$HOME"/* ]] && snippet="~/${snippet#"$HOME"/}"
printf '\n%s\nsource = %s\n' "$FU_HYPRLOCK_MARK" "$snippet" >> "$conf" || return 1
}
# fu_hyprlock_text_off
# The mark, the source line under it, and the empty lines before it. Written
# back in place, so a hyprlock.conf that is a link to a dotfile stays one.
fu_hyprlock_text_off() {
local conf="$FU_XDG_CONFIG/hypr/hyprlock.conf" content
rm -f "$FU_HYPRLOCK_SNIPPET"
[[ -f $conf ]] && grep -qxF "$FU_HYPRLOCK_MARK" "$conf" || return 0
content="$(awk -v mark="$FU_HYPRLOCK_MARK" '
$0 == mark { held = ""; skip = 1; next }
skip && /^[[:space:]]*source[[:space:]]*=/ { skip = 0; next }
{ skip = 0 }
/^[[:space:]]*$/ { held = held $0 "\n"; next }
{ printf "%s", held; held = ""; print }
' "$conf")" || return 1
printf '%s\n' "$content" > "$conf"
}
# fu_own_lock_hint
# Where face-unlock's lock screen has to be started from: the user's key and
# idle lock, which are theirs to change.
fu_own_lock_hint() {
# shellcheck disable=SC2088 # shown to the user, not a path to open
case "$FU_DESKTOP" in
hyprland)
if [[ -f $FU_XDG_CONFIG/hypr/hyprland.lua ]]; then
fu_note "$(fu_msg "To lock with it, add this to %s, and set %s in %s:" "~/.config/hypr/hyprland.lua" "lock_cmd = $FU_NAME lock" "hypridle.conf")"
fu_code "hl.bind(\"SUPER + L\", hl.dsp.exec_cmd(\"$FU_NAME lock\"))"
else
fu_note "$(fu_msg "To lock with it, add this to %s, and set %s in %s:" "~/.config/hypr/hyprland.conf" "lock_cmd = $FU_NAME lock" "hypridle.conf")"
fu_code "bind = SUPER, L, exec, $FU_NAME lock"
fi
;;
niri)
fu_note "$(fu_msg "To lock with it, add this to the binds in %s, and use %s in swayidle:" "~/.config/niri/config.kdl" "$FU_NAME lock")"
fu_code "Mod+Alt+L { spawn \"$FU_NAME\" \"lock\"; }"
;;
*)
fu_note "$(fu_msg "To lock with it, run %s where your lock screen is started now." "$FU_NAME lock")"
;;
esac
}
# fu_lock_style_set <own|yours>
fu_lock_style_set() {
# shellcheck disable=SC2088 # shown to the user, not a path to open
local conf="~/.config/hypr/hyprlock.conf"
case "$1" in
own)
fu_config_set LockScreenStyle own || { fu_bad "$(fu_msg "Could not save the setting.")"; return 1; }
fu_hyprlock_text_off
fu_ok "$(fu_msg "You lock with face-unlock's lock screen now.")"
fu_own_lock_hint
;;
yours)
fu_config_set LockScreenStyle yours || { fu_bad "$(fu_msg "Could not save the setting.")"; return 1; }
fu_hyprlock_text_on
case $? in
0) fu_ok "$(fu_msg "hyprlock shows what face unlock is doing at the top, from the next time it locks.")" ;;
1) fu_bad "$(fu_msg "Could not add the line to %s." "$conf")" ;;
2) fu_ok "$(fu_msg "Your lock screen stays as it is. Press Enter on the empty password field to scan.")" ;;
3) fu_note "$(fu_msg "hyprlock has no %s, so it cannot show the text." "$conf")" ;;
esac
;;
*) return 1 ;;
esac
}
# fu_lock_choose
# Asks in a window which lock screen to use, and carries it out. 1 when the
# window was closed or cannot open.
fu_lock_choose() {
local choice
[[ -n ${WAYLAND_DISPLAY:-} ]] || return 1
choice="$("$FU_AGENT" --choose-lock-screen 2> /dev/null)" || return 1
fu_lock_style_set "$choice"
}
fu_agent_disable() {
systemctl --user disable --now "$FU_UNIT_AGENT" > /dev/null 2>&1 || true
}