diff --git a/autorandr b/autorandr index c14f5cb..fd4c642 100755 --- a/autorandr +++ b/autorandr @@ -75,7 +75,7 @@ fi setup_fp_xrandr_edid() { $XRANDR -q --verbose | awk ' - /^[^ ]+ (dis)?connected / { DEV=$1; } + /^[^ ]+ (dis)?connected / || /^[^ ]+ unknown connection / { DEV=$1; } $1 ~ /^[a-f0-9]+$/ { ID[DEV] = ID[DEV] $1 } END { for (X in ID) { print X " " ID[X]; } }' } @@ -164,6 +164,13 @@ config_equal() { } load_cfg_xrandr() { + # Disable all displays first. There is a bug in xrandr where trying to enable a different display + # when two displays are already attached gives the error "cannot find crtc for output" even + # when --off was passed to disable existing displays. If --off is called first as a separate + # command the crtcs are freed up for use. + # https://bugs.freedesktop.org/show_bug.cgi?id=22539 + # https://bugs.freedesktop.org/show_bug.cgi?id=29929 + $XRANDR | grep -P '(^[^ ]+) (dis)?connected' | sed -r 's/(^[^ ]+).*/--output \1 --off/' | xargs $XRANDR sed 's!^!--!' "$1" | xargs $XRANDR } @@ -250,6 +257,7 @@ if [ -n "$LOAD_PROFILE" ]; then exit $? fi +LOADED=0 for SETUP_FILE in $PROFILES/*/setup; do if ! [ -e $SETUP_FILE ]; then break @@ -257,7 +265,11 @@ for SETUP_FILE in $PROFILES/*/setup; do PROFILE="$(basename $(dirname "$SETUP_FILE"))" echo -n "$PROFILE" - if blocked "$PROFILE"; then + if [ "$LOADED" -eq 1 ]; then + # profile already loaded, skip the rest + echo "" + continue + elif blocked "$PROFILE"; then echo " (blocked)" continue fi @@ -268,15 +280,19 @@ for SETUP_FILE in $PROFILES/*/setup; do if [ "$CHANGE_PROFILE" -eq 1 ]; then if [ "$FORCE_LOAD" -eq 1 ] || ! config_equal "$PROFILE"; then load "$PROFILE" + LOADED=1 fi fi - # found the profile, exit with success - exit 0 else echo "" fi done +# found the profile, exit with success +if [ "$LOADED" -eq 1 ]; then + exit 0 +fi + # we did not find the profile, load default if [ -n "$DEFAULT_PROFILE" ]; then echo "No suitable profile detected, falling back to $DEFAULT_PROFILE" diff --git a/pm-utils/40auto-disper b/pm-utils/40auto-disper new file mode 120000 index 0000000..9d7b227 --- /dev/null +++ b/pm-utils/40auto-disper @@ -0,0 +1 @@ +40autorandr \ No newline at end of file diff --git a/pm-utils/40autorandr b/pm-utils/40autorandr index 60ca9ae..db4b15f 100755 --- a/pm-utils/40autorandr +++ b/pm-utils/40autorandr @@ -2,22 +2,35 @@ # # 40autorandr: Change autorandr profile on thaw/resume -AUTORANDR="autorandr -c" +# detect if we are being called as 40auto-disper or 40autorandr +FORM=${0##*40} +case $FORM in + auto-disper) + AUTORANDR="auto-disper -c" + ;; + *) + AUTORANDR="autorandr -c" + ;; +esac +echo "$AUTORANDR" detect_display() { for X in /tmp/.X11-unix/X*; do D="${X##/tmp/.X11-unix/X}" - user=$(who | awk -vD="$D" '$5 ~ "\\(:"D"\\)$" {print $1}') + user=$(who | awk -vD="$D" '$5 ~ "\\(:"D"\\)$" {print $1; exit}') + echo "Checking $X -- $D - $user" if [ x"$user" != x"" ]; then + echo "AUTORANDR $D - $user" export DISPLAY=":$D" /bin/su -c "${AUTORANDR}" "$user" fi done + echo "Done" } case "$1" in thaw|resume) - detect_display + detect_display ;; esac