Search code examples
windowgtkheightwidthvala

Gtk.window get window width and height with VALA


I am trying to create a small program which displays an Image. This image will be resized to fit the window size. Until now you can already see the image on the screen but to make it change its size when resizing the window I have to know how to get the window width and height of my Window. The problem is, I havent found a good way to do this... and would like to know if somebody could help me with that.

(I am programming with vala in elementary os if that is necessary to know)

I can also post my code if that would help


Solution

  • Here is a simple example to get the width and Height of the window when it resizes. On the signal you can do stuff like resizing the child image pixbuf/image or whatever. Hope it helps.

    using Gtk;
    
    public void main (string[] args) {
        Gtk.init (ref args);
    
        var window = new Gtk.Window ();
    
        window.configure_event.connect ((event) => {
            print ("Width: %d Height: %d\n", event.width, event.height);
            return false;
        });
    
        window.destroy.connect (Gtk.main_quit);
    
        window.show_all ();
    
        Gtk.main ();
    }