mirror of
https://github.com/JakeStanger/ironbar.git
synced 2026-07-11 07:15:19 +01:00
[GH-ISSUE #415] Dynamic class names #5764
Labels
No labels
A:Build
A:CI
A:Client
A:Config
A:Core
A:Documentation
A:Documentation
A:IPC
A:Testing
A:UX/UI
blocked
BREAKING CHANGE
duplicate
good first issue
GTK4
help wanted
invalid
M:Battery
M:Battery
M:Bindmode
M:Bluetooth
M:Brightness
M:Cairo
M:Clipboard
M:Clock
M:Clock
M:Custom
M:Focused
M:Keyboard
M:Launcher
M:Menu
M:Music
M:Music
M:Music
M:Network Manager
M:Notifications
M:SysInfo
M:Tray
M:Volume
M:Workspaces
partially resolved
P:Critical
P:High
P:Low
P:Medium
pull-request
T:Bug
T:Bug
T:Core Enhancement
T:Module Enhancement
T:New Module
T:Question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
JakeStanger/ironbar#5764
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @izelnakri on GitHub (Jan 24, 2024).
Original GitHub issue: https://github.com/JakeStanger/ironbar/issues/415
Problem statement: As a user I'd like style my battery module when it's charging(or not) and the battery levels. Same dynamic styling is needed for disk usage, cpu, memory etc.
In waybar I could create a module with different states for different css class name styling.
For example in config.json:
This allows me in waybar to style different states via:
How can I go about implementing this in ironbar?
One not-so-ideal solution I found is to create different modules with
type: customand has differentshow_ifs andclassattributes. However this solution is very verbose and requires me to create bash scripts(I think?). I'm not even sure how to accomplish this with Pango markup, could you provide an example for this scenario in the documentation?Basically I think we need:
statesoption object & assignments fortype: customand have it documented, or make theclassvalueDynamic String, even then I'm not sure how to add these classes dynamically on same bash(?) script check?. I'm also not sure how I can create conditionals in Pango markup. I found Pango markup documentation to be insufficient to say the least 😅show_ifsolution is the only way to go(?). It would be great if we can put a basic example in the documentation for a battery level + charging states custom css classes assignment/change.Modules for ironbar.@JakeStanger commented on GitHub (Jan 24, 2024):
Thanks for the detailed issue. It sounds like there's a few things nested into one here.
As it stands:
This is not currently achievable natively, and does require some external scripting, but there are ways of doing it with a single
scriptorlabelmodule.Pango markup is akin to HTML, and lets you set some basic attributes on a span. This means it does give you some styling control. For example,
<span color="red">hello</span>will work. The entire spec can be found here.You could output the entire markup from an external script directly (doesn't have to be bash, just needs to write to stdout), or use a l
abelalong with theironvarfeature.For example with ironvars:
And then you'd have a script call
ironbar set battery-colorandironbar set battery-percent.Alternatively you can use
<span color='{{my_script.sh}}'>to call a script directly.The future:
I think there is a clear need for improvement to this, so I'm open to implementing additional functionality. I have never been a big fan of the
statemodel in waybar as it never felt very intuitive to me. It may be that this ends up being the best way to go, but I think this is a long-term goal that requires some planning.Making the
classoption a dynamic string feels like a no-brainer to get a quick win. This would still require some external scripting as it stands, but would allow for this to be achieved via the native modules at least.The documentation requests I'd consider separate to this issue, and there's two there. I'd ask that separate issues are opened for each so they can be individually tracked:
@izelnakri commented on GitHub (Jan 25, 2024):
Hi again @JakeStanger
I tried your two suggestions and there is a pango parser bug with
"<span color='#battery-color'>#battery-percent</span>"the parser tries to output the markup before reading the variable inside thecolorattribute, even whenironvar_defaultsdeclared on the top level, the .textContent area with ironvars work correctly.This solution works, and its fantastic, because it allows me to run even deno scripts via
#!/usr/bin/env -S deno run --allow-envso sky is the limit ;)@JakeStanger commented on GitHub (Jan 25, 2024):
Glad to hear you found a working solution! If you get a chance, could you log the pango bug separately please and I'll investigate that as part of the next release?
@izelnakri commented on GitHub (Jan 25, 2024):
Added the issue here: https://github.com/JakeStanger/ironbar/issues/418
@azertyfun commented on GitHub (Sep 11, 2025):
Hi! I might be interested in helping out with this. I'm not entirely satisfied by the work-around of
<span color="{{ script }}">because it does not allow me to re-use my CSS variables (e.g.@blue), so I unfortunately have to make my script aware of my ironbar theme.@JakeStanger I haven't yet looked into the code base but what do you reckon would be easiest to get working?
end.bar.classinto a Dynamic String:classas an attribute for<span>(currently I getAttribute 'class' is not allowed on the <span> tag)EDIT: Oh, I just realized that
background-coloris not supported as an attribute for<span>either. That leads me to believe the first solution would probably be best.@JakeStanger commented on GitHub (Sep 11, 2025):
The
<span>element is provided by Pango, which is baked into GTK, so there's no changing that.Dynamic strings would be possible to implement without too much work (you'd just need a bit of logic to split the string and add/remove class names on update). They'd also provide Ironvar support.
In case you missed it, it's also now possible to add/remove classes using the
ironbar styleIPC/CLI commands.@azertyfun commented on GitHub (Sep 11, 2025):
Indeed I noticed that after making my comment. It's already a bit more elegant, though it is a bit weird that I have to set
my-classfor all custom modules, then discriminate with.my-custom.my-class. Oh well, it works well enough for my use-case.Thanks!