diff --git a/polybar/config.ini b/polybar/config.ini index 672cfdf..ca39915 100644 --- a/polybar/config.ini +++ b/polybar/config.ini @@ -18,13 +18,11 @@ foreground-alt = #777 foreground-caution = #bd2c40 foreground-alert = #ff4e4e -[bar/midbard] +[bardefaults] ;enable-ipc = true ; I don't use this at the moment enable-ipc = false -monitor = ${env:MONITOR:eDP-1} -width = 100% height = 27 fixed-center = true @@ -53,6 +51,15 @@ font-6 = "Material Wifi Signal strength:pixelsize=14;2" ; MPD song position font-7 = "Fira Mono:size=7;-1" +cursor-click = pointer +cursor-scroll = ns-resize + +[bar/midbard] +inherit = bardefaults + +monitor = ${env:MONITOR:eDP-1} +width = 100% + modules-left = i3 volume mpd-online-1 modules-center = date modules-right = battery cpu memory temperature eth wlan @@ -60,8 +67,14 @@ modules-right = battery cpu memory temperature eth wlan tray-position = right tray-padding = 2 -cursor-click = pointer -cursor-scroll = ns-resize +[bar/secondary] +inherit = bardefaults + +modules-left = i3 +monitor = ${env:MONITOR:eDP-1} +width = 100% + + [module/xwindow] type = internal/xwindow @@ -116,7 +129,7 @@ index-sort = true wrapping-scroll = false ; Only show workspaces on the same output as the bar -;pin-workspaces = true +pin-workspaces = true label-mode-padding = 2 label-mode-foreground = #000 @@ -124,22 +137,22 @@ label-mode-background = #ffb52a ; focused = Active workspace on focused monitor label-focused = " %index% " -label-focused-background = ${module/bspwm.label-focused-background} -label-focused-padding = ${module/bspwm.label-focused-padding} +label-focused-background = ${colors.background-selected} +label-focused-padding = 2 ; unfocused = Inactive workspace on any monitor label-unfocused = %index% -label-unfocused-padding = ${module/bspwm.label-occupied-padding} +label-unfocused-padding = 2 ; visible = Active workspace on unfocused monitor -label-visible = %index% -label-visible-background = ${self.label-focused-background} +label-visible = ${self.label-focused} +label-visible-background = ${colors.background-alt} label-visible-padding = ${self.label-focused-padding} ; urgent = Workspace with urgency hint set label-urgent = %index% -label-urgent-background = ${module/bspwm.label-urgent-background} -label-urgent-padding = ${module/bspwm.label-urgent-padding} +label-urgent-background = ${colors.background-alert} +label-urgent-padding = 2 [mpd-shared] type = internal/mpd diff --git a/polybar/launch.sh b/polybar/launch.sh index 01f6be2..e847170 100755 --- a/polybar/launch.sh +++ b/polybar/launch.sh @@ -2,23 +2,65 @@ echo "Launching polybar" +LOGDIR="$HOME/.log/my-i3-desktop/polybar-$(date +%Y%m%d_%H%M%S.%N)" +mkdir -p "$LOGDIR" +INIT_LOG="$LOGDIR/launch.log" +exec 1>&- 2>&- +exec 1>"$INIT_LOG" 2>&1 + + + +detect_primary_monitor() { + primary="$(xrandr | grep -F " connected primary" | head -n1 | cut -d ' ' -f1)" + [[ -n $primary ]] || primary="$(echo "$monitors" | grep " connected" | head -n1 | cut -d ' ' -f1)" + echo "$primary" +} + +echo -e "\nDetermining primary monitor..." +primary=$(detect_primary_monitor) +[[ -n $primary ]] || { echo "WARNING: no primary monitor detected!"; notify-send -a "Polybar launcher" "No primary monitor detected" "Couldn't detect primary monitor. Check $INIT_LOG."; } +echo "Primary monitor: $primary" + +echo -e "\nDetermining secondary monitors..." +secondary="$(xrandr --listmonitors | sed -n "1d;/$primary\$/d;"'s/^.* \([^ ][^ ]*\)$/\1/p')" +echo "Secondary monitors:"; echo "$secondary" | sed -r 's/^/* /' + + + # Terminate already running bar instances +echo -e "\nTerminating already running bars..." +echo "Running Polybar processes:" +pgrep -u $UID -x polybar | sed -r 's/^/* /' + killall -q polybar # Wait until the processes have been shut down while pgrep -u $UID -x polybar >/dev/null; do sleep 1; done +echo "Terminated." + ( + echo -e "\nReading secrets..." set -o allexport # Make all assignments exports source "$(dirname "$0")"/secrets.sh set +o allexport - # Get the primary monitor, or else just any active monitor - MONITOR="$(xrandr | grep " connected primary" | head -n1 | cut -d ' ' -f1)" - [[ -n $MONITOR ]] || MONITOR="$(xrandr | grep " connected" | head -n1 | cut -d ' ' -f1)" - [[ -n $MONITOR ]] && export MONITOR + echo - polybar --config="$HOME/.config/polybar/config.ini" midbard &>$HOME/.log/my-i3-desktop/polybar-midbard.log + start_polybar() { + echo "Starting $1 on $2" + MONITOR="$2" \ + polybar --config="$HOME/.config/polybar/config.ini" "$1" \ + &>"$LOGDIR/$1-$2.log" & disown + } + + start_polybar midbard "$primary" + + while read -r monitor; do + start_polybar secondary "$monitor" + done <<< "$secondary" ) +exec 1>&- 2>&- + echo "Polybar launched."