From df69a5b1ea29c4adc498d1a2fb6ad471fa6da716 Mon Sep 17 00:00:00 2001 From: Alexander Rosenberg Date: Wed, 18 Feb 2026 19:32:13 -0800 Subject: [PATCH] Update waybar sleep stuff --- cl/list-manual-sleep-locks.lisp | 22 +++++++++++++++++++++- system-menu/system-sleep-menu.sh | 5 ++++- systemd/manual-inhibit-sleep@.service | 3 ++- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/cl/list-manual-sleep-locks.lisp b/cl/list-manual-sleep-locks.lisp index 1f37510..03d6fba 100644 --- a/cl/list-manual-sleep-locks.lisp +++ b/cl/list-manual-sleep-locks.lisp @@ -49,13 +49,33 @@ from which to calculate." (list (subseq line 0 index) (subseq line (1+ index))))) +(defun systemd-unescape (str &key (start 0) (end (length str))) + "Act as sytemd-escape --unescape (for non-path strings) for STR." + (with-output-to-string (stream) + (let ((copy-start start)) + (flet ((copy-to-output (i skip) + (when (<= copy-start end) + (write-string str stream :start copy-start :end i) + (setq copy-start (+ i skip))))) + (loop for i upfrom start below end + for c = (aref str i) + when (and (eql c #\\) (>= (- end i) 4) + (eql (aref str (1+ i)) #\x)) + do (copy-to-output i 4) + and do (write-char (code-char (parse-integer str + :start (+ i 2) + :end (+ i 4) + :radix 16)) + stream)) + (copy-to-output end 0))))) + (defun extract-lock-length-string-from-service-name (name) "Extract the lock length string from a service name NAME of the form \"NAME@TIME.service\"." (let ((start-idx (1+ (position #\@ name))) (end-idx (when (uiop:string-suffix-p name ".service") (- (length name) (length ".service"))))) - (subseq name start-idx end-idx))) + (systemd-unescape name :start start-idx :end end-idx))) (defparameter *lock-length-string-units* `((#\d . ,(* 24 60 60 1000 1000)) diff --git a/system-menu/system-sleep-menu.sh b/system-menu/system-sleep-menu.sh index a5db477..74077b7 100755 --- a/system-menu/system-sleep-menu.sh +++ b/system-menu/system-sleep-menu.sh @@ -26,6 +26,7 @@ done function is_valid_sleep_time() { [[ "${1}" = forever ]] \ + || [[ "${1}" = infinity ]] \ || [[ "${1}" =~ ' *([0-9]+[smhd]? *)+' ]] } @@ -53,7 +54,9 @@ else exit elif is_valid_sleep_time "${choice}"; then [[ "${choice}" == forever ]] && choice=infinity - systemctl --user start "manual-inhibit-sleep@${choice}.service" + local unit="$(systemd-escape --template=manual-inhibit-sleep@.service \ + "${choice}")" + systemctl --user start "${unit}" else printf 'Invalid sleep time: %s\n' "${choice}" 1>&2 fi diff --git a/systemd/manual-inhibit-sleep@.service b/systemd/manual-inhibit-sleep@.service index 5aa2a4b..3ac6551 100644 --- a/systemd/manual-inhibit-sleep@.service +++ b/systemd/manual-inhibit-sleep@.service @@ -3,8 +3,9 @@ Description=Inhibit sleep for some period of time [Service] Type=exec +Environment=TIME=%I ExecStartPre=-pkill -f -SIGUSR1 '^(.*/)?emacs +-Q +--script +(.*/)?sb-manual-sleep-locks( +.+)?$' -ExecStart=systemd-inhibit --what=sleep:idle "--who=manual-inhibit-sleep@%i.service" --mode=block "--why=User manually inhibited sleep" sleep %i +ExecStart=systemd-inhibit --what=sleep:idle "--who=manual-inhibit-sleep@%I.service" --mode=block "--why=User manually inhibited sleep" sleep $TIME ExecStopPost=-pkill -f -SIGUSR1 '^(.*/)?emacs +-Q +--script +(.*/)?sb-manual-sleep-locks( +.+)?$' [Install]