From 420ed353b53bd624331bd249d7df98d14714b504 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Fri, 7 Aug 2009 08:18:17 +0100 Subject: [PATCH] [x11] Do not ask to destroy an empty Window The fix for bug 1750 inside commit b190448e made Clutter-GTK spew BadWindow errors. The reason for that is that we call XDestroyWindow() without checking if the old Window is None; this happens if we call clutter_x11_set_stage_foreign() on a new ClutterStage before it has been realized. Since Clutter-GTK does not need to realize the Stage it is going to embed anymore (the only reason for that was to obtain a proper Visual but now there's ClutterBackendX11 API for that), the set_stage_foreign() call is effectively setting the StageX11 Window for the first time. --- clutter/x11/clutter-stage-x11.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/clutter/x11/clutter-stage-x11.c b/clutter/x11/clutter-stage-x11.c index b2182467f..178a8cac2 100644 --- a/clutter/x11/clutter-stage-x11.c +++ b/clutter/x11/clutter-stage-x11.c @@ -790,10 +790,15 @@ set_foreign_window_callback (ClutterActor *actor, { ForeignWindowData *fwd = data; - CLUTTER_NOTE (BACKEND, "Setting foreign window (0x%x)", (int) fwd->xwindow); + CLUTTER_NOTE (BACKEND, "Setting foreign window (0x%x)", + (unsigned int) fwd->xwindow); - if (fwd->destroy_old_xwindow) - XDestroyWindow (fwd->stage_x11->xdpy, fwd->stage_x11->xwin); + if (fwd->destroy_old_xwindow && fwd->stage_x11->xwin != None) + { + CLUTTER_NOTE (BACKEND, "Destroying previous window (0x%x)", + (unsigned int) fwd->xwindow); + XDestroyWindow (fwd->stage_x11->xdpy, fwd->stage_x11->xwin); + } fwd->stage_x11->xwin = fwd->xwindow; fwd->stage_x11->is_foreign_xwin = TRUE; @@ -862,8 +867,13 @@ 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; + + /* destroy the old Window, if we have one and it's ours */ + if (stage_x11->xwin != None && !stage_x11->is_foreign_xwin) + fwd.destroy_old_xwindow = TRUE; + else + fwd.destroy_old_xwindow = FALSE; + fwd.geom.x = x; fwd.geom.y = y; fwd.geom.width = width;