1706f2543Smrg/*
2706f2543Smrg *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved.
3706f2543Smrg *
4706f2543Smrg *Permission is hereby granted, free of charge, to any person obtaining
5706f2543Smrg * a copy of this software and associated documentation files (the
6706f2543Smrg *"Software"), to deal in the Software without restriction, including
7706f2543Smrg *without limitation the rights to use, copy, modify, merge, publish,
8706f2543Smrg *distribute, sublicense, and/or sell copies of the Software, and to
9706f2543Smrg *permit persons to whom the Software is furnished to do so, subject to
10706f2543Smrg *the following conditions:
11706f2543Smrg *
12706f2543Smrg *The above copyright notice and this permission notice shall be
13706f2543Smrg *included in all copies or substantial portions of the Software.
14706f2543Smrg *
15706f2543Smrg *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16706f2543Smrg *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17706f2543Smrg *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18706f2543Smrg *NONINFRINGEMENT. IN NO EVENT SHALL THE XFREE86 PROJECT BE LIABLE FOR
19706f2543Smrg *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
20706f2543Smrg *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21706f2543Smrg *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22706f2543Smrg *
23706f2543Smrg *Except as contained in this notice, the name of the XFree86 Project
24706f2543Smrg *shall not be used in advertising or otherwise to promote the sale, use
25706f2543Smrg *or other dealings in this Software without prior written authorization
26706f2543Smrg *from the XFree86 Project.
27706f2543Smrg *
28706f2543Smrg * Authors:	Kensuke Matsuzaki
29706f2543Smrg *		Earle F. Philhower, III
30706f2543Smrg *		Harold L Hunt II
31706f2543Smrg */
32706f2543Smrg
33706f2543Smrg#ifdef HAVE_XWIN_CONFIG_H
34706f2543Smrg#include <xwin-config.h>
35706f2543Smrg#endif
36706f2543Smrg#include "win.h"
37706f2543Smrg#include "winprefs.h"
38706f2543Smrg
39706f2543Smrg#if 0
40706f2543Smrg/*
41706f2543Smrg * winMWExtWMReorderWindows
42706f2543Smrg */
43706f2543Smrg
44706f2543Smrgvoid
45706f2543SmrgwinMWExtWMReorderWindows (ScreenPtr pScreen)
46706f2543Smrg{
47706f2543Smrg  winScreenPriv(pScreen);
48706f2543Smrg  HWND hwnd = NULL;
49706f2543Smrg  win32RootlessWindowPtr pRLWin = NULL;
50706f2543Smrg  win32RootlessWindowPtr pRLWinSib = NULL;
51706f2543Smrg  DWORD dwCurrentProcessID = GetCurrentProcessId ();
52706f2543Smrg  DWORD dwWindowProcessID = 0;
53706f2543Smrg  XID vlist[2];
54706f2543Smrg
55706f2543Smrg#if CYGMULTIWINDOW_DEBUG && FALSE
56706f2543Smrg  winDebug ("winMWExtWMReorderWindows\n");
57706f2543Smrg#endif
58706f2543Smrg
59706f2543Smrg  pScreenPriv->fRestacking = TRUE;
60706f2543Smrg
61706f2543Smrg  if (pScreenPriv->fWindowOrderChanged)
62706f2543Smrg    {
63706f2543Smrg#if CYGMULTIWINDOW_DEBUG
64706f2543Smrg      winDebug ("winMWExtWMReorderWindows - Need to restack\n");
65706f2543Smrg#endif
66706f2543Smrg      hwnd = GetTopWindow (NULL);
67706f2543Smrg
68706f2543Smrg      while (hwnd)
69706f2543Smrg	{
70706f2543Smrg	  GetWindowThreadProcessId (hwnd, &dwWindowProcessID);
71706f2543Smrg
72706f2543Smrg	  if ((dwWindowProcessID == dwCurrentProcessID)
73706f2543Smrg	      && GetProp (hwnd, WIN_WINDOW_PROP))
74706f2543Smrg	    {
75706f2543Smrg	      pRLWinSib = pRLWin;
76706f2543Smrg	      pRLWin = (win32RootlessWindowPtr)GetProp (hwnd, WIN_WINDOW_PROP);
77706f2543Smrg
78706f2543Smrg	      if (pRLWinSib)
79706f2543Smrg		{
80706f2543Smrg		  vlist[0] = pRLWinSib->pFrame->win->drawable.id;
81706f2543Smrg		  vlist[1] = Below;
82706f2543Smrg
83706f2543Smrg		  ConfigureWindow (pRLWin->pFrame->win, CWSibling | CWStackMode,
84706f2543Smrg				   vlist, wClient(pRLWin->pFrame->win));
85706f2543Smrg		}
86706f2543Smrg	      else
87706f2543Smrg		{
88706f2543Smrg		  /* 1st window - raise to the top */
89706f2543Smrg		  vlist[0] = Above;
90706f2543Smrg
91706f2543Smrg		  ConfigureWindow (pRLWin->pFrame->win, CWStackMode,
92706f2543Smrg				   vlist, wClient(pRLWin->pFrame->win));
93706f2543Smrg		}
94706f2543Smrg	    }
95706f2543Smrg	  hwnd = GetNextWindow (hwnd, GW_HWNDNEXT);
96706f2543Smrg	}
97706f2543Smrg    }
98706f2543Smrg
99706f2543Smrg  pScreenPriv->fRestacking = FALSE;
100706f2543Smrg  pScreenPriv->fWindowOrderChanged = FALSE;
101706f2543Smrg}
102706f2543Smrg#endif
103706f2543Smrg
104706f2543Smrg
105706f2543Smrg/*
106706f2543Smrg * winMWExtWMMoveXWindow
107706f2543Smrg */
108706f2543Smrg
109706f2543Smrgvoid
110706f2543SmrgwinMWExtWMMoveXWindow (WindowPtr pWin, int x, int y)
111706f2543Smrg{
112706f2543Smrg  CARD32 *vlist = malloc(sizeof(CARD32)*2);
113706f2543Smrg
114706f2543Smrg  vlist[0] = x;
115706f2543Smrg  vlist[1] = y;
116706f2543Smrg  ConfigureWindow (pWin, CWX | CWY, vlist, wClient(pWin));
117706f2543Smrg  free(vlist);
118706f2543Smrg}
119706f2543Smrg
120706f2543Smrg
121706f2543Smrg/*
122706f2543Smrg * winMWExtWMResizeXWindow
123706f2543Smrg */
124706f2543Smrg
125706f2543Smrgvoid
126706f2543SmrgwinMWExtWMResizeXWindow (WindowPtr pWin, int w, int h)
127706f2543Smrg{
128706f2543Smrg  CARD32 *vlist = malloc(sizeof(CARD32)*2);
129706f2543Smrg
130706f2543Smrg  vlist[0] = w;
131706f2543Smrg  vlist[1] = h;
132706f2543Smrg  ConfigureWindow (pWin, CWWidth | CWHeight, vlist, wClient(pWin));
133706f2543Smrg  free(vlist);
134706f2543Smrg}
135706f2543Smrg
136706f2543Smrg
137706f2543Smrg/*
138706f2543Smrg * winMWExtWMMoveResizeXWindow
139706f2543Smrg */
140706f2543Smrg
141706f2543Smrgvoid
142706f2543SmrgwinMWExtWMMoveResizeXWindow (WindowPtr pWin, int x, int y, int w, int h)
143706f2543Smrg{
144706f2543Smrg  CARD32 *vlist = malloc(sizeof(long)*4);
145706f2543Smrg
146706f2543Smrg  vlist[0] = x;
147706f2543Smrg  vlist[1] = y;
148706f2543Smrg  vlist[2] = w;
149706f2543Smrg  vlist[3] = h;
150706f2543Smrg
151706f2543Smrg  ConfigureWindow (pWin, CWX | CWY | CWWidth | CWHeight, vlist, wClient(pWin));
152706f2543Smrg  free(vlist);
153706f2543Smrg}
154706f2543Smrg
155706f2543Smrg
156706f2543Smrg/*
157706f2543Smrg * winMWExtWMUpdateIcon
158706f2543Smrg * Change the Windows window icon
159706f2543Smrg */
160706f2543Smrg
161706f2543Smrgvoid
162706f2543SmrgwinMWExtWMUpdateIcon (Window id)
163706f2543Smrg{
164706f2543Smrg  WindowPtr		pWin;
165706f2543Smrg  HICON			hIcon, hiconOld;
166706f2543Smrg
167706f2543Smrg  dixLookupResourceByType((pointer) &pWin, id, RT_WINDOW, NullClient, DixUnknownAccess);
168706f2543Smrg  hIcon = winOverrideIcon ((unsigned long)pWin);
169706f2543Smrg
170706f2543Smrg  if (!hIcon)
171706f2543Smrg    hIcon = winXIconToHICON (pWin, GetSystemMetrics(SM_CXICON));
172706f2543Smrg
173706f2543Smrg  if (hIcon)
174706f2543Smrg    {
175706f2543Smrg      win32RootlessWindowPtr pRLWinPriv
176706f2543Smrg	= (win32RootlessWindowPtr) RootlessFrameForWindow (pWin, FALSE);
177706f2543Smrg
178706f2543Smrg      if (pRLWinPriv->hWnd)
179706f2543Smrg	{
180706f2543Smrg
181706f2543Smrg          hiconOld = (HICON) SendMessage (pRLWinPriv->hWnd,
182706f2543Smrg                     WM_SETICON, ICON_BIG, (LPARAM) hIcon);
183706f2543Smrg          winDestroyIcon(hiconOld);
184706f2543Smrg	}
185706f2543Smrg      hIcon=NULL;
186706f2543Smrg    }
187706f2543Smrg}
188706f2543Smrg
189706f2543Smrg
190706f2543Smrg/*
191706f2543Smrg * winMWExtWMDecorateWindow - Update window style. Called by EnumWindows.
192706f2543Smrg */
193706f2543Smrg
194706f2543SmrgwBOOL CALLBACK
195706f2543SmrgwinMWExtWMDecorateWindow (HWND hwnd, LPARAM lParam)
196706f2543Smrg{
197706f2543Smrg  win32RootlessWindowPtr pRLWinPriv = NULL;
198706f2543Smrg  ScreenPtr		pScreen = NULL;
199706f2543Smrg  winPrivScreenPtr	pScreenPriv = NULL;
200706f2543Smrg  winScreenInfo		*pScreenInfo = NULL;
201706f2543Smrg
202706f2543Smrg  /* Check if the Windows window property for our X window pointer is valid */
203706f2543Smrg  if ((pRLWinPriv = (win32RootlessWindowPtr)GetProp (hwnd, WIN_WINDOW_PROP)) != NULL)
204706f2543Smrg    {
205706f2543Smrg      pScreen				= pRLWinPriv->pFrame->win->drawable.pScreen;
206706f2543Smrg      if (pScreen) pScreenPriv		= winGetScreenPriv(pScreen);
207706f2543Smrg      if (pScreenPriv) pScreenInfo	= pScreenPriv->pScreenInfo;
208706f2543Smrg      if (pRLWinPriv && pScreenInfo) winMWExtWMUpdateWindowDecoration (pRLWinPriv, pScreenInfo);
209706f2543Smrg    }
210706f2543Smrg  return TRUE;
211706f2543Smrg}
212706f2543Smrg
213706f2543Smrg
214706f2543Smrg/*
215706f2543Smrg * winMWExtWMUpdateWindowDecoration - Update window style.
216706f2543Smrg */
217706f2543Smrg
218706f2543Smrgvoid
219706f2543SmrgwinMWExtWMUpdateWindowDecoration (win32RootlessWindowPtr pRLWinPriv,
220706f2543Smrg				  winScreenInfoPtr pScreenInfo)
221706f2543Smrg{
222706f2543Smrg  Bool		fDecorate = FALSE;
223706f2543Smrg  DWORD		dwExStyle = 0;
224706f2543Smrg  DWORD		dwStyle = 0;
225706f2543Smrg  WINDOWPLACEMENT wndPlace;
226706f2543Smrg  UINT		showCmd = 0;
227706f2543Smrg
228706f2543Smrg  wndPlace.length = sizeof (WINDOWPLACEMENT);
229706f2543Smrg
230706f2543Smrg  /* Get current window placement */
231706f2543Smrg  GetWindowPlacement (pRLWinPriv->hWnd, &wndPlace);
232706f2543Smrg
233706f2543Smrg  if (winIsInternalWMRunning(pScreenInfo))
234706f2543Smrg    {
235706f2543Smrg      if (!pRLWinPriv->pFrame->win->overrideRedirect)
236706f2543Smrg	fDecorate = TRUE;
237706f2543Smrg    }
238706f2543Smrg#if 0
239706f2543Smrg  if (wndPlace.showCmd == SW_HIDE)
240706f2543Smrg    return;//showCmd = SWP_HIDEWINDOW;
241706f2543Smrg  else
242706f2543Smrg    showCmd = SWP_SHOWWINDOW;
243706f2543Smrg#else
244706f2543Smrg  if (wndPlace.showCmd == SW_HIDE)
245706f2543Smrg    return;
246706f2543Smrg
247706f2543Smrg  if (IsWindowVisible (pRLWinPriv->hWnd))
248706f2543Smrg    showCmd = SWP_SHOWWINDOW;
249706f2543Smrg#endif
250706f2543Smrg
251706f2543Smrg  showCmd |= SWP_NOMOVE | SWP_FRAMECHANGED | SWP_NOACTIVATE | SWP_NOZORDER;
252706f2543Smrg
253706f2543Smrg  winDebug ("winMWExtWMUpdateWindowDecoration %08x %s\n",
254706f2543Smrg	    (int)pRLWinPriv, fDecorate?"Decorate":"Bare");
255706f2543Smrg
256706f2543Smrg  /* Get the standard and extended window style information */
257706f2543Smrg  dwExStyle = GetWindowLongPtr (pRLWinPriv->hWnd, GWL_EXSTYLE);
258706f2543Smrg  dwStyle = GetWindowLongPtr (pRLWinPriv->hWnd, GWL_STYLE);
259706f2543Smrg
260706f2543Smrg  if (fDecorate)
261706f2543Smrg    {
262706f2543Smrg      RECT		rcNew;
263706f2543Smrg      int		iDx, iDy;
264706f2543Smrg      winWMMessageRec	wmMsg;
265706f2543Smrg      winScreenPriv(pScreenInfo->pScreen);
266706f2543Smrg
267706f2543Smrg      /* */
268706f2543Smrg      if (!(dwExStyle & WS_EX_APPWINDOW))
269706f2543Smrg	{
270706f2543Smrg	  winDebug ("\tBare=>Decorate\n");
271706f2543Smrg	  /* Setup a rectangle with the X window position and size */
272706f2543Smrg	  SetRect (&rcNew,
273706f2543Smrg		   pRLWinPriv->pFrame->x,
274706f2543Smrg		   pRLWinPriv->pFrame->y,
275706f2543Smrg		   pRLWinPriv->pFrame->x + pRLWinPriv->pFrame->width,
276706f2543Smrg		   pRLWinPriv->pFrame->y + pRLWinPriv->pFrame->height);
277706f2543Smrg
278706f2543Smrg#ifdef CYGMULTIWINDOW_DEBUG
279706f2543Smrg          winDebug("\tWindow extend {%d, %d, %d, %d}, {%d, %d}\n",
280706f2543Smrg              rcNew.left, rcNew.top, rcNew.right, rcNew.bottom,
281706f2543Smrg              rcNew.right - rcNew.left, rcNew.bottom - rcNew.top);
282706f2543Smrg#endif
283706f2543Smrg	  /* */
284706f2543Smrg	  AdjustWindowRectEx (&rcNew,
285706f2543Smrg			      WS_POPUP | WS_SIZEBOX | WS_OVERLAPPEDWINDOW,
286706f2543Smrg			      FALSE,
287706f2543Smrg			      WS_EX_APPWINDOW);
288706f2543Smrg
289706f2543Smrg#ifdef CYGMULTIWINDOW_DEBUG
290706f2543Smrg          winDebug("\tAdjusted {%d, %d, %d, %d}, {%d, %d}\n",
291706f2543Smrg              rcNew.left, rcNew.top, rcNew.right, rcNew.bottom,
292706f2543Smrg              rcNew.right - rcNew.left, rcNew.bottom - rcNew.top);
293706f2543Smrg#endif
294706f2543Smrg	  /* Calculate position deltas */
295706f2543Smrg	  iDx = pRLWinPriv->pFrame->x - rcNew.left;
296706f2543Smrg	  iDy = pRLWinPriv->pFrame->y - rcNew.top;
297706f2543Smrg
298706f2543Smrg	  /* Calculate new rectangle */
299706f2543Smrg	  rcNew.left += iDx;
300706f2543Smrg	  rcNew.right += iDx;
301706f2543Smrg	  rcNew.top += iDy;
302706f2543Smrg	  rcNew.bottom += iDy;
303706f2543Smrg
304706f2543Smrg	  /* Set the window extended style flags */
305706f2543Smrg	  SetWindowLongPtr (pRLWinPriv->hWnd, GWL_EXSTYLE, WS_EX_APPWINDOW);
306706f2543Smrg
307706f2543Smrg	  /* Set the window standard style flags */
308706f2543Smrg	  SetWindowLongPtr (pRLWinPriv->hWnd, GWL_STYLE,
309706f2543Smrg			    WS_POPUP | WS_SIZEBOX | WS_OVERLAPPEDWINDOW);
310706f2543Smrg
311706f2543Smrg#ifdef CYGMULTIWINDOW_DEBUG
312706f2543Smrg          winDebug("\tWindowStyle: %08x %08x\n",
313706f2543Smrg              WS_POPUP | WS_SIZEBOX | WS_OVERLAPPEDWINDOW,
314706f2543Smrg              WS_EX_APPWINDOW);
315706f2543Smrg#endif
316706f2543Smrg	  /* Position the Windows window */
317706f2543Smrg#ifdef CYGMULTIWINDOW_DEBUG
318706f2543Smrg          winDebug("\tMoved {%d, %d, %d, %d}, {%d, %d}\n",
319706f2543Smrg              rcNew.left, rcNew.top, rcNew.right, rcNew.bottom,
320706f2543Smrg              rcNew.right - rcNew.left, rcNew.bottom - rcNew.top);
321706f2543Smrg#endif
322706f2543Smrg	  SetWindowPos (pRLWinPriv->hWnd, NULL,
323706f2543Smrg			rcNew.left, rcNew.top,
324706f2543Smrg			rcNew.right - rcNew.left, rcNew.bottom - rcNew.top,
325706f2543Smrg			showCmd);
326706f2543Smrg
327706f2543Smrg
328706f2543Smrg	  wmMsg.hwndWindow = pRLWinPriv->hWnd;
329706f2543Smrg	  wmMsg.iWindow	= (Window)pRLWinPriv->pFrame->win->drawable.id;
330706f2543Smrg	  wmMsg.msg = WM_WM_NAME_EVENT;
331706f2543Smrg	  winSendMessageToWM (pScreenPriv->pWMInfo, &wmMsg);
332706f2543Smrg
333706f2543Smrg	  winMWExtWMReshapeFrame ((RootlessFrameID)pRLWinPriv ,
334706f2543Smrg				  wBoundingShape(pRLWinPriv->pFrame->win));
335706f2543Smrg	}
336706f2543Smrg    }
337706f2543Smrg  else
338706f2543Smrg    {
339706f2543Smrg      RECT		rcNew;
340706f2543Smrg
341706f2543Smrg      /* */
342706f2543Smrg      if (dwExStyle & WS_EX_APPWINDOW)
343706f2543Smrg	{
344706f2543Smrg	  winDebug ("\tDecorate=>Bare\n");
345706f2543Smrg	  /* Setup a rectangle with the X window position and size */
346706f2543Smrg	  SetRect (&rcNew,
347706f2543Smrg		   pRLWinPriv->pFrame->x,
348706f2543Smrg		   pRLWinPriv->pFrame->y,
349706f2543Smrg		   pRLWinPriv->pFrame->x + pRLWinPriv->pFrame->width,
350706f2543Smrg		   pRLWinPriv->pFrame->y + pRLWinPriv->pFrame->height);
351706f2543Smrg#if 0
352706f2543Smrg	  /* */
353706f2543Smrg	  AdjustWindowRectEx (&rcNew,
354706f2543Smrg			      WS_POPUP | WS_CLIPCHILDREN,
355706f2543Smrg			      FALSE,
356706f2543Smrg			      WS_EX_TOOLWINDOW);
357706f2543Smrg
358706f2543Smrg	  /* Calculate position deltas */
359706f2543Smrg	  iDx = pRLWinPriv->pFrame->x - rcNew.left;
360706f2543Smrg	  iDy = pRLWinPriv->pFrame->y - rcNew.top;
361706f2543Smrg
362706f2543Smrg	  /* Calculate new rectangle */
363706f2543Smrg	  rcNew.left += iDx;
364706f2543Smrg	  rcNew.right += iDx;
365706f2543Smrg	  rcNew.top += iDy;
366706f2543Smrg	  rcNew.bottom += iDy;
367706f2543Smrg#endif
368706f2543Smrg
369706f2543Smrg	  /* Hide window temporary to remove from taskbar. */
370706f2543Smrg	  ShowWindow( pRLWinPriv->hWnd, SW_HIDE );
371706f2543Smrg
372706f2543Smrg	  /* Set the window extended style flags */
373706f2543Smrg	  SetWindowLongPtr (pRLWinPriv->hWnd, GWL_EXSTYLE, WS_EX_TOOLWINDOW);
374706f2543Smrg
375706f2543Smrg	  /* Set the window standard style flags */
376706f2543Smrg	  SetWindowLongPtr (pRLWinPriv->hWnd, GWL_STYLE,
377706f2543Smrg			    WS_POPUP | WS_CLIPCHILDREN);
378706f2543Smrg
379706f2543Smrg	  /* Position the Windows window */
380706f2543Smrg	  SetWindowPos (pRLWinPriv->hWnd, NULL,
381706f2543Smrg			rcNew.left, rcNew.top,
382706f2543Smrg			rcNew.right - rcNew.left, rcNew.bottom - rcNew.top,
383706f2543Smrg			showCmd);
384706f2543Smrg
385706f2543Smrg	  winMWExtWMReshapeFrame ((RootlessFrameID)pRLWinPriv ,
386706f2543Smrg				  wBoundingShape(pRLWinPriv->pFrame->win));
387706f2543Smrg	}
388706f2543Smrg    }
389706f2543Smrg}
390706f2543Smrg
391706f2543Smrg
392706f2543Smrg/*
393706f2543Smrg * winIsInternalWMRunning (winScreenInfoPtr pScreenInfo)
394706f2543Smrg */
395706f2543SmrgBool
396706f2543SmrgwinIsInternalWMRunning (winScreenInfoPtr pScreenInfo)
397706f2543Smrg{
398706f2543Smrg  return pScreenInfo->fInternalWM && !pScreenInfo->fAnotherWMRunning;
399706f2543Smrg}
400706f2543Smrg
401706f2543Smrg
402706f2543Smrg/*
403706f2543Smrg * winMWExtWMRestackWindows
404706f2543Smrg */
405706f2543Smrg
406706f2543Smrgvoid
407706f2543SmrgwinMWExtWMRestackWindows (ScreenPtr pScreen)
408706f2543Smrg{
409706f2543Smrg  winScreenPriv(pScreen);
410706f2543Smrg  WindowPtr pRoot = pScreen->root;
411706f2543Smrg  WindowPtr pWin = NULL;
412706f2543Smrg  WindowPtr pWinPrev = NULL;
413706f2543Smrg  win32RootlessWindowPtr pRLWin = NULL;
414706f2543Smrg  win32RootlessWindowPtr pRLWinPrev = NULL;
415706f2543Smrg  int  nWindow = 0;
416706f2543Smrg  HDWP hWinPosInfo = NULL;
417706f2543Smrg
418706f2543Smrg#if CYGMULTIWINDOW_DEBUG
419706f2543Smrg  winDebug ("winMWExtWMRestackWindows\n");
420706f2543Smrg#endif
421706f2543Smrg
422706f2543Smrg  pScreenPriv->fRestacking = TRUE;
423706f2543Smrg
424706f2543Smrg  if (pRoot != NULL)
425706f2543Smrg    {
426706f2543Smrg      for (pWin = pRoot->firstChild; pWin; pWin = pWin->nextSib)
427706f2543Smrg	nWindow ++;
428706f2543Smrg
429706f2543Smrg      hWinPosInfo = BeginDeferWindowPos(nWindow);
430706f2543Smrg
431706f2543Smrg      for (pWin = pRoot->firstChild; pWin; pWin = pWin->nextSib)
432706f2543Smrg	{
433706f2543Smrg	  if (pWin->realized)
434706f2543Smrg	    {
435706f2543Smrg	      UINT uFlags;
436706f2543Smrg
437706f2543Smrg	      pRLWin = (win32RootlessWindowPtr) RootlessFrameForWindow (pWin, FALSE);
438706f2543Smrg	      if (pRLWin == NULL) continue;
439706f2543Smrg
440706f2543Smrg	      if (pWinPrev)
441706f2543Smrg		pRLWinPrev = (win32RootlessWindowPtr) RootlessFrameForWindow (pWinPrev, FALSE);
442706f2543Smrg
443706f2543Smrg	      uFlags = SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW;
444706f2543Smrg	      if (pRLWinPrev != NULL) uFlags |= SWP_NOACTIVATE;
445706f2543Smrg
446706f2543Smrg#if CYGMULTIWINDOW_DEBUG
447706f2543Smrg	      winDebug ("winMWExtWMRestackWindows - DeferWindowPos (%08x, %08x)\n",
448706f2543Smrg			pRLWin->hWnd,
449706f2543Smrg			pRLWinPrev ? pRLWinPrev->hWnd : HWND_TOP);
450706f2543Smrg#endif
451706f2543Smrg	      hWinPosInfo = DeferWindowPos (hWinPosInfo, pRLWin->hWnd,
452706f2543Smrg					    pRLWinPrev ? pRLWinPrev->hWnd : HWND_TOP,
453706f2543Smrg					    0, 0, 0, 0,
454706f2543Smrg					    uFlags);
455706f2543Smrg	      if (hWinPosInfo == NULL)
456706f2543Smrg		{
457706f2543Smrg		  ErrorF ("winMWExtWMRestackWindows - DeferWindowPos () failed: %d\n",
458706f2543Smrg			  (int) GetLastError ());
459706f2543Smrg		  return;
460706f2543Smrg		}
461706f2543Smrg	      pWinPrev = pWin;
462706f2543Smrg	    }
463706f2543Smrg	}
464706f2543Smrg      if (!EndDeferWindowPos (hWinPosInfo))
465706f2543Smrg	{
466706f2543Smrg	  ErrorF ("winMWExtWMRestackWindows - EndDeferWindowPos () failed: %d\n",
467706f2543Smrg		  (int) GetLastError ());
468706f2543Smrg	  return;
469706f2543Smrg	}
470706f2543Smrg    }
471706f2543Smrg
472706f2543Smrg#if CYGMULTIWINDOW_DEBUG
473706f2543Smrg  winDebug ("winMWExtWMRestackWindows - done\n");
474706f2543Smrg#endif
475706f2543Smrg  pScreenPriv->fRestacking = FALSE;
476706f2543Smrg}
477