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