File destroywin-2.patch of Package ami

diff -ru ami-1.2.3.orig/src/dispwin.c ami-1.2.3/src/dispwin.c
--- ami-1.2.3.orig/src/dispwin.c	2003-03-28 08:48:30.000000000 +0100
+++ ami-1.2.3/src/dispwin.c	2004-05-28 15:58:08.222735323 +0200
@@ -266,6 +266,16 @@
 }
 #endif
 
+static gboolean is_client_win_dead;
+
+static int
+client_bad_window_handler (Display *disp, XErrorEvent *err)
+{
+    is_client_win_dead = TRUE;
+    if (debug) g_print ("client_win is already dead.\n");
+    return 0;
+}
+
 static GdkFilterReturn
 dw_event_filter(XEvent *xev, GdkEvent *ev, DispWindow *dw)
 {
@@ -274,7 +284,42 @@
 	return GDK_FILTER_REMOVE;
     }
     if (xev->xany.type == DestroyNotify) {
-	ic_destroy(dw->ic);
+	Window win;
+	GdkWindow *destroy, *parent;
+
+	{
+	  XWindowAttributes client_win_attr;
+	  XErrorHandler old;
+	  Status status;
+
+	  is_client_win_dead = FALSE;
+	  old = XSetErrorHandler (client_bad_window_handler);
+	  status = XGetWindowAttributes (GDK_DISPLAY(),
+	      GDK_WINDOW_XWINDOW(dw->ic->client_win), &client_win_attr);
+	  (void) XSetErrorHandler (old);
+	}
+
+	win = xev->xany.window;
+	if (debug) g_print ("Destroy: xwin=%#lx\n", win);
+
+	destroy = gdk_window_lookup (win);
+	if (destroy != NULL) {
+	    if (debug)  g_print ("Destroy: gdkwin=%p\n", destroy);
+
+	    parent = gdk_window_get_parent (destroy);
+	    if (parent != NULL) {
+		if (debug) g_print ("Parent : xwin=%#lx, gdkwin=%p\n", GDK_WINDOW_XWINDOW (parent), parent);
+		
+		if (is_client_win_dead || parent == dw->ic->client_win)
+		  ic_destroy(dw->ic); 
+		else {
+		    dw->ic->focus_win = NULL;
+		    dw->win = NULL;
+		    if (dw->ic->edit_win != NULL)
+		      dw_set_parent (dw->ic->edit_win, dw->ic->client_win);
+		}
+	    }
+	}
 	return GDK_FILTER_REMOVE;
     }
     return GDK_FILTER_CONTINUE;
openSUSE Build Service is sponsored by