Newer
Older
Copyright (c) 2006, Red Hat, Inc.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice (including the next
paragraph) 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 AUTHORS OR COPYRIGHT HOLDERS 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.
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.
*/
/* The panoramix components contained the following notice */
/*****************************************************************
Copyright (c) 1991, 1997 Digital Equipment Corporation, Maynard, Massachusetts.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software.
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
DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR ANY CLAIM, DAMAGES, INCLUDING,
BUT NOT LIMITED TO CONSEQUENTIAL OR INCIDENTAL 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 Digital Equipment Corporation
shall not be used in advertising or otherwise to promote the sale, use or other
dealings in this Software without prior written authorization from Digital
Equipment Corporation.
******************************************************************/
#ifdef HAVE_DIX_CONFIG_H
#include <dix-config.h>
#endif
#include "dix/dix_priv.h"
#include "dix/exevents_priv.h"
#include "os/auth.h"
#include "misc.h"
#include "os.h"
#include "regionstr.h"
#include "validate.h"
#include "windowstr.h"
#include "resource.h"
#include "colormapst.h"
#include "cursorstr.h"
#include "dixstruct.h"
#include "gcstruct.h"
#include "servermd.h"
#ifdef PANORAMIX
#include "panoramiX.h"
#include "panoramiXsrv.h"
#endif
#include "dixevents.h"
#include "globals.h"
#include "selection.h"
#include "privates.h"
#include <X11/Xatom.h> /* must come after server includes */
*
* CreateRootWindow, CreateWindow, ChangeWindowAttributes,
* GetWindowAttributes, DeleteWindow, DestroySubWindows,
* HandleSaveSet, ReparentWindow, MapWindow, MapSubWindows,
* UnmapWindow, UnmapSubWindows, ConfigureWindow, CirculateWindow,
Bool bgNoneRoot = FALSE;
static unsigned char _back_lsb[4] = { 0x88, 0x22, 0x44, 0x11 };
static unsigned char _back_msb[4] = { 0x11, 0x44, 0x22, 0x88 };
static Bool WindowParentHasDeviceCursor(WindowPtr pWin,
DeviceIntPtr pDev, CursorPtr pCurs);
static Bool
WindowSeekDeviceCursor(WindowPtr pWin,
DeviceIntPtr pDev,
DevCursNodePtr * pNode, DevCursNodePtr * pPrev);
int screenIsSaved = SCREEN_SAVER_OFF;
static Bool TileScreenSaver(ScreenPtr pScreen, int kind);
#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))
static const char *overlay_win_name = "<composite overlay>";
static const char *
get_window_name(WindowPtr pWin)
{
#define WINDOW_NAME_BUF_LEN 512
PropertyPtr prop;
static char buf[WINDOW_NAME_BUF_LEN];
int len;
#ifdef COMPOSITE
CompScreenPtr comp_screen = GetCompScreen(pWin->drawable.pScreen);
if (comp_screen && pWin == comp_screen->pOverlayWin)
return overlay_win_name;
for (prop = wUserProps(pWin); prop; prop = prop->next) {
if (prop->propertyName == XA_WM_NAME && prop->type == XA_STRING &&
len = min(prop->size, WINDOW_NAME_BUF_LEN - 1);
memcpy(buf, prop->data, len);
buf[len] = '\0';
return buf;
}
}
return NULL;
#undef WINDOW_NAME_BUF_LEN
}
static void
log_window_info(WindowPtr pWin, int depth)
const char *win_name, *visibility;
BoxPtr rects;
for (i = 0; i < (depth << 2); i++)
ErrorF(" ");
win_name = get_window_name(pWin);
ErrorF("win 0x%.8x (%s), [%d, %d] to [%d, %d]",
win_name ? win_name : "no name",
pWin->drawable.x, pWin->drawable.y,
pWin->drawable.x + pWin->drawable.width,
pWin->drawable.y + pWin->drawable.height);
if (pWin->overrideRedirect)
ErrorF(" (override redirect)");
if (pWin->redirectDraw)
ErrorF(" (%s compositing: pixmap %x)",
(pWin->redirectDraw == RedirectDrawAutomatic) ?
Jeremy Huddleston Sequoia
committed
(unsigned) pWin->drawable.pScreen->GetWindowPixmap(pWin)->drawable.id);
visibility = "unobscured";
break;
case VisibilityPartiallyObscured:
visibility = "partially obscured";
break;
visibility = "fully obscured";
break;
visibility = "unviewable";
break;
}
ErrorF(", %s", visibility);
Jeremy Huddleston Sequoia
committed
if (RegionNotEmpty(&pWin->clipList)) {
Jeremy Huddleston Sequoia
committed
rects = RegionRects(&pWin->clipList);
for (i = 0; i < RegionNumRects(&pWin->clipList); i++)
ErrorF(" [(%d, %d) to (%d, %d)]",
rects[i].x1, rects[i].y1, rects[i].x2, rects[i].y2);
ErrorF("; extents [(%d, %d) to (%d, %d)]",
pWin->clipList.extents.x1, pWin->clipList.extents.y1,
pWin->clipList.extents.x2, pWin->clipList.extents.y2);
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
static const char*
grab_grabtype_to_text(GrabPtr pGrab)
{
switch (pGrab->grabtype) {
case XI2:
return "xi2";
case CORE:
return "core";
default:
return "xi1";
}
}
static const char*
grab_type_to_text(GrabPtr pGrab)
{
switch (pGrab->type) {
case ButtonPress:
return "ButtonPress";
case KeyPress:
return "KeyPress";
case XI_Enter:
return "XI_Enter";
case XI_FocusIn:
return "XI_FocusIn";
default:
return "unknown?!";
}
}
static void
log_grab_info(void *value, XID id, void *cdata)
{
int i, j;
GrabPtr pGrab = (GrabPtr)value;
ErrorF(" grab 0x%lx (%s), type '%s' on window 0x%lx\n",
(unsigned long) pGrab->resource,
grab_grabtype_to_text(pGrab),
grab_type_to_text(pGrab),
(unsigned long) pGrab->window->drawable.id);
ErrorF(" detail %d (mask %lu), modifiersDetail %d (mask %lu)\n",
pGrab->detail.exact,
pGrab->detail.pMask ? (unsigned long) *(pGrab->detail.pMask) : 0,
pGrab->modifiersDetail.exact,
pGrab->modifiersDetail.pMask ?
(unsigned long) *(pGrab->modifiersDetail.pMask) :
(unsigned long) 0);
ErrorF(" device '%s' (%d), modifierDevice '%s' (%d)\n",
pGrab->device->name, pGrab->device->id,
pGrab->modifierDevice->name, pGrab->modifierDevice->id);
if (pGrab->grabtype == CORE) {
ErrorF(" core event mask 0x%lx\n",
(unsigned long) pGrab->eventMask);
}
else if (pGrab->grabtype == XI) {
ErrorF(" xi1 event mask 0x%lx\n",
(unsigned long) pGrab->eventMask);
}
else if (pGrab->grabtype == XI2) {
for (i = 0; i < xi2mask_num_masks(pGrab->xi2mask); i++) {
const unsigned char *mask;
int print;
print = 0;
for (j = 0; j < XI2MASKSIZE; j++) {
mask = xi2mask_get_one_mask(pGrab->xi2mask, i);
if (mask[j]) {
print = 1;
break;
}
}
if (!print)
continue;
ErrorF(" xi2 event mask 0x");
for (j = 0; j < xi2mask_mask_size(pGrab->xi2mask); j++)
ErrorF("%x ", mask[j]);
ErrorF("\n");
}
}
ErrorF(" owner-events %s, kb %d ptr %d, confine 0x%lx, cursor 0x%lx\n",
pGrab->ownerEvents ? "true" : "false",
pGrab->keyboardMode, pGrab->pointerMode,
pGrab->confineTo ? (unsigned long) pGrab->confineTo->drawable.id : 0,
pGrab->cursor ? (unsigned long) pGrab->cursor->id : 0);
}
void
PrintPassiveGrabs(void)
{
int i;
LocalClientCredRec *lcc;
pid_t clientpid;
const char *cmdname;
const char *cmdargs;
ErrorF("Printing all currently registered grabs\n");
for (i = 1; i < currentMaxClients; i++) {
if (!clients[i] || clients[i]->clientState != ClientStateRunning)
continue;
clientpid = GetClientPid(clients[i]);
cmdname = GetClientCmdName(clients[i]);
cmdargs = GetClientCmdArgs(clients[i]);
if ((clientpid > 0) && (cmdname != NULL)) {
ErrorF(" Printing all registered grabs of client pid %ld %s %s\n",
(long) clientpid, cmdname, cmdargs ? cmdargs : "");
} else {
if (GetLocalClientCreds(clients[i], &lcc) == -1) {
ErrorF(" GetLocalClientCreds() failed\n");
continue;
}
ErrorF(" Printing all registered grabs of client pid %ld uid %ld gid %ld\n",
(lcc->fieldsSet & LCC_PID_SET) ? (long) lcc->pid : 0,
(lcc->fieldsSet & LCC_UID_SET) ? (long) lcc->euid : 0,
(lcc->fieldsSet & LCC_GID_SET) ? (long) lcc->egid : 0);
FreeLocalClientCreds(lcc);
}
FindClientResourcesByType(clients[i], X11_RESTYPE_PASSIVEGRAB, log_grab_info, NULL);
}
ErrorF("End list of registered passive grabs\n");
}
int scrnum, depth;
ScreenPtr pScreen;
WindowPtr pWin;
for (scrnum = 0; scrnum < screenInfo.numScreens; scrnum++) {
pScreen = screenInfo.screens[scrnum];
ErrorF("[dix] Dumping windows for screen %d (pixmap %x):\n", scrnum,
(unsigned) pScreen->GetScreenPixmap(pScreen)->drawable.id);
pWin = pScreen->root;
depth = 1;
pWin = pWin->firstChild;
depth++;
continue;
}
pWin = pWin->parent;
depth--;
}
if (!pWin)
break;
pWin = pWin->nextSib;
TraverseTree(WindowPtr pWin, VisitWindowProcPtr func, void *data)
int result;
WindowPtr pChild;
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;
* Walk the window tree, for SCREEN, performing FUNC(pWin, data) on
* each window. If FUNC returns WT_WALKCHILDREN, traverse the children,
* if it returns WT_DONTWALKCHILDREN, don't. If it returns WT_STOPWALKING,
* exit WalkTree. Does depth-first traverse.
*****/
WalkTree(ScreenPtr pScreen, VisitWindowProcPtr func, void *data)
return (TraverseTree(pScreen->root, func, data));
}
/* hack to force no backing store */
Bool disableBackingStore = FALSE;
Bool enableBackingStore = FALSE;
SetWindowToDefaults(WindowPtr pWin)
{
pWin->prevSib = NullWindow;
pWin->firstChild = NullWindow;
pWin->lastChild = NullWindow;
pWin->valdata = NULL;
pWin->optional = NULL;
pWin->cursorIsNone = TRUE;
pWin->backingStore = NotUseful;
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->redirectDraw = RedirectDrawNone;
pWin->forcedBG = FALSE;
#ifdef COMPOSITE
pWin->damagedDescendants = FALSE;
#endif
{
ScreenPtr pScreen = pWin->drawable.pScreen;
GCPtr pGC;
unsigned char back[128];
int len = BitmapBytePad(sizeof(long));
unsigned char *from, *to;
int i, j;
pWin->background.pixmap = (*pScreen->CreatePixmap) (pScreen, 4, 4,
pScreen->rootDepth, 0);
pWin->backgroundState = BackgroundPixmap;
pGC = GetScratchGC(pScreen->rootDepth, pScreen);
if (!pWin->background.pixmap || !pGC)
FatalError("could not create root tile");
attributes[0].val = pScreen->whitePixel;
attributes[1].val = pScreen->blackPixel;
(void) ChangeGC(NullClient, pGC, GCForeground | GCBackground,
attributes);
ValidateGC((DrawablePtr) pWin->background.pixmap, pGC);
from = (screenInfo.bitmapBitOrder == LSBFirst) ? _back_lsb : _back_msb;
to = back;
for (i = 4; i > 0; i--, from++)
for (j = len; j > 0; j--)
*to++ = *from;
(*pGC->ops->PutImage) ((DrawablePtr) pWin->background.pixmap, pGC, 1,
0, 0, len, 4, 0, XYBitmap, (char *) back);
}
/*****
* CreateRootWindow
* Makes a window at initialization time for specified screen
*****/
pWin = dixAllocateScreenObjectWithPrivates(pScreen, WindowRec, PRIVATE_WINDOW);
pScreen->screensaver.pWindow = NULL;
pScreen->screensaver.wid = FakeClientID(0);
pScreen->screensaver.ExternalScreenSaver = NULL;
screenIsSaved = SCREEN_SAVER_OFF;
pScreen->root = 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 = malloc(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;
pWin->optional->boundingShape = NULL;
pWin->optional->clipShape = NULL;
pWin->optional->inputShape = NULL;
pWin->optional->deviceCursors = NULL;
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;
RegionInit(&pWin->clipList, &box, 1);
RegionInit(&pWin->winSize, &box, 1);
RegionInit(&pWin->borderSize, &box, 1);
RegionInit(&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;
/* security creation/labeling check
*/
if (XaceHookResourceAccess(serverClient, pWin->drawable.id,
X11_RESTYPE_WINDOW, pWin, X11_RESTYPE_NONE, NULL, DixCreateAccess))
if (!AddResource(pWin->drawable.id, X11_RESTYPE_WINDOW, (void *) pWin))
pScreen->backingStoreSupport = NotUseful;
pScreen->backingStoreSupport = WhenMapped;
#ifdef COMPOSITE
if (noCompositeExtension)
pScreen->backingStoreSupport = NotUseful;
#endif
ScreenPtr pScreen = pWin->drawable.pScreen;
int backFlag = CWBorderPixel | CWCursor | CWBackingStore;
if (!(*pScreen->CreateWindow) (pWin))
return; /* XXX */
(*pScreen->PositionWindow) (pWin, 0, 0);
pWin->optional->cursor = RefCursor(rootCursor);
if (party_like_its_1989) {
MakeRootTile(pWin);
backFlag |= CWBackPixmap;
}
else if (pScreen->canDoBGNoneRoot && bgNoneRoot) {
pWin->backgroundState = XaceBackgroundNoneState(pWin);
pWin->background.pixel = pScreen->whitePixel;
backFlag |= CWBackPixmap;
pWin->backgroundState = BackgroundPixel;
else
pWin->background.pixel = pScreen->blackPixel;
pWin->backingStore = NotUseful;
/* We SHOULD check for an error value here XXX */
(*pScreen->ChangeWindowAttributes) (pWin, backFlag);
MapWindow(pWin, serverClient);
}
/* 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.
*/
ClippedRegionFromBox(WindowPtr pWin, RegionPtr Rgn, int x, int y, int w, int h)
BoxRec box = *RegionExtents(&pWin->winSize);
/* we do these calculations to avoid overflows */
if (x > box.x1)
RegionReset(Rgn, &box);
RegionIntersect(Rgn, Rgn, &pWin->winSize);
static RealChildHeadProc realChildHeadProc = NULL;
RegisterRealChildHeadProc(RealChildHeadProc proc)
{
realChildHeadProc = proc;
}
WindowPtr
RealChildHead(WindowPtr pWin)
(screenIsSaved == SCREEN_SAVER_ON) &&
(HasSaverWindow(pWin->drawable.pScreen)))
return pWin->firstChild;
}
/*****
* CreateWindow
* Makes a window in response to client request
WindowPtr
CreateWindow(Window wid, WindowPtr pParent, int x, int y, unsigned w,
unsigned h, unsigned bw, unsigned class, Mask vmask, XID *vlist,
int depth, ClientPtr client, VisualID visual, int *error)
int idepth, ivisual;
Bool fOK;
DepthPtr pDepth;
PixmapFormatRec *format;
WindowOptPtr ancwopt;
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))
ancwopt = pParent->optional;
if (!ancwopt)
ancwopt = FindWindowWithOptional(pParent)->optional;
}
/* 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 = dixAllocateScreenObjectWithPrivates(pScreen, WindowRec, PRIVATE_WINDOW);
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;
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)) {
dixFreeObjectWithPrivates(pWin, PRIVATE_WINDOW);
*error = BadAlloc;
return NullWindow;
}
pWin->optional->visual = visual;
pWin->optional->colormap = None;
/* security creation/labeling check
*error = XaceHookResourceAccess(client, wid, X11_RESTYPE_WINDOW, pWin,
X11_RESTYPE_WINDOW, pWin->parent,
DixCreateAccess | DixSetAttrAccess);
if (*error != Success) {
dixFreeObjectWithPrivates(pWin, PRIVATE_WINDOW);
return NullWindow;
pWin->backgroundState = XaceBackgroundNoneState(pWin);
pWin->background.pixel = pScreen->whitePixel;
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 */
RegionNull(&pWin->clipList);
RegionNull(&pWin->borderClip);
RegionNull(&pWin->winSize);
RegionNull(&pWin->borderSize);
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);
*error = ChangeWindowAttributes(pWin, vmask, vlist, wClient(pWin));
if (*error != Success) {
DeleteWindow(pWin, None);
return NullWindow;
}
if (SubSend(pParent)) {
xEvent event = {
.u.createNotify.window = wid,
.u.createNotify.parent = pParent->drawable.id,
.u.createNotify.x = x,
.u.createNotify.y = y,
.u.createNotify.width = w,
.u.createNotify.height = h,
.u.createNotify.borderWidth = bw,
.u.createNotify.override = pWin->overrideRedirect
};
event.u.u.type = CreateNotify;
DeliverEvents(pParent, &event, 1, NullWindow);
DisposeWindowOptional(WindowPtr pWin)
/*
* everything is peachy. Delete the optional record
* and clean up
*/
if (pWin->optional->cursor) {
FreeCursor(pWin->optional->cursor, (Cursor) 0);
pWin->cursorIsNone = FALSE;
if (pWin->optional->deviceCursors) {
DevCursorList pList;
DevCursorList pPrev;
free(pPrev);
}
pWin->optional->deviceCursors = NULL;
}
free(pWin->optional);
pWin->optional = NULL;
}
FreeWindowResources(WindowPtr pWin)
ScreenPtr pScreen = pWin->drawable.pScreen;
DeleteWindowFromAnySaveSet(pWin);