]> git.donarmstrong.com Git - deb_pkgs/autorandr.git/blobdiff - autorandr
Enable xrandr outputs one-by-one, --pos 0x0 first
[deb_pkgs/autorandr.git] / autorandr
index 19b981c7e08fdb3b00bfdb56bbb9b7f0d6d7449c..5937f8a2a8ad3ded1cd9dd27a3d9d7b3535b1bcf 100755 (executable)
--- a/autorandr
+++ b/autorandr
@@ -47,7 +47,7 @@
 XRANDR=/usr/bin/xrandr
 DISPER=/usr/bin/disper
 XDPYINFO=/usr/bin/xdpyinfo
-PROFILES=~/.autorandr/
+PROFILES=~/.autorandr
 CONFIG=~/.autorandr.conf
 RESERVED_PROFILE_NAMES=`cat <<EOF
  common     Clone all connected outputs at the largest common resolution
@@ -277,26 +277,34 @@ config_equal() {
 load_cfg_xrandr() {
        # sed 1: Prefix arguments with "--"
        # sed 2: Merge arguments into one line per output
-       # sed 3: Merge into two lines, all --off outputs in the first one
+       # sed 3:  * Merge all --off outputs into the first line
+       #         * Place the output with --pos 0x0 on the second line
+       #         * Remaining outputs are appended as they appear
+       #         * Keep everything in hold buffer until the last line
+       # sed 4: Remove empty lines caused by G and H on empty hold buffer
        sed 's/^/--/' "$1" | sed -e '
                :START
                /\n--output/{P;D}
                s/\n/ /
                N;bSTART' | sed -e '
-                       ### First line
                        / --off/{
                                G
-                               # Merge if next line contains --off
+                               # Merge with next line if it contains --off
                                s/\n\([^\n]* --off\)/ \1/
                                h
                                $!d;b
                        }
-                       ### Last line
-                       H;x
-                       # Merge if previous line contains --mode
-                       s/\(--mode [^\n]*\)\n/\1 /
-                       h
-                       $!d' | xargs -L 1 $XRANDR
+                       / --pos 0x0/{
+                               G
+                               # Swap lines 1 and 2 if --off is found
+                               / --off/ s/^\([^\n]*\)\n\([^\n]*\)/\2\n\1/
+                               h
+                               $!d;b
+                       }
+                       H
+                       $!d
+                       x' | sed -e '
+                               /./ !d' | xargs -L 1 $XRANDR
 }
 
 load_cfg_disper() {
@@ -307,7 +315,12 @@ load() {
        local PROFILE="$1"
        local CONF="$PROFILES/$PROFILE/config"
        local IS_VIRTUAL_PROFILE=`echo "$RESERVED_PROFILE_NAMES" | grep -c "^ $PROFILE "`
-       [ -f "$CONF" -o -n $IS_VIRTUAL_PROFILE ] || return 1
+
+       if [ ! -f "$CONF" -a $IS_VIRTUAL_PROFILE -eq 0 ]; then
+               echo " -> Error: Profile '$PROFILE' does not exist." >&2
+               return
+       fi
+
        if [ -x "$PROFILES/preswitch" ]; then
                "$PROFILES/preswitch" "$PROFILE"
        fi
@@ -317,7 +330,7 @@ load() {
 
        if [ -f "$CONF" ]; then
                echo " -> loading profile $PROFILE"
-               if [ -n $IS_VIRTUAL_PROFILE ]; then
+               if [ $IS_VIRTUAL_PROFILE -ne 0 ]; then
                        echo " -> Warning: Existing profile overrides virtual profile with same name" >&2
                fi
                $LOAD_METHOD "$CONF"