New approach to display selector.
This commit is contained in:
parent
1ae5ab2386
commit
13afdf1a41
@ -1,18 +1,37 @@
|
||||
#!/bin/sh
|
||||
|
||||
both() { # If both is selected and there are two screens.
|
||||
primary=$(echo "$screens" | rofi -dmenu -i -p "Select primary display:")
|
||||
twoscreen() {
|
||||
mirror=$(printf "no\\nyes" | rofi -dmenu -i -p "Mirror displays?")
|
||||
if [ "$mirror" = "yes" ]; then
|
||||
external=$(echo "$screens" | rofi -dmenu -i -p "Optimize resolution for")
|
||||
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" --mode 1920x1080 --scale 1.0x1.0 --output "$secondary" --"$direction"-of "$primary" --mode 2560x1440 --scale 1.0x1.0
|
||||
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() {
|
||||
case "$1" in
|
||||
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
|
||||
xrandr --output "$1" --auto --scale 1.0x1.0 $(echo "$allposs" | grep -v "\b$1" | awk '{print "--output", $1, "--off"}' | paste -sd ' ' -)
|
||||
}
|
||||
|
||||
postrun() {
|
||||
@ -31,9 +50,11 @@ screens=$(echo "$allposs" | awk '/ connected/ {print $1}')
|
||||
{ onescreen "$screens"; postrun; exit ;}
|
||||
|
||||
# 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
|
||||
"both") both ;;
|
||||
"home") home ;;
|
||||
"multi") twoscreen ;;
|
||||
"----") exit ;;
|
||||
*) onescreen "$chosen" ;;
|
||||
esac
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user