[comp.windows.x] twm orphan windows patch

toml@Solbourne.COM (Tom LaStrange) (04/27/89)

Enclosed is a patch that fixes the X11R3 twm problem of leaving
orphan windows around if a client dies or goes away during the
reparenting process.

--
Tom LaStrange

Solbourne Computer Inc.    ARPA: toml@Solbourne.COM
Longmont, CO               UUCP: ...!{boulder,nbires,sun}!stan!toml

----------------------------------
diff -c orig//add_window.c ./add_window.c
*** orig//add_window.c	Thu Apr 27 08:29:13 1989
--- ./add_window.c	Thu Apr 27 08:32:16 1989
***************
*** 338,343 ****
--- 338,360 ----
      tmp_win->icon = FALSE;
      tmp_win->icon_on = FALSE;
  
+     XGrabServer(dpy);
+ 
+     /*
+      * Make sure the client window still exists.  We don't want to leave an
+      * orphan frame window if it doesn't.  Since we now have the server
+      * grabbed, the window can't disappear later without having been
+      * reparented, so we'll get a DestroyNotify for it.  We won't have
+      * gotten one for anything up to here, however.
+      */
+     if (XGetGeometry(dpy, tmp_win->w, &JunkRoot, &JunkX, &JunkY,
+                      &JunkWidth, &JunkHeight, &JunkBW, &JunkDepth) == 0)
+     {
+         free((char *)tmp_win);
+         XUngrabServer(dpy);
+         return(NULL);
+     }
+ 
      /* add the window into the twm list */
      tmp_win->next = TwmRoot.next;
      if (TwmRoot.next != NULL)
diff -c orig//events.c ./events.c
*** orig//events.c	Thu Apr 27 08:29:14 1989
--- ./events.c	Thu Apr 27 08:31:21 1989
***************
*** 656,661 ****
--- 656,663 ----
  	}
  
  	tmp_win = AddWindow(w);
+ 	if (tmp_win == NULL)
+ 		return;
  	if (tmp_win->wmhints && (tmp_win->wmhints->flags & StateHint))
  	{
  	    switch (tmp_win->wmhints->initial_state)