Repository navigation
Report the display scale Hyprland applies, not the next one up - #8066
chessing234 wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
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.
| 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) |
There was a problem hiding this comment.
helper uses the same bounded bidirectional search now, so the preset the panel shows is what hyprctl actually gets.
|
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 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.
|
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.
6b8ce64 to
29c06f5
Compare
|
@dhh @ryanrhughes ready for review |
|
folded into #12263 for easier review. |
The Display panel and the compositor disagree about what a chosen scale actually becomes, on ordinary laptop panels.
Model.cleanScalesnaps a requested scale to one that divides the mode evenly, but it only ever searched upward, and without a bound: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):So whenever the nearest clean scale is below the request, the panel names a number the compositor never applies.
What that costs
matchingScaleIndexcompares 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.
cleanScalehad no such case — it always returned something, because clamping to the gcd guarantees a hit. It now returns""there, andavailableScalesdrops 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 / scaleis whole exactly when the scale in 1/120 units divides both mode dimensions in the same units — which is what the existinggcdalready tests. That also avoids Hyprland's float division, where a scale like 1.6 can miss by an ulp.monitor-test.shnow 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 as1.33, where Hyprland applies1.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-testandmonitor-state-teststill pass;monitor-modeless-testfails identically onquattroin 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.