Update waybar sleep stuff

This commit is contained in:
2026-02-18 19:32:13 -08:00
parent 44145ecfde
commit df69a5b1ea
3 changed files with 27 additions and 3 deletions

View File

@ -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))

View File

@ -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

View File

@ -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]