Skip to content

Conversation

zane-weissman
Copy link

@zane-weissman zane-weissman commented Dec 1, 2024

Description

Fixes #761.

This fix applies to high resolution displays (or any display where the user has set the display scale to something other than 100%). For example, imagine you want to render a 16x16 image (in yuck: :image-height 16 :image-width 16) at 2x scale. The resulting image will be 32x32 physical pixels on the display. If your image source has the fidelity (e.g. you have a >32x32 pixel PNG or an SVG), the resulting image should be sharp, but previously, it was being rendered at the logical resolution (16x16) and upscaled to the physical resolution, creating a blurry image.

Usage

No configuration changes. Images will simply be rendered at high resolution if possible.

Showcase

Before and after:
Screenshot from 2024-12-01 13-48-26 Screenshot from 2024-12-01 13-54-54

Additional Notes

All of the practical code is taken from src/widgets/systray.rs. Thank you to whoever wrote that code! Also, I am relatively new to Rust, any comments on style etc. are welcome.

Checklist

Please make sure you can check all the boxes that apply to this PR.

  • All widgets I've added are correctly documented.
  • I added my changes to CHANGELOG.md, if appropriate.
  • The documentation in the docs/content/main directory has been adjusted to reflect my changes.
  • I used cargo fmt to automatically format all code before committing

@zane-weissman zane-weissman marked this pull request as ready for review December 1, 2024 19:04
@Kynson
Copy link

Kynson commented Feb 10, 2025

It would be great if this can get merged, currently facing the same problem. (I know the team maybe busy with other stuff, not intended to rush anyone)

Thanks a lot!

@UnnaturalTwilight
Copy link
Contributor

Trying this out on my own fork. Eww fails to load if any images don't have both width and height defined. Most of my config is only defining :image-width and using the default :preserve-aspect-ratio value of true to implicitly define the height.
I'm using fractional scaling on hyprland.

@zane-weissman
Copy link
Author

zane-weissman commented May 17, 2025

Trying this out on my own fork. Eww fails to load if any images don't have both width and height defined. Most of my config is only defining :image-width and using the default :preserve-aspect-ratio value of true to implicitly define the height. I'm using fractional scaling on hyprland.

Thanks for noticing this - I had image_width and image_height both defined in all my configs. It looks like somehow when image_height was omitted from the yuck config, it was getting passed into the graphics library as 0 and failing a check when the library tried to scale the image to the requested size. I'm not sure why this happened, because I think the default value for image_height should be -1... See line 594 of widget_definitions.rs:

prop(path: as_string, image_width: as_i32 = -1, image_height: as_i32 = -1, preserve_aspect_ratio: as_bool = true, fill_svg: as_string = "") {

Anyways, the fix in 22a970f just sets the image_height and/or image_width to -1 if they're not positive before passing them to gtk::gdk_pixbuf::Pixbuf::from_file_at_scale(). Let me know if it's working for you too!

@UnnaturalTwilight
Copy link
Contributor

It seems to be working. Great job!

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.

[FEATURE] Better image scaling with SVG (on Wayland)
3 participants