[x11] Destroy the Window we own when setting a foreign one
authorEmmanuele Bassi <ebassi@linux.intel.com>
Tue, 4 Aug 2009 15:59:15 +0000 (16:59 +0100)
committerEmmanuele Bassi <ebassi@linux.intel.com>
Tue, 4 Aug 2009 15:59:15 +0000 (16:59 +0100)
When we replace the stage Window using a foreign one we also need to
destroy the Window we created, if needed, to avoid leaking resources
all around.

Fixes bug:

  http://bugzilla.openedhand.com/show_bug.cgi?id=1750

clutter/x11/clutter-stage-x11.c

index 78d08c7..b218246 100644 (file)
@@ -781,6 +781,7 @@ typedef struct {
   ClutterStageX11 *stage_x11;
   ClutterGeometry geom;
   Window xwindow;
+  guint destroy_old_xwindow : 1;
 } ForeignWindowData;
 
 static void
@@ -791,6 +792,9 @@ set_foreign_window_callback (ClutterActor *actor,
 
   CLUTTER_NOTE (BACKEND, "Setting foreign window (0x%x)", (int) fwd->xwindow);
 
+  if (fwd->destroy_old_xwindow)
+    XDestroyWindow (fwd->stage_x11->xdpy, fwd->stage_x11->xwin);
+
   fwd->stage_x11->xwin = fwd->xwindow;
   fwd->stage_x11->is_foreign_xwin = TRUE;
 
@@ -858,6 +862,8 @@ clutter_x11_set_stage_foreign (ClutterStage *stage,
 
   fwd.stage_x11 = stage_x11;
   fwd.xwindow = xwindow;
+  /* destroy the old Window, if we own it */
+  fwd.destroy_old_xwindow = stage_x11->is_foreign_xwin ? FALSE : TRUE;
   fwd.geom.x = x;
   fwd.geom.y = y;
   fwd.geom.width = width;