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
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
for display in $(xrandr --listactivemonitors | tail -n +2 | awk '{ print$2 }'); do
display=${display:1} # discard leading '+'
isprimary=$(expr match ${display} '^\*') # is this the primary display?
if [[ $isprimary -eq 1 ]]; then
MONITOR="${display:1}" polybar primary -r --config-file=${POLYBAR_CONFIG} &
else
MONITOR="$display" polybar secondary -r --config-file=${POLYBAR_CONFIG} &
for display in ${displays[@]}; do
# discard leading '+'
display=${display:1}
# If display name begins with '*' (primary) or only one display is available
isprimary=0
if [ $(expr match ${display} '^\*') -eq 1 ] || [ ${#displays[@]} -eq 1 ]; then
isprimary=1
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