More generic display chooser script.
This commit is contained in:
parent
d3e5dd977b
commit
2004f6c097
@ -1,9 +1,9 @@
|
||||
#!/bin/sh
|
||||
|
||||
twoscreen() {
|
||||
mirror=$(printf "no\\nyes" | dmenu -l 20 -i -p "mirror")
|
||||
mirror=$(printf "no\\nyes" | dmenu -l 2 -i -p "mirror")
|
||||
if [ "$mirror" = "yes" ]; then
|
||||
external=$(echo "$screens" | dmenu -l 20 -i -p "optimize resolution for")
|
||||
external=$(echo "$screens" | dmenu -l 2 -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}')
|
||||
@ -19,20 +19,23 @@ twoscreen() {
|
||||
--output "$internal" --auto --same-as "$external" \
|
||||
--scale "$scale_x"x"$scale_y"
|
||||
else
|
||||
primary=$(echo "$screens" | dmenu -l 20 -i -p "primary")
|
||||
primary=$(echo "$screens" | dmenu -l 50 -i -p "primary")
|
||||
secondary=$(echo "$screens" | grep -v "$primary")
|
||||
direction=$(printf "left\\nright" | dmenu -l 20 -i -p "side of $primary should $secondary be on")
|
||||
direction=$(printf "left\\nright" | dmenu -l 2 -i -p "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-${1}" --auto --scale 0.75x0.75 $(echo "$allposs" | grep -v "\bDisplayPort-${1}" | awk '{print "--output", $1, "--off"}' | paste -sd ' ' -)
|
||||
echo xrandr --output "DisplayPort-${1}" --mode 2560x1440 --scale 1.0x1.0 $(echo "$allposs" | grep -v "\bDisplayPort-${1}" | awk '{print "--output", $1, "--off"}' | paste -sd ' ' -)
|
||||
}
|
||||
|
||||
onescreen() {
|
||||
xrandr --output "$1" --auto --scale 1.0x1.0 $(echo "$allposs" | grep -v "\b$1" | awk '{print "--output", $1, "--off"}' | paste -sd ' ' -)
|
||||
if [ "$2" = "native" ]; then
|
||||
xrandr --output "$1" --auto --scale 1.0x1.0 $(echo "$allposs" | grep -v "\b$1" | awk '{print "--output", $1, "--off"}' | paste -sd ' ' -)
|
||||
else
|
||||
scale=$(printf "native\\n0.75\\n0.5" | dmenu -l 3 -i -p "scale") &&
|
||||
case "$scale" in
|
||||
"native") xrandr --output "$1" --auto --scale 1.0x1.0 $(echo "$allposs" | grep -v "\b$1" | awk '{print "--output", $1, "--off"}' | paste -sd ' ' -);;
|
||||
*) xrandr --output "$1" --auto --scale ${scale}x${scale} $(echo "$allposs" | grep -v "\b$1" | awk '{print "--output", $1, "--off"}' | paste -sd ' ' -);;
|
||||
esac
|
||||
fi
|
||||
}
|
||||
|
||||
postrun() {
|
||||
@ -49,15 +52,12 @@ screens=$(echo "$allposs" | awk '/ connected/ {print $1}')
|
||||
|
||||
# If there's only one screen
|
||||
[ "$(echo "$screens" | wc -l)" -lt 2 ] &&
|
||||
{ onescreen "$screens"; postrun; dunstify -u critical "💻 no device to switch"; exit ;}
|
||||
{ onescreen "$screens" "native"; postrun; dunstify -u critical "💻 no device to switch"; exit ;}
|
||||
|
||||
# Get user choice including both and manual selection:
|
||||
chosen=$(printf -- "home-1\\nhome-2\\n----\\n%s\\n----\\nmulti" "$screens" | dmenu -l 20 -i -p "display") &&
|
||||
chosen=$(printf -- "%s\\nmulti" "$screens" | dmenu -l 5 -i -p "display") &&
|
||||
case "$chosen" in
|
||||
"home-1") home 0 ;;
|
||||
"home-2") home 1 ;;
|
||||
"multi") twoscreen ;;
|
||||
"----") exit ;;
|
||||
*) onescreen "$chosen" ;;
|
||||
esac
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user