elkowar / eww

ElKowars wacky widgets
https://elkowar.github.io/eww
MIT License
9.39k stars 381 forks source link

[BUG] image-width or image-height properties on .gif image widget doesn't seems to change size #1017

Open Ora9 opened 9 months ago

Ora9 commented 9 months ago

Checklist before submitting an issue

Description of the bug

EDIT: this post is the original issue that was quickly resolved, a new issue is described below in this comment

Using the image widget I can't render an animated image (in gif format), it just doesn't appear on screen, and shows no error on eww logs

Reproducing the issue

(image
    :path "/path/to/image.gif"
    :image-width 256
    :image-height 256
)

Expected behaviour

Seeing the image animated

Additional context

No response

Localghost385 commented 9 months ago

i am able to render gifs this way, animated or not. can you provide more info? does the image tag render other images?

Ora9 commented 9 months ago

Ok that's weird, it renders now! (and i think i understand why it didn't earlier) but i still encountered one issues : image-width and image-height properties doesn't change the size of the image

And it doesn't output anything to the eww logs

Should i open another issue, or edit the original post (i just changed the title for now) ?

Reproducing the issue

(defwindow giftests
    :monitor 0
    :windowtype "overlay"
    :geometry (geometry
        :width 512
        :height 512
        :anchor "center"
    )
    (image
        :path "/path/to/image.gif"
        :image-width 50
        :image-height 50
    )
)
~ > eww open giftests

Then change image-width and image-height to another value

Additional Context

I'm on wayland

~ > eww --version
eww 0.4.0 d58d91de78d2b9984a1bbb8314be197bc0e283dc
~ > uname -srmo
Linux 6.7.1-arch1-1 x86_64 GNU/Linux
Localghost385 commented 9 months ago

what sort of output were you expecting from eww logs? i set up this test

(defwindow giftests
    :monitor 0
    :windowtype "overlay"
    :geometry (geometry
        :width 512
        :height 512
        :anchor "bottom left"
    )
    (image
        :path "/home/grace/jam.gif"
        :image-width 50
        :image-height 50
    )
)

(defwindow control
    :monitor 0
    :windowtype "overlay"
    :geometry (geometry
        :width 512
        :height 512
        :anchor "bottom left"
    )
  (box
    (button 'foo')
    (button 'bar')
  ) 
)

and eww logs is outputting

 2024-01-31T22:09:52.234Z INFO  eww::app        > Opening window giftests
 2024-01-31T22:09:53.153Z INFO  eww::app        > Closing gtk window giftests
 2024-01-31T22:09:55.000Z INFO  eww::app        > Opening window control
 2024-01-31T22:09:55.808Z INFO  eww::app        > Closing gtk window control

The sizing does definitely seem to be an issue though.

Ora9 commented 9 months ago

what sort of output were you expecting from eww logs?

I didn't expected much, but maybe an internal error from the image handler

Ora9 commented 9 months ago

I think i found the issue in code :

https://github.com/elkowar/eww/blob/master/crates/eww/src/widgets/widget_definitions.rs#L521

const WIDGET_NAME_IMAGE: &str = "image";
/// @widget image
/// @desc A widget displaying an image
fn build_gtk_image(bargs: &mut BuilderArgs) -> Result<gtk::Image> {
    let gtk_widget = gtk::Image::new();
    def_widget!(bargs, _g, gtk_widget, {
        // @prop path - path to the image file
        // @prop image-width - width of the image
        // @prop image-height - height of the image
        prop(path: as_string, image_width: as_i32 = -1, image_height: as_i32 = -1) {
            if path.ends_with(".gif") {
                let pixbuf_animation = gtk::gdk_pixbuf::PixbufAnimation::from_file(std::path::PathBuf::from(path))?;
                gtk_widget.set_from_animation(&pixbuf_animation);
            } else {
                let pixbuf = gtk::gdk_pixbuf::Pixbuf::from_file_at_size(std::path::PathBuf::from(path), image_width, image_height)?;
                gtk_widget.set_from_pixbuf(Some(&pixbuf));
            }
        }
    });
    Ok(gtk_widget)
}

If the file ends in .gif, an animation is created with no reference to image_width or image_height parameters (PixbufAnimation::from_file), but if the file is not a gif, Pixbuf::from_file_at_size is used and is passed the two values

Localghost385 commented 9 months ago

Yeah, I saw that, but there is no equivalent resizing function for the pixbuf_animation, and I couldn't find good docs for it.