diff options
| author | 2026-04-21 01:24:52 +0100 | |
|---|---|---|
| committer | 2026-04-21 01:24:52 +0100 | |
| commit | 1a19bec22a45a4ca92e1ef4637b8e55286df0585 (patch) | |
| tree | 6cf4ad4e7da32892a164385081390b21a102fb37 /dot_config | |
| parent | 061bbf62c1af95a8c51f040680c9610537cb3230 (diff) | |
| download | dotfiles-1a19bec22a45a4ca92e1ef4637b8e55286df0585.tar.gz dotfiles-1a19bec22a45a4ca92e1ef4637b8e55286df0585.tar.bz2 dotfiles-1a19bec22a45a4ca92e1ef4637b8e55286df0585.zip | |
sway: auto-toggle display layout on external plug/unplug
Diffstat (limited to 'dot_config')
| -rw-r--r-- | dot_config/sway/config | 1 | ||||
| -rwxr-xr-x | dot_config/sway/executable_display-watcher.sh | 20 |
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 |
