GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Sat Aug 23, 2014 7:28 am

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Bug in GTK, or Metacity?
PostPosted: Mon Feb 20, 2012 9:16 am 
Offline
Familiar Face

Joined: Wed Aug 17, 2011 12:20 pm
Posts: 20
I have some windows of type GtkWindow, which as the only child have a GtkDrawingArea. I want them resizable, but with fixed aspect ratio. The aspect ratio varies amongst the windows, though. I use
Code:
hints.min_width = min_width;
hints.min_height = min_height;
hints.min_aspect = hints.max_aspect = (float) min_width / min_height;
gtk_window_set_geometry_hints (GTK_WINDOW (window), drawing_area, &hints, GDK_HINT_MIN_SIZE | GDK_HINT_ASPECT);
to achieve this.
It seems to work ok with aspect ratios around 1.5. With high aspect ratios (7 ... 10) I observe a strange behaviour. The window is opened with the min_height as the height of the drawing area, but is about 50% wider than expected. When I try to enlarge it by re-sizing, it keeps this (wrong) aspect ratio, enlarging width and height simultaneously. I can also re-size it to make it smaller, in this case the height stays the same and only the width decreases until it's at min_width. Enlarging again, again only the width increases until that width is reached the freshly opened window was wide, then suddenly the height also increases as to keep the now reached (wrong) aspect ratio.
Anybody heard of or seen this behaviour before? Could it be a bug in GTK or the window manager? I'm working with Ubuntu Karmic, with GTK v2.18 under Metacity. I realize these are kind of outdated components for which no bugfix can be expected, but I want to know where this comes from.
BTW I'm not talking about inaccuracies due to rounding, the effect is large. With min_width = 300 und min_height = 30 I get a window with a drawing area that is 30 pixels tall but 408 pixels wide.


Top
 Profile  
 
 Post subject: Re: Bug in GTK, or Metacity?
PostPosted: Mon Feb 20, 2012 9:52 am 
Offline
Familiar Face

Joined: Wed Aug 17, 2011 12:20 pm
Posts: 20
Ok, I've narrowed it down. I stripped my code down to the relevant pieces to demonstrate the effect, getting rid of more and more stuff until the problem went away. The critical bit is setting a window border:
Code:
gtk_container_set_border_width (GTK_CONTAINER (window), 6);
If I comment this line in the code below, the drawing area sits snug in the window, without borders, but with proper initial size, and the re-sizing works properly now. It appears to me GTK cannot deal properly with hints with these borders, if the aspect ratio too high. I have ruled out the window manager by running this test code in a session without window manager. There, I cannot re-size but I can clearly tell the window is opened again with the same excessive width, and wrong aspect ratio.

Here is the demonstrator:
Code:
#include <gtk/gtk.h>

typedef struct
{
     float  min_width, min_height;
  } WININFO;


void  destroy_handler (GtkObject *object, gpointer meter)
{
   gtk_main_quit();
}

void  create (WININFO *info)
{
   GtkWidget    *window, *drawing_area;
   GdkGeometry  hints;

   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
   gtk_window_set_resizable (GTK_WINDOW (window), TRUE);
   gtk_container_set_border_width (GTK_CONTAINER (window), 6);
   g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (destroy_handler), info);
   drawing_area = gtk_drawing_area_new();
   gtk_container_add (GTK_CONTAINER (window), drawing_area);
   hints.min_width  = info->min_width;
   hints.min_height = info->min_height;
   hints.min_aspect = hints.max_aspect = (float) info->min_width / info->min_height;
   gtk_window_set_geometry_hints (GTK_WINDOW (window), drawing_area, & hints, GDK_HINT_MIN_SIZE | GDK_HINT_ASPECT);
   gtk_widget_show_all (window);
}

int main(int argc, char*argv[])

{
   WININFO  info;

   info.min_width = 300;
   info.min_height = 30;
   gtk_init (& argc, & argv);
   create (& info);
   gtk_main();
   return 0;
}
The code is built with
Code:
gcc test.c `pkg-config gtk+-2.0 --cflags --libs`


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group