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

Implement #392, take 2 #674

Merged
merged 10 commits into from
Dec 18, 2019

Conversation

xkr47
Copy link
Contributor

@xkr47 xkr47 commented Nov 29, 2019

New attempt at #392, with great ideas from @tsipinakis taken into account. Have still not attempted to test/take into account any DPI-related functionality, so cannot say yet how/if it will affect the outcome.

Do you want more tests for the scaling functionality? Current tests pass.

Implementation details: I moved the scaling responsibility to the lowest functions in the call hierarchy involved in loading the images - both when loading from disk and from the notification message so responsibilities are clearer code-wise. Made some functions static that are no longer needed elsewhere.

@xkr47
Copy link
Contributor Author

xkr47 commented Nov 29, 2019

Will check those CI errors and try to fix them.. Excellent that you have valgrind in your build process! 👍

@xkr47
Copy link
Contributor Author

xkr47 commented Dec 3, 2019

Apparently the function gdk_pixbuf_get_file_info() which I used to be able to get the default image size has a memory leak that is triggered when loading e.g. test/data/icons /path/invalid/icon1.svg. I currently have 2.36.11-1ubuntu0.1 of gdk-pixbuf and at least the version in the CI build also has the same issue.

@tsipinakis I could check with the latest release and with the latest development branch version of gdk-pixbuf to see if it is already fixed or try to get it fixed if not. But nevertheless I guess you'd want me not to use this function as not to cause memory leaks when loading broken images? As an alternative, I could just load the image using the normal gdk_pixbuf_new_from_file(), check its size and in case a different size is wanted, reload it using the gdk_pixbuf_new_from_file_at_scale(). What do you think?

@tsipinakis
Copy link
Member

Weirdly enough I can't reproduce this with Debian stable or sid, which leads me to believe that this might've already been fixed and our CI images are simply out of date. It's also not clear if the leak is in gdk-pixbuf or librsvg, my bet is on the latter.

But nevertheless I guess you'd want me not to use this function as not to cause memory leaks when loading broken images?

Eh, that's a bug that'll even if it's not fixed yet it'll be fixed by the time this is released and reaches the distros. There is no need to hold off to using that function IMO.


On another note, some small TODOs for adding a new setting:

  • Add min_icon_size to the dunstrc with a small explanation similar to max_icon_size
  • Similarly, document its function in docs/dunst.pod.

src/icon.c Show resolved Hide resolved
@tsipinakis
Copy link
Member

Weirdly enough I can't reproduce this with Debian stable or sid, which leads me to believe that this might've already been fixed and our CI images are simply out of date. It's also not clear if the leak is in gdk-pixbuf or librsvg, my bet is on the latter.

Oh! Duh! This is probably rsvg/147, our suppression file just didn't catch it because the stack trace changed with this PR. In this case you can just update .valgrind.supressions and ignore it.

@xkr47
Copy link
Contributor Author

xkr47 commented Dec 3, 2019

Thanks for your feedback & review!

@xkr47
Copy link
Contributor Author

xkr47 commented Dec 3, 2019

Do you have any preferred default value for min_icon_size? Should I set it to 0 to avoid changing current operation (except for downscaling of svgs which will unconditionally be improved slightly 😄)?

Also what is the purpose of the "default" values set in config.h?

@xkr47
Copy link
Contributor Author

xkr47 commented Dec 3, 2019

Are these out of sync?

  • max_icon_size = 0 in config.h
  • max_icon_size defaults to 0 in dunst.pod
  • max_icon_size = 32 in dunstrc

@xkr47
Copy link
Contributor Author

xkr47 commented Dec 3, 2019

I want to add that this solution is not taking DPI into account as @bebehei requested. If we want it to scale icons based on DPI as well, I guess we would need to determine a base DPI like 96 or something, and then scale images by current_dpi / base_dpi. Are images reloaded when notification moves between montiors? I.e. do we have an opportunity to reload & rescale them to the correct (dpi-adjusted) size every time?

@xkr47
Copy link
Contributor Author

xkr47 commented Dec 4, 2019

If we go down the path of dpi-awareness I guess at least the following settings should be dpi-aware too:

  • geometry
  • line_height
  • notification_height
  • separator_height
  • padding
  • horizontal_padding

@tsipinakis
Copy link
Member

Do you have any preferred default value for min_icon_size? Should I set it to 0 to avoid changing current operation (except for downscaling of svgs which will unconditionally be improved slightly smile)?

Leaving it at 0 is fine, I don't think there's any real reason to have it enabled by default.

Also what is the purpose of the "default" values set in config.h?

The default values in config.h is what will be used if a setting isn't present in the dunstrc. These weren't in sync when I took on maintaining dunst and since then I've never really looked more into fixing that because I don't want to break existing setups without a proper reason. (I've seen many people define only the settings they want in dunstrc and leave everything else use config.h values).

Are images reloaded when notification moves between montiors? I.e. do we have an opportunity to reload & rescale them to the correct (dpi-adjusted) size every time?

Yes, images are reloaded on every redraw (perhaps wrongly) - So it can be done and there's also opportunity for optimization to avoid rescaling every time.

I want to add that this solution is not taking DPI into account as @bebehei requested

IMO this is out of the scope of this PR, let's not delay merging this.
But if you're up to implementing proper DPI support don't let me discourage you by all means I'd love to see such a PR :) (Especially if you have the screen/setup to properly test it!)


Either way I'll do the final review either tonight or tomorrow, thanks for implementing this!

@xkr47
Copy link
Contributor Author

xkr47 commented Dec 4, 2019

Yeah the dpi scaling is apparently experimental and not even documented in the pod.. I almost started writing a script already that ensures everything is documented but got distracted..

@xkr47 xkr47 force-pushed the patch-min_icon_size-20191122 branch from adc89db to 667503e Compare December 4, 2019 19:01
src/icon.c Outdated Show resolved Hide resolved
tsipinakis
tsipinakis previously approved these changes Dec 5, 2019
Copy link
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.

Other than the bug mentioned above everything else looks good. Thanks again for the contribution! :)

@xkr47
Copy link
Contributor Author

xkr47 commented Dec 5, 2019

Do you want more tests for the scaling functionality?

@tsipinakis
Copy link
Member

Do you want more tests for the scaling functionality?

More tests are always better. I didn't mention anything about tests earlier because it didn't feel right asking for them when there aren't any for max_icon_size either.
If you have the time to add them please go ahead!

@xkr47
Copy link
Contributor Author

xkr47 commented Dec 6, 2019

I will try next week. If you are in a hurry I can create a separate PR later.

@tsipinakis
Copy link
Member

@xkr47 Ping? No pressure, just wanted to make sure you haven't forgotten about this.

@xkr47
Copy link
Contributor Author

xkr47 commented Dec 17, 2019

Thanks! Yeah bit busy but not forgotten :)

@xkr47
Copy link
Contributor Author

xkr47 commented Dec 17, 2019

There we go, got it done thanks to some well-timed motivation speech :) I split most of dbus_notification_set_raw_image() test helper to a separate function in a separate file (see test/helpers.[ch]) so I could do better unit testing of images embedded in notifications.

Let me know of any improvements/corrections/etc you'd wish to see.

(The travis builds did not get very far and the failures feel totally unrelated to my code.)

@xkr47 xkr47 force-pushed the patch-min_icon_size-20191122 branch 2 times, most recently from aa92d73 to d08cee7 Compare December 17, 2019 20:32
@xkr47 xkr47 force-pushed the patch-min_icon_size-20191122 branch from d08cee7 to ad5d20b Compare December 17, 2019 20:40
@tsipinakis
Copy link
Member

LGTM, merged! Kudos for taking care of the tests as well, it's the part most people dread.

@tsipinakis tsipinakis merged commit 3f3082e into dunst-project:master Dec 18, 2019
@xkr47
Copy link
Contributor Author

xkr47 commented Dec 18, 2019

Excellent news! It was a pleasure really, the codebase was easy to follow and the existing test helpers did most of the dreaded hard work already :)

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.

None yet

2 participants