diff options
Diffstat (limited to 'autodetect.sh')
-rwxr-xr-x | autodetect.sh | 22 |
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 |