From d6aaf30e43686aebbfb1f9ae8e5bf9986c4d7731 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 19 Apr 2026 17:11:48 +0200 Subject: [PATCH] Ensure internal display is turned back on if the external one is disconnected --- bin/omarchy-hyprland-monitor-internal-recover | 14 ++++++++++++++ bin/omarchy-hyprland-monitor-watch | 14 ++++++++++++++ default/hypr/autostart.conf | 2 ++ install/omarchy-base.packages | 1 + migrations/1776611242.sh | 2 ++ 5 files changed, 33 insertions(+) create mode 100755 bin/omarchy-hyprland-monitor-internal-recover create mode 100755 bin/omarchy-hyprland-monitor-watch create mode 100644 migrations/1776611242.sh diff --git a/bin/omarchy-hyprland-monitor-internal-recover b/bin/omarchy-hyprland-monitor-internal-recover new file mode 100755 index 00000000..54df8099 --- /dev/null +++ b/bin/omarchy-hyprland-monitor-internal-recover @@ -0,0 +1,14 @@ +#!/bin/bash + +# Re-enable the internal display if it was toggled off and no external monitors +# are currently active (e.g. external got disconnected live, during sleep, or +# wasn't present on boot). + +if omarchy-hyprland-toggle-enabled internal-monitor-disable; then + ACTIVE_COUNT=$(hyprctl monitors -j 2>/dev/null | jq 'length') + if [[ ${ACTIVE_COUNT:-0} -eq 0 ]]; then + omarchy-hyprland-toggle \ + --disabled-notification "󰍹 Internal display restored (no external connected)" \ + internal-monitor-disable + fi +fi diff --git a/bin/omarchy-hyprland-monitor-watch b/bin/omarchy-hyprland-monitor-watch new file mode 100755 index 00000000..0dce58cb --- /dev/null +++ b/bin/omarchy-hyprland-monitor-watch @@ -0,0 +1,14 @@ +#!/bin/bash + +# Listen on Hyprland's event socket and recover the internal display whenever +# a monitor is removed. + +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 + ;; + esac +done diff --git a/default/hypr/autostart.conf b/default/hypr/autostart.conf index d6e1e4c8..f4a2f392 100644 --- a/default/hypr/autostart.conf +++ b/default/hypr/autostart.conf @@ -7,6 +7,8 @@ exec-once = uwsm-app -- swayosd-server exec-once = /usr/lib/polkit-gnome/polkit-gnome-authentication-agent-1 exec-once = omarchy-cmd-first-run exec-once = omarchy-powerprofiles-init +exec-once = omarchy-hyprland-monitor-internal-recover +exec-once = uwsm-app -- omarchy-hyprland-monitor-watch # Slow app launch fix -- set systemd vars exec-once = systemctl --user import-environment $(env | cut -d'=' -f 1) diff --git a/install/omarchy-base.packages b/install/omarchy-base.packages index d8dd7f55..c04547bf 100644 --- a/install/omarchy-base.packages +++ b/install/omarchy-base.packages @@ -112,6 +112,7 @@ sddm signal-desktop slurp spotify +socat starship sushi swaybg diff --git a/migrations/1776611242.sh b/migrations/1776611242.sh new file mode 100644 index 00000000..8e0fddca --- /dev/null +++ b/migrations/1776611242.sh @@ -0,0 +1,2 @@ +echo "Install socat for the Hyprland monitor event watcher" +omarchy-pkg-add socat