fix auto-display script

This commit is contained in:
2022-11-09 15:07:32 +01:00
parent 0e3edbd176
commit f71fb47e7c

View File

@@ -1,5 +1,7 @@
#! /bin/bash #! /bin/bash
# Note for future configuration: use arandr and save layout (direct xrandr calls)
# Needed exports and vars # Needed exports and vars
#export DISPLAY=$(w -h -s | grep ":[0-9]\W" | head -1 | awk '{print $3}') #export DISPLAY=$(w -h -s | grep ":[0-9]\W" | head -1 | awk '{print $3}')
X_USER=$(w -h -s | grep ":[0-9]\W" | head -1 | awk '{print $1}') X_USER=$(w -h -s | grep ":[0-9]\W" | head -1 | awk '{print $1}')
@@ -7,23 +9,26 @@ X_UID=$(id -u ${X_USER})
export XAUTHORITY=/home/${X_USER}/.Xauthority export XAUTHORITY=/home/${X_USER}/.Xauthority
# Grep connected/disconnected monitors from xrandr # Grep connected/disconnected monitors from xrandr
EXTRA_DISPLAY=$(xrandr | grep " connected" | grep -v "eDP1" | awk '{print $1}') EXTRA_DISPLAY=$(xrandr | grep " connected" | grep -v "eDP1" | awk '{print $1}' | tr '\n' ' ')
DISCONNECTED_DISPLAY=$(xrandr | grep " disconnected" | awk '{print $1}') DISCONNECTED_DISPLAY=$(xrandr | grep " disconnected" | awk '{print $1}')
xrandr --auto
# Make sure disconnected display are off # Make sure disconnected display are off
for display in ${DISCONNECTED_DISPLAY}; do for display in ${DISCONNECTED_DISPLAY}; do
xrandr --output ${display} --off xrandr --output ${display} --off
done done
if [ $(wc -l <<< ${EXTRA_DISPLAY}) -eq 0 ]; then case "${EXTRA_DISPLAY}" in
xrandr --output eDP1 --primary "")
elif [ $(wc -l <<< ${EXTRA_DISPLAY}) -eq 1 ]; then # Laptop screen only
xrandr --output ${EXTRA_DISPLAY} --primary --output eDP1 --right-of ${EXTRA_DISPLAY} xrandr --output eDP1 --primary --mode 2560x1440 --pos 0x0 --rotate normal;;
else HDMI1\ )
xrandr --output eDP1 --off # Extra display
FIRST_DISPLAY=$(head -n1 <<< ${EXTRA_DISPLAY}) xrandr --output eDP1 --primary --mode 2560x1440 --pos 0x0 --rotate normal --output HDMI1 --auto;;
SECOND_DISPLAY=$(head -n2 <<< ${EXTRA_DISPLAY} | tail -n1) DP1-1\ DP1-2\ )
xrandr --output ${FIRST_DISPLAY} --primary --output ${SECOND_DISPLAY} --right-of ${FIRST_DISPLAY} # Docked, for whatever reason, need an extra step to disable laptop screen and use both dock ports...
fi xrandr --output eDP1 --primary --mode 2560x1440 --pos 0x0 --rotate normal --output DP1-1 --mode 1920x1080 --pos 2560x180 --rotate normal --output DP1-2 --off
xrandr --output eDP1 --off --output DP1-1 --primary --mode 1920x1080 --pos 0x0 --rotate normal --output DP1-2 --mode 1920x1080 --pos 1920x0 --rotate normal;;
*)
echo "auto-display: unknown configuration";;
esac