avoid (re)loading of identical configurations

This commit is contained in:
Stefan Tomanek 2010-11-09 15:17:22 +01:00
parent e0408ae8c8
commit 236e99a016
1 changed files with 24 additions and 4 deletions

View File

@ -21,6 +21,9 @@
# #
# To manually load a profile, you can use the --load <profile> option. # To manually load a profile, you can use the --load <profile> option.
# #
# autorandr tries to avoid reloading an identical configuration. To force the
# configuration, apply --force.
#
# To prevent a profile from being loaded, place a script call "block" in its # To prevent a profile from being loaded, place a script call "block" in its
# directory. The script is evaluated before the screen setup is inspected, and # directory. The script is evaluated before the screen setup is inspected, and
# in case of it returning a value of 0 the profile is skipped. This can be used # in case of it returning a value of 0 the profile is skipped. This can be used
@ -40,6 +43,7 @@ PROFILES=~/.autorandr/
CONFIG=~/.autorandr.conf CONFIG=~/.autorandr.conf
CHANGE_PROFILE=0 CHANGE_PROFILE=0
FORCE_LOAD=0
DEFAULT_PROFILE="" DEFAULT_PROFILE=""
SAVE_PROFILE="" SAVE_PROFILE=""
@ -101,9 +105,19 @@ blocked() {
"$PROFILES/$PROFILE/block" "$PROFILE" "$PROFILES/$PROFILE/block" "$PROFILE"
} }
config_equal() {
local PROFILE="$1"
if [ "$(cat "$PROFILES/$PROFILE/config")" = "$(current_cfg)" ]; then
echo "Config already loaded"
return 0
else
return 1
fi
}
load() { load() {
local PROFILE="$1" local PROFILE="$1"
if [ "$CHANGE_PROFILE" -eq 1 ] && [ -e "$PROFILES/$PROFILE/config" ] ; then if [ -e "$PROFILES/$PROFILE/config" ] ; then
echo " -> loading profile $PROFILE" echo " -> loading profile $PROFILE"
sed 's!^!--!' "$PROFILES/$PROFILE/config" | xargs xrandr sed 's!^!--!' "$PROFILES/$PROFILE/config" | xargs xrandr
@ -122,6 +136,7 @@ Usage: autorandr action [profile-name]
-c, --change reload current setup -c, --change reload current setup
-s, --save <profile> save your current setup to profile <profile> -s, --save <profile> save your current setup to profile <profile>
-l, --load <profile> load profile <profile> -l, --load <profile> load profile <profile>
--force force loading of a profile
--fingerprint fingerprints your actual config --fingerprint fingerprints your actual config
To prevent a profile from being loaded, place a script call "block" in its To prevent a profile from being loaded, place a script call "block" in its
@ -141,7 +156,7 @@ EOH
exit exit
} }
# process parameters # process parameters
OPTS=$(getopt -n autorandr -o s:l:d:cfh --long change,default:,save:,load:,fingerprint,help -- "$@") OPTS=$(getopt -n autorandr -o s:l:d:cfh --long change,default:,save:,load:,force,fingerprint,help -- "$@")
if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
eval set -- "$OPTS" eval set -- "$OPTS"
@ -152,6 +167,7 @@ while true; do
-s|--save) SAVE_PROFILE="$2"; shift 2 ;; -s|--save) SAVE_PROFILE="$2"; shift 2 ;;
-l|--load) LOAD_PROFILE="$2"; shift 2 ;; -l|--load) LOAD_PROFILE="$2"; shift 2 ;;
-h|--help) help ;; -h|--help) help ;;
--force) FORCE_LOAD=1; shift ;;
--fingerprint) setup_fp; exit 0;; --fingerprint) setup_fp; exit 0;;
--) shift; break ;; --) shift; break ;;
*) echo "Error: $1"; exit 1;; *) echo "Error: $1"; exit 1;;
@ -169,7 +185,7 @@ if [ -n "$SAVE_PROFILE" ]; then
fi fi
if [ -n "$LOAD_PROFILE" ]; then if [ -n "$LOAD_PROFILE" ]; then
CHANGE_PROFILE=1 load "$LOAD_PROFILE" CHANGE_PROFILE=1 FORCE_LOAD=1 load "$LOAD_PROFILE"
exit $? exit $?
fi fi
@ -188,7 +204,11 @@ for SETUP_FILE in $PROFILES/*/setup; do
FILE_SETUP="$(cat "$PROFILES/$PROFILE/setup")" FILE_SETUP="$(cat "$PROFILES/$PROFILE/setup")"
if [ "$CURRENT_SETUP" = "$FILE_SETUP" ]; then if [ "$CURRENT_SETUP" = "$FILE_SETUP" ]; then
echo " (detected)" echo " (detected)"
load "$PROFILE" if [ "$CHANGE_PROFILE" -eq 1 ]; then
if [ "$FORCE_LOAD" -eq 1 ] || ! config_equal "$PROFILE"; then
load "$PROFILE"
fi
fi
# found the profile, exit with success # found the profile, exit with success
exit 0 exit 0
else else