From 7af66d281ca74717f3d0ab024f4cc12753aee1b1 Mon Sep 17 00:00:00 2001 From: Maciej Sitarz Date: Wed, 18 Jan 2012 21:59:28 +0100 Subject: [PATCH 01/10] Merged with last wertarbyte changes --- autorandr | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/autorandr b/autorandr index a8d8914..b38d250 100755 --- a/autorandr +++ b/autorandr @@ -107,7 +107,7 @@ setup_fp() { done if [ -z "$FP" ]; then echo "Unable to fingerprint display configuration" >&2 - return + e:return fi echo "$FP" } @@ -120,6 +120,7 @@ current_cfg_xrandr() { print "output "$1; print "mode "A[1]; print "pos "A[2]"x"A[3]; + print " "A[4]; next; } # disconnected or disabled displays From a2e85e5aa72cf6d3526ce38af108ce6883f1fb1c Mon Sep 17 00:00:00 2001 From: Maciej Sitarz Date: Wed, 18 Jan 2012 22:07:01 +0100 Subject: [PATCH 02/10] Added pm-utils hook to be run on resume/thaw. --- 00autorandr_pm-utils | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 00autorandr_pm-utils diff --git a/00autorandr_pm-utils b/00autorandr_pm-utils new file mode 100755 index 0000000..1637445 --- /dev/null +++ b/00autorandr_pm-utils @@ -0,0 +1,27 @@ +#!/bin/sh +# +# 90autorandr: Change autorand profile on thaw/resume + +AUTORANDR="autorandr -c" + +detect_display() +{ + for x in /tmp/.X11-unix/*; do + displaynum=`echo $x | sed s#/tmp/.X11-unix/X##` + user=$(who|awk '$5 ~ regexp {print $1}' regexp="\\\(:$displaynum\\\)") + if [ x"$user" = x"" ]; then + user=$(who|awk '$2 ~ regexp {print $1}' regexp=":$displaynum") + fi + if [ x"$user" != x"" ]; then + export DISPLAY=":$displaynum" + /bin/su -c "${AUTORANDR}" "$user" + return 0 + fi + done +} + +case "$1" in + thaw|resume) + detect_display + ;; +esac From 1e78bf51509750e8a2ebefee9357aa1cc6919fd3 Mon Sep 17 00:00:00 2001 From: Maciej Sitarz Date: Sat, 11 Feb 2012 22:17:06 +0100 Subject: [PATCH 03/10] Detect primary screen and save to config. --- autorandr | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/autorandr b/autorandr index b38d250..d93ebe4 100755 --- a/autorandr +++ b/autorandr @@ -113,14 +113,16 @@ setup_fp() { } current_cfg_xrandr() { - $XRANDR -q | awk ' + local PRIMARY_SETUP=$(xdpyinfo -ext XINERAMA|awk '/^ head #0:/ {printf $3 $5}') + $XRANDR -q | awk -v primary_setup=${PRIMARY_SETUP} ' # display is connected and has a mode /^[^ ]+ connected [^(]/ { split($3, A, "+"); print "output "$1; print "mode "A[1]; print "pos "A[2]"x"A[3]; - print " "A[4]; + if (A[1] A[2] "," A[3] == primary_setup) + print "primary"; next; } # disconnected or disabled displays From 4f161c79503cd53b9d91b05d4f966d8595c310f6 Mon Sep 17 00:00:00 2001 From: Maciej Sitarz Date: Sun, 12 Feb 2012 14:10:06 +0100 Subject: [PATCH 04/10] Handle outputs with "unknown connection" as "off". --- autorandr | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/autorandr b/autorandr index d93ebe4..d36ea6a 100755 --- a/autorandr +++ b/autorandr @@ -126,7 +126,8 @@ current_cfg_xrandr() { next; } # disconnected or disabled displays - /^[^ ]+ (dis)?connected / { + /^[^ ]+ (dis)?connected / || + /^[^ ]+ unknown connection / { print "output "$1; print "off"; next; From 4e1c2b515bbe2d314cba63d0cb13c440eab6322c Mon Sep 17 00:00:00 2001 From: Maciej Sitarz Date: Wed, 15 Feb 2012 20:53:13 +0100 Subject: [PATCH 05/10] Fixed script name and typo in variable name. Renamed according to pm-utils "SLEEP HOOK ORDERING CONVENTION" --- pm-utils/{90autorandr => 40autorandr} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename pm-utils/{90autorandr => 40autorandr} (91%) diff --git a/pm-utils/90autorandr b/pm-utils/40autorandr similarity index 91% rename from pm-utils/90autorandr rename to pm-utils/40autorandr index 59992a8..f284839 100755 --- a/pm-utils/90autorandr +++ b/pm-utils/40autorandr @@ -10,7 +10,7 @@ detect_display() D="${X##/tmp/.X11-unix/X}" user=$(who | awk -vD="$D" '$5 ~ "\\(:"D"\\)$" {print $1}') if [ x"$user" != x"" ]; then - export DISPLAY=":$displaynum" + export DISPLAY=":$D" /bin/su -c "${AUTORANDR}" "$user" fi done From 85347d7823340ecde8dc3e1e3b60f91881aaa193 Mon Sep 17 00:00:00 2001 From: Maciej Sitarz Date: Thu, 1 Mar 2012 17:29:26 +0100 Subject: [PATCH 06/10] Fixed config EDID line for outputs with 'unknown connection' status --- autorandr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autorandr b/autorandr index 2e2f392..1a1e1ba 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]; } }' } From a5393e98cc14818c4acf3ecabb46d11c99113e0a Mon Sep 17 00:00:00 2001 From: Maciej Sitarz Date: Thu, 1 Mar 2012 17:46:36 +0100 Subject: [PATCH 07/10] Fixed a typo made during one of the merges with upstream --- autorandr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autorandr b/autorandr index 1a1e1ba..e7f710f 100755 --- a/autorandr +++ b/autorandr @@ -108,7 +108,7 @@ setup_fp() { done if [ -z "$FP" ]; then echo "Unable to fingerprint display configuration" >&2 - e:return + return fi echo "$FP" } From 632fb4c621f82362ecd2df00ac0f7ef61a7b95cf Mon Sep 17 00:00:00 2001 From: Maciej Sitarz Date: Sun, 30 Dec 2012 12:42:33 +0100 Subject: [PATCH 08/10] Ahow all profiles even one was alreaady detected --- autorandr | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/autorandr b/autorandr index e7f710f..f86a6e7 100755 --- a/autorandr +++ b/autorandr @@ -250,6 +250,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 +258,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 +273,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" From 8648668ed7c482cbe11fb5c8207f34b32a14369a Mon Sep 17 00:00:00 2001 From: John Coulter Date: Thu, 13 Dec 2012 14:20:09 -0700 Subject: [PATCH 09/10] Disable all displays before attempting to call xrandr. Workaround for error "cannot find crtc for output". See https://bugs.freedesktop.org/show_bug.cgi?id=22539 and https://bugs.freedesktop.org/show_bug.cgi?id=29929 --- autorandr | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/autorandr b/autorandr index d2b5186..fd4c642 100755 --- a/autorandr +++ b/autorandr @@ -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 } From 2546f4075e27072392f5d7fb26a8126caf82f315 Mon Sep 17 00:00:00 2001 From: Maciej Sitarz Date: Sun, 30 Dec 2012 13:23:17 +0100 Subject: [PATCH 10/10] Updated pm-utils scripts 40autorandr had issues when resuming on a system where one or more users have multiple terminal sessions open. enhanced 40autorandr to allow being called as 40auto-disper to automatically swap to using auto-disper semantics Merged changes from helterscelter/autorandr commit #afd63d50667eb9665754eb6679e48816f092b078 --- pm-utils/40auto-disper | 1 + pm-utils/40autorandr | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) create mode 120000 pm-utils/40auto-disper 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