Skip to content

Report the display scale Hyprland applies, not the next one up - #8066

Closed
chessing234 wants to merge 2 commits into
omacom:quattrofrom
chessing234:fix/monitor-scale-matches-hyprland
Closed

chessing234 wants to merge 2 commits into
omacom:quattrofrom
chessing234:fix/monitor-scale-matches-hyprland

Conversation

@chessing234

Copy link
Copy Markdown
Contributor

The Display panel and the compositor disagree about what a chosen scale actually becomes, on ordinary laptop panels.

Model.cleanScale snaps a requested scale to one that divides the mode evenly, but it only ever searched upward, and without a bound:

if (scaleUnits > divisor) scaleUnits = divisor
while (divisor % scaleUnits !== 0) scaleUnits++

Hyprland rounds the request to 1/120 units and, when the logical size is not whole, steps outward — one up, one down, at each distance, up to 89 steps — taking the first scale that divides the mode evenly, and gives up if none does (CMonitor::applyMonitorRule, src/output/Monitor.cpp):

for (size_t i = 1; i < 90; ++i) {
    double scaleUp   = (searchScale + i) / 120.0;
    double scaleDown = (searchScale - i) / 120.0;
    ...
    if (logicalUp   == logicalUp.round())   { found = true; searchScale = scaleUp;   break; }
    if (logicalDown == logicalDown.round()) { found = true; searchScale = scaleDown; break; }
}

So whenever the nearest clean scale is below the request, the panel names a number the compositor never applies.

What that costs

Display Requested Panel said Hyprland applies
1366x768 1.25 2 1
2256x1504 (Framework 13) 1.25 1.33 1.18
3024x1964 (MacBook Pro 14) 1.6 2 1.33
1920x1080 1.75 2 1.67

matchingScaleIndex compares the current scale against these numbers, so on exactly those displays the panel also highlights the wrong preset.

Hyprland additionally gives up rather than reaching further, falling back to the display's default scale with an error overlay. cleanScale had no such case — it always returned something, because clamping to the gcd guarantees a hit. It now returns "" there, and availableScales drops the preset: offering a scale that lands somewhere the panel cannot name is worse than not offering it.

Verification

The equivalence that makes this testable with integers: pixelSize / scale is whole exactly when the scale in 1/120 units divides both mode dimensions in the same units — which is what the existing gcd already tests. That also avoids Hyprland's float division, where a scale like 1.6 can miss by an ulp.

monitor-test.sh now checks against a transcription of Hyprland's own search rather than a table of remembered answers, sweeping 400+ mode and request combinations. That is what caught that an existing expectation was already wrong: cleanScale(1.25, 6016, 3384) was recorded as 1.33, where Hyprland applies 1.18. That assertion is corrected here.

Locally the same oracle over 11,043 combinations (widths 640–4096 across four aspect ratios, nine requested scales) reports zero mismatches. monitor-scaling-test, monitor-clamshell-scale-test and monitor-state-test still pass; monitor-modeless-test fails identically on quattro in this checkout and is untouched by this change.

Not run: no Hyprland here, so the panel was never opened and no real monitor was rescaled — the evidence is the compositor's source and the sweep above, not a running session.

Copilot AI balanced review requested due to automatic review settings August 24, 2026 15:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates monitor-scale prediction to mirror Hyprland’s bounded bidirectional search.

Changes:

  • Searches upward and downward for valid scales.
  • Filters unreachable presets.
  • Adds regression and sweep tests.

Tip

If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
shell/plugins/panels/monitor/Model.js Implements revised scale prediction and filtering.
test/shell.d/monitor-test.sh Adds scale-search regression coverage.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +49 to +52
for (var step = 1; step < 90; step++) {
if (divisor % (scaleUnits + step) === 0) return normalizeScale((scaleUnits + step) / 120)
if (scaleUnits - step > 0 && divisor % (scaleUnits - step) === 0)
return normalizeScale((scaleUnits - step) / 120)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

helper uses the same bounded bidirectional search now, so the preset the panel shows is what hyprctl actually gets.

@chessing234

Copy link
Copy Markdown
Contributor Author

good catch, and it is worse than a gap — correcting only the label left the two layers further apart than they started. the panel now says 1366x768 at 1.25 lands on 1 while the helper rewrites that request to 2 before hyprctl sees it.

i had checked Model.js against the compositor and missed that set_scale sends clean_scale's output rather than the request, so the helper is the authority on what actually gets applied. there are two copies of the rule in there, clean_scale and scale_from_current's clean(); both now do the same bounded bidirectional search, and an unreachable preset drops out of the up/down rotation the way it drops out of the offered list.

one thing your note did not cover that follows from it: with the bound in place there are now requests with no answer, and the old code could not refuse — clamping to the gcd always found something. set_scale now fails and applies nothing rather than sending an unrelated scale, since Hyprland's own behaviour there is to fall back to the display default.

monitor-scaling-test.sh is at 16 assertions. one existing expectation changed with it: 6016x3384 at 1.25 was recorded as 1.33333 and is 1.175. added a table checking the applied value on the four displays from the PR table, plus the refusal case asserting nothing is written to hyprctl or monitors.lua. reverting only the helper fails it; monitor-test, monitor-clamshell-scale-test and monitor-state-test still pass.

cleanScale searched upward only, and without a bound, so the panel named a
scale the compositor never applies. Hyprland rounds the request to 1/120
units and, when the logical size is not whole, steps outward -- one up, one
down, up to 89 steps -- taking the first scale that divides the mode evenly
(CMonitor::applyMonitorRule).

The gap is not small on ordinary hardware. A 1366x768 panel asked for 1.25
read as 2 here while Hyprland applies 1. A 2256x1504 Framework display read
as 1.33 against Hyprland's 1.18, and a 3024x1964 MacBook asked for 1.6 read
as 2 against 1.33. matchingScaleIndex compares against these numbers, so the
selected preset was wrong on exactly those displays.

Hyprland also gives up rather than reaching further, falling back to the
default scale. Return "" there and drop the preset from the offered list: a
preset that lands somewhere the panel cannot name is worse than one absent.

Test it against a transcription of Hyprland's own search rather than a table
of remembered answers -- 400+ mode and request combinations, which is what
caught that 1.25 on a 6016x3384 display was already recorded wrong.
omarchy-hyprland-monitor-scaling carries the same snapping rule twice more,
in clean_scale and in scale_from_current, and set_scale sends its result to
hyprctl rather than the request -- so the helper, not the compositor, decides
what gets applied. Correcting only the panel's label left the two further
apart than before: the panel now says a 1366x768 display asked for 1.25 lands
on 1, while the helper still rewrites that request to 2 on the way out.

Give both copies the same bounded bidirectional search, and drop a preset
from the up/down rotation when the mode cannot reach it, the way the panel
now drops it from the offered list.

Refuse rather than guess when nothing is near enough. Hyprland gives up after
89 steps and falls back to the display default; sending an unrelated scale
instead would move the display somewhere nobody asked for, and the old code
could not refuse at all because clamping to the gcd always found something.
@chessing234
chessing234 force-pushed the fix/monitor-scale-matches-hyprland branch from 6b8ce64 to 29c06f5 Compare August 26, 2026 12:56
@chessing234

Copy link
Copy Markdown
Contributor Author

@dhh @ryanrhughes ready for review

@chessing234

Copy link
Copy Markdown
Contributor Author

folded into #12263 for easier review.

chessing234 added a commit to chessing234/omarchy that referenced this pull request Sep 25, 2026
chessing234 added a commit to chessing234/omarchy that referenced this pull request Sep 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants