From 1a19bec22a45a4ca92e1ef4637b8e55286df0585 Mon Sep 17 00:00:00 2001 From: sommerfeld Date: Tue, 21 Apr 2026 01:24:52 +0100 Subject: sway: auto-toggle display layout on external plug/unplug --- dot_config/sway/executable_display-watcher.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100755 dot_config/sway/executable_display-watcher.sh (limited to 'dot_config/sway/executable_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 -- cgit v1.2.3-70-g09d2