summaryrefslogtreecommitdiffstats
path: root/autodetect.sh
diff options
context:
space:
mode:
authorGravatar Robin Obůrka <r.oburka@gmail.com> 2015-03-27 18:37:05 +0100
committerGravatar Robin Obůrka <r.oburka@gmail.com> 2015-03-27 18:37:05 +0100
commit27351a0c6e3b72693b5476cec1f24d5d924c2439 (patch)
tree6e5f8d052f737b93a33fa3ab47ae1770d04abcc0 /autodetect.sh
parentChange definition of "profile" (diff)
downloaddisplay_autoset-27351a0c6e3b72693b5476cec1f24d5d924c2439.tar.xz
Save/restore profiles
Diffstat (limited to 'autodetect.sh')
-rwxr-xr-xautodetect.sh22
1 files changed, 22 insertions, 0 deletions
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