dgy
/
hexagons
Archived
1
0
Fork 0
This repository has been archived on 2021-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
hexagons/.local/bin/monisel

61 lines
2.5 KiB
Bash
Executable File

#!/bin/sh
twoscreen() { # If there are two screens.
mirror=$(printf "no\\nyes" | dmenu -i -w 300 -p "Mirror displays? ")
# Mirror displays using native resolution of external display and a scaled
# version for the internal display
if [ "$mirror" = "yes" ]; then
external=$(echo "$screens" | dmenu -i -w 320 -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 -i -w 320 -p "Select primary display: ")
secondary=$(echo "$screens" | grep -v "$primary")
direction=$(printf "left\\nright" | dmenu -i -w 500 -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
}
morescreen() { # If there are more than two screens.
primary=$(echo "$screens" | dmenu -i -w 320 -p "Select primary display: ")
secondary=$(echo "$screens" | grep -v "$primary" | dmenu -i -w 320 -p "Select secondary display: ")
direction=$(printf "left\\nright" | dmenu -i -w 500 -p "What side of $primary should $secondary be on? ")
tertiary=$(echo "$screens" | grep -v "$primary" | grep -v "$secondary" | dmenu -i -w 320 -p "Select third display: ")
xrandr --output "$primary" --auto --output "$secondary" --"$direction"-of "$primary" --auto --output "$tertiary" --"$(printf "left\\nright" | grep -v "$direction")"-of "$primary" --auto
}
multimon() { # Multi-monitor handler.
case "$(echo "$screens" | wc -l)" in
2) twoscreen ;;
*) morescreen ;;
esac ;}
postrun() {
setbg
bspc monitor "$(bspc query -M | awk NR==1)" -d 1 2 3 4 5
bspc monitor "$(bspc query -M | awk NR==2)" -d 6 7 8 9 10
}
# Get all connected screens.
screens=$(xrandr -q | awk '/ connected/ {print $1}')
multimon
postrun