#!/bin/sh
secondMonName=$(xrandr | awk '{if($2=="connected" && $1!="eDP-1"){print $1}}')
resol=$(xrandr | sed -n "/^$secondMonName/{n;p}" | awk '{print $1}')
resol_x=$(echo $resol | awk -F "x" '{print $1}')
resol_y=$(echo $resol | awk -F "x" '{print $2}')
choices="laptopdual\nlaptop\nsecond\nmirror\nmirror2\nManual selection"
chosen=$(echo -e "$choices" | dmenu -i)
case "$chosen" in
laptopdual) xrandr --output eDP-1 --auto --output $secondMonName --auto --right-of eDP-1 ;;
laptop) xrandr --output eDP-1 --auto --output $secondMonName --off ;;
second) xrandr --output $secondMonName --auto --output eDP-1 --off ;;
mirror) xrandr --addmode eDP-1 "$resol" && xrandr --output eDP-1 --mode $resol --output $secondMonName --mode $resol --same-as eDP-1 ;;
mirror2) xrandr --output eDP-1 --mode 1366x768 --output $secondMonName --same-as eDP-1 --scale `echo "1366/$resol_x" | bc -l`x`echo "768/$resol_y" | bc -l`;;
"Manual selection") arandr ;;
esac
~/.fehbg
# Relaunch polybar if there was a selection.
#[ "$chosen" == "" ] || polybar_launch