feat: improve monitor toggle

This commit is contained in:
itsscb 2025-08-27 07:57:57 +02:00
parent a64a298181
commit 97a72e9dc8
3 changed files with 37 additions and 36 deletions

View File

@ -1,35 +0,0 @@
#!/usr/bin/env bash
# ~/.local/bin/hyprautointernal.sh
# Disable the laptop panel (eDP1) when any other monitor is connected,
# otherwise enable it.
set -u
INT="eDP-1" # internal monitor name change if yours differs
log() {
notify-send "$*"
}
# -------------------------------------------------
# 1⃣ Get current monitor list
# -------------------------------------------------
MONS=$(hyprctl monitors 2>/dev/null || true)
# -------------------------------------------------
# 2⃣ Decide whether an external monitor is present
# -------------------------------------------------
# Any line that is *not* the internal monitor counts as external.
if echo "$MONS" | grep -qv "$INT"; then
# At least one external monitor is connected
log "External monitor detected → disabling $INT"
hyprctl keyword monitor $INT, disable 2>/dev/null
hyprctl keyword workspace r[1-5] m[DP-4]
hyprctl keyword workspace r[6-0] m[DP-5]
else
# No external monitor → make sure the internal one is on
log "No external monitor → enabling $INT"
hyprctl keyword monitor $INT, preferred,auto,1.5 2>/dev/null
hyprctl reload 2>/dev/null
fi

View File

@ -0,0 +1,36 @@
#!/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

View File

@ -40,4 +40,4 @@ bindd = CTRL ALT, PRINT, Screen record display, exec, omarchy-cmd-screenrecord o
bindd = SUPER, PRINT, Color picker, exec, pkill hyprpicker || hyprpicker -a
# Disable internal monitor
bindd = SUPER CTRL, F12, Disable Internal Monitor, exec, comarchy-disable-internal-monitor
bindd = SUPER CTRL, F12, Disable Internal Monitor, exec, comarchy-toggle-disable-internal-monitor