[GH-ISSUE #1049] truncate.length doesn't seem to work #3142

Closed
opened 2026-05-22 23:54:15 +01:00 by JakeStanger · 6 comments
Owner

Originally created by @postsolar on GitHub (Jun 14, 2025).
Original GitHub issue: https://github.com/JakeStanger/ironbar/issues/1049

Describe the bug

From the wiki on truncate.length:

The fixed width (in chars) of the widget. Leave blank to let GTK automatically handle.

But it doesn't appear to work this way. Maybe there's something else involved? My widgets' labels just don't get truncated with this setting. truncate.max_length works but truncate.length does not, regardless of label's pre-truncate length. I tried different modules, focused, music.

To reproduce
Steps to reproduce the behavior:

{
  "start": [
    {
      "type": "focused",
      "truncate": {
        "length": 5,
        "mode": "start"
      }
    }
  ]
}
  1. Use config above
  2. Observe truncation is broken

Expected behavior

Truncate works and widget has fixed width as specified in the config

System information:

  • Distro: NixOS
  • Compositor: Hyprland
  • Ironbar version: 4fad5a4d18

Configuration

Config

Styles

Additional context

Screenshots

With truncate.length = 5 and truncate.mode = "start":

Image

Originally created by @postsolar on GitHub (Jun 14, 2025). Original GitHub issue: https://github.com/JakeStanger/ironbar/issues/1049 **Describe the bug** <!-- A clear and concise description of what the bug is. --> From the wiki on `truncate.length`: > The fixed width (in chars) of the widget. Leave blank to let GTK automatically handle. But it doesn't appear to work this way. Maybe there's something else involved? My widgets' labels just don't get truncated with this setting. `truncate.max_length` works but `truncate.length` does not, regardless of label's pre-truncate length. I tried different modules, `focused`, `music`. **To reproduce** Steps to reproduce the behavior: ```json { "start": [ { "type": "focused", "truncate": { "length": 5, "mode": "start" } } ] } ``` 1. Use config above 2. Observe truncation is broken **Expected behavior** <!-- A clear and concise description of what you expected to happen. --> Truncate works and widget has fixed width as specified in the config **System information:** - Distro: NixOS - Compositor: Hyprland - Ironbar version: 4fad5a4d185d6d5c3d450cc385e854dfc59fc545 **Configuration** <!-- Share your bar configuration and stylesheet as applicable: --> <details><summary>Config</summary> ``` ``` </details> <details><summary>Styles</summary> ```css ``` </details> **Additional context** <!-- Add any other context about the problem here. --> **Screenshots** <!-- If applicable, add screenshots to help explain your problem. --> With `truncate.length = 5` and `truncate.mode = "start"`: ![Image](https://github.com/user-attachments/assets/76bf0736-5645-4a68-a478-52cb651d9377)
JakeStanger 2026-05-22 23:54:15 +01:00
Author
Owner

@JakeStanger commented on GitHub (Jun 16, 2025):

I suspect this is more of an issue of the docs not being very clear than anything else.

The truncate.length property works more akin to a minimum, so its much less useful than the max_length property. Under the hood it calls set_width_chars. From the GTK docs:

Changes the size request of the entry to be about the right size for n_chars characters. Note that it changes the size request, the size can still be affected by how you pack the widget into containers. If n_chars is -1, the size reverts to the default entry size.

https://docs.gtk.org/gtk3/method.Entry.set_width_chars.html

Note that the two aren't mutually exclusive:

github.com/JakeStanger/ironbar@ff9f4477bb/src/gtk_helpers.rs (L107-L117)

<!-- gh-comment-id:2975872178 --> @JakeStanger commented on GitHub (Jun 16, 2025): I suspect this is more of an issue of the docs not being very clear than anything else. The `truncate.length` property works more akin to a minimum, so its much less useful than the `max_length` property. Under the hood it calls `set_width_chars`. From the GTK docs: > Changes the size request of the entry to be about the right size for n_chars characters. Note that it changes the size request, the size can still be affected by how you pack the widget into containers. If n_chars is -1, the size reverts to the default entry size. <https://docs.gtk.org/gtk3/method.Entry.set_width_chars.html> Note that the two aren't mutually exclusive: https://github.com/JakeStanger/ironbar/blob/ff9f4477bb4573c38bae27ad8642c3883172d0ff/src/gtk_helpers.rs#L107-L117
Author
Owner

@postsolar commented on GitHub (Jun 17, 2025):

Thank you for clarifying. I also just noticed that for clipboard I'd have to also set length to some number, otherwise it truncates at just 1 char regardless of max_length being much higher:

{ "type": "clipboard", "truncate": { "mode": "end", "max_length": 100 } }

— truncates to just 1 char

{ "type": "clipboard", "truncate": { "mode": "end", "max_length": 100, "length": 10 } }

— truncates to ~10 chars

But for label, length doesn't work this way.

<!-- gh-comment-id:2978842751 --> @postsolar commented on GitHub (Jun 17, 2025): Thank you for clarifying. I also just noticed that for `clipboard` I'd have to also set `length` to some number, otherwise it truncates at just 1 char regardless of `max_length` being much higher: ``` { "type": "clipboard", "truncate": { "mode": "end", "max_length": 100 } } ``` — truncates to just 1 char ``` { "type": "clipboard", "truncate": { "mode": "end", "max_length": 100, "length": 10 } } ``` — truncates to ~10 chars But for `label`, `length` doesn't work this way.
Author
Owner

@postsolar commented on GitHub (Jun 18, 2025):

In case of music.truncate_popup_title this is all also quite confusing, not obvious how to set it up the preferred way:

  • max_length = 60: title gets truncated regardless of its length, even if it's shorter than 60 chars.
  • length = 60: title only gets truncated if it's ≥60 chars, good. But an issue here is that it's also centered which results in this:

Image

Not good looking. Apparently this can't be fixed with GTK3 CSS. Maybe we could hardcode left alignment and then remove it in GTK4 branch? Or maybe there's something lower-level that could be addressed? What do you think @JakeStanger ?

<!-- gh-comment-id:2984093350 --> @postsolar commented on GitHub (Jun 18, 2025): In case of `music.truncate_popup_title` this is all also quite confusing, not obvious how to set it up the preferred way: - `max_length = 60`: title gets truncated regardless of its length, even if it's shorter than 60 chars. - `length = 60`: title only gets truncated if it's ≥60 chars, good. But an issue here is that it's also centered which results in this: ![Image](https://github.com/user-attachments/assets/f225833e-65b6-473d-8266-29761f2726d1) Not good looking. Apparently this can't be fixed with GTK3 CSS. Maybe we could hardcode left alignment and then remove it in GTK4 branch? Or maybe there's something lower-level that could be addressed? What do you think @JakeStanger ?
Author
Owner

@postsolar commented on GitHub (Jun 18, 2025):

I suspect length and max_length work differently depending on whether it's a widget or a popup (which follows from your quoting of GTK docs). But I'm yet to hammer it home how exactly it works.

<!-- gh-comment-id:2984123751 --> @postsolar commented on GitHub (Jun 18, 2025): I suspect `length` and `max_length` work differently depending on whether it's a widget or a popup (which follows from your quoting of GTK docs). But I'm yet to hammer it home how exactly it works.
Author
Owner

@JakeStanger commented on GitHub (Jun 18, 2025):

I'm not able to check right now, but if I were to hazard a guess, I would assume it's got something to do with how GTK is packing the widgets. For example I think the volume slider container is actually set to expand to ensure it gets sufficient width, which is possibly pushing back on the labels when they're set to truncate. Alignment might help that, I don't know?

The difference between a bar widget and popup shouldn't be any more than that, at least.

If none of that holds up, perhaps we could look at adding a max_length_naive that doesn't use the GTK truncation system and just trims the string.

<!-- gh-comment-id:2984141331 --> @JakeStanger commented on GitHub (Jun 18, 2025): I'm not able to check right now, but if I were to hazard a guess, I would assume it's got something to do with how GTK is packing the widgets. For example I think the volume slider container is actually set to expand to ensure it gets sufficient width, which is possibly pushing back on the labels when they're set to truncate. Alignment might help that, I don't know? The difference between a bar widget and popup shouldn't be any more than that, at least. If none of that holds up, perhaps we could look at adding a `max_length_naive` that doesn't use the GTK truncation system and just trims the string.
Author
Owner

@postsolar commented on GitHub (Jun 24, 2025):

Summing this up, I think my personal issue was just max_length not working as expected, specifically within popups. This seems to be due to certain popups defaulting to a certain width. Setting min-width in the stylesheet fixes this, and popups' initial width is perhaps a different issue.

<!-- gh-comment-id:3000310007 --> @postsolar commented on GitHub (Jun 24, 2025): Summing this up, I think my personal issue was just `max_length` not working as expected, specifically within popups. This seems to be due to certain popups defaulting to a certain width. Setting `min-width` in the stylesheet fixes this, and popups' initial width is perhaps a different issue.
Sign in to join this conversation.
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
JakeStanger/ironbar#3142
No description provided.