Skip to content

Instantly share code, notes, and snippets.

@c00kiemon5ter
Created February 25, 2012 02:40
  • Star 13 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save c00kiemon5ter/1905427 to your computer and use it in GitHub Desktop.
monsterwm output to dzen2 or some_sorta_bar
ff="/tmp/monsterwm.fifo"
[[ -p $ff ]] || mkfifo -m 600 "$ff"
# desktop names
ds=("web" "dev" "foo" "null")
# layout names
ms=("T" "M" "B" "G" "F")
while read -t 60 -r wmout || true; do
if [[ $wmout =~ ^(([[:digit:]]+:)+[[:digit:]]+ ?)+$ ]]; then
read -ra desktops <<< "$wmout" && unset r
for desktop in "${desktops[@]}"; do
IFS=':' read -r d w m c u <<< "$desktop"
((c)) && fg="\\f4" i="${ms[$m]}" || fg="\\f3"
((u)) && w+='\f5!'
r+="$fg${ds[$d]} ${w/#0/\\f8-} \\f3:: "
done
r="${r%::*}"
fi
printf "\\\l%s\\\r%s\n" "$r\\f5[\\f3$i\\f5]" "$(date +"%F %R")"
done < "$ff" | bar &
# pass output to fifo
monsterwm > "$ff"
#!/usr/bin/env bash
# create a fifo to send output
ff="/tmp/monsterwm.fifo"
[[ -p $ff ]] || mkfifo -m 600 "$ff"
while read -r; do
# filter output to only what we want to match and parse
[[ $REPLY =~ ^(([[:digit:]]+:)+[[:digit:]]+ ?)+$ ]] && read -ra desktops <<< "$REPLY" || continue
for desktop in "${desktops[@]}"; do
# set values for
# d - the desktop id
# w - number of windows in that desktop
# m - tiling layout/mode for that desktop
# c - whether that desktop is the current (1) or not (0)
# u - whether a window in that desktop has an urgent hint set (1) or not (0)
IFS=':' read -r d w m c u <<< "$desktop"
# name each desktop
case $d in
0) d="web" s="" ;;
1) d="dev" s="::" ;;
2) d="foo" s="::" ;;
esac
# the current desktop color should be #d11783
# we will also display the current desktop's tiling layout/mode
((c)) && f="#d11783" && case $m in
# name each layout/mode with a symbol
0) i="[T]" ;;
1) i="[M]" ;;
2) i="[B]" ;;
3) i="[G]" ;;
esac || f="#5e7175"
# if the desktop has an urgent hint its color should be #ff0000
((u)) && f="#ff0000"
# if the desktop has windows print that number next to the desktop name
# else just print the desktop name
((w)) && r+="$s ^fg($f)$d $w^fg() " || r+="$s ^fg($f)$d^fg() "
done
# read from fifo and output to dzen2
printf "%s%s\n" "$r" "$i" && unset r
done < "$ff" | dzen2 -h 18 -w 400 -ta l -e -p -fn "-misc-terminusmod.icons-medium-r-normal--12-120-72-72-c-60-*-*" &
# pass output to fifo
monsterwm > "$ff"
#!/usr/bin/env bash
: "${wm:=$HOME/Projects/monsterwm/monsterwm}"
: "${ff:="/tmp/$RANDOM.monsterwm.fifo"}"
tags=('1' '2' '3' '4')
layouts=('[]=' '[ ]' 'TTT' '[#]')
conky | dzen2 -h 18 -x 320 -ta r -e -p -fn &
# Check if it's a pipe, otherwise create it
[[ -p $ff ]] || mkfifo -m 600 "$ff"
while read -t 60 -r wmout || true; do
desktops=( $(cut -d"|" -f1 <<< "$wmout") )
title="$(cut -d"|" -f2- <<< "$wmout")"
if [[ "${desktops[@]}" =~ ^(([[:digit:]]+:)+[[:digit:]]+ ?)+$ ]]; then
unset tmp
for desktop in "${desktops[@]}"; do
IFS=':' read -r d w m c u <<< "$desktop"
# Tags labels
label="${tags[$d]}"
# Is this the current desktop ? save the layout
((c)) && fg="#fefefe" bg="#204a87" && layout="${layouts[$m]}" \
|| fg="#b3b3b3" bg=""
# Has windows ?
((w)) && fg="#fce94f"
# Urgent windows ?
((u)) && fg="#ef2929"
tmp+="^fg($fg)^bg($bg) $label ^bg()^fg()"
done
fi
# Merge the clients indications, the tile and the info
echo "$tmp $layout $title"
done < "$ff" | dzen2 -w 320 -h 18 -ta l -e -p &
while :; do "$wm" || break; done | tee -a "$ff"
#$wm > "$ff"
#!/usr/bin/env bash
# create a fifo to send output
ff="/tmp/monsterwm.fifo"
[[ -p $ff ]] || mkfifo -m 600 "$ff"
# desktop names
ds=("web" "dev" "foo" "null")
# layout names
ls=("T" "M" "B" "G" "F")
while read -t 60 -r wmout || true; do
if [[ $wmout =~ ^(([[:digit:]]+:)+[[:digit:]]+ ?)+$ ]]; then
read -ra desktops <<< "$wmout" && unset r
for desktop in "${desktops[@]}"; do
# set values for
# d - the desktop id
# w - number of windows in that desktop
# m - tiling layout/mode for that desktop
# c - whether that desktop is the current (1) or not (0)
# u - whether a window in that desktop has an urgent hint set (1) or not (0)
IFS=':' read -r d w m c u <<< "$desktop"
# if this is the current desktop, color should be '&4'
# if this is the current desktop, also set the layout name
# else the color should be '&3'
((c)) && fg="&4" i="${ls[$m]}" || fg="&3"
# if the desktop has an urgent hint, add an
# exclamation mark '!' with '&5' color
((u)) && w+='&5!'
r+="$fg${ds[$d]} $w &3:: "
done
r="${r%::*}"
fi
# read from fifo and output to some_sorta_bar
printf "&L%s&R%s\n" "$r&5[&3$i&5]" "$(date +"%F %R")"
done < "$ff" | some_sorta_bar &
# pass output to fifo
monsterwm > "$ff"
@c00kiemon5ter
Copy link
Author

monsterwm 🌵 is a tiny but monsterous dynamic tiling wm by @c00kiemon5ter written in less than 650lines of C

bar 🔥 is a @LemonBoy creation, a simple bar written in C/XCB.

some_sorta_bar ⚡ is a @moetunes creation, some sort of a bar, written in C/Xlib.

@c00kiemon5ter
Copy link
Author

I use tee to get the output to stdout on the tty/console too.
If you don't want that, then just redirect the output from mosterwm directly to the pipe.

monsterwm > "$ff"

update: this is now the default.

@c00kiemon5ter
Copy link
Author

some_sorta_bar now reads input from stdin instead of xsetroot -name, so it works just like dzen does. Replacing dzen (and its options) with some_sorta_bar (and vice versa) will work the same.

@c00kiemon5ter
Copy link
Author

added friendlier script by @LemonBoy, edited to also include the window titles.

@c00kiemon5ter
Copy link
Author

@livinglifeback I had forgotten a & at the end of the dzen2 call.
the only thing you need to run the script is to make it executable and add

exec /path/to/monsterwm2dzen

in your ~/.xinitrc

@c00kiemon5ter
Copy link
Author

added script to output to bar by @LemonBoy

@c00kiemon5ter
Copy link
Author

Also check mstatusbar
Use it as indicated in monsterbar.sh replacing the above scripts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment