summaryrefslogtreecommitdiffstats
path: root/polybar/info-hlwm-workspaces.sh
diff options
context:
space:
mode:
Diffstat (limited to 'polybar/info-hlwm-workspaces.sh')
-rwxr-xr-xpolybar/info-hlwm-workspaces.sh65
1 files changed, 65 insertions, 0 deletions
diff --git a/polybar/info-hlwm-workspaces.sh b/polybar/info-hlwm-workspaces.sh
new file mode 100755
index 0000000..4a42500
--- /dev/null
+++ b/polybar/info-hlwm-workspaces.sh
@@ -0,0 +1,65 @@
+#!/usr/bin/env bash
+
+# Multi monitor support. Needs MONITOR environment variable to be set for each instance of polybar
+# If MONITOR environment variable is not set this will default to monitor 0
+# Check https://github.com/polybar/polybar/issues/763
+MON_IDX="0"
+mapfile -t MONITOR_LIST < <(polybar --list-monitors | cut -d":" -f1)
+for (( i=0; i<$((${#MONITOR_LIST[@]})); i++ )); do
+ [[ ${MONITOR_LIST[${i}]} == "$MONITOR" ]] && MON_IDX="$i"
+done;
+
+herbstclient --idle "tag_*" 2>/dev/null | {
+ while true; do
+ # Read tags into $tags as array
+ IFS=$'\t' read -ra tags <<< "$(herbstclient tag_status "${MON_IDX}")"
+ {
+ for i in "${tags[@]}" ; do
+ name=${i#?}
+ # Read the prefix from each tag and render them according to that prefix
+ case ${i:0:1} in
+ '.')
+ # the tag is empty
+ printf "%%{F#707880}"
+ ;;
+ ':')
+ # the tag is not empty
+ printf "%%{F#C5C8C6}"
+ ;;
+ '+')
+ # the tag is viewed on the specified MONITOR, but this monitor is not focused.
+ printf "%%{F#cccccc}"
+ ;;
+ '#')
+ # the tag is viewed on the specified MONITOR and it is focused.
+ printf "%%{R}"
+ ;;
+ '-')
+ # the tag is viewed on a different MONITOR, but this monitor is not focused.
+ # TODO Add your formatting tags
+ ;;
+ '%')
+ # the tag is viewed on a different MONITOR and it is focused.
+ # TODO Add your formatting tags
+ ;;
+ '!')
+ # the tag contains an urgent window
+ printf "%%{B#CC6666}"
+ ;;
+ esac
+
+ # focus the monitor of the current bar before switching tags
+ echo "%{A1:herbstclient focus_monitor ${MON_IDX}; herbstclient use ${i:1}:} ${i:1} %{A -u -o F- B-}"
+ done
+
+ # reset foreground and background color to default
+ echo "%{F-}%{B-}"
+ } | tr -d "\n"
+
+ echo
+
+ # wait for next event from herbstclient --idle
+ read -r || break
+done
+} 2>/dev/null
+