Re: How to be notified before GdkWindow is destroyed

Gustavo Joćo Alves Marques Carneiro <ee96090 fe up pt> writes:

> On 13 May 2001, Havoc Pennington wrote:
> > 
> > Gustavo Joćo Alves Marques Carneiro <ee96090 fe up pt> writes:
> > >   I have a GtkDrawingArea widget on which I'm using an external library
> > > (libplot) to draw directly to widget->window. I need to receive a
> > > notification when the widget is about to be destroyed but *before* the
> > > GdkWindow is destroyed, because libplot is still using the window.
> > > 
> > >   Which signal should I connect to? I already tried "destroy" and
> > > "unrealize", but those happen too late---the window is already destroyed.
> > > I also tried to keep a reference to the GdkWindow (with g_object_ref) to
> > > prevent it from being destroyed, but it didn't work. Any idea will be
> > > deeply appreciated.
> > > 
> > 
> > "unrealize" would normally work except that probably the window gets
> > implicitly blown away when the toplevel GtkWindow is unrealized. 
> > So maybe unmap_event or "unrealize" on the toplevel?
>   Shouldn't the child widget's window be unrealized before the parent?
> Can't GTK be changed to force child widgets to be unrealized before their
> parents? It would really make programming this sort of thing much more
> elegant, and it has more logic: child widgets should be destroyed before
> their parents. I'd really like to make a self-contained library that
> doesn't depend on the widget's parent at all.

Snippet from gtkwidget.c:gtk_widget_real_unrealize:

   /* We must do unrealize child widget BEFORE container widget.
    * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
    * So, unrealizing container widget bofore its children causes the problem 
    * (for example, gdk_ic_destroy () with destroyed window causes crash. )

  if (GTK_IS_CONTAINER (widget))
    gtk_container_forall (GTK_CONTAINER (widget),
			  (GtkCallback) gtk_widget_unrealize,

  gtk_style_detach (widget->style);
  if (!GTK_WIDGET_NO_WINDOW (widget))
      gdk_window_set_user_data (widget->window, NULL);
      gdk_window_destroy (widget->window);
      widget->window = NULL;
      gdk_window_unref (widget->window);
      widget->window = NULL;

So, the general ordering in GTK+ _is_ to unrealize children before

Note that some container widgets don't preserve this order, e.g.
gtk_viewport_unrealize - if someone wanted to go through the devel
branch of GTK+, find all these instances, and submit a bug to listing them, that could be useful.


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