199 lines
4.4 KiB
Bash
Executable file
199 lines
4.4 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
source "$HOME/.config/bspwm/common"
|
|
|
|
cleanup() {
|
|
jobs=( $(jobs -p) )
|
|
|
|
if [[ "$jobs" ]]; then
|
|
kill "${jobs[@]}"
|
|
fi
|
|
|
|
bspc config top_padding 0
|
|
}
|
|
|
|
get_line() {
|
|
declare counter=0 line=$1
|
|
|
|
while read; do
|
|
if (( counter == line )); then
|
|
printf '%s\n' "$REPLY"
|
|
return 0
|
|
fi
|
|
|
|
(( counter++ ))
|
|
done
|
|
}
|
|
|
|
parse_fifo_data() {
|
|
declare msg desktop_spec
|
|
declare -g win_name misc bspwm_status
|
|
|
|
while read; do
|
|
case "$REPLY" in
|
|
cmd::*)
|
|
read -r cmd args <<< "${REPLY#cmd::}"
|
|
|
|
case "$cmd" in
|
|
redraw)
|
|
printf 'Redraw triggered\n'
|
|
sleep 1
|
|
printf '%s\n' "$msg"
|
|
;;
|
|
respawn)
|
|
printf 'Dying...\n'
|
|
sleep 1
|
|
rexec
|
|
;;
|
|
run)
|
|
$args
|
|
rexec
|
|
;;
|
|
esac
|
|
;;
|
|
updates::*) updates="${REPLY#*updates::}";;
|
|
date::*) date="${REPLY#*date::}";;
|
|
T*)
|
|
if (( panel_taskbar_enable )); then
|
|
unset win_title
|
|
unset taskbar taskbar_windows taskbar_length
|
|
|
|
panel_taskbar_max_title_current=$panel_taskbar_max_title
|
|
|
|
while read -r _ _ _ wid _ _ _ _ focus; do
|
|
if [[ "$wid" =~ [0-9]x[0-9A-F] ]]; then
|
|
if [[ "$focus" == '*' ]]; then
|
|
taskbar_windows+=( "$wid::F" )
|
|
else
|
|
taskbar_windows+=( "$wid::u" )
|
|
fi
|
|
fi
|
|
done < <( bspc query -T -d focused )
|
|
|
|
taskbar_windows_n="${#taskbar_windows[@]}"
|
|
|
|
if (( taskbar_windows_n )); then
|
|
until (( taskbar_length )) && (( taskbar_length <= panel_taskbar_max_length )); do
|
|
unset taskbar
|
|
taskbar_length=$(( (taskbar_windows_n * 2) + 2 ))
|
|
|
|
for w in "${taskbar_windows[@]}"; do
|
|
IFS='::' read -r wid _ state <<< "$w"
|
|
win_title=$( xtitle -f '%s' -t "${panel_taskbar_max_title_current}" "$wid" )
|
|
win_title_length="${#win_title}"
|
|
|
|
taskbar_length=$(( taskbar_length + win_title_length ))
|
|
|
|
if [[ "$state" == 'F' ]]; then
|
|
taskbar+=" %{B#${panel_bg_focused}}%{F#${panel_bg_normal}}%{F-} ${win_title} %{B-}%{F#${panel_bg_focused}}%{F-}"
|
|
else
|
|
taskbar+=" %{A:bspc window -f ${wid}:} ${win_title} %{A}"
|
|
fi
|
|
done
|
|
|
|
(( panel_taskbar_max_title_current-- ))
|
|
done
|
|
fi
|
|
else
|
|
win_title="${REPLY#*T}"
|
|
if [[ "$win_title" ]]; then
|
|
taskbar=" %{B#${panel_bg_focused}}%{F#${panel_bg_normal}}%{F-} ${win_title} %{B-}%{F#${panel_bg_focused}}%{F-}"
|
|
else
|
|
unset taskbar
|
|
fi
|
|
fi
|
|
;;
|
|
WM*)
|
|
unset desktop_spec
|
|
IFS=':' read -a bspwm_status <<< "$REPLY"
|
|
|
|
for i in "${bspwm_status[@]}"; do
|
|
if [[ "$i" =~ ^[oOfFuU].+ ]]; then
|
|
n="${i#*[oOfFuU]}"
|
|
|
|
case "$i" in
|
|
O*|F*|U*) desktop_spec+="%{B#${panel_bg_focused}} $n %{B-}";;
|
|
u*) desktop_spec+="%{B#${colour_urgent}}%{A:bspc desktop -f $n:} $n %{A}%{B-}";;
|
|
o*) desktop_spec+="%{B-}%{A:bspc desktop -f $n:} $n %{A}";;
|
|
f*)
|
|
(( panel_show_empty_tags )) && {
|
|
desktop_spec+="%{B-} $n "
|
|
}
|
|
;;
|
|
esac
|
|
fi
|
|
done
|
|
|
|
read _ _ _ _ layout float _ < <( bspc query -T -d focused | get_line 1 )
|
|
|
|
if [[ "$float" == 'f' ]]; then
|
|
float_flag='f'
|
|
else
|
|
float_flag=''
|
|
fi
|
|
|
|
case "$layout" in
|
|
T) layout_flag='t';;
|
|
M) layout_flag='m';;
|
|
esac
|
|
|
|
desktop_spec+=" %{A:bsptl:}[${layout_flag}${float_flag}]%{A}"
|
|
;;
|
|
esac
|
|
|
|
msg="$desktop_spec"
|
|
|
|
[[ "$taskbar" ]] && { msg+="$taskbar"; }
|
|
|
|
msg+="%{r}%{F#${colour_bg_focused}}%{F-}%{B#${panel_bg_focused}} $updates $date "
|
|
msg+='%{B-}%{F-}'
|
|
|
|
printf '%s\n' "$msg"
|
|
done < "$panel_fifo"
|
|
}
|
|
|
|
misc_status() {
|
|
declare ip msg date
|
|
|
|
while sleep 1; do
|
|
date=$( date +%A,\ %Y.%m.%d\ %H:%M:%S )
|
|
msg="[ $date ]"
|
|
printf 'S:%s\n' "$msg"
|
|
done
|
|
}
|
|
|
|
rexec() {
|
|
kill $(jobs -p)
|
|
exec "$0"
|
|
}
|
|
|
|
main() {
|
|
trap 'cleanup' EXIT TERM INT
|
|
trap 'rexec' HUP
|
|
|
|
[[ -e "$panel_fifo" ]] && {
|
|
rm "$panel_fifo" || { return 1; }
|
|
}
|
|
|
|
mkfifo "$panel_fifo"
|
|
|
|
if (( panel_taskbar_enable )); then
|
|
xtitle -s -t "$panel_taskbar_max_title" -f 'T%s' > "$panel_fifo" &
|
|
else
|
|
xtitle -s -f 'T%s' > "$panel_fifo" &
|
|
fi
|
|
|
|
bspc control --subscribe > "$panel_fifo" &
|
|
/home/von/.config/bspwm/panel/panel_status &
|
|
|
|
bspc config top_padding "$(( panel_h + bspwm_window_gap ))"
|
|
|
|
parse_fifo_data | lemonbar -g "1280x16+0+0" \
|
|
-f "$fontspec" \
|
|
-f "$font_bold" \
|
|
-F "#${panel_fg_normal}" \
|
|
-B "#${panel_bg_normal}" | sh &
|
|
wait
|
|
}
|
|
|
|
main
|