feat(scripts): enable plock to use Caelestia’s lock screen

This commit also adds the wlr-which-key shortcut for plock.
This commit is contained in:
2026-01-25 16:19:09 +01:00
parent a35d536b75
commit b8ed5984df
2 changed files with 31 additions and 1 deletions

View File

@@ -1,16 +1,40 @@
{pkgs, ...}: {pkgs, ...}:
pkgs.writeShellScriptBin "plock" '' pkgs.writeShellScriptBin "plock" ''
LOG_FILE="$HOME/.local/share/plock.log"
logger() {
local level="$1"
local message="$2"
local timestamp
timestamp=$(date +"%Y-%m-%d %H:%M:%S")
printf "[%s] [%-7s] %s\n" "$timestamp" "''${level^^}" "$message" >> "$LOG_FILE"
}
CAELESTIA_ACTIVE=$(systemctl --user is-active caelestia.service)
logger debug "Caelestia activity: $CAELESTIA_ACTIVE"
if systemctl --user is-active caelestia.service | grep 'active' &> /dev/null ; then
logger info "locking Caelestia session"
caelestia shell lock lock || \
logger error "failed to lock Caelestia session"
exit 0
fi
TMPBG="/tmp/screen.png" TMPBG="/tmp/screen.png"
if [ "$XDG_SESSION_TYPE" = "wayland" ]; then if [ "$XDG_SESSION_TYPE" = "wayland" ]; then
logger info "wayland session detected"
SCREENER=${pkgs.grim}/bin/grim SCREENER=${pkgs.grim}/bin/grim
LOCKER="${pkgs.swaylock}/bin/swaylock -feF" LOCKER="${pkgs.swaylock}/bin/swaylock -feF"
else else
logger info "x11 session detected"
SCREENER=${pkgs.scrot}/bin/scrot SCREENER=${pkgs.scrot}/bin/scrot
LOCKER="${pkgs.i3lock}/bin/i3lock -ef" LOCKER="${pkgs.i3lock}/bin/i3lock -ef"
fi fi
$SCREENER "$TMPBG" $SCREENER "$TMPBG"
${pkgs.corrupter}/bin/corrupter -add 0 "$TMPBG" "$TMPBG" logger info "generating lock screen image"
${pkgs.corrupter}/bin/corrupter -add 0 "$TMPBG" "$TMPBG" || logger error "failed to generate lock screen image"
logger info "locking screen"
logger debug "locking screen with command `''${SCREENER}`"
$LOCKER -ti "$TMPBG" $LOCKER -ti "$TMPBG"
rm "$TMPBG" rm "$TMPBG"
'' ''

View File

@@ -26,6 +26,7 @@
fullscreen = import ./fullscreen.nix {inherit pkgs;}; fullscreen = import ./fullscreen.nix {inherit pkgs;};
logout = import ./logout.nix {inherit pkgs;}; logout = import ./logout.nix {inherit pkgs;};
ytplay = import ../../modules/cli/scripts/ytplay.nix {inherit pkgs;}; ytplay = import ../../modules/cli/scripts/ytplay.nix {inherit pkgs;};
plock = import ../../modules/cli/scripts/plock.nix {inherit pkgs;};
in [ in [
{ {
key = "a"; key = "a";
@@ -165,6 +166,11 @@
} }
]; ];
} }
{
key = "l";
desc = "Lock session";
cmd = "${plock}/bin/plock";
}
{ {
key = "p"; key = "p";
desc = "Power"; desc = "Power";