monitor-hotplug (1162B)
1 #!/usr/bin/env bash 2 3 export DISPLAY=:0.0 4 5 connect() { 6 local display=$1 7 local position=$2 8 9 case "${position}" in 10 "left"|"l") xrandr --output eDP-1 --auto --left-of "${display}" \ 11 --output "${display}" --auto ;; 12 "right"|"r") xrandr --output eDP-1 --auto --right-of "${display}" \ 13 --output "${display}" --auto ;; 14 "above"|"a") xrandr --output eDP-1 --auto --above "${display}" \ 15 --output "${display}" --auto ;; 16 "below"|"b") xrandr --output eDP-1 --auto --below "${display}" \ 17 --output "${display}" --auto ;; 18 *) xrandr --output eDP-1 --off --output "${display}" --auto ;; 19 esac 20 21 notify-send "Connected monitor." 22 } 23 24 disconnect() { 25 xrandr --output eDP-1 --auto \ 26 --output DP-1 --off \ 27 --output DP-2 --off \ 28 --output DP-3 --off \ 29 --output DP-4 --off 30 31 notify-send "Disconnected monitor." 32 } 33 34 main() { 35 local display 36 for d in DP-1 DP-2 DP-3 DP-4; do 37 if xrandr | grep -q "^${d} connected"; then 38 display="${d}" 39 break 40 fi 41 done 42 43 if [ -n "${display}" ]; then 44 printf "connecting" 45 connect "${display}" "$1" 46 else 47 disconnect 48 fi 49 50 map-bg 51 doas systemctl restart keyd 52 } 53 54 main "$@"