Re: Re: GdkWindow ref counting

On Fri, 2006-11-03 at 11:20 +0200, Johan Bilien wrote:

> Let me try to explain the usecase: the code is from the Task Navigator
> on the Hildon Desktop. We are trying to keep track of all the top-level
> window creation and destruction. When we detect (from the WM client
> list) that a new window has appeared, we need to install an event filter
> on it. We use the following code:
>   gdk_wrapper_win = gdk_window_foreign_new
> (hn_wm_watched_window_get_x_win(win));
>   if (gdk_wrapper_win != NULL)
>     {
>       /* Monitor the window for prop changes */
>       gdk_window_set_events(gdk_wrapper_win,
>                 gdk_window_get_events(gdk_wrapper_win)
>                 | GDK_PROPERTY_CHANGE_MASK);
>       gdk_window_add_filter(gdk_wrapper_win,
>                 hn_wm_x_event_filter,
>                 NULL);
>     }
> Now what would be the correct way to dispose of this GdkWindow?
> Currently, when the window disappears from the WM's client list, we
> called gdk_window_destroy () on the window. But the refcount at this
> point seems to be quite unpredictable, and we end up leaking the object.

Replace the gdk_window_set_events() above with the equivalent
X code (XGetWindowAttributes/your_event_mask/XSelectInput) and also
include StructureNotifyMask.
						- Owen

(You could probably pretty safely optimize that by checking if the
window is foreign, then if so, 
  XSelectInput(xdisplay, window, 
               PropertyChangeMask | StructureNotifyMask);
but using XGetWindowAttributes() is a little more theoretically

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