Gtk-Rs 3 : how to connect to window resized event?

I am trying to execute code when my main window is been resized, but I don’t find on which event I must connect.

I’ve been looking at Window and some of its implementations (such as GtkWindowExt).

You can connect to both of its properties; default-witdh and default-height (if they exist in GTK3, they do in GTK4).

1 Like

Thank you, but those are properties, not signals I can connect to in order to get noticed when the window will be resized.

I’ve found. I need to connect to the size-allocate event. The new position and size will be contained in the given Allocation instance.

You can connect to property changes. You just use notify::<property-name> as a signal name.

In fact I’ve connected to this event using the connect_size_allocate from gtk-rs 3.

I’ve just written size_allocate because I’m using Relm, a framework which simplifies the development of gtk3 applications in Rust.

If you are still skeptical, just try for yourself. Because I’ve managed this way.

Using the size allocation signal is fine with GTK3. The signal was removed in GTK4 as it was a crutch that people used in lieu of properly subclassing widgets, and introduced a performance bottleneck.

When porting your code to relm4, you will need to use the default-width and default-height properties to know the size of your window.

You have not been very clear as to what code you’re executing when the window size changes; just be aware that you should not cause a layout update from inside a handler of the size-allocate signal, as that is going to cause a layout cycle.

1 Like

Thank you very much :slight_smile:

Indeed, I was not aware of this difference and deprecation in Gtk 4.

So I’m apologizing for having had a doubt about the first reply.

The fact also is that I’ve always used signals (starting from connect_* in gtk rs 3) in order to manage event.
I’m happy to learn now that’s there is a new way to get notified. :smiley:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.