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;
451 if( X11DRV_GetXRootWindow() == DefaultRootWindow(display) )
454 cs.lpCreateParams = NULL;
455 cs.hInstance = 0; /* not used in following call */
456 cs.hMenu = 0; /* not used in following call */
457 cs.hwndParent = pWndParent->hwndSelf;
458 cs.cy = wndPtr->rectWindow.bottom - wndPtr->rectWindow.top;
461 cs.cx = wndPtr->rectWindow.right - wndPtr->rectWindow.left;
464 cs.y = wndPtr->rectWindow.top;
465 cs.x = wndPtr->rectWindow.left;
466 cs.style = wndPtr->dwStyle;
467 cs.lpszName = 0; /* not used in following call */
468 cs.lpszClass = 0; /*not used in following call */
469 cs.dwExStyle = wndPtr->dwExStyle;
470 X11DRV_WND_CreateWindow(wndPtr, wndPtr->class,
474 else /* a child window */
476 if( !( wndPtr->dwStyle & WS_CHILD ) )
478 wndPtr->dwStyle |= WS_CHILD;
479 if( wndPtr->wIDmenu != 0)
481 DestroyMenu( (HMENU) wndPtr->wIDmenu );
486 WIN_LinkWindow(wndPtr->hwndSelf, HWND_TOP);
488 WIN_ReleaseDesktop();
491 WIN_ReleaseDesktop();
495 /***********************************************************************
496 * X11DRV_WND_ForceWindowRaise
498 * Raise a window on top of the X stacking order, while preserving
499 * the correct Windows Z order.
501 void X11DRV_WND_ForceWindowRaise(WND *wndPtr)
503 XWindowChanges winChanges;
504 WND *wndPrev,*pDesktop = WIN_GetDesktop();
506 if( !wndPtr || !X11DRV_WND_GetXWindow(wndPtr) || (wndPtr->flags & WIN_MANAGED) )
508 WIN_ReleaseDesktop();
512 /* Raise all windows up to wndPtr according to their Z order.
513 * (it would be easier with sibling-related Below but it doesn't
514 * work very well with SGI mwm for instance)
516 winChanges.stack_mode = Above;
519 if (X11DRV_WND_GetXWindow(wndPtr))
520 TSXReconfigureWMWindow( display, X11DRV_WND_GetXWindow(wndPtr), 0,
521 CWStackMode, &winChanges );
522 wndPrev = pDesktop->child;
523 if (wndPrev == wndPtr) break;
524 while (wndPrev && (wndPrev->next != wndPtr)) wndPrev = wndPrev->next;
527 WIN_ReleaseDesktop();
530 /***********************************************************************
531 * X11DRV_WND_FindDesktopXWindow [Internal]
533 * Find the actual X window which needs be restacked.
534 * Used by X11DRV_WND_SetWindowPos().
536 static Window X11DRV_WND_FindDesktopXWindow( WND *wndPtr )
538 if (!(wndPtr->flags & WIN_MANAGED))
539 return X11DRV_WND_GetXWindow(wndPtr);
542 Window window, root, parent, *children;
544 window = X11DRV_WND_GetXWindow(wndPtr);
547 TSXQueryTree( display, window, &root, &parent,
548 &children, &nchildren );
557 /***********************************************************************
558 * WINPOS_SetXWindowPos
560 * SetWindowPos() for an X window. Used by the real SetWindowPos().
562 void X11DRV_WND_SetWindowPos(WND *wndPtr, const WINDOWPOS *winpos, BOOL bChangePos)
564 XWindowChanges winChanges;
566 WND *winposPtr = WIN_FindWndPtr( winpos->hwnd );
567 if ( !winposPtr ) return;
569 if(!wndPtr->hwndSelf) wndPtr = NULL; /* FIXME: WND destroyed, shouldn't happen!!! */
571 if (!(winpos->flags & SWP_SHOWWINDOW) && (winpos->flags & SWP_HIDEWINDOW))
573 if(X11DRV_WND_GetXWindow(wndPtr))
574 TSXUnmapWindow( display, X11DRV_WND_GetXWindow(wndPtr) );
579 if ( !(winpos->flags & SWP_NOSIZE))
581 winChanges.width = (winpos->cx > 0 ) ? winpos->cx : 1;
582 winChanges.height = (winpos->cy > 0 ) ? winpos->cy : 1;
583 changeMask |= CWWidth | CWHeight;
585 /* Tweak dialog window size hints */
587 if ((winposPtr->flags & WIN_MANAGED) &&
588 HAS_DLGFRAME(winposPtr->dwStyle,winposPtr->dwExStyle))
590 XSizeHints *size_hints = TSXAllocSizeHints();
594 long supplied_return;
596 TSXGetWMSizeHints( display, X11DRV_WND_GetXWindow(winposPtr), size_hints,
597 &supplied_return, XA_WM_NORMAL_HINTS);
598 size_hints->min_width = size_hints->max_width = winpos->cx;
599 size_hints->min_height = size_hints->max_height = winpos->cy;
600 TSXSetWMSizeHints( display, X11DRV_WND_GetXWindow(winposPtr), size_hints,
601 XA_WM_NORMAL_HINTS );
606 if (!(winpos->flags & SWP_NOMOVE))
608 winChanges.x = winpos->x;
609 winChanges.y = winpos->y;
610 changeMask |= CWX | CWY;
612 if (!(winpos->flags & SWP_NOZORDER))
614 winChanges.stack_mode = Below;
615 changeMask |= CWStackMode;
617 if (winpos->hwndInsertAfter == HWND_TOP) winChanges.stack_mode = Above;
618 else if (winpos->hwndInsertAfter != HWND_BOTTOM)
620 WND* insertPtr = WIN_FindWndPtr( winpos->hwndInsertAfter );
623 stack[0] = X11DRV_WND_FindDesktopXWindow( insertPtr );
624 stack[1] = X11DRV_WND_FindDesktopXWindow( winposPtr );
626 /* for stupid window managers (i.e. all of them) */
628 TSXRestackWindows(display, stack, 2);
629 changeMask &= ~CWStackMode;
631 WIN_ReleaseWndPtr(insertPtr);
634 if (changeMask && X11DRV_WND_GetXWindow(winposPtr))
636 TSXReconfigureWMWindow( display, X11DRV_WND_GetXWindow(winposPtr), 0, changeMask, &winChanges );
637 if( winposPtr->class->style & (CS_VREDRAW | CS_HREDRAW) )
638 X11DRV_WND_SetHostAttr( winposPtr, HAK_BITGRAVITY, BGForget );
642 if ( winpos->flags & SWP_SHOWWINDOW )
644 if(X11DRV_WND_GetXWindow(wndPtr))
645 TSXMapWindow( display, X11DRV_WND_GetXWindow(wndPtr) );
647 WIN_ReleaseWndPtr(winposPtr);
650 /*****************************************************************
653 void X11DRV_WND_SetText(WND *wndPtr, LPCSTR text)
655 if (!X11DRV_WND_GetXWindow(wndPtr))
658 TSXStoreName( display, X11DRV_WND_GetXWindow(wndPtr), text );
659 TSXSetIconName( display, X11DRV_WND_GetXWindow(wndPtr), text );
662 /*****************************************************************
663 * X11DRV_WND_SetFocus
666 * Explicit colormap management seems to work only with OLVWM.
668 void X11DRV_WND_SetFocus(WND *wndPtr)
670 HWND hwnd = wndPtr->hwndSelf;
671 XWindowAttributes win_attr;
675 /* Only mess with the X focus if there's */
676 /* no desktop window and if the window is not managed by the WM. */
677 if ((X11DRV_GetXRootWindow() != DefaultRootWindow(display))) return;
678 while (w && !((X11DRV_WND_DATA *) w->pDriverData)->window)
681 if (w->flags & WIN_MANAGED) return;
683 if (!hwnd) /* If setting the focus to 0, uninstall the colormap */
685 if (X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_PRIVATE)
686 TSXUninstallColormap( display, X11DRV_PALETTE_PaletteXColormap );
690 /* Set X focus and install colormap */
692 if (!(win = X11DRV_WND_FindXWindow(wndPtr))) return;
693 if (!TSXGetWindowAttributes( display, win, &win_attr ) ||
694 (win_attr.map_state != IsViewable))
695 return; /* If window is not viewable, don't change anything */
697 TSXSetInputFocus( display, win, RevertToParent, CurrentTime );
698 if (X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_PRIVATE)
699 TSXInstallColormap( display, X11DRV_PALETTE_PaletteXColormap );
704 /*****************************************************************
705 * X11DRV_WND_PreSizeMove
707 void X11DRV_WND_PreSizeMove(WND *wndPtr)
709 if (!(wndPtr->dwStyle & WS_CHILD) && (X11DRV_GetXRootWindow() == DefaultRootWindow(display)))
710 TSXGrabServer( display );
713 /*****************************************************************
714 * X11DRV_WND_PostSizeMove
716 void X11DRV_WND_PostSizeMove(WND *wndPtr)
718 if (!(wndPtr->dwStyle & WS_CHILD) &&
719 (X11DRV_GetXRootWindow() == DefaultRootWindow(display)))
720 TSXUngrabServer( display );
723 /*****************************************************************
724 * X11DRV_WND_SurfaceCopy
726 * Copies rect to (rect.left + dx, rect.top + dy).
728 void X11DRV_WND_SurfaceCopy(WND* wndPtr, DC *dcPtr, INT dx, INT dy,
729 const RECT *rect, BOOL bUpdate)
731 X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dcPtr->physDev;
734 dst.x = (src.x = dcPtr->w.DCOrgX + rect->left) + dx;
735 dst.y = (src.y = dcPtr->w.DCOrgY + rect->top) + dy;
737 if (bUpdate) /* handles non-Wine windows hanging over the copied area */
738 TSXSetGraphicsExposures( display, physDev->gc, True );
739 TSXSetFunction( display, physDev->gc, GXcopy );
740 TSXCopyArea( display, physDev->drawable, physDev->drawable,
741 physDev->gc, src.x, src.y,
742 rect->right - rect->left,
743 rect->bottom - rect->top,
746 TSXSetGraphicsExposures( display, physDev->gc, False );
748 if (bUpdate) /* Make sure exposure events have been processed */
752 /***********************************************************************
753 * X11DRV_WND_SetDrawable
755 * Set the drawable, origin and dimensions for the DC associated to
758 void X11DRV_WND_SetDrawable(WND *wndPtr, DC *dc, WORD flags, BOOL bSetClipOrigin)
760 X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
761 INT dcOrgXCopy = 0, dcOrgYCopy = 0;
762 BOOL offsetClipRgn = FALSE;
764 if (!wndPtr) /* Get a DC for the whole screen */
768 physDev->drawable = X11DRV_GetXRootWindow();
769 TSXSetSubwindowMode( display, physDev->gc, IncludeInferiors );
774 * This function change the coordinate system (DCOrgX,DCOrgY)
775 * values. When it moves the origin, other data like the current clipping
776 * region will not be moved to that new origin. In the case of DCs that are class
777 * or window DCs that clipping region might be a valid value from a previous use
778 * of the DC and changing the origin of the DC without moving the clip region
779 * results in a clip region that is not placed properly in the DC.
780 * This code will save the dc origin, let the SetDrawable
781 * modify the origin and reset the clipping. When the clipping is set,
782 * it is moved according to the new DC origin.
784 if ( (wndPtr->class->style & (CS_OWNDC | CS_CLASSDC)) && (dc->w.hClipRgn > 0))
786 dcOrgXCopy = dc->w.DCOrgX;
787 dcOrgYCopy = dc->w.DCOrgY;
788 offsetClipRgn = TRUE;
791 if (flags & DCX_WINDOW)
793 dc->w.DCOrgX = wndPtr->rectWindow.left;
794 dc->w.DCOrgY = wndPtr->rectWindow.top;
798 dc->w.DCOrgX = wndPtr->rectClient.left;
799 dc->w.DCOrgY = wndPtr->rectClient.top;
801 while (!X11DRV_WND_GetXWindow(wndPtr))
803 wndPtr = wndPtr->parent;
804 dc->w.DCOrgX += wndPtr->rectClient.left;
805 dc->w.DCOrgY += wndPtr->rectClient.top;
807 dc->w.DCOrgX -= wndPtr->rectWindow.left;
808 dc->w.DCOrgY -= wndPtr->rectWindow.top;
810 /* reset the clip region, according to the new origin */
813 OffsetRgn(dc->w.hClipRgn, dc->w.DCOrgX - dcOrgXCopy,dc->w.DCOrgY - dcOrgYCopy);
816 physDev->drawable = X11DRV_WND_GetXWindow(wndPtr);
819 /* This is needed when we reuse a cached DC because
820 * SetDCState() called by ReleaseDC() screws up DC
821 * origins for child windows.
825 TSXSetClipOrigin( display, physDev->gc, dc->w.DCOrgX, dc->w.DCOrgY );
830 /***********************************************************************
833 static BOOL X11DRV_SetWMHint(Display* display, WND* wndPtr, int hint, int val)
835 XWMHints* wm_hints = TSXGetWMHints( display, X11DRV_WND_GetXWindow(wndPtr) );
836 if (!wm_hints) wm_hints = TSXAllocWMHints();
839 wm_hints->flags = hint;
843 wm_hints->input = val;
847 wm_hints->initial_state = val;
851 wm_hints->icon_pixmap = (Pixmap)val;
855 wm_hints->icon_window = (Window)val;
859 TSXSetWMHints( display, X11DRV_WND_GetXWindow(wndPtr), wm_hints );
867 /***********************************************************************
868 * X11DRV_WND_SetHostAttr
870 * This function returns TRUE if the attribute is supported and the
871 * action was successful. Otherwise it should return FALSE and Wine will try
872 * to get by without the functionality provided by the host window system.
874 BOOL X11DRV_WND_SetHostAttr(WND* wnd, INT ha, INT value)
878 if( (w = X11DRV_WND_GetXWindow(wnd)) )
880 XSetWindowAttributes win_attr;
884 case HAK_ICONICSTATE: /* called when a window is minimized/restored */
886 if( (wnd->flags & WIN_MANAGED) )
890 if( wnd->dwStyle & WS_VISIBLE )
892 XClientMessageEvent ev;
894 /* FIXME: set proper icon */
896 ev.type = ClientMessage;
897 ev.display = display;
898 ev.message_type = wmChangeState;
900 ev.data.l[0] = IconicState;
903 if( TSXSendEvent (display,
904 RootWindow( display, XScreenNumberOfScreen(X11DRV_GetXScreen()) ),
905 True, (SubstructureRedirectMask | SubstructureNotifyMask), (XEvent*)&ev))
909 while( !TSXCheckTypedWindowEvent( display, w, UnmapNotify, &xe) );
915 X11DRV_SetWMHint( display, wnd, StateHint, IconicState );
919 if( !(wnd->flags & WS_VISIBLE) )
920 X11DRV_SetWMHint( display, wnd, StateHint, NormalState );
924 TSXMapWindow(display, w );
925 while( !TSXCheckTypedWindowEvent( display, w, MapNotify, &xe) );
932 case HAK_BITGRAVITY: /* called when a window is resized */
934 if( ((X11DRV_WND_DATA *) wnd->pDriverData)->bit_gravity != value )
936 win_attr.bit_gravity = value;
937 ((X11DRV_WND_DATA *) wnd->pDriverData)->bit_gravity = value;
938 TSXChangeWindowAttributes( display, w, CWBitGravity, &win_attr );
942 case HAK_ICONS: /* called when the icons change */
943 if ( (wnd->flags & WIN_MANAGED) )
944 X11DRV_WND_UpdateIconHints(wnd);
947 case HAK_ACCEPTFOCUS: /* called when a window is disabled/enabled */
949 if( (wnd->flags & WIN_MANAGED) )
950 return X11DRV_SetWMHint( display, wnd, InputHint, value );
956 /***********************************************************************
957 * X11DRV_WND_IsSelfClipping
959 BOOL X11DRV_WND_IsSelfClipping(WND *wndPtr)
961 return X11DRV_WND_GetXWindow(wndPtr) != None;
964 /***********************************************************************
965 * X11DRV_WND_DockWindow
967 * Set the X Property of the window that tells the windowmanager we really
968 * want to be in the systray
970 * KDE: set "KWM_DOCKWINDOW", type "KWM_DOCKWINDOW" to 1 before a window is
973 * all others: to be added ;)
975 void X11DRV_WND_DockWindow(WND *wndPtr)
978 Window win = X11DRV_WND_GetXWindow(wndPtr);
979 if (kwmDockWindow == None)
980 return; /* no KDE running */
982 display,win,kwmDockWindow,kwmDockWindow,32,PropModeReplace,(char*)&data,1