Re: [gtk-list] Re: more widget size problems/questions




On Sun, 20 Jun 1999, brent verner wrote:
> 
> what i am trying to do is come up with a way of positioning the
> new window within the boundary of the parent window to replace
> gtk_window_position(), as _i_ think it would be nice. if gtk has
> now way of doing this at this time, i'm more than willing to 
> *attempt* to add this functionality to gtk, so let me know where
> to start looking in gtk to add this functionality -- if this
> is possible.
> 

This code is in Gnome:

void       gnome_dialog_set_parent     (GnomeDialog * dialog,
                                        GtkWindow   * parent)
{
  /* This code is duplicated in gnome-file-entry.c:browse-clicked.  If
   * a change is made here, update it there too. */
  /* Also, It might be good at some point to make the first argument
   * GtkWidget, instead of GnomeDialog */
  g_return_if_fail(dialog != NULL);
  g_return_if_fail(GNOME_IS_DIALOG(dialog));
  g_return_if_fail(parent != NULL);
  g_return_if_fail(GTK_IS_WINDOW(parent));
  g_return_if_fail(parent != GTK_WINDOW(dialog));

  gtk_window_set_transient_for (GTK_WINDOW(dialog), parent);

  if ( gnome_preferences_get_dialog_centered() ) {

    /* User wants us to center over parent */

    gint x, y, w, h, dialog_x, dialog_y;

    if ( ! GTK_WIDGET_VISIBLE(parent)) return; /* Can't get its
                                                  size/pos */

    /* Throw out other positioning */
    gtk_window_set_position(GTK_WINDOW(dialog),GTK_WIN_POS_NONE);

    gdk_window_get_origin (GTK_WIDGET(parent)->window, &x, &y);
    gdk_window_get_size   (GTK_WIDGET(parent)->window, &w, &h);

    /* The problem here is we don't know how big the dialog is.
       So "centered" isn't really true. We'll go with 
       "kind of more or less on top" */

    dialog_x = x + w/4;
    dialog_y = y + h/4;

    gtk_widget_set_uposition(GTK_WIDGET(dialog), dialog_x, dialog_y); 
  }
}

As you can see, it punts on the issue. The "gratuitous frame" hack...
we'll it's a big hack. :-) The fact is that it doesn't really work,
because a GtkWindow does not know its size until it tries to map (show),
and the window manager can give it a smaller size if it wants. In
practice, I can't think of a window manager that does this, but that's
probably why Gtk is the way it is. 

Actually, window managers are supposed to do this in a session-management
situation; they will record that the user has resized the window, and
restore its size. So, if the user had resized the window, the frame will
get more or less than its size request. This is something that most WM's
should be starting to support. (maybe irrelevant for transient dialogs
though.)

Anyway, if your GtkWindow does not receive its full size request, then the
GtkFrame will not get the size it wants. size request is only a request;
it's not an allocation.

It's also problematic that user's can't configure where dialogs go, as
they can in Gnome.

Anyway, I'm sure your code will work most of the time for now, but you
should know that from a design point of view it's the Wrong Thing and
might not work quite right forever because you're relying on
non-guaranteed behavior. If someone can suggest a reliable way of doing
this that would be great, and we'll fix that Gnome function too, but I
don't think there's any way around the fact the the window manager can
(and in some cases should) resize the window as it's being mapped.
Most likely the WM should be doing this centering; maybe we will add a
hint to the KDE/Gnome window manager spec for that purpose.

FWIW,
Havoc







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