diff options
-rwxr-xr-x | autodetect.sh | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/autodetect.sh b/autodetect.sh index 651ecf4..8ed8efb 100755 --- a/autodetect.sh +++ b/autodetect.sh @@ -57,6 +57,22 @@ handle_non_exist_mode() { xrandr --dpi "$DPI" $(off_except "$1" "$2") --output $2 --mode $4 --output $1 --mode $3 --left-of $2 } +compute_hash() { + INPUT="$1" + + NOTE_ACTIVE="$(echo "$INPUT" | detect_active "$NOTE_NAME")" + HASH_DATA="${NOTE_NAME}${NOTE_STATUS}${NOTE_MAX}${NOTE_ACTIVE}" + if [ -n "$EXT1_NAME" ]; then + EXT1_ACTIVE="$(echo "$INPUT" | detect_active "$EXT1_NAME")" + HASH_DATA="${HASH_DATA}${EXT1_NAME}${EXT1_STATUS}${EXT1_MAX}${EXT1_ACTIVE}" + fi + if [ -n "$EXT2_NAME" ]; then + EXT2_ACTIVE="$(echo "$INPUT" | detect_active "$EXT2_NAME")" + HASH_DATA="${HASH_DATA}${EXT2_NAME}${EXT2_STATUS}${EXT2_MAX}${EXT2_ACTIVE}" + fi + echo "$HASH_DATA" | sha1sum | awk '{ print $1 }' +} + ## Get notebook display status NOTE_STATUS="$(echo "$XRANDR" | detect_status "$NOTE_NAME")" @@ -123,19 +139,7 @@ fi ## Query current status XRANDR="$(xrandr -q)" - -## Compute HASH of this profile -NOTE_ACTIVE="$(echo "$XRANDR" | detect_active "$NOTE_NAME")" -HASH_DATA="${NOTE_NAME}${NOTE_STATUS}${NOTE_MAX}${NOTE_ACTIVE}" -if [ -n "$EXT1_NAME" ]; then - EXT1_ACTIVE="$(echo "$XRANDR" | detect_active "$EXT1_NAME")" - HASH_DATA="${HASH_DATA}${EXT1_NAME}${EXT1_STATUS}${EXT1_MAX}${EXT1_ACTIVE}" -fi -if [ -n "$EXT2_NAME" ]; then - EXT2_ACTIVE="$(echo "$XRANDR" | detect_active "$EXT2_NAME")" - HASH_DATA="${HASH_DATA}${EXT2_NAME}${EXT2_STATUS}${EXT2_MAX}${EXT2_ACTIVE}" -fi -HASH="$(echo "$HASH_DATA" | sha1sum | awk '{ print $1 }')" +HASH="$(compute_hash "$XRANDR")" ## Update LAST echo "$HASH" > "$SAVEPATH"/"$LAST_FILE" |