From 390597ecd763de045b2d13e7b985f0ba8b8c4c77 Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Thu, 15 Jul 2021 14:32:00 +0200 Subject: [PATCH] polybar: avoid querying xrandr for changes too much For some reason, this makes X probe again the monitors. Switch to `xrandr --current` seems to make this problem goes away. Maybe, this is also `polybar --list-monitors` keeping a grab while polybar is starting. --- bin/polybar | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/bin/polybar b/bin/polybar index 89196f0..3bb5d1b 100755 --- a/bin/polybar +++ b/bin/polybar @@ -3,17 +3,18 @@ export DPI=$(xrdb -query | sed -nE 's/^Xft\.dpi:\s*//p') export HEIGHT=$((20 * DPI / 96)) -NUMS=$(polybar --list-monitors | wc -l) -PRIMARY=$(polybar --list-monitors | awk -F: '($0 ~ /primary/) {print $1; exit}') +MONITORS=$(xrandr --current | awk '($0 ~ / connected / && $0 ~ / [0-9]+x[0-9]+\+/) {print $1}') +PRIMARY=$(xrandr --current | awk '($0 ~ / primary /) {print $1; exit}') +NUMS=$(echo $MONITORS | wc -w) case $NUMS in 1) MONITOR=$PRIMARY polybar --reload alone & ;; *) MONITOR=$PRIMARY polybar --reload primary & - for MONITOR in $(polybar --list-monitors | awk -F: '($0 !~ /primary/) {print $1}'); do - export MONITOR - polybar --reload secondary & + for MONITOR in ${MONITORS}; do + [ $MONITOR != $PRIMARY ] || continue + MONITOR=$MONITOR polybar --reload secondary & done ;; esac