4 * Copyright 1993, 1994, 1995, 1996 Alexandre Julliard
6 * 1995, 1996 Alex Korobka
11 #include <X11/Xatom.h>
21 #include "debugtools.h"
31 #include "wine/winuser16.h"
33 DEFAULT_DEBUG_CHANNEL(win
);
35 /* Some useful macros */
36 #define HAS_DLGFRAME(style,exStyle) \
37 ((!((style) & WS_THICKFRAME)) && (((style) & WS_DLGFRAME) || ((exStyle) & WS_EX_DLGMODALFRAME)))
39 /**********************************************************************/
41 extern Cursor X11DRV_MOUSE_XCursor
; /* Current X cursor */
42 extern BOOL
X11DRV_CreateBitmap( HBITMAP
);
43 extern Pixmap
X11DRV_BITMAP_Pixmap( HBITMAP
);
45 /**********************************************************************/
47 /* X context to associate a hwnd to an X window */
48 XContext winContext
= 0;
50 Atom wmProtocols
= None
;
51 Atom wmDeleteWindow
= None
;
52 Atom dndProtocol
= None
;
53 Atom dndSelection
= None
;
54 Atom wmChangeState
= None
;
56 Atom kwmDockWindow
= None
;
58 /***********************************************************************
59 * X11DRV_WND_GetXWindow
61 * Return the X window associated to a window.
63 Window
X11DRV_WND_GetXWindow(WND
*wndPtr
)
65 return wndPtr
&& wndPtr
->pDriverData
?
66 ((X11DRV_WND_DATA
*) wndPtr
->pDriverData
)->window
: 0;
69 /***********************************************************************
70 * X11DRV_WND_FindXWindow
72 * Return the the first X window associated to a window chain.
74 Window
X11DRV_WND_FindXWindow(WND
*wndPtr
)
77 !((X11DRV_WND_DATA
*) wndPtr
->pDriverData
)->window
)
78 wndPtr
= wndPtr
->parent
;
80 ((X11DRV_WND_DATA
*) wndPtr
->pDriverData
)->window
: 0;
83 /***********************************************************************
84 * X11DRV_WND_RegisterWindow
86 * Associate an X window to a HWND.
88 static void X11DRV_WND_RegisterWindow(WND
*wndPtr
)
90 TSXSetWMProtocols( display
, X11DRV_WND_GetXWindow(wndPtr
), &wmDeleteWindow
, 1 );
92 if (!winContext
) winContext
= TSXUniqueContext();
93 TSXSaveContext( display
, X11DRV_WND_GetXWindow(wndPtr
),
94 winContext
, (char *) wndPtr
->hwndSelf
);
97 /**********************************************************************
98 * X11DRV_WND_Initialize
100 void X11DRV_WND_Initialize(WND
*wndPtr
)
102 X11DRV_WND_DATA
*pWndDriverData
=
103 (X11DRV_WND_DATA
*) HeapAlloc(SystemHeap
, 0, sizeof(X11DRV_WND_DATA
));
105 wndPtr
->pDriverData
= (void *) pWndDriverData
;
107 pWndDriverData
->window
= 0;
110 /**********************************************************************
111 * X11DRV_WND_Finalize
113 void X11DRV_WND_Finalize(WND
*wndPtr
)
115 X11DRV_WND_DATA
*pWndDriverData
=
116 (X11DRV_WND_DATA
*) wndPtr
->pDriverData
;
118 if (!wndPtr
->pDriverData
) {
119 ERR("Trying to destroy window again. Not good.\n");
122 if(pWndDriverData
->window
)
125 "WND destroyed without destroying "
126 "the associated X Window (%ld)\n",
127 pWndDriverData
->window
130 HeapFree(SystemHeap
, 0, wndPtr
->pDriverData
);
131 wndPtr
->pDriverData
= NULL
;
134 /**********************************************************************
135 * X11DRV_WND_CreateDesktopWindow
137 BOOL
X11DRV_WND_CreateDesktopWindow(WND
*wndPtr
, CLASS
*classPtr
, BOOL bUnicode
)
139 if (wmProtocols
== None
)
140 wmProtocols
= TSXInternAtom( display
, "WM_PROTOCOLS", True
);
141 if (wmDeleteWindow
== None
)
142 wmDeleteWindow
= TSXInternAtom( display
, "WM_DELETE_WINDOW", True
);
143 if( dndProtocol
== None
)
144 dndProtocol
= TSXInternAtom( display
, "DndProtocol" , False
);
145 if( dndSelection
== None
)
146 dndSelection
= TSXInternAtom( display
, "DndSelection" , False
);
147 if( wmChangeState
== None
)
148 wmChangeState
= TSXInternAtom (display
, "WM_CHANGE_STATE", False
);
149 if (kwmDockWindow
== None
)
150 kwmDockWindow
= TSXInternAtom( display
, "KWM_DOCKWINDOW", False
);
152 ((X11DRV_WND_DATA
*) wndPtr
->pDriverData
)->window
= X11DRV_GetXRootWindow();
153 X11DRV_WND_RegisterWindow( wndPtr
);
158 /**********************************************************************
159 * X11DRV_WND_IconChanged
161 * hIcon or hIconSm has changed (or is being initialised for the
162 * first time). Complete the X11 driver-specific initialisation.
164 * This is not entirely correct, may need to create
165 * an icon window and set the pixmap as a background
167 static void X11DRV_WND_IconChanged(WND
*wndPtr
)
170 HICON16 hIcon
= NC_IconForWindow(wndPtr
);
172 if( ((X11DRV_WND_DATA
*) wndPtr
->pDriverData
)->hWMIconBitmap
)
173 DeleteObject( ((X11DRV_WND_DATA
*) wndPtr
->pDriverData
)->hWMIconBitmap
);
175 if( ((X11DRV_WND_DATA
*) wndPtr
->pDriverData
)->hWMIconMask
)
176 DeleteObject( ((X11DRV_WND_DATA
*) wndPtr
->pDriverData
)->hWMIconMask
);
180 ((X11DRV_WND_DATA
*) wndPtr
->pDriverData
)->hWMIconBitmap
= 0;
181 ((X11DRV_WND_DATA
*) wndPtr
->pDriverData
)->hWMIconMask
= 0;
191 GetIconInfo(hIcon
, &ii
);
193 X11DRV_CreateBitmap(ii
.hbmMask
);
194 X11DRV_CreateBitmap(ii
.hbmColor
);
196 GetObjectA(ii
.hbmMask
, sizeof(bmMask
), &bmMask
);
199 rcMask
.right
= bmMask
.bmWidth
;
200 rcMask
.bottom
= bmMask
.bmHeight
;
202 hDC
= CreateCompatibleDC(0);
203 hbmOrig
= SelectObject(hDC
, ii
.hbmMask
);
204 InvertRect(hDC
, &rcMask
);
205 SelectObject(hDC
, hbmOrig
);
208 ((X11DRV_WND_DATA
*) wndPtr
->pDriverData
)->hWMIconBitmap
= ii
.hbmColor
;
209 ((X11DRV_WND_DATA
*) wndPtr
->pDriverData
)->hWMIconMask
= ii
.hbmMask
;
214 static void X11DRV_WND_SetIconHints(WND
*wndPtr
, XWMHints
*hints
)
216 if (((X11DRV_WND_DATA
*) wndPtr
->pDriverData
)->hWMIconBitmap
)
219 = X11DRV_BITMAP_Pixmap(((X11DRV_WND_DATA
*) wndPtr
->pDriverData
)->hWMIconBitmap
);
220 hints
->flags
|= IconPixmapHint
;
223 hints
->flags
&= ~IconPixmapHint
;
225 if (((X11DRV_WND_DATA
*) wndPtr
->pDriverData
)->hWMIconMask
)
228 = X11DRV_BITMAP_Pixmap(((X11DRV_WND_DATA
*) wndPtr
->pDriverData
)->hWMIconMask
);
229 hints
->flags
|= IconMaskHint
;
232 hints
->flags
&= ~IconMaskHint
;
235 /**********************************************************************
236 * X11DRV_WND_UpdateIconHints
238 * hIcon or hIconSm has changed (or is being initialised for the
239 * first time). Complete the X11 driver-specific initialisation
240 * and set the window hints.
242 * This is not entirely correct, may need to create
243 * an icon window and set the pixmap as a background
245 static void X11DRV_WND_UpdateIconHints(WND
*wndPtr
)
249 X11DRV_WND_IconChanged(wndPtr
);
251 wm_hints
= TSXGetWMHints( display
, X11DRV_WND_GetXWindow(wndPtr
) );
252 if (!wm_hints
) wm_hints
= TSXAllocWMHints();
255 X11DRV_WND_SetIconHints(wndPtr
, wm_hints
);
256 TSXSetWMHints( display
, X11DRV_WND_GetXWindow(wndPtr
), wm_hints
);
262 /**********************************************************************
263 * X11DRV_WND_CreateWindow
265 BOOL
X11DRV_WND_CreateWindow(WND
*wndPtr
, CLASS
*classPtr
, CREATESTRUCTA
*cs
, BOOL bUnicode
)
267 /* Create the X window (only for top-level windows, and then only */
268 /* when there's no desktop window) */
270 if (!(cs
->style
& WS_CHILD
) && (X11DRV_GetXRootWindow() == DefaultRootWindow(display
)))
274 XSetWindowAttributes win_attr
;
276 /* Create "managed" windows only if a title bar or resizable */
277 /* frame is required. */
278 if (WIN_WindowNeedsWMBorder(cs
->style
, cs
->dwExStyle
)) {
279 win_attr
.event_mask
= ExposureMask
| KeyPressMask
|
280 KeyReleaseMask
| PointerMotionMask
|
281 ButtonPressMask
| ButtonReleaseMask
|
282 FocusChangeMask
| StructureNotifyMask
;
283 win_attr
.override_redirect
= FALSE
;
284 wndPtr
->flags
|= WIN_MANAGED
;
286 win_attr
.event_mask
= ExposureMask
| KeyPressMask
|
287 KeyReleaseMask
| PointerMotionMask
|
288 ButtonPressMask
| ButtonReleaseMask
|
290 win_attr
.override_redirect
= TRUE
;
292 wndPtr
->flags
|= WIN_NATIVE
;
294 win_attr
.bit_gravity
= (classPtr
->style
& (CS_VREDRAW
| CS_HREDRAW
)) ? BGForget
: BGNorthWest
;
295 win_attr
.colormap
= X11DRV_PALETTE_PaletteXColormap
;
296 win_attr
.backing_store
= NotUseful
;
297 win_attr
.save_under
= ((classPtr
->style
& CS_SAVEBITS
) != 0);
298 win_attr
.cursor
= X11DRV_MOUSE_XCursor
;
300 ((X11DRV_WND_DATA
*) wndPtr
->pDriverData
)->hWMIconBitmap
= 0;
301 ((X11DRV_WND_DATA
*) wndPtr
->pDriverData
)->hWMIconMask
= 0;
302 ((X11DRV_WND_DATA
*) wndPtr
->pDriverData
)->bit_gravity
= win_attr
.bit_gravity
;
303 ((X11DRV_WND_DATA
*) wndPtr
->pDriverData
)->window
=
304 TSXCreateWindow( display
, X11DRV_GetXRootWindow(),
305 cs
->x
, cs
->y
, cs
->cx
, cs
->cy
,
307 InputOutput
, CopyFromParent
,
308 CWEventMask
| CWOverrideRedirect
|
309 CWColormap
| CWCursor
| CWSaveUnder
|
310 CWBackingStore
| CWBitGravity
,
313 if(!(wGroupLeader
= X11DRV_WND_GetXWindow(wndPtr
)))
316 /* If we are the systray, we need to be managed to be noticed by KWM */
318 if (wndPtr
->dwExStyle
& WS_EX_TRAYWINDOW
)
319 X11DRV_WND_DockWindow(wndPtr
);
321 if (wndPtr
->flags
& WIN_MANAGED
)
323 XClassHint
*class_hints
= TSXAllocClassHint();
324 XSizeHints
* size_hints
= TSXAllocSizeHints();
328 class_hints
->res_name
= "wineManaged";
329 class_hints
->res_class
= "Wine";
330 TSXSetClassHint( display
, ((X11DRV_WND_DATA
*) wndPtr
->pDriverData
)->window
, class_hints
);
331 TSXFree (class_hints
);
336 size_hints
->win_gravity
= StaticGravity
;
337 size_hints
->flags
= PWinGravity
;
339 if (HAS_DLGFRAME(cs
->style
,cs
->dwExStyle
))
341 size_hints
->min_width
= size_hints
->max_width
= cs
->cx
;
342 size_hints
->min_height
= size_hints
->max_height
= cs
->cy
;
343 size_hints
->flags
|= PMinSize
| PMaxSize
;
346 TSXSetWMSizeHints( display
, X11DRV_WND_GetXWindow(wndPtr
),
347 size_hints
, XA_WM_NORMAL_HINTS
);
352 if (cs
->hwndParent
) /* Get window owner */
355 WND
*tmpWnd
= WIN_FindWndPtr(cs
->hwndParent
);
357 w
= X11DRV_WND_FindXWindow( tmpWnd
);
360 TSXSetTransientForHint( display
, X11DRV_WND_GetXWindow(wndPtr
), w
);
363 WIN_ReleaseWndPtr(tmpWnd
);
366 if ((wm_hints
= TSXAllocWMHints()))
368 wm_hints
->flags
= InputHint
| StateHint
| WindowGroupHint
;
369 wm_hints
->input
= True
;
371 if( wndPtr
->flags
& WIN_MANAGED
)
373 X11DRV_WND_IconChanged(wndPtr
);
374 X11DRV_WND_SetIconHints(wndPtr
, wm_hints
);
376 wm_hints
->initial_state
= (wndPtr
->dwStyle
& WS_MINIMIZE
)
377 ? IconicState
: NormalState
;
380 wm_hints
->initial_state
= NormalState
;
381 wm_hints
->window_group
= wGroupLeader
;
383 TSXSetWMHints( display
, X11DRV_WND_GetXWindow(wndPtr
), wm_hints
);
386 X11DRV_WND_RegisterWindow( wndPtr
);
391 /***********************************************************************
392 * X11DRV_WND_DestroyWindow
394 BOOL
X11DRV_WND_DestroyWindow(WND
*wndPtr
)
397 if ((w
= X11DRV_WND_GetXWindow(wndPtr
)))
400 TSXDeleteContext( display
, w
, winContext
);
401 TSXDestroyWindow( display
, w
);
402 while( TSXCheckWindowEvent(display
, w
, NoEventMask
, &xe
) );
404 ((X11DRV_WND_DATA
*) wndPtr
->pDriverData
)->window
= None
;
405 if( ((X11DRV_WND_DATA
*) wndPtr
->pDriverData
)->hWMIconBitmap
)
407 DeleteObject( ((X11DRV_WND_DATA
*) wndPtr
->pDriverData
)->hWMIconBitmap
);
408 ((X11DRV_WND_DATA
*) wndPtr
->pDriverData
)->hWMIconBitmap
= 0;
410 if( ((X11DRV_WND_DATA
*) wndPtr
->pDriverData
)->hWMIconMask
)
412 DeleteObject( ((X11DRV_WND_DATA
*) wndPtr
->pDriverData
)->hWMIconMask
);
413 ((X11DRV_WND_DATA
*) wndPtr
->pDriverData
)->hWMIconMask
= 0;
420 /*****************************************************************
421 * X11DRV_WND_SetParent
423 WND
*X11DRV_WND_SetParent(WND
*wndPtr
, WND
*pWndParent
)
425 WND
*pDesktop
= WIN_GetDesktop();
427 if( wndPtr
&& pWndParent
&& (wndPtr
!= pDesktop
) )
429 WND
* pWndPrev
= wndPtr
->parent
;
431 if( pWndParent
!= pWndPrev
)
433 if ( X11DRV_WND_GetXWindow(wndPtr
) )
435 /* Toplevel window needs to be reparented. Used by Tk 8.0 */
437 TSXDestroyWindow( display
, X11DRV_WND_GetXWindow(wndPtr
) );
438 ((X11DRV_WND_DATA
*) wndPtr
->pDriverData
)->window
= None
;
441 WIN_UnlinkWindow(wndPtr
->hwndSelf
);
442 wndPtr
->parent
= pWndParent
;
444 /* Create an X counterpart for reparented top-level windows
445 * when not in the desktop mode. */
447 if( pWndParent
== pDesktop
)
449 wndPtr
->dwStyle
&= ~WS_CHILD
;
450 if( X11DRV_GetXRootWindow() == DefaultRootWindow(display
) )
453 cs
.lpCreateParams
= NULL
;
454 cs
.hInstance
= 0; /* not used in following call */
455 cs
.hMenu
= 0; /* not used in following call */
456 cs
.hwndParent
= pWndParent
->hwndSelf
;
457 cs
.cy
= wndPtr
->rectWindow
.bottom
- wndPtr
->rectWindow
.top
;
460 cs
.cx
= wndPtr
->rectWindow
.right
- wndPtr
->rectWindow
.left
;
463 cs
.y
= wndPtr
->rectWindow
.top
;
464 cs
.x
= wndPtr
->rectWindow
.left
;
465 cs
.style
= wndPtr
->dwStyle
;
466 cs
.lpszName
= 0; /* not used in following call */
467 cs
.lpszClass
= 0; /*not used in following call */
468 cs
.dwExStyle
= wndPtr
->dwExStyle
;
469 X11DRV_WND_CreateWindow(wndPtr
, wndPtr
->class,
473 else /* a child window */
475 if( !( wndPtr
->dwStyle
& WS_CHILD
) )
477 wndPtr
->dwStyle
|= WS_CHILD
;
478 if( wndPtr
->wIDmenu
!= 0)
480 DestroyMenu( (HMENU
) wndPtr
->wIDmenu
);
485 WIN_LinkWindow(wndPtr
->hwndSelf
, HWND_TOP
);
487 WIN_ReleaseDesktop();
490 WIN_ReleaseDesktop();
494 /***********************************************************************
495 * X11DRV_WND_ForceWindowRaise
497 * Raise a window on top of the X stacking order, while preserving
498 * the correct Windows Z order.
500 void X11DRV_WND_ForceWindowRaise(WND
*wndPtr
)
502 XWindowChanges winChanges
;
503 WND
*wndPrev
,*pDesktop
= WIN_GetDesktop();
505 if( !wndPtr
|| !X11DRV_WND_GetXWindow(wndPtr
) || (wndPtr
->flags
& WIN_MANAGED
) )
507 WIN_ReleaseDesktop();
511 /* Raise all windows up to wndPtr according to their Z order.
512 * (it would be easier with sibling-related Below but it doesn't
513 * work very well with SGI mwm for instance)
515 winChanges
.stack_mode
= Above
;
518 if (X11DRV_WND_GetXWindow(wndPtr
))
519 TSXReconfigureWMWindow( display
, X11DRV_WND_GetXWindow(wndPtr
), 0,
520 CWStackMode
, &winChanges
);
521 wndPrev
= pDesktop
->child
;
522 if (wndPrev
== wndPtr
) break;
523 while (wndPrev
&& (wndPrev
->next
!= wndPtr
)) wndPrev
= wndPrev
->next
;
526 WIN_ReleaseDesktop();
529 /***********************************************************************
530 * X11DRV_WND_FindDesktopXWindow [Internal]
532 * Find the actual X window which needs be restacked.
533 * Used by X11DRV_WND_SetWindowPos().
535 static Window
X11DRV_WND_FindDesktopXWindow( WND
*wndPtr
)
537 if (!(wndPtr
->flags
& WIN_MANAGED
))
538 return X11DRV_WND_GetXWindow(wndPtr
);
541 Window window
, root
, parent
, *children
;
543 window
= X11DRV_WND_GetXWindow(wndPtr
);
546 TSXQueryTree( display
, window
, &root
, &parent
,
547 &children
, &nchildren
);
556 /***********************************************************************
557 * WINPOS_SetXWindowPos
559 * SetWindowPos() for an X window. Used by the real SetWindowPos().
561 void X11DRV_WND_SetWindowPos(WND
*wndPtr
, const WINDOWPOS
*winpos
, BOOL bChangePos
)
563 XWindowChanges winChanges
;
565 WND
*winposPtr
= WIN_FindWndPtr( winpos
->hwnd
);
566 if ( !winposPtr
) return;
568 if(!wndPtr
->hwndSelf
) wndPtr
= NULL
; /* FIXME: WND destroyed, shouldn't happen!!! */
570 if (!(winpos
->flags
& SWP_SHOWWINDOW
) && (winpos
->flags
& SWP_HIDEWINDOW
))
572 if(X11DRV_WND_GetXWindow(wndPtr
))
573 TSXUnmapWindow( display
, X11DRV_WND_GetXWindow(wndPtr
) );
578 if ( !(winpos
->flags
& SWP_NOSIZE
))
580 winChanges
.width
= (winpos
->cx
> 0 ) ? winpos
->cx
: 1;
581 winChanges
.height
= (winpos
->cy
> 0 ) ? winpos
->cy
: 1;
582 changeMask
|= CWWidth
| CWHeight
;
584 /* Tweak dialog window size hints */
586 if ((winposPtr
->flags
& WIN_MANAGED
) &&
587 HAS_DLGFRAME(winposPtr
->dwStyle
,winposPtr
->dwExStyle
))
589 XSizeHints
*size_hints
= TSXAllocSizeHints();
593 long supplied_return
;
595 TSXGetWMSizeHints( display
, X11DRV_WND_GetXWindow(winposPtr
), size_hints
,
596 &supplied_return
, XA_WM_NORMAL_HINTS
);
597 size_hints
->min_width
= size_hints
->max_width
= winpos
->cx
;
598 size_hints
->min_height
= size_hints
->max_height
= winpos
->cy
;
599 TSXSetWMSizeHints( display
, X11DRV_WND_GetXWindow(winposPtr
), size_hints
,
600 XA_WM_NORMAL_HINTS
);
605 if (!(winpos
->flags
& SWP_NOMOVE
))
607 winChanges
.x
= winpos
->x
;
608 winChanges
.y
= winpos
->y
;
609 changeMask
|= CWX
| CWY
;
611 if (!(winpos
->flags
& SWP_NOZORDER
))
613 winChanges
.stack_mode
= Below
;
614 changeMask
|= CWStackMode
;
616 if (winpos
->hwndInsertAfter
== HWND_TOP
) winChanges
.stack_mode
= Above
;
617 else if (winpos
->hwndInsertAfter
!= HWND_BOTTOM
)
619 WND
* insertPtr
= WIN_FindWndPtr( winpos
->hwndInsertAfter
);
622 stack
[0] = X11DRV_WND_FindDesktopXWindow( insertPtr
);
623 stack
[1] = X11DRV_WND_FindDesktopXWindow( winposPtr
);
625 /* for stupid window managers (i.e. all of them) */
627 TSXRestackWindows(display
, stack
, 2);
628 changeMask
&= ~CWStackMode
;
630 WIN_ReleaseWndPtr(insertPtr
);
633 if (changeMask
&& X11DRV_WND_GetXWindow(winposPtr
))
635 TSXReconfigureWMWindow( display
, X11DRV_WND_GetXWindow(winposPtr
), 0, changeMask
, &winChanges
);
636 if( winposPtr
->class->style
& (CS_VREDRAW
| CS_HREDRAW
) )
637 X11DRV_WND_SetHostAttr( winposPtr
, HAK_BITGRAVITY
, BGForget
);
641 if ( winpos
->flags
& SWP_SHOWWINDOW
)
643 if(X11DRV_WND_GetXWindow(wndPtr
))
644 TSXMapWindow( display
, X11DRV_WND_GetXWindow(wndPtr
) );
646 WIN_ReleaseWndPtr(winposPtr
);
649 /*****************************************************************
652 void X11DRV_WND_SetText(WND
*wndPtr
, LPCSTR text
)
654 if (!X11DRV_WND_GetXWindow(wndPtr
))
657 TSXStoreName( display
, X11DRV_WND_GetXWindow(wndPtr
), text
);
658 TSXSetIconName( display
, X11DRV_WND_GetXWindow(wndPtr
), text
);
661 /*****************************************************************
662 * X11DRV_WND_SetFocus
665 * Explicit colormap management seems to work only with OLVWM.
667 void X11DRV_WND_SetFocus(WND
*wndPtr
)
669 HWND hwnd
= wndPtr
->hwndSelf
;
670 XWindowAttributes win_attr
;
674 /* Only mess with the X focus if there's */
675 /* no desktop window and if the window is not managed by the WM. */
676 if ((X11DRV_GetXRootWindow() != DefaultRootWindow(display
))) return;
677 while (w
&& !((X11DRV_WND_DATA
*) w
->pDriverData
)->window
)
680 if (w
->flags
& WIN_MANAGED
) return;
682 if (!hwnd
) /* If setting the focus to 0, uninstall the colormap */
684 if (X11DRV_PALETTE_PaletteFlags
& X11DRV_PALETTE_PRIVATE
)
685 TSXUninstallColormap( display
, X11DRV_PALETTE_PaletteXColormap
);
689 /* Set X focus and install colormap */
691 if (!(win
= X11DRV_WND_FindXWindow(wndPtr
))) return;
692 if (!TSXGetWindowAttributes( display
, win
, &win_attr
) ||
693 (win_attr
.map_state
!= IsViewable
))
694 return; /* If window is not viewable, don't change anything */
696 TSXSetInputFocus( display
, win
, RevertToParent
, CurrentTime
);
697 if (X11DRV_PALETTE_PaletteFlags
& X11DRV_PALETTE_PRIVATE
)
698 TSXInstallColormap( display
, X11DRV_PALETTE_PaletteXColormap
);
703 /*****************************************************************
704 * X11DRV_WND_PreSizeMove
706 void X11DRV_WND_PreSizeMove(WND
*wndPtr
)
708 if (!(wndPtr
->dwStyle
& WS_CHILD
) && (X11DRV_GetXRootWindow() == DefaultRootWindow(display
)))
709 TSXGrabServer( display
);
712 /*****************************************************************
713 * X11DRV_WND_PostSizeMove
715 void X11DRV_WND_PostSizeMove(WND
*wndPtr
)
717 if (!(wndPtr
->dwStyle
& WS_CHILD
) &&
718 (X11DRV_GetXRootWindow() == DefaultRootWindow(display
)))
719 TSXUngrabServer( display
);
722 /*****************************************************************
723 * X11DRV_WND_SurfaceCopy
725 * Copies rect to (rect.left + dx, rect.top + dy).
727 void X11DRV_WND_SurfaceCopy(WND
* wndPtr
, DC
*dcPtr
, INT dx
, INT dy
,
728 const RECT
*rect
, BOOL bUpdate
)
730 X11DRV_PDEVICE
*physDev
= (X11DRV_PDEVICE
*)dcPtr
->physDev
;
733 dst
.x
= (src
.x
= dcPtr
->w
.DCOrgX
+ rect
->left
) + dx
;
734 dst
.y
= (src
.y
= dcPtr
->w
.DCOrgY
+ rect
->top
) + dy
;
736 if (bUpdate
) /* handles non-Wine windows hanging over the copied area */
737 TSXSetGraphicsExposures( display
, physDev
->gc
, True
);
738 TSXSetFunction( display
, physDev
->gc
, GXcopy
);
739 TSXCopyArea( display
, physDev
->drawable
, physDev
->drawable
,
740 physDev
->gc
, src
.x
, src
.y
,
741 rect
->right
- rect
->left
,
742 rect
->bottom
- rect
->top
,
745 TSXSetGraphicsExposures( display
, physDev
->gc
, False
);
747 if (bUpdate
) /* Make sure exposure events have been processed */
751 /***********************************************************************
752 * X11DRV_WND_SetDrawable
754 * Set the drawable, origin and dimensions for the DC associated to
757 void X11DRV_WND_SetDrawable(WND
*wndPtr
, DC
*dc
, WORD flags
, BOOL bSetClipOrigin
)
759 X11DRV_PDEVICE
*physDev
= (X11DRV_PDEVICE
*)dc
->physDev
;
760 INT dcOrgXCopy
= 0, dcOrgYCopy
= 0;
761 BOOL offsetClipRgn
= FALSE
;
763 if (!wndPtr
) /* Get a DC for the whole screen */
767 physDev
->drawable
= X11DRV_GetXRootWindow();
768 TSXSetSubwindowMode( display
, physDev
->gc
, IncludeInferiors
);
773 * This function change the coordinate system (DCOrgX,DCOrgY)
774 * values. When it moves the origin, other data like the current clipping
775 * region will not be moved to that new origin. In the case of DCs that are class
776 * or window DCs that clipping region might be a valid value from a previous use
777 * of the DC and changing the origin of the DC without moving the clip region
778 * results in a clip region that is not placed properly in the DC.
779 * This code will save the dc origin, let the SetDrawable
780 * modify the origin and reset the clipping. When the clipping is set,
781 * it is moved according to the new DC origin.
783 if ( (wndPtr
->class->style
& (CS_OWNDC
| CS_CLASSDC
)) && (dc
->w
.hClipRgn
> 0))
785 dcOrgXCopy
= dc
->w
.DCOrgX
;
786 dcOrgYCopy
= dc
->w
.DCOrgY
;
787 offsetClipRgn
= TRUE
;
790 if (flags
& DCX_WINDOW
)
792 dc
->w
.DCOrgX
= wndPtr
->rectWindow
.left
;
793 dc
->w
.DCOrgY
= wndPtr
->rectWindow
.top
;
797 dc
->w
.DCOrgX
= wndPtr
->rectClient
.left
;
798 dc
->w
.DCOrgY
= wndPtr
->rectClient
.top
;
800 while (!X11DRV_WND_GetXWindow(wndPtr
))
802 wndPtr
= wndPtr
->parent
;
803 dc
->w
.DCOrgX
+= wndPtr
->rectClient
.left
;
804 dc
->w
.DCOrgY
+= wndPtr
->rectClient
.top
;
806 dc
->w
.DCOrgX
-= wndPtr
->rectWindow
.left
;
807 dc
->w
.DCOrgY
-= wndPtr
->rectWindow
.top
;
809 /* reset the clip region, according to the new origin */
812 OffsetRgn(dc
->w
.hClipRgn
, dc
->w
.DCOrgX
- dcOrgXCopy
,dc
->w
.DCOrgY
- dcOrgYCopy
);
815 physDev
->drawable
= X11DRV_WND_GetXWindow(wndPtr
);
818 /* This is needed when we reuse a cached DC because
819 * SetDCState() called by ReleaseDC() screws up DC
820 * origins for child windows.
824 TSXSetClipOrigin( display
, physDev
->gc
, dc
->w
.DCOrgX
, dc
->w
.DCOrgY
);
829 /***********************************************************************
832 static BOOL
X11DRV_SetWMHint(Display
* display
, WND
* wndPtr
, int hint
, int val
)
834 XWMHints
* wm_hints
= TSXGetWMHints( display
, X11DRV_WND_GetXWindow(wndPtr
) );
835 if (!wm_hints
) wm_hints
= TSXAllocWMHints();
838 wm_hints
->flags
= hint
;
842 wm_hints
->input
= val
;
846 wm_hints
->initial_state
= val
;
850 wm_hints
->icon_pixmap
= (Pixmap
)val
;
854 wm_hints
->icon_window
= (Window
)val
;
858 TSXSetWMHints( display
, X11DRV_WND_GetXWindow(wndPtr
), wm_hints
);
866 /***********************************************************************
867 * X11DRV_WND_SetHostAttr
869 * This function returns TRUE if the attribute is supported and the
870 * action was successful. Otherwise it should return FALSE and Wine will try
871 * to get by without the functionality provided by the host window system.
873 BOOL
X11DRV_WND_SetHostAttr(WND
* wnd
, INT ha
, INT value
)
877 if( (w
= X11DRV_WND_GetXWindow(wnd
)) )
879 XSetWindowAttributes win_attr
;
883 case HAK_ICONICSTATE
: /* called when a window is minimized/restored */
885 if( (wnd
->flags
& WIN_MANAGED
) )
889 if( wnd
->dwStyle
& WS_VISIBLE
)
891 XClientMessageEvent ev
;
893 /* FIXME: set proper icon */
895 ev
.type
= ClientMessage
;
896 ev
.display
= display
;
897 ev
.message_type
= wmChangeState
;
899 ev
.data
.l
[0] = IconicState
;
902 if( TSXSendEvent (display
,
903 RootWindow( display
, XScreenNumberOfScreen(X11DRV_GetXScreen()) ),
904 True
, (SubstructureRedirectMask
| SubstructureNotifyMask
), (XEvent
*)&ev
))
908 while( !TSXCheckTypedWindowEvent( display
, w
, UnmapNotify
, &xe
) );
914 X11DRV_SetWMHint( display
, wnd
, StateHint
, IconicState
);
918 if( !(wnd
->flags
& WS_VISIBLE
) )
919 X11DRV_SetWMHint( display
, wnd
, StateHint
, NormalState
);
923 TSXMapWindow(display
, w
);
924 while( !TSXCheckTypedWindowEvent( display
, w
, MapNotify
, &xe
) );
931 case HAK_BITGRAVITY
: /* called when a window is resized */
933 if( ((X11DRV_WND_DATA
*) wnd
->pDriverData
)->bit_gravity
!= value
)
935 win_attr
.bit_gravity
= value
;
936 ((X11DRV_WND_DATA
*) wnd
->pDriverData
)->bit_gravity
= value
;
937 TSXChangeWindowAttributes( display
, w
, CWBitGravity
, &win_attr
);
941 case HAK_ICONS
: /* called when the icons change */
942 if ( (wnd
->flags
& WIN_MANAGED
) )
943 X11DRV_WND_UpdateIconHints(wnd
);
946 case HAK_ACCEPTFOCUS
: /* called when a window is disabled/enabled */
948 if( (wnd
->flags
& WIN_MANAGED
) )
949 return X11DRV_SetWMHint( display
, wnd
, InputHint
, value
);
955 /***********************************************************************
956 * X11DRV_WND_IsSelfClipping
958 BOOL
X11DRV_WND_IsSelfClipping(WND
*wndPtr
)
960 return X11DRV_WND_GetXWindow(wndPtr
) != None
;
963 /***********************************************************************
964 * X11DRV_WND_DockWindow
966 * Set the X Property of the window that tells the windowmanager we really
967 * want to be in the systray
969 * KDE: set "KWM_DOCKWINDOW", type "KWM_DOCKWINDOW" to 1 before a window is
972 * all others: to be added ;)
974 void X11DRV_WND_DockWindow(WND
*wndPtr
)
977 Window win
= X11DRV_WND_GetXWindow(wndPtr
);
978 if (kwmDockWindow
== None
)
979 return; /* no KDE running */
981 display
,win
,kwmDockWindow
,kwmDockWindow
,32,PropModeReplace
,(char*)&data
,1