basic bar and module system ready
This commit is contained in:
parent
a4c06b34cf
commit
657c1c3068
7 changed files with 181 additions and 10 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,3 +1,4 @@
|
|||
colors/gen/vendor
|
||||
colors/gen/tmp
|
||||
*.lock
|
||||
*.log
|
||||
|
|
|
@ -4,3 +4,9 @@ export COLOR_BACKGROUND="#ff$(get_color 00)"
|
|||
export COLOR_HIGHLIGHT="#ff$(get_color 0D)"
|
||||
export COLOR_URGENT="#ff$(get_color 08)"
|
||||
|
||||
export COLOR_S1="#ff$(get_color 0E)"
|
||||
export COLOR_S2="#ff$(get_color 0F)"
|
||||
export COLOR_S3="#ff$(get_color 0D)"
|
||||
export COLOR_S4="#ff$(get_color 0A)"
|
||||
export COLOR_S5="#ff$(get_color 09)"
|
||||
|
||||
|
|
|
@ -3,6 +3,9 @@
|
|||
source "$DOTFILES_PATH/variables.bash"
|
||||
source "$DOTFILES_PATH/wm/extras/bar/colors.bash"
|
||||
|
||||
export BAR_LOG="$PWD/bar.log"
|
||||
echo -e "BEGIN BAR LOG\n" > "$BAR_LOG"
|
||||
|
||||
ul="u"
|
||||
if [ $BAR_UNDERLINE -eq 1 ]; then
|
||||
:
|
||||
|
@ -10,23 +13,42 @@ else
|
|||
ul="o"
|
||||
fi
|
||||
|
||||
export $MODULE_MATCH=
|
||||
export $MODULE_CALLBACK=
|
||||
export $MODULE_DATA=
|
||||
export MODULE_MATCH=()
|
||||
export MODULE_CALLBACK=()
|
||||
export MODULE_DATA=()
|
||||
export MODULE_CONTENT=()
|
||||
|
||||
register_bar_module() {
|
||||
:
|
||||
MODULE_MATCH[$1]=$2
|
||||
MODULE_CALLBACK[$1]=$3
|
||||
MODULE_DATA[$1]=
|
||||
MODULE_CONTENT[$1]=
|
||||
echo -e "Registered Bar Module: $1 $2 $3" >> "$BAR_LOG"
|
||||
}
|
||||
export -f register_bar_module
|
||||
|
||||
source "$DOTFILES_PATH/wm/extras/bar/modules/*-bm.bash"
|
||||
for f in "$DOTFILES_PATH/wm/extras/bar/modules/"*-bm.bash; do
|
||||
source "$f"
|
||||
done
|
||||
|
||||
while read -r line; do
|
||||
content=
|
||||
for i in $MODULE_MATCH; do
|
||||
content=$content$i
|
||||
echo -e "Bar Line: $line" >> "$BAR_LOG"
|
||||
for i in ${!MODULE_MATCH[@]}; do
|
||||
if [[ $line == ${MODULE_MATCH[$i]} ]]; then
|
||||
echo -e "Bar Module Update: [$i] Matched ${MODULE_MATCH[$i]} with $line" >> "$BAR_LOG"
|
||||
MODULE_CONTENT[$i]=$("${MODULE_CALLBACK[$i]}" $line)
|
||||
echo -e "New Module Content: "${MODULE_CONTENT[$i]} >> "$BAR_LOG"
|
||||
fi
|
||||
done
|
||||
|
||||
content=""
|
||||
for i in ${!MODULE_CONTENT[@]}; do
|
||||
echo -e "Processing Module $i Content..." >> "$BAR_LOG"
|
||||
content="$content ${MODULE_CONTENT[$i]}"
|
||||
done
|
||||
|
||||
printf " %s \n" "$content"
|
||||
done
|
||||
|
||||
echo -e "\nEND BAR LOG" >> "$BAR_LOG"
|
||||
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
source "$DOTFILES_PATH/variables.bash"
|
||||
source "$DOTFILES_PATH/wm/extras/bar/colors.bash"
|
||||
|
||||
PRIORITY=2500
|
||||
|
||||
MATCH_PREFIX="W"
|
||||
MATCH="$MATCH_PREFIX*"
|
||||
|
||||
ul="u"
|
||||
if [ $BAR_UNDERLINE -eq 1 ]; then
|
||||
:
|
||||
else
|
||||
ul="o"
|
||||
fi
|
||||
|
||||
bar_module_bspwm() {
|
||||
content="%{F$COLOR_FOREGROUND}%{c}"
|
||||
line=$1
|
||||
IFS=':'
|
||||
set -- ${line#?}
|
||||
while [ $# -gt 0 ] ; do
|
||||
item=$1
|
||||
name=${item#?}
|
||||
cname="$name"
|
||||
case $item in
|
||||
M*)
|
||||
:
|
||||
;;
|
||||
m*)
|
||||
:
|
||||
;;
|
||||
O*)
|
||||
# focused occupied desktop
|
||||
content="${content} %{F$COLOR_HIGHLIGHT}%{U$COLOR_HIGHLIGHT}%{+${ul}}${cname}%{-${ul}}%{U-}%{F-}"
|
||||
;;
|
||||
F*)
|
||||
# focused free desktop
|
||||
content="${content} %{F$COLOR_DARK}%{U$COLOR_DARK}%{+${ul}}${cname}%{-${ul}}%{U-}%{F-}"
|
||||
;;
|
||||
U*)
|
||||
# focused occupied desktop
|
||||
content="${content} %{F$COLOR_URGENT}%{U$COLOR_URGENT}%{+${ul}}${cname}%{-${ul}}%{U-}%{F-}"
|
||||
;;
|
||||
o*)
|
||||
# occupied desktop
|
||||
content="${content} %{F$COLOR_FOREGROUND}${cname}%{F-}"
|
||||
;;
|
||||
f*)
|
||||
# free desktop
|
||||
content="${content} %{F$COLOR_DARK}${cname}%{F-}"
|
||||
;;
|
||||
u*)
|
||||
# urgent desktop
|
||||
content="${content} %{F$COLOR_URGENT}${cname}%{F-}"
|
||||
;;
|
||||
L*)
|
||||
# layout
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
echo -e "$content%{F-}"
|
||||
}
|
||||
export -f bar_module_bspwm
|
||||
register_bar_module "$PRIORITY" "$MATCH" "bar_module_bspwm"
|
||||
|
||||
bspc subscribe all > "$BAR_FIFO" &
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
source "$DOTFILES_PATH/variables.bash"
|
||||
source "$DOTFILES_PATH/wm/extras/bar/colors.bash"
|
||||
|
||||
PRIORITY=3800
|
||||
|
||||
MATCH_PREFIX="BM_CLOCK"
|
||||
MATCH="$MATCH_PREFIX*"
|
||||
|
||||
bar_module_clock() {
|
||||
echo -e "%{T-}%{r}%{F$COLOR_S1}${1:8}%{F-}"
|
||||
}
|
||||
|
||||
export -f bar_module_clock
|
||||
register_bar_module "$PRIORITY" "$MATCH" "bar_module_clock"
|
||||
|
||||
bar_module_clock_updater() {
|
||||
while true; do
|
||||
echo -e "$MATCH_PREFIX""$(date +%H.%M.%S)" > $BAR_FIFO
|
||||
sleep 1
|
||||
done
|
||||
}
|
||||
bar_module_clock_updater &
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
source "$DOTFILES_PATH/variables.bash"
|
||||
|
||||
# This defines this module's priority, determining where it will be rendered on
|
||||
# the bar relative to other modules.
|
||||
PRIORITY=2500
|
||||
|
||||
# This is the trigger that the incoming line from the FIFO must match in order
|
||||
# to be processed by this module.
|
||||
MATCH_PREFIX="BM_EXAMPLE"
|
||||
MATCH="$MATCH_PREFIX*"
|
||||
|
||||
# Define the function that will be called upon the match being triggered. This
|
||||
# should process the first argument (the line from the FIFO) and echo the
|
||||
# desired bar output.
|
||||
bar_module_example() {
|
||||
# Write the line from the 10th character (cutting off the MATCH_PREFIX) with
|
||||
# lemonbar's left-align delimiter.
|
||||
echo -e "%{l}${1:10}"
|
||||
}
|
||||
|
||||
# Export our function so that the formatter script can call it.
|
||||
export -f bar_module_bspwm
|
||||
|
||||
# Call this handy function for adding the various thing we declared to the
|
||||
# MODULE_ variables that the formatter script uses.
|
||||
register_bar_module "$PRIORITY" "$MATCH" "bar_module_example"
|
||||
|
||||
# Create a function that will periodically write to the FIFO with the correct
|
||||
# prefix, thereby updating the module.
|
||||
bar_module_example_updater() {
|
||||
while [ $BAR_RUNNING -eq 1 ]; do
|
||||
echo -e "$MATCH_PREFIX""$(date +%H.%M)" > "$BAR_FIFO"
|
||||
sleep 30
|
||||
done
|
||||
}
|
||||
|
||||
# Fork that function to a background process.
|
||||
bar_module_clock_updater &
|
||||
|
||||
# Optional: Initialize that module by immediately writing to the FIFO using your
|
||||
# prefix to show some default information on the bar when it loads.
|
||||
echo -e "$MATCH_PREFIX"Loading... > "$BAR_FIFO"
|
||||
|
|
@ -2,7 +2,9 @@
|
|||
|
||||
source "$DOTFILES_PATH/variables.bash"
|
||||
|
||||
export BAR_RUNNING=1
|
||||
function killbar() {
|
||||
export BAR_RUNNING=0
|
||||
if [ $BAR_TOP -eq 1 ]; then
|
||||
bspc config -m $(bspc query -M | head -n 1) top_padding "0"
|
||||
else
|
||||
|
@ -21,8 +23,6 @@ else
|
|||
bspc config -m $(bspc query -M | head -n 1) bottom_padding "$BAR_HEIGHT"
|
||||
fi
|
||||
|
||||
bspc subscribe all > "$BAR_FIFO" &
|
||||
|
||||
# get width of our main monitor
|
||||
WIDTH=`xrandr -q | egrep '(^| )connected( |$)' | tr 'x' '\n' | head -n 1 | awk '{print $NF}'`
|
||||
WIDTH=$((WIDTH-BAR_MARGIN-BAR_MARGIN))
|
||||
|
@ -37,3 +37,5 @@ fi
|
|||
source "$DOTFILES_PATH/wm/extras/bar/colors.bash"
|
||||
|
||||
cat "$BAR_FIFO" | "$DOTFILES_PATH/wm/extras/bar/formatter.bash" | lemonbar $BAR_B -d -g "$WIDTH"x"$BAR_HEIGHT"+"$BAR_MARGIN"+"$POS_Y" -u "$BAR_BORDER_WIDTH" -f "$BAR_FONT_FAMILY" -F "$COLOR_FOREGROUND" -B "$COLOR_BACKGROUND"
|
||||
|
||||
killbar
|
||||
|
|
Reference in a new issue