better screen handling, add shortkey to use it

This commit is contained in:
2022-11-09 12:10:56 +01:00
parent 5253c7e9de
commit 0e3edbd176
3 changed files with 31 additions and 21 deletions

29
bin/auto-display Executable file
View File

@@ -0,0 +1,29 @@
#! /bin/bash
# Needed exports and vars
#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_UID=$(id -u ${X_USER})
export XAUTHORITY=/home/${X_USER}/.Xauthority
# Grep connected/disconnected monitors from xrandr
EXTRA_DISPLAY=$(xrandr | grep " connected" | grep -v "eDP1" | awk '{print $1}')
DISCONNECTED_DISPLAY=$(xrandr | grep " disconnected" | awk '{print $1}')
xrandr --auto
# Make sure disconnected display are off
for display in ${DISCONNECTED_DISPLAY}; do
xrandr --output ${display} --off
done
if [ $(wc -l <<< ${EXTRA_DISPLAY}) -eq 0 ]; then
xrandr --output eDP1 --primary
elif [ $(wc -l <<< ${EXTRA_DISPLAY}) -eq 1 ]; then
xrandr --output ${EXTRA_DISPLAY} --primary --output eDP1 --right-of ${EXTRA_DISPLAY}
else
xrandr --output eDP1 --off
FIRST_DISPLAY=$(head -n1 <<< ${EXTRA_DISPLAY})
SECOND_DISPLAY=$(head -n2 <<< ${EXTRA_DISPLAY} | tail -n1)
xrandr --output ${FIRST_DISPLAY} --primary --output ${SECOND_DISPLAY} --right-of ${FIRST_DISPLAY}
fi