From 118f77032c9e6a27f681b49b67c646d95cc61a62 Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Wed, 27 Jul 2016 08:57:56 -0500 Subject: [PATCH] work on better bar mechanics --- sh/bashrc | 16 +++++- variables.bash | 17 +++++- wm/bspwm_config | 3 +- wm/extras/bar/colors.bash | 20 +++---- wm/extras/bar/formatter.bash | 8 ++- wm/extras/bar/modules/bspwm-bm.bash | 9 ++- wm/extras/bar/modules/clock-bm.bash | 4 +- wm/extras/bar/modules/date-bm.bash | 5 +- wm/extras/bar/modules/pacaur-updates-bm.bash | 6 +- wm/extras/bar/run_bar.bash | 47 ---------------- wm/extras/bar/start.bash | 59 ++++++++++++++++++-- wm/sxhkdrc | 32 +++++++++-- 12 files changed, 140 insertions(+), 86 deletions(-) diff --git a/sh/bashrc b/sh/bashrc index f2802a5..c3f2e41 100644 --- a/sh/bashrc +++ b/sh/bashrc @@ -53,19 +53,29 @@ if [ -t 0 ]; then # arch aliases alias archupdate="pacaur -Syyu --noconfirm --noedit" - # wm aliases - alias startbar="source $DOTFILES_PATH/wm/extras/bar/start.bash" stopbar() { if [[ -f "$BAR_PID_FILE" ]]; then + echo kill -SIGINT $(cat "$BAR_PID_FILE") rm -f "$BAR_PID_FILE" - killall lemonbar else echo "Bar is not running." fi } export -f stopbar + # wm aliases + startbar() { + if [[ -f "$BAR_PID_FILE" ]]; then + stopbar + fi + "$DOTFILES_PATH/wm/extras/bar/start.bash" + echo $! > "$BAR_PID_FILE" + bg + disown + } + export -f startbar + # misc aliases alias keyrepeat="xset r rate 250 80" diff --git a/variables.bash b/variables.bash index d2d995e..31c91d2 100755 --- a/variables.bash +++ b/variables.bash @@ -5,8 +5,8 @@ export DOTFILES_PATH="$HOME/.dotfiles" export REPOSITORY_PATH="$HOME/Documents/open-source" -export WINDOW_GAP=5 export BORDER_WIDTH=1 +export WINDOW_GAP=5 export BAR_PID_FILE="$DOTFILES_PATH/wm_bar.pid" source "$DOTFILES_PATH/scripts/get_x_fonts.sh" @@ -14,14 +14,27 @@ source "$DOTFILES_PATH/scripts/get_color.sh" export BAR_ON_XINIT=0 export BAR_FIFO="$DOTFILES_PATH/wm_bar_fifo.lock" +export BAR_LOG="$DOTFILES_PATH/wm_bar.log" export BAR_TOP=0 -export BAR_MARGIN=$WINDOW_GAP export BAR_HEIGHT=20 export BAR_BORDER_WIDTH=1 export BAR_FONT_FAMILY="$PRIMARY_FONT_FAMILY_WITH_SIZE" export BAR_UNDERLINE=1 +# export BAR_MARGIN=$WINDOW_GAP +export BAR_MARGIN=700 export BAR_WID="wmpanel" +export TOP_BAR_PADDING=0 +export BOTTOM_BAR_PADDING=0 + +if [[ $BAR_TOP -eq 0 ]]; then + export BOTTOM_BAR_PADDING=$BAR_HEIGHT +else + export TOP_BAR_PADDING=$BAR_HEIGHT +fi + +export WINDOW_GAP=$(expr $WINDOW_GAP - $BORDER_WIDTH) + # load per-device bashrc_env if it exists if [ -a "$HOME/.bashrc_env" ]; then . "$HOME/.bashrc_env" diff --git a/wm/bspwm_config b/wm/bspwm_config index 01bcf60..8c4702d 100755 --- a/wm/bspwm_config +++ b/wm/bspwm_config @@ -11,13 +11,12 @@ source "$DOTFILES_PATH/scripts/get_x_fonts.sh" bspc config normal_border_color "#$(get_color 01)" bspc config focused_border_color "#$(get_color 0D)" -bspc config active_border_color "#$(get_color 0C)" +bspc config active_border_color "#$(get_color 09)" bspc config presel_feedback_color "#$(get_color 04)" bspc config border_width "$BORDER_WIDTH" bspc config split_ratio 0.50 bspc config borderless_monocle true bspc config gapless_monocle true -bspc config focus_by_distance true bspc config window_gap "$WINDOW_GAP" diff --git a/wm/extras/bar/colors.bash b/wm/extras/bar/colors.bash index caa2443..5995e75 100644 --- a/wm/extras/bar/colors.bash +++ b/wm/extras/bar/colors.bash @@ -1,12 +1,12 @@ -export COLOR_FOREGROUND="#ff$(get_color 05)" -export COLOR_DARK="#ff$(get_color 02)" -export COLOR_BACKGROUND="#ff$(get_color 00)" -export COLOR_HIGHLIGHT="#ff$(get_color 0D)" -export COLOR_URGENT="#ff$(get_color 08)" +export COLOR_FOREGROUND="#$(get_color 05 | awk '{print toupper($0)}')" +export COLOR_DARK="#$(get_color 02 | awk '{print toupper($0)}')" +export COLOR_BACKGROUND="#$(get_color 00 | awk '{print toupper($0)}')" +export COLOR_HIGHLIGHT="#$(get_color 0D | awk '{print toupper($0)}')" +export COLOR_URGENT="#$(get_color 08 | awk '{print toupper($0)}')" -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)" +export COLOR_S1="#$(get_color 0E | awk '{print toupper($0)}')" +export COLOR_S2="#$(get_color 0F | awk '{print toupper($0)}')" +export COLOR_S3="#$(get_color 0D | awk '{print toupper($0)}')" +export COLOR_S4="#$(get_color 0A | awk '{print toupper($0)}')" +export COLOR_S5="#$(get_color 09 | awk '{print toupper($0)}')" diff --git a/wm/extras/bar/formatter.bash b/wm/extras/bar/formatter.bash index 3f5fb01..40b1a14 100755 --- a/wm/extras/bar/formatter.bash +++ b/wm/extras/bar/formatter.bash @@ -16,13 +16,19 @@ export MODULE_MATCH=() export MODULE_CALLBACK=() export MODULE_DATA=() export MODULE_CONTENT=() +export MODULE_INIT=() +export MODULE_PIDS="" 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" + MODULE_INIT[$1]=$4 + ${MODULE_INIT[$1]} & + PID=$! + echo $PID > "$DOTFILES_PATH/wm/extras/bar/modules/$3.pid" + # echo -e "Registered Bar Module: $1 $2 $3 $4 with PID $PID" >> "$BAR_LOG" } export -f register_bar_module diff --git a/wm/extras/bar/modules/bspwm-bm.bash b/wm/extras/bar/modules/bspwm-bm.bash index d969747..4e0d5fb 100644 --- a/wm/extras/bar/modules/bspwm-bm.bash +++ b/wm/extras/bar/modules/bspwm-bm.bash @@ -51,7 +51,12 @@ bar_module_bspwm() { echo -e "$content" } export -f bar_module_bspwm -register_bar_module "$PRIORITY" "$MATCH" "bar_module_bspwm" -bspc subscribe all > "$BAR_FIFO" & +bar_module_bspwm_updater() +{ + bspc subscribe all > "$BAR_FIFO" +} +export -f bar_module_bspwm_updater + +register_bar_module "$PRIORITY" "$MATCH" "bar_module_bspwm" "bar_module_bspwm_updater" diff --git a/wm/extras/bar/modules/clock-bm.bash b/wm/extras/bar/modules/clock-bm.bash index 42c674c..10faaba 100644 --- a/wm/extras/bar/modules/clock-bm.bash +++ b/wm/extras/bar/modules/clock-bm.bash @@ -13,7 +13,6 @@ bar_module_clock() { } export -f bar_module_clock -register_bar_module "$PRIORITY" "$MATCH" "bar_module_clock" bar_module_clock_updater() { while true; do @@ -21,5 +20,6 @@ bar_module_clock_updater() { sleep 1 done } -bar_module_clock_updater & +export -f bar_module_clock_updater +register_bar_module "$PRIORITY" "$MATCH" "bar_module_clock" "bar_module_clock_updater" diff --git a/wm/extras/bar/modules/date-bm.bash b/wm/extras/bar/modules/date-bm.bash index 7fe4685..75a63c8 100644 --- a/wm/extras/bar/modules/date-bm.bash +++ b/wm/extras/bar/modules/date-bm.bash @@ -11,9 +11,7 @@ MATCH="$MATCH_PREFIX*" bar_module_date() { echo -e "%{T-}%{r}%{F$COLOR_S2}${1:7}%{F-}" } - export -f bar_module_date -register_bar_module "$PRIORITY" "$MATCH" "bar_module_date" bar_module_date_updater() { while true; do @@ -21,5 +19,6 @@ bar_module_date_updater() { sleep 60 done } -bar_module_date_updater & +export -f bar_module_date_updater +register_bar_module "$PRIORITY" "$MATCH" "bar_module_date" "bar_module_date_updater" diff --git a/wm/extras/bar/modules/pacaur-updates-bm.bash b/wm/extras/bar/modules/pacaur-updates-bm.bash index 04aba2f..48ac86d 100644 --- a/wm/extras/bar/modules/pacaur-updates-bm.bash +++ b/wm/extras/bar/modules/pacaur-updates-bm.bash @@ -11,9 +11,7 @@ MATCH="$MATCH_PREFIX*" bar_module_pacaur() { echo -e "%{T-}%{F$COLOR_DARK}pac %{F$COLOR_S1}${1:9}%{F-}" } - export -f bar_module_pacaur -register_bar_module "$PRIORITY" "$MATCH" "bar_module_pacaur" bar_module_pacaur_updater() { while true; do @@ -26,6 +24,8 @@ bar_module_pacaur_updater() { fi done } -bar_module_pacaur_updater & +export -f bar_module_pacaur_updater + +register_bar_module "$PRIORITY" "$MATCH" "bar_module_pacaur" "bar_module_pacaur_updater" echo -e "$MATCH_PREFIX"?? > "$BAR_FIFO" diff --git a/wm/extras/bar/run_bar.bash b/wm/extras/bar/run_bar.bash index 46feb6e..e69de29 100755 --- a/wm/extras/bar/run_bar.bash +++ b/wm/extras/bar/run_bar.bash @@ -1,47 +0,0 @@ -#!/usr/bin/env bash - -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 - bspc config -m $(bspc query -M | head -n 1) bottom_padding "0" - fi -} - -if [ -e "$BAR_PID_FILE" ]; then - killbar -fi - -trap killbar INT TERM QUIT EXIT - -rm -f "$BAR_FIFO" -mkfifo "$BAR_FIFO" - -if [ $BAR_TOP -eq 1 ]; then - bspc config -m $(bspc query -M | head -n 1) top_padding "$BAR_HEIGHT" -else - bspc config -m $(bspc query -M | head -n 1) bottom_padding "$BAR_HEIGHT" -fi - -# 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)) - -BAR_B="" -if [ $BAR_TOP -eq 1 ]; then - : -else - BAR_B="-b" -fi - -source "$DOTFILES_PATH/wm/extras/bar/colors.bash" - -cat "$BAR_FIFO" | "$DOTFILES_PATH/wm/extras/bar/formatter.bash" | lemonbar $BAR_B -g \ - "$WIDTH"x"$BAR_HEIGHT"+"$BAR_MARGIN"+"$POS_Y" -u "$BAR_BORDER_WIDTH" -f \ - "$BAR_FONT_FAMILY" -F "$COLOR_FOREGROUND" -B "$COLOR_BACKGROUND" -n "$BAR_WID" - -killbar diff --git a/wm/extras/bar/start.bash b/wm/extras/bar/start.bash index 6c6b3e4..e335ade 100755 --- a/wm/extras/bar/start.bash +++ b/wm/extras/bar/start.bash @@ -2,11 +2,60 @@ source "$DOTFILES_PATH/variables.bash" -"$DOTFILES_PATH/wm/extras/bar/run_bar.bash" & -export BAR_PID=$! +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 + bspc config -m $(bspc query -M | head -n 1) bottom_padding "0" + fi + for f in $(ls "$DOTFILES_PATH"/wm/extras/bar/modules/*.pid 2>/dev/null); do + # echo "KILLING MODULE PROCESS $f WITH PID $(cat "$f")" + # kill -SIGTERM $(cat "$f") + rm "$f" + done + kill $! + # kill -SIGTERM $BARPID +} +export -f killbar -echo "$BAR_PID" > "$BAR_PID_FILE" -echo "Starting bar with PID $BAR_PID" +trap killbar INT TERM QUIT EXIT -xdo lower -a wmpanel +rm -f "$BAR_FIFO" +mkfifo "$BAR_FIFO" +if [ $BAR_TOP -eq 1 ]; then + bspc config -m $(bspc query -M | head -n 1) top_padding "$BAR_HEIGHT" +else + bspc config -m $(bspc query -M | head -n 1) bottom_padding "$BAR_HEIGHT" +fi + +# 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)) + +BAR_B="" +if [ $BAR_TOP -eq 1 ]; then + : +else + BAR_B="-b" +fi + +source "$DOTFILES_PATH/wm/extras/bar/colors.bash" + +echo $COLOR_FOREGROUND +echo $COLOR_DARK +echo $COLOR_BACKGROUND +echo $COLOR_HIGHLIGHT +echo $COLOR_URGENT + +echo $COLOR_S1 +echo $COLOR_S2 +echo $COLOR_S3 +echo $COLOR_S4 +echo $COLOR_S5 + + +cat "$BAR_FIFO" | "$DOTFILES_PATH/wm/extras/bar/formatter.bash" | \ + lemonbar $BAR_B -g "$WIDTH"x"$BAR_HEIGHT"+"$BAR_MARGIN"+"$POS_Y" -u "$BAR_BORDER_WIDTH" -f "$BAR_FONT_FAMILY" -F "$COLOR_FOREGROUND" -B"$COLOR_BACKGROUND" -n "$BAR_WID" diff --git a/wm/sxhkdrc b/wm/sxhkdrc index ba8ba09..3cf4ec6 100755 --- a/wm/sxhkdrc +++ b/wm/sxhkdrc @@ -102,22 +102,42 @@ super + @button{1-3} # change node gap and desktop padding super + plus - bspc config -d focused node_gap $((`bspc config -d focused node_gap` + 5 )) + bspc config -d focused window_gap $((`bspc config -d focused window_gap` + 5 )) super + equal - bspc config -m $(bspc query -M | head -n 1) top_padding $BAR_HEIGHT; bspc config -d focused node_gap $node_GAP + bspc config -m $(bspc query -M | head -n 1) top_padding $TOP_BAR_PADDING; bspc config -m $(bspc query -M | head -n 1) bottom_padding $BOTTOM_BAR_PADDING; bspc config -d focused window_gap $WINDOW_GAP super + minus - bspc config -d focused node_gap $((`bspc config -d focused node_gap` - 5 )) + bspc config -d focused window_gap $((`bspc config -d focused window_gap` - 5 )) super + alt + r - bspc config -m $(bspc query -M | head -n 1) top_padding $BAR_HEIGHT; bspc config -d focused node_gap 0 + bspc config -m $(bspc query -M | head -n 1) bottom_padding $BOTTOM_BAR_PADDING; bspc config -m $(bspc query -M | head -n 1) top_padding $TOP_BAR_PADDING; bspc config -d focused window_gap $WINDOW_GAP + +super + alt + equal + bspc config -d focused bottom_padding 0; bspc config -d focused top_padding 0; bspc config -d focused left_padding 0; bspc config -d focused right_padding 0 super + alt + plus - bspwm_padding +5 + bspc config -d focused bottom_padding $(expr $(bspc config -d focused bottom_padding) + 5); bspc config -d focused top_padding $(expr $(bspc config -d focused top_padding) + 5); bspc config -d focused left_padding $(expr $(bspc config -d focused left_padding) + 5); bspc config -d focused right_padding $(expr $(bspc config -d focused right_padding) + 5) + + bspc config -d focused bottom_padding $(expr $(bspc config -d focused bottom_padding) + 5); bspc config -d focused top_padding $(expr $(bspc config -d focused top_padding) + 5); bspc config -d focused left_padding $(expr $(bspc config -d focused left_padding) + 5); bspc config -d focused right_padding $(expr $(bspc config -d focused right_padding) + 5) + +super + ctrl + alt + k + bspc config -d focused bottom_padding $(expr $(bspc config -d focused bottom_padding) - 5); bspc config -d focused top_padding $(expr $(bspc config -d focused top_padding) - 5) + +super + ctrl + alt + j + bspc config -d focused bottom_padding $(expr $(bspc config -d focused bottom_padding) + 5); bspc config -d focused top_padding $(expr $(bspc config -d focused top_padding) + 5) + +super + ctrl + alt + h + bspc config -d focused left_padding $(expr $(bspc config -d focused left_padding) - 5); bspc config -d focused right_padding $(expr $(bspc config -d focused right_padding) - 5) + +super + ctrl + alt + l + bspc config -d focused left_padding $(expr $(bspc config -d focused left_padding) + 5); bspc config -d focused right_padding $(expr $(bspc config -d focused right_padding) + 5) + +super + alt + plus + bspc config -d focused bottom_padding $(expr $(bspc config -d focused bottom_padding) + 5); bspc config -d focused top_padding $(expr $(bspc config -d focused top_padding) + 5); bspc config -d focused left_padding $(expr $(bspc config -d focused left_padding) + 5); bspc config -d focused right_padding $(expr $(bspc config -d focused right_padding) + 5) super + alt + minus - bspwm_padding -5 + bspc config -d focused bottom_padding $(expr $(bspc config -d focused bottom_padding) - 5) # wm-independant shortcuts