dotfiles/_suckless/_scripts/dmenu-display

64 lines
2.4 KiB
Plaintext
Raw Normal View History

2021-06-19 15:50:04 +02:00
#!/bin/sh
2021-08-16 18:05:47 +02:00
twoscreen() {
2021-08-23 00:35:19 +02:00
mirror=$(printf "no\\nyes" | dmenu -l 20 -i -p "Mirror displays?")
2021-08-16 18:05:47 +02:00
if [ "$mirror" = "yes" ]; then
2021-08-23 00:35:19 +02:00
external=$(echo "$screens" | dmenu -l 20 -i -p "Optimize resolution for:")
2021-08-16 18:05:47 +02:00
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
2021-08-23 00:35:19 +02:00
primary=$(echo "$screens" | dmenu -l 20 -i -p "Select primary display:")
2021-08-16 18:05:47 +02:00
secondary=$(echo "$screens" | grep -v "$primary")
2021-08-23 00:35:19 +02:00
direction=$(printf "left\\nright" | dmenu -l 20 -i -p "What side of $primary should $secondary be on?")
2021-08-16 18:05:47 +02:00
xrandr --output "$primary" --auto --scale 1.0x1.0 --output "$secondary" --"$direction"-of "$primary" --auto --scale 1.0x1.0
fi
}
home() {
xrandr --output "DisplayPort-${1}" --mode 2560x1440 $(echo "$allposs" | grep -v "\bDisplayPort-${1}" | awk '{print "--output", $1, "--off"}' | paste -sd ' ' -)
2021-06-19 15:50:04 +02:00
}
onescreen() {
2021-08-16 18:05:47 +02:00
xrandr --output "$1" --auto --scale 1.0x1.0 $(echo "$allposs" | grep -v "\b$1" | awk '{print "--output", $1, "--off"}' | paste -sd ' ' -)
2021-06-19 15:50:04 +02:00
}
postrun() {
feh --no-fehbg --bg-scale ~/.local/share/wallpaper
{ killall dunst ; setsid -f dunst ;} >/dev/null 2>&1 # Restart dunst to ensure proper location on screen
2021-08-20 19:38:24 +02:00
kill -46 $(pidof dwmblocks)
2021-06-19 15:50:04 +02:00
}
# Get all possible displays
allposs=$(xrandr -q | grep "connected")
# Get all connected screens.
screens=$(echo "$allposs" | awk '/ connected/ {print $1}')
# If there's only one screen
[ "$(echo "$screens" | wc -l)" -lt 2 ] &&
2021-08-20 19:38:24 +02:00
{ onescreen "$screens"; postrun; notify-send "💻 Only one screen detected."; exit ;}
2021-06-19 15:50:04 +02:00
# Get user choice including both and manual selection:
2021-08-23 00:35:19 +02:00
chosen=$(printf -- "home-1\\nhome-2\\n----\\n%s\\n----\\nmulti" "$screens" | dmenu -l 20 -i -p "Select display:") &&
2021-06-19 15:50:04 +02:00
case "$chosen" in
"home-1") home 0 ;;
"home-2") home 1 ;;
2021-08-16 18:05:47 +02:00
"multi") twoscreen ;;
"----") exit ;;
*) onescreen "$chosen" ;;
2021-06-19 15:50:04 +02:00
esac
postrun