Added: support for round corners#420
Conversation
bebehei
left a comment
There was a problem hiding this comment.
I can't say anything about x_win_corners. @tsipinakis has to review this.
For the look and feel of this PR: IMHO the rounded corners are very ugly and should somewhat smoothed. I don't see this as in improvement yet.
|
|
||
| #include <X11/X.h> | ||
| #include <X11/Xlib.h> | ||
| #include <X11/extensions/shape.h> |
| xrandr \ | ||
| xscrnsaver | ||
| xscrnsaver \ | ||
| xext |
There was a problem hiding this comment.
Keep track of your indentation please. For alignment you have to use spaces.
There was a problem hiding this comment.
Also e < s. Please sort the libs correctly.
| # automatically after a crash. | ||
| startup_notification = false | ||
|
|
||
| # window corners |
There was a problem hiding this comment.
Please add this stuff to the manpage, too and elaborate it a bit more and give a unit. For a passive user, this could be anything (em, inch, pixels).
|
I tweaked now the
|
tsipinakis
left a comment
There was a problem hiding this comment.
Here's a quick review for x_win_round_corners, haven't gotten around to looking at the cairo stuff yet.
I've been having trouble finding good documentation on the X11 Shape APIs so reviewing this is a bit of a guess on their behaviour.
| startup_notification = false | ||
|
|
||
| # window corners | ||
| corner = 0 |
There was a problem hiding this comment.
rounded_corner_radius would be a better name for this setting in my opinion.
Edit: or just corner_radius
|
|
||
| XSetForeground(xctx.dpy, shape_gc, 1); | ||
|
|
||
| XFillArc(xctx.dpy, mask, shape_gc, 0, 0, dia, dia, 0, 23040); |
There was a problem hiding this comment.
-
2304is an ugly way to say360*64, it'll be optimized away by the compiler anyway and it's much better for readability to write it out. -
This is the first time I'm looking into the X drawing API so correct me if I'm wrong but is there a reason you're drawing the entire 360 degrees instead of just the ones needed? Is there a downside to it?
There was a problem hiding this comment.
To the second point: There's no specific reason to draw the entire 360 degrees. I just did it for simplicity. I'm going to test the behaviour with just filling the need arc.
| XSetForeground(xctx.dpy, shape_gc, 1); | ||
|
|
||
| XFillArc(xctx.dpy, mask, shape_gc, 0, 0, dia, dia, 0, 23040); | ||
| XFillArc(xctx.dpy, mask, shape_gc, width-dia-1, 0, dia, dia, 0, 23040); |
There was a problem hiding this comment.
Style nitpick: Please put a space before and after each - to make it obvious that it's an expression.
| GC shape_gc = XCreateGC(xctx.dpy, mask, 0, &xgcv); | ||
|
|
||
| int rad = settings.corner_radius; | ||
| int dia = 2 * rad; |
There was a problem hiding this comment.
The diameter of the corner should be capped to the window width/height so that it doesn't cause rendering weirdness in case it's bigger than the window size.
|
Fixed the behaviour that frame and corner frame doesnt match in the following commit. This only happens, when the corner radius is bigger than the height of the notification. I restricted it to the maximum height as @tsipinakis stated out in his review. |
|
@bebehei Yes, I did. Can you post your configuration for the frame and corner radius so I can investigate? I played with the config values and for me it seem to work fine. 🤔 |
|
@dj95 Here it is:dunstrc.txt |
|
I have to admit, I've set horrible values. But IMHO dunst should be able to handle (or sanitize) them. Interestingly, I got now 3 notifications from thunderbird. There, the corner frame was correct. But after a short time, the lower one began to flap. |
|
I know. But to ensure the software quality dunst should be able to sanitize those values :) |
bebehei
left a comment
There was a problem hiding this comment.
I've marked all unnecessary changes in your commits.
Also, as one of us will definitely come up and ask you to squash the commits. Could you do it please?
I have reviewd while you pushed you new commit.
About your latest commit: I see no problems in style anymore. These are looking quite good.
The only thing what's left are the round corners by the compositor. In my case, compton does not recognize round corners (albeit --detect-rounded-corners is set). This may be an issue related to chjj/compton#388.
| # check if we need libxdg-basedir | ||
| ifeq (,$(findstring STATIC_CONFIG,$(CFLAGS))) | ||
| pkg_config_packs += libxdg-basedir | ||
| pkg_config_packs += libxdg-basedir |
There was a problem hiding this comment.
Sorry, but this is unrelated to your intent of this PR. Please remove the space change. (I'll mark further changes with "unrelated".)
There was a problem hiding this comment.
I did this one because the rest of the indentation in this file uses spaces, not tabs. But I'm going to revert this if you want it.
| # dunstify also needs libnotify | ||
| ifneq (,$(findstring dunstify,${MAKECMDGOALS})) | ||
| pkg_config_packs += libnotify | ||
| pkg_config_packs += libnotify |
| cairo_destroy(c); | ||
| cairo_surface_destroy(image_surface); | ||
| r_free_layouts(layouts); | ||
|
|
| c = cairo_create(image_surface); | ||
|
|
||
| x_win_move(width, height); | ||
|
|
|
|
||
| void x_win_draw(void) | ||
| { | ||
|
|
| if (ev.xexpose.count == 0 && xctx.visible) { | ||
| x_win_round_corners(); | ||
|
|
||
| x_win_draw(); |
There was a problem hiding this comment.
There are many more calls of x_win_draw(). One for example is in run() of dunst.c.
For my understanding the rounded corners have to be called every time the window gets drawn. Why don't you put it into x_win_draw directly?
There was a problem hiding this comment.
I do it in the following commit. I first thought, that its only necessary on the expose event.
There was a problem hiding this comment.
I was also about to point out that negative values in the corner_radius setting aren't handled but when I tried it it actually produced a pretty nifty effect
It's a bug feature!
This PR is getting close to completion so as @bebehei said can you squash all fixups in order to make the final review easier?
| int bg_height = MAX(settings.notification_height, (2 * settings.padding) + h); | ||
| double bg_half_height = settings.notification_height/2.0; | ||
| int pango_offset = (int) floor(h/2.0); | ||
| double degrees = M_PI / 180.0; |
There was a problem hiding this comment.
This should be a const, we don't need to modify it.
There was a problem hiding this comment.
@dj95 He meant to solely mark it with const (instead of defining a new macro).
| if (settings.frame_width > 0) { | ||
| if (first && last) { | ||
| cairo_new_sub_path (c); | ||
| cairo_arc (c, bg_x + bg_width - settings.corner_radius, bg_y + settings.corner_radius, settings.corner_radius, -90 * degrees, 0 * degrees); |
There was a problem hiding this comment.
Another style nitpick but I think this is borderline unreadable. I'd prefer if it was one parameter per line for long function calls like so:
cairo_arc (c,
bg_x + bg_width - corner_radius,
bg_y + corner_radius,
corner_radius,
-90 * degrees,
0 * degrees);Same goes for XFillArc and XFillRectangle.
Though I'm not 100% on this decision. @bebehei What do you think? (I'm aware that this is the case for other calls in the same function but since it came up now might as-well discuss it and maybe start fixing it.)
There was a problem hiding this comment.
@bebehei What do you think?
Well, I'd like to have parameters in one line. I prefer it.
| else bg_height += settings.separator_height; | ||
|
|
||
| cairo_set_source_rgb(c, cl->frame.r, cl->frame.g, cl->frame.b); | ||
| cairo_set_source_rgba(c, cl->bg.r, cl->bg.g, cl->bg.b, 255); |
There was a problem hiding this comment.
Please use RGB. Everything else is also based on RGB
200994a to
8d3c36e
Compare
|
I hope I haven't fucked up the commit history... Maybe you are more experienced to squash those commits. |
|
Or shall I squash all commits I made in this PR to one commit? |
Yes please. |
75aa307 to
f760ba8
Compare
|
@tsipinakis has shown me this once: https://chris.beams.io/posts/git-commit/ |
|
And I destroyed the functionality... damn. I'll take a look tomorrow |
f83a95d to
3109610
Compare
|
Nevermind. It was just a wrong variable type. Amazing how different the graphical behaviour is 😄 I hope all fixes are now present :) |
|
Simply from looking at the diff I see that it still includes irrelevant changes from other commits (looks like parts of #421 are in there). Can you rebase on master and remove them? Also it might be beneficial to trim the commit message - we don't need to know what commits got squashed. |
|
@dj95 Before you work further, do this: |
|
ping @dj95 |
3109610 to
92f9ee4
Compare
|
I'm sorry that you need to wait that long, was a busy last week. I think the PR now contains just the changes that are needed for the round corners feature. Tests on my machine (and hopefully yours, too) are working fine. I'm a bit afraid to squash the commits because last time I made a mistake and squashed a merge from your master branch. I need to practice it a bit with a test-project first(This is my first pull request I've ever made :D ). |
|
@dj95 The two commits are intended. |
|
Looks much better. I'll review it later. |
7c7f0b3 to
60cbc86
Compare
It is but I don't see a reasonable alternative. If we force it to use the higher radius it just looks broken. |
|
Instead of mocking about the continuously repeating code, I had a try to touch X11/cairo code for myself. And it was a great learning experience.
I guess we have to document this and give out the hint, that the user shall not choose a radius, which is bigger than half the height (or maybe even the width if the user has got a superweird geometry) of the smallest expected notification. |
7612039 to
aef05a9
Compare
tsipinakis
left a comment
There was a problem hiding this comment.
Instead of mocking about the continuously repeating code, I had a try to touch X11/cairo code for myself. And it was a great learning experience.
That's awesome to hear and your changes do bring a big improvement in code readability.
I guess we have to document this and give out the hint, that the user shall not choose a radius, which is bigger than half the height (or maybe even the width if the user has got a superweird geometry) of the smallest expected notification.
We could but that has the disadvantage that if someone does want a higher radius when available they won't be able to use it without cutting off smaller notifications.
A middle ground might be to limit the radius to the minimum of the height of the first and last layout if there are more than 1 notifications being displayed and to height/2 if only one is.
With the latest commits separator_color = frame is broken but I cannot figure out what broke it, bisect says 040be9a. Keep in mind we don't redraw the separator on top if it's the same color as the frame, we just leave a gap when rendering the background (at least that's how it used to work).
| const int width = win->dim.w; | ||
| const int height = win->dim.h; | ||
| const int dia = 2 * rad; | ||
| const int degrees = 64; |
There was a problem hiding this comment.
I'd add a comment here to explain why 64, or just point to the docs.
There was a problem hiding this comment.
I'm aware, but someone looking at it a few months or years in the future is going to be really confused at this random value if they're not very familiar with the extension.
There was a problem hiding this comment.
Good point. It definitely warrants a comment.
Fuck it. Sorry for the strong language. Let's draw the separator actively. I'm forging the commit right now. |
aef05a9 to
c9052b2
Compare
| degrees * 180); | ||
| } else { | ||
| cairo_line_to(c, x + width, y+width); | ||
| cairo_line_to(c, x, y+width); |
There was a problem hiding this comment.
Let's draw the separator actively. I'm forging the commit right now.
While true it's simple to just draw over it and be done. Things not working like this can indicate some type of problem in the implementation. Like here, you're adding the width to the vertical axis, which is what broke the separator.
a70ad2f to
ce65fa2
Compare
ce65fa2 to
eb1b5ca
Compare
eb1b5ca to
c475a0b
Compare
|
I documented that |
c475a0b to
20b3c67
Compare
Simultaneously yes and no. I appreciate dropping this commit. But we're definitely missing here a test. AFAIK, I'm the third person stumbling over this bit in a PR and the only person, who found out about this, had been you. |
We're definitely are, I'm looking into converting out tests to glib right now and after that I'll look into adding tests for the drawing part. |
20b3c67 to
aab9fef
Compare
|
Dropped it which dismissed your review, oops! |












As requested in issue #358 here's the support for round corners via the x11 shape extension.