/nx-3.5.0/nx-X11/programs/Xserver/hw/nxagent/NXwindow.c
C | 4179 lines | 3338 code | 377 blank | 464 comment | 817 complexity | 17995efbba0762126b9891ab0454d8aa MD5 | raw file
Possible License(s): BSD-3-Clause, GPL-2.0, LGPL-2.0
Large files files are truncated, but you can click here to view the full file
- #ifdef NXAGENT_UPGRADE
- #include "X/NXwindow.c"
- #else
- /**************************************************************************/
- /* */
- /* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/. */
- /* */
- /* NXAGENT, NX protocol compression and NX extensions to this software */
- /* are copyright of NoMachine. Redistribution and use of the present */
- /* software is allowed according to terms specified in the file LICENSE */
- /* which comes in the source distribution. */
- /* */
- /* Check http://www.nomachine.com/licensing.html for applicability. */
- /* */
- /* NX and NoMachine are trademarks of Medialogic S.p.A. */
- /* */
- /* All rights reserved. */
- /* */
- /**************************************************************************/
- /*
- Copyright 1987, 1998 The Open Group
- Permission to use, copy, modify, distribute, and sell this software and its
- documentation for any purpose is hereby granted without fee, provided that
- the above copyright notice appear in all copies and that both that
- copyright notice and this permission notice appear in supporting
- documentation.
- The above copyright notice and this permission notice shall be included
- in all copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
- OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- OTHER DEALINGS IN THE SOFTWARE.
- Except as contained in this notice, the name of The Open Group shall
- not be used in advertising or otherwise to promote the sale, use or
- other dealings in this Software without prior written authorization
- from The Open Group.
- Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
- All Rights Reserved
- Permission to use, copy, modify, and distribute this software and its
- documentation for any purpose and without fee is hereby granted,
- provided that the above copyright notice appear in all copies and that
- both that copyright notice and this permission notice appear in
- supporting documentation, and that the name of Digital not be
- used in advertising or publicity pertaining to distribution of the
- software without specific, written prior permission.
- DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
- ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
- DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
- ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
- WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
- ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- SOFTWARE.
- */
- /****************************************************************
- * *
- * Copyright (c) Digital Equipment Corporation, 1991, 1997 *
- * *
- * All Rights Reserved. Unpublished rights reserved under *
- * the copyright laws of the United States. *
- * *
- * The software contained on this media is proprietary to *
- * and embodies the confidential technology of Digital *
- * Equipment Corporation. Possession, use, duplication or *
- * dissemination of the software and media is authorized only *
- * pursuant to a valid written license from Digital Equipment *
- * Corporation. *
- * *
- * RESTRICTED RIGHTS LEGEND Use, duplication, or disclosure *
- * by the U.S. Government is subject to restrictions as set *
- * forth in Subparagraph (c)(1)(ii) of DFARS 252.227-7013, *
- * or in FAR 52.227-19, as applicable. *
- * *
- *****************************************************************/
- #include "misc.h"
- #include "scrnintstr.h"
- #include "os.h"
- #include "regionstr.h"
- #include "validate.h"
- #include "windowstr.h"
- #include "input.h"
- #include "resource.h"
- #include "colormapst.h"
- #include "cursorstr.h"
- #include "dixstruct.h"
- #include "gcstruct.h"
- #include "servermd.h"
- #include "selection.h"
- #ifdef PANORAMIX
- #include "../../Xext/panoramiX.h"
- #include "../../Xext/panoramiXsrv.h"
- #endif
- #include "dixevents.h"
- #include "globals.h"
- #ifdef XAPPGROUP
- #include "Xagsrv.h"
- #endif
- #ifdef XCSECURITY
- #define _SECURITY_SERVER
- #include "security.h"
- #endif
- #include "Screen.h"
- #include "Options.h"
- #include "Atoms.h"
- #include "Clipboard.h"
- #include "Splash.h"
- #include "Rootless.h"
- #include "Composite.h"
- #include "Drawable.h"
- #include "Colormap.h"
- #if defined(NEED_SCREEN_REGIONS)
- #define REGION_PTR(pScreen,pWin) \
- register ScreenPtr pScreen = pWin->drawable.pScreen;
- #else
- #define REGION_PTR(pScreen,pWin) /* nothing */
- #endif
- extern Bool nxagentWMIsRunning;
- extern Bool nxagentScreenTrap;
- /******
- * Window stuff for server
- *
- * CreateRootWindow, CreateWindow, ChangeWindowAttributes,
- * GetWindowAttributes, DeleteWindow, DestroySubWindows,
- * HandleSaveSet, ReparentWindow, MapWindow, MapSubWindows,
- * UnmapWindow, UnmapSubWindows, ConfigureWindow, CirculateWindow,
- *
- ******/
- int screenIsSaved = SCREEN_SAVER_OFF;
- ScreenSaverStuffRec savedScreenInfo[MAXSCREENS];
- #if 0
- extern void DeleteWindowFromAnyEvents();
- extern Mask EventMaskForClient();
- extern void WindowHasNewCursor();
- extern void RecalculateDeliverableEvents();
- #endif
- static Bool TileScreenSaver(
- #if NeedFunctionPrototypes
- int /*i*/,
- int /*kind*/
- #endif
- );
- #define INPUTONLY_LEGAL_MASK (CWWinGravity | CWEventMask | \
- CWDontPropagate | CWOverrideRedirect | CWCursor )
- #define BOXES_OVERLAP(b1, b2) \
- (!( ((b1)->x2 <= (b2)->x1) || \
- ( ((b1)->x1 >= (b2)->x2)) || \
- ( ((b1)->y2 <= (b2)->y1)) || \
- ( ((b1)->y1 >= (b2)->y2)) ) )
- #define RedirectSend(pWin) \
- ((pWin->eventMask|wOtherEventMasks(pWin)) & SubstructureRedirectMask)
- #define SubSend(pWin) \
- ((pWin->eventMask|wOtherEventMasks(pWin)) & SubstructureNotifyMask)
- #define StrSend(pWin) \
- ((pWin->eventMask|wOtherEventMasks(pWin)) & StructureNotifyMask)
- #define SubStrSend(pWin,pParent) (StrSend(pWin) || SubSend(pParent))
- /*
- * Set here the required log level.
- */
- #define PANIC
- #define WARNING
- #undef TEST
- #undef DEBUG
- int numSaveUndersViewable = 0;
- int deltaSaveUndersViewable = 0;
- WindowPtr nxagentRootTileWindow;
- /*
- * This block used the DEBUG symbol.
- */
- #ifdef WINDOW_TREE_DEBUG
- /******
- * PrintWindowTree
- * For debugging only
- ******/
- int
- PrintChildren(p1, indent)
- WindowPtr p1;
- int indent;
- {
- WindowPtr p2;
- int i;
- while (p1)
- {
- p2 = p1->firstChild;
- for (i=0; i<indent; i++) ErrorF( " ");
- ErrorF( "%x\n", p1->drawable.id);
- miPrintRegion(&p1->clipList);
- PrintChildren(p2, indent+4);
- p1 = p1->nextSib;
- }
- }
- PrintWindowTree()
- {
- int i;
- WindowPtr pWin, p1;
- for (i=0; i<screenInfo.numScreens; i++)
- {
- ErrorF( "WINDOW %d\n", i);
- pWin = WindowTable[i];
- miPrintRegion(&pWin->clipList);
- p1 = pWin->firstChild;
- PrintChildren(p1, 4);
- }
- }
- #endif
- int
- TraverseTree(pWin, func, data)
- register WindowPtr pWin;
- VisitWindowProcPtr func;
- pointer data;
- {
- register int result;
- register WindowPtr pChild;
- if (!(pChild = pWin))
- return(WT_NOMATCH);
- while (1)
- {
- result = (* func)(pChild, data);
- if (result == WT_STOPWALKING)
- return(WT_STOPWALKING);
- if ((result == WT_WALKCHILDREN) && pChild->firstChild)
- {
- pChild = pChild->firstChild;
- continue;
- }
- while (!pChild->nextSib && (pChild != pWin))
- pChild = pChild->parent;
- if (pChild == pWin)
- break;
- pChild = pChild->nextSib;
- }
- return(WT_NOMATCH);
- }
- /*****
- * WalkTree
- * Walk the window tree, for SCREEN, preforming FUNC(pWin, data) on
- * each window. If FUNC returns WT_WALKCHILDREN, traverse the children,
- * if it returns WT_DONTWALKCHILDREN, dont. If it returns WT_STOPWALKING
- * exit WalkTree. Does depth-first traverse.
- *****/
- int
- WalkTree(pScreen, func, data)
- ScreenPtr pScreen;
- VisitWindowProcPtr func;
- pointer data;
- {
- return(TraverseTree(WindowTable[pScreen->myNum], func, data));
- }
- /* hack for forcing backing store on all windows */
- int defaultBackingStore = NotUseful;
- /* hack to force no backing store */
- Bool disableBackingStore = FALSE;
- Bool enableBackingStore = FALSE;
- /* hack to force no save unders */
- Bool disableSaveUnders = FALSE;
- static void
- #if NeedFunctionPrototypes
- SetWindowToDefaults(register WindowPtr pWin)
- #else
- SetWindowToDefaults(pWin)
- register WindowPtr pWin;
- #endif
- {
- pWin->prevSib = NullWindow;
- pWin->firstChild = NullWindow;
- pWin->lastChild = NullWindow;
- pWin->valdata = (ValidatePtr)NULL;
- pWin->optional = (WindowOptPtr)NULL;
- pWin->cursorIsNone = TRUE;
- pWin->backingStore = NotUseful;
- pWin->DIXsaveUnder = FALSE;
- pWin->backStorage = (pointer) NULL;
- pWin->mapped = FALSE; /* off */
- pWin->realized = FALSE; /* off */
- pWin->viewable = FALSE;
- pWin->visibility = VisibilityNotViewable;
- pWin->overrideRedirect = FALSE;
- pWin->saveUnder = FALSE;
- pWin->bitGravity = ForgetGravity;
- pWin->winGravity = NorthWestGravity;
- pWin->eventMask = 0;
- pWin->deliverableEvents = 0;
- pWin->dontPropagate = 0;
- pWin->forcedBS = FALSE;
- #ifdef NEED_DBE_BUF_BITS
- pWin->srcBuffer = DBE_FRONT_BUFFER;
- pWin->dstBuffer = DBE_FRONT_BUFFER;
- #endif
- }
- void nxagentClearSplash(WindowPtr pW)
- {
- int w, h;
- ScreenPtr pScreen;
- w = pW->drawable.width;
- h = pW->drawable.height;
- pScreen = pW->drawable.pScreen;
- if (pW->backgroundState == BackgroundPixmap)
- {
- (*pScreen->DestroyPixmap)(pW->background.pixmap);
- }
- pW->backgroundState = BackgroundPixel;
- pW->background.pixel = nxagentLogoBlack;
- (*pScreen->ChangeWindowAttributes)(pW, CWBackPixmap|CWBackPixel);
- }
- static void
- #if NeedFunctionPrototypes
- MakeRootTile(WindowPtr pWin)
- #else
- MakeRootTile(pWin)
- WindowPtr pWin;
- #endif
- {
- nxagentRootTileWindow = pWin;
- }
- WindowPtr
- AllocateWindow(pScreen)
- ScreenPtr pScreen;
- {
- WindowPtr pWin;
- register char *ptr;
- register DevUnion *ppriv;
- register unsigned *sizes;
- register unsigned size;
- register int i;
- pWin = (WindowPtr)xalloc(pScreen->totalWindowSize);
- if (pWin)
- {
- ppriv = (DevUnion *)(pWin + 1);
- pWin->devPrivates = ppriv;
- sizes = pScreen->WindowPrivateSizes;
- ptr = (char *)(ppriv + pScreen->WindowPrivateLen);
- for (i = pScreen->WindowPrivateLen; --i >= 0; ppriv++, sizes++)
- {
- if ( (size = *sizes) )
- {
- ppriv->ptr = (pointer)ptr;
- ptr += size;
- }
- else
- ppriv->ptr = (pointer)NULL;
- }
- }
- return pWin;
- }
- /*****
- * CreateRootWindow
- * Makes a window at initialization time for specified screen
- *****/
- Bool
- CreateRootWindow(pScreen)
- ScreenPtr pScreen;
- {
- WindowPtr pWin;
- BoxRec box;
- PixmapFormatRec *format;
- pWin = AllocateWindow(pScreen);
- if (!pWin)
- return FALSE;
- savedScreenInfo[pScreen->myNum].pWindow = NULL;
- savedScreenInfo[pScreen->myNum].wid = FakeClientID(0);
- savedScreenInfo[pScreen->myNum].ExternalScreenSaver = NULL;
- screenIsSaved = SCREEN_SAVER_OFF;
- WindowTable[pScreen->myNum] = pWin;
- pWin->drawable.pScreen = pScreen;
- pWin->drawable.type = DRAWABLE_WINDOW;
- pWin->drawable.depth = pScreen->rootDepth;
- for (format = screenInfo.formats;
- format->depth != pScreen->rootDepth;
- format++)
- ;
- pWin->drawable.bitsPerPixel = format->bitsPerPixel;
- pWin->drawable.serialNumber = NEXT_SERIAL_NUMBER;
- pWin->parent = NullWindow;
- SetWindowToDefaults(pWin);
- pWin->optional = (WindowOptRec *) xalloc (sizeof (WindowOptRec));
- if (!pWin->optional)
- return FALSE;
- pWin->optional->dontPropagateMask = 0;
- pWin->optional->otherEventMasks = 0;
- pWin->optional->otherClients = NULL;
- pWin->optional->passiveGrabs = NULL;
- pWin->optional->userProps = NULL;
- pWin->optional->backingBitPlanes = ~0L;
- pWin->optional->backingPixel = 0;
- #ifdef SHAPE
- pWin->optional->boundingShape = NULL;
- pWin->optional->clipShape = NULL;
- #endif
- #ifdef XINPUT
- pWin->optional->inputMasks = NULL;
- #endif
- pWin->optional->colormap = pScreen->defColormap;
- pWin->optional->visual = pScreen->rootVisual;
- pWin->nextSib = NullWindow;
- pWin->drawable.id = FakeClientID(0);
- pWin->origin.x = pWin->origin.y = 0;
- pWin->drawable.height = pScreen->height;
- pWin->drawable.width = pScreen->width;
- pWin->drawable.x = pWin->drawable.y = 0;
- box.x1 = 0;
- box.y1 = 0;
- box.x2 = pScreen->width;
- box.y2 = pScreen->height;
- REGION_INIT(pScreen, &pWin->clipList, &box, 1);
- REGION_INIT(pScreen, &pWin->winSize, &box, 1);
- REGION_INIT(pScreen, &pWin->borderSize, &box, 1);
- REGION_INIT(pScreen, &pWin->borderClip, &box, 1);
- pWin->drawable.class = InputOutput;
- pWin->optional->visual = pScreen->rootVisual;
- pWin->backgroundState = BackgroundPixel;
- pWin->background.pixel = pScreen->whitePixel;
- pWin->borderIsPixel = TRUE;
- pWin->border.pixel = pScreen->blackPixel;
- pWin->borderWidth = 0;
- if (!AddResource(pWin->drawable.id, RT_WINDOW, (pointer)pWin))
- return FALSE;
- if (disableBackingStore)
- {
- pScreen -> backingStoreSupport = NotUseful;
- }
- if (enableBackingStore)
- {
- pScreen -> backingStoreSupport = Always;
- }
- pScreen->saveUnderSupport = False;
- #ifdef DO_SAVE_UNDERS
- if ((pScreen->backingStoreSupport != NotUseful) &&
- (pScreen->saveUnderSupport == NotUseful))
- {
- /*
- * If the screen has backing-store but no save-unders, let the
- * clients know we can support save-unders using backing-store.
- */
- pScreen->saveUnderSupport = USE_DIX_SAVE_UNDERS;
- }
- #endif /* DO_SAVE_UNDERS */
-
- if (disableSaveUnders)
- pScreen->saveUnderSupport = NotUseful;
- return TRUE;
- }
- void
- InitRootWindow(pWin)
- WindowPtr pWin;
- {
- ScreenPtr pScreen;
- #ifdef TEST
- fprintf(stderr, "InitRootWindow: Called for window at [%p][%ld] with parent [%p].\n",
- (void *) pWin, nxagentWindowPriv(pWin)->window, (void *) pWin -> parent);
- #endif
- if (nxagentOption(Rootless))
- {
- #ifdef TEST
- fprintf(stderr, "InitRootWindow: Assigned agent root to window at [%p][%ld] with parent [%p].\n",
- (void *) pWin, nxagentWindowPriv(pWin)->window, (void *) pWin -> parent);
- #endif
- nxagentRootlessWindow = pWin;
- }
- pScreen = pWin->drawable.pScreen;
- /*
- * A root window is created for each screen by main
- * and the pointer is saved in WindowTable as in the
- * following snippet:
- *
- * for (i = 0; i < screenInfo.numScreens; i++)
- * InitRootWindow(WindowTable[i]);
- *
- * Our root window on the real display was already
- * created at the time the screen was opened, so it
- * is unclear how this window (or the other window,
- * if you prefer) fits in the big picture.
- */
- #ifdef TEST
- fprintf(stderr, "InitRootWindow: Going to create window as root at [%p][%ld] with parent [%p].\n",
- (void *) pWin, nxagentWindowPriv(pWin)->window, (void *) pWin -> parent);
- #endif
- if (!(*pScreen->CreateWindow)(pWin))
- return; /* XXX */
- #ifdef TEST
- fprintf(stderr, "InitRootWindow: Created window as root at [%p][%ld] with parent [%p].\n",
- (void *) pWin, nxagentWindowPriv(pWin)->window, (void *) pWin -> parent);
- #endif
- (*pScreen->PositionWindow)(pWin, 0, 0);
- pWin->cursorIsNone = FALSE;
- pWin->optional->cursor = rootCursor;
- rootCursor->refcnt++;
- pWin->backingStore = defaultBackingStore;
- pWin->forcedBS = (defaultBackingStore != NotUseful);
- #ifdef NXAGENT_SPLASH
- /* We SHOULD check for an error value here XXX */
- pWin -> background.pixel = pScreen -> blackPixel;
- (*pScreen->ChangeWindowAttributes)(pWin,
- CWBackPixel|CWBorderPixel|CWCursor|CWBackingStore);
- #else
- (*pScreen->ChangeWindowAttributes)(pWin,
- CWBackPixmap|CWBorderPixel|CWCursor|CWBackingStore);
- #endif
- MakeRootTile(pWin);
- /*
- * Map both the root and the default agent window.
- */
- #ifdef TEST
- fprintf(stderr, "InitRootWindow: Mapping default windows.\n");
- #endif
- nxagentInitAtoms(pWin);
- nxagentInitClipboard(pWin);
- nxagentMapDefaultWindows();
- nxagentRedirectDefaultWindows();
- #ifdef NXAGENT_ARTSD
- {
- char artsd_port[10];
- int nPort;
- extern void nxagentPropagateArtsdProperties(ScreenPtr pScreen, char *port);
- nPort = atoi(display) + 7000;
- sprintf(artsd_port,"%d", nPort);
- nxagentPropagateArtsdProperties(pScreen, artsd_port);
- }
- #endif
- }
- /* Set the region to the intersection of the rectangle and the
- * window's winSize. The window is typically the parent of the
- * window from which the region came.
- */
- void
- ClippedRegionFromBox(pWin, Rgn, x, y, w, h)
- register WindowPtr pWin;
- RegionPtr Rgn;
- register int x, y;
- int w, h;
- {
- REGION_PTR(pScreen, pWin)
- BoxRec box;
- box = *(REGION_EXTENTS(pScreen, &pWin->winSize));
- /* we do these calculations to avoid overflows */
- if (x > box.x1)
- box.x1 = x;
- if (y > box.y1)
- box.y1 = y;
- x += w;
- if (x < box.x2)
- box.x2 = x;
- y += h;
- if (y < box.y2)
- box.y2 = y;
- if (box.x1 > box.x2)
- box.x2 = box.x1;
- if (box.y1 > box.y2)
- box.y2 = box.y1;
- REGION_RESET(pScreen, Rgn, &box);
- REGION_INTERSECT(pScreen, Rgn, Rgn, &pWin->winSize);
- }
- WindowPtr
- RealChildHead(pWin)
- register WindowPtr pWin;
- {
- if (!pWin->parent &&
- (screenIsSaved == SCREEN_SAVER_ON) &&
- (HasSaverWindow (pWin->drawable.pScreen->myNum)))
- return (pWin->firstChild);
- else
- return (NullWindow);
- }
- /*****
- * CreateWindow
- * Makes a window in response to client request
- *****/
- WindowPtr
- CreateWindow(wid, pParent, x, y, w, h, bw, class, vmask, vlist,
- depth, client, visual, error)
- Window wid;
- register WindowPtr pParent;
- int x,y;
- unsigned int w, h, bw;
- unsigned int class;
- register Mask vmask;
- XID *vlist;
- int depth;
- ClientPtr client;
- VisualID visual;
- int *error;
- {
- register WindowPtr pWin;
- WindowPtr pHead;
- register ScreenPtr pScreen;
- xEvent event;
- int idepth, ivisual;
- Bool fOK;
- DepthPtr pDepth;
- PixmapFormatRec *format;
- register WindowOptPtr ancwopt;
- if (class == CopyFromParent)
- class = pParent->drawable.class;
- if ((class != InputOutput) && (class != InputOnly))
- {
- *error = BadValue;
- client->errorValue = class;
- return NullWindow;
- }
- if ((class != InputOnly) && (pParent->drawable.class == InputOnly))
- {
- *error = BadMatch;
- return NullWindow;
- }
- if ((class == InputOnly) && ((bw != 0) || (depth != 0)))
- {
- *error = BadMatch;
- return NullWindow;
- }
- pScreen = pParent->drawable.pScreen;
- if ((class == InputOutput) && (depth == 0))
- depth = pParent->drawable.depth;
- ancwopt = pParent->optional;
- if (!ancwopt)
- ancwopt = FindWindowWithOptional(pParent)->optional;
- if (visual == CopyFromParent) {
- #ifdef XAPPGROUP
- VisualID ag_visual;
- if (client->appgroup && !pParent->parent &&
- (ag_visual = XagRootVisual (client)))
- visual = ag_visual;
- else
- #endif
- visual = ancwopt->visual;
- }
- /* Find out if the depth and visual are acceptable for this Screen */
- if ((visual != ancwopt->visual) || (depth != pParent->drawable.depth))
- {
- fOK = FALSE;
- for(idepth = 0; idepth < pScreen->numDepths; idepth++)
- {
- pDepth = (DepthPtr) &pScreen->allowedDepths[idepth];
- if ((depth == pDepth->depth) || (depth == 0))
- {
- for (ivisual = 0; ivisual < pDepth->numVids; ivisual++)
- {
- if (visual == pDepth->vids[ivisual])
- {
- fOK = TRUE;
- break;
- }
- }
- }
- }
- if (fOK == FALSE)
- {
- *error = BadMatch;
- return NullWindow;
- }
- }
- if (((vmask & (CWBorderPixmap | CWBorderPixel)) == 0) &&
- (class != InputOnly) &&
- (depth != pParent->drawable.depth))
- {
- *error = BadMatch;
- return NullWindow;
- }
- if (((vmask & CWColormap) == 0) &&
- (class != InputOnly) &&
- ((visual != ancwopt->visual) || (ancwopt->colormap == None)))
- {
- *error = BadMatch;
- return NullWindow;
- }
- pWin = AllocateWindow(pScreen);
- if (!pWin)
- {
- *error = BadAlloc;
- return NullWindow;
- }
- pWin->drawable = pParent->drawable;
- pWin->drawable.depth = depth;
- if (depth == pParent->drawable.depth)
- pWin->drawable.bitsPerPixel = pParent->drawable.bitsPerPixel;
- else
- {
- for (format = screenInfo.formats; format->depth != depth; format++)
- ;
- pWin->drawable.bitsPerPixel = format->bitsPerPixel;
- }
- if (class == InputOnly)
- pWin->drawable.type = (short) UNDRAWABLE_WINDOW;
- pWin->drawable.serialNumber = NEXT_SERIAL_NUMBER;
- pWin->drawable.id = wid;
- pWin->drawable.class = class;
- pWin->parent = pParent;
- SetWindowToDefaults(pWin);
- if (visual != ancwopt->visual)
- {
- if (!MakeWindowOptional (pWin))
- {
- xfree (pWin);
- *error = BadAlloc;
- return NullWindow;
- }
- pWin->optional->visual = visual;
- pWin->optional->colormap = None;
- }
- pWin->borderWidth = bw;
- #ifdef XCSECURITY
- /* can't let untrusted clients have background None windows;
- * they make it too easy to steal window contents
- */
- if (client->trustLevel != XSecurityClientTrusted)
- {
- pWin->backgroundState = BackgroundPixel;
- pWin->background.pixel = 0;
- }
- else
- #endif
- pWin->backgroundState = None;
- pWin->borderIsPixel = pParent->borderIsPixel;
- pWin->border = pParent->border;
- if (pWin->borderIsPixel == FALSE)
- pWin->border.pixmap->refcnt++;
-
- pWin->origin.x = x + (int)bw;
- pWin->origin.y = y + (int)bw;
- pWin->drawable.width = w;
- pWin->drawable.height = h;
- pWin->drawable.x = pParent->drawable.x + x + (int)bw;
- pWin->drawable.y = pParent->drawable.y + y + (int)bw;
- /* set up clip list correctly for unobscured WindowPtr */
- REGION_INIT(pScreen, &pWin->clipList, NullBox, 1);
- REGION_INIT(pScreen, &pWin->borderClip, NullBox, 1);
- REGION_INIT(pScreen, &pWin->winSize, NullBox, 1);
- REGION_INIT(pScreen, &pWin->borderSize, NullBox, 1);
- pHead = RealChildHead(pParent);
- if (pHead)
- {
- pWin->nextSib = pHead->nextSib;
- if (pHead->nextSib)
- pHead->nextSib->prevSib = pWin;
- else
- pParent->lastChild = pWin;
- pHead->nextSib = pWin;
- pWin->prevSib = pHead;
- }
- else
- {
- pWin->nextSib = pParent->firstChild;
- if (pParent->firstChild)
- pParent->firstChild->prevSib = pWin;
- else
- pParent->lastChild = pWin;
- pParent->firstChild = pWin;
- }
- SetWinSize (pWin);
- SetBorderSize (pWin);
- /* We SHOULD check for an error value here XXX */
- if (!(*pScreen->CreateWindow)(pWin))
- {
- *error = BadAlloc;
- DeleteWindow(pWin, None);
- return NullWindow;
- }
- /* We SHOULD check for an error value here XXX */
- (*pScreen->PositionWindow)(pWin, pWin->drawable.x, pWin->drawable.y);
- if (!(vmask & CWEventMask))
- RecalculateDeliverableEvents(pWin);
- if (vmask)
- *error = ChangeWindowAttributes(pWin, vmask, vlist, wClient (pWin));
- else
- *error = Success;
- if (*error != Success)
- {
- DeleteWindow(pWin, None);
- return NullWindow;
- }
- if (!(vmask & CWBackingStore) && (defaultBackingStore != NotUseful))
- {
- XID value = defaultBackingStore;
- (void)ChangeWindowAttributes(pWin, CWBackingStore, &value, wClient (pWin));
- pWin->forcedBS = TRUE;
- }
- if (SubSend(pParent))
- {
- event.u.u.type = CreateNotify;
- event.u.createNotify.window = wid;
- event.u.createNotify.parent = pParent->drawable.id;
- event.u.createNotify.x = x;
- event.u.createNotify.y = y;
- event.u.createNotify.width = w;
- event.u.createNotify.height = h;
- event.u.createNotify.borderWidth = bw;
- event.u.createNotify.override = pWin->overrideRedirect;
- DeliverEvents(pParent, &event, 1, NullWindow);
- }
- return pWin;
- }
- static void
- #if NeedFunctionPrototypes
- FreeWindowResources(register WindowPtr pWin)
- #else
- FreeWindowResources(pWin)
- register WindowPtr pWin;
- #endif
- {
- register ScreenPtr pScreen = pWin->drawable.pScreen;
- DeleteWindowFromAnySaveSet(pWin);
- DeleteWindowFromAnySelections(pWin);
- DeleteWindowFromAnyEvents(pWin, TRUE);
- REGION_UNINIT(pScreen, &pWin->clipList);
- REGION_UNINIT(pScreen, &pWin->winSize);
- REGION_UNINIT(pScreen, &pWin->borderClip);
- REGION_UNINIT(pScreen, &pWin->borderSize);
- #ifdef SHAPE
- if (wBoundingShape (pWin))
- REGION_DESTROY(pScreen, wBoundingShape (pWin));
- if (wClipShape (pWin))
- REGION_DESTROY(pScreen, wClipShape (pWin));
- #endif
- if (pWin->borderIsPixel == FALSE)
- (*pScreen->DestroyPixmap)(pWin->border.pixmap);
- if (pWin->backgroundState == BackgroundPixmap)
- (*pScreen->DestroyPixmap)(pWin->background.pixmap);
- DeleteAllWindowProperties(pWin);
- /* We SHOULD check for an error value here XXX */
- (*pScreen->DestroyWindow)(pWin);
- DisposeWindowOptional (pWin);
- }
- static void
- #if NeedFunctionPrototypes
- CrushTree(WindowPtr pWin)
- #else
- CrushTree(pWin)
- WindowPtr pWin;
- #endif
- {
- register WindowPtr pChild, pSib, pParent;
- UnrealizeWindowProcPtr UnrealizeWindow;
- xEvent event;
- if (!(pChild = pWin->firstChild))
- return;
- UnrealizeWindow = pWin->drawable.pScreen->UnrealizeWindow;
- while (1)
- {
- if (pChild->firstChild)
- {
- pChild = pChild->firstChild;
- continue;
- }
- while (1)
- {
- pParent = pChild->parent;
- if (SubStrSend(pChild, pParent))
- {
- event.u.u.type = DestroyNotify;
- event.u.destroyNotify.window = pChild->drawable.id;
- DeliverEvents(pChild, &event, 1, NullWindow);
- }
- FreeResource(pChild->drawable.id, RT_WINDOW);
- pSib = pChild->nextSib;
- #ifdef DO_SAVE_UNDERS
- if (pChild->saveUnder && pChild->viewable)
- deltaSaveUndersViewable--;
- #endif
- pChild->viewable = FALSE;
- if (pChild->realized)
- {
- pChild->realized = FALSE;
- (*UnrealizeWindow)(pChild);
- }
- FreeWindowResources(pChild);
- xfree(pChild);
- if ( (pChild = pSib) )
- break;
- pChild = pParent;
- pChild->firstChild = NullWindow;
- pChild->lastChild = NullWindow;
- if (pChild == pWin)
- return;
- }
- }
- }
-
- /*****
- * DeleteWindow
- * Deletes child of window then window itself
- * If wid is None, don't send any events
- *****/
- /*ARGSUSED*/
- int
- DeleteWindow(value, wid)
- pointer value;
- XID wid;
- {
- register WindowPtr pParent;
- register WindowPtr pWin = (WindowPtr)value;
- xEvent event;
- UnmapWindow(pWin, FALSE);
- CrushTree(pWin);
- pParent = pWin->parent;
- if (wid && pParent && SubStrSend(pWin, pParent))
- {
- event.u.u.type = DestroyNotify;
- event.u.destroyNotify.window = pWin->drawable.id;
- DeliverEvents(pWin, &event, 1, NullWindow);
- }
- FreeWindowResources(pWin);
- if (pParent)
- {
- if (pParent->firstChild == pWin)
- pParent->firstChild = pWin->nextSib;
- if (pParent->lastChild == pWin)
- pParent->lastChild = pWin->prevSib;
- if (pWin->nextSib)
- pWin->nextSib->prevSib = pWin->prevSib;
- if (pWin->prevSib)
- pWin->prevSib->nextSib = pWin->nextSib;
- }
- xfree(pWin);
- if (pWin -> optional &&
- pWin -> optional -> colormap &&
- pWin -> parent)
- {
- nxagentSetInstalledColormapWindows(pWin -> drawable.pScreen);
- }
- return Success;
- }
- /*ARGSUSED*/
- void
- DestroySubwindows(pWin, client)
- register WindowPtr pWin;
- ClientPtr client;
- {
- /* XXX
- * The protocol is quite clear that each window should be
- * destroyed in turn, however, unmapping all of the first
- * eliminates most of the calls to ValidateTree. So,
- * this implementation is incorrect in that all of the
- * UnmapNotifies occur before all of the DestroyNotifies.
- * If you care, simply delete the call to UnmapSubwindows.
- */
- UnmapSubwindows(pWin);
- while (pWin->lastChild)
- FreeResource(pWin->lastChild->drawable.id, RT_NONE);
- }
- #define DeviceEventMasks (KeyPressMask | KeyReleaseMask | ButtonPressMask | \
- ButtonReleaseMask | PointerMotionMask)
- /*****
- * ChangeWindowAttributes
- *
- * The value-mask specifies which attributes are to be changed; the
- * value-list contains one value for each one bit in the mask, from least
- * to most significant bit in the mask.
- *****/
-
- int
- ChangeWindowAttributes(pWin, vmask, vlist, client)
- register WindowPtr pWin;
- Mask vmask;
- XID *vlist;
- ClientPtr client;
- {
- register Mask index2;
- register XID *pVlist;
- PixmapPtr pPixmap;
- Pixmap pixID;
- CursorPtr pCursor, pOldCursor;
- Cursor cursorID;
- WindowPtr pChild;
- Colormap cmap;
- ColormapPtr pCmap;
- xEvent xE;
- int result;
- register ScreenPtr pScreen;
- Mask vmaskCopy = 0;
- register Mask tmask;
- unsigned int val;
- int error;
- Bool checkOptional = FALSE;
- Bool borderRelative = FALSE;
- WindowPtr pLayerWin;
- if ((pWin->drawable.class == InputOnly) && (vmask & (~INPUTONLY_LEGAL_MASK)))
- return BadMatch;
- error = Success;
- pScreen = pWin->drawable.pScreen;
- pVlist = vlist;
- tmask = vmask;
- while (tmask)
- {
- index2 = (Mask) lowbit (tmask);
- tmask &= ~index2;
- switch (index2)
- {
- case CWBackPixmap:
- pixID = (Pixmap )*pVlist;
- pVlist++;
- if (pWin->backgroundState == ParentRelative)
- borderRelative = TRUE;
- if (pixID == None)
- {
- #ifdef XCSECURITY
- /* can't let untrusted clients have background None windows */
- if (client->trustLevel == XSecurityClientTrusted)
- {
- #endif
- if (pWin->backgroundState == BackgroundPixmap)
- (*pScreen->DestroyPixmap)(pWin->background.pixmap);
- if (!pWin->parent)
- MakeRootTile(pWin);
- else
- pWin->backgroundState = None;
- #ifdef XCSECURITY
- }
- else
- { /* didn't change the background to None, so don't tell ddx */
- index2 = 0;
- }
- #endif
- }
- else if (pixID == ParentRelative)
- {
- if (pWin->parent &&
- pWin->drawable.depth != pWin->parent->drawable.depth)
- {
- error = BadMatch;
- goto PatchUp;
- }
- if (pWin->backgroundState == BackgroundPixmap)
- (*pScreen->DestroyPixmap)(pWin->background.pixmap);
- if (!pWin->parent)
- MakeRootTile(pWin);
- else
- pWin->backgroundState = ParentRelative;
- borderRelative = TRUE;
- /* Note that the parent's backgroundTile's refcnt is NOT
- * incremented. */
- }
- else
- {
- pPixmap = (PixmapPtr)SecurityLookupIDByType(client, pixID,
- RT_PIXMAP, SecurityReadAccess);
- if (pPixmap != (PixmapPtr) NULL)
- {
- if ((pPixmap->drawable.depth != pWin->drawable.depth) ||
- (pPixmap->drawable.pScreen != pScreen))
- {
- error = BadMatch;
- goto PatchUp;
- }
- if (pWin->backgroundState == BackgroundPixmap)
- (*pScreen->DestroyPixmap)(pWin->background.pixmap);
- pWin->backgroundState = BackgroundPixmap;
- pWin->background.pixmap = pPixmap;
- pPixmap->refcnt++;
- }
- else
- {
- error = BadPixmap;
- client->errorValue = pixID;
- goto PatchUp;
- }
- }
- break;
- case CWBackPixel:
- if (pWin->backgroundState == ParentRelative)
- borderRelative = TRUE;
- if (pWin->backgroundState == BackgroundPixmap)
- (*pScreen->DestroyPixmap)(pWin->background.pixmap);
- pWin->backgroundState = BackgroundPixel;
- pWin->background.pixel = (CARD32 ) *pVlist;
- /* background pixel overrides background pixmap,
- so don't let the ddx layer see both bits */
- vmaskCopy &= ~CWBackPixmap;
- pVlist++;
- break;
- case CWBorderPixmap:
- pixID = (Pixmap ) *pVlist;
- pVlist++;
- if (pixID == CopyFromParent)
- {
- if (!pWin->parent ||
- (pWin->drawable.depth != pWin->parent->drawable.depth))
- {
- error = BadMatch;
- goto PatchUp;
- }
- if (pWin->borderIsPixel == FALSE)
- (*pScreen->DestroyPixmap)(pWin->border.pixmap);
- pWin->border = pWin->parent->border;
- if ((pWin->borderIsPixel = pWin->parent->borderIsPixel) == TRUE)
- {
- index2 = CWBorderPixel;
- }
- else
- {
- pWin->parent->border.pixmap->refcnt++;
- }
- }
- else
- {
- pPixmap = (PixmapPtr)SecurityLookupIDByType(client, pixID,
- RT_PIXMAP, SecurityReadAccess);
- if (pPixmap)
- {
- if ((pPixmap->drawable.depth != pWin->drawable.depth) ||
- (pPixmap->drawable.pScreen != pScreen))
- {
- error = BadMatch;
- goto PatchUp;
- }
- if (pWin->borderIsPixel == FALSE)
- (*pScreen->DestroyPixmap)(pWin->border.pixmap);
- pWin->borderIsPixel = FALSE;
- pWin->border.pixmap = pPixmap;
- pPixmap->refcnt++;
- }
- else
- {
- error = BadPixmap;
- client->errorValue = pixID;
- goto PatchUp;
- }
- }
- break;
- case CWBorderPixel:
- if (pWin->borderIsPixel == FALSE)
- (*pScreen->DestroyPixmap)(pWin->border.pixmap);
- pWin->borderIsPixel = TRUE;
- pWin->border.pixel = (CARD32) *pVlist;
- /* border pixel overrides border pixmap,
- so don't let the ddx layer see both bits */
- vmaskCopy &= ~CWBorderPixmap;
- pVlist++;
- break;
- case CWBitGravity:
- val = (CARD8 )*pVlist;
- pVlist++;
- if (val > StaticGravity)
- {
- error = BadValue;
- client->errorValue = val;
- goto PatchUp;
- }
- pWin->bitGravity = val;
- break;
- case CWWinGravity:
- val = (CARD8 )*pVlist;
- pVlist++;
- if (val > StaticGravity)
- {
- error = BadValue;
- client->errorValue = val;
- goto PatchUp;
- }
- pWin->winGravity = val;
- break;
- case CWBackingStore:
- val = (CARD8 )*pVlist;
- pVlist++;
- if ((val != NotUseful) && (val != WhenMapped) && (val != Always))
- {
- error = BadValue;
- client->errorValue = val;
- goto PatchUp;
- }
- pWin->backingStore = val;
- #ifdef TEST
- fprintf(stderr, "ChangeWindowAttributes: Changed backing store value to %d for window at %p.\n",
- val, (void*)pWin);
- #endif
- pWin->forcedBS = FALSE;
- break;
- case CWBackingPlanes:
- if (pWin->optional || ((CARD32)*pVlist != (CARD32)~0L)) {
- if (!pWin->optional && !MakeWindowOptional (pWin))
- {
- error = BadAlloc;
- goto PatchUp;
- }
- pWin->optional->backingBitPlanes = (CARD32) *pVlist;
- if ((CARD32)*pVlist == (CARD32)~0L)
- checkOptional = TRUE;
- }
- pVlist++;
- break;
- case CWBackingPixel:
- if (pWin->optional || (CARD32) *pVlist) {
- if (!pWin->optional && !MakeWindowOptional (pWin))
- {
- error = BadAlloc;
- goto PatchUp;
- }
- pWin->optional->backingPixel = (CARD32) *pVlist;
- if (!*pVlist)
- checkOptional = TRUE;
- }
- pVlist++;
- break;
- case CWSaveUnder:
- val = (BOOL) *pVlist;
- pVlist++;
- if ((val != xTrue) && (val != xFalse))
- {
- error = BadValue;
- client->errorValue = val;
- goto PatchUp;
- }
- #ifdef DO_SAVE_UNDERS
- if (pWin->parent && (pWin->saveUnder != val) && (pWin->viewable) &&
- DO_SAVE_UNDERS(pWin))
- {
- /*
- * Re-check all siblings and inferiors for obscurity or
- * exposition (hee hee).
- */
- if (pWin->saveUnder)
- deltaSaveUndersViewable--;
- else
- deltaSaveUndersViewable++;
- pWin->saveUnder = val;
- if (pWin->firstChild)
- {
- pLayerWin = (*pScreen->GetLayerWindow)(pWin);
- if ((*pScreen->ChangeSaveUnder)(pLayerWin->parent, pWin->nextSib))
- (*pScreen->PostChangeSaveUnder)(pLayerWin->parent,
- pWin->nextSib);
- }
- else
- {
- if ((*pScreen->ChangeSaveUnder)(pWin, pWin->nextSib))
- (*pScreen->PostChangeSaveUnder)(pWin,
- pWin->nextSib);
- }
- }
- else
- {
- /* If we're changing the saveUnder attribute of the root
- * window, all we do is set pWin->saveUnder so that
- * GetWindowAttributes returns the right value. We don't
- * do the "normal" save-under processing (as above).
- * Hope that doesn't cause any problems.
- */
- pWin->saveUnder = val;
- }
- #else
- pWin->saveUnder = val;
- #endif /* DO_SAVE_UNDERS */
- break;
- case CWEventMask:
- /*
- * TODO: Some applications like java bean shell
- * don' t work if they cannot monitor the root
- * window for Structure Redirect events. However
- * this doesn't seem to be the best solution, since
- * also an X server with a window manager running,
- * doesn't allow to monitor for those events, but
- * the java bean shell works flawlessy on this
- * server.
- *
- * if (nxagentCheckIllegalRootMonitoring(pWin, (Mask)*pVlist))
- * {
- * return BadAccess;
- * }
- */
- result = EventSelectForWindow(pWin, client, (Mask )*pVlist);
- if (result)
- {
- error = result;
- goto PatchUp;
- }
- pVlist++;
- break;
- case CWDontPropagate:
- result = EventSuppressForWindow(pWin, client, (Mask )*pVlist,
- &checkOptional);
- if (result)
- {
- error = result;
- goto PatchUp;
- }
- pVlist++;
- break;
- case CWOverrideRedirect:
- val = (BOOL ) *pVlist;
- pVlist++;
- if ((val != xTrue) && (val != xFalse))
- {
- error = BadValue;
- client->errorValue = val;
- goto PatchUp;
- }
- pWin->overrideRedirect = val;
- break;
- case CWColormap:
- cmap = (Colormap) *pVlist;
- pVlist++;
- if (cmap == CopyFromParent)
- {
- #ifdef XAPPGROUP
- Colormap ag_colormap;
- ClientPtr win_owner;
- /*
- * win_owner == client for CreateWindow, other clients
- * can ChangeWindowAttributes
- */
- win_owner = clients[CLIENT_ID(pWin->drawable.id)];
- if ( win_owner && win_owner->appgroup &&
- !pWin->parent->parent &&
- (ag_colormap = XagDefaultColormap (win_owner)))
- cmap = ag_colormap;
- else
- #endif
- if (pWin->parent &&
- (!pWin->optional ||
- pWin->optional->visual == wVisual (pWin->parent)))
- {
- cmap = wColormap (pWin->parent);
- }
- else
- cmap = None;
- }
- if (cmap == None)
- {
- error = BadMatch;
- goto PatchUp;
- }
- pCmap = (ColormapPtr)SecurityLookupIDByType(client, cmap,
- RT_COLORMAP, SecurityReadAccess);
- if (!pCmap)
- {
- error = BadColor;
- client->errorValue = cmap;
- goto PatchUp;
- }
- if (pCmap->pVisual->vid != wVisual (pWin) ||
- pCmap->pScreen != pScreen)
- {
- error = BadMatch;
- goto PatchUp;
- }
- if (cmap != wColormap (pWin))
- {
- if (!pWin->optional)
- {
- if (!MakeWindowOptional (pWin))
- {
- error = BadAlloc;
- goto PatchUp;
- }
- }
- else if (pWin->parent && cmap == wColormap (pWin->parent))
- checkOptional = TRUE;
- /*
- * propagate the original colormap to any children
- * inheriting it
- */
- for (pChild = pWin->firstChild; pChild; pChild=pChild->nextSib)
- {
- if (!pChild->optional && !MakeWindowOptional (pChild))
- {
- error = BadAlloc;
- goto PatchUp;
- }
- }
- pWin->optional->colormap = cmap;
- /*
- * check on any children now matching the new colormap
- */
- for (pChild = pWin->firstChild; pChild; pChild=pChild->nextSib)
- {
- if (pChild->optional->colormap == cmap)
- CheckWindowOptionalNeed (pChild);
- }
-
- xE.u.u.type = ColormapNotify;
- xE.u.colormap.window = pWin->drawable.id;
- xE.u.colormap.colormap = cmap;
- xE.u.colormap.new = xTrue;
- xE.u.colormap.state = IsMapInstalled(cmap, pWin);
- DeliverEvents(pWin, &xE, 1, NullWindow);
- }
- break;
- case CWCursor:
- cursorID = (Cursor ) *pVlist;
- pVlist++;
- /*
- * install the new
- */
- if ( cursorID == None)
- {
- if (pWin == WindowTable[pWin->drawable.pScreen->myNum])
- pCursor = rootCursor;
- else
- pCursor = (CursorPtr) None;
- }
- else
- {
- pCursor = (CursorPtr)SecurityLookupIDByType(client, cursorID,
- RT_CURSOR, SecurityReadAccess);
- if (!pCursor)
- {
- error = BadCursor;
- client->errorValue = cursorID;
- goto PatchUp;
- }
- }
- if (pCursor != wCursor (pWin))
- {
- /*
- * patch up child windows so they don't lose cursors.
- */
- for (pChild = pWin->firstChild; pChild; pChild=pChild->nextSib)
- {
- if (!pChild->optional && !pChild->cursorIsNone &&
- !MakeWindowOptional (pChild))
- {
- error = BadAlloc;
- goto PatchUp;
- }
- }
- pOldCursor = 0;
- if (pCursor == (CursorPtr) None)
- {
- pWin->cursorIsNone = TRUE;
- if (pWin->optional)
- {
- pOldCursor = pWin->optional->cursor;
- pWin->optional->cursor = (CursorPtr) None;
- checkOptional = TRUE;
- }
- } else {
- if (!pWin->optional)
- {
- if (!MakeWindowOptional (pWin))
- {
- error = BadAlloc;
- goto PatchUp;
- }
- }
- else if (pWin->parent && pCursor == wCursor (pWin->parent))
- checkOptional = TRUE;
- pOldCursor = pWin->optional->cursor;
- pWin->optional->cursor = pCursor;
- pCursor->refcnt++;
- pWin->cursorIsNone = FALSE;
- /*
- * check on any children now matching the new cursor
- */
- for (pChild=pWin->firstChild; pChild; pChild=pChild->nextSib)
- {
- if (pChild->optional &&
- (pChild->optional->cursor == pCursor))
- CheckWindowOptionalNeed (pChild);
- }
- }
- if (pWin->realized)
- WindowHasNewCursor( pWin);
- /* Can't free cursor until here - old cursor
- * is needed in WindowHasNewCursor
- */
- if (pOldCursor)
- FreeCursor (pOldCursor, (Cursor)0);
- }
- break;
- default:
- error = BadValue;
- client->errorValue = vmask;
- goto PatchUp;
- }
- vmaskCopy |= index2;
- }
- PatchUp:
- if (checkOptional)
- CheckWindowOptionalNeed (pWin);
- /* We SHOULD check for an error value here XXX */
- (*pScreen->ChangeWindowAttributes)(pWin, vmaskCopy);
- /*
- If the border contents have changed, redraw the border.
- Note that this has to be done AFTER pScreen->ChangeWindowAttributes
- for the tile to be rotated, and the correct function selected.
- */
- if (((vmaskCopy & (CWBorderPixel | CWBorderPixmap)) || borderRelative)
- && pWin->viewable && HasBorder (pWin))
- {
- RegionRec exposed;
- REGION_INIT(pScreen, &exposed, NullBox, 0);
- REGION_SUBTRACT(pScreen, &exposed, &pWin->borderClip, &pWin->winSize);
- (*pWin->drawable.pScreen->PaintWindowBorder)(pWin, &exposed, PW_BORDER);
- REGION_UNINIT(pScreen, &exposed);
- }
- return error;
- }
- /*****
- * GetWindowAttributes
- * Notice that this is different than ChangeWindowAttributes
- *****/
- void
- GetWindowAttributes(pWin, client, wa)
- register WindowPtr pWin;
- ClientPtr client;
- xGetWindowAttributesReply *wa;
- {
- wa->type = X_Reply;
- wa->bitGravity = pWin->bitGravity;
- wa->winGravity = pWin->winGravity;
- if (pWin->forcedBS && pWin->backingStore != Always)
- wa->backingStore = NotUseful;
- else
- wa->backingStore = pWin->backingStore;
- wa->length = (sizeof(xGetWindowAttributesReply) -
- sizeof(xGenericReply)) >> 2;
- wa->sequenceNumber = client->sequence;
- wa->backingBitPlanes = wBackingBitPlanes (pWin);
- wa->backingPixel = wBackingPixel (pWin);
- wa->saveUnder = (BOOL)pWin->saveUnder;
- wa->override = pWin->overrideRedirect;
- if (!pWin->mapped)
- wa->mapState = IsUnmapped;
- else if (pWin->realized)
- wa->mapState = IsViewable;
- else
- wa->mapState = IsUnviewable;
- wa->colormap = wColormap (pWin);
- wa->mapInstalled = (wa->colormap == None) ? xFalse
- : IsMapInstalled(wa->colormap, pWin);
- wa->yourEventMask = EventMaskForClient(pWin, client);
- wa->allEventMasks = pWin->eventMask | wOtherEventMasks (pWin);
- wa->doNotPropagateMask = wDontPropagateMask (pWin);
- wa->class = pWin->drawable.class;
- wa->visualID = wVisual (pWin);
- }
- WindowPtr
- MoveWindowInStack(pWin, pNextSib)
- register WindowPtr pWin, pNextSib;
- {
- register WindowPtr pParent = pWin->parent;
- WindowPtr pFirstChange = pWin; /* highest window where list changes */
- if (pWin->nextSib != pNextSib)
- {
- WindowPtr pOldNextSib = pWin->nextSib;
- if (!pNextSib) /* move to bottom */
- {
- if (pParent->firstChild == pWin)
- pParent->firstChild = pWin->nextSib;
- /* if (pWin->nextSib) */ /* is always True: pNextSib == NULL
- * and pWin->nextSib != pNextSib
- * therefore pWin->nextSib != NULL */
- pFirstChange = pWin->nextSib;
- pWin->nextSib->prevSib = pWin->prevSib;
- if (pWin->prevSib)
- pWin->prevSib->nextSib = pWin->nextSib;
- pParent->lastChild->nextSib = pWin;
- pWin->prevSib = pParent->lastChild;
- pWin->nextSib = NullWindow;
- pParent->lastChild = pWin;
- }
- else if (pParent->firstChild == pNextSib) /* move to top */
- {
- pFirstChange = pWin;
- if (pParent->lastChild == pWin)
- pParent->lastChild = pWin->prevSib;
- if (pWin->nextSib)
- pWin->nextSib->prevSib = pWin->prevSib;
- if (pWin->prevSib)
- pWin->prevSib->nextSib = pWin->nextSib;
- pWin->nextSib = pParent->firstChild;
- pWin->prevSib = (WindowPtr ) NULL;
- pNextSib->prevSib = pWin;
- pParent->firstChild = pWin;
- }
- else /* move in middle of list */
- {
- WindowPtr pOldNext = pWin->nextSib;
- pFirstChange = NullWindow;
- if (pParent->firstChild == pWin)
- pFirstChange = pParent->firstChild = pWin->nextSib;
- if (pParent->lastChild == pWin) {
- pFirstChange = pWin;
- pParent->lastChild = pWin->prevSib;
- }
- if (pWin->nextSib)
- pWin->nextSib->prevSib = pWin->prevSib;
- if (pWin->prevSib)
- pWin->prevSib->nextSib = pWin->nextSib;
- pWin->nextSib = pNextSib;
- pWin->prevSib = pNextSib->prevSib;
- if (pNextSib->prevSib)
- pNextSib->prevSib->nextSib = pWin;
- pNextSib->prevSib = pWin;
- if (!pFirstChange) { /* do we know it yet? */
- pFirstChange = pParent->firstChild; /* no, search from top */
- while ((pFirstChange != pWin) && (pFirstChange != pOldNext))
- pFirstChange = pFirstChange->nextSib;
- }
- }
- if(pWin->drawable.pScreen->RestackWindow)
- (*pWin->drawable.pScreen->RestackWindow)(pWin, pOldNextSib);
- }
- return( pFirstChange );
- }
- RegionPtr
- CreateUnclippedWinSize (pWin)
- register WindowPtr pWin;
- {
- RegionPtr pRgn;
- BoxRec box;
- box.x1 = pWin->drawable.x;
- box.y1 = pWin->drawable.y;
- box.x2 = pWin->drawable.x + (int) pWin->drawable.width;
- box.y2 = pWin->drawable.y + (int) pWin->drawable.height;
- pRgn = REGION_CREATE(pWin->drawable.pScreen, &box, 1);
- #ifdef SHAPE
- if (wBoundingShape (pWin) || wClipShape (pWin)) {
- REGION_PTR(pScreen, pWin)
- REGION_TRANSLATE(pScreen, pRgn, - pWin->drawable.x,
- - pWin->drawable.y);
- if (wBoundingShape (pWin))
- REGION_INTERSECT(pScreen, pRgn, pRgn, wBoundingShape (pWin));
- if (wClipShape (pWin))
- REGION_INTERSECT(pScreen, pRgn, pRgn, wClipShape (pWin));
- REGION_TRANSLATE(pScreen, pRgn, pWin->drawable.x, pWin->drawable.y);
- }
- #endif
- return pRgn;
- }
- void
- SetWinSize (pWin)
- register WindowPtr pWin;
- {
- ClippedRegionFromBox(pWin->parent, &pWin->winSize,
- pWin->drawable.x, pWin->drawable.y,
- (int)pWin->drawable.width,
- (int)pWin->drawable.height);
- #ifdef SHAPE
- if (wBoundingShape (pWin) || wClipShape (pWin)) {
- REGION_PTR(pScreen, pWin)
- REGION_TRANSLATE(pScreen, &pWin->winSize, - pWin->drawable.x,
- - pWin->drawable.y);
- if (wBoundingShape (pWin))
- REGION_INTERSECT(pScreen, &pWin->winSize, &pWin->winSize,
- wBoundingShape (pWin));
- if (wClipShape (pWin))
- REGION_INTERSECT(pScreen, &pWin->winSize, &pWin->winSize,
- wClipShape (pWin));
- REGION_TRANSLATE(pScreen, &pWin->winSize, pWin->drawable.x,
- pWin->drawable.y);
- }
- #endif
- }
- void
- SetBorderSize (pWin)
- register WindowPtr pWin;
- {
- int bw;
- if (HasBorder (pWin)) {
- bw = wBorderWidth (pWin);
- ClippedRegionFromBox(pWin->parent, &pWin->borderSize,
- pWin->drawable.x - bw, pWin->drawable.y - bw,
- (int)(pWin->drawable.width + (bw<<1)),
- (int)(pWin->drawable.height + (bw<<1)));
- #ifdef SHAPE
- if (wBoundingShape (pWin)) {
- REGION_PTR(pScreen, pWin)
- REGION_TRANSLATE(pScreen, &pWin->borderSize, - pWin->drawable.x,
- - pWin->drawable.y);
- REGION_INTERSECT(pScreen, &pWin->borderSize, &pWin->borderSize,
- wBoundingShape (pWin));
- REGION_TRANSLATE(pScreen, &pWin->borderSize, pWin->drawable.x,
- pWin->drawable.y);
- REGION_UNION(pScreen, &pWin->borderSize, &pWin->borderSize,
- &pWin->winSize);
- }
- #endif
- } else {
- REGION_COPY(pWin->drawable.pScreen, &pWin->borderSize,
- &pWin->winSize);
- }
- }
- void
- GravityTranslate (x, y, oldx, oldy, dw, dh, gravity, destx, desty)
- register int x, y; /* new window position */
- int oldx, oldy; /* old window position */
- int dw, dh;
- unsigned gravity;
- register int *destx, *desty; /* position relative to gravity */
- {
- switch (gravity) {
- case NorthGravity:
- *destx = x + dw / 2;
- *desty = y;
- break;
- case NorthEastGravity:
- *destx = x + dw;
- *desty = y;
- break;
- case WestGravity:
- *destx = x;
- *desty = y + dh / 2;
- break;
- case CenterGravity:
- *destx = x + dw / 2;
- *desty = y + dh / 2;
- break;
- case EastGravity:
- *dest…
Large files files are truncated, but you can click here to view the full file