Files
dotfiles/.config/hypr/scripts/monitor-toggle.sh
T

67 lines
1.6 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
PRIMARY="eDP-2"
DP_OUT="DP-2"
HDMI_OUT="HDMI-A-1"
# eDP-2 at scale 1.5 → logical width 1280px → externals start at x=1280
# DP-2 at 1920px wide → HDMI starts at x=1280+1920=3200
notify() {
notify-send -a "monitor-toggle" "$1" "${2:-}" 2>/dev/null || true
}
active_monitors() {
hyprctl -j monitors | jq -r '.[] | select(.disabled != true) | .name'
}
has_external() {
active_monitors | grep -qvx "$PRIMARY"
}
profile_laptop() {
wlr-randr --output "$DP_OUT" --off 2>/dev/null || true
wlr-randr --output "$HDMI_OUT" --off 2>/dev/null || true
notify "Laptop only"
}
profile_dual() {
wlr-randr --output "$PRIMARY" --on --mode 1920x1080@144 --pos 0,0 --scale 1
wlr-randr --output "$HDMI_OUT" --on --mode 1920x1080@60 --pos 1920,0 --scale 1
wlr-randr --output "$DP_OUT" --off 2>/dev/null || true
notify "Dual"
}
profile_triple() {
wlr-randr --output "$PRIMARY" --on --mode 1920x1080@144 --pos 0,0 --scale 1
wlr-randr --output "$HDMI_OUT" --on --mode 1920x1080@60 --pos 1920,0 --scale 1
wlr-randr --output "$DP_OUT" --on --mode 1920x1080@60 --pos 3840,0 --scale 1 --transform 90
notify "Triple"
}
toggle() {
if has_external; then
profile_laptop
else
profile_triple
fi
}
status() {
echo "Active monitors:"
active_monitors | sed 's/^/ - /'
}
case "${1:-}" in
laptop) profile_laptop ;;
dual) profile_dual ;;
triple) profile_triple ;;
toggle) toggle ;;
status) status ;;
*)
echo "Usage: $(basename "$0") laptop|dual|triple|toggle|status"
exit 1
;;
esac