aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/dot_config/sway
diff options
context:
space:
mode:
Diffstat (limited to 'dot_config/sway')
-rw-r--r--dot_config/sway/config1
-rwxr-xr-xdot_config/sway/executable_display-watcher.sh20
2 files changed, 21 insertions, 0 deletions
diff --git a/dot_config/sway/config b/dot_config/sway/config
index e66b077..df05597 100644
--- a/dot_config/sway/config
+++ b/dot_config/sway/config
@@ -156,3 +156,4 @@ exec dbus-update-activation-environment --systemd DISPLAY WAYLAND_DISPLAY SWAYSO
exec mako
exec poweralertd
exec "sleep 2 && ~/.config/sway/display-toggle.sh init"
+exec ~/.config/sway/display-watcher.sh
diff --git a/dot_config/sway/executable_display-watcher.sh b/dot_config/sway/executable_display-watcher.sh
new file mode 100755
index 0000000..94ee943
--- /dev/null
+++ b/dot_config/sway/executable_display-watcher.sh
@@ -0,0 +1,20 @@
+#!/bin/sh
+# Watch sway output events. When the set of connected external displays
+# changes (plug/unplug), re-apply the preferred layout via display-toggle.sh.
+# Manual F7 toggles don't trip this because they don't change external count.
+set -eu
+
+has_external() {
+ swaymsg -t get_outputs -r |
+ jq -e '[.[] | select(.name | test("^eDP") | not)] | length > 0' >/dev/null
+}
+
+prev=$(has_external && echo yes || echo no)
+
+swaymsg -t subscribe -m '["output"]' | while read -r _; do
+ cur=$(has_external && echo yes || echo no)
+ if [ "$cur" != "$prev" ]; then
+ ~/.config/sway/display-toggle.sh init
+ prev="$cur"
+ fi
+done