From 27351a0c6e3b72693b5476cec1f24d5d924c2439 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20Ob=C5=AFrka?= Date: Fri, 27 Mar 2015 18:37:05 +0100 Subject: Save/restore profiles --- autodetect.sh | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/autodetect.sh b/autodetect.sh index bade06d..651ecf4 100755 --- a/autodetect.sh +++ b/autodetect.sh @@ -6,6 +6,11 @@ NOTE_NAME="eDP1" DPI="96" ########################################## +## Settings +SAVEPATH="/tmp/wpos" +LAST_FILE="LAST" +PROG_PATH="$(dirname "$0")" + ## Init COMMAND="$1" EXT1_NAME="none" @@ -33,6 +38,10 @@ detect_all() { sed -n -e 's/^\([A-Za-z0-9-]*\)\s*\(dis\)*connected.*$/\1/p' } +detect_active() { + grep -A1 "^$1\s*connected" | tail -n1 | awk '{ print $2 }' | grep '\*' +} + off_except() { OFF_STRING="" for device in $(echo "$XRANDR" | detect_all); do @@ -62,6 +71,11 @@ NOTE_MAX="$(echo "$XRANDR" | get_resolution "$NOTE_NAME")" EXT1_MAX="$(echo "$XRANDR" | get_resolution "$EXT1_NAME")" EXT2_MAX="$(echo "$XRANDR" | get_resolution "$EXT2_NAME")" +## Save windows' positions before autodetection +if [ -f "$SAVEPATH"/"$LAST_FILE" ]; then + "$PROG_PATH"/wpos.sh save "$(cat "$SAVEPATH"/"$LAST_FILE")" +fi + ## Main "profiles" logic ## Start with some special command if [ "$COMMAND" = "none" ]; then @@ -122,3 +136,11 @@ if [ -n "$EXT2_NAME" ]; then HASH_DATA="${HASH_DATA}${EXT2_NAME}${EXT2_STATUS}${EXT2_MAX}${EXT2_ACTIVE}" fi HASH="$(echo "$HASH_DATA" | sha1sum | awk '{ print $1 }')" + +## Update LAST +echo "$HASH" > "$SAVEPATH"/"$LAST_FILE" + +## Restore known profile +if [ -f "$SAVEPATH"/"$HASH" ]; then + "$PROG_PATH"/wpos.sh restore "$HASH" +fi -- cgit v1.2.3