From 97a72e9dc87fb32d9d14273f358cfef89c621b70 Mon Sep 17 00:00:00 2001 From: itsscb Date: Wed, 27 Aug 2025 07:57:57 +0200 Subject: [PATCH] feat: improve monitor toggle --- bin/comarchy-disable-internal-monitor | 35 ------------------- bin/comarchy-toggle-disable-internal-monitor | 36 ++++++++++++++++++++ default/hypr/bindings/utilities.conf | 2 +- 3 files changed, 37 insertions(+), 36 deletions(-) delete mode 100755 bin/comarchy-disable-internal-monitor create mode 100755 bin/comarchy-toggle-disable-internal-monitor diff --git a/bin/comarchy-disable-internal-monitor b/bin/comarchy-disable-internal-monitor deleted file mode 100755 index 9f7ecdca..00000000 --- a/bin/comarchy-disable-internal-monitor +++ /dev/null @@ -1,35 +0,0 @@ - -#!/usr/bin/env bash -# ~/.local/bin/hypr‑auto‑internal.sh -# Disable the laptop panel (eDP‑1) 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 diff --git a/bin/comarchy-toggle-disable-internal-monitor b/bin/comarchy-toggle-disable-internal-monitor new file mode 100755 index 00000000..c4c1e761 --- /dev/null +++ b/bin/comarchy-toggle-disable-internal-monitor @@ -0,0 +1,36 @@ +#!/usr/bin/env bash +# Disable the laptop panel (eDP‑1) 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 diff --git a/default/hypr/bindings/utilities.conf b/default/hypr/bindings/utilities.conf index 9dfb29d1..8608f50a 100644 --- a/default/hypr/bindings/utilities.conf +++ b/default/hypr/bindings/utilities.conf @@ -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