diff --git a/.config/bspwm/bspwmrc b/.config/bspwm/bspwmrc index 489d4a0c..a6d2060f 100755 --- a/.config/bspwm/bspwmrc +++ b/.config/bspwm/bspwmrc @@ -38,11 +38,8 @@ if [[ $(pgrep polybar) ]]; then killall polybar fi -# Polybar and related configuration -$( - export PB_WM_RESTACK=bspwm - polybar -r primary-top & -)& +# Start Polybar +$HOME/.config/polybar/start.sh ## bspwm GENERAL CONFIGURATION bspc monitor -d 1 2 3 4 5 6 7 8 diff --git a/.config/polybar/config b/.config/polybar/config index 1dfde189..d09fd587 100644 --- a/.config/polybar/config +++ b/.config/polybar/config @@ -73,6 +73,7 @@ font-4 = ${res/fonts.font-4} # BARS #==================== [bar/primary-top] +monitor = ${env:PB_MONITOR} inherit = template/bar tray-position = right @@ -81,6 +82,7 @@ modules-center = xwindow modules-right = xbacklight volume battery wlan date [bar/secondary-top] +monitor = ${env:PB_MONITOR} inherit = template/bar modules-left = i3 bspwm diff --git a/.config/polybar/start.sh b/.config/polybar/start.sh new file mode 100755 index 00000000..1ecdfbb6 --- /dev/null +++ b/.config/polybar/start.sh @@ -0,0 +1,37 @@ +#!/bin/bash +# +# start.sh +# Copyright (C) 2018 salt +# +# Distributed under terms of the MIT license. +# + +# Which WM are we using? +if $(pgrep i3); then + export PB_WM_RESTACK=i3 +fi +if $(pgrep bspwm); then + export PB_WM_RESTACK=bspwm +fi + +# Iterate through monitors and spawn bars on each +# Starting with the primary monitor... +export PB_MONITOR=$(xrandr -q | awk '/\/{print $1}') +if [[ $PB_MONITOR == "" ]]; then + exit 1 +fi +polybar -r primary-top& +# ...and then moving on to secondaries, if we have them +# Alright, now this looks *really* bad, but there's no way in hell you can get +# me to attempt to solve this with regex. Fuck regex. It starts more problems +# than it solves +export secondary_monitors=$(xrandr -q | grep ' connected' | grep -v 'primary' | awk '{print $1}') +if [[ $PB_MONITOR == "" ]]; then + exit 0 +fi +for monitor in secondary_monitors; do + PB_MONITOR=$monitor polybar -r secondary-top +done + +disown +exit