Poor man's multihead management.
mont r
put external 1080p monitor to the right of laptop's built-in 4K monitor.mont s
use built-in monitor only.mont a
automatically choose among the above 2 setups.
#!/bin/bash | |
DPI=192 | |
IND=eDP-1 | |
EXD="will be overridden later" | |
dir=$1 | |
shift | |
xrr() { | |
xrandr --dpi $DPI "$@" | |
} | |
xrrtop() { | |
xrr \ | |
--output "$IND" --auto --pos 0x2160 --primary \ | |
--output "$EXD" --auto --pos 0x0 --scale 2x2 | |
} | |
xrrleft() { | |
xrr \ | |
--output "$IND" --auto --pos 3840x0 --primary \ | |
--output "$EXD" --auto --scale 2x2 --pos 0x0 | |
} | |
xrrright() { | |
xrr \ | |
--output "$IND" --auto --pos 0x0 --primary \ | |
--output "$EXD" --auto --scale 2x2 --pos 3840x0 | |
} | |
xrrsingle() { | |
active_exd="$(xrandr --listactivemonitors | grep -Ee '\b(HDMI|DP)\b' | awk '{print $4}')" | |
xrr --output "$IND" --auto --primary \ | |
--output "$active_exd" --off | |
} | |
find_external_display() { | |
EXD="$(xrandr -q | grep -E '\bconnected\b' | grep -v "^$IND" | cut -d ' ' -f1)" | |
} | |
find_external_display | |
case $dir in | |
a|auto) | |
if xrandr --listmonitors | grep "$EXD" -q &>/dev/null; then | |
xrrright | |
else | |
xrrsingle | |
fi | |
;; | |
up|u|t|top) | |
xrrtop | |
;; | |
left|l) | |
xrrleft | |
;; | |
right|r) | |
xrrright | |
;; | |
single|s) | |
xrrsingle | |
;; | |
*) | |
exit 1 | |
;; | |
esac | |
(sleep 1; nitrogen --restore &>/dev/null) & | |
(sleep 2; launch-polybar &>/dev/null) & |