feat(examples): color the focused window's dot using the state file's column and row
- commit
- 32a3738649981b53be8df34af11b88de7892bc9b
- author
- brice · · 2026-10-05 18:55 UTC
- parent
- 2f98a9a
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
1 file · +24 -13
M examples/bundle/left.sh +24 -13
| @@ -1,8 +1,9 @@ | |||
| 1 | 1 | #!/bin/bash | |
| 2 | 2 | # Left: the active workspace as an accent block that fades into the bar, then | |
| 3 | - | # the workspaces with one dot per window. The active workspace shows only its | |
| 4 | - | # dots. On NeferWL it also shows the stash. Without NeferWL's state file it | |
| 5 | - | # shows nothing. | |
| 3 | + | # the workspaces with one dot per window, in layout order (left to right). The | |
| 4 | + | # active workspace shows only its dots, and the focused window's dot is in the | |
| 5 | + | # accent color. On NeferWL it also shows the stash. Without NeferWL's state file | |
| 6 | + | # it shows nothing. | |
| 6 | 7 | . "$(dirname "$0")/lib.sh" | |
| 7 | 8 | ||
| 8 | 9 | DOT=$ICON_DOT STASH=$ICON_STASH | |
| @@ -13,16 +14,21 @@ DOT=$ICON_DOT STASH=$ICON_STASH | |||
| 13 | 14 | ||
| 14 | 15 | draw() { | |
| 15 | 16 | # First line: "<active> <count>" of the focused output. Then one line per | |
| 16 | - | # workspace: "<n> <windows> <stashed>". | |
| 17 | - | local data active count n w s line pips | |
| 17 | + | # workspace: "<n> <windows> <stashed> <focused>", where <focused> is the | |
| 18 | + | # place (from 1) of the focused window in the workspace's layout order, or 0. | |
| 19 | + | # Windows are ordered by column, then row; floating ones (column 0) come last. | |
| 20 | + | local data active count n w s f line pips i color | |
| 18 | 21 | data=$(jq -r ' | |
| 19 | 22 | .output as $o | |
| 20 | 23 | | (.outputs[] | select(.name == $o)) as $out | |
| 21 | 24 | | [.windows[] | select(.output == $o)] as $ws | |
| 25 | + | | (if .window.output == $o then .window.id else null end) as $focus | |
| 22 | 26 | | "\($out.active) \($out.count)", | |
| 23 | 27 | (range(1; $out.count + 1) as $n | |
| 24 | - | | [$ws[] | select(.workspace == $n)] as $here | |
| 25 | - | | "\($n) \($here | length) \([$here[] | select(.stash_count > 0)] | length)")' \ | |
| 28 | + | | [$ws[] | select(.workspace == $n)] | |
| 29 | + | | sort_by([(if (.column // 0) > 0 then .column else 1000000 end), (.row // 0), .id]) as $here | |
| 30 | + | | (if $focus == null then null else ($here | map(.id) | index($focus)) end) as $at | |
| 31 | + | | "\($n) \($here | length) \([$here[] | select(.stash_count > 0)] | length) \(if $at == null then 0 else $at + 1 end)")' \ | |
| 26 | 32 | "$NEFERWL_STATE" 2>/dev/null) || return | |
| 27 | 33 | read -r active count <<<"$(head -1 <<<"$data")" | |
| 28 | 34 | # The state file is data, not code: bash arithmetic runs command | |
| @@ -30,18 +36,23 @@ draw() { | |||
| 30 | 36 | [[ $active =~ ^[0-9]+$ && $count =~ ^[0-9]+$ ]] || return | |
| 31 | 37 | ||
| 32 | 38 | line="$(bg "$ACCENT")$(fg "$(ink "$ACCENT")")$BOLD $active $RESET$(fade "$ACCENT" "$BAR")$(bg "$BAR")" | |
| 33 | - | while read -r n w s; do | |
| 34 | - | [[ $n =~ ^[0-9]+$ && $w =~ ^[0-9]+$ && $s =~ ^[0-9]+$ ]] || continue | |
| 35 | - | # One dot per window, at most 4. | |
| 39 | + | while read -r n w s f; do | |
| 40 | + | [[ $n =~ ^[0-9]+$ && $w =~ ^[0-9]+$ && $s =~ ^[0-9]+$ && $f =~ ^[0-9]+$ ]] || continue | |
| 41 | + | # One dot per window, at most 4; a focused window past the 4th lights the 4th. | |
| 36 | 42 | pips="" | |
| 37 | - | ((w > 0)) && printf -v pips "$DOT%.0s" $(seq 1 $((w > 4 ? 4 : w))) | |
| 43 | + | for ((i = 1; i <= (w > 4 ? 4 : w); i++)); do | |
| 44 | + | color=$DIM | |
| 45 | + | ((n == active)) && color=$NEFERBAR_FOREGROUND | |
| 46 | + | ((i == (f > 4 ? 4 : f))) && color=$ACCENT | |
| 47 | + | pips+="$(fg "$color")$DOT" | |
| 48 | + | done | |
| 38 | 49 | if ((n == active)); then | |
| 39 | 50 | # The number is already in the accent block on the left. | |
| 40 | - | line+="$(fg "$NEFERBAR_FOREGROUND") $pips" | |
| 51 | + | line+=" $pips" | |
| 41 | 52 | ((s > 0)) && line+="$(fg "$NEFERBAR_COLOR2") $STASH$s" | |
| 42 | 53 | line+=" " | |
| 43 | 54 | elif ((w > 0)); then | |
| 44 | - | line+="$(fg "$NEFERBAR_FOREGROUND") $n $(fg "$DIM")$pips " | |
| 55 | + | line+="$(fg "$NEFERBAR_FOREGROUND") $n $pips " | |
| 45 | 56 | else | |
| 46 | 57 | line+="$(fg "$DIM") $n " | |
| 47 | 58 | fi | |
| @@ -1,8 +1,9 @@ | |||||
| 1 | #!/bin/bash | 1 | #!/bin/bash | ||
| 2 | # Left: the active workspace as an accent block that fades into the bar, then | 2 | # Left: the active workspace as an accent block that fades into the bar, then | ||
| 3 | - | # the workspaces with one dot per window. The active workspace shows only its | 3 | + | # the workspaces with one dot per window, in layout order (left to right). The |
| 4 | - | # dots. On NeferWL it also shows the stash. Without NeferWL's state file it | 4 | + | # active workspace shows only its dots, and the focused window's dot is in the |
| 5 | - | # shows nothing. | 5 | + | # accent color. On NeferWL it also shows the stash. Without NeferWL's state file |
| 6 | + | # it shows nothing. | |||
| 6 | . "$(dirname "$0")/lib.sh" | 7 | . "$(dirname "$0")/lib.sh" | ||
| 7 | 8 | ||||
| 8 | DOT=$ICON_DOT STASH=$ICON_STASH | 9 | DOT=$ICON_DOT STASH=$ICON_STASH | ||
| @@ -13,16 +14,21 @@ DOT=$ICON_DOT STASH=$ICON_STASH | |||||
| 13 | 14 | ||||
| 14 | draw() { | 15 | draw() { | ||
| 15 | # First line: "<active> <count>" of the focused output. Then one line per | 16 | # First line: "<active> <count>" of the focused output. Then one line per | ||
| 16 | - | # workspace: "<n> <windows> <stashed>". | 17 | + | # workspace: "<n> <windows> <stashed> <focused>", where <focused> is the |
| 17 | - | local data active count n w s line pips | 18 | + | # place (from 1) of the focused window in the workspace's layout order, or 0. |
| 19 | + | # Windows are ordered by column, then row; floating ones (column 0) come last. | |||
| 20 | + | local data active count n w s f line pips i color | |||
| 18 | data=$(jq -r ' | 21 | data=$(jq -r ' | ||
| 19 | .output as $o | 22 | .output as $o | ||
| 20 | | (.outputs[] | select(.name == $o)) as $out | 23 | | (.outputs[] | select(.name == $o)) as $out | ||
| 21 | | [.windows[] | select(.output == $o)] as $ws | 24 | | [.windows[] | select(.output == $o)] as $ws | ||
| 25 | + | | (if .window.output == $o then .window.id else null end) as $focus | |||
| 22 | | "\($out.active) \($out.count)", | 26 | | "\($out.active) \($out.count)", | ||
| 23 | (range(1; $out.count + 1) as $n | 27 | (range(1; $out.count + 1) as $n | ||
| 24 | - | | [$ws[] | select(.workspace == $n)] as $here | 28 | + | | [$ws[] | select(.workspace == $n)] |
| 25 | - | | "\($n) \($here | length) \([$here[] | select(.stash_count > 0)] | length)")' \ | 29 | + | | sort_by([(if (.column // 0) > 0 then .column else 1000000 end), (.row // 0), .id]) as $here |
| 30 | + | | (if $focus == null then null else ($here | map(.id) | index($focus)) end) as $at | |||
| 31 | + | | "\($n) \($here | length) \([$here[] | select(.stash_count > 0)] | length) \(if $at == null then 0 else $at + 1 end)")' \ | |||
| 26 | "$NEFERWL_STATE" 2>/dev/null) || return | 32 | "$NEFERWL_STATE" 2>/dev/null) || return | ||
| 27 | read -r active count <<<"$(head -1 <<<"$data")" | 33 | read -r active count <<<"$(head -1 <<<"$data")" | ||
| 28 | # The state file is data, not code: bash arithmetic runs command | 34 | # The state file is data, not code: bash arithmetic runs command | ||
| @@ -30,18 +36,23 @@ draw() { | |||||
| 30 | [[ $active =~ ^[0-9]+$ && $count =~ ^[0-9]+$ ]] || return | 36 | [[ $active =~ ^[0-9]+$ && $count =~ ^[0-9]+$ ]] || return | ||
| 31 | 37 | ||||
| 32 | line="$(bg "$ACCENT")$(fg "$(ink "$ACCENT")")$BOLD $active $RESET$(fade "$ACCENT" "$BAR")$(bg "$BAR")" | 38 | line="$(bg "$ACCENT")$(fg "$(ink "$ACCENT")")$BOLD $active $RESET$(fade "$ACCENT" "$BAR")$(bg "$BAR")" | ||
| 33 | - | while read -r n w s; do | 39 | + | while read -r n w s f; do |
| 34 | - | [[ $n =~ ^[0-9]+$ && $w =~ ^[0-9]+$ && $s =~ ^[0-9]+$ ]] || continue | 40 | + | [[ $n =~ ^[0-9]+$ && $w =~ ^[0-9]+$ && $s =~ ^[0-9]+$ && $f =~ ^[0-9]+$ ]] || continue |
| 35 | - | # One dot per window, at most 4. | 41 | + | # One dot per window, at most 4; a focused window past the 4th lights the 4th. |
| 36 | pips="" | 42 | pips="" | ||
| 37 | - | ((w > 0)) && printf -v pips "$DOT%.0s" $(seq 1 $((w > 4 ? 4 : w))) | 43 | + | for ((i = 1; i <= (w > 4 ? 4 : w); i++)); do |
| 44 | + | color=$DIM | |||
| 45 | + | ((n == active)) && color=$NEFERBAR_FOREGROUND | |||
| 46 | + | ((i == (f > 4 ? 4 : f))) && color=$ACCENT | |||
| 47 | + | pips+="$(fg "$color")$DOT" | |||
| 48 | + | done | |||
| 38 | if ((n == active)); then | 49 | if ((n == active)); then | ||
| 39 | # The number is already in the accent block on the left. | 50 | # The number is already in the accent block on the left. | ||
| 40 | - | line+="$(fg "$NEFERBAR_FOREGROUND") $pips" | 51 | + | line+=" $pips" |
| 41 | ((s > 0)) && line+="$(fg "$NEFERBAR_COLOR2") $STASH$s" | 52 | ((s > 0)) && line+="$(fg "$NEFERBAR_COLOR2") $STASH$s" | ||
| 42 | line+=" " | 53 | line+=" " | ||
| 43 | elif ((w > 0)); then | 54 | elif ((w > 0)); then | ||
| 44 | - | line+="$(fg "$NEFERBAR_FOREGROUND") $n $(fg "$DIM")$pips " | 55 | + | line+="$(fg "$NEFERBAR_FOREGROUND") $n $pips " |
| 45 | else | 56 | else | ||
| 46 | line+="$(fg "$DIM") $n " | 57 | line+="$(fg "$DIM") $n " | ||
| 47 | fi | 58 | fi | ||