Update stuff for screen lock

This commit is contained in:
2025-11-27 03:12:08 -08:00
parent a3aba45b6e
commit 6da1ad41b5
3 changed files with 40 additions and 13 deletions

View File

@ -5,7 +5,7 @@ local operation="--on"
local jq_filter_neg="| not"
local ignored=()
while getopts 'ldi:' name; do
while getopts 'hldi:' name; do
case "${name}" in
h)
echo 'enable-displays-for-sleep [-l] [-d] [-i]'

17
laptop-lid-daemon Executable file
View File

@ -0,0 +1,17 @@
#!/usr/bin/env zsh
acpi_listen | while read event; do
let num_outputs="$(wlr-randr --json | jq 'length')"
if ((num_outputs <= 1)); then
kanshictl switch default
else
case "${event}" in
'button/lid LID open')
kanshictl switch docked-open
;;
'button/lid LID close')
kanshictl switch docked-closed
;;
esac
fi
done

View File

@ -1,6 +1,7 @@
#!/usr/bin/env zsh
LOCKFILE="${HOME}/.cache/swayidle-lock-screen.lock"
ENABLE_DISPLAYS="${HOME}/scripts/enable-displays-for-sleep"
function has-rootful-xwayland-p {
for pid in $(pgrep Xwayland); do
@ -21,18 +22,23 @@ function run {
if [[ "${XDG_CURRENT_DESKTOP}" == 'river' ]] && has-rootful-xwayland-p; then
swaylock ${empty_flag} --color '#000000'
else
local swayidle_pid
if ((dont_sleep)); then
# get the list of currently disabled monitors so we don't touch them
local ignored=("${(0)$(enable-displays-for-sleep -l)}")
local ignored=("${(0)$("${ENABLE_DISPLAYS}" -l)}")
local ignored_args=()
for name in ${ignored}; do
# quote so it can be safely passed to swayidle
ignored_args+=(-i "${(q)name}")
done
swayidle -w -C /dev/null \
timeout 15 "enable-displays-for-sleep -d ${ignored}" \
resume "enable-displays-for-sleep {$ignored}" &
local swayidle_pid="${!}"
timeout 15 "${(q)ENABLE_DISPLAYS} -d ${ignored_args}" \
resume "${(q)ENABLE_DISPLAYS} {$ignored_args}" &
swayidle_pid="${!}"
else
swayidle -w -C /dev/null timeout 15 "systemctl sleep" &
swayidle_pid="${!}"
fi
swaylock ${empty_flag} ${img_flags}
kill "${swayidle_pid}"
fi
@ -52,6 +58,7 @@ local suspend_command=''
local wake_command=''
local empty_flag=''
local fix_eww=()
let dont_sleep=0
while [[ "${1}" =~ '^-' ]]; do
case "${1}" in
--)
@ -68,6 +75,9 @@ while [[ "${1}" =~ '^-' ]]; do
-e)
empty_flag='-e'
;;
-d)
dont_sleep=1
;;
-*)
printf "error: unknown flag '%s'\n" "${1}" >&2
;;