Added error checking for display configurations and cleaned up language a bit.

in-use
Emily Frost 7 years ago
parent ada672da01
commit 511a9db034
No known key found for this signature in database
GPG Key ID: FD1FA524668FB1FA

@ -1,17 +1,36 @@
#!/bin/bash #!/bin/bash
# TODO: Am I calling them displays or video outputs? Pick one!
function call_xrandr() { function call_xrandr() {
xrandr_opts='' xrandr_opts=''
for output in "${!video_outputs[@]}"; do for display in "${!display_configurations[@]}"; do
echo "Setting ${output} to ${video_outputs[$output]}" echo "Setting ${display} to ${display_configurations[$display]}"
xrandr_opts="${xrandr_opts} --output ${output} ${video_outputs[$output]}" xrandr_opts="${xrandr_opts} --output ${display} ${display_configurations[$display]}"
done done
# Word splitting here is important, so it's not in quotes.
xrandr $xrandr_opts xrandr $xrandr_opts
} }
function display_config() {
display_name="$1"
display_config="$2"
if [[ ${display_configurations[$display_name]} = '' ]]; then
echo "Tried to configure invalid display ${display_name}."
exit 1
fi
if [[ ${connected_displays[$display_name]} != 'yes' ]]; then
echo "Tried to configure disconnected display ${display_name}."
exit 1
fi
display_configurations[$display_name]="$display_config"
}
declare -A display_configurations
declare -A connected_displays
if [ "$1" = '-a' ]; then if [ "$1" = '-a' ]; then
switch_audio='yes' switch_audio='yes'
@ -20,35 +39,39 @@ else
video_mode="$1" video_mode="$1"
fi fi
declare -A video_outputs
while read -r display_line; do while read -r display_line; do
display_name="$(echo "$display_line" | cut -d " " -f 1)" display_name="$(echo "$display_line" | cut -d " " -f 1)"
video_outputs[$display_name]=' --off'
if [[ "$(echo "$display_line" | cut -d " " -f 2)" = 'connected' ]]; then
connected_displays[$display_name]='yes'
else
connected_displays[$display_name]='no'
fi
display_configurations[$display_name]=' --off'
done <<< "$(xrandr | grep connected)" done <<< "$(xrandr | grep connected)"
# TODO: I'm kind of inattentive, so build in a mechanism to make sure the display I try # TODO: I'm very lazy, so build a method that automatically figures out which HDMI
# to use is actually connected.
# TODO: I'm also very lazy, so build a method that automatically figures out which HDMI
# output to use if there's only one. # output to use if there's only one.
case $video_mode in case $video_mode in
'lvds-hdmi1') 'lvds-hdmi1')
video_outputs['LVDS1']='--primary --mode 1366x768' display_config 'LVDS1' '--primary --mode 1366x768'
video_outputs['HDMI1']='--mode 1280x720 --above LVDS1' display_config 'HDMI1' '--mode 1280x720 --above LVDS1'
if [ "$switch_audio" = 'yes' ]; then if [ "$switch_audio" = 'yes' ]; then
audio_profile='output:hdmi-stereo' audio_profile='output:hdmi-stereo'
fi fi
;; ;;
'hdmi1') 'hdmi1')
video_outputs['HDMI1']='--primary --mode 1280x720' display_config 'HDMI1' '--primary --mode 1280x720'
if [ "$switch_audio" = 'yes' ]; then if [ "$switch_audio" = 'yes' ]; then
audio_profile='output:hdmi-stereo' audio_profile='output:hdmi-stereo'
fi fi
;; ;;
'lvds') 'lvds')
video_outputs['LVDS1']='--primary --mode 1366x768' display_config 'LVDS1' '--primary --mode 1366x768'
if [ "$switch_audio" = 'yes' ]; then if [ "$switch_audio" = 'yes' ]; then
audio_profile='output:analog-stereo' audio_profile='output:analog-stereo'
fi fi
@ -56,7 +79,7 @@ case $video_mode in
# This is intended to be a quick rescue mode. # This is intended to be a quick rescue mode.
'') '')
video_outputs['LVDS1']='--primary --mode 1366x768' display_config 'LVDS1' '--primary --mode 1377x768'
audio_profile='output:analog-stereo' audio_profile='output:analog-stereo'
;; ;;
*) *)
@ -65,7 +88,7 @@ case $video_mode in
;; ;;
esac esac
call_xrandr "${video_outputs[@]}" call_xrandr
if [ "$switch_audio" = 'yes' ]; then if [ "$switch_audio" = 'yes' ]; then
ponymix -c 0 set-profile "${audio_profile}" ponymix -c 0 set-profile "${audio_profile}"
fi fi

Loading…
Cancel
Save