PageRenderTime 45ms CodeModel.GetById 6ms RepoModel.GetById 0ms app.codeStats 1ms

/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

  1. #ifdef NXAGENT_UPGRADE
  2. #include "X/NXwindow.c"
  3. #else
  4. /**************************************************************************/
  5. /* */
  6. /* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/. */
  7. /* */
  8. /* NXAGENT, NX protocol compression and NX extensions to this software */
  9. /* are copyright of NoMachine. Redistribution and use of the present */
  10. /* software is allowed according to terms specified in the file LICENSE */
  11. /* which comes in the source distribution. */
  12. /* */
  13. /* Check http://www.nomachine.com/licensing.html for applicability. */
  14. /* */
  15. /* NX and NoMachine are trademarks of Medialogic S.p.A. */
  16. /* */
  17. /* All rights reserved. */
  18. /* */
  19. /**************************************************************************/
  20. /*
  21. Copyright 1987, 1998 The Open Group
  22. Permission to use, copy, modify, distribute, and sell this software and its
  23. documentation for any purpose is hereby granted without fee, provided that
  24. the above copyright notice appear in all copies and that both that
  25. copyright notice and this permission notice appear in supporting
  26. documentation.
  27. The above copyright notice and this permission notice shall be included
  28. in all copies or substantial portions of the Software.
  29. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  30. OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  31. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  32. IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
  33. OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  34. ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  35. OTHER DEALINGS IN THE SOFTWARE.
  36. Except as contained in this notice, the name of The Open Group shall
  37. not be used in advertising or otherwise to promote the sale, use or
  38. other dealings in this Software without prior written authorization
  39. from The Open Group.
  40. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
  41. All Rights Reserved
  42. Permission to use, copy, modify, and distribute this software and its
  43. documentation for any purpose and without fee is hereby granted,
  44. provided that the above copyright notice appear in all copies and that
  45. both that copyright notice and this permission notice appear in
  46. supporting documentation, and that the name of Digital not be
  47. used in advertising or publicity pertaining to distribution of the
  48. software without specific, written prior permission.
  49. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  50. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  51. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  52. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  53. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  54. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  55. SOFTWARE.
  56. */
  57. /****************************************************************
  58. * *
  59. * Copyright (c) Digital Equipment Corporation, 1991, 1997 *
  60. * *
  61. * All Rights Reserved. Unpublished rights reserved under *
  62. * the copyright laws of the United States. *
  63. * *
  64. * The software contained on this media is proprietary to *
  65. * and embodies the confidential technology of Digital *
  66. * Equipment Corporation. Possession, use, duplication or *
  67. * dissemination of the software and media is authorized only *
  68. * pursuant to a valid written license from Digital Equipment *
  69. * Corporation. *
  70. * *
  71. * RESTRICTED RIGHTS LEGEND Use, duplication, or disclosure *
  72. * by the U.S. Government is subject to restrictions as set *
  73. * forth in Subparagraph (c)(1)(ii) of DFARS 252.227-7013, *
  74. * or in FAR 52.227-19, as applicable. *
  75. * *
  76. *****************************************************************/
  77. #include "misc.h"
  78. #include "scrnintstr.h"
  79. #include "os.h"
  80. #include "regionstr.h"
  81. #include "validate.h"
  82. #include "windowstr.h"
  83. #include "input.h"
  84. #include "resource.h"
  85. #include "colormapst.h"
  86. #include "cursorstr.h"
  87. #include "dixstruct.h"
  88. #include "gcstruct.h"
  89. #include "servermd.h"
  90. #include "selection.h"
  91. #ifdef PANORAMIX
  92. #include "../../Xext/panoramiX.h"
  93. #include "../../Xext/panoramiXsrv.h"
  94. #endif
  95. #include "dixevents.h"
  96. #include "globals.h"
  97. #ifdef XAPPGROUP
  98. #include "Xagsrv.h"
  99. #endif
  100. #ifdef XCSECURITY
  101. #define _SECURITY_SERVER
  102. #include "security.h"
  103. #endif
  104. #include "Screen.h"
  105. #include "Options.h"
  106. #include "Atoms.h"
  107. #include "Clipboard.h"
  108. #include "Splash.h"
  109. #include "Rootless.h"
  110. #include "Composite.h"
  111. #include "Drawable.h"
  112. #include "Colormap.h"
  113. #if defined(NEED_SCREEN_REGIONS)
  114. #define REGION_PTR(pScreen,pWin) \
  115. register ScreenPtr pScreen = pWin->drawable.pScreen;
  116. #else
  117. #define REGION_PTR(pScreen,pWin) /* nothing */
  118. #endif
  119. extern Bool nxagentWMIsRunning;
  120. extern Bool nxagentScreenTrap;
  121. /******
  122. * Window stuff for server
  123. *
  124. * CreateRootWindow, CreateWindow, ChangeWindowAttributes,
  125. * GetWindowAttributes, DeleteWindow, DestroySubWindows,
  126. * HandleSaveSet, ReparentWindow, MapWindow, MapSubWindows,
  127. * UnmapWindow, UnmapSubWindows, ConfigureWindow, CirculateWindow,
  128. *
  129. ******/
  130. int screenIsSaved = SCREEN_SAVER_OFF;
  131. ScreenSaverStuffRec savedScreenInfo[MAXSCREENS];
  132. #if 0
  133. extern void DeleteWindowFromAnyEvents();
  134. extern Mask EventMaskForClient();
  135. extern void WindowHasNewCursor();
  136. extern void RecalculateDeliverableEvents();
  137. #endif
  138. static Bool TileScreenSaver(
  139. #if NeedFunctionPrototypes
  140. int /*i*/,
  141. int /*kind*/
  142. #endif
  143. );
  144. #define INPUTONLY_LEGAL_MASK (CWWinGravity | CWEventMask | \
  145. CWDontPropagate | CWOverrideRedirect | CWCursor )
  146. #define BOXES_OVERLAP(b1, b2) \
  147. (!( ((b1)->x2 <= (b2)->x1) || \
  148. ( ((b1)->x1 >= (b2)->x2)) || \
  149. ( ((b1)->y2 <= (b2)->y1)) || \
  150. ( ((b1)->y1 >= (b2)->y2)) ) )
  151. #define RedirectSend(pWin) \
  152. ((pWin->eventMask|wOtherEventMasks(pWin)) & SubstructureRedirectMask)
  153. #define SubSend(pWin) \
  154. ((pWin->eventMask|wOtherEventMasks(pWin)) & SubstructureNotifyMask)
  155. #define StrSend(pWin) \
  156. ((pWin->eventMask|wOtherEventMasks(pWin)) & StructureNotifyMask)
  157. #define SubStrSend(pWin,pParent) (StrSend(pWin) || SubSend(pParent))
  158. /*
  159. * Set here the required log level.
  160. */
  161. #define PANIC
  162. #define WARNING
  163. #undef TEST
  164. #undef DEBUG
  165. int numSaveUndersViewable = 0;
  166. int deltaSaveUndersViewable = 0;
  167. WindowPtr nxagentRootTileWindow;
  168. /*
  169. * This block used the DEBUG symbol.
  170. */
  171. #ifdef WINDOW_TREE_DEBUG
  172. /******
  173. * PrintWindowTree
  174. * For debugging only
  175. ******/
  176. int
  177. PrintChildren(p1, indent)
  178. WindowPtr p1;
  179. int indent;
  180. {
  181. WindowPtr p2;
  182. int i;
  183. while (p1)
  184. {
  185. p2 = p1->firstChild;
  186. for (i=0; i<indent; i++) ErrorF( " ");
  187. ErrorF( "%x\n", p1->drawable.id);
  188. miPrintRegion(&p1->clipList);
  189. PrintChildren(p2, indent+4);
  190. p1 = p1->nextSib;
  191. }
  192. }
  193. PrintWindowTree()
  194. {
  195. int i;
  196. WindowPtr pWin, p1;
  197. for (i=0; i<screenInfo.numScreens; i++)
  198. {
  199. ErrorF( "WINDOW %d\n", i);
  200. pWin = WindowTable[i];
  201. miPrintRegion(&pWin->clipList);
  202. p1 = pWin->firstChild;
  203. PrintChildren(p1, 4);
  204. }
  205. }
  206. #endif
  207. int
  208. TraverseTree(pWin, func, data)
  209. register WindowPtr pWin;
  210. VisitWindowProcPtr func;
  211. pointer data;
  212. {
  213. register int result;
  214. register WindowPtr pChild;
  215. if (!(pChild = pWin))
  216. return(WT_NOMATCH);
  217. while (1)
  218. {
  219. result = (* func)(pChild, data);
  220. if (result == WT_STOPWALKING)
  221. return(WT_STOPWALKING);
  222. if ((result == WT_WALKCHILDREN) && pChild->firstChild)
  223. {
  224. pChild = pChild->firstChild;
  225. continue;
  226. }
  227. while (!pChild->nextSib && (pChild != pWin))
  228. pChild = pChild->parent;
  229. if (pChild == pWin)
  230. break;
  231. pChild = pChild->nextSib;
  232. }
  233. return(WT_NOMATCH);
  234. }
  235. /*****
  236. * WalkTree
  237. * Walk the window tree, for SCREEN, preforming FUNC(pWin, data) on
  238. * each window. If FUNC returns WT_WALKCHILDREN, traverse the children,
  239. * if it returns WT_DONTWALKCHILDREN, dont. If it returns WT_STOPWALKING
  240. * exit WalkTree. Does depth-first traverse.
  241. *****/
  242. int
  243. WalkTree(pScreen, func, data)
  244. ScreenPtr pScreen;
  245. VisitWindowProcPtr func;
  246. pointer data;
  247. {
  248. return(TraverseTree(WindowTable[pScreen->myNum], func, data));
  249. }
  250. /* hack for forcing backing store on all windows */
  251. int defaultBackingStore = NotUseful;
  252. /* hack to force no backing store */
  253. Bool disableBackingStore = FALSE;
  254. Bool enableBackingStore = FALSE;
  255. /* hack to force no save unders */
  256. Bool disableSaveUnders = FALSE;
  257. static void
  258. #if NeedFunctionPrototypes
  259. SetWindowToDefaults(register WindowPtr pWin)
  260. #else
  261. SetWindowToDefaults(pWin)
  262. register WindowPtr pWin;
  263. #endif
  264. {
  265. pWin->prevSib = NullWindow;
  266. pWin->firstChild = NullWindow;
  267. pWin->lastChild = NullWindow;
  268. pWin->valdata = (ValidatePtr)NULL;
  269. pWin->optional = (WindowOptPtr)NULL;
  270. pWin->cursorIsNone = TRUE;
  271. pWin->backingStore = NotUseful;
  272. pWin->DIXsaveUnder = FALSE;
  273. pWin->backStorage = (pointer) NULL;
  274. pWin->mapped = FALSE; /* off */
  275. pWin->realized = FALSE; /* off */
  276. pWin->viewable = FALSE;
  277. pWin->visibility = VisibilityNotViewable;
  278. pWin->overrideRedirect = FALSE;
  279. pWin->saveUnder = FALSE;
  280. pWin->bitGravity = ForgetGravity;
  281. pWin->winGravity = NorthWestGravity;
  282. pWin->eventMask = 0;
  283. pWin->deliverableEvents = 0;
  284. pWin->dontPropagate = 0;
  285. pWin->forcedBS = FALSE;
  286. #ifdef NEED_DBE_BUF_BITS
  287. pWin->srcBuffer = DBE_FRONT_BUFFER;
  288. pWin->dstBuffer = DBE_FRONT_BUFFER;
  289. #endif
  290. }
  291. void nxagentClearSplash(WindowPtr pW)
  292. {
  293. int w, h;
  294. ScreenPtr pScreen;
  295. w = pW->drawable.width;
  296. h = pW->drawable.height;
  297. pScreen = pW->drawable.pScreen;
  298. if (pW->backgroundState == BackgroundPixmap)
  299. {
  300. (*pScreen->DestroyPixmap)(pW->background.pixmap);
  301. }
  302. pW->backgroundState = BackgroundPixel;
  303. pW->background.pixel = nxagentLogoBlack;
  304. (*pScreen->ChangeWindowAttributes)(pW, CWBackPixmap|CWBackPixel);
  305. }
  306. static void
  307. #if NeedFunctionPrototypes
  308. MakeRootTile(WindowPtr pWin)
  309. #else
  310. MakeRootTile(pWin)
  311. WindowPtr pWin;
  312. #endif
  313. {
  314. nxagentRootTileWindow = pWin;
  315. }
  316. WindowPtr
  317. AllocateWindow(pScreen)
  318. ScreenPtr pScreen;
  319. {
  320. WindowPtr pWin;
  321. register char *ptr;
  322. register DevUnion *ppriv;
  323. register unsigned *sizes;
  324. register unsigned size;
  325. register int i;
  326. pWin = (WindowPtr)xalloc(pScreen->totalWindowSize);
  327. if (pWin)
  328. {
  329. ppriv = (DevUnion *)(pWin + 1);
  330. pWin->devPrivates = ppriv;
  331. sizes = pScreen->WindowPrivateSizes;
  332. ptr = (char *)(ppriv + pScreen->WindowPrivateLen);
  333. for (i = pScreen->WindowPrivateLen; --i >= 0; ppriv++, sizes++)
  334. {
  335. if ( (size = *sizes) )
  336. {
  337. ppriv->ptr = (pointer)ptr;
  338. ptr += size;
  339. }
  340. else
  341. ppriv->ptr = (pointer)NULL;
  342. }
  343. }
  344. return pWin;
  345. }
  346. /*****
  347. * CreateRootWindow
  348. * Makes a window at initialization time for specified screen
  349. *****/
  350. Bool
  351. CreateRootWindow(pScreen)
  352. ScreenPtr pScreen;
  353. {
  354. WindowPtr pWin;
  355. BoxRec box;
  356. PixmapFormatRec *format;
  357. pWin = AllocateWindow(pScreen);
  358. if (!pWin)
  359. return FALSE;
  360. savedScreenInfo[pScreen->myNum].pWindow = NULL;
  361. savedScreenInfo[pScreen->myNum].wid = FakeClientID(0);
  362. savedScreenInfo[pScreen->myNum].ExternalScreenSaver = NULL;
  363. screenIsSaved = SCREEN_SAVER_OFF;
  364. WindowTable[pScreen->myNum] = pWin;
  365. pWin->drawable.pScreen = pScreen;
  366. pWin->drawable.type = DRAWABLE_WINDOW;
  367. pWin->drawable.depth = pScreen->rootDepth;
  368. for (format = screenInfo.formats;
  369. format->depth != pScreen->rootDepth;
  370. format++)
  371. ;
  372. pWin->drawable.bitsPerPixel = format->bitsPerPixel;
  373. pWin->drawable.serialNumber = NEXT_SERIAL_NUMBER;
  374. pWin->parent = NullWindow;
  375. SetWindowToDefaults(pWin);
  376. pWin->optional = (WindowOptRec *) xalloc (sizeof (WindowOptRec));
  377. if (!pWin->optional)
  378. return FALSE;
  379. pWin->optional->dontPropagateMask = 0;
  380. pWin->optional->otherEventMasks = 0;
  381. pWin->optional->otherClients = NULL;
  382. pWin->optional->passiveGrabs = NULL;
  383. pWin->optional->userProps = NULL;
  384. pWin->optional->backingBitPlanes = ~0L;
  385. pWin->optional->backingPixel = 0;
  386. #ifdef SHAPE
  387. pWin->optional->boundingShape = NULL;
  388. pWin->optional->clipShape = NULL;
  389. #endif
  390. #ifdef XINPUT
  391. pWin->optional->inputMasks = NULL;
  392. #endif
  393. pWin->optional->colormap = pScreen->defColormap;
  394. pWin->optional->visual = pScreen->rootVisual;
  395. pWin->nextSib = NullWindow;
  396. pWin->drawable.id = FakeClientID(0);
  397. pWin->origin.x = pWin->origin.y = 0;
  398. pWin->drawable.height = pScreen->height;
  399. pWin->drawable.width = pScreen->width;
  400. pWin->drawable.x = pWin->drawable.y = 0;
  401. box.x1 = 0;
  402. box.y1 = 0;
  403. box.x2 = pScreen->width;
  404. box.y2 = pScreen->height;
  405. REGION_INIT(pScreen, &pWin->clipList, &box, 1);
  406. REGION_INIT(pScreen, &pWin->winSize, &box, 1);
  407. REGION_INIT(pScreen, &pWin->borderSize, &box, 1);
  408. REGION_INIT(pScreen, &pWin->borderClip, &box, 1);
  409. pWin->drawable.class = InputOutput;
  410. pWin->optional->visual = pScreen->rootVisual;
  411. pWin->backgroundState = BackgroundPixel;
  412. pWin->background.pixel = pScreen->whitePixel;
  413. pWin->borderIsPixel = TRUE;
  414. pWin->border.pixel = pScreen->blackPixel;
  415. pWin->borderWidth = 0;
  416. if (!AddResource(pWin->drawable.id, RT_WINDOW, (pointer)pWin))
  417. return FALSE;
  418. if (disableBackingStore)
  419. {
  420. pScreen -> backingStoreSupport = NotUseful;
  421. }
  422. if (enableBackingStore)
  423. {
  424. pScreen -> backingStoreSupport = Always;
  425. }
  426. pScreen->saveUnderSupport = False;
  427. #ifdef DO_SAVE_UNDERS
  428. if ((pScreen->backingStoreSupport != NotUseful) &&
  429. (pScreen->saveUnderSupport == NotUseful))
  430. {
  431. /*
  432. * If the screen has backing-store but no save-unders, let the
  433. * clients know we can support save-unders using backing-store.
  434. */
  435. pScreen->saveUnderSupport = USE_DIX_SAVE_UNDERS;
  436. }
  437. #endif /* DO_SAVE_UNDERS */
  438. if (disableSaveUnders)
  439. pScreen->saveUnderSupport = NotUseful;
  440. return TRUE;
  441. }
  442. void
  443. InitRootWindow(pWin)
  444. WindowPtr pWin;
  445. {
  446. ScreenPtr pScreen;
  447. #ifdef TEST
  448. fprintf(stderr, "InitRootWindow: Called for window at [%p][%ld] with parent [%p].\n",
  449. (void *) pWin, nxagentWindowPriv(pWin)->window, (void *) pWin -> parent);
  450. #endif
  451. if (nxagentOption(Rootless))
  452. {
  453. #ifdef TEST
  454. fprintf(stderr, "InitRootWindow: Assigned agent root to window at [%p][%ld] with parent [%p].\n",
  455. (void *) pWin, nxagentWindowPriv(pWin)->window, (void *) pWin -> parent);
  456. #endif
  457. nxagentRootlessWindow = pWin;
  458. }
  459. pScreen = pWin->drawable.pScreen;
  460. /*
  461. * A root window is created for each screen by main
  462. * and the pointer is saved in WindowTable as in the
  463. * following snippet:
  464. *
  465. * for (i = 0; i < screenInfo.numScreens; i++)
  466. * InitRootWindow(WindowTable[i]);
  467. *
  468. * Our root window on the real display was already
  469. * created at the time the screen was opened, so it
  470. * is unclear how this window (or the other window,
  471. * if you prefer) fits in the big picture.
  472. */
  473. #ifdef TEST
  474. fprintf(stderr, "InitRootWindow: Going to create window as root at [%p][%ld] with parent [%p].\n",
  475. (void *) pWin, nxagentWindowPriv(pWin)->window, (void *) pWin -> parent);
  476. #endif
  477. if (!(*pScreen->CreateWindow)(pWin))
  478. return; /* XXX */
  479. #ifdef TEST
  480. fprintf(stderr, "InitRootWindow: Created window as root at [%p][%ld] with parent [%p].\n",
  481. (void *) pWin, nxagentWindowPriv(pWin)->window, (void *) pWin -> parent);
  482. #endif
  483. (*pScreen->PositionWindow)(pWin, 0, 0);
  484. pWin->cursorIsNone = FALSE;
  485. pWin->optional->cursor = rootCursor;
  486. rootCursor->refcnt++;
  487. pWin->backingStore = defaultBackingStore;
  488. pWin->forcedBS = (defaultBackingStore != NotUseful);
  489. #ifdef NXAGENT_SPLASH
  490. /* We SHOULD check for an error value here XXX */
  491. pWin -> background.pixel = pScreen -> blackPixel;
  492. (*pScreen->ChangeWindowAttributes)(pWin,
  493. CWBackPixel|CWBorderPixel|CWCursor|CWBackingStore);
  494. #else
  495. (*pScreen->ChangeWindowAttributes)(pWin,
  496. CWBackPixmap|CWBorderPixel|CWCursor|CWBackingStore);
  497. #endif
  498. MakeRootTile(pWin);
  499. /*
  500. * Map both the root and the default agent window.
  501. */
  502. #ifdef TEST
  503. fprintf(stderr, "InitRootWindow: Mapping default windows.\n");
  504. #endif
  505. nxagentInitAtoms(pWin);
  506. nxagentInitClipboard(pWin);
  507. nxagentMapDefaultWindows();
  508. nxagentRedirectDefaultWindows();
  509. #ifdef NXAGENT_ARTSD
  510. {
  511. char artsd_port[10];
  512. int nPort;
  513. extern void nxagentPropagateArtsdProperties(ScreenPtr pScreen, char *port);
  514. nPort = atoi(display) + 7000;
  515. sprintf(artsd_port,"%d", nPort);
  516. nxagentPropagateArtsdProperties(pScreen, artsd_port);
  517. }
  518. #endif
  519. }
  520. /* Set the region to the intersection of the rectangle and the
  521. * window's winSize. The window is typically the parent of the
  522. * window from which the region came.
  523. */
  524. void
  525. ClippedRegionFromBox(pWin, Rgn, x, y, w, h)
  526. register WindowPtr pWin;
  527. RegionPtr Rgn;
  528. register int x, y;
  529. int w, h;
  530. {
  531. REGION_PTR(pScreen, pWin)
  532. BoxRec box;
  533. box = *(REGION_EXTENTS(pScreen, &pWin->winSize));
  534. /* we do these calculations to avoid overflows */
  535. if (x > box.x1)
  536. box.x1 = x;
  537. if (y > box.y1)
  538. box.y1 = y;
  539. x += w;
  540. if (x < box.x2)
  541. box.x2 = x;
  542. y += h;
  543. if (y < box.y2)
  544. box.y2 = y;
  545. if (box.x1 > box.x2)
  546. box.x2 = box.x1;
  547. if (box.y1 > box.y2)
  548. box.y2 = box.y1;
  549. REGION_RESET(pScreen, Rgn, &box);
  550. REGION_INTERSECT(pScreen, Rgn, Rgn, &pWin->winSize);
  551. }
  552. WindowPtr
  553. RealChildHead(pWin)
  554. register WindowPtr pWin;
  555. {
  556. if (!pWin->parent &&
  557. (screenIsSaved == SCREEN_SAVER_ON) &&
  558. (HasSaverWindow (pWin->drawable.pScreen->myNum)))
  559. return (pWin->firstChild);
  560. else
  561. return (NullWindow);
  562. }
  563. /*****
  564. * CreateWindow
  565. * Makes a window in response to client request
  566. *****/
  567. WindowPtr
  568. CreateWindow(wid, pParent, x, y, w, h, bw, class, vmask, vlist,
  569. depth, client, visual, error)
  570. Window wid;
  571. register WindowPtr pParent;
  572. int x,y;
  573. unsigned int w, h, bw;
  574. unsigned int class;
  575. register Mask vmask;
  576. XID *vlist;
  577. int depth;
  578. ClientPtr client;
  579. VisualID visual;
  580. int *error;
  581. {
  582. register WindowPtr pWin;
  583. WindowPtr pHead;
  584. register ScreenPtr pScreen;
  585. xEvent event;
  586. int idepth, ivisual;
  587. Bool fOK;
  588. DepthPtr pDepth;
  589. PixmapFormatRec *format;
  590. register WindowOptPtr ancwopt;
  591. if (class == CopyFromParent)
  592. class = pParent->drawable.class;
  593. if ((class != InputOutput) && (class != InputOnly))
  594. {
  595. *error = BadValue;
  596. client->errorValue = class;
  597. return NullWindow;
  598. }
  599. if ((class != InputOnly) && (pParent->drawable.class == InputOnly))
  600. {
  601. *error = BadMatch;
  602. return NullWindow;
  603. }
  604. if ((class == InputOnly) && ((bw != 0) || (depth != 0)))
  605. {
  606. *error = BadMatch;
  607. return NullWindow;
  608. }
  609. pScreen = pParent->drawable.pScreen;
  610. if ((class == InputOutput) && (depth == 0))
  611. depth = pParent->drawable.depth;
  612. ancwopt = pParent->optional;
  613. if (!ancwopt)
  614. ancwopt = FindWindowWithOptional(pParent)->optional;
  615. if (visual == CopyFromParent) {
  616. #ifdef XAPPGROUP
  617. VisualID ag_visual;
  618. if (client->appgroup && !pParent->parent &&
  619. (ag_visual = XagRootVisual (client)))
  620. visual = ag_visual;
  621. else
  622. #endif
  623. visual = ancwopt->visual;
  624. }
  625. /* Find out if the depth and visual are acceptable for this Screen */
  626. if ((visual != ancwopt->visual) || (depth != pParent->drawable.depth))
  627. {
  628. fOK = FALSE;
  629. for(idepth = 0; idepth < pScreen->numDepths; idepth++)
  630. {
  631. pDepth = (DepthPtr) &pScreen->allowedDepths[idepth];
  632. if ((depth == pDepth->depth) || (depth == 0))
  633. {
  634. for (ivisual = 0; ivisual < pDepth->numVids; ivisual++)
  635. {
  636. if (visual == pDepth->vids[ivisual])
  637. {
  638. fOK = TRUE;
  639. break;
  640. }
  641. }
  642. }
  643. }
  644. if (fOK == FALSE)
  645. {
  646. *error = BadMatch;
  647. return NullWindow;
  648. }
  649. }
  650. if (((vmask & (CWBorderPixmap | CWBorderPixel)) == 0) &&
  651. (class != InputOnly) &&
  652. (depth != pParent->drawable.depth))
  653. {
  654. *error = BadMatch;
  655. return NullWindow;
  656. }
  657. if (((vmask & CWColormap) == 0) &&
  658. (class != InputOnly) &&
  659. ((visual != ancwopt->visual) || (ancwopt->colormap == None)))
  660. {
  661. *error = BadMatch;
  662. return NullWindow;
  663. }
  664. pWin = AllocateWindow(pScreen);
  665. if (!pWin)
  666. {
  667. *error = BadAlloc;
  668. return NullWindow;
  669. }
  670. pWin->drawable = pParent->drawable;
  671. pWin->drawable.depth = depth;
  672. if (depth == pParent->drawable.depth)
  673. pWin->drawable.bitsPerPixel = pParent->drawable.bitsPerPixel;
  674. else
  675. {
  676. for (format = screenInfo.formats; format->depth != depth; format++)
  677. ;
  678. pWin->drawable.bitsPerPixel = format->bitsPerPixel;
  679. }
  680. if (class == InputOnly)
  681. pWin->drawable.type = (short) UNDRAWABLE_WINDOW;
  682. pWin->drawable.serialNumber = NEXT_SERIAL_NUMBER;
  683. pWin->drawable.id = wid;
  684. pWin->drawable.class = class;
  685. pWin->parent = pParent;
  686. SetWindowToDefaults(pWin);
  687. if (visual != ancwopt->visual)
  688. {
  689. if (!MakeWindowOptional (pWin))
  690. {
  691. xfree (pWin);
  692. *error = BadAlloc;
  693. return NullWindow;
  694. }
  695. pWin->optional->visual = visual;
  696. pWin->optional->colormap = None;
  697. }
  698. pWin->borderWidth = bw;
  699. #ifdef XCSECURITY
  700. /* can't let untrusted clients have background None windows;
  701. * they make it too easy to steal window contents
  702. */
  703. if (client->trustLevel != XSecurityClientTrusted)
  704. {
  705. pWin->backgroundState = BackgroundPixel;
  706. pWin->background.pixel = 0;
  707. }
  708. else
  709. #endif
  710. pWin->backgroundState = None;
  711. pWin->borderIsPixel = pParent->borderIsPixel;
  712. pWin->border = pParent->border;
  713. if (pWin->borderIsPixel == FALSE)
  714. pWin->border.pixmap->refcnt++;
  715. pWin->origin.x = x + (int)bw;
  716. pWin->origin.y = y + (int)bw;
  717. pWin->drawable.width = w;
  718. pWin->drawable.height = h;
  719. pWin->drawable.x = pParent->drawable.x + x + (int)bw;
  720. pWin->drawable.y = pParent->drawable.y + y + (int)bw;
  721. /* set up clip list correctly for unobscured WindowPtr */
  722. REGION_INIT(pScreen, &pWin->clipList, NullBox, 1);
  723. REGION_INIT(pScreen, &pWin->borderClip, NullBox, 1);
  724. REGION_INIT(pScreen, &pWin->winSize, NullBox, 1);
  725. REGION_INIT(pScreen, &pWin->borderSize, NullBox, 1);
  726. pHead = RealChildHead(pParent);
  727. if (pHead)
  728. {
  729. pWin->nextSib = pHead->nextSib;
  730. if (pHead->nextSib)
  731. pHead->nextSib->prevSib = pWin;
  732. else
  733. pParent->lastChild = pWin;
  734. pHead->nextSib = pWin;
  735. pWin->prevSib = pHead;
  736. }
  737. else
  738. {
  739. pWin->nextSib = pParent->firstChild;
  740. if (pParent->firstChild)
  741. pParent->firstChild->prevSib = pWin;
  742. else
  743. pParent->lastChild = pWin;
  744. pParent->firstChild = pWin;
  745. }
  746. SetWinSize (pWin);
  747. SetBorderSize (pWin);
  748. /* We SHOULD check for an error value here XXX */
  749. if (!(*pScreen->CreateWindow)(pWin))
  750. {
  751. *error = BadAlloc;
  752. DeleteWindow(pWin, None);
  753. return NullWindow;
  754. }
  755. /* We SHOULD check for an error value here XXX */
  756. (*pScreen->PositionWindow)(pWin, pWin->drawable.x, pWin->drawable.y);
  757. if (!(vmask & CWEventMask))
  758. RecalculateDeliverableEvents(pWin);
  759. if (vmask)
  760. *error = ChangeWindowAttributes(pWin, vmask, vlist, wClient (pWin));
  761. else
  762. *error = Success;
  763. if (*error != Success)
  764. {
  765. DeleteWindow(pWin, None);
  766. return NullWindow;
  767. }
  768. if (!(vmask & CWBackingStore) && (defaultBackingStore != NotUseful))
  769. {
  770. XID value = defaultBackingStore;
  771. (void)ChangeWindowAttributes(pWin, CWBackingStore, &value, wClient (pWin));
  772. pWin->forcedBS = TRUE;
  773. }
  774. if (SubSend(pParent))
  775. {
  776. event.u.u.type = CreateNotify;
  777. event.u.createNotify.window = wid;
  778. event.u.createNotify.parent = pParent->drawable.id;
  779. event.u.createNotify.x = x;
  780. event.u.createNotify.y = y;
  781. event.u.createNotify.width = w;
  782. event.u.createNotify.height = h;
  783. event.u.createNotify.borderWidth = bw;
  784. event.u.createNotify.override = pWin->overrideRedirect;
  785. DeliverEvents(pParent, &event, 1, NullWindow);
  786. }
  787. return pWin;
  788. }
  789. static void
  790. #if NeedFunctionPrototypes
  791. FreeWindowResources(register WindowPtr pWin)
  792. #else
  793. FreeWindowResources(pWin)
  794. register WindowPtr pWin;
  795. #endif
  796. {
  797. register ScreenPtr pScreen = pWin->drawable.pScreen;
  798. DeleteWindowFromAnySaveSet(pWin);
  799. DeleteWindowFromAnySelections(pWin);
  800. DeleteWindowFromAnyEvents(pWin, TRUE);
  801. REGION_UNINIT(pScreen, &pWin->clipList);
  802. REGION_UNINIT(pScreen, &pWin->winSize);
  803. REGION_UNINIT(pScreen, &pWin->borderClip);
  804. REGION_UNINIT(pScreen, &pWin->borderSize);
  805. #ifdef SHAPE
  806. if (wBoundingShape (pWin))
  807. REGION_DESTROY(pScreen, wBoundingShape (pWin));
  808. if (wClipShape (pWin))
  809. REGION_DESTROY(pScreen, wClipShape (pWin));
  810. #endif
  811. if (pWin->borderIsPixel == FALSE)
  812. (*pScreen->DestroyPixmap)(pWin->border.pixmap);
  813. if (pWin->backgroundState == BackgroundPixmap)
  814. (*pScreen->DestroyPixmap)(pWin->background.pixmap);
  815. DeleteAllWindowProperties(pWin);
  816. /* We SHOULD check for an error value here XXX */
  817. (*pScreen->DestroyWindow)(pWin);
  818. DisposeWindowOptional (pWin);
  819. }
  820. static void
  821. #if NeedFunctionPrototypes
  822. CrushTree(WindowPtr pWin)
  823. #else
  824. CrushTree(pWin)
  825. WindowPtr pWin;
  826. #endif
  827. {
  828. register WindowPtr pChild, pSib, pParent;
  829. UnrealizeWindowProcPtr UnrealizeWindow;
  830. xEvent event;
  831. if (!(pChild = pWin->firstChild))
  832. return;
  833. UnrealizeWindow = pWin->drawable.pScreen->UnrealizeWindow;
  834. while (1)
  835. {
  836. if (pChild->firstChild)
  837. {
  838. pChild = pChild->firstChild;
  839. continue;
  840. }
  841. while (1)
  842. {
  843. pParent = pChild->parent;
  844. if (SubStrSend(pChild, pParent))
  845. {
  846. event.u.u.type = DestroyNotify;
  847. event.u.destroyNotify.window = pChild->drawable.id;
  848. DeliverEvents(pChild, &event, 1, NullWindow);
  849. }
  850. FreeResource(pChild->drawable.id, RT_WINDOW);
  851. pSib = pChild->nextSib;
  852. #ifdef DO_SAVE_UNDERS
  853. if (pChild->saveUnder && pChild->viewable)
  854. deltaSaveUndersViewable--;
  855. #endif
  856. pChild->viewable = FALSE;
  857. if (pChild->realized)
  858. {
  859. pChild->realized = FALSE;
  860. (*UnrealizeWindow)(pChild);
  861. }
  862. FreeWindowResources(pChild);
  863. xfree(pChild);
  864. if ( (pChild = pSib) )
  865. break;
  866. pChild = pParent;
  867. pChild->firstChild = NullWindow;
  868. pChild->lastChild = NullWindow;
  869. if (pChild == pWin)
  870. return;
  871. }
  872. }
  873. }
  874. /*****
  875. * DeleteWindow
  876. * Deletes child of window then window itself
  877. * If wid is None, don't send any events
  878. *****/
  879. /*ARGSUSED*/
  880. int
  881. DeleteWindow(value, wid)
  882. pointer value;
  883. XID wid;
  884. {
  885. register WindowPtr pParent;
  886. register WindowPtr pWin = (WindowPtr)value;
  887. xEvent event;
  888. UnmapWindow(pWin, FALSE);
  889. CrushTree(pWin);
  890. pParent = pWin->parent;
  891. if (wid && pParent && SubStrSend(pWin, pParent))
  892. {
  893. event.u.u.type = DestroyNotify;
  894. event.u.destroyNotify.window = pWin->drawable.id;
  895. DeliverEvents(pWin, &event, 1, NullWindow);
  896. }
  897. FreeWindowResources(pWin);
  898. if (pParent)
  899. {
  900. if (pParent->firstChild == pWin)
  901. pParent->firstChild = pWin->nextSib;
  902. if (pParent->lastChild == pWin)
  903. pParent->lastChild = pWin->prevSib;
  904. if (pWin->nextSib)
  905. pWin->nextSib->prevSib = pWin->prevSib;
  906. if (pWin->prevSib)
  907. pWin->prevSib->nextSib = pWin->nextSib;
  908. }
  909. xfree(pWin);
  910. if (pWin -> optional &&
  911. pWin -> optional -> colormap &&
  912. pWin -> parent)
  913. {
  914. nxagentSetInstalledColormapWindows(pWin -> drawable.pScreen);
  915. }
  916. return Success;
  917. }
  918. /*ARGSUSED*/
  919. void
  920. DestroySubwindows(pWin, client)
  921. register WindowPtr pWin;
  922. ClientPtr client;
  923. {
  924. /* XXX
  925. * The protocol is quite clear that each window should be
  926. * destroyed in turn, however, unmapping all of the first
  927. * eliminates most of the calls to ValidateTree. So,
  928. * this implementation is incorrect in that all of the
  929. * UnmapNotifies occur before all of the DestroyNotifies.
  930. * If you care, simply delete the call to UnmapSubwindows.
  931. */
  932. UnmapSubwindows(pWin);
  933. while (pWin->lastChild)
  934. FreeResource(pWin->lastChild->drawable.id, RT_NONE);
  935. }
  936. #define DeviceEventMasks (KeyPressMask | KeyReleaseMask | ButtonPressMask | \
  937. ButtonReleaseMask | PointerMotionMask)
  938. /*****
  939. * ChangeWindowAttributes
  940. *
  941. * The value-mask specifies which attributes are to be changed; the
  942. * value-list contains one value for each one bit in the mask, from least
  943. * to most significant bit in the mask.
  944. *****/
  945. int
  946. ChangeWindowAttributes(pWin, vmask, vlist, client)
  947. register WindowPtr pWin;
  948. Mask vmask;
  949. XID *vlist;
  950. ClientPtr client;
  951. {
  952. register Mask index2;
  953. register XID *pVlist;
  954. PixmapPtr pPixmap;
  955. Pixmap pixID;
  956. CursorPtr pCursor, pOldCursor;
  957. Cursor cursorID;
  958. WindowPtr pChild;
  959. Colormap cmap;
  960. ColormapPtr pCmap;
  961. xEvent xE;
  962. int result;
  963. register ScreenPtr pScreen;
  964. Mask vmaskCopy = 0;
  965. register Mask tmask;
  966. unsigned int val;
  967. int error;
  968. Bool checkOptional = FALSE;
  969. Bool borderRelative = FALSE;
  970. WindowPtr pLayerWin;
  971. if ((pWin->drawable.class == InputOnly) && (vmask & (~INPUTONLY_LEGAL_MASK)))
  972. return BadMatch;
  973. error = Success;
  974. pScreen = pWin->drawable.pScreen;
  975. pVlist = vlist;
  976. tmask = vmask;
  977. while (tmask)
  978. {
  979. index2 = (Mask) lowbit (tmask);
  980. tmask &= ~index2;
  981. switch (index2)
  982. {
  983. case CWBackPixmap:
  984. pixID = (Pixmap )*pVlist;
  985. pVlist++;
  986. if (pWin->backgroundState == ParentRelative)
  987. borderRelative = TRUE;
  988. if (pixID == None)
  989. {
  990. #ifdef XCSECURITY
  991. /* can't let untrusted clients have background None windows */
  992. if (client->trustLevel == XSecurityClientTrusted)
  993. {
  994. #endif
  995. if (pWin->backgroundState == BackgroundPixmap)
  996. (*pScreen->DestroyPixmap)(pWin->background.pixmap);
  997. if (!pWin->parent)
  998. MakeRootTile(pWin);
  999. else
  1000. pWin->backgroundState = None;
  1001. #ifdef XCSECURITY
  1002. }
  1003. else
  1004. { /* didn't change the background to None, so don't tell ddx */
  1005. index2 = 0;
  1006. }
  1007. #endif
  1008. }
  1009. else if (pixID == ParentRelative)
  1010. {
  1011. if (pWin->parent &&
  1012. pWin->drawable.depth != pWin->parent->drawable.depth)
  1013. {
  1014. error = BadMatch;
  1015. goto PatchUp;
  1016. }
  1017. if (pWin->backgroundState == BackgroundPixmap)
  1018. (*pScreen->DestroyPixmap)(pWin->background.pixmap);
  1019. if (!pWin->parent)
  1020. MakeRootTile(pWin);
  1021. else
  1022. pWin->backgroundState = ParentRelative;
  1023. borderRelative = TRUE;
  1024. /* Note that the parent's backgroundTile's refcnt is NOT
  1025. * incremented. */
  1026. }
  1027. else
  1028. {
  1029. pPixmap = (PixmapPtr)SecurityLookupIDByType(client, pixID,
  1030. RT_PIXMAP, SecurityReadAccess);
  1031. if (pPixmap != (PixmapPtr) NULL)
  1032. {
  1033. if ((pPixmap->drawable.depth != pWin->drawable.depth) ||
  1034. (pPixmap->drawable.pScreen != pScreen))
  1035. {
  1036. error = BadMatch;
  1037. goto PatchUp;
  1038. }
  1039. if (pWin->backgroundState == BackgroundPixmap)
  1040. (*pScreen->DestroyPixmap)(pWin->background.pixmap);
  1041. pWin->backgroundState = BackgroundPixmap;
  1042. pWin->background.pixmap = pPixmap;
  1043. pPixmap->refcnt++;
  1044. }
  1045. else
  1046. {
  1047. error = BadPixmap;
  1048. client->errorValue = pixID;
  1049. goto PatchUp;
  1050. }
  1051. }
  1052. break;
  1053. case CWBackPixel:
  1054. if (pWin->backgroundState == ParentRelative)
  1055. borderRelative = TRUE;
  1056. if (pWin->backgroundState == BackgroundPixmap)
  1057. (*pScreen->DestroyPixmap)(pWin->background.pixmap);
  1058. pWin->backgroundState = BackgroundPixel;
  1059. pWin->background.pixel = (CARD32 ) *pVlist;
  1060. /* background pixel overrides background pixmap,
  1061. so don't let the ddx layer see both bits */
  1062. vmaskCopy &= ~CWBackPixmap;
  1063. pVlist++;
  1064. break;
  1065. case CWBorderPixmap:
  1066. pixID = (Pixmap ) *pVlist;
  1067. pVlist++;
  1068. if (pixID == CopyFromParent)
  1069. {
  1070. if (!pWin->parent ||
  1071. (pWin->drawable.depth != pWin->parent->drawable.depth))
  1072. {
  1073. error = BadMatch;
  1074. goto PatchUp;
  1075. }
  1076. if (pWin->borderIsPixel == FALSE)
  1077. (*pScreen->DestroyPixmap)(pWin->border.pixmap);
  1078. pWin->border = pWin->parent->border;
  1079. if ((pWin->borderIsPixel = pWin->parent->borderIsPixel) == TRUE)
  1080. {
  1081. index2 = CWBorderPixel;
  1082. }
  1083. else
  1084. {
  1085. pWin->parent->border.pixmap->refcnt++;
  1086. }
  1087. }
  1088. else
  1089. {
  1090. pPixmap = (PixmapPtr)SecurityLookupIDByType(client, pixID,
  1091. RT_PIXMAP, SecurityReadAccess);
  1092. if (pPixmap)
  1093. {
  1094. if ((pPixmap->drawable.depth != pWin->drawable.depth) ||
  1095. (pPixmap->drawable.pScreen != pScreen))
  1096. {
  1097. error = BadMatch;
  1098. goto PatchUp;
  1099. }
  1100. if (pWin->borderIsPixel == FALSE)
  1101. (*pScreen->DestroyPixmap)(pWin->border.pixmap);
  1102. pWin->borderIsPixel = FALSE;
  1103. pWin->border.pixmap = pPixmap;
  1104. pPixmap->refcnt++;
  1105. }
  1106. else
  1107. {
  1108. error = BadPixmap;
  1109. client->errorValue = pixID;
  1110. goto PatchUp;
  1111. }
  1112. }
  1113. break;
  1114. case CWBorderPixel:
  1115. if (pWin->borderIsPixel == FALSE)
  1116. (*pScreen->DestroyPixmap)(pWin->border.pixmap);
  1117. pWin->borderIsPixel = TRUE;
  1118. pWin->border.pixel = (CARD32) *pVlist;
  1119. /* border pixel overrides border pixmap,
  1120. so don't let the ddx layer see both bits */
  1121. vmaskCopy &= ~CWBorderPixmap;
  1122. pVlist++;
  1123. break;
  1124. case CWBitGravity:
  1125. val = (CARD8 )*pVlist;
  1126. pVlist++;
  1127. if (val > StaticGravity)
  1128. {
  1129. error = BadValue;
  1130. client->errorValue = val;
  1131. goto PatchUp;
  1132. }
  1133. pWin->bitGravity = val;
  1134. break;
  1135. case CWWinGravity:
  1136. val = (CARD8 )*pVlist;
  1137. pVlist++;
  1138. if (val > StaticGravity)
  1139. {
  1140. error = BadValue;
  1141. client->errorValue = val;
  1142. goto PatchUp;
  1143. }
  1144. pWin->winGravity = val;
  1145. break;
  1146. case CWBackingStore:
  1147. val = (CARD8 )*pVlist;
  1148. pVlist++;
  1149. if ((val != NotUseful) && (val != WhenMapped) && (val != Always))
  1150. {
  1151. error = BadValue;
  1152. client->errorValue = val;
  1153. goto PatchUp;
  1154. }
  1155. pWin->backingStore = val;
  1156. #ifdef TEST
  1157. fprintf(stderr, "ChangeWindowAttributes: Changed backing store value to %d for window at %p.\n",
  1158. val, (void*)pWin);
  1159. #endif
  1160. pWin->forcedBS = FALSE;
  1161. break;
  1162. case CWBackingPlanes:
  1163. if (pWin->optional || ((CARD32)*pVlist != (CARD32)~0L)) {
  1164. if (!pWin->optional && !MakeWindowOptional (pWin))
  1165. {
  1166. error = BadAlloc;
  1167. goto PatchUp;
  1168. }
  1169. pWin->optional->backingBitPlanes = (CARD32) *pVlist;
  1170. if ((CARD32)*pVlist == (CARD32)~0L)
  1171. checkOptional = TRUE;
  1172. }
  1173. pVlist++;
  1174. break;
  1175. case CWBackingPixel:
  1176. if (pWin->optional || (CARD32) *pVlist) {
  1177. if (!pWin->optional && !MakeWindowOptional (pWin))
  1178. {
  1179. error = BadAlloc;
  1180. goto PatchUp;
  1181. }
  1182. pWin->optional->backingPixel = (CARD32) *pVlist;
  1183. if (!*pVlist)
  1184. checkOptional = TRUE;
  1185. }
  1186. pVlist++;
  1187. break;
  1188. case CWSaveUnder:
  1189. val = (BOOL) *pVlist;
  1190. pVlist++;
  1191. if ((val != xTrue) && (val != xFalse))
  1192. {
  1193. error = BadValue;
  1194. client->errorValue = val;
  1195. goto PatchUp;
  1196. }
  1197. #ifdef DO_SAVE_UNDERS
  1198. if (pWin->parent && (pWin->saveUnder != val) && (pWin->viewable) &&
  1199. DO_SAVE_UNDERS(pWin))
  1200. {
  1201. /*
  1202. * Re-check all siblings and inferiors for obscurity or
  1203. * exposition (hee hee).
  1204. */
  1205. if (pWin->saveUnder)
  1206. deltaSaveUndersViewable--;
  1207. else
  1208. deltaSaveUndersViewable++;
  1209. pWin->saveUnder = val;
  1210. if (pWin->firstChild)
  1211. {
  1212. pLayerWin = (*pScreen->GetLayerWindow)(pWin);
  1213. if ((*pScreen->ChangeSaveUnder)(pLayerWin->parent, pWin->nextSib))
  1214. (*pScreen->PostChangeSaveUnder)(pLayerWin->parent,
  1215. pWin->nextSib);
  1216. }
  1217. else
  1218. {
  1219. if ((*pScreen->ChangeSaveUnder)(pWin, pWin->nextSib))
  1220. (*pScreen->PostChangeSaveUnder)(pWin,
  1221. pWin->nextSib);
  1222. }
  1223. }
  1224. else
  1225. {
  1226. /* If we're changing the saveUnder attribute of the root
  1227. * window, all we do is set pWin->saveUnder so that
  1228. * GetWindowAttributes returns the right value. We don't
  1229. * do the "normal" save-under processing (as above).
  1230. * Hope that doesn't cause any problems.
  1231. */
  1232. pWin->saveUnder = val;
  1233. }
  1234. #else
  1235. pWin->saveUnder = val;
  1236. #endif /* DO_SAVE_UNDERS */
  1237. break;
  1238. case CWEventMask:
  1239. /*
  1240. * TODO: Some applications like java bean shell
  1241. * don' t work if they cannot monitor the root
  1242. * window for Structure Redirect events. However
  1243. * this doesn't seem to be the best solution, since
  1244. * also an X server with a window manager running,
  1245. * doesn't allow to monitor for those events, but
  1246. * the java bean shell works flawlessy on this
  1247. * server.
  1248. *
  1249. * if (nxagentCheckIllegalRootMonitoring(pWin, (Mask)*pVlist))
  1250. * {
  1251. * return BadAccess;
  1252. * }
  1253. */
  1254. result = EventSelectForWindow(pWin, client, (Mask )*pVlist);
  1255. if (result)
  1256. {
  1257. error = result;
  1258. goto PatchUp;
  1259. }
  1260. pVlist++;
  1261. break;
  1262. case CWDontPropagate:
  1263. result = EventSuppressForWindow(pWin, client, (Mask )*pVlist,
  1264. &checkOptional);
  1265. if (result)
  1266. {
  1267. error = result;
  1268. goto PatchUp;
  1269. }
  1270. pVlist++;
  1271. break;
  1272. case CWOverrideRedirect:
  1273. val = (BOOL ) *pVlist;
  1274. pVlist++;
  1275. if ((val != xTrue) && (val != xFalse))
  1276. {
  1277. error = BadValue;
  1278. client->errorValue = val;
  1279. goto PatchUp;
  1280. }
  1281. pWin->overrideRedirect = val;
  1282. break;
  1283. case CWColormap:
  1284. cmap = (Colormap) *pVlist;
  1285. pVlist++;
  1286. if (cmap == CopyFromParent)
  1287. {
  1288. #ifdef XAPPGROUP
  1289. Colormap ag_colormap;
  1290. ClientPtr win_owner;
  1291. /*
  1292. * win_owner == client for CreateWindow, other clients
  1293. * can ChangeWindowAttributes
  1294. */
  1295. win_owner = clients[CLIENT_ID(pWin->drawable.id)];
  1296. if ( win_owner && win_owner->appgroup &&
  1297. !pWin->parent->parent &&
  1298. (ag_colormap = XagDefaultColormap (win_owner)))
  1299. cmap = ag_colormap;
  1300. else
  1301. #endif
  1302. if (pWin->parent &&
  1303. (!pWin->optional ||
  1304. pWin->optional->visual == wVisual (pWin->parent)))
  1305. {
  1306. cmap = wColormap (pWin->parent);
  1307. }
  1308. else
  1309. cmap = None;
  1310. }
  1311. if (cmap == None)
  1312. {
  1313. error = BadMatch;
  1314. goto PatchUp;
  1315. }
  1316. pCmap = (ColormapPtr)SecurityLookupIDByType(client, cmap,
  1317. RT_COLORMAP, SecurityReadAccess);
  1318. if (!pCmap)
  1319. {
  1320. error = BadColor;
  1321. client->errorValue = cmap;
  1322. goto PatchUp;
  1323. }
  1324. if (pCmap->pVisual->vid != wVisual (pWin) ||
  1325. pCmap->pScreen != pScreen)
  1326. {
  1327. error = BadMatch;
  1328. goto PatchUp;
  1329. }
  1330. if (cmap != wColormap (pWin))
  1331. {
  1332. if (!pWin->optional)
  1333. {
  1334. if (!MakeWindowOptional (pWin))
  1335. {
  1336. error = BadAlloc;
  1337. goto PatchUp;
  1338. }
  1339. }
  1340. else if (pWin->parent && cmap == wColormap (pWin->parent))
  1341. checkOptional = TRUE;
  1342. /*
  1343. * propagate the original colormap to any children
  1344. * inheriting it
  1345. */
  1346. for (pChild = pWin->firstChild; pChild; pChild=pChild->nextSib)
  1347. {
  1348. if (!pChild->optional && !MakeWindowOptional (pChild))
  1349. {
  1350. error = BadAlloc;
  1351. goto PatchUp;
  1352. }
  1353. }
  1354. pWin->optional->colormap = cmap;
  1355. /*
  1356. * check on any children now matching the new colormap
  1357. */
  1358. for (pChild = pWin->firstChild; pChild; pChild=pChild->nextSib)
  1359. {
  1360. if (pChild->optional->colormap == cmap)
  1361. CheckWindowOptionalNeed (pChild);
  1362. }
  1363. xE.u.u.type = ColormapNotify;
  1364. xE.u.colormap.window = pWin->drawable.id;
  1365. xE.u.colormap.colormap = cmap;
  1366. xE.u.colormap.new = xTrue;
  1367. xE.u.colormap.state = IsMapInstalled(cmap, pWin);
  1368. DeliverEvents(pWin, &xE, 1, NullWindow);
  1369. }
  1370. break;
  1371. case CWCursor:
  1372. cursorID = (Cursor ) *pVlist;
  1373. pVlist++;
  1374. /*
  1375. * install the new
  1376. */
  1377. if ( cursorID == None)
  1378. {
  1379. if (pWin == WindowTable[pWin->drawable.pScreen->myNum])
  1380. pCursor = rootCursor;
  1381. else
  1382. pCursor = (CursorPtr) None;
  1383. }
  1384. else
  1385. {
  1386. pCursor = (CursorPtr)SecurityLookupIDByType(client, cursorID,
  1387. RT_CURSOR, SecurityReadAccess);
  1388. if (!pCursor)
  1389. {
  1390. error = BadCursor;
  1391. client->errorValue = cursorID;
  1392. goto PatchUp;
  1393. }
  1394. }
  1395. if (pCursor != wCursor (pWin))
  1396. {
  1397. /*
  1398. * patch up child windows so they don't lose cursors.
  1399. */
  1400. for (pChild = pWin->firstChild; pChild; pChild=pChild->nextSib)
  1401. {
  1402. if (!pChild->optional && !pChild->cursorIsNone &&
  1403. !MakeWindowOptional (pChild))
  1404. {
  1405. error = BadAlloc;
  1406. goto PatchUp;
  1407. }
  1408. }
  1409. pOldCursor = 0;
  1410. if (pCursor == (CursorPtr) None)
  1411. {
  1412. pWin->cursorIsNone = TRUE;
  1413. if (pWin->optional)
  1414. {
  1415. pOldCursor = pWin->optional->cursor;
  1416. pWin->optional->cursor = (CursorPtr) None;
  1417. checkOptional = TRUE;
  1418. }
  1419. } else {
  1420. if (!pWin->optional)
  1421. {
  1422. if (!MakeWindowOptional (pWin))
  1423. {
  1424. error = BadAlloc;
  1425. goto PatchUp;
  1426. }
  1427. }
  1428. else if (pWin->parent && pCursor == wCursor (pWin->parent))
  1429. checkOptional = TRUE;
  1430. pOldCursor = pWin->optional->cursor;
  1431. pWin->optional->cursor = pCursor;
  1432. pCursor->refcnt++;
  1433. pWin->cursorIsNone = FALSE;
  1434. /*
  1435. * check on any children now matching the new cursor
  1436. */
  1437. for (pChild=pWin->firstChild; pChild; pChild=pChild->nextSib)
  1438. {
  1439. if (pChild->optional &&
  1440. (pChild->optional->cursor == pCursor))
  1441. CheckWindowOptionalNeed (pChild);
  1442. }
  1443. }
  1444. if (pWin->realized)
  1445. WindowHasNewCursor( pWin);
  1446. /* Can't free cursor until here - old cursor
  1447. * is needed in WindowHasNewCursor
  1448. */
  1449. if (pOldCursor)
  1450. FreeCursor (pOldCursor, (Cursor)0);
  1451. }
  1452. break;
  1453. default:
  1454. error = BadValue;
  1455. client->errorValue = vmask;
  1456. goto PatchUp;
  1457. }
  1458. vmaskCopy |= index2;
  1459. }
  1460. PatchUp:
  1461. if (checkOptional)
  1462. CheckWindowOptionalNeed (pWin);
  1463. /* We SHOULD check for an error value here XXX */
  1464. (*pScreen->ChangeWindowAttributes)(pWin, vmaskCopy);
  1465. /*
  1466. If the border contents have changed, redraw the border.
  1467. Note that this has to be done AFTER pScreen->ChangeWindowAttributes
  1468. for the tile to be rotated, and the correct function selected.
  1469. */
  1470. if (((vmaskCopy & (CWBorderPixel | CWBorderPixmap)) || borderRelative)
  1471. && pWin->viewable && HasBorder (pWin))
  1472. {
  1473. RegionRec exposed;
  1474. REGION_INIT(pScreen, &exposed, NullBox, 0);
  1475. REGION_SUBTRACT(pScreen, &exposed, &pWin->borderClip, &pWin->winSize);
  1476. (*pWin->drawable.pScreen->PaintWindowBorder)(pWin, &exposed, PW_BORDER);
  1477. REGION_UNINIT(pScreen, &exposed);
  1478. }
  1479. return error;
  1480. }
  1481. /*****
  1482. * GetWindowAttributes
  1483. * Notice that this is different than ChangeWindowAttributes
  1484. *****/
  1485. void
  1486. GetWindowAttributes(pWin, client, wa)
  1487. register WindowPtr pWin;
  1488. ClientPtr client;
  1489. xGetWindowAttributesReply *wa;
  1490. {
  1491. wa->type = X_Reply;
  1492. wa->bitGravity = pWin->bitGravity;
  1493. wa->winGravity = pWin->winGravity;
  1494. if (pWin->forcedBS && pWin->backingStore != Always)
  1495. wa->backingStore = NotUseful;
  1496. else
  1497. wa->backingStore = pWin->backingStore;
  1498. wa->length = (sizeof(xGetWindowAttributesReply) -
  1499. sizeof(xGenericReply)) >> 2;
  1500. wa->sequenceNumber = client->sequence;
  1501. wa->backingBitPlanes = wBackingBitPlanes (pWin);
  1502. wa->backingPixel = wBackingPixel (pWin);
  1503. wa->saveUnder = (BOOL)pWin->saveUnder;
  1504. wa->override = pWin->overrideRedirect;
  1505. if (!pWin->mapped)
  1506. wa->mapState = IsUnmapped;
  1507. else if (pWin->realized)
  1508. wa->mapState = IsViewable;
  1509. else
  1510. wa->mapState = IsUnviewable;
  1511. wa->colormap = wColormap (pWin);
  1512. wa->mapInstalled = (wa->colormap == None) ? xFalse
  1513. : IsMapInstalled(wa->colormap, pWin);
  1514. wa->yourEventMask = EventMaskForClient(pWin, client);
  1515. wa->allEventMasks = pWin->eventMask | wOtherEventMasks (pWin);
  1516. wa->doNotPropagateMask = wDontPropagateMask (pWin);
  1517. wa->class = pWin->drawable.class;
  1518. wa->visualID = wVisual (pWin);
  1519. }
  1520. WindowPtr
  1521. MoveWindowInStack(pWin, pNextSib)
  1522. register WindowPtr pWin, pNextSib;
  1523. {
  1524. register WindowPtr pParent = pWin->parent;
  1525. WindowPtr pFirstChange = pWin; /* highest window where list changes */
  1526. if (pWin->nextSib != pNextSib)
  1527. {
  1528. WindowPtr pOldNextSib = pWin->nextSib;
  1529. if (!pNextSib) /* move to bottom */
  1530. {
  1531. if (pParent->firstChild == pWin)
  1532. pParent->firstChild = pWin->nextSib;
  1533. /* if (pWin->nextSib) */ /* is always True: pNextSib == NULL
  1534. * and pWin->nextSib != pNextSib
  1535. * therefore pWin->nextSib != NULL */
  1536. pFirstChange = pWin->nextSib;
  1537. pWin->nextSib->prevSib = pWin->prevSib;
  1538. if (pWin->prevSib)
  1539. pWin->prevSib->nextSib = pWin->nextSib;
  1540. pParent->lastChild->nextSib = pWin;
  1541. pWin->prevSib = pParent->lastChild;
  1542. pWin->nextSib = NullWindow;
  1543. pParent->lastChild = pWin;
  1544. }
  1545. else if (pParent->firstChild == pNextSib) /* move to top */
  1546. {
  1547. pFirstChange = pWin;
  1548. if (pParent->lastChild == pWin)
  1549. pParent->lastChild = pWin->prevSib;
  1550. if (pWin->nextSib)
  1551. pWin->nextSib->prevSib = pWin->prevSib;
  1552. if (pWin->prevSib)
  1553. pWin->prevSib->nextSib = pWin->nextSib;
  1554. pWin->nextSib = pParent->firstChild;
  1555. pWin->prevSib = (WindowPtr ) NULL;
  1556. pNextSib->prevSib = pWin;
  1557. pParent->firstChild = pWin;
  1558. }
  1559. else /* move in middle of list */
  1560. {
  1561. WindowPtr pOldNext = pWin->nextSib;
  1562. pFirstChange = NullWindow;
  1563. if (pParent->firstChild == pWin)
  1564. pFirstChange = pParent->firstChild = pWin->nextSib;
  1565. if (pParent->lastChild == pWin) {
  1566. pFirstChange = pWin;
  1567. pParent->lastChild = pWin->prevSib;
  1568. }
  1569. if (pWin->nextSib)
  1570. pWin->nextSib->prevSib = pWin->prevSib;
  1571. if (pWin->prevSib)
  1572. pWin->prevSib->nextSib = pWin->nextSib;
  1573. pWin->nextSib = pNextSib;
  1574. pWin->prevSib = pNextSib->prevSib;
  1575. if (pNextSib->prevSib)
  1576. pNextSib->prevSib->nextSib = pWin;
  1577. pNextSib->prevSib = pWin;
  1578. if (!pFirstChange) { /* do we know it yet? */
  1579. pFirstChange = pParent->firstChild; /* no, search from top */
  1580. while ((pFirstChange != pWin) && (pFirstChange != pOldNext))
  1581. pFirstChange = pFirstChange->nextSib;
  1582. }
  1583. }
  1584. if(pWin->drawable.pScreen->RestackWindow)
  1585. (*pWin->drawable.pScreen->RestackWindow)(pWin, pOldNextSib);
  1586. }
  1587. return( pFirstChange );
  1588. }
  1589. RegionPtr
  1590. CreateUnclippedWinSize (pWin)
  1591. register WindowPtr pWin;
  1592. {
  1593. RegionPtr pRgn;
  1594. BoxRec box;
  1595. box.x1 = pWin->drawable.x;
  1596. box.y1 = pWin->drawable.y;
  1597. box.x2 = pWin->drawable.x + (int) pWin->drawable.width;
  1598. box.y2 = pWin->drawable.y + (int) pWin->drawable.height;
  1599. pRgn = REGION_CREATE(pWin->drawable.pScreen, &box, 1);
  1600. #ifdef SHAPE
  1601. if (wBoundingShape (pWin) || wClipShape (pWin)) {
  1602. REGION_PTR(pScreen, pWin)
  1603. REGION_TRANSLATE(pScreen, pRgn, - pWin->drawable.x,
  1604. - pWin->drawable.y);
  1605. if (wBoundingShape (pWin))
  1606. REGION_INTERSECT(pScreen, pRgn, pRgn, wBoundingShape (pWin));
  1607. if (wClipShape (pWin))
  1608. REGION_INTERSECT(pScreen, pRgn, pRgn, wClipShape (pWin));
  1609. REGION_TRANSLATE(pScreen, pRgn, pWin->drawable.x, pWin->drawable.y);
  1610. }
  1611. #endif
  1612. return pRgn;
  1613. }
  1614. void
  1615. SetWinSize (pWin)
  1616. register WindowPtr pWin;
  1617. {
  1618. ClippedRegionFromBox(pWin->parent, &pWin->winSize,
  1619. pWin->drawable.x, pWin->drawable.y,
  1620. (int)pWin->drawable.width,
  1621. (int)pWin->drawable.height);
  1622. #ifdef SHAPE
  1623. if (wBoundingShape (pWin) || wClipShape (pWin)) {
  1624. REGION_PTR(pScreen, pWin)
  1625. REGION_TRANSLATE(pScreen, &pWin->winSize, - pWin->drawable.x,
  1626. - pWin->drawable.y);
  1627. if (wBoundingShape (pWin))
  1628. REGION_INTERSECT(pScreen, &pWin->winSize, &pWin->winSize,
  1629. wBoundingShape (pWin));
  1630. if (wClipShape (pWin))
  1631. REGION_INTERSECT(pScreen, &pWin->winSize, &pWin->winSize,
  1632. wClipShape (pWin));
  1633. REGION_TRANSLATE(pScreen, &pWin->winSize, pWin->drawable.x,
  1634. pWin->drawable.y);
  1635. }
  1636. #endif
  1637. }
  1638. void
  1639. SetBorderSize (pWin)
  1640. register WindowPtr pWin;
  1641. {
  1642. int bw;
  1643. if (HasBorder (pWin)) {
  1644. bw = wBorderWidth (pWin);
  1645. ClippedRegionFromBox(pWin->parent, &pWin->borderSize,
  1646. pWin->drawable.x - bw, pWin->drawable.y - bw,
  1647. (int)(pWin->drawable.width + (bw<<1)),
  1648. (int)(pWin->drawable.height + (bw<<1)));
  1649. #ifdef SHAPE
  1650. if (wBoundingShape (pWin)) {
  1651. REGION_PTR(pScreen, pWin)
  1652. REGION_TRANSLATE(pScreen, &pWin->borderSize, - pWin->drawable.x,
  1653. - pWin->drawable.y);
  1654. REGION_INTERSECT(pScreen, &pWin->borderSize, &pWin->borderSize,
  1655. wBoundingShape (pWin));
  1656. REGION_TRANSLATE(pScreen, &pWin->borderSize, pWin->drawable.x,
  1657. pWin->drawable.y);
  1658. REGION_UNION(pScreen, &pWin->borderSize, &pWin->borderSize,
  1659. &pWin->winSize);
  1660. }
  1661. #endif
  1662. } else {
  1663. REGION_COPY(pWin->drawable.pScreen, &pWin->borderSize,
  1664. &pWin->winSize);
  1665. }
  1666. }
  1667. void
  1668. GravityTranslate (x, y, oldx, oldy, dw, dh, gravity, destx, desty)
  1669. register int x, y; /* new window position */
  1670. int oldx, oldy; /* old window position */
  1671. int dw, dh;
  1672. unsigned gravity;
  1673. register int *destx, *desty; /* position relative to gravity */
  1674. {
  1675. switch (gravity) {
  1676. case NorthGravity:
  1677. *destx = x + dw / 2;
  1678. *desty = y;
  1679. break;
  1680. case NorthEastGravity:
  1681. *destx = x + dw;
  1682. *desty = y;
  1683. break;
  1684. case WestGravity:
  1685. *destx = x;
  1686. *desty = y + dh / 2;
  1687. break;
  1688. case CenterGravity:
  1689. *destx = x + dw / 2;
  1690. *desty = y + dh / 2;
  1691. break;
  1692. case EastGravity:
  1693. *dest

Large files files are truncated, but you can click here to view the full file