Tray menu: more room between item labels and the submenu chevron #3

Closed
opened 2026-11-28 23:03:57 +00:00 by jfro · 1 comment
Owner

In the tray menu, container/project items sit right up against the submenu chevron; it's a bit too cozy.

The menu is drawn by the desktop's tray host over DBusMenu (ksni, src/tray.rs), so first find out what the app can control (label padding, a trailing spacer, item properties) versus what the host decides. Pick the least hacky fix that looks right on KDE Plasma and doesn't look wrong on other hosts.

Done when there's visible breathing room before the chevron, with before/after screenshots in the PR, or a short write-up of why it can't be done from the app.

In the tray menu, container/project items sit right up against the submenu chevron; it's a bit too cozy. The menu is drawn by the desktop's tray host over DBusMenu (`ksni`, `src/tray.rs`), so first find out what the app can control (label padding, a trailing spacer, item properties) versus what the host decides. Pick the least hacky fix that looks right on KDE Plasma and doesn't look wrong on other hosts. **Done when** there's visible breathing room before the chevron, with before/after screenshots in the PR, or a short write-up of why it can't be done from the app.
Author
Owner

Posted by Upper Wolfjaw for Nye, whose token can't comment here.

Research: room before the submenu chevron (Nye)

Short version: Krane can't set spacing. The tray host draws the menu. The fix that works on every host is to pad submenu labels with trailing spaces. I measured it on Qt/Breeze and GTK3, and the exact change is below.

What the app controls

  • DBusMenu items have only these properties: type, label, enabled, visible, icon-name, icon-data, shortcut, toggle-type, toggle-state, children-display, disposition and accessible-desc. None of them sets width, padding or spacing (libdbusmenu constants).
  • ksni 0.3.3 sends label through unchanged (src/menu.rs, no trimming).
  • So the only thing Krane controls is the label text, plus the item structure.

What the hosts draw

  • KDE Plasma: libdbusmenu-qt turns the menu into a QMenu with action->setText(label). The only change it makes is _→&, and it doesn't trim (dbusmenuimporter.cpp). Breeze sizes the column from the widest label and puts the arrow in a 20px box right after it (MenuButton_IndicatorWidth 20, MenuItem_ItemSpacing 2 in breezemetrics.h). I measured the gap on the widest item at 16px, which is why it feels cozy. Shorter labels have plenty of room.
  • XFCE panel and waybar: both use libdbusmenu-gtk3, which makes a GtkMenu (sn-item.c, Waybar item.cpp). Adwaita puts the arrow 10px after the label (menu menuitem arrow { margin-left: 10px }, gtk-contained.css). The theme decides that gap.
  • GNOME (AppIndicator extension): it builds PopupSubMenuMenuItems (dbusMenu.js). These are inline expanders whose arrow is pinned to the right edge of the whole menu. Labels aren't trimmed, and it strips only the first _.

Measured: do trailing spaces count?

I checked this on Qt 6.8.2 (PyQt6, Breeze and Fusion styles) and GTK 3.24 on this Debian box. The test is one submenu item labelled postgres-database:

Label suffix Breeze menu width GTK3 item width
none 154 155
3 ASCII spaces 166 (+12) 167 (+12)
3 NBSP 166 167
1 em space 166 159

Both toolkits count trailing whitespace. NBSP and em space are no better than plain spaces, and em space is inconsistent on GTK. On a Krane-like menu in Breeze, 4 trailing spaces take the label→chevron gap from 16px to 31px (screenshot attached).

Pad the three SubMenu labels in src/tray.rs (Stopped · N, compose project, container) and leave StandardItems alone:

/// DBusMenu has no spacing property and tray hosts put the submenu chevron right after
/// the widest label (Breeze leaves ~16px), so submenu labels get trailing spaces that
/// Qt and GTK both measure: ~15px more room on Plasma, ~16px on GTK hosts.
const SUBMENU_LABEL_PAD: &str = "    ";

fn submenu_label(label: impl Into<String>) -> String {
    let mut label = label.into();
    label.push_str(SUBMENU_LABEL_PAD);
    label
}

Then use label: submenu_label(format!("Stopped · {}", total - running_count)), label: submenu_label(project) and label: submenu_label(name). This is a 14+/3− patch. It's on my local branch nye/tray-chevron-spacing (ab8db56), and @UpperWolfjaw has the patch file. I haven't compiled it here yet because Qt dev isn't installed, but rustfmt parses it.

Where it could look off

  • GNOME AppIndicator: the arrow is right-aligned across the whole menu, so the padding only makes the menu about 15px wider. It's harmless, but there it does nothing.
  • Screen readers may read the label with trailing spaces. That should be inaudible in practice.
  • Other items don't get extra width. The menu just grows by the padding on its widest row.

Noticed while here (separate)

Labels go through mnemonic handling on every host (_→& in Qt, first _ dropped on GNOME). A container or project named my_app will likely show as myapp with an underlined a. Escaping with label.replace('_', "__") in submenu_label and the header_item image/id labels would fix that. I haven't verified it on a live host yet, so it's worth a quick look when this lands.

Breeze before/after

_Posted by Upper Wolfjaw for Nye, whose token can't comment here._ ## Research: room before the submenu chevron (Nye) **Short version:** Krane can't set spacing. The tray host draws the menu. The fix that works on every host is to pad submenu labels with trailing spaces. I measured it on Qt/Breeze and GTK3, and the exact change is below. ### What the app controls - DBusMenu items have only these properties: `type`, `label`, `enabled`, `visible`, `icon-name`, `icon-data`, `shortcut`, `toggle-type`, `toggle-state`, `children-display`, `disposition` and `accessible-desc`. None of them sets width, padding or spacing ([libdbusmenu constants](https://lazka.github.io/pgi-docs/Dbusmenu-0.4/constants.html)). - ksni 0.3.3 sends `label` through unchanged (`src/menu.rs`, no trimming). - So the only thing Krane controls is the label text, plus the item structure. ### What the hosts draw - **KDE Plasma:** libdbusmenu-qt turns the menu into a `QMenu` with `action->setText(label)`. The only change it makes is `_`→`&`, and it doesn't trim ([dbusmenuimporter.cpp](https://sources.debian.org/src/libdbusmenu-qt/0.9.3+16.04.20160218-2/src/dbusmenuimporter.cpp/)). Breeze sizes the column from the widest label and puts the arrow in a 20px box right after it (`MenuButton_IndicatorWidth` 20, `MenuItem_ItemSpacing` 2 in [breezemetrics.h](https://github.com/KDE/breeze/blob/master/kstyle/breezemetrics.h)). I measured the gap on the widest item at **16px**, which is why it feels cozy. Shorter labels have plenty of room. - **XFCE panel and waybar:** both use libdbusmenu-gtk3, which makes a `GtkMenu` ([sn-item.c](https://gitlab.xfce.org/xfce/xfce4-panel/-/raw/master/plugins/systray/sn-item.c), [Waybar item.cpp](https://github.com/Alexays/Waybar/blob/master/src/modules/sni/item.cpp)). Adwaita puts the arrow 10px after the label (`menu menuitem arrow { margin-left: 10px }`, [gtk-contained.css](https://github.com/GNOME/gtk/blob/gtk-3-24/gtk/theme/Adwaita/gtk-contained.css)). The theme decides that gap. - **GNOME (AppIndicator extension):** it builds `PopupSubMenuMenuItem`s ([dbusMenu.js](https://github.com/ubuntu/gnome-shell-extension-appindicator/blob/master/dbusMenu.js)). These are inline expanders whose arrow is pinned to the right edge of the whole menu. Labels aren't trimmed, and it strips only the first `_`. ### Measured: do trailing spaces count? I checked this on Qt 6.8.2 (PyQt6, Breeze and Fusion styles) and GTK 3.24 on this Debian box. The test is one submenu item labelled `postgres-database`: | Label suffix | Breeze menu width | GTK3 item width | |---|---|---| | none | 154 | 155 | | 3 ASCII spaces | 166 (+12) | 167 (+12) | | 3 NBSP | 166 | 167 | | 1 em space | 166 | 159 | Both toolkits count trailing whitespace. NBSP and em space are no better than plain spaces, and em space is inconsistent on GTK. On a Krane-like menu in Breeze, **4 trailing spaces take the label→chevron gap from 16px to 31px** (screenshot attached). ### Recommended fix Pad the three `SubMenu` labels in `src/tray.rs` (Stopped · N, compose project, container) and leave `StandardItem`s alone: ```rust /// DBusMenu has no spacing property and tray hosts put the submenu chevron right after /// the widest label (Breeze leaves ~16px), so submenu labels get trailing spaces that /// Qt and GTK both measure: ~15px more room on Plasma, ~16px on GTK hosts. const SUBMENU_LABEL_PAD: &str = " "; fn submenu_label(label: impl Into<String>) -> String { let mut label = label.into(); label.push_str(SUBMENU_LABEL_PAD); label } ``` Then use `label: submenu_label(format!("Stopped · {}", total - running_count))`, `label: submenu_label(project)` and `label: submenu_label(name)`. This is a 14+/3− patch. It's on my local branch `nye/tray-chevron-spacing` (ab8db56), and @UpperWolfjaw has the patch file. I haven't compiled it here yet because Qt dev isn't installed, but rustfmt parses it. ### Where it could look off - **GNOME AppIndicator:** the arrow is right-aligned across the whole menu, so the padding only makes the menu about 15px wider. It's harmless, but there it does nothing. - **Screen readers** may read the label with trailing spaces. That should be inaudible in practice. - Other items don't get extra width. The menu just grows by the padding on its widest row. ### Noticed while here (separate) Labels go through mnemonic handling on every host (`_`→`&` in Qt, first `_` dropped on GNOME). A container or project named `my_app` will likely show as `myapp` with an underlined `a`. Escaping with `label.replace('_', "__")` in `submenu_label` and the `header_item` image/id labels would fix that. I haven't verified it on a live host yet, so it's worth a quick look when this lands. ![Breeze before/after](https://git.knope.dev/attachments/2a67cda7-7d45-4007-9212-818f0d5c048e)
jfro closed this issue 2026-11-29 00:39:36 +00:00
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
jfro/krane#3
No description provided.