#!/bin/bash # Left: the active workspace as an accent block that fades into the bar, then # the workspaces with one dot per window, in layout order (left to right). The # active workspace shows only its dots, and the focused window's dot is in the # accent color. On NeferWL it also shows the stash. Without NeferWL's state file # it shows nothing. . "$(dirname "$0")/lib.sh" DOT=$ICON_DOT STASH=$ICON_STASH [ -r "${NEFERWL_STATE:-}" ] || { echo exec sleep infinity } draw() { # First line: " " of the focused output. Then one line per # workspace: " ", where is the # place (from 1) of the focused window in the workspace's layout order, or 0. # Windows are ordered by column, then row; floating ones (column 0) come last. local data active count n w s f line pips i color data=$(jq -r ' .output as $o | (.outputs[] | select(.name == $o)) as $out | [.windows[] | select(.output == $o)] as $ws | (if .window.output == $o then .window.id else null end) as $focus | "\($out.active) \($out.count)", (range(1; $out.count + 1) as $n | [$ws[] | select(.workspace == $n)] | sort_by([(if (.column // 0) > 0 then .column else 1000000 end), (.row // 0), .id]) as $here | (if $focus == null then null else ($here | map(.id) | index($focus)) end) as $at | "\($n) \($here | length) \([$here[] | select(.stash_count > 0)] | length) \(if $at == null then 0 else $at + 1 end)")' \ "$NEFERWL_STATE" 2>/dev/null) || return read -r active count <<<"$(head -1 <<<"$data")" # The state file is data, not code: bash arithmetic runs command # substitutions, so only digits may reach it. [[ $active =~ ^[0-9]+$ && $count =~ ^[0-9]+$ ]] || return line="$(bg "$ACCENT")$(fg "$(ink "$ACCENT")")$BOLD $active $RESET$(fade "$ACCENT" "$BAR")$(bg "$BAR")" while read -r n w s f; do [[ $n =~ ^[0-9]+$ && $w =~ ^[0-9]+$ && $s =~ ^[0-9]+$ && $f =~ ^[0-9]+$ ]] || continue # One dot per window, at most 4; a focused window past the 4th lights the 4th. pips="" for ((i = 1; i <= (w > 4 ? 4 : w); i++)); do color=$DIM ((n == active)) && color=$NEFERBAR_FOREGROUND ((i == (f > 4 ? 4 : f))) && color=$ACCENT pips+="$(fg "$color")$DOT" done if ((n == active)); then # The number is already in the accent block on the left. line+=" $pips" ((s > 0)) && line+="$(fg "$NEFERBAR_COLOR2") $STASH$s" line+=" " elif ((w > 0)); then line+="$(fg "$NEFERBAR_FOREGROUND") $n $pips " else line+="$(fg "$DIM") $n " fi done < <(tail -n +2 <<<"$data") printf '%s%s\f' "$line" "$RESET" } state_changed_loop draw