From ea10a0e5b2a9641f020d9bade293e44d7b9f38d7 Mon Sep 17 00:00:00 2001 From: elenapan Date: Tue, 1 Apr 2025 17:05:31 +0300 Subject: [PATCH] eww: Set window revealer duration inside `manage` script only Use window arguments to pass revealer duration to eww. --- config/eww/scripts/manage | 34 ++++++++++++-------- config/eww/windows/alarms.yuck | 4 +-- config/eww/windows/microphone-indicator.yuck | 4 +-- config/eww/windows/mode-indicator.yuck | 4 +-- config/eww/windows/networks.yuck | 4 +-- config/eww/windows/powermenu.yuck | 4 +-- config/eww/windows/sidebar.yuck | 6 ++-- config/eww/windows/split-indicator.yuck | 4 +-- 8 files changed, 34 insertions(+), 30 deletions(-) diff --git a/config/eww/scripts/manage b/config/eww/scripts/manage index d53c40d..bc4e94a 100755 --- a/config/eww/scripts/manage +++ b/config/eww/scripts/manage @@ -37,16 +37,15 @@ secondary_monitors=( declare -A overlay_widgets overlay_widgets[powermenu]=true -# How long to wait for the revealer animation to complete. This should be -# match the revealer delay in the respective *.yuck files. -declare -A revealer_delay -revealer_delay[sidebar]=0.3 -revealer_delay[powermenu]=0.3 -revealer_delay[split-indicator]=0.3 -revealer_delay[mode-indicator]=0.3 -revealer_delay[microphone-indicator]=0.2 -revealer_delay[networks]=0.3 -revealer_delay[alarms]=0.3 +# How long to wait for the revealer animation to complete (in milliseconds). +declare -A revealer_duration +revealer_duration[sidebar]=300 +revealer_duration[powermenu]=300 +revealer_duration[split-indicator]=300 +revealer_duration[mode-indicator]=300 +revealer_duration[microphone-indicator]=200 +revealer_duration[networks]=300 +revealer_duration[alarms]=300 # Only one of these should be visible at a time mutually_exclusive_widgets=( @@ -98,6 +97,11 @@ _is_secondary_monitor() { grep -q "^${mon}$" <<< "$(printf '%s\n' "${secondary_monitors[@]}")" } +_get_revealer_duration_seconds() { + widget_name="$1" + awk "BEGIN {printf \"%.3f\",${revealer_duration[$widget_name]:-0}/1000}" +} + _open() { widget_name="$1" @@ -110,6 +114,10 @@ _open() { done fi + if [[ -v revealer_duration["$widget_name"] ]]; then + extra_args+=" --arg revealer-duration=${revealer_duration[$widget_name]}ms" + fi + # shellcheck disable=2086 eww open-many "$widget_name" $extra_args >/dev/null } @@ -215,11 +223,10 @@ _show() { _hide() { widget_name="$1" - delay="${revealer_delay[$widget_name]:-0}" # default delay is 0 _pre_hide "$widget_name" _mode_disable "$widget_name" eww update "${widget_name}"-visible=false - sleep "$delay" + sleep "$(_get_revealer_duration_seconds "$widget_name")" _close "$widget_name" _post_hide "$widget_name" } @@ -251,7 +258,6 @@ hide_all_except() { for widget in "${mutually_exclusive_widgets[@]}"; do if [[ ! "$widget" == "$widget_except" ]] && grep -e "^${widget}:" >/dev/null <<< "$active_windows"; then - delay="${revealer_delay[$widget]:-0}" # default delay is 0 # We do not call the `hide` helper because we do not necessarily # want to mess with the sway modes. # The widget to be activated will set its own mode through the @@ -272,7 +278,7 @@ hide_all_except() { ( _pre_hide "$widget" eww update "${widget}-visible"=false - sleep "$delay" + sleep "$(_get_revealer_duration_seconds "$widget_name")" _close "$widget" _post_hide "$widget" )& diff --git a/config/eww/windows/alarms.yuck b/config/eww/windows/alarms.yuck index 7d5b318..e3949d3 100644 --- a/config/eww/windows/alarms.yuck +++ b/config/eww/windows/alarms.yuck @@ -1,4 +1,4 @@ -(defwindow alarms +(defwindow alarms [revealer-duration] :monitor 0 :geometry (geometry :x 0 ; Same as sway gaps (we cannot use EWW_SCALE here) @@ -13,7 +13,7 @@ (revealer :transition "slideleft" :reveal "${alarms-visible}" - :duration "300ms" + :duration "${revealer-duration}" (eventbox :onmiddleclick "${eww-scripts}/manage hide alarms" :halign "fill" diff --git a/config/eww/windows/microphone-indicator.yuck b/config/eww/windows/microphone-indicator.yuck index 78fd8ff..2fc4c27 100644 --- a/config/eww/windows/microphone-indicator.yuck +++ b/config/eww/windows/microphone-indicator.yuck @@ -1,4 +1,4 @@ -(defwindow microphone-indicator +(defwindow microphone-indicator [revealer-duration] :monitor 0 :geometry (geometry :x 0 ; We cannot use get_env(EWW_SCALE) here @@ -9,7 +9,7 @@ (revealer :transition "slidedown" :reveal "${microphone-indicator-visible}" - :duration "200ms" + :duration "${revealer-duration}" (eventbox :cursor "hand2" :onclick "pactl set-source-mute @DEFAULT_SOURCE@ toggle" :onmiddleclick "${eww-scripts}/manage hide microphone-indicator &" diff --git a/config/eww/windows/mode-indicator.yuck b/config/eww/windows/mode-indicator.yuck index ea2f330..878cd6e 100644 --- a/config/eww/windows/mode-indicator.yuck +++ b/config/eww/windows/mode-indicator.yuck @@ -1,4 +1,4 @@ -(defwindow mode-indicator +(defwindow mode-indicator [revealer-duration] :monitor 0 :geometry (geometry :x 0 :y 0 @@ -12,7 +12,7 @@ (revealer :transition "slidedown" :reveal "${mode-indicator-visible}" - :duration "300ms" + :duration "${revealer-duration}" (eventbox ; On click, cancel active binding mode and hide widget :onclick "swaymsg -q mode default & ${eww-scripts}/manage hide mode-indicator &" diff --git a/config/eww/windows/networks.yuck b/config/eww/windows/networks.yuck index 2d09347..c9bbafc 100644 --- a/config/eww/windows/networks.yuck +++ b/config/eww/windows/networks.yuck @@ -1,4 +1,4 @@ -(defwindow networks +(defwindow networks [revealer-duration] :monitor 0 :geometry (geometry :x 0 ; Same as sway gaps (we cannot use EWW_SCALE here) @@ -13,7 +13,7 @@ (revealer :transition "slideleft" :reveal "${networks-visible}" - :duration "300ms" + :duration "${revealer-duration}" (eventbox :onmiddleclick "${eww-scripts}/manage hide networks" :halign "fill" diff --git a/config/eww/windows/powermenu.yuck b/config/eww/windows/powermenu.yuck index 6197500..37d2ed7 100644 --- a/config/eww/windows/powermenu.yuck +++ b/config/eww/windows/powermenu.yuck @@ -1,4 +1,4 @@ -(defwindow powermenu [is-secondary] +(defwindow powermenu [is-secondary revealer-duration] :monitor 0 :geometry (geometry :x 0 @@ -21,7 +21,7 @@ (revealer :transition "crossfade" :reveal "${powermenu-visible}" - :duration "300ms" + :duration "${revealer-duration}" (eventbox :halign "fill" :valign "fill" diff --git a/config/eww/windows/sidebar.yuck b/config/eww/windows/sidebar.yuck index 4ea8045..8de3c12 100644 --- a/config/eww/windows/sidebar.yuck +++ b/config/eww/windows/sidebar.yuck @@ -1,4 +1,4 @@ -(defwindow sidebar +(defwindow sidebar [revealer-duration] :monitor 0 :geometry (geometry :x 0 :y 0 @@ -11,11 +11,9 @@ :exclusive false :focusable false (revealer - ; Would prefer a slideright animation here but it does not work - ; https://github.com/elkowar/eww/issues/1107 :transition "slideright" :reveal "${sidebar-visible}" - :duration "300ms" + :duration "${revealer-duration}" (eventbox :width "${300 * get_env("EWW_SCALE")}" :onmiddleclick "${eww-scripts}/manage hide sidebar &" diff --git a/config/eww/windows/split-indicator.yuck b/config/eww/windows/split-indicator.yuck index 8e6fcdf..d699b91 100644 --- a/config/eww/windows/split-indicator.yuck +++ b/config/eww/windows/split-indicator.yuck @@ -1,4 +1,4 @@ -(defwindow split-indicator +(defwindow split-indicator [revealer-duration] :monitor 0 :geometry (geometry :x 0 :y 0 @@ -8,7 +8,7 @@ (revealer :transition "crossfade" :reveal "${split-indicator-visible}" - :duration "300ms" + :duration "${revealer-duration}" (eventbox :onclick "${eww-scripts}/manage hide split-indicator &" :onmiddleclick "${eww-scripts}/manage hide split-indicator &"