aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--dot_config/sway/config6
-rwxr-xr-xdot_config/sway/executable_display-toggle.sh31
2 files changed, 31 insertions, 6 deletions
diff --git a/dot_config/sway/config b/dot_config/sway/config
index 73283c9..ac7acb3 100644
--- a/dot_config/sway/config
+++ b/dot_config/sway/config
@@ -40,6 +40,10 @@ seat * xcursor_theme Adwaita 24
# ── Output ────────────────────────────────────────────────────────────────────
output * bg #282828 solid_color
+# Per-output enable/disable/position is written by display-toggle.sh and
+# re-read by sway on every reload. Sway's `include` silently no-ops if the
+# file doesn't exist (first boot, before the script has run).
+include ~/.config/sway/outputs.conf
# ── Window rules ──────────────────────────────────────────────────────────────
for_window [class="feh"] floating enable
@@ -238,7 +242,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_always "sleep 2 && ~/.config/sway/display-toggle.sh apply"
+exec "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 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