diff --git a/bin/omarchy-hyprland-monitor-internal b/bin/omarchy-hyprland-monitor-internal index 865c82d616..977bd2ec35 100755 --- a/bin/omarchy-hyprland-monitor-internal +++ b/bin/omarchy-hyprland-monitor-internal @@ -1,7 +1,7 @@ #!/bin/bash # omarchy:summary=Enable, disable, toggle, or recover the internal laptop display -# omarchy:args= +# omarchy:args= TOGGLE="internal-monitor-disable" TOGGLE_FLAG="$HOME/.local/state/omarchy/toggles/hypr/$TOGGLE.conf" @@ -31,7 +31,15 @@ off() { } recover() { - if ! omarchy-hw-external-monitors; then + if omarchy-hyprland-toggle-enabled $TOGGLE; then + # External monitors can take a few seconds to become available after sleep, so wait up to 3s + for i in {1..6}; do + if omarchy-hw-external-monitors; then + return + fi + sleep 0.5 + done + omarchy-hyprland-toggle $TOGGLE off fi } @@ -44,13 +52,20 @@ toggle() { fi } +reapply() { + if omarchy-hyprland-toggle-enabled $TOGGLE; then + hyprctl reload + fi +} + case "$1" in on) on ;; off) off ;; toggle) toggle ;; recover) recover ;; + reapply) reapply ;; *) - echo "Usage: $(basename "$0") {on|off|toggle|recover}" >&2 + echo "Usage: $(basename "$0") {on|off|toggle|recover|reapply}" >&2 exit 1 ;; esac diff --git a/bin/omarchy-hyprland-monitor-internal-mirror b/bin/omarchy-hyprland-monitor-internal-mirror index 5c9e92bcda..30d47eab82 100755 --- a/bin/omarchy-hyprland-monitor-internal-mirror +++ b/bin/omarchy-hyprland-monitor-internal-mirror @@ -1,7 +1,7 @@ #!/bin/bash # omarchy:summary=Enable, disable, toggle, or recover mirroring the internal display to an external monitor -# omarchy:args= +# omarchy:args= TOGGLE="internal-monitor-mirror" TOGGLE_FLAG="$HOME/.local/state/omarchy/toggles/hypr/$TOGGLE.conf" @@ -45,18 +45,33 @@ toggle() { } recover() { - if ! omarchy-hw-external-monitors; then + if omarchy-hyprland-toggle-enabled $TOGGLE; then + # External monitors can take a few seconds to become available after sleep, so wait up to 3s + for i in {1..6}; do + if omarchy-hw-external-monitors; then + return + fi + sleep 0.5 + done + omarchy-hyprland-toggle $TOGGLE off fi } +reapply() { + if omarchy-hyprland-toggle-enabled $TOGGLE; then + hyprctl reload + fi +} + case "$1" in on) on ;; off) off ;; toggle) toggle ;; recover) recover ;; + reapply) reapply ;; *) - echo "Usage: $(basename "$0") {on|off|toggle|recover}" >&2 + echo "Usage: $(basename "$0") {on|off|toggle|recover|reapply}" >&2 exit 1 ;; esac diff --git a/bin/omarchy-hyprland-monitor-watch b/bin/omarchy-hyprland-monitor-watch index 7d0df49410..14e4fae32d 100755 --- a/bin/omarchy-hyprland-monitor-watch +++ b/bin/omarchy-hyprland-monitor-watch @@ -6,9 +6,13 @@ SOCKET="$XDG_RUNTIME_DIR/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock" socat -U - "UNIX-CONNECT:$SOCKET" | while read -r event; do case "$event" in - monitorremoved\>\>*|monitorremovedv2\>\>*) - omarchy-hyprland-monitor-internal recover - omarchy-hyprland-monitor-internal-mirror recover - ;; + monitorremoved\>* | monitorremovedv2\>*) + omarchy-hyprland-monitor-internal recover + omarchy-hyprland-monitor-internal-mirror recover + ;; + monitoradded\>* | monitoraddedv2\>*) + omarchy-hyprland-monitor-internal reapply + omarchy-hyprland-monitor-internal-mirror reapply + ;; esac done