]> git.donarmstrong.com Git - deb_pkgs/autorandr.git/blobdiff - autorandr
Log to stderr (Required to allow users to redirect --dry-run output)
[deb_pkgs/autorandr.git] / autorandr
index 8cbf1758510fb336526e6258bd560f518b2fd5c1..eace95048e1713ba00ee90b254319e51c1e72e5c 100755 (executable)
--- a/autorandr
+++ b/autorandr
@@ -4,12 +4,6 @@
 #
 # Copyright (c) 2013 Stefan Tomanek <stefan.tomanek@wertarbyte.de>
 #
-#
-#
-# THE FOLLOWING LICENCE AGREEMENT IS PRELIMINARY AND INVALID UNTIL ISSUE #7 AT
-#  https://github.com/phillipberndt/autorandr/issues/7
-# HAS BEEN RESOLVED!
-#
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation, either version 3 of the License, or
@@ -81,7 +75,7 @@ FORCE_LOAD=0
 DEFAULT_PROFILE=""
 SAVE_PROFILE=""
 
-FP_METHODS="setup_fp_sysfs_edid setup_fp_xrandr_edid"
+FP_METHODS="setup_fp_xrandr_edid setup_fp_sysfs_edid"
 CURRENT_CFG_METHOD="current_cfg_xrandr"
 LOAD_METHOD="load_cfg_xrandr"
 
@@ -99,6 +93,20 @@ if [ -f $CONFIG ]; then
        . $CONFIG
 fi
 
+if ! which xxd 2>&1 >/dev/null; then
+       xxd() {
+               # xxd replacement for systems without vim. Ugly, but the only simple
+               # version that both Python 2 and 3 understand that I could come up with.
+               # awk can only do one direction, it has no ord() function.
+               if [ "$1" = "-r" ]; then
+                       python -c "import binascii, sys; getattr(sys.stdout, 'buffer', sys.stdout).write(binascii.unhexlify(getattr(sys.stdin, 'buffer', sys.stdin).read()))"
+               else
+                       python -c "import binascii, sys; getattr(sys.stdout, 'buffer', sys.stdout).write(binascii.hexlify(getattr(sys.stdin, 'buffer', sys.stdin).read()))"
+                       echo
+               fi
+       }
+fi
+
 setup_fp_xrandr_edid() {
        $XRANDR -q --verbose | awk '
        ORS="";
@@ -118,12 +126,11 @@ setup_fp_xrandr_edid() {
 }
 
 setup_fp_sysfs_edid() {
-       which xxd >/dev/null 2>&1 || return
        $XRANDR -q > /dev/null
        for DEVICE in /sys/class/drm/card*-*; do
                [ -e "${DEVICE}/status" ] && grep -q "^connected$" "${DEVICE}/status" || continue
                echo -n "$(echo "${DEVICE}/edid" | sed -re 's#^.+card[0-9]+-([^/]+).+#\1#; s#-([A-Z]-)?##') "
-                       xxd -c 256 -ps "${DEVICE}/edid" | awk 'ORS=""; /.+/ { print; }'
+                       cat "${DEVICE}/edid" | xxd -c 256 -ps | awk 'ORS=""; /.+/ { print; }'
                echo
        done
 }
@@ -144,7 +151,7 @@ setup_fp() {
                echo "Unable to fingerprint display configuration" >&2
                return
        fi
-       echo "$FINGERPRINT" | sort
+       echo "$FP" | sort
 }
 
 current_cfg_xrandr() {
@@ -155,6 +162,7 @@ current_cfg_xrandr() {
        $XRANDR -q | awk -v primary_setup="${PRIMARY_SETUP}" '
        # display is connected and has a mode
        /^[^ ]+ connected [^(]/ {
+               output=$1
                print "output "$1;
                if ($3 == "primary") {
                        print $3
@@ -180,9 +188,19 @@ current_cfg_xrandr() {
                }
                next;
        }
+       /  [0-9]+x[0-9]+ .+/ {
+               if (output) {
+                       for (n=1; n<10; n++) {
+                               if($n ~ /[0-9]+\.[0-9]+\*/) {
+                                       print "rate " gensub(/(+|\*)/, "", "g", $n);
+                               }
+                       }
+               }
+       }
        # disconnected or disabled displays
        /^[^ ]+ (dis)?connected / ||
        /^[^ ]+ unknown connection / {
+               output=""
                print "output "$1;
                print "off";
                next;