aboutsummaryrefslogtreecommitdiffstats
path: root/bin/cwmbar
blob: 7d723dd52cfcca9f13298118c3c3014a80a6ad2b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/sh
set -o errexit

main() {
  # Redraw when the active group or the window list changes.
  # -spy prints once at startup too, so the bar draws immediately.
  xprop -root -spy _NET_CURRENT_DESKTOP _NET_CLIENT_LIST |
  while read -r _; do
      groups
  done | lemonbar-xft -g x18 -B '#222222' -F '#dddddd' | sh
}

groups() {
    cur=$(xprop -root _NET_CURRENT_DESKTOP | awk '{print $3}')
    num=$(xprop -root _NET_NUMBER_OF_DESKTOPS | awk '{print $3}')

    # groups that currently contain windows
    occ=$(for w in $(xprop -root _NET_CLIENT_LIST | cut -d'#' -f2 | tr -d ','); do
              xprop -id "$w" _NET_WM_DESKTOP 2>/dev/null | awk '{print $3}'
          done | sort -u)

    out=""
    i=1                         # skip 0 ("nogroup")
    while [ "$i" -lt "$num" ]; do
        if [ "$i" -eq "$cur" ]; then
            out="$out%{R} $i %{R}"                     # active: reversed colors
        elif echo "$occ" | grep -qx "$i"; then
            out="$out%{A:xdotool set_desktop $i:} $i %{A}"   # occupied, clickable
        else
            out="$out%{F#555}%{A:xdotool set_desktop $i:} $i %{A}%{F-}"  # empty, dimmed
        fi
        i=$((i + 1))
    done
    echo "%{l}$out"
}

main