Skip to content

topbar: size the clock cell and the right group from what they draw - #135

Open
kingfree wants to merge 2 commits into
Lemxy:mainfrom
kingfree:tray-spacing
Open

kingfree wants to merge 2 commits into
Lemxy:mainfrom
kingfree:tray-spacing

Conversation

@kingfree

Copy link
Copy Markdown

Fixes the spacing around the clock at the right end of the bar.

The clock cell. It was a fixed 96 px. "10:07" over "2026/11/24" sat in it with 17 px of air left and right, while the bar gave the block 5 px above and below, so the block floated and the hover pill looked like a letterbox around it. The cell is measured now from the two lines in the bar's own fonts (the same bar_fonts() the painter uses), with CLOCK_PAD (10 px) on both sides and CLOCK_MIN (72 px) so a short date like "1/1/2026" does not make it hug its edges. A locale's date widens the cell instead of being ellipsized.

The right group. layout() reserved 150 px for the language label + wifi + volume (216 with a battery) but paint() drew them in 96: the rest was a hole between the volume icon and the clock — 71 px on this machine, which runs at 200 % scaling — and a click in the hole opened the battery panel. The width is added up now from the same SYS_* slots the painter draws at, and hit() reads those slots as well.

Measured on a 3840 px wide bar at 200 % (physical pixels, ink to ink):

before after
volume icon → clock text 143 52
clock text → screen edge 46 33
air inside the clock cell, left / right 34 / 34 21 / 21

Side bar: the clock lines are drawn inside their cell instead of the whole bar width, like the bottom bar.

Tests (cargo test -p topbar, 16 pass):

  • clock_cell_fits_every_locale — the short time and short date of en-US, ru-RU, ja-JP, pt-BR and zh-CN at 200 % both fit the cell with the padding on each side, and the cell never drops below CLOCK_MIN.
  • system_group_is_as_wide_as_it_draws — the group's width equals its slots, with and without a battery.

The clock cell was a fixed 96 px, so "10:07" over "2026/11/24" got 17 px of air on both sides while the bar gave
the block 5 px above and below, and the hover pill looked like a letterbox around it. The cell is measured from the
two lines in the bar's own fonts now, the same CLOCK_PAD on both sides, with CLOCK_MIN for a short date.

The right group reserved 150 px (216 with a battery) but drew the language label, the wifi and the volume in 96:
the rest was a hole between the volume icon and the clock (71 px at 200 % here) that also opened the battery panel
on a click. Its width is added up from the SYS_* slots paint() draws at, and hit() reads the same slots.

Side bar: the clock lines are drawn inside the cell instead of the whole bar width, like the bottom bar.

Tests: the cell fits every locale's short date (en-US, ru-RU, ja-JP, pt-BR, zh-CN at 200 %), and the group's width
equals what it draws, with and without a battery.
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.

1 participant