Re: Tricky resizing problem




Matt Carlson <mindbender@lokigames.com> writes:

> I've been stewing over this for a bit and can't seem to come up with a
> reasonable answer.
> 
> I am working on a program that has a menubar and a drawing area in the
> main window.  When the user attempts to resize the window, the program
> obtains the new dimensions, calculates the closest size among several
> predetermined sizes, and resizes the window to the result of the
> analysis.  My problem is that the newly calculated size is intended for
> the drawing area and not the window.  Is there a way to resize a window
> around the new size of the widgets it contains?  If not, how can I
> obtain the information to determine this "manually"?

Trying to constrain a users ability to change the size
of a window after the fact is a bad idea in X. 
Especially if the user has enabled opaque resizing in
their window manager, the effect will be that your
program will fight with the user for the right window
size, to bad effect.

You should just accept the users choice, and add some
padding if necessary.

That being said, there is some ability to tell the window
manager about what sizes are permissable. The call you
want here is:

void gtk_window_set_geometry_hints (GtkWindow           *window,
                                    GtkWidget           *geometry_widget,
                                    GdkGeometry         *geometry,
                                    GdkWindowHints       geom_mask);

By setting geometry_widget to your drawing area, you tell
GTK+ to compute the hints for the toplevel based on the
hints you give for a widget within the toplevel.

Within the geometry argument, you can set:

 1) a desired aspect ratio
 2) an arithmetic progression of allowed sizes.

The interpretation of all this is a bit unclear in the
ICCCM, so the effect may be somewhat window manager
dependent.

Also note that there are some bugs and holes in 
this code for GTK+-1.2.0 - GTK+-1.2.3. We are currently
working on fixing things up nicely for 1.2.4, but
you may want to test things out with earlier versions
if you expect your customers to be using these versions.

Regards,
                                        Owen


 



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