From af84673c80ae02091009a901770b505e756d002e Mon Sep 17 00:00:00 2001 From: sommerfeld Date: Wed, 13 May 2026 13:43:38 +0100 Subject: refactor(sway): apply display layout natively via include file Persist the layout as a sway-include file (~/.config/sway/outputs.conf) so sway's own parser applies output directives natively on every reload. Eliminates the side-by-side flash that came from sway's default "enable everything side-by-side" before exec_always could override it. - display-toggle.sh: write outputs.conf alongside the live swaymsg commands, mirroring the same enable/disable/pos directives. - sway/config: `include ~/.config/sway/outputs.conf` next to the background line; downgrade exec_always back to plain exec since the include handles reloads now (script only needs to run once at startup to bootstrap the include file on first boot). --- dot_config/sway/executable_display-toggle.sh | 31 +++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 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 08481dc..07fa59e 100755 --- a/dot_config/sway/executable_display-toggle.sh +++ b/dot_config/sway/executable_display-toggle.sh @@ -1,15 +1,29 @@ #!/bin/sh # Display mode manager: laptop-off ↔ side-by-side. # (no arg) toggle between modes (F7 / Super+x d). -# 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. +# apply re-apply the saved mode (used by display-watcher after +# hotplug). First boot defaults to laptop-off. # init force laptop-off; used by the hotplug watcher when a # newly-plugged external should preempt whatever was saved. +# +# State is persisted as a sway-include file at $OUTPUTS_CONF so that +# sway's own config parser applies the layout natively on every reload +# — no side-by-side flash before override. The script also issues live +# swaymsg commands so toggles are immediate without needing a reload. STATE_FILE="${XDG_RUNTIME_DIR:-/tmp}/display-mode" +OUTPUTS_CONF="${XDG_CONFIG_HOME:-$HOME/.config}/sway/outputs.conf" + +write_conf() { + # $1 = mode (laptop-off | side-by-side | laptop-only) + # remaining args are the sway `output ...` directives, one per arg. + { + printf '# Auto-generated by display-toggle.sh; do not edit.\n' + printf '# Current mode: %s\n' "$1" + shift + for line in "$@"; do printf '%s\n' "$line"; done + } >"$OUTPUTS_CONF" +} OUTPUTS=$(swaymsg -t get_outputs -r) LAPTOP=$(echo "$OUTPUTS" | jq -r '[.[] | select(.name | test("^eDP")) | .name] | first // empty') @@ -21,6 +35,7 @@ if [ -z "$EXTERNAL" ]; then if [ -n "$LAPTOP" ]; then swaymsg output "$LAPTOP" enable pos 0 0 || true echo "laptop-only" >"$STATE_FILE" + write_conf "laptop-only" "output $LAPTOP enable pos 0 0" fi [ -z "${1:-}" ] && notify-send "Display" "No external display connected" exit 0 @@ -49,12 +64,18 @@ case "$NEXT" in swaymsg output "$EXTERNAL" enable || true swaymsg workspace number 1 || true echo "laptop-off" >"$STATE_FILE" + write_conf "laptop-off" \ + "output $LAPTOP disable" \ + "output $EXTERNAL enable" [ -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" + write_conf "side-by-side" \ + "output $LAPTOP enable pos 0 0" \ + "output $EXTERNAL enable pos $LAPTOP_WIDTH 0" [ -z "${1:-}" ] && notify-send "Display" "Side by side" ;; esac -- cgit v1.3.1