dotfiles/_suckless/_scripts/dmenu-display

64 lines
2.4 KiB
Bash
Executable File

#!/bin/sh
twoscreen() {
mirror=$(printf "no\\nyes" | dmenu -l 20 -i -p "mirror")
if [ "$mirror" = "yes" ]; then
external=$(echo "$screens" | dmenu -l 20 -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" | dmenu -l 20 -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")
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 --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 ' ' -)
}
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
kill -46 $(pidof dwmblocks)
}
# 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 ] &&
{ onescreen "$screens"; 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") &&
case "$chosen" in
"home-1") home 0 ;;
"home-2") home 1 ;;
"multi") twoscreen ;;
"----") exit ;;
*) onescreen "$chosen" ;;
esac
postrun