Skip to content

Added: support for round corners#420

Merged
tsipinakis merged 3 commits into
dunst-project:masterfrom
dj95:feature/round_corners
May 28, 2018
Merged

Added: support for round corners#420
tsipinakis merged 3 commits into
dunst-project:masterfrom
dj95:feature/round_corners

Conversation

@dj95
Copy link
Copy Markdown
Contributor

@dj95 dj95 commented Oct 27, 2017

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

Copy link
Copy Markdown
Member

@bebehei bebehei left a comment

Choose a reason for hiding this comment

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

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.

Comment thread src/x11/x.h Outdated

#include <X11/X.h>
#include <X11/Xlib.h>
#include <X11/extensions/shape.h>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

h > c. Please sort it.

Comment thread config.mk Outdated
xrandr \
xscrnsaver
xscrnsaver \
xext
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Keep track of your indentation please. For alignment you have to use spaces.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also e < s. Please sort the libs correctly.

Comment thread dunstrc Outdated
# automatically after a crash.
startup_notification = false

# window corners
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

@bebehei
Copy link
Copy Markdown
Member

bebehei commented Oct 27, 2017

I tweaked now the frame and corner options a bit to make dunst very ugly. I don't claim, that there is a user, who is so stupid, to configure dunst this way, but this explains the stuff, which should get fixed first:

screenshot from 2017-10-27 13-06-21

  • For some reasons, compton (or in general the compositing manager) does not get informed, that the window is round.
  • Also when having frame > 0, the corners of the frame get rounded, but not the actual notification window. So frame and corner cannot get combined.

Copy link
Copy Markdown
Member

@tsipinakis tsipinakis left a comment

Choose a reason for hiding this comment

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

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.

Comment thread dunstrc Outdated
startup_notification = false

# window corners
corner = 0
Copy link
Copy Markdown
Member

@tsipinakis tsipinakis Oct 27, 2017

Choose a reason for hiding this comment

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

rounded_corner_radius would be a better name for this setting in my opinion.

Edit: or just corner_radius

Comment thread src/x11/x.c Outdated

XSetForeground(xctx.dpy, shape_gc, 1);

XFillArc(xctx.dpy, mask, shape_gc, 0, 0, dia, dia, 0, 23040);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

  • 2304 is an ugly way to say 360*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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Comment thread src/x11/x.c Outdated
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);
Copy link
Copy Markdown
Member

@tsipinakis tsipinakis Oct 27, 2017

Choose a reason for hiding this comment

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

Style nitpick: Please put a space before and after each - to make it obvious that it's an expression.

Comment thread src/x11/x.c Outdated
GC shape_gc = XCreateGC(xctx.dpy, mask, 0, &xgcv);

int rad = settings.corner_radius;
int dia = 2 * rad;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

@bebehei
Copy link
Copy Markdown
Member

bebehei commented Oct 29, 2017

screenshot from 2017-10-29 13-56-27

Better: Now, there is frame in the corner. But the frame of the corner and the frame of the side do not match.

@dj95
Copy link
Copy Markdown
Contributor Author

dj95 commented Oct 29, 2017

screenshot_2017-10-29_14-52-45

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

bebehei commented Oct 29, 2017

@dj95 Your screenshot looks correct.

I'm using dc10dce

screenshot from 2017-10-29 15-36-43

There's a frame missing in the corners.

screenshot from 2017-10-29 15-43-01

Ah, there's the missing frame. But, well 😕

Have you pushed the commit, you made the screenshot with?

@dj95
Copy link
Copy Markdown
Contributor Author

dj95 commented Oct 29, 2017

@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. 🤔

@bebehei
Copy link
Copy Markdown
Member

bebehei commented Oct 29, 2017

@dj95 Here it is:dunstrc.txt

@bebehei
Copy link
Copy Markdown
Member

bebehei commented Oct 29, 2017

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.

@dj95
Copy link
Copy Markdown
Contributor Author

dj95 commented Oct 29, 2017

I know. But to ensure the software quality dunst should be able to sanitize those values :)

@dj95
Copy link
Copy Markdown
Contributor Author

dj95 commented Oct 29, 2017

screenshot_2017-10-29_19-18-13
screenshot_2017-10-29_19-18-28

Now the problem of a too big radius is fixed and capped to the half of one notification 😊

Copy link
Copy Markdown
Member

@bebehei bebehei left a comment

Choose a reason for hiding this comment

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

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.

Comment thread config.mk Outdated
# check if we need libxdg-basedir
ifeq (,$(findstring STATIC_CONFIG,$(CFLAGS)))
pkg_config_packs += libxdg-basedir
pkg_config_packs += libxdg-basedir
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sorry, but this is unrelated to your intent of this PR. Please remove the space change. (I'll mark further changes with "unrelated".)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Comment thread config.mk Outdated
# dunstify also needs libnotify
ifneq (,$(findstring dunstify,${MAKECMDGOALS}))
pkg_config_packs += libnotify
pkg_config_packs += libnotify
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

unrelated

Comment thread src/x11/x.c Outdated
cairo_destroy(c);
cairo_surface_destroy(image_surface);
r_free_layouts(layouts);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

unrelated

Comment thread src/x11/x.c Outdated
c = cairo_create(image_surface);

x_win_move(width, height);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

same.

Comment thread src/x11/x.c Outdated

void x_win_draw(void)
{

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

unrelated

Comment thread src/x11/x.c Outdated
if (ev.xexpose.count == 0 && xctx.visible) {
x_win_round_corners();

x_win_draw();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I do it in the following commit. I first thought, that its only necessary on the expose event.

Copy link
Copy Markdown
Member

@tsipinakis tsipinakis left a comment

Choose a reason for hiding this comment

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

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

2017-10-29t21-37-15 2017-10-29t21-43-33

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?

Comment thread src/x11/x.c Outdated
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;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should be a const, we don't need to modify it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@dj95 He meant to solely mark it with const (instead of defining a new macro).

Comment thread src/x11/x.c Outdated
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);
Copy link
Copy Markdown
Member

@tsipinakis tsipinakis Oct 29, 2017

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@bebehei What do you think?

Well, I'd like to have parameters in one line. I prefer it.

Comment thread src/x11/x.c Outdated
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);
Copy link
Copy Markdown
Member

@bebehei bebehei Oct 29, 2017

Choose a reason for hiding this comment

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

Please use RGB. Everything else is also based on RGB

@dj95 dj95 force-pushed the feature/round_corners branch from 200994a to 8d3c36e Compare October 29, 2017 20:36
@dj95
Copy link
Copy Markdown
Contributor Author

dj95 commented Oct 29, 2017

I hope I haven't fucked up the commit history... Maybe you are more experienced to squash those commits.

@dj95
Copy link
Copy Markdown
Contributor Author

dj95 commented Oct 29, 2017

Or shall I squash all commits I made in this PR to one commit?

@bebehei
Copy link
Copy Markdown
Member

bebehei commented Oct 29, 2017

Or shall I squash all commits I made in this PR to one commit?

Yes please.

@dj95 dj95 force-pushed the feature/round_corners branch 2 times, most recently from 75aa307 to f760ba8 Compare October 29, 2017 21:33
@bebehei
Copy link
Copy Markdown
Member

bebehei commented Oct 29, 2017

@tsipinakis has shown me this once: https://chris.beams.io/posts/git-commit/

@dj95
Copy link
Copy Markdown
Contributor Author

dj95 commented Oct 29, 2017

And I destroyed the functionality... damn. I'll take a look tomorrow

@dj95 dj95 force-pushed the feature/round_corners branch from f83a95d to 3109610 Compare November 1, 2017 14:01
@dj95
Copy link
Copy Markdown
Contributor Author

dj95 commented Nov 1, 2017

Nevermind. It was just a wrong variable type. Amazing how different the graphical behaviour is 😄 I hope all fixes are now present :)

@tsipinakis
Copy link
Copy Markdown
Member

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.

@bebehei
Copy link
Copy Markdown
Member

bebehei commented Nov 2, 2017

@dj95 Before you work further, do this:

git clone https://github.com/dj95/dunst dunst-new
cd dunst-new
git checkout master
git pull --ff-only http://github.com/dunst-project/dunst/ master
git checkout feature/round_corners
git reset --hard master
git pull --ff-only http://github.com/bebehei/dunst/ 420-rebase
git push --force -u origin feature/round_corners

@bebehei
Copy link
Copy Markdown
Member

bebehei commented Nov 6, 2017

ping @dj95

@dj95 dj95 force-pushed the feature/round_corners branch from 3109610 to 92f9ee4 Compare November 8, 2017 12:15
@dj95
Copy link
Copy Markdown
Contributor Author

dj95 commented Nov 8, 2017

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

@bebehei
Copy link
Copy Markdown
Member

bebehei commented Nov 8, 2017

@dj95 The two commits are intended.

@bebehei
Copy link
Copy Markdown
Member

bebehei commented May 27, 2018

Looks much better. I'll review it later.

@tsipinakis tsipinakis force-pushed the feature/round_corners branch from 7c7f0b3 to 60cbc86 Compare May 27, 2018 12:33
@bebehei
Copy link
Copy Markdown
Member

bebehei commented May 27, 2018

Same configuration as before. Additonally a corner_radius set to 2000.

screenshot from 2018-05-27 15-25-20

screenshot from 2018-05-27 15-26-13

screenshot from 2018-05-27 15-25-35

I think the approach to limit the corner radius to half the height of the notification is a bit counterintuitive, what do you think?

@tsipinakis
Copy link
Copy Markdown
Member

I think the approach to limit the corner radius to half the height of the notification is a bit counterintuitive, what do you think?

It is but I don't see a reasonable alternative. If we force it to use the higher radius it just looks broken.

@bebehei
Copy link
Copy Markdown
Member

bebehei commented May 28, 2018

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.

It is but I don't see a reasonable alternative. If we force it to use the higher radius it just looks broken.

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.

@bebehei bebehei force-pushed the feature/round_corners branch from 7612039 to aef05a9 Compare May 28, 2018 08:20
Copy link
Copy Markdown
Member

@tsipinakis tsipinakis left a comment

Choose a reason for hiding this comment

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

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

Comment thread src/x11/x.c Outdated
const int width = win->dim.w;
const int height = win->dim.h;
const int dia = 2 * rad;
const int degrees = 64;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd add a comment here to explain why 64, or just point to the docs.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Err, this is because of the docs ™️.

Copy link
Copy Markdown
Member

@tsipinakis tsipinakis May 28, 2018

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Good point. It definitely warrants a comment.

@bebehei
Copy link
Copy Markdown
Member

bebehei commented May 28, 2018

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

Fuck it. Sorry for the strong language. Let's draw the separator actively. I'm forging the commit right now.

@bebehei bebehei force-pushed the feature/round_corners branch from aef05a9 to c9052b2 Compare May 28, 2018 09:49
Comment thread src/draw.c Outdated
degrees * 180);
} else {
cairo_line_to(c, x + width, y+width);
cairo_line_to(c, x, y+width);
Copy link
Copy Markdown
Member

@tsipinakis tsipinakis May 28, 2018

Choose a reason for hiding this comment

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

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.

@bebehei bebehei force-pushed the feature/round_corners branch from a70ad2f to ce65fa2 Compare May 28, 2018 10:07
@tsipinakis tsipinakis force-pushed the feature/round_corners branch from ce65fa2 to eb1b5ca Compare May 28, 2018 10:35
@tsipinakis tsipinakis force-pushed the feature/round_corners branch from eb1b5ca to c475a0b Compare May 28, 2018 10:36
@tsipinakis
Copy link
Copy Markdown
Member

tsipinakis commented May 28, 2018

I documented that corner_radius is automatically lowered in the man page and dunstrc. I'd call this one ready to be merged if you agree, with one suggestion being to drop 20b3c67, if everything is implemented properly that optimisation should work as intended and if not there's a good chance something else was broken alongside so it's worth keeping in IMO.

@tsipinakis tsipinakis force-pushed the feature/round_corners branch from c475a0b to 20b3c67 Compare May 28, 2018 10:41
@bebehei
Copy link
Copy Markdown
Member

bebehei commented May 28, 2018

with one suggestion being to drop c475a0b,

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.

@tsipinakis
Copy link
Copy Markdown
Member

But we're definitely missing here a test.

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.

bebehei
bebehei previously approved these changes May 28, 2018
@tsipinakis
Copy link
Copy Markdown
Member

Dropped it which dismissed your review, oops!

@tsipinakis
Copy link
Copy Markdown
Member

Thanks @dj95 for the initial implementation it's been a while since we've implemented a major feature and this brings a nice change of pace.

(And as usual thanks @bebehei for the help/review!)

@tsipinakis tsipinakis merged commit 15c252a into dunst-project:master May 28, 2018
Holzhaus added a commit to Holzhaus/dotfiles that referenced this pull request Jul 28, 2018
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.

3 participants