Skip to content
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

Merged
merged 8 commits into from
Apr 7, 2024
Merged

Store colors in a struct #1306

merged 8 commits into from
Apr 7, 2024

Conversation

bynect
Copy link
Member

@bynect bynect commented Mar 4, 2024

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

@bynect
Copy link
Member Author

bynect commented Mar 4, 2024

Still working on the tests

@bynect bynect force-pushed the cache-colors branch 2 times, most recently from cf83285 to 3ad3886 Compare March 4, 2024 23:44
@bynect bynect requested review from fwsmit and zappolowski March 4, 2024 23:56
@bynect
Copy link
Member Author

bynect commented Mar 4, 2024

Fixes what we talked about in #1286

@bynect
Copy link
Member Author

bynect commented Mar 5, 2024

Note that invalid colors sent to dbus are ignored

@fwsmit
Copy link
Member

fwsmit commented Mar 8, 2024

Yeah, looks good!

#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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Copy link
Member Author

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)
Copy link
Member

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.

Copy link
Member Author

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 != '#') {
Copy link
Member

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).

Copy link
Member Author

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)
Copy link
Member

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;
Copy link
Member

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.

Copy link
Member Author

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
Copy link
Member

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.

Copy link
Member Author

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

@bynect
Copy link
Member Author

bynect commented Mar 9, 2024

I will do some fixes and merge it then 👍

@zappolowski
Copy link
Member

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.

@bynect
Copy link
Member Author

bynect commented Mar 9, 2024

Right, ci is still down 😬

@zappolowski
Copy link
Member

@bynect As I've merged the new pipeline you could rebase this branch and then hopefully we can go forward merging it.

@codecov-commenter
Copy link

codecov-commenter commented Apr 6, 2024

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 83.91608% with 23 lines in your changes missing coverage. Please review.

Project coverage is 65.30%. Comparing base (15b1e8c) to head (6740fb0).
Report is 179 commits behind head on master.

Files with missing lines Patch % Lines
src/draw.c 53.57% 13 Missing ⚠️
src/notification.c 69.23% 4 Missing ⚠️
src/option_parser.c 92.85% 3 Missing ⚠️
src/dbus.c 75.00% 2 Missing ⚠️
src/rules.c 87.50% 1 Missing ⚠️

❗ 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     
Flag Coverage Δ
unittests 65.30% <83.91%> (+0.23%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bynect
Copy link
Member Author

bynect commented Apr 6, 2024

@zappolowski should I merge it now?

@zappolowski
Copy link
Member

Yes, just go ahead and merge it.

@bynect bynect merged commit 6d2296b into dunst-project:master Apr 7, 2024
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants