2 *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved.
4 *Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 *"Software"), to deal in the Software without restriction, including
7 *without limitation the rights to use, copy, modify, merge, publish,
8 *distribute, sublicense, and/or sell copies of the Software, and to
9 *permit persons to whom the Software is furnished to do so, subject to
10 *the following conditions:
12 *The above copyright notice and this permission notice shall be
13 *included in all copies or substantial portions of the Software.
15 *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 *NONINFRINGEMENT. IN NO EVENT SHALL THE XFREE86 PROJECT BE LIABLE FOR
19 *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
20 *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 *Except as contained in this notice, the name of the XFree86 Project
24 *shall not be used in advertising or otherwise to promote the sale, use
25 *or other dealings in this Software without prior written authorization
26 *from the XFree86 Project.
28 * Authors: Kensuke Matsuzaki
29 * Earle F. Philhower, III
33 #ifdef HAVE_XWIN_CONFIG_H
34 #include <xwin-config.h>
41 * winMWExtWMReorderWindows
45 winMWExtWMReorderWindows(ScreenPtr pScreen
)
47 winScreenPriv(pScreen
);
49 win32RootlessWindowPtr pRLWin
= NULL
;
50 win32RootlessWindowPtr pRLWinSib
= NULL
;
51 DWORD dwCurrentProcessID
= GetCurrentProcessId();
52 DWORD dwWindowProcessID
= 0;
55 #if CYGMULTIWINDOW_DEBUG && FALSE
56 winDebug("winMWExtWMReorderWindows\n");
59 pScreenPriv
->fRestacking
= TRUE
;
61 if (pScreenPriv
->fWindowOrderChanged
) {
62 #if CYGMULTIWINDOW_DEBUG
63 winDebug("winMWExtWMReorderWindows - Need to restack\n");
65 hwnd
= GetTopWindow(NULL
);
68 GetWindowThreadProcessId(hwnd
, &dwWindowProcessID
);
70 if ((dwWindowProcessID
== dwCurrentProcessID
)
71 && GetProp(hwnd
, WIN_WINDOW_PROP
)) {
74 (win32RootlessWindowPtr
) GetProp(hwnd
, WIN_WINDOW_PROP
);
77 vlist
[0] = pRLWinSib
->pFrame
->win
->drawable
.id
;
80 ConfigureWindow(pRLWin
->pFrame
->win
,
81 CWSibling
| CWStackMode
, vlist
,
82 wClient(pRLWin
->pFrame
->win
));
85 /* 1st window - raise to the top */
88 ConfigureWindow(pRLWin
->pFrame
->win
, CWStackMode
,
89 vlist
, wClient(pRLWin
->pFrame
->win
));
92 hwnd
= GetNextWindow(hwnd
, GW_HWNDNEXT
);
96 pScreenPriv
->fRestacking
= FALSE
;
97 pScreenPriv
->fWindowOrderChanged
= FALSE
;
102 * winMWExtWMMoveXWindow
106 winMWExtWMMoveXWindow(WindowPtr pWin
, int x
, int y
)
108 CARD32
*vlist
= malloc(sizeof(CARD32
) * 2);
112 ConfigureWindow(pWin
, CWX
| CWY
, vlist
, wClient(pWin
));
117 * winMWExtWMResizeXWindow
121 winMWExtWMResizeXWindow(WindowPtr pWin
, int w
, int h
)
123 CARD32
*vlist
= malloc(sizeof(CARD32
) * 2);
127 ConfigureWindow(pWin
, CWWidth
| CWHeight
, vlist
, wClient(pWin
));
132 * winMWExtWMMoveResizeXWindow
136 winMWExtWMMoveResizeXWindow(WindowPtr pWin
, int x
, int y
, int w
, int h
)
138 CARD32
*vlist
= malloc(sizeof(long) * 4);
145 ConfigureWindow(pWin
, CWX
| CWY
| CWWidth
| CWHeight
, vlist
, wClient(pWin
));
152 * winMWExtWMDecorateWindow - Update window style. Called by EnumWindows.
156 winMWExtWMDecorateWindow(HWND hwnd
, LPARAM lParam
)
158 win32RootlessWindowPtr pRLWinPriv
= NULL
;
159 ScreenPtr pScreen
= NULL
;
160 winPrivScreenPtr pScreenPriv
= NULL
;
161 winScreenInfo
*pScreenInfo
= NULL
;
163 /* Check if the Windows window property for our X window pointer is valid */
165 (win32RootlessWindowPtr
) GetProp(hwnd
, WIN_WINDOW_PROP
)) != NULL
) {
166 if (pRLWinPriv
!= NULL
&& pRLWinPriv
->pFrame
!= NULL
&&
167 pRLWinPriv
->pFrame
->win
!= NULL
)
168 pScreen
= pRLWinPriv
->pFrame
->win
->drawable
.pScreen
;
170 pScreenPriv
= winGetScreenPriv(pScreen
);
172 pScreenInfo
= pScreenPriv
->pScreenInfo
;
173 if (pRLWinPriv
&& pScreenInfo
)
174 winMWExtWMUpdateWindowDecoration(pRLWinPriv
, pScreenInfo
);
180 * winMWExtWMUpdateWindowDecoration - Update window style.
184 winMWExtWMUpdateWindowDecoration(win32RootlessWindowPtr pRLWinPriv
,
185 winScreenInfoPtr pScreenInfo
)
187 Bool fDecorate
= FALSE
;
189 WINDOWPLACEMENT wndPlace
;
192 wndPlace
.length
= sizeof(WINDOWPLACEMENT
);
194 /* Get current window placement */
195 GetWindowPlacement(pRLWinPriv
->hWnd
, &wndPlace
);
197 if (winIsInternalWMRunning(pScreenInfo
)) {
198 if (!pRLWinPriv
->pFrame
->win
->overrideRedirect
)
202 if (wndPlace
.showCmd
== SW_HIDE
)
203 return; //showCmd = SWP_HIDEWINDOW;
205 showCmd
= SWP_SHOWWINDOW
;
207 if (wndPlace
.showCmd
== SW_HIDE
)
210 if (IsWindowVisible(pRLWinPriv
->hWnd
))
211 showCmd
= SWP_SHOWWINDOW
;
214 showCmd
|= SWP_NOMOVE
| SWP_FRAMECHANGED
| SWP_NOACTIVATE
| SWP_NOZORDER
;
216 winDebug("winMWExtWMUpdateWindowDecoration %p %s\n",
217 pRLWinPriv
, fDecorate
? "Decorate" : "Bare");
219 /* Get the extended window style information */
220 dwExStyle
= GetWindowLongPtr(pRLWinPriv
->hWnd
, GWL_EXSTYLE
);
225 winWMMessageRec wmMsg
;
227 winScreenPriv(pScreenInfo
->pScreen
);
230 if (!(dwExStyle
& WS_EX_APPWINDOW
)) {
231 winDebug("\tBare=>Decorate\n");
232 /* Setup a rectangle with the X window position and size */
234 pRLWinPriv
->pFrame
->x
,
235 pRLWinPriv
->pFrame
->y
,
236 pRLWinPriv
->pFrame
->x
+ pRLWinPriv
->pFrame
->width
,
237 pRLWinPriv
->pFrame
->y
+ pRLWinPriv
->pFrame
->height
);
239 #ifdef CYGMULTIWINDOW_DEBUG
240 winDebug("\tWindow extend {%d, %d, %d, %d}, {%d, %d}\n",
241 rcNew
.left
, rcNew
.top
, rcNew
.right
, rcNew
.bottom
,
242 rcNew
.right
- rcNew
.left
, rcNew
.bottom
- rcNew
.top
);
245 AdjustWindowRectEx(&rcNew
,
246 WS_POPUP
| WS_SIZEBOX
| WS_OVERLAPPEDWINDOW
,
247 FALSE
, WS_EX_APPWINDOW
);
249 #ifdef CYGMULTIWINDOW_DEBUG
250 winDebug("\tAdjusted {%d, %d, %d, %d}, {%d, %d}\n",
251 rcNew
.left
, rcNew
.top
, rcNew
.right
, rcNew
.bottom
,
252 rcNew
.right
- rcNew
.left
, rcNew
.bottom
- rcNew
.top
);
254 /* Calculate position deltas */
255 iDx
= pRLWinPriv
->pFrame
->x
- rcNew
.left
;
256 iDy
= pRLWinPriv
->pFrame
->y
- rcNew
.top
;
258 /* Calculate new rectangle */
264 /* Set the window extended style flags */
265 SetWindowLongPtr(pRLWinPriv
->hWnd
, GWL_EXSTYLE
, WS_EX_APPWINDOW
);
267 /* Set the window standard style flags */
268 SetWindowLongPtr(pRLWinPriv
->hWnd
, GWL_STYLE
,
269 WS_POPUP
| WS_SIZEBOX
| WS_OVERLAPPEDWINDOW
);
271 #ifdef CYGMULTIWINDOW_DEBUG
272 winDebug("\tWindowStyle: %08x %08x\n",
273 WS_POPUP
| WS_SIZEBOX
| WS_OVERLAPPEDWINDOW
,
276 /* Position the Windows window */
277 #ifdef CYGMULTIWINDOW_DEBUG
278 winDebug("\tMoved {%d, %d, %d, %d}, {%d, %d}\n",
279 rcNew
.left
, rcNew
.top
, rcNew
.right
, rcNew
.bottom
,
280 rcNew
.right
- rcNew
.left
, rcNew
.bottom
- rcNew
.top
);
282 SetWindowPos(pRLWinPriv
->hWnd
, NULL
,
283 rcNew
.left
, rcNew
.top
,
284 rcNew
.right
- rcNew
.left
, rcNew
.bottom
- rcNew
.top
,
287 wmMsg
.hwndWindow
= pRLWinPriv
->hWnd
;
288 wmMsg
.iWindow
= (Window
) pRLWinPriv
->pFrame
->win
->drawable
.id
;
289 wmMsg
.msg
= WM_WM_NAME_EVENT
;
290 winSendMessageToWM(pScreenPriv
->pWMInfo
, &wmMsg
);
292 winMWExtWMReshapeFrame((RootlessFrameID
) pRLWinPriv
,
293 wBoundingShape(pRLWinPriv
->pFrame
->win
));
300 if (dwExStyle
& WS_EX_APPWINDOW
) {
301 winDebug("\tDecorate=>Bare\n");
302 /* Setup a rectangle with the X window position and size */
304 pRLWinPriv
->pFrame
->x
,
305 pRLWinPriv
->pFrame
->y
,
306 pRLWinPriv
->pFrame
->x
+ pRLWinPriv
->pFrame
->width
,
307 pRLWinPriv
->pFrame
->y
+ pRLWinPriv
->pFrame
->height
);
310 AdjustWindowRectEx(&rcNew
,
311 WS_POPUP
| WS_CLIPCHILDREN
,
312 FALSE
, WS_EX_TOOLWINDOW
);
314 /* Calculate position deltas */
315 iDx
= pRLWinPriv
->pFrame
->x
- rcNew
.left
;
316 iDy
= pRLWinPriv
->pFrame
->y
- rcNew
.top
;
318 /* Calculate new rectangle */
325 /* Hide window temporary to remove from taskbar. */
326 ShowWindow(pRLWinPriv
->hWnd
, SW_HIDE
);
328 /* Set the window extended style flags */
329 SetWindowLongPtr(pRLWinPriv
->hWnd
, GWL_EXSTYLE
, WS_EX_TOOLWINDOW
);
331 /* Set the window standard style flags */
332 SetWindowLongPtr(pRLWinPriv
->hWnd
, GWL_STYLE
,
333 WS_POPUP
| WS_CLIPCHILDREN
);
335 /* Position the Windows window */
336 SetWindowPos(pRLWinPriv
->hWnd
, NULL
,
337 rcNew
.left
, rcNew
.top
,
338 rcNew
.right
- rcNew
.left
, rcNew
.bottom
- rcNew
.top
,
341 winMWExtWMReshapeFrame((RootlessFrameID
) pRLWinPriv
,
342 wBoundingShape(pRLWinPriv
->pFrame
->win
));
348 * winIsInternalWMRunning (winScreenInfoPtr pScreenInfo)
351 winIsInternalWMRunning(winScreenInfoPtr pScreenInfo
)
353 return pScreenInfo
->fInternalWM
&& !pScreenInfo
->fAnotherWMRunning
;
357 * winMWExtWMRestackWindows
361 winMWExtWMRestackWindows(ScreenPtr pScreen
)
363 winScreenPriv(pScreen
);
364 WindowPtr pRoot
= pScreen
->root
;
365 WindowPtr pWin
= NULL
;
366 WindowPtr pWinPrev
= NULL
;
367 win32RootlessWindowPtr pRLWin
= NULL
;
368 win32RootlessWindowPtr pRLWinPrev
= NULL
;
370 HDWP hWinPosInfo
= NULL
;
372 #if CYGMULTIWINDOW_DEBUG
373 winDebug("winMWExtWMRestackWindows\n");
376 pScreenPriv
->fRestacking
= TRUE
;
379 for (pWin
= pRoot
->firstChild
; pWin
; pWin
= pWin
->nextSib
)
382 hWinPosInfo
= BeginDeferWindowPos(nWindow
);
384 for (pWin
= pRoot
->firstChild
; pWin
; pWin
= pWin
->nextSib
) {
385 if (pWin
->realized
) {
389 (win32RootlessWindowPtr
) RootlessFrameForWindow(pWin
,
396 (win32RootlessWindowPtr
)
397 RootlessFrameForWindow(pWinPrev
, FALSE
);
399 uFlags
= SWP_NOMOVE
| SWP_NOSIZE
| SWP_SHOWWINDOW
;
400 if (pRLWinPrev
!= NULL
)
401 uFlags
|= SWP_NOACTIVATE
;
403 #if CYGMULTIWINDOW_DEBUG
405 ("winMWExtWMRestackWindows - DeferWindowPos (%08x, %08x)\n",
406 pRLWin
->hWnd
, pRLWinPrev
? pRLWinPrev
->hWnd
: HWND_TOP
);
408 hWinPosInfo
= DeferWindowPos(hWinPosInfo
, pRLWin
->hWnd
,
409 pRLWinPrev
? pRLWinPrev
->
410 hWnd
: HWND_TOP
, 0, 0, 0, 0,
412 if (hWinPosInfo
== NULL
) {
414 ("winMWExtWMRestackWindows - DeferWindowPos () failed: %d\n",
415 (int) GetLastError());
421 if (!EndDeferWindowPos(hWinPosInfo
)) {
423 ("winMWExtWMRestackWindows - EndDeferWindowPos () failed: %d\n",
424 (int) GetLastError());
429 #if CYGMULTIWINDOW_DEBUG
430 winDebug("winMWExtWMRestackWindows - done\n");
432 pScreenPriv
->fRestacking
= FALSE
;