omarchy/bin/comarchy-toggle-disable-internal-monitor

37 lines
924 B
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
# Disable the laptop panel (eDP1) when any other monitor is connected,
# otherwise enable it.
set -u
# internal monitor name change if yours differs
INT="eDP-1"
log() {
notify-send "$*"
}
output=$(hyprctl monitors 2>/dev/null) || {
echo "Error: hyprctl not found or command failed" >&2
exit 1
}
mapfile -t monitors < <(
grep -oP '(?<=^Monitor ).*?(?= \(ID )' <<<"$output"
)
len=${#monitors[@]}
if (( len == 2 )); then
hyprctl keyword monitor $INT, disable 2>/dev/null
hyprctl keyword workspace r[0-9] m[${monitors[1]}]
elif (( len == 3 )); then
hyprctl keyword monitor $INT, disable 2>/dev/null
hyprctl keyword workspace r[1-5] m[${monitors[1]}]
hyprctl keyword workspace r[6-9] m[${monitors[2]}]
hyprctl keyword workspace r[0] m[${monitors[2]}]
else
hyprctl keyword monitor $INT, preferred,auto,1.5 2>/dev/null
hyprctl reload 2>/dev/null
fi