testsAndMisc/linux_configuration/features/setup_monitor_autoconfig.sh
Krzysztof kuhy Rudnicki ba7b502322
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (mypy, mypy) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (pylint, pylint) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (rest, ) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (shellcheck, shellcheck) (push) Waiting to run
Python tests / test (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
Shell tests / shell-tests (push) Waiting to run
Shell tests / lib-tests (push) Waiting to run
Shell tests / arch-tests (push) Waiting to run
Monitors: survive boot, biggest is primary
The watcher started at the LightDM greeter, X refused it, and it hit
the systemd restart limit in 15 s, so DP-2 never came up. It now waits
for X, the unit passes XAUTHORITY, and i3 restarts it at login. The
biggest monitor is now primary and leftmost (DP-0 was hardcoded).
Prunes the oldest evidence file (60-file cap).

CI_GREEN_SKIP: main is red from a runner DNS outage (apt could not
resolve security.ubuntu.com), not code; failed jobs re-run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WzxdWWTekMNwEdyLgWRgTs
2026-11-12 08:03:06 +01:00

55 lines
1.7 KiB
Bash
Executable File

#!/bin/bash
# setup_monitor_autoconfig.sh — every monitor at its best mode, automatically.
#
# Installs the monitor-autoconfig systemd user service. It applies the layout
# at login and again whenever a monitor is plugged or unplugged:
# - each monitor runs its native resolution at the highest refresh rate;
# - the biggest monitor is primary and leftmost, the others to its right;
# - an unplugged monitor is switched off so no gap is left.
# Policy lives in monitor_layout.py; the watcher in monitor_autoconfig.py.
#
# Run as your normal user (never with sudo). Idempotent: rerun after edits.
# Uninstall: systemctl --user disable --now monitor-autoconfig.service
set -euo pipefail
HERE="$(dirname "$(readlink -f "$0")")"
readonly HERE
readonly UNIT=monitor-autoconfig.service
readonly UNIT_DIR="$HOME/.config/systemd/user"
log() { printf '[monitor-autoconfig] %s\n' "$*"; }
die() {
printf '[monitor-autoconfig] ERROR: %s\n' "$*" >&2
exit 1
}
install_deps() {
local pkg missing=()
for pkg in python-xlib xorg-xrandr; do
pacman -Q "$pkg" >/dev/null 2>&1 || missing+=("$pkg")
done
if ((${#missing[@]})); then
log "installing ${missing[*]}"
sudo pacman -S --needed --noconfirm "${missing[@]}"
fi
}
install_unit() {
mkdir -p "$UNIT_DIR"
sed "s|@FEATURES_DIR@|$HERE|" "$HERE/systemd/$UNIT" >"$UNIT_DIR/$UNIT"
systemctl --user daemon-reload
systemctl --user enable "$UNIT" >/dev/null
systemctl --user restart "$UNIT"
}
main() {
((EUID != 0)) || die "run as your normal user, not root"
install_deps
install_unit
systemctl --user is-active --quiet "$UNIT" || die "$UNIT failed to start"
log "active; layout now: $(xrandr --listmonitors | tail -n +2 | awk '{print $4}' | paste -sd' ')"
}
main "$@"