diff -ru xwin78/win.h xwin/win.h
--- xwin78/win.h	Sat Jan 25 01:34:16 2003
+++ xwin/win.h	Sat Mar  8 10:32:57 2003
@@ -483,6 +483,8 @@
   /* Privates used by multi-window server */
   pthread_t		ptWMProc;
   void			*pWMInfo;
+  Bool                  fWindowOrderChanged;
+  Bool                  fRestacking;
 
   /* Privates used for any module running in a seperate thread */
   pthread_mutex_t	pmServerStarted;
@@ -1408,6 +1410,9 @@
 void
 winSetShapeMultiWindow (WindowPtr pWindow);
 #endif
+
+void
+winReorderWindowsMultiWindow (ScreenPtr pScreen);
 
 
 /*
diff -ru xwin78/winblock.c xwin/winblock.c
--- xwin78/winblock.c	Sat Jan 25 00:55:14 2003
+++ xwin/winblock.c	Sat Mar  8 10:32:57 2003
@@ -73,4 +73,5 @@
 	  DispatchMessage (&msg);
 	}
     }
+    winReorderWindowsMultiWindow ((ScreenPtr)pBlockData);
 }
diff -ru xwin78/winmultiwindowwindow.c xwin/winmultiwindowwindow.c
--- xwin78/winmultiwindowwindow.c	Thu Jan 23 01:59:46 2003
+++ xwin/winmultiwindowwindow.c	Sat Mar  8 12:26:49 2003
@@ -49,13 +49,19 @@
 static XID
 winGetWindowID (WindowPtr pWin);
 
-static void
-SendConfigureNotify (WindowPtr pWin);
-
 static
 void
 winUpdateRgn (WindowPtr pWindow);
 
+static void
+winMoveXWindow (WindowPtr pWin, int x, int y);
+
+static void
+winResizeXWindow (WindowPtr pWin, int w, int h);
+
+static void
+winRestackXWindow (WindowPtr pWin, int smode);
+
 #ifdef SHAPE
 static
 void
@@ -376,6 +382,7 @@
   WindowPtr		pPrevWin;
   UINT			uFlags;
   HWND			hInsertAfter;
+  HWND                  hWnd = NULL;
   winWindowPriv(pWin);
 
 #if CYGMULTIWINDOW_DEBUG
@@ -387,6 +394,9 @@
     winGetScreenPriv(pWin->drawable.pScreen)->RestackWindow (pWin,
 							     pOldNextSib);
   
+  if (winGetScreenPriv(pWin->drawable.pScreen)->fRestacking)
+    return;
+
   /* Bail out if no window privates or window handle is invalid */
   if (!pWinPriv || !pWinPriv->hWnd)
     return;
@@ -409,6 +419,22 @@
       /* Valid sibling - get handle to insert window after */
       hInsertAfter = winGetWindowPriv(pPrevWin)->hWnd;
       uFlags = SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE;
+  
+      hWnd = GetNextWindow (pWinPriv->hWnd, GW_HWNDPREV);
+
+      do
+	{
+	  if (GetProp (hWnd, WIN_WINDOW_PROP))
+	    {
+	      if (hWnd == winGetWindowPriv(pPrevWin)->hWnd)
+		{
+		  uFlags |= SWP_NOZORDER;
+		}
+	      break;
+	    }
+	  hWnd = GetNextWindow (hWnd, GW_HWNDPREV);
+	}
+      while (hWnd);
     }
   else
     {
@@ -629,6 +655,7 @@
   DrawablePtr		pDraw = NULL;
   int		        iX, iY, iWidth, iHeight, iBorder;
   winWMMessageRec	wmMsg;
+  Bool                  fWMMsgInitialized = FALSE;
   static Bool		s_fTracking = FALSE;
   static Bool           s_fCursor = TRUE;
   
@@ -668,7 +695,7 @@
       wmMsg.iWidth	= pDraw.width;
       wmMsg.iHeight	= pDraw.height;
 #endif
-
+      fWMMsgInitialized = TRUE;
 
 #if 0
       /*
@@ -973,22 +1000,16 @@
       /* Pass the message to the root window */
       SendMessage (hwndScreen, message, wParam, lParam);
 
-      /* Bail if inactivating */
-      if (LOWORD(wParam) == WA_INACTIVE)
-	return 0;
+      if (s_pScreenPriv != NULL)
+	s_pScreenPriv->fWindowOrderChanged = TRUE;
 
-      /* Check if the current window is the active window in Windows */
-      if (GetActiveWindow () == hwnd)
+      if (LOWORD(wParam) != WA_INACTIVE)
 	{
-	  /* Tell our Window Manager thread to raise the window */
-	  wmMsg.msg = WM_WM_RAISE;
-	  winSendMessageToWM (s_pScreenPriv->pWMInfo, &wmMsg);
+	  /* Tell our Window Manager thread to activate the window */
+	  wmMsg.msg = WM_WM_ACTIVATE;
+	  if (fWMMsgInitialized)
+	    winSendMessageToWM (s_pScreenPriv->pWMInfo, &wmMsg);
 	}
-      
-      /* Tell our Window Manager thread to activate the window */
-      wmMsg.msg = WM_WM_ACTIVATE;
-      winSendMessageToWM (s_pScreenPriv->pWMInfo, &wmMsg);
-	  
       return 0;
 
     case WM_ACTIVATEAPP:
@@ -1016,7 +1037,8 @@
 	{
 	  /* Tell our Window Manager thread to kill the window */
 	  wmMsg.msg = WM_WM_KILL;
-	  winSendMessageToWM (s_pScreenPriv->pWMInfo, &wmMsg);
+	  if (fWMMsgInitialized)
+	    winSendMessageToWM (s_pScreenPriv->pWMInfo, &wmMsg);
 	}
       return 0;
 
@@ -1032,7 +1054,8 @@
 	  
 	  /* Tell our Window Manager thread to kill the window */
 	  wmMsg.msg = WM_WM_KILL;
-	  winSendMessageToWM (s_pScreenPriv->pWMInfo, &wmMsg);
+	  if (fWMMsgInitialized)
+	    winSendMessageToWM (s_pScreenPriv->pWMInfo, &wmMsg);
 	}
 
 #if CYGMULTIWINDOW_DEBUG
@@ -1058,16 +1081,9 @@
       ErrorF ("\t(%d, %d)\n", pWinPriv->iX, pWinPriv->iY);
 #endif
 
-      /* Notify the X client that its window is moving */
-      if (SubStrSend(pWin, pWin->parent))
-	SendConfigureNotify (pWin);
-
-      /* Tell X that the window is moving */
-      (s_pScreen->MoveWindow) (pWin,
-			       (int)(short) LOWORD(lParam) - wBorderWidth (pWin),
-			       (int)(short) HIWORD(lParam) - wBorderWidth (pWin),
-			       pWin->nextSib,
-			       VTMove);
+      winMoveXWindow (pWin,
+		      LOWORD(lParam) - wBorderWidth (pWin),
+		      HIWORD(lParam) - wBorderWidth (pWin));
       return 0;
 
     case WM_SHOWWINDOW:
@@ -1154,13 +1170,11 @@
       wmMsg.iHeight = pWinPriv->iHeight;
 
       /* Tell our Window Manager thread to map the window */
-      winSendMessageToWM (s_pScreenPriv->pWMInfo, &wmMsg);
-
-      /* Setup the Window Manager message */
-      wmMsg.msg = WM_WM_RAISE;
+      if (fWMMsgInitialized)
+	winSendMessageToWM (s_pScreenPriv->pWMInfo, &wmMsg);
 
-      /* Tell our Window Manager thread to raise the window */
-      winSendMessageToWM (s_pScreenPriv->pWMInfo, &wmMsg);
+      if (s_pScreenPriv != NULL)
+	s_pScreenPriv->fWindowOrderChanged = TRUE;
       return 0;
 
     case WM_SIZE:
@@ -1176,11 +1190,8 @@
 #if CYGMULTIWINDOW_DEBUG
 	  ErrorF ("\tSIZE_MINIMIZED\n");
 #endif
-	  
-	  wmMsg.msg = WM_WM_LOWER;
-
-	  /* Tell our Window Manager thread to lower the window */
-	  winSendMessageToWM (s_pScreenPriv->pWMInfo, &wmMsg);
+	  if (s_pScreenPriv != NULL)
+	    s_pScreenPriv->fWindowOrderChanged = TRUE;
 	  break;
 
 	case SIZE_RESTORED:
@@ -1197,50 +1208,9 @@
 	  ErrorF ("\t(%d, %d)\n", pWinPriv->iWidth, pWinPriv->iHeight);
 #endif
 
-	  /* Check if resize events are redirected */
-	  if ((pWin->eventMask | wOtherEventMasks (pWin)) & ResizeRedirectMask)
-	    {
-	      xEvent		eventT;
-
-	      /* Setup the X event structure */
-	      eventT.u.u.type = ResizeRequest;
-	      eventT.u.resizeRequest.window = pWin->drawable.id;
-	      eventT.u.resizeRequest.width = pWinPriv->iWidth;
-	      eventT.u.resizeRequest.height = pWinPriv->iHeight;
-
-	      /* */
-	      if (MaybeDeliverEventsToClient (pWin, &eventT, 1,
-					      ResizeRedirectMask,
-					      wClient(pWin)) == 1)
-		break;
-	    }
-
-	  /* Notify the X client that its window is being resized */
-	  if (SubStrSend (pWin, pWin->parent))
-	    SendConfigureNotify (pWin);
-	  
-	  /* Tell the X server that the window is being resized */
-	  (s_pScreen->ResizeWindow) (pWin,
-				     pWinPriv->iX - wBorderWidth (pWin),
-				     pWinPriv->iY - wBorderWidth (pWin),
-				     pWinPriv->iWidth,
-				     pWinPriv->iHeight,
-				     pWin->nextSib);
-
-	  /* Tell X to redraw the exposed portions of the window */
-	  {
-	    RegionRec		temp;
-
-	    /* Get the region describing the X window clip list */
-	    REGION_INIT(s_pScreen, &temp, NullBox, 0);
-	    REGION_COPY(s_pScreen, &temp, &pWin->clipList);
-
-	    /* Expose the clipped region */
-	    (*s_pScreen->WindowExposures) (pWin, &temp, NullRegion);
-
-	    /* Free the region */
-	    REGION_UNINIT(s_pScreen, &temp);
-	  }
+	  winResizeXWindow (pWin,
+			   LOWORD(lParam),
+			   HIWORD(lParam));
 	  break;
 
 #if 0
@@ -1542,33 +1512,117 @@
 
 
 /*
- * SendConfigureNotify - 
+ * winMoveXWindow - 
  */
 
 static void
-SendConfigureNotify(WindowPtr pWin)
+winMoveXWindow (WindowPtr pWin, int x, int y)
 {
-  xEvent		event;
-  winWindowPriv(pWin);
+  XID *vlist = malloc(sizeof(long)*2);
 
-  event.u.u.type = ConfigureNotify;
-  event.u.configureNotify.window = pWin->drawable.id;
+  (CARD32*)vlist[0] = x;
+  (CARD32*)vlist[1] = y;
+  ConfigureWindow (pWin, CWX | CWY, vlist, wClient(pWin));
+  free(vlist);
+}
 
-  if (pWin->nextSib)
-    event.u.configureNotify.aboveSibling = pWin->nextSib->drawable.id;
-  else
-    event.u.configureNotify.aboveSibling = None;
 
-  event.u.configureNotify.x = pWinPriv->iX - wBorderWidth (pWin);
-  event.u.configureNotify.y = pWinPriv->iY - wBorderWidth (pWin);
+/*
+ * winResizeXWindow - 
+ */
 
-  event.u.configureNotify.width = pWinPriv->iWidth;
-  event.u.configureNotify.height = pWinPriv->iHeight;
+static void
+winResizeXWindow (WindowPtr pWin, int w, int h)
+{
+  XID *vlist = malloc(sizeof(long)*2);
 
-  event.u.configureNotify.borderWidth = wBorderWidth (pWin);
+  (CARD32*)vlist[0] = w;
+  (CARD32*)vlist[1] = h;
+  ConfigureWindow (pWin, CWWidth | CWHeight, vlist, wClient(pWin));
+  free(vlist);
+}
 
-  event.u.configureNotify.override = pWin->overrideRedirect;
 
-  /* */
-  DeliverEvents (pWin, &event, 1, NullWindow);
+/*
+ * winRestackXWindow - 
+ */
+
+static void
+winRestackXWindow (WindowPtr pWin, int smode)
+{
+  XID *vlist = malloc(sizeof(unsigned long));
+
+  if (vlist == NULL)
+    {
+      ErrorF ("winRestackXWindow - malloc () failed\n");
+      return;
+    }
+
+  if (pWin == NULL)
+    {
+      ErrorF ("winRestackXWindow - NULL window\n");
+      free(vlist);
+      return;
+    }
+
+  *((unsigned long*)vlist) = smode;
+  ConfigureWindow (pWin, CWStackMode, vlist, wClient(pWin));
+
+  free(vlist);
+}
+
+
+/*
+ * winOrderWindowsMultiWindow - 
+ */
+
+void
+winOrderWindowsMultiWindow (ScreenPtr pScreen)
+{
+  winScreenPriv(pScreen);
+  HWND hwnd = NULL;
+  WindowPtr pWin = NULL;
+  WindowPtr pWinSib = NULL;
+  
+  ErrorF ("winOrderWindowsMultiWindow\n");
+
+  pScreenPriv->fRestacking = TRUE;
+
+  if (pScreenPriv->fWindowOrderChanged)
+    {
+      ErrorF ("\tNeed to restack\n");
+      hwnd = GetTopWindow (NULL);
+
+      while (hwnd)
+	{
+	  if (GetProp (hwnd, WIN_WINDOW_PROP))
+	    {
+	      pWinSib = pWin;
+	      pWin = GetProp (hwnd, WIN_WINDOW_PROP);
+	      
+	      if (pWinSib)
+		{
+		  XID *vlist = malloc(sizeof(long)*2);
+		  
+		  if (vlist == NULL)
+		    {
+		      ErrorF ("winOrderWindowsMultiWindow - malloc () failed\n");
+		      return;
+		    }
+		  
+		  ((long*)vlist)[0] = winGetWindowID (pWinSib);
+		  ((long*)vlist)[1] = Below;
+
+		  ConfigureWindow (pWin, CWSibling | CWStackMode,
+				   vlist, wClient(pWin));
+		  
+		  free(vlist);
+		}
+	    }
+	  hwnd = GetNextWindow (hwnd, GW_HWNDNEXT);
+	}
+    }
+
+  pScreenPriv->fRestacking = FALSE;
+  pScreenPriv->fWindowOrderChanged = FALSE;
 }
diff -ru xwin78/winmultiwindowwm.c xwin/winmultiwindowwm.c
--- xwin78/winmultiwindowwm.c	Wed Jan 29 14:31:57 2003
+++ xwin/winmultiwindowwm.c	Sat Mar  8 10:32:57 2003
@@ -212,7 +212,7 @@
 }
 
 
-#if 0
+#if CYGMULTIWINDOW_DEBUG
 /*
  * QueueSize - Return the size of the queue
  */
@@ -652,7 +652,8 @@
       && pErr->error_code == BadAccess)
     {
       ErrorF ("ChangeWindowAttributes BadAccess.\n");
-      pthread_exit (NULL);
+      //pthread_exit (NULL);
+      return 0;
     }
   
   XGetErrorText (pDisplay,
@@ -665,7 +666,8 @@
       || pErr->error_code==BadMatch
       || pErr->error_code==BadDrawable)
     {
-      pthread_exit (NULL);
+      //pthread_exit (NULL);
+      return 0;
     }
 
   pthread_exit (NULL);
diff -ru xwin78/winscrinit.c xwin/winscrinit.c
--- xwin78/winscrinit.c	Sat Jan 25 00:58:41 2003
+++ xwin/winscrinit.c	Sat Mar  8 10:32:57 2003
@@ -510,6 +510,11 @@
   /* Set the ServerStarted flag to false */
   pScreenPriv->fServerStarted = FALSE;
 
+  /* Set the WindowOrderChanged flag to false */
+  pScreenPriv->fWindowOrderChanged = FALSE;
+
+  pScreenPriv->fRestacking = FALSE;
+
 #if CYGDEBUG || YES
   if (pScreenInfo->fMultiWindow)
     ErrorF ("winFinishScreenInitFB - Calling winInitWM.\n");
diff -ru xwin78/winwakeup.c xwin/winwakeup.c
--- xwin78/winwakeup.c	Mon Jan 20 14:10:21 2003
+++ xwin/winwakeup.c	Sat Mar  8 10:32:57 2003
@@ -52,6 +52,7 @@
 	  DispatchMessage (&msg);
 	}
     }
+  winReorderWindowsMultiWindow ((ScreenPtr)pWakeupData);
 }
 
 
