From fa11e305ce19dc13c3b376e1231f2518dba14da4 Mon Sep 17 00:00:00 2001 From: Diggory Hardy Date: Mon, 4 Oct 2010 11:44:44 +0200 Subject: [PATCH 1/6] Added support for saving/restoring rotation (xrandr). Single-screen only. --- auto-disper | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/auto-disper b/auto-disper index 0f8110f..73e575b 100755 --- a/auto-disper +++ b/auto-disper @@ -39,6 +39,7 @@ # or other applications about it. DISPER=/usr/bin/disper +XRANDR=/usr/bin/xrandr PROFILES=~/.auto-disper/ CHANGE_PROFILE=0 @@ -57,6 +58,12 @@ load() { if [ "$CHANGE_PROFILE" -eq 1 ]; then echo " -> loading profile $PROFILE" $DISPER -i < "$PROFILES/$PROFILE/config" + #hack to add auto-rotate support (manual config): + if [ -f "$PROFILES/$PROFILE/xrandr-orientation" ]; then + $XRANDR --orientation $(cat "$PROFILES/$PROFILE/xrandr-orientation") + else + $XRANDR --orientation normal + fi [ -x "$PROFILES/$PROFILE/postswitch" ] && \ "$PROFILES/$PROFILE/postswitch" "$PROFILE" @@ -88,6 +95,8 @@ if [ -n "$SAVE_PROFILE" ]; then mkdir -p "$PROFILES/$SAVE_PROFILE" echo "$CURRENT_SETUP" > "$PROFILES/$SAVE_PROFILE/setup" $DISPER -p > "$PROFILES/$SAVE_PROFILE/config" + #Note: not really sure if we should search for "default", and this has no multi-display support: + $XRANDR -q | grep default | cut -d ' ' -f 4 > "$PROFILES/$SAVE_PROFILE/xrandr-orientation" exit 0 fi From e55859e38650e8c4a0e92a5fa303eb9e1a495ad5 Mon Sep 17 00:00:00 2001 From: Diggory Hardy Date: Tue, 7 Dec 2010 13:48:02 +0100 Subject: [PATCH 2/6] Added a script to toggle between auto-disper and internal screen settings. --- screen-button | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100755 screen-button diff --git a/screen-button b/screen-button new file mode 100755 index 0000000..1addcc3 --- /dev/null +++ b/screen-button @@ -0,0 +1,17 @@ +#!/bin/sh +# An example script which can be run when a "screen button" (e.g. Fn+F7 on +# Thinkpads) is pressed to toggle between laptop screen and an external/extended/ +# cloned screen. This script detects whether the laptop screen is active (using +# the resolution - make sure this is correct), and switches either to a profile +# called "laptop" or auto-disper's automatic profile. (A profile must be created +# for "laptop" and each external display used by running +# ./auto-disper --save NAME +# ). +PATH=~/sh + +if [ "$(xrandr|grep Screen|cut -d " " -f 8-10)x" = "1440 x 900,x" ] +then + $PATH/auto-disper --change +else + $PATH/auto-disper --load laptop +fi From bad68ddeeb105c1a46dbaff475cef45757db4304 Mon Sep 17 00:00:00 2001 From: Diggory Hardy Date: Wed, 8 Dec 2010 09:28:25 +0100 Subject: [PATCH 3/6] Fix: don't use a shell variable called PATH! --- screen-button | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/screen-button b/screen-button index 1addcc3..48a3612 100755 --- a/screen-button +++ b/screen-button @@ -7,11 +7,13 @@ # for "laptop" and each external display used by running # ./auto-disper --save NAME # ). -PATH=~/sh + +# Path where auto-disper can be found: +AD_PATH=~/sh if [ "$(xrandr|grep Screen|cut -d " " -f 8-10)x" = "1440 x 900,x" ] then - $PATH/auto-disper --change + $AD_PATH/auto-disper --change else - $PATH/auto-disper --load laptop + $AD_PATH/auto-disper --load laptop fi From adcaedacca1556c8255efa785d7ea63150bbf213 Mon Sep 17 00:00:00 2001 From: Diggory Hardy Date: Wed, 23 Nov 2011 09:46:16 +0100 Subject: [PATCH 4/6] Added toggle option (requires default profile to be set and other profiles to be saved; has been working fine for me for months). --- auto-disper | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/auto-disper b/auto-disper index 73e575b..5b6cede 100755 --- a/auto-disper +++ b/auto-disper @@ -42,8 +42,9 @@ DISPER=/usr/bin/disper XRANDR=/usr/bin/xrandr PROFILES=~/.auto-disper/ +# 0: no change, 1: switch to detected, 2: toggle between detected and default CHANGE_PROFILE=0 -DEFAULT_PROFILE="" +DEFAULT_PROFILE="laptop" SAVE_PROFILE="" blocked() { @@ -55,7 +56,7 @@ blocked() { load() { local PROFILE="$1" - if [ "$CHANGE_PROFILE" -eq 1 ]; then + if [ "$CHANGE_PROFILE" -ge 1 ]; then echo " -> loading profile $PROFILE" $DISPER -i < "$PROFILES/$PROFILE/config" #hack to add auto-rotate support (manual config): @@ -73,7 +74,7 @@ load() { } # process parameters -OPTS=$(getopt -n auto-disper -o s:l:d:c --long change,default:,save:,load: -- "$@") +OPTS=$(getopt -n auto-disper -o s:l:d:cth --long toggle,change,default:,save:,load:,help -- "$@") if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi eval set -- "$OPTS" @@ -83,11 +84,25 @@ while true; do -d|--default) DEFAULT_PROFILE="$2"; shift 2 ;; -s|--save) SAVE_PROFILE="$2"; shift 2 ;; -l|--load) LOAD_PROFILE="$2"; shift 2 ;; + -t|--toggle) CHANGE_PROFILE=2; shift ;; + -h|--help) PRINT_HELP=1; shift ;; --) shift; break ;; *) echo "Error: $1"; exit 1;; esac done +if [ -n "$PRINT_HELP" ]; then + echo "auto-disper. Options:" + echo " -c --change Switch to auto-detected profile" + echo " -d --default Switch to default profile" + echo " -s --save NAME Save current configuration as profile NAME." + echo " -l --load NAME Load profile NAME." + echo " -t --toggle If the default profile is not current, switch to it." + echo "\t\t\tOtherwise, switch to auto-detected profile." + echo " -h --help Print this message." + exit 0 +fi + CURRENT_SETUP="$($DISPER -l | grep '^display ')" if [ -n "$SAVE_PROFILE" ]; then @@ -96,7 +111,10 @@ if [ -n "$SAVE_PROFILE" ]; then echo "$CURRENT_SETUP" > "$PROFILES/$SAVE_PROFILE/setup" $DISPER -p > "$PROFILES/$SAVE_PROFILE/config" #Note: not really sure if we should search for "default", and this has no multi-display support: - $XRANDR -q | grep default | cut -d ' ' -f 4 > "$PROFILES/$SAVE_PROFILE/xrandr-orientation" + XRANDR_ORIENTATION=$($XRANDR -q | grep default | cut -d ' ' -f4) + if [ "$XRANDR_ORIENTATION" != "(normal" ]; then + echo $XRANDR_ORIENTATION > "$PROFILES/$SAVE_PROFILE/xrandr-orientation" + fi exit 0 fi @@ -120,9 +138,19 @@ for SETUP_FILE in $PROFILES/*/setup; do FILE_SETUP="$(cat "$PROFILES/$PROFILE/setup")" if [ "$CURRENT_SETUP" = "$FILE_SETUP" ]; then echo " (detected)" - load "$PROFILE" - # found the profile, exit with success - exit 0 + if [ "$CHANGE_PROFILE" -eq 1 ]; then + load "$PROFILE" + # found the profile, exit with success + exit 0 + elif [ "$CHANGE_PROFILE" -eq 2 ]; then + ACTIVE_CONFIG="$($DISPER -p)" + FILE_CONFIG="$(cat "$PROFILES/$PROFILE/config")" + if [ "$ACTIVE_CONFIG" != "$FILE_CONFIG" ]; then + load "$PROFILE" + # found the profile, exit with success + exit 0 + fi + fi else echo "" fi From f9d5fce113e68766b5029c627a379b1df2394d31 Mon Sep 17 00:00:00 2001 From: Diggory Hardy Date: Wed, 23 Nov 2011 09:48:19 +0100 Subject: [PATCH 5/6] Removed screen-button script (it's not needed any more). --- screen-button | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100755 screen-button diff --git a/screen-button b/screen-button deleted file mode 100755 index 48a3612..0000000 --- a/screen-button +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/sh -# An example script which can be run when a "screen button" (e.g. Fn+F7 on -# Thinkpads) is pressed to toggle between laptop screen and an external/extended/ -# cloned screen. This script detects whether the laptop screen is active (using -# the resolution - make sure this is correct), and switches either to a profile -# called "laptop" or auto-disper's automatic profile. (A profile must be created -# for "laptop" and each external display used by running -# ./auto-disper --save NAME -# ). - -# Path where auto-disper can be found: -AD_PATH=~/sh - -if [ "$(xrandr|grep Screen|cut -d " " -f 8-10)x" = "1440 x 900,x" ] -then - $AD_PATH/auto-disper --change -else - $AD_PATH/auto-disper --load laptop -fi From 60feb328fbf0a5eaa248175342991f302ebaba88 Mon Sep 17 00:00:00 2001 From: Diggory Hardy Date: Wed, 23 Nov 2011 09:52:05 +0100 Subject: [PATCH 6/6] Added some doc for toggle option. --- auto-disper | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/auto-disper b/auto-disper index 5b6cede..fa9c78a 100755 --- a/auto-disper +++ b/auto-disper @@ -22,6 +22,11 @@ # # To automatically reload your setup, just append --change to the command line # +# To alternate between the detected setup and a default one (such as your laptop +# screen, set DEFAULT_PROFILE below appropriately and use the --toggle command +# line option. This is useful to bind to a keyboard shortcut (via your desktop's +# global shortcuts bindings or similar). +# # To manually load a profile, you can use the --load option. # # To prevent a profile from being loaded, place a script call "block" in its