]> git.donarmstrong.com Git - deb_pkgs/autorandr.git/blobdiff - autorandr
detect primary screen and save to config.
[deb_pkgs/autorandr.git] / autorandr
index 6d1f91f2fe08a349415c336a0b108d15a8f10882..89d5e25609a6310ff514f304fa9c115bb681767d 100755 (executable)
--- a/autorandr
+++ b/autorandr
@@ -61,12 +61,16 @@ LOAD_METHOD="load_cfg_xrandr"
 SCRIPTNAME="$(basename $0)"
 # when called as autodisper/auto-disper, we assume different defaults
 if [ "$SCRIPTNAME" = "auto-disper" ] || [ "$SCRIPTNAME" = "autodisper" ]; then
+       echo "Assuming disper defaults..." >&2
        FP_METHODS="setup_fp_disper"
        CURRENT_CFG_METHOD="current_cfg_disper"
        LOAD_METHOD="load_cfg_disper"
 fi
 
-test -f $CONFIG && . $CONFIG 
+if [ -f $CONFIG ]; then
+       echo "Loading configuration from '$CONFIG'" >&2
+       . $CONFIG
+fi
 
 setup_fp_xrandr_edid() {
        $XRANDR -q --verbose | awk '
@@ -80,6 +84,8 @@ setup_fp_sysfs_edid() {
        $XRANDR -q > /dev/null
        # hash the EDIDs of all _connected_ devices
        for P in /sys/class/drm/card*-*/; do
+               # nothing found
+               [ ! -d "$P" ] && continue
                if grep -q "^connected$" < "${P}status"; then
                        echo -n "$(basename "$P") "
                        md5sum ${P}edid | awk '{print $1}'
@@ -95,7 +101,9 @@ setup_fp() {
        local FP="";
        for M in $FP_METHODS; do
                FP="$($M)"
-               [ -n "$FP" ] && break;
+               if [ -n "$FP" ]; then
+                       break
+               fi
        done
        if [ -z "$FP" ]; then
                echo "Unable to fingerprint display configuration" >&2
@@ -105,16 +113,23 @@ setup_fp() {
 }
 
 current_cfg_xrandr() {
-       $XRANDR -q | awk '
-       /^[^ ]+ disconnected / {
-        print "output "$1;
-               print "off";
-       }
-       /^[^ ]+ connected / {
+       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];
+               if (A[1] A[2] "," A[3] == primary_setup)
+                       print "primary";
+               next;
+       }
+       # disconnected or disabled displays
+       /^[^ ]+ (dis)?connected / {
+               print "output "$1;
+               print "off";
+               next;
        }'
 }
 
@@ -123,7 +138,7 @@ current_cfg_disper() {
 }
 
 current_cfg() {
-       $CURRENT_METHOD;
+       $CURRENT_CFG_METHOD;
 }
 
 blocked() {
@@ -148,7 +163,7 @@ load_cfg_xrandr() {
 }
 
 load_cfg_disper() {
-       $DISPER -i < "$1"
+       $DISPER -i < "$1"
 }
 
 load() {
@@ -221,7 +236,7 @@ if [ -n "$SAVE_PROFILE" ]; then
        echo "Saving current configuration as profile '${SAVE_PROFILE}'"
        mkdir -p "$PROFILES/$SAVE_PROFILE"
        echo "$CURRENT_SETUP" > "$PROFILES/$SAVE_PROFILE/setup"
-       current_cfg > "$PROFILES/$SAVE_PROFILE/config"
+       $CURRENT_CFG_METHOD > "$PROFILES/$SAVE_PROFILE/config"
        exit 0
 fi