- Restore desktop DP-3=primary/DP-2=secondary workspace mapping that broke when workspace routing switched from name-matching to raw geometric ordering. - Extract shared laptop/desktop detection + output ranking into lib-outputs.sh (battery presence selects the profile automatically), sourced by both select-workspace.sh and the new apply-outputs.sh, so keybind routing and monitor placement can never disagree. - Add apply-outputs.sh: on the laptop, automatically positions whatever external display is plugged in (and re-runs on hotplug via swaymsg -t subscribe), making it primary. No-op on the desktop, which keeps its static fixed-arrangement config.
38 lines
890 B
Bash
Executable File
38 lines
890 B
Bash
Executable File
#!/usr/bin/env bash
|
|
set -Eeuo pipefail
|
|
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
|
|
source "$SCRIPT_DIR/lib-outputs.sh"
|
|
|
|
slot=${1:-}
|
|
action=${2:-select}
|
|
|
|
if [[ ! "$slot" =~ ^([1-9]|10)$ ]]; then
|
|
printf 'Usage: %s <1-10> [select|move]\n' "${0##*/}" >&2
|
|
exit 2
|
|
fi
|
|
|
|
mapfile -t ordered < <(output_order)
|
|
focused=$(swaymsg -t get_outputs -r | jq -r '.[] | select(.focused) | .name')
|
|
|
|
index=-1
|
|
for i in "${!ordered[@]}"; do
|
|
[[ "${ordered[$i]}" == "$focused" ]] && index=$i && break
|
|
done
|
|
if ((index < 0)); then
|
|
printf 'Focused output %s is not currently tracked\n' "$focused" >&2
|
|
exit 1
|
|
fi
|
|
|
|
workspace=$((slot + index * 10))
|
|
|
|
case "$action" in
|
|
select) swaymsg workspace number "$workspace" >/dev/null ;;
|
|
move)
|
|
swaymsg move container to workspace number "$workspace" >/dev/null
|
|
;;
|
|
*)
|
|
printf 'Unknown action: %s\n' "$action" >&2
|
|
exit 2
|
|
;;
|
|
esac
|