-
Notifications
You must be signed in to change notification settings - Fork 351
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Store colors in a struct #1306
Store colors in a struct #1306
Conversation
Still working on the tests |
cf83285
to
3ad3886
Compare
Fixes what we talked about in #1286 |
Note that invalid colors sent to dbus are ignored |
Yeah, looks good! |
src/option_parser.c
Outdated
#define UINT_MAX_N(bits) ((1 << bits) - 1) | ||
|
||
// Parse a #RRGGBB[AA] string | ||
int string_parse_color(const void *data, const char *s, void *ret) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
int string_parse_color(const void *data, const char *s, void *ret) | |
int string_parse_color(const void *data, const char *s, struct color *color) |
Shouldn't the target always be a struct color *
? Then we should be able to get rid of line 205 as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I was trying to use TYPE_CUSTOM before but then I changed
src/draw.h
Outdated
}; | ||
|
||
#define COLOR_UNINIT { -1, -1, -1, -1 } | ||
#define COLOR_VALID(c) ((c).r >= 0 && (c).g >= 0 && (c).b >= 0 && (c).a >= 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we check c.x > 1
here as well (instead of just when trying to print it)? Cairo colors have to be in the [0, 1] range and thus COLOR_VALID
should enforce this everywhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My idea was that either a color was valid or it was initialized with all -1. But yes, maybe an extra check for correctness is fine
// Parse a #RRGGBB[AA] string | ||
int string_parse_color(const void *data, const char *s, void *ret) | ||
{ | ||
if (STR_EMPTY(s) || *s != '#') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know it was basically this way already before your changes, but dunst.5
states, that named colors like "Yellow" are supported, which doesn't seem to be the case anymore (I don't know since when). Either it is removed from the documentation (breaking change, should be added - retroactively - to CHANGELOG.md
) or it is possible to somehow get it back to work (starting point could be this list).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mmm, didn't know about that. I moved the parsing code from draw.c. maybe we can add color names in another pr.
Did you think about embedding an array with all the info from that file?
|
||
#define COLOR_UNINIT { -1, -1, -1, -1 } | ||
#define COLOR_VALID(c) ((c).r >= 0 && (c).g >= 0 && (c).b >= 0 && (c).a >= 0) | ||
#define COLOR_SAME(c1, c2) ((c1).r == (c2).r && (c1).g == (c2).g && (c1).b == (c2).b && (c1).a == (c2).a) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is just used in tests. I think, it should be moved to test/helpers.h
.
if (!COLOR_VALID(n->colors.fg)) n->colors.fg = defcolors.fg; | ||
if (!COLOR_VALID(n->colors.bg)) n->colors.bg = defcolors.bg; | ||
if (!COLOR_VALID(n->colors.highlight)) n->colors.highlight = defcolors.highlight; | ||
if (!COLOR_VALID(n->colors.frame)) n->colors.frame = defcolors.frame; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're a bit inconsistent on your style (see src/rules.c
). Sometimes you make single statement if a oneliner and sometimes it's put on two lines. Personally, I prefer to have the two line variant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. I try to minimize the use of lines, so if both the condition and statements are really short I put them in a single line (especially if there are a lot chained like here). I will try to be more consistent in the future
@@ -160,12 +160,16 @@ void settings_init(void) { | |||
} | |||
} | |||
|
|||
// NOTE: This function is probably outdated and no longer relevant | |||
// Since it does not even fully display rule information we | |||
// may want to remove it or change it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with removing it ... it basically just echoes the user input. The only use case could be to find typos in the configuration, but a) is this just printed at DEBUG level and b) is there already a WARNING issued, whenever an unknown key is encountered.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The main problem is that it prints only some values, so it doesn't really help that much
I will do some fixes and merge it then 👍 |
I wouldn't merge as long as CI doesn't work properly. I also accidentally merged a branch yesterday - but luckily, this was just update of a pod file and thus the chance of breakage is rather low. |
Right, ci is still down 😬 |
@bynect As I've merged the new pipeline you could rebase this branch and then hopefully we can go forward merging it. |
Codecov ReportAttention: Patch coverage is
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #1306 +/- ##
==========================================
+ Coverage 65.06% 65.30% +0.23%
==========================================
Files 48 48
Lines 8173 8215 +42
==========================================
+ Hits 5318 5365 +47
+ Misses 2855 2850 -5
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
@zappolowski should I merge it now? |
Yes, just go ahead and merge it. |
I changed every usage of colors from a string to a color struct. Colors are now parsed only once in the option_parser instead of every single draw call.
Note: Hopefully I haven't missed anything. I would be super grateful if someone could do some extra testing on their own if they encounter anything strange