Repost: Resizing and Moving a GtkWindow doesn't work



Hi,

Sorry about reposting this.  I didn't receive any responses to this
message I sent last week on this list, so maybe my earlier message was
missed by the list members.  I would really appreciate if I can get
some any tips on the problem I'm facing!!

In my application I need to resize and move a GtkWindow to a new
location, and I'm using the gtk_window_resize() and gtk_window_move()
APIs for the purpose.  However, these APIs do not work sometimes.

For example, refer my sample program at the end of this mail.  If the
initial location of my window is say 0,0 and I stretch the height of
the window to occupy almost the entire screen height, and then I press
"Move And Resize", then the new location of the window comes as : left
= 200, top = 35, right = 600, bottom = 435.

That is obviously incorrect.  The expected result is: left = 200, top
= 200, right = 600, bottom = 600

This problem does not occur when the initial window size is smaller,
but starts happening when the window size is increased to large values
(covering almost entire screen).

Another interesting thing that I found is an undocumented GTK API :
gtk_decorated_window_move_resize_window() which is giving correct
results for all cases.  However, I cannot (and do not want to) use an
undocumented API.

Is there a proper way to get correct results from GTK?

Thanks in advance.
Gaurav

----- sample program ------
#include <gtk/gtk.h>

static void button_clicked( GtkWidget *widget, gpointer   data )
{
       GtkWidget *window = (GtkWidget *)data;
       gtk_window_unmaximize(GTK_WINDOW(window));

       gtk_window_resize(GTK_WINDOW(window), 400, 400);
       gtk_window_move(GTK_WINDOW(window), 200, 200);
}

gint resize_event(GtkWidget *widget, GtkAllocation *allocation,
gpointer clientData)
{
       gint x, y;
       gtk_window_get_position(GTK_WINDOW(widget), &x, &y);
       printf("resize_event, left = %d, top = %d, right = %d, bottom
= %d [%d X %d]\n",
               x, y, x + allocation->width, y + allocation->height,
               allocation->width, allocation->height);
       return FALSE;
}

int main( int   argc,
         char *argv[] )
{
   GtkWidget *window;
   GtkWidget *button;

   gtk_init (&argc, &argv);

   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

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

   button = gtk_button_new_with_label ("Move And Resize");

   g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK
(button_clicked), window);

   gtk_container_add (GTK_CONTAINER (window), button);

   gtk_widget_show (button);

   gtk_widget_show (window);

   gtk_main ();

   return 0;
}



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