#!/usr/bin/env bash # Laptop-only dynamic monitor placement: whenever a display is plugged or # unplugged, arrange active outputs left-to-right in output_order() order # (external display(s) first, internal panel last), so a newly connected # external monitor gets a sensible position automatically without any # manual config. On the desktop this exits immediately — that monitor # pair has a fixed physical arrangement set statically in # conf.d/10-appearance.conf. set -Eeuo pipefail SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" source "$SCRIPT_DIR/lib-outputs.sh" is_laptop || exit 0 apply_layout() { local outputs_json x=0 name width outputs_json=$(swaymsg -t get_outputs -r) mapfile -t ordered < <(output_order) for name in "${ordered[@]}"; do width=$(jq -r --arg n "$name" '.[] | select(.name==$n) | .rect.width' <<<"$outputs_json") swaymsg output "$name" position "$x" 0 >/dev/null 2>&1 || true x=$((x + width)) done } apply_layout swaymsg -t subscribe -m '["output"]' | while read -r _; do apply_layout done