fix up polybar launch.sh to always treat single display as primary

This commit is contained in:
Mark Riedesel 2019-07-19 15:46:52 -05:00
parent 79f2d23372
commit 44480115c3

View file

@ -5,13 +5,26 @@ POLYBAR_CONFIG=$(dirname $0)/config
killall -q polybar killall -q polybar
while pgrep -u $UID -x polybar >/dev/null; do sleep 1; done while pgrep -u $UID -x polybar >/dev/null; do sleep 1; done
displays=($(xrandr --listactivemonitors | tail -n +2 | awk '{ print $2 }'))
# display 'primary' bar on primary display and 'secondary' bar on all other displays # display 'primary' bar on primary display and 'secondary' bar on all other displays
for display in $(xrandr --listactivemonitors | tail -n +2 | awk '{ print$2 }'); do for display in ${displays[@]}; do
display=${display:1} # discard leading '+' # discard leading '+'
isprimary=$(expr match ${display} '^\*') # is this the primary display? display=${display:1}
if [[ $isprimary -eq 1 ]]; then
MONITOR="${display:1}" polybar primary -r --config-file=${POLYBAR_CONFIG} & # If display name begins with '*' (primary) or only one display is available
else isprimary=0
MONITOR="$display" polybar secondary -r --config-file=${POLYBAR_CONFIG} & if [ $(expr match ${display} '^\*') -eq 1 ] || [ ${#displays[@]} -eq 1 ]; then
isprimary=1
fi fi
# Choose appropriate configuration depending whether or not this is a primary display
[ $isprimary -eq 1 ] && config='primary' || config='secondary'
# Clean up the display name
display=${display#"*"} # discard leading '*' if present
echo $display $isprimary $config
# Launch polybar!
MONITOR=${display} polybar ${config} -r --config-file=${POLYBAR_CONFIG} &
done done