2021-02-12 23:20:57 +01:00
|
|
|
#!/usr/bin/env sh
|
2020-05-06 03:20:19 +02:00
|
|
|
|
2020-05-20 18:34:34 +02:00
|
|
|
######################################################################
|
2020-05-23 15:47:21 +02:00
|
|
|
# @author : swytch (adapted from Luke Smith - lukesmith.xyz)
|
|
|
|
# @file : displayselect
|
2020-06-25 18:19:40 +02:00
|
|
|
# @license : MIT
|
2020-05-23 15:47:21 +02:00
|
|
|
# @created : Wednesday May 20, 2020 18:04:01 CEST
|
2020-05-20 18:34:34 +02:00
|
|
|
#
|
2020-05-23 15:47:21 +02:00
|
|
|
# @description : detect displays and select an organisation
|
2020-05-20 18:34:34 +02:00
|
|
|
######################################################################
|
2020-05-06 03:20:19 +02:00
|
|
|
|
|
|
|
|
|
|
|
twoscreen() { # If multi-monitor is selected and there are two screens.
|
|
|
|
mirror=$(printf "no\\nyes" | dmenu -i -p "Mirror displays?")
|
|
|
|
# Mirror displays using native resolution of external display and a scaled
|
|
|
|
# version for the internal display
|
|
|
|
if [ "$mirror" = "yes" ]; then
|
2020-12-13 20:14:42 +01:00
|
|
|
external=$(echo "$screens" | dmenu -i -p "Optimize resolution for:")
|
|
|
|
internal=$(echo "$screens" | grep -v "$external")
|
2020-05-06 03:20:19 +02:00
|
|
|
|
2020-12-13 20:14:42 +01:00
|
|
|
res_external=$(xrandr --query | sed -n "/^$external/,/\+/p" | \
|
|
|
|
tail -n 1 | awk '{print $1}')
|
|
|
|
res_internal=$(xrandr --query | sed -n "/^$internal/,/\+/p" | \
|
|
|
|
tail -n 1 | awk '{print $1}')
|
2020-05-06 03:20:19 +02:00
|
|
|
|
2020-12-13 20:14:42 +01:00
|
|
|
res_ext_x=$(echo $res_external | sed 's/x.*//')
|
|
|
|
res_ext_y=$(echo $res_external | sed 's/.*x//')
|
|
|
|
res_int_x=$(echo $res_internal | sed 's/x.*//')
|
|
|
|
res_int_y=$(echo $res_internal | sed 's/.*x//')
|
2020-05-06 03:20:19 +02:00
|
|
|
|
2020-12-13 20:14:42 +01:00
|
|
|
scale_x=$(echo "$res_ext_x / $res_int_x" | bc -l)
|
|
|
|
scale_y=$(echo "$res_ext_y / $res_int_y" | bc -l)
|
2020-05-06 03:20:19 +02:00
|
|
|
|
2020-12-13 20:14:42 +01:00
|
|
|
xrandr --output "$external" --auto --scale 1.0x1.0 \
|
|
|
|
--output "$internal" --auto --same-as "$external" \
|
|
|
|
--scale "$scale_x"x"$scale_y"
|
2020-05-06 03:20:19 +02:00
|
|
|
else
|
2020-12-13 20:14:42 +01:00
|
|
|
default=$(printf "yes\\nno" | dmenu -i -p "Default settings?")
|
|
|
|
if [ $default = "no" ]; then
|
|
|
|
primary=$(echo "$screens" | dmenu -i -p "Select primary display:")
|
|
|
|
secondary=$(echo "$screens" | grep -v "$primary")
|
|
|
|
direction=$(printf "left\\nright" | dmenu -i -p "What side of $primary should $secondary be on?")
|
|
|
|
rotation=$(printf "normal\\nleft\\nright" | dmenu -i -p "Rotate $secondary?")
|
|
|
|
xrandr --output "$primary" --auto --scale 1.0x1.0 \
|
|
|
|
--output "$secondary" --"$direction"-of "$primary" --auto --scale 1.2x1.2 --rotate $rotation
|
2020-09-12 19:13:24 +02:00
|
|
|
else
|
2020-12-13 20:14:42 +01:00
|
|
|
xrandr --fb 4224x2376 \
|
2021-02-11 23:48:49 +01:00
|
|
|
--output "eDP1" --mode 1920x1080 --pos 2304x0\
|
|
|
|
--output "HDMI2" --scale 1.2x1.2 --pos 0x0
|
2020-12-13 20:14:42 +01:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
2020-05-06 03:20:19 +02:00
|
|
|
|
|
|
|
morescreen() { # If multi-monitor is selected and there are more than two screens.
|
|
|
|
primary=$(echo "$screens" | dmenu -i -p "Select primary display:")
|
|
|
|
secondary=$(echo "$screens" | grep -v "$primary" | dmenu -i -p "Select secondary display:")
|
|
|
|
direction=$(printf "left\\nright" | dmenu -i -p "What side of $primary should $secondary be on?")
|
|
|
|
tertiary=$(echo "$screens" | grep -v "$primary" | grep -v "$secondary" | dmenu -i -p "Select third display:")
|
|
|
|
xrandr --output "$primary" --auto --output "$secondary" --"$direction"-of "$primary" --auto --output "$tertiary" --"$(printf "left\\nright" | grep -v "$direction")"-of "$primary" --auto
|
|
|
|
}
|
|
|
|
|
|
|
|
multimon() { # Multi-monitor handler.
|
|
|
|
case "$(echo "$screens" | wc -l)" in
|
|
|
|
1) xrandr $(echo "$allposs" | grep -v "$screens" | awk '{print "--output", $1, "--off"}' | tr '\n' ' ') ;;
|
|
|
|
2) twoscreen ;;
|
|
|
|
*) morescreen ;;
|
|
|
|
esac ;}
|
|
|
|
|
|
|
|
# Get all possible displays
|
|
|
|
allposs=$(xrandr -q | grep "connected")
|
|
|
|
|
|
|
|
# Get all connected screens.
|
|
|
|
screens=$(echo "$allposs" | grep " connected" | awk '{print $1}')
|
|
|
|
|
|
|
|
# Get user choice including multi-monitor and manual selection:
|
2020-09-12 19:13:24 +02:00
|
|
|
chosen=$(printf "multi-monitor\\n%s\\nmanual selection" "$screens" | dmenu -i -p "Select display arangement:") &&
|
2020-05-06 03:20:19 +02:00
|
|
|
case "$chosen" in
|
|
|
|
"manual selection") arandr ; exit ;;
|
|
|
|
"multi-monitor") multimon ;;
|
|
|
|
*) xrandr --output "$chosen" --auto --scale 1.0x1.0 $(echo "$allposs" | grep -v "$chosen" | awk '{print "--output", $1, "--off"}' | tr '\n' ' ') ;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
setbg # Fix background if screen size/arangement has changed.
|
|
|
|
pgrep -x dunst >/dev/null && killall dunst && setsid dunst & # Restart dunst to ensure proper location on screen
|