#!/bin/sh twoscreen() { mirror=$(printf "no\\nyes" | rofi -dmenu -i -p "Mirror displays?") if [ "$mirror" = "yes" ]; then external=$(echo "$screens" | rofi -dmenu -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" | rofi -dmenu -i -p "Select primary display") secondary=$(echo "$screens" | grep -v "$primary") direction=$(printf "left\\nright" | rofi -dmenu -i -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 } home() { xrandr --output "DisplayPort-${1}" --mode 2560x1440 $(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; notify-send "💻 Only one screen detected."; exit ;} # Get user choice including both and manual selection: chosen=$(printf -- "home-1\\nhome-2\\n----\\n%s\\n----\\nmulti" "$screens" | rofi -dmenu -i -p "Select display arangement") && case "$chosen" in "home-1") home 0 ;; "home-2") home 1 ;; "multi") twoscreen ;; "----") exit ;; *) onescreen "$chosen" ;; esac postrun