How to get width and height while resizing window?



#include <gtk/gtk.h>

How to get width and height while resizing window?

I used size-allocate event as in the test program below:


static gboolean szalloccallback ( GtkWidget * w,
                                  GtkAllocation * a,
                                  char * data )
   {
 printf ( " szalloc (x,y)=(%d,%d) (w,h)=(%d,%d)\n" ,
          a->x , a->y , a->width , a->height ) ;
   return false;
   }

int main ( int argc , char * argv[] )
   {
   gtk_init(&argc, &argv);

   GtkWidget * window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
   gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
   gtk_window_set_default_size(GTK_WINDOW(window), 250, 180);
   gtk_window_set_title(GTK_WINDOW(window), "Testing");

   g_signal_connect(window, "size-allocate" ,
                    G_CALLBACK (szalloccallback), NULL);

   gtk_widget_show_all(window);
   gtk_main();

   return 0;
   }

and found that the size-allocate callback was always called twice with the same parameters. For example, got the following when increasing the height:

 szalloc (x,y)=(0,0) (w,h)=(250,181)
 szalloc (x,y)=(0,0) (w,h)=(250,181)
 szalloc (x,y)=(0,0) (w,h)=(250,182)
 szalloc (x,y)=(0,0) (w,h)=(250,182)
 szalloc (x,y)=(0,0) (w,h)=(250,183)
 szalloc (x,y)=(0,0) (w,h)=(250,183)
 szalloc (x,y)=(0,0) (w,h)=(250,184)
 szalloc (x,y)=(0,0) (w,h)=(250,184)

I don't understand why there is a second call. Of course I only need one. How can I stop the second?

OR is there a better way, perhaps using different signals, to get
width and height while resizing a window?

Ken




Get your new Email address!
Grab the Email name you've always wanted before someone else does!

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]