Moved setdisplay to displayconf project.
parent
94b398c282
commit
de853dfdda
@ -1,126 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# setdisplay
|
||||
# A simple script to configure X and PulseAudio with predefined profiles.
|
||||
|
||||
### Usage
|
||||
# setdisplay [PROFILE]
|
||||
# Configure X with the specified profile, but don't change the audio profile.
|
||||
|
||||
# setdisplay -a [PROFILE]
|
||||
# Configure X with the specified profile and change the audio profile to match it.
|
||||
|
||||
function call_xrandr() {
|
||||
xrandr_opts=''
|
||||
|
||||
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"
|
||||
}
|
||||
|
||||
function guess_output_from_class() {
|
||||
display_class="$1"
|
||||
|
||||
canonical_display_name=''
|
||||
|
||||
for display in "${!display_configurations[@]}"; do
|
||||
if [[ ( $display == ${display_class}* ) && \
|
||||
( "${connected_displays[$display]}" == 'yes' ) ]]; then
|
||||
|
||||
if [[ $canonical_display_name == '' ]]; then
|
||||
canonical_display_name="$display"
|
||||
else
|
||||
echo "Multiple displays of class ${display_class} are connected. Quitting."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ $canonical_display_name == '' ]]; then
|
||||
echo "No displays of class ${display_class} found. Quitting."
|
||||
exit 1
|
||||
fi
|
||||
echo "$canonical_display_name"
|
||||
}
|
||||
|
||||
declare -A display_configurations
|
||||
declare -A connected_displays
|
||||
|
||||
if [ "$1" = '-a' ]; then
|
||||
switch_audio='yes'
|
||||
display_profile="$2"
|
||||
else
|
||||
display_profile="$1"
|
||||
fi
|
||||
|
||||
|
||||
while read -r display_line; do
|
||||
display_name="$(echo "$display_line" | cut -d " " -f 1)"
|
||||
|
||||
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: These cases can probably just be read from input now.
|
||||
case $display_profile in
|
||||
'lvds-hdmi')
|
||||
hdmi_display="$(guess_output_from_class "HDMI")"
|
||||
display_config 'LVDS1' '--primary --mode 1366x768'
|
||||
display_config "$hdmi_display" '--mode 1280x720 --above LVDS1'
|
||||
audio_profile='output:hdmi-stereo'
|
||||
;;
|
||||
|
||||
'hdmi')
|
||||
hdmi_display="$(guess_output_from_class "HDMI")"
|
||||
display_config "$hdmi_display" '--primary --mode 1280x720'
|
||||
audio_profile='output:hdmi-stereo'
|
||||
;;
|
||||
|
||||
'lvds')
|
||||
display_config 'LVDS1' '--primary --mode 1366x768'
|
||||
audio_profile='output:analog-stereo'
|
||||
;;
|
||||
|
||||
# This is intended to be a quick rescue mode.
|
||||
'')
|
||||
display_config 'LVDS1' '--primary --mode 1366x768'
|
||||
audio_profile='output:analog-stereo'
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "No profile ${display_profile} has been defined."
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
call_xrandr
|
||||
if [ "$switch_audio" = 'yes' ]; then
|
||||
# TODO: Figure out how to remove this dependency.
|
||||
ponymix -c 0 set-profile "${audio_profile}"
|
||||
fi
|
||||
Loading…
Reference in New Issue