New approach to display selector.

This commit is contained in:
Bartek Stalewski 2021-08-16 18:05:47 +02:00
parent 1ae5ab2386
commit 13afdf1a41

View File

@ -1,18 +1,37 @@
#!/bin/sh #!/bin/sh
both() { # If both is selected and there are two screens. twoscreen() {
primary=$(echo "$screens" | rofi -dmenu -i -p "Select primary display:") mirror=$(printf "no\\nyes" | rofi -dmenu -i -p "Mirror displays?")
secondary=$(echo "$screens" | grep -v "$primary") if [ "$mirror" = "yes" ]; then
direction=$(printf "left\\nright" | rofi -dmenu -i -p "What side of $primary should $secondary be on?") external=$(echo "$screens" | rofi -dmenu -i -p "Optimize resolution for")
xrandr --output "$primary" --mode 1920x1080 --scale 1.0x1.0 --output "$secondary" --"$direction"-of "$primary" --mode 2560x1440 --scale 1.0x1.0 internal=$(echo "$screens" | grep -v "$external")
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}')
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//')
scale_x=$(echo "$res_ext_x / $res_int_x" | bc -l)
scale_y=$(echo "$res_ext_y / $res_int_y" | bc -l)
xrandr --output "$external" --auto --scale 1.0x1.0 \
--output "$internal" --auto --same-as "$external" \
--scale "$scale_x"x"$scale_y"
else
primary=$(echo "$screens" | rofi -dmenu -i -p "Select primary display")
secondary=$(echo "$screens" | grep -v "$primary")
direction=$(printf "left\\nright" | rofi -dmenu -i -p "What side of $primary should $secondary be on?")
xrandr --output "$primary" --auto --scale 1.0x1.0 --output "$secondary" --"$direction"-of "$primary" --auto --scale 1.0x1.0
fi
}
home() {
xrandr --output "DisplayPort-0" --mode 2560x1440 $(echo "$allposs" | grep -v "\bDisplayPort-0" | awk '{print "--output", $1, "--off"}' | paste -sd ' ' -)
} }
onescreen() { onescreen() {
case "$1" in xrandr --output "$1" --auto --scale 1.0x1.0 $(echo "$allposs" | grep -v "\b$1" | awk '{print "--output", $1, "--off"}' | paste -sd ' ' -)
eDP) xrandr --output "$1" --mode 1920x1080 $(echo "$allposs" | grep -v "\b$1" | awk '{print "--output", $1, "--off"}' | paste -sd ' ' -) ;;
DisplayPort*) xrandr --output "$1" --mode 2560x1440 $(echo "$allposs" | grep -v "\b$1" | awk '{print "--output", $1, "--off"}' | paste -sd ' ' -) ;;
*) xrandr --output "$1" --auto $(echo "$allposs" | grep -v "\b$1" | awk '{print "--output", $1, "--off"}' | paste -sd ' ' -) ;;
esac
} }
postrun() { postrun() {
@ -28,13 +47,15 @@ screens=$(echo "$allposs" | awk '/ connected/ {print $1}')
# If there's only one screen # If there's only one screen
[ "$(echo "$screens" | wc -l)" -lt 2 ] && [ "$(echo "$screens" | wc -l)" -lt 2 ] &&
{ onescreen "$screens"; postrun; exit ;} { onescreen "$screens"; postrun; exit ;}
# Get user choice including both and manual selection: # Get user choice including both and manual selection:
chosen=$(printf "%s\\nboth" "$screens" | rofi -dmenu -i -p "Select display arangement:") && chosen=$(printf -- "home\\n----\\n%s\\n----\\nmulti" "$screens" | rofi -dmenu -i -p "Select display arangement") &&
case "$chosen" in case "$chosen" in
"both") both ;; "home") home ;;
*) onescreen "$chosen" ;; "multi") twoscreen ;;
"----") exit ;;
*) onescreen "$chosen" ;;
esac esac
postrun postrun