diff --git a/enable-displays-for-sleep b/enable-displays-for-sleep index 51a5007..b46fbfe 100755 --- a/enable-displays-for-sleep +++ b/enable-displays-for-sleep @@ -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]' diff --git a/laptop-lid-daemon b/laptop-lid-daemon new file mode 100755 index 0000000..36d4af4 --- /dev/null +++ b/laptop-lid-daemon @@ -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 diff --git a/swayidle-lock-screen b/swayidle-lock-screen index 2112512..3c74fea 100755 --- a/swayidle-lock-screen +++ b/swayidle-lock-screen @@ -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 - # get the list of currently disabled monitors so we don't touch them - local ignored=("${(0)$(enable-displays-for-sleep -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="${!}" + 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}" -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 "${(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 ;;