PageRenderTime 58ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 1ms

/nx-3.5.0/nx-X11/programs/Xserver/hw/nxagent/X/NXwindow.c

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

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