diff options
-rwxr-xr-x | autodetect.sh | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/autodetect.sh b/autodetect.sh index c5867fb..6b95d0f 100755 --- a/autodetect.sh +++ b/autodetect.sh @@ -26,20 +26,23 @@ detect_connected() { sed -n -e 's/^\([A-Za-z0-9-]*\)\s*connected.*$/\1/p' } -detect_disconnected() { - sed -n -e 's/^\([A-Za-z0-9-]*\)\s*disconnected.*$/\1/p' +detect_all() { + sed -n -e 's/^\([A-Za-z0-9-]*\)\s*\(dis\)*connected.*$/\1/p' } -rest_off() { +off_except() { OFF_STRING="" - for device in $(echo "$XRANDR" | detect_disconnected); do + for device in $(echo "$XRANDR" | detect_all); do + for ignore in $@ ; do + [ "$device" = "$ignore" ] && continue 2 + done OFF_STRING="$OFF_STRING --output $device --off" done echo "$OFF_STRING" } handle_non_exist_mode() { - xrandr --dpi "$DPI" $(rest_off) --output $2 --mode $4 --output $1 --mode $3 --left-of $2 + xrandr --dpi "$DPI" $(off_except "$1" "$2") --output $2 --mode $4 --output $1 --mode $3 --left-of $2 } ## Get notebook display status @@ -58,10 +61,10 @@ EXT1_MAX=$(echo "$XRANDR" | grep -A 1 "$EXT1_NAME" | tail -n1 | awk '{ print $1 EXT2_MAX=$(echo "$XRANDR" | grep -A 1 "$EXT2_NAME" | tail -n1 | awk '{ print $1 }') if [ "$COMMAND" = "external" -a "$EXT1_STATUS" = "connected" ]; then - xrandr --dpi "$DPI" --output "$EXT1_NAME" --mode "$EXT1_MAX" --output "$NOTE_NAME" --off + xrandr --dpi "$DPI" $(off_except "$EXT1_NAME") --output "$EXT1_NAME" --mode "$EXT1_MAX" elif [ "$COMMAND" = "external" -a "$EXT2_STATUS" = "connected" ]; then - xrandr --dpi "$DPI" --output "$EXT2_NAME" --mode "$EXT2_MAX" --output "$NOTE_NAME" --off + xrandr --dpi "$DPI" $(off_except "$EXT2_NAME") --output "$EXT2_NAME" --mode "$EXT2_MAX" elif [ "$EXT2_STATUS" = "connected" -a "$NOTE_STATUS" = "connected" -a "$EXT1_STATUS" = "disconnected" ]; then handle_non_exist_mode "$EXT2_NAME" "$NOTE_NAME" "$EXT2_MAX" "$NOTE_MAX" @@ -70,7 +73,7 @@ elif [ "$EXT2_STATUS" = "disconnected" -a "$NOTE_STATUS" = "connected" -a "$EXT1 handle_non_exist_mode "$EXT1_NAME" "$NOTE_NAME" "$EXT1_MAX" "$NOTE_MAX" elif [ "$EXT2_STATUS" = "connected" -a "$NOTE_STATUS" = "connected" -a "$EXT1_STATUS" = "connected" ]; then - xrandr --dpi "$DPI" $(rest_off) + xrandr --dpi "$DPI" $(off_except "$NOTE_NAME" "$EXT1_NAME" "$EXT2_NAME") xrandr --dpi "$DPI" --output "$NOTE_NAME" --mode "$NOTE_MAX" xrandr --dpi "$DPI" --output "$EXT1_NAME" --mode "$EXT1_MAX" --left-of "$NOTE_NAME" xrandr --dpi "$DPI" --output "$EXT2_NAME" --mode "$EXT2_MAX" --left-of "$EXT1_NAME" |