feat (clock): Add support for optional CSS classes to the clock module's calendar tooltip#4896
Open
nickjj wants to merge 2 commits intoAlexays:masterfrom
Open
feat (clock): Add support for optional CSS classes to the clock module's calendar tooltip#4896nickjj wants to merge 2 commits intoAlexays:masterfrom
nickjj wants to merge 2 commits intoAlexays:masterfrom
Conversation
Replace the inner loop with regex_replace. We're already using this elsewhere and the performance difference isn't worth the loss of human readability. Use static const to pre-calc the search string.
This was referenced Mar 21, 2026
Author
|
@Alexays sorry for the ping but any chance this can get reviewed? I'd like to retire my custom fork of Waybar if we can get this merged. It solves quite a few open issues and is a quality of life win for folks who want to theme Waybar's clock. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
NOTE: I've never written a line of C++ in my life. I used a combination of looking at the existing source code and Google's ask AI. I'd like to think this isn't pure AI slop as I thought through the problem and scope of the problem ahead of time. I only used AI to help me understand the C++ syntax. The diff is pretty small.
This fixes #3686 and addresses #4787.
Feature
The clock's calendar doesn't support CSS classes. To customize its colors you typically have to do:
Waybar itself exposes CSS based styling. Having hard coded hex colors in the JSON config makes it tedious to theme Waybar's clock module since you'd have to update the JSON file instead of the CSS file. This is problematic if you have your dotfiles in version control where inline edits create git diffs.
It is IMO cleaner if you can do:
And now in your CSS file you can do:
This lets you extract the above into CSS variables in a theme specific file and now you can symlink your active theme.
Backwards and forwards compatibility
I tried to be mindful of both scenarios.
I wanted to keep the original implementation as close as possible so I went for a "post processing" approach which uses a string find / replace.
If in the future someone overhauls Waybar or this module to have proper CSS support, end users won't have to modify their class based approach to have that continue working.
Manual tests
The following works:
#clock.calendar-today { color: maze; }:[2026-03-02 20:09:07.523] [error] style.css:73:35'maze' is not a valid color name#clock.calendar-today { hello: world; }:[2026-03-02 20:10:09.736] [error] style.css:73:30'hello' is not a valid property nameLimitations
Hot reloading
For hot reloading the CSS without needing to restart Waybar, the clock itself has to update in some way such as the time changing or performing one of the mouse actions.
I tried slamming my head at this problem for a bit but I don't know enough about C++ to solve this. If anyone has any suggestions please let me know. I don't think this is a show stopper but if it's easy to add this behavior, that would be nice!
Limited CSS options
Secondly, not all CSS is supported since I didn't use a CSS parser. Behind the scenes it simply turns
class=intocolor=and ensures a 6 digit hex code is provided for the color so Pango is happy. You can still use Pango supported syntax like<b>in your JSON file.This isn't ideal but it's a first step and likely solves the 95% case of folks wanting to use custom CSS colors.
Given this limitation I didn't document this new behavior in the
manentry. My thought process is the world survived for years without this feature and if you care enough about theming this calendar you'll find this PR or figure it out through experimentation. What do you think, is it worth documenting as is?Alternative strategy
If using a "fake"
class=is too misleading maybe we can overloadcolor=and if instead of a color being passed in, if someone passes in@todayit will look for acalendar-todayclass in your stylesheet and get that value. This way the intent is a little more clear that it only supports colors and not all CSS properties. Using@was chosen because it's how you reference CSS variables. It at least has a mental model to that.