From b8ed5984df8d06799391781b44d3e8edf33ffc4f Mon Sep 17 00:00:00 2001 From: Lucien Cartier-Tilet Date: Sun, 25 Jan 2026 16:19:09 +0100 Subject: [PATCH] =?UTF-8?q?feat(scripts):=20enable=20plock=20to=20use=20Ca?= =?UTF-8?q?elestia=E2=80=99s=20lock=20screen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit also adds the wlr-which-key shortcut for plock. --- users/modules/cli/scripts/plock.nix | 26 +++++++++++++++++++++++- users/phundrak/wlr-which-key/default.nix | 6 ++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/users/modules/cli/scripts/plock.nix b/users/modules/cli/scripts/plock.nix index 7c17991..bde9997 100644 --- a/users/modules/cli/scripts/plock.nix +++ b/users/modules/cli/scripts/plock.nix @@ -1,16 +1,40 @@ {pkgs, ...}: 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" if [ "$XDG_SESSION_TYPE" = "wayland" ]; then + logger info "wayland session detected" SCREENER=${pkgs.grim}/bin/grim LOCKER="${pkgs.swaylock}/bin/swaylock -feF" else + logger info "x11 session detected" SCREENER=${pkgs.scrot}/bin/scrot LOCKER="${pkgs.i3lock}/bin/i3lock -ef" fi $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" rm "$TMPBG" '' diff --git a/users/phundrak/wlr-which-key/default.nix b/users/phundrak/wlr-which-key/default.nix index 8b0fea3..2ef203e 100644 --- a/users/phundrak/wlr-which-key/default.nix +++ b/users/phundrak/wlr-which-key/default.nix @@ -26,6 +26,7 @@ fullscreen = import ./fullscreen.nix {inherit pkgs;}; logout = import ./logout.nix {inherit pkgs;}; ytplay = import ../../modules/cli/scripts/ytplay.nix {inherit pkgs;}; + plock = import ../../modules/cli/scripts/plock.nix {inherit pkgs;}; in [ { key = "a"; @@ -165,6 +166,11 @@ } ]; } + { + key = "l"; + desc = "Lock session"; + cmd = "${plock}/bin/plock"; + } { key = "p"; desc = "Power";