aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/dot_config/sway
diff options
context:
space:
mode:
authorLibravatar sommerfeld <sommerfeld@sommerfeld.dev>2026-05-13 13:43:38 +0100
committerLibravatar sommerfeld <sommerfeld@sommerfeld.dev>2026-05-13 13:43:38 +0100
commit2098f17c701b28ce2d0725a1e4837d628f4beb1d (patch)
tree0235ed470b5391b73241e6ce95bed94bc04fbf5d /dot_config/sway
parentedc642139610cd9923130558ae96cef6c55958a7 (diff)
downloaddotfiles-2098f17c701b28ce2d0725a1e4837d628f4beb1d.tar.gz
dotfiles-2098f17c701b28ce2d0725a1e4837d628f4beb1d.tar.bz2
dotfiles-2098f17c701b28ce2d0725a1e4837d628f4beb1d.zip
fix(sway): re-apply display layout on config reload, drop resume hook
Real cause of the silent switch back to side-by-side: sway reload (Super+Shift+c or swaymsg reload) re-evaluates output config and defaults to all-outputs-enabled-side-by-side, dropping the runtime positions set by display-toggle.sh. - sway config: `exec` -> `exec_always` so the saved layout is re-applied on every reload, and use `apply` instead of `init` so user-chosen layouts (e.g. side-by-side picked deliberately) survive reloads. First boot still defaults to laptop-off via the script's state-file fallback. - swayidle.service: drop the after-resume hook -- DPMS resume isn't what was breaking the layout, reload was. Less surface area.
Diffstat (limited to 'dot_config/sway')
-rw-r--r--dot_config/sway/config2
-rwxr-xr-xdot_config/sway/executable_display-toggle.sh23
2 files changed, 14 insertions, 11 deletions
diff --git a/dot_config/sway/config b/dot_config/sway/config
index 1e2cc5f..73283c9 100644
--- a/dot_config/sway/config
+++ b/dot_config/sway/config
@@ -238,7 +238,7 @@ bindsym $mod+t exec ~/.config/sway/tb-toggle.sh
# ── Autostart ─────────────────────────────────────────────────────────────────
exec systemctl --user import-environment DISPLAY WAYLAND_DISPLAY SWAYSOCK XDG_CURRENT_DESKTOP XDG_SESSION_TYPE XDG_SESSION_DESKTOP PASSWORD_STORE_DIR
exec dbus-update-activation-environment --systemd DISPLAY WAYLAND_DISPLAY SWAYSOCK XDG_CURRENT_DESKTOP XDG_SESSION_TYPE XDG_SESSION_DESKTOP PASSWORD_STORE_DIR
-exec "sleep 2 && ~/.config/sway/display-toggle.sh init"
+exec_always "sleep 2 && ~/.config/sway/display-toggle.sh apply"
exec systemctl --user start sway-session.target
exec ~/.config/sway/tb-autostart.sh
diff --git a/dot_config/sway/executable_display-toggle.sh b/dot_config/sway/executable_display-toggle.sh
index 66747fb..08481dc 100755
--- a/dot_config/sway/executable_display-toggle.sh
+++ b/dot_config/sway/executable_display-toggle.sh
@@ -1,10 +1,13 @@
#!/bin/sh
# Display mode manager: laptop-off ↔ side-by-side.
# (no arg) toggle between modes (F7 / Super+x d).
-# init force laptop-off on session start / external plugged in.
-# apply re-apply whatever is in the state file (used after resume,
-# since sway resets output config on wake → both monitors
-# come back enabled side-by-side regardless of saved state).
+# apply re-apply whatever is in the state file. Used by sway's
+# exec_always at startup and on every config reload (sway
+# reload re-enables all outputs side-by-side by default;
+# this restores the user's chosen layout). First boot
+# defaults to laptop-off when no state file exists.
+# init force laptop-off; used by the hotplug watcher when a
+# newly-plugged external should preempt whatever was saved.
STATE_FILE="${XDG_RUNTIME_DIR:-/tmp}/display-mode"
@@ -19,7 +22,7 @@ if [ -z "$EXTERNAL" ]; then
swaymsg output "$LAPTOP" enable pos 0 0 || true
echo "laptop-only" >"$STATE_FILE"
fi
- [ -z "$1" ] && notify-send "Display" "No external display connected"
+ [ -z "${1:-}" ] && notify-send "Display" "No external display connected"
exit 0
fi
@@ -28,10 +31,10 @@ fi
LAPTOP_WIDTH=$(echo "$OUTPUTS" | jq -r ".[] | select(.name == \"$LAPTOP\") | .current_mode.width // .modes[0].width")
[ -z "$LAPTOP_WIDTH" ] && LAPTOP_WIDTH=1920
-if [ "${1:-}" = "init" ]; then
- NEXT="laptop-off"
-elif [ "${1:-}" = "apply" ]; then
+if [ "${1:-}" = "apply" ]; then
NEXT=$(cat "$STATE_FILE" 2>/dev/null || echo "laptop-off")
+elif [ "${1:-}" = "init" ]; then
+ NEXT="laptop-off"
else
CURRENT=$(cat "$STATE_FILE" 2>/dev/null || echo "laptop-off")
case "$CURRENT" in
@@ -46,12 +49,12 @@ case "$NEXT" in
swaymsg output "$EXTERNAL" enable || true
swaymsg workspace number 1 || true
echo "laptop-off" >"$STATE_FILE"
- [ -z "$1" ] && notify-send "Display" "Laptop screen off"
+ [ -z "${1:-}" ] && notify-send "Display" "Laptop screen off"
;;
side-by-side)
swaymsg output "$LAPTOP" enable pos 0 0 || true
swaymsg output "$EXTERNAL" enable pos "$LAPTOP_WIDTH" 0 || true
echo "side-by-side" >"$STATE_FILE"
- [ -z "$1" ] && notify-send "Display" "Side by side"
+ [ -z "${1:-}" ] && notify-send "Display" "Side by side"
;;
esac