diff --git a/laptop-lid-daemon b/laptop-lid-daemon index e56f539..8e8eec0 100755 --- a/laptop-lid-daemon +++ b/laptop-lid-daemon @@ -3,17 +3,5 @@ "${HOME}/scripts/set-initial-kanshi-state" 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 + "${HOME}/scripts/set-initial-kanshi-state" done diff --git a/set-initial-kanshi-state b/set-initial-kanshi-state index b5dd2da..f045ae2 100755 --- a/set-initial-kanshi-state +++ b/set-initial-kanshi-state @@ -1,11 +1,8 @@ #!/usr/bin/zsh -let monitor_count="$(wlr-randr --json | jq 'length')" -(( monitor_count <= 1 )) && exit - # Wait for the socket if ! [[ -S /run/user/1000/fr.emersion.kanshi.wayland-1 ]]; then - printf 'Waiting for socket ' 1>&2 + printf 'Waiting for socket .' 1>&2 let i=0 while ! [[ -S /run/user/1000/fr.emersion.kanshi.wayland-1 ]]; do if (( i >= 20 )); then @@ -13,25 +10,34 @@ if ! [[ -S /run/user/1000/fr.emersion.kanshi.wayland-1 ]]; then exit 1 fi i+=1 - printf '.' 1>&2 sleep 0.1 + printf '.' 1>&2 done printf '\n' 1>&2 fi get_current_profile() { - kanshictl status | jq -er '.current_profile' + local profile + profile="$(kanshictl status | jq -er '.current_profile')" + (( $? )) && return 1 + : ${(P)1::="${profile}"} } +local current_profile let i=0 -while ! get_current_profile >/dev/null; do +while ! get_current_profile current_profile >/dev/null; do if (( i >= 5 )); then break fi sleep 0.1 done -local current_profile="$(get_current_profile)" +local monitor_count_str="$(wlr-randr --json | jq 'length')" +[[ "${monitor_count_str}" =~ '[0-9]+' ]] || exit +let monitor_count="${monitor_count_str}" +(( monitor_count <= 1 )) && [[ "${current_profile}" != 'default' ]] \ + && kanshictl switch default + local current_state="$(