diff options
Diffstat (limited to 'dot_config/sway/executable_display-toggle.sh')
| -rwxr-xr-x | dot_config/sway/executable_display-toggle.sh | 31 |
1 files changed, 26 insertions, 5 deletions
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 |
