feat(display): menu-driven per-output resolution, in-flake
Phase 3 of the in-flake-state philosophy (mirroring night-light + the
keyboard-layout watcher): a System ▸ Display menu item picks an output's
resolution and persists it into the flake instead of a runtime-only tweak.
- rofi.nix: the `display` case reads `hyprctl monitors -j` (auto-skips the
chooser with one output), lists the output's advertised modes (rounded
refresh, deduped, highest-first) plus the preferred/highres/highrr
tokens, applies the pick INSTANTLY via `hyprctl keyword monitor` —
keeping the output's current position + scale, so only the resolution
changes — then persists it with `nomarchy-theme-sync set
settings.monitors.<name> <mode> --no-switch` (no rebuild).
- theme.nix: seed `settings.monitors = {}` (output-name -> "WxH@R") so a
sparse/older state file still evaluates; exposed via nomarchy.settings.
- hyprland.nix: `resolvedMonitors` overlays settings.monitors onto
nomarchy.monitors by name — a declared output keeps its other fields
with only the resolution swapped, an undeclared output (wildcard-only,
e.g. the laptop panel) becomes a fresh rule. So a later rebuild bakes
the menu pick into the generated monitor rule — the monitor twin of the
keyboard graduation. The menu pick wins over a hand-set resolution (it's
the explicit live action).
Monitor connector names are dot-free, so a direct dotted set-path is safe
(no whole-map read-modify-write like the keyboard watcher needs).
VM-verified via a headless-Hyprland nixosTest (run + removed; too heavy
for a CI gate): the graduation baked the rule into the generated
hyprland.conf, the set/get round-trip persisted, and `hyprctl keyword
monitor` actually changed the reported resolution. Only the interactive
rofi picker isn't headlessly driveable (same caveat as the keyboard watcher).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -280,6 +280,56 @@ ${themeRows}
|
||||
*Input*) exec rofi-pulse-select source ;;
|
||||
esac ;;
|
||||
|
||||
display)
|
||||
# Per-output resolution picker. Applies the chosen mode INSTANTLY via
|
||||
# `hyprctl keyword monitor` — keeping the output's current position and
|
||||
# scale, so only the resolution changes — and PERSISTS it to the in-flake
|
||||
# state (settings.monitors.<name>, --no-switch = no rebuild), so the
|
||||
# choice survives logout/reboot. A later rebuild bakes the same
|
||||
# resolution into the generated monitor rule (hyprland.nix overlays
|
||||
# settings.monitors onto nomarchy.monitors by name). Self-gated to the
|
||||
# Hyprland session; guard here too in case it's invoked directly.
|
||||
command -v hyprctl >/dev/null 2>&1 \
|
||||
|| { notify-send "Display" "Hyprland is not running."; exit 0; }
|
||||
mons=$(hyprctl monitors -j)
|
||||
|
||||
# Choose the output (skip the chooser when only one is connected).
|
||||
if [ "$(printf '%s' "$mons" | jq -r '.[].name' | grep -c .)" -gt 1 ]; then
|
||||
name=$( {
|
||||
printf '%s' "$mons" | jq -r '.[] | "\(.name) · \(.width)x\(.height)@\(.refreshRate|round)Hz"'
|
||||
printf '%s\n' "$BACK"
|
||||
} | rofi -dmenu -p Display ) || exit 0
|
||||
[ "$name" = "$BACK" ] && exec "$0" system
|
||||
name=''${name%% ·*} # strip the " · WxH@R" hint
|
||||
else
|
||||
name=$(printf '%s' "$mons" | jq -r '.[0].name')
|
||||
fi
|
||||
[ -n "$name" ] || exit 0
|
||||
|
||||
# Pick a mode: a few Hyprland resolution tokens, then the output's
|
||||
# advertised modes (rounded refresh rate, deduped, highest first). The
|
||||
# prompt shows the current mode.
|
||||
cur=$(printf '%s' "$mons" | jq -r --arg n "$name" \
|
||||
'.[]|select(.name==$n)|"\(.width)x\(.height)@\(.refreshRate|round)"')
|
||||
mode=$( {
|
||||
printf 'preferred\nhighres\nhighrr\n'
|
||||
printf '%s' "$mons" | jq -r --arg n "$name" '.[]|select(.name==$n)|.availableModes[]' \
|
||||
| sed 's/Hz$//' | awk -F@ '{ printf "%s@%d\n", $1, $2 + 0.5 }' | sort -rV -u
|
||||
printf '%s\n' "$BACK"
|
||||
} | rofi -dmenu -p "$name (now $cur)" ) || exit 0
|
||||
[ "$mode" = "$BACK" ] && exec "$0" display
|
||||
[ -n "$mode" ] || exit 0
|
||||
|
||||
# Apply live (keep the output's current position + scale), then persist.
|
||||
pos=$(printf '%s' "$mons" | jq -r --arg n "$name" '.[]|select(.name==$n)|"\(.x)x\(.y)"')
|
||||
scale=$(printf '%s' "$mons" | jq -r --arg n "$name" '.[]|select(.name==$n)|.scale')
|
||||
if hyprctl keyword monitor "$name,$mode,$pos,$scale" >/dev/null 2>&1; then
|
||||
nomarchy-theme-sync --quiet set "settings.monitors.$name" "$mode" --no-switch
|
||||
notify-send "Display" "$name → $mode"
|
||||
else
|
||||
notify-send "Display" "Could not set $name to $mode."
|
||||
fi ;;
|
||||
|
||||
capture)
|
||||
choice=$( {
|
||||
row "Region → clipboard" applets-screenshooter
|
||||
@@ -382,6 +432,7 @@ ${themeRows}
|
||||
row "Bluetooth" bluetooth
|
||||
[ -e "''${XDG_RUNTIME_DIR:-/run/user/$(id -u)}/pulse/native" ] \
|
||||
&& row "Audio" audio-volume-high
|
||||
row "Display" video-display
|
||||
command -v system-config-printer >/dev/null 2>&1 && row "Printers" printer
|
||||
row "Do Not Disturb" notification-disabled
|
||||
if systemctl --user is-active --quiet hyprsunset.service 2>/dev/null
|
||||
@@ -404,6 +455,7 @@ ${themeRows}
|
||||
*VPN*) exec "$0" vpn ;;
|
||||
*Bluetooth*) exec "$0" bluetooth ;;
|
||||
*Audio*) exec "$0" audio ;;
|
||||
*Display*) exec "$0" display ;;
|
||||
*Printers*) exec "$0" printers ;;
|
||||
*"Do Not Disturb"*) exec "$0" dnd ;;
|
||||
*"Night light"*) exec "$0" nightlight ;;
|
||||
@@ -434,7 +486,7 @@ ${themeRows}
|
||||
esac ;;
|
||||
|
||||
*)
|
||||
echo "usage: nomarchy-menu [tools|system|power|power-profile|theme|clipboard|calc|files|emoji|web|network|bluetooth|audio|printers|capture|keybinds|ask|dnd|nightlight|autotimezone|vpn|snapshot]" >&2
|
||||
echo "usage: nomarchy-menu [tools|system|power|power-profile|theme|clipboard|calc|files|emoji|web|network|bluetooth|audio|display|printers|capture|keybinds|ask|dnd|nightlight|autotimezone|vpn|snapshot]" >&2
|
||||
exit 64 ;;
|
||||
esac
|
||||
'';
|
||||
|
||||
Reference in New Issue
Block a user