Skip to content

Monitor: report Hyprland scale and persist named outputs - #12263

Open
chessing234 wants to merge 9 commits into
omacom:quattrofrom
chessing234:fold/monitor-scale-persist
Open

chessing234 wants to merge 9 commits into
omacom:quattrofrom
chessing234:fold/monitor-scale-persist

Conversation

@chessing234

@chessing234 chessing234 commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Consolidates the monitor scaling and persistence work from #8066 and #8145. The branch updates named output rules, retains symlinked dotfiles and displays effective preset scales.

The review follow-up stages monitor and GDK edits together and atomically replaces the resolved configuration target only after every transformation succeeds. Missing rules remain distinct from processing failures. A failed parse, partial staged write, GDK edit or final rename leaves the original bytes intact and returns an error explaining that the live change was not saved. Publication preserves file mode, ownership and extended attributes, requires write access to the target directory and replaces the target inode.

Validation: 26 scaling groups and 29 monitor-model groups pass on macOS. Four injected failures preserve the original content and symlink, return failure and clean temporary files. The previous source fails the processing-error regression. The macOS GNU cp lacks xattr support, so a private adapter exercised that copy step; native Linux attribute preservation and the running desktop were not tested.

This does not resolve all review findings. Description-based/custom catchall rules, Lua block/trailing comments and separators, appended-rule layout defaults, the clamshell multiline parser, and exact compositor scale acceptance still need work and native validation. The scale model tests demonstrate current branch behavior, not independent agreement with a running Hyprland compositor.

@llstrk

llstrk commented Sep 25, 2026

Copy link
Copy Markdown

Automated AI review

Community review: Independent automated community review, unaffiliated with the Omarchy team, intended to help prepare PRs for their review.

Verified: the new two-way scale search follows Hyprland's search order, 89-step bound and give-up case, and persisting to the focused output's own hl.monitor rule fixes the reported case where the clamshell poller reverted the new scale. Six edge cases in persistence and scale arithmetic still differ from what Hyprland does; the first two affect common nwg-displays and dotfiles setups.

Case (stubbed hyprctl) Base This PR
1366x768, request 1.25 sends 2 sends 1 (Hyprland also applies 1)
Default config plus a one-line eDP-1 rule, request 1.6 only the catch-all variable changes; the poller reverts to 2 the eDP-1 rule becomes 1.6; the poller makes no call
nwg-displays multi-line file (output names) file untouched only the focused output's scale changes; the file still parses as Lua
1366x768, request 3 sends 2 refuses and leaves the file unchanged

1. The appended fallback rule overrides desc: rules and custom catch-alls

When no rule names the focused output and no Omarchy default is recognized, the script appends:

hl.monitor({ output = "DP-1", mode = "preferred", position = "auto", scale = 1.25 })

Hyprland resolves a monitor from the newest matching named or desc: rule (CMonitorRuleManager::get, v0.56.2), and a rule with a different output string starts from defaults instead of merging. With an nwg-displays file written using its "use desc" option (output = "desc:<description>"), the appended connector rule wins on the next reload:

before: desc rule   -> mode 3840x2160@60, position 0x0, scale 1.5, transform 1, bitdepth 10, vrr 1
after:  appended DP-1 rule -> mode preferred, position auto, scale 1.25 (other fields default)

The same happens against a catch-all such as output = "", mode = "highrr", bitdepth = 10.

Impact: after a reload or reboot, that monitor loses its configured mode, position, rotation, bit depth and VRR. Base left these files untouched, so only the scale was lost on reload.

Suggested change: match desc: rules against the monitor's description from hyprctl monitors -j and update that rule. Alternatively, append with the current mode and position instead of preferred/auto, and skip the append when a desc: rule could match.

2. Updating a named rule replaces a symlinked monitors.lua

update_named_monitor_scale writes a temp file next to monitors.lua and finishes with mv "$tmp" "$file", which replaces the symlink itself. The --follow-symlinks handling from the third commit only covers the sed paths.

~/.config/hypr/monitors.lua -> dotfiles/monitors.lua   (named eDP-1 rule, scale 2)
after `omarchy-hyprland-monitor-scaling 1.6`:
~/.config/hypr/monitors.lua   regular file, scale 1.6
dotfiles/monitors.lua         unchanged, scale 2

Impact: Stow-managed setups (recommended in the manual's dotfiles section) silently lose the link, and the tracked copy stops receiving changes. For nwg-displays files this is new, since base never wrote to them. The added symlink test uses a config with only the default variables, so it never reaches this path.

Suggested change: write through the link (cat "$tmp" >"$file" && rm -f "$tmp"), or create the temp file next to readlink -f "$file". Extend the symlink test to single-line and multi-line named rules.

3. Integer divisibility is not Hyprland's acceptance test

clean_scale, scale_from_current and Model.js cleanScale accept a candidate when it divides the mode exactly in integers. Hyprland computes width / (k / 120.0) in doubles and requires an exactly whole result, and some mathematically clean candidates miss by one rounding step, for example 2944 / (368/120) = 959.9999999999999. Hyprland then skips that candidate.

Mode, request Panel label / sent value Hyprland result Compared with base
2944x1840, preset 3 3.07 / 3.06667 re-snaps to 3.2 with an "Invalid scale" notification; a raw 3 gives 2.875 same on base
1600x900, CLI 2.25 sends 2.08333 re-snaps to 2.0 base sent 2.5, which Hyprland also picks for a raw 2.25
1648x927 (custom mode), request 2 1.72 / 1.71667 re-snaps to 1; a raw 2 gives 2.575 new with the two-way search

Impact: on these modes the panel label and the applied scale disagree, and some CLI requests land further from the request than on base. Across 84 realistic panel modes checked with the presets, only 2944x1840 and 3000x1875 disagree, and both disagreed on base too.

Suggested change: keep the new search, but test each candidate the way Hyprland does: w / (k / 120) and h / (k / 120) must be whole in double arithmetic, in all three places. In an isolated sweep, that one change matched a transcription of Hyprland's scale search for every on-grid request tested (presets and 0.05 steps). Optional test improvement: the hyprlandScale oracle in monitor-test.sh uses the same integer test as the code, so its sweep cannot detect this. Switching it to the double-division test makes the sweep catch these cases.

4. Inserting a missing scale after a trailing comma produces invalid Lua

For a multi-line named rule without scale, replace_scale appends , scale = X right after the last non-space character before }:

hl.monitor({
  output = "eDP-1",
  mode = "preferred",, scale = 1.6
})

Impact: luac rejects the file (unexpected symbol near ','), so on the next reload Hyprland loads no rules or GDK_SCALE from monitors.lua. The script still reports success. The shape is uncommon, since nwg-displays always writes scale, but a trailing comma is valid in hand-written Lua tables.

Suggested change: skip the separator when the previous character is already , or {, or insert scale = X, on its own line after the output line.

5. Comments are edited as if they were live rules

replace_scale only skips lines that start with --. Lines inside a --[[ ... ]] block and trailing -- ... scale = N comments are treated as config. For example, a commented-out hl.monitor({ output = "eDP-1", ... }) inside a block comment is rewritten while no active rule changes.

Impact: the script reports success, so the generic and append fallbacks are skipped and the new scale is not persisted at all. With a block comment on base, the catch-all variable was updated correctly.

Suggested change: strip line and block comments before matching in replace_scale, as has_named_output already does for line comments.

6. The clamshell poller still reverts multi-line internal rules

omarchy-hyprland-monitor-clamshell only parses one-line hl.monitor rules. With the default local omarchy_monitor_scale = 2 and a multi-line eDP-1 rule, this PR writes 1.6 into the rule, but the poller reads 2 from the variable and applies it again while an external monitor is connected.

Impact: in that configuration the new scale is reverted within about two seconds while docked. Base wrote the variable instead, so the poller agreed with it.

Suggested change: teach the poller's rule parser the multi-line form that the scaling script now writes.


Review information

Test scope: source review of the PR against Hyprland v0.56.2 (the scale search is identical in v0.53.3 to v0.55.4) and nwg-displays v0.4.4. The real scaling and clamshell scripts ran in isolated sandboxes with a stubbed hyprctl against about 25 monitors.lua shapes at head and base. Resulting files were checked with luac and with a Lua model of Hyprland's rule lookup. The changed repository tests pass at head; the JavaScript test ran under Deno rather than Node or Quickshell. No live compositor was used, so Hyprland outcomes come from source transcriptions, and layout effects after a reload were not tested.

AI process: Opus 5.5 Medium coordination and synthesis, independent Opus 5.5 Xhigh and GPT 6 Sol Xhigh technical assessments with targeted follow-up questions, Opus 5.5 Medium editorial check.

Opt out: To stop receiving these reviews, reply to this comment saying so.

mv replaced a stow-managed monitors.lua link; cat through the link keeps
the target. Also avoid a double comma when inserting a missing scale.
@chessing234

Copy link
Copy Markdown
Contributor Author

addressed the review: named-rule updates write through symlinks now, and inserting a missing scale no longer doubles a trailing comma.

@chessing234
chessing234 force-pushed the fold/monitor-scale-persist branch from 95ba8da to 3cab508 Compare September 25, 2026 15:41
@llstrk

llstrk commented Sep 27, 2026

Copy link
Copy Markdown

Automated AI review

Community review: Independent automated community review, unaffiliated with the Omarchy team, intended to help prepare PRs for their review.

Follow-up to the earlier review and the author's reply, checked at 3cab5084. The branch was rebased; the three earlier commits are unchanged, and the new commit only touches update_named_monitor_scale and its test.

Verified: both fixes in the reply work. The new write-through has one new gap when the write fails (below).

Earlier finding Status at 3cab5084
2. Named-rule update replaces a symlinked monitors.lua Resolved
4. Missing scale after a trailing comma gives invalid Lua Resolved
1. Appended fallback rule overrides desc: rules and custom catch-alls Still present, code unchanged
3. Integer divisibility is not Hyprland's acceptance test Still present, code unchanged
5. Comments are edited as if they were live rules Still present, comment handling unchanged
6. Clamshell poller reverts multi-line internal rules Still present, code unchanged

Resolved

2. Symlinks: absolute, relative and chained links to single-line and nwg-displays multi-line files all stay links, the target receives the new scale, other rules are unchanged, and no temp files are left behind. The new test fails against the previous script and passes at this head, so it guards the regression. It covers only the single-line shape.

4. Trailing comma: a multi-line or single-line rule ending in , now gets mode = "preferred", scale = 1.6 and parses with luac. A rule whose last field ends in ; (also valid Lua) still gets ;, scale = 1.6, which does not parse; this was the same before the commit and is a rare shape. Adding ; to the same check covers it.

Still present

Findings 1, 3, 5 and 6 reproduce at this head as originally described, including every number in the finding 3 table; the code behind them is identical to the earlier head (for finding 5, the new commit changed only the separator, not the comment handling). For finding 5, one more shape: when the last field line of a rule without scale ends in a comment (mode = "preferred", -- panel mode), the inserted scale = X lands inside the comment, the script reports success, and nothing is persisted. Stripping comments before matching, as suggested earlier, and before choosing the insertion point covers this too.

New: a failed write-through still reports success

update_named_monitor_scale now finishes with:

cat "$tmp" >"$file"
rm -f "$tmp"
return 0

The status of cat is ignored, the complete temp copy is always deleted, and the function returns success.

Case (stubbed hyprctl, request 1.6) This head Previous head / base
monitors.lua read-only (0444) in a writable directory Permission denied on stderr, file unchanged, other fallbacks skipped, exit 0 previous head: persisted (mv replaced the file); base: persisted through Omarchy's scale variable when present
Write fails partway (injected: 40 bytes written, then ENOSPC) monitors.lua truncated and no longer valid Lua, temp copy deleted, exit 0 previous head's mv was atomic
Link into a non-writable directory, writable target, file with only named rules temp file cannot be created, treated as "no named rule"; a second same-name rule with mode = "preferred", position = "auto" is appended and overrides the user's mode and position; exit 4 previous head replaced the link; base left the file untouched

Impact: uncommon triggers (full disk, I/O error, read-only files or directories), but the partial-write case leaves a monitors.lua that Hyprland cannot load while reporting success.

Suggested change: check the write, keep the staged copy on failure and return a code the caller treats as fatal, for example:

if ! cat "$tmp" >"$file"; then
  echo "Could not write $file; update kept in $tmp" >&2
  return 2
fi
rm -f "$tmp"

Then have set_scale stop when it returns 2. Today its if … elif chain treats any failure as "no named rule" and falls through to the variable and append paths. Also distinguish a failure to create the temp file from "no named rule" for the same reason.

Related PR: open #13142 changes the live hyprctl eval line next to this PR's changes (keeping the current position instead of auto) and rewrites the same persistence block with its own named-rule update, so whichever lands second will need to reconcile both.


Review information

Test scope: source review of the new commit and rebase against Hyprland v0.56.2 (scale search unchanged on current main) and nwg-displays v0.4.4. The real scaling and clamshell scripts ran in isolated sandboxes with a stubbed hyprctl in 20 monitors.lua scenarios at this head, the previous head and base; results were checked with luac and Lua and Python transcriptions of Hyprland's rule lookup and scale search. The disk-full case used fault injection. The changed repository tests pass at this head, with the JavaScript test under Node. No live compositor was used.

AI process: Opus 5.5 Medium coordination and synthesis, Opus 5.5 Xhigh technical review and final fact check, GPT 6 Sol Xhigh search for related issues, Opus 5.5 Medium editorial check.

Opt out: To stop receiving these reviews, reply to this comment saying so.

@greptile-apps

greptile-apps Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The changes since the previous review appear safe to merge.

Summary

Updates monitor scale choices to search nearby values and skip presets the display cannot reach.

  • Monitor scale choices now match the scales Hyprland can reach.

No new actionable issues were found since the previous review. The earlier comment-related findings no longer apply because scaling saves settings separately instead of rewriting Lua monitor rules.

Reviews (5) · Last reviewed commit: "Keep compositor-backed scale regression ..." · Reviewed by Greptile

Comment thread bin/omarchy-hyprland-monitor-scaling Resolved
Comment thread bin/omarchy-hyprland-monitor-scaling Resolved
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed at 5c10dfa. The classification is unsettled, so this PR has no class label yet and nothing was run on a worker.

Two models classified it separately and disagreed. Opus 5.5 read it as a bug: on base, omarchy-hyprland-monitor-scaling and the monitor panel round a request upward to a scale Hyprland would not have picked itself (a 1366x768 panel asked for 1.25 is sent 2, where Hyprland applies 1). On a config with a named hl.monitor rule for the output, the new scale was saved only to the catch-all variable, so the clamshell poller reverted it. Codex Medium read it as an enhancement, most likely because persisting into named and nwg-displays output rules is new behaviour the script never had. Both readings fit parts of the diff: it fixes the scale search and also adds a Lua rule rewriter and a new append fallback.

Open #13142 rewrites the same persistence block in bin/omarchy-hyprland-monitor-scaling with its own named-rule update, so whichever lands second will need to reconcile the two.

Next step: the maintainer decides whether this is a fix or a feature. Once that is settled it will be verified on a worker against quattro.

@omarchybot omarchybot added the bug Something isn't working label Nov 18, 2026
Integer divisibility accepts scales that Hyprland skips after double division. On 1600x900 a request for 2.25 was rewritten to 2.08333, reapplied as 2, and labelled 2.08, while the compositor chooses 2.5 for the original request. Use the compositor's whole-pixel check in the CLI, stepping and panel model, and cover the mismatch in the existing tests.

Co-Authored-By: GPT-6 High <[email protected]>
Co-Authored-By: Opus 5.5 High <[email protected]>
@omarchybot omarchybot added the verified Omarchy Triage has verified that this issue is ready for final review label Nov 18, 2026
The mode sweep repeats the bounded search and acceptance test used by cleanScale, so shared mistakes pass both copies. Keep the focused regressions checked against the running compositor instead of maintaining another implementation as its own oracle.

Co-Authored-By: GPT-6 High <[email protected]>
Co-Authored-By: Opus 5.5 (default effort) <[email protected]>
@omarchybot omarchybot added verified Omarchy Triage has verified that this issue is ready for final review and removed verified Omarchy Triage has verified that this issue is ready for final review labels Nov 18, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Verified the scale-search fix on an Omarchy ISO worker running Hyprland 0.57.2. At 1856×1392, requesting 1.25 applied 1.3333334 on base and 1.2083334 on this branch, matching a direct Hyprland request; restoring base brought the failure back.

Pushed 23459aeb6e3c49a8488f5c422107796b9d7d9ead to match Hyprland's floating-point acceptance check. At 1600×900, a 2.25 request now applies 2.5 instead of 2, and the panel model agrees. At 2944×1840, preset 3 applies 2.875. Removed the redundant sweep that repeated the implementation; the focused regressions tied to live compositor results remain. The CLI and focused monitor suites passed all 223 checks, including regressions that failed before the correction.

GPT-6 High in Codex reviewed this with Opus 5.5 High and muse-wonder via pi, thinking high. Their final code review found no blocking defects and agreed with the result; independence is not guaranteed. Opus 5.5 at default effort also assessed the test scope.

This is waiting on the author to update the title and body to describe the current scale-search change and add the captures below to a Screenshots section. The body still describes the removed Lua persistence rewrite, and the visual-evidence CI check requires screenshots in the body.

The captures show the scale row at the same 1856×1392 mode and scale 1; the 1.25 preset's label changes from 1.33x to 1.21x. The live command checks above establish which scale was applied.

Before: the scale row labels the 1.25 preset as 1.33x

After: the scale row labels the 1.25 preset as 1.21x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working verified Omarchy Triage has verified that this issue is ready for final review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants