Skip to content

Center bar labels on the ink their figures paint - #17914

Closed
serhiivinichuk wants to merge 3 commits into
omacom:quattrofrom
serhiivinichuk:bar-label-figure-centering
Closed

serhiivinichuk wants to merge 3 commits into
omacom:quattrofrom
serhiivinichuk:bar-label-figure-centering

Conversation

@serhiivinichuk

@serhiivinichuk serhiivinichuk commented Nov 6, 2026 •

Copy link
Copy Markdown

What changes

Fixes #17902.

WidgetButton centered a label's figures by the font's ascent and descent:

(labelMetrics.descent - labelMetrics.ascent + labelMetrics.tightBoundingRect("0").height) / 2

That holds only when the text item's height is exactly ascent plus descent. Qt rounds the line box up, so at the 10 px caption size the box is 14 px against 13.19 px of metrics, and the figures land 0.4 px above the middle of the box — a whole row once rasterized. At 12 px the same error is 0.09 px, which is why #14234 lined up the clock and the workspace numbers and left the caption-size keyboard layout label (EN, UA) a row above the icons beside it.

The offset now centers the figure ink where it actually paints: up from the baseline, which is the metrics' ascent for a single line, by the digit's ink box from the FontMetrics the file already had. Ascent and height are read in the same expression so the offset follows the label when its font changes — a tightBoundingRect call on its own is not a dependency QML tracks, so reading only the label's baselineOffset left the ink stale across a font change (which the test below caught once the caption size moves mid-file).

Nothing else changes: centerFigures: false (the menu logo), vertical bars and multi-line labels keep the plain line-box centering.

BarIconButton repeats the old expression for the labels beside panel and status icons (battery percentages, tray counts). Left out here: those paint at 13 px and 11 px in their own row, and this is the reported bar widget, so they want a before/after of their own.

Verification

  • test/shell.d/bar-icon-geometry-test.sh gains the label side of the same geometry: the WidgetButton at the caption size (what the keyboard layout indicator draws) and at 15 px must center their digit ink on their own line box, within 0.05 px, and a centerFigures: false label must keep the plain line-box centering. On quattro it fails with caption label figure ink centers at 12.59, its line box at 13; with the change it passes, including through the two theme rescales the file already runs.
  • ./test/shell: 421 files, 9 of which report skips for things this machine lacks (battery, Kitty, some locales, an omarchy-pkgs checkout). A handful of timing-sensitive files fail under the pool (camera, shell-idle-spawn, channel-switch, screenrecording-process, ssh-reconnect, t3code-install); re-run one at a time, only camera-test.sh still fails, on WirePlumber waits until the seat's camera opens, which it also does on the base branch — this desktop has no camera. The rest pass alone.
  • Live bar running this branch's shell, with the change and with it reverted, 2560×1440 at scale 1, default JetBrainsMono Nerd Font, kb_layout = "us,ua" so the widget draws its label: the label moves from ink rows 8–15 to 9–16 and lands on the row line of the icons beside it (12.5, the bar's middle being 13). The two captures differ in a single 10×9 region — the label itself — so the clock and the workspace numbers do not move.
  • Not checked: fractional scaling, 2× displays, other monospace fonts.

Screenshots

Live bar, this branch's shell before and after the change, 4×. The red line marks the bar's middle row:

The EN label one row above the icons, then on their row line

@greptile-apps

greptile-apps Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The PR appears safe to merge, with the existing non-blocking caption-test concern still open.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with the existing non-blocking caption-test concern still open.

Findings

  1. P2 Caption check accepts the bug ▶

Summary

Updates WidgetButton to center figure ink using the label’s height, font ascent, and digit bounds.

  • Horizontal bar labels center their painted figures in the slot.

Reviews (5) · Last reviewed commit: "Keep bar label centering covered without..." · Reviewed by Greptile

@serhiivinichuk

Copy link
Copy Markdown
Author

Checked #17878 for overlap, since it works on the same row. It corrects OpticalGlyph's ink measurement for icons only: a WidgetButton label is a plain Text centered by anchors and never goes through OpticalGlyph, so nothing here is superseded.

Measured on this machine with #17878 applied on top of quattro, against this branch without it (26 px bar, middle 13.0, default JetBrainsMono Nerd Font, the glyphs from the right of the bar):

quattro + #17878
icons (bluetooth, audio, power, elsewhen, network, monitor) 13.00 13.00 (heights move by 0.02)
EN label at the caption size 12.59 12.59

That is what #17878 reports itself — with JetBrainsMono Nerd Font the same icons measure the same before and after, except the weather icon — so on this font it moves no icon and leaves the label where it was.

They are complementary rather than overlapping: on the Nerd Font Mono variants #17878 does move icons (11.5–12.5 → 13.0), which would leave this label further off until a label-side fix lands.

@serhiivinichuk
serhiivinichuk force-pushed the bar-label-figure-centering branch from 7fdc642 to 411301d Compare November 6, 2026 16:13
@omarchybot

Copy link
Copy Markdown
Collaborator

GPT-6 in Codex (effort not exposed) read the diff, discussion, and #17902 and classified this as a bug fix. The second classifier, deepseek-v4p1-flash (effort not recorded), returned no usable classification, so classification remains unsettled. No tests ran and no code changed; this is waiting on the maintainer to resolve classification before verification continues.

@omarchybot

Copy link
Copy Markdown
Collaborator

Classification now agrees on bug. GPT-6 High in Codex read the diff, #17902, the base branch’s shell guidance, and the competing change in #19373. #19373 changes the same label-positioning code using a different measurement method; #19075 covers the separate percentage labels in BarIconButton.

No tests ran and no code changed in this session. The configured Opus 5.5 High comparison review terminated before returning a result, although the subsequent reviewer availability check succeeded. No second code review completed, so the choice between these competing fixes remains with the maintainer. This pull request remains open.

Bar geometry test removed upstream with the test suite rework, so the
branch keeps only the WidgetButton change.
Upstream removed bar-icon-geometry-test.sh with the test suite rework, so
measure the label on its own: digits center on their ink, and the offset
follows the label when its font changes.
return
}
var center = inkCenter(button, label)
if (Math.abs(center - button.height / 2) > 0.5) {

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.

P2 Caption check accepts the bug

The reported old position, 12.59375 against a middle of 13, differs by only 0.40625, so it passes this 0.5 threshold. The caption check therefore accepts the misalignment this PR fixes.

AGENTS.md requires a regression test to fail without the fix. Before merging, tighten the figure check to the stated 0.05 tolerance and check that reverting the offset makes the caption check fail.

File Used: AGENTS.md (source)

@serhiivinichuk

Copy link
Copy Markdown
Author

Closing in favour of #19373, which puts the figures on the bar's middle exactly where this branch only halves the error.

Measured the production WidgetButton on the merged head against quattro (26 px bar, middle 13.0, JetBrainsMono Nerd Font, ink read from a 100× TextMetrics so whole-pixel rounding does not hide it). Positive is low, negative is high:

label size quattro this branch
10 +0.44 −0.15
11 +0.24 −0.52
12 (caption, keyboard layout) +0.53 −0.38
13 +0.33 −0.25
14 +0.12 −0.61
18 +0.81 −0.07

The bug is still there on quattro, so a fix is still needed — this one just is not tight enough. Two residuals remain, and Greptile's latest P2 on bar-label-centering/shell.qml points at the same thing:

  • tightBoundingRect("0") is whole-pixel rounded at bar sizes (10 px of ink for 9 at size 12), so the offset over-corrects and the label ends up high by about as much as it was low — worse than quattro at 14 px.
  • anchors.centerIn snaps an odd-height label up half a pixel (sizes 11 and 14), which is why a 0.5 threshold passes while the label is still visibly off.

The 0.05 tolerance the review asks for cannot pass without changing the placement, which is what #19373 does (label placed by y, figures measured with a 100× TextMetrics as OpticalGlyph already does). Measured the same way, that approach is 0 at every size above, and it also covers BarIconButton percentage labels and fractional scales, which this branch does not.

One thing worth keeping: #19904 deleted test/shell.d/bar-icon-geometry-test.sh, so the coverage I ported to test/shell.d/fixtures/bar-label-centering/ with its run_qml_fixture wrapper is a starting point for #19373's test once it is rebased.

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

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bar labels at caption size sit 1 px high: keyboard layout indicator is off the icon line

2 participants