From 2098f17c701b28ce2d0725a1e4837d628f4beb1d Mon Sep 17 00:00:00 2001 From: sommerfeld Date: Wed, 13 May 2026 13:43:38 +0100 Subject: 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. --- dot_config/sway/executable_display-toggle.sh | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'dot_config/sway/executable_display-toggle.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 -- cgit v1.3.1