miwindow.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851
  1. /***********************************************************
  2. Copyright 1987, 1998 The Open Group
  3. Permission to use, copy, modify, distribute, and sell this software and its
  4. documentation for any purpose is hereby granted without fee, provided that
  5. the above copyright notice appear in all copies and that both that
  6. copyright notice and this permission notice appear in supporting
  7. documentation.
  8. The above copyright notice and this permission notice shall be included in
  9. all copies or substantial portions of the Software.
  10. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  11. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  12. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  13. OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  14. AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  15. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  16. Except as contained in this notice, the name of The Open Group shall not be
  17. used in advertising or otherwise to promote the sale, use or other dealings
  18. in this Software without prior written authorization from The Open Group.
  19. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
  20. All Rights Reserved
  21. Permission to use, copy, modify, and distribute this software and its
  22. documentation for any purpose and without fee is hereby granted,
  23. provided that the above copyright notice appear in all copies and that
  24. both that copyright notice and this permission notice appear in
  25. supporting documentation, and that the name of Digital not be
  26. used in advertising or publicity pertaining to distribution of the
  27. software without specific, written prior permission.
  28. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  29. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  30. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  31. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  32. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  33. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  34. SOFTWARE.
  35. ******************************************************************/
  36. #ifdef HAVE_DIX_CONFIG_H
  37. #include <dix-config.h>
  38. #endif
  39. #include <X11/X.h>
  40. #include "regionstr.h"
  41. #include "region.h"
  42. #include "mi.h"
  43. #include "windowstr.h"
  44. #include "scrnintstr.h"
  45. #include "pixmapstr.h"
  46. #include "mivalidate.h"
  47. _X_EXPORT void
  48. miClearToBackground(pWin, x, y, w, h, generateExposures)
  49. WindowPtr pWin;
  50. int x,y;
  51. int w,h;
  52. Bool generateExposures;
  53. {
  54. BoxRec box;
  55. RegionRec reg;
  56. RegionPtr pBSReg = NullRegion;
  57. ScreenPtr pScreen;
  58. BoxPtr extents;
  59. int x1, y1, x2, y2;
  60. /* compute everything using ints to avoid overflow */
  61. x1 = pWin->drawable.x + x;
  62. y1 = pWin->drawable.y + y;
  63. if (w)
  64. x2 = x1 + (int) w;
  65. else
  66. x2 = x1 + (int) pWin->drawable.width - (int) x;
  67. if (h)
  68. y2 = y1 + h;
  69. else
  70. y2 = y1 + (int) pWin->drawable.height - (int) y;
  71. extents = &pWin->clipList.extents;
  72. /* clip the resulting rectangle to the window clipList extents. This
  73. * makes sure that the result will fit in a box, given that the
  74. * screen is < 32768 on a side.
  75. */
  76. if (x1 < extents->x1)
  77. x1 = extents->x1;
  78. if (x2 > extents->x2)
  79. x2 = extents->x2;
  80. if (y1 < extents->y1)
  81. y1 = extents->y1;
  82. if (y2 > extents->y2)
  83. y2 = extents->y2;
  84. if (x2 <= x1 || y2 <= y1)
  85. {
  86. x2 = x1 = 0;
  87. y2 = y1 = 0;
  88. }
  89. box.x1 = x1;
  90. box.x2 = x2;
  91. box.y1 = y1;
  92. box.y2 = y2;
  93. pScreen = pWin->drawable.pScreen;
  94. REGION_INIT(&reg, &box, 1);
  95. REGION_INTERSECT(&reg, &reg, &pWin->clipList);
  96. if (generateExposures)
  97. (*pScreen->WindowExposures)(pWin, &reg, pBSReg);
  98. else if (pWin->backgroundState != None)
  99. (*pScreen->PaintWindowBackground)(pWin, &reg, PW_BACKGROUND);
  100. REGION_UNINIT(&reg);
  101. if (pBSReg)
  102. REGION_DESTROY(pBSReg);
  103. }
  104. void
  105. miMarkWindow(pWin)
  106. WindowPtr pWin;
  107. {
  108. ValidatePtr val;
  109. if (pWin->valdata)
  110. return;
  111. val = (ValidatePtr)malloc(sizeof(ValidateRec));
  112. val->before.oldAbsCorner.x = pWin->drawable.x;
  113. val->before.oldAbsCorner.y = pWin->drawable.y;
  114. val->before.borderVisible = NullRegion;
  115. val->before.resized = FALSE;
  116. pWin->valdata = val;
  117. }
  118. Bool
  119. miMarkOverlappedWindows(pWin, pFirst, ppLayerWin)
  120. WindowPtr pWin;
  121. WindowPtr pFirst;
  122. WindowPtr *ppLayerWin;
  123. {
  124. BoxPtr box;
  125. WindowPtr pChild, pLast;
  126. Bool anyMarked = FALSE;
  127. MarkWindowProcPtr MarkWindow = pWin->drawable.pScreen->MarkWindow;
  128. /* single layered systems are easy */
  129. if (ppLayerWin) *ppLayerWin = pWin;
  130. if (pWin == pFirst)
  131. {
  132. /* Blindly mark pWin and all of its inferiors. This is a slight
  133. * overkill if there are mapped windows that outside pWin's border,
  134. * but it's better than wasting time on RectIn checks.
  135. */
  136. pChild = pWin;
  137. while (1)
  138. {
  139. if (pChild->viewable)
  140. {
  141. if (REGION_BROKEN(&pChild->winSize))
  142. SetWinSize (pChild);
  143. if (REGION_BROKEN(&pChild->borderSize))
  144. SetBorderSize (pChild);
  145. (* MarkWindow)(pChild);
  146. if (pChild->firstChild)
  147. {
  148. pChild = pChild->firstChild;
  149. continue;
  150. }
  151. }
  152. while (!pChild->nextSib && (pChild != pWin))
  153. pChild = pChild->parent;
  154. if (pChild == pWin)
  155. break;
  156. pChild = pChild->nextSib;
  157. }
  158. anyMarked = TRUE;
  159. pFirst = pFirst->nextSib;
  160. }
  161. if ( (pChild = pFirst) )
  162. {
  163. box = REGION_EXTENTS(&pWin->borderSize);
  164. pLast = pChild->parent->lastChild;
  165. while (1)
  166. {
  167. if (pChild->viewable)
  168. {
  169. if (REGION_BROKEN(&pChild->winSize))
  170. SetWinSize (pChild);
  171. if (REGION_BROKEN(&pChild->borderSize))
  172. SetBorderSize (pChild);
  173. if (RECT_IN_REGION(&pChild->borderSize, box))
  174. {
  175. (* MarkWindow)(pChild);
  176. anyMarked = TRUE;
  177. if (pChild->firstChild)
  178. {
  179. pChild = pChild->firstChild;
  180. continue;
  181. }
  182. }
  183. }
  184. while (!pChild->nextSib && (pChild != pLast))
  185. pChild = pChild->parent;
  186. if (pChild == pLast)
  187. break;
  188. pChild = pChild->nextSib;
  189. }
  190. }
  191. if (anyMarked)
  192. (* MarkWindow)(pWin->parent);
  193. return anyMarked;
  194. }
  195. /*****
  196. * miHandleValidateExposures(pWin)
  197. * starting at pWin, draw background in any windows that have exposure
  198. * regions, translate the regions, restore any backing store,
  199. * and then send any regions still exposed to the client
  200. *****/
  201. _X_EXPORT void
  202. miHandleValidateExposures(pWin)
  203. WindowPtr pWin;
  204. {
  205. WindowPtr pChild;
  206. ValidatePtr val;
  207. WindowExposuresProcPtr WindowExposures;
  208. pChild = pWin;
  209. WindowExposures = pChild->drawable.pScreen->WindowExposures;
  210. while (1)
  211. {
  212. if ( (val = pChild->valdata) )
  213. {
  214. if (REGION_NOTEMPTY(&val->after.borderExposed))
  215. (*pChild->drawable.pScreen->PaintWindowBorder)(pChild,
  216. &val->after.borderExposed,
  217. PW_BORDER);
  218. REGION_UNINIT(&val->after.borderExposed);
  219. (*WindowExposures)(pChild, &val->after.exposed, NullRegion);
  220. REGION_UNINIT(&val->after.exposed);
  221. free(val);
  222. pChild->valdata = (ValidatePtr)NULL;
  223. if (pChild->firstChild)
  224. {
  225. pChild = pChild->firstChild;
  226. continue;
  227. }
  228. }
  229. while (!pChild->nextSib && (pChild != pWin))
  230. pChild = pChild->parent;
  231. if (pChild == pWin)
  232. break;
  233. pChild = pChild->nextSib;
  234. }
  235. }
  236. void
  237. miMoveWindow(pWin, x, y, pNextSib, kind)
  238. WindowPtr pWin;
  239. int x,y;
  240. WindowPtr pNextSib;
  241. VTKind kind;
  242. {
  243. WindowPtr pParent;
  244. Bool WasViewable = (Bool)(pWin->viewable);
  245. short bw;
  246. RegionPtr oldRegion = NULL;
  247. DDXPointRec oldpt;
  248. Bool anyMarked = FALSE;
  249. ScreenPtr pScreen;
  250. WindowPtr windowToValidate;
  251. WindowPtr pLayerWin;
  252. /* if this is a root window, can't be moved */
  253. if (!(pParent = pWin->parent))
  254. return ;
  255. pScreen = pWin->drawable.pScreen;
  256. bw = wBorderWidth (pWin);
  257. oldpt.x = pWin->drawable.x;
  258. oldpt.y = pWin->drawable.y;
  259. if (WasViewable)
  260. {
  261. oldRegion = REGION_CREATE(NullBox, 1);
  262. REGION_COPY(oldRegion, &pWin->borderClip);
  263. anyMarked = (*pScreen->MarkOverlappedWindows)(pWin, pWin, &pLayerWin);
  264. }
  265. pWin->origin.x = x + (int)bw;
  266. pWin->origin.y = y + (int)bw;
  267. x = pWin->drawable.x = pParent->drawable.x + x + (int)bw;
  268. y = pWin->drawable.y = pParent->drawable.y + y + (int)bw;
  269. SetWinSize (pWin);
  270. SetBorderSize (pWin);
  271. (*pScreen->PositionWindow)(pWin, x, y);
  272. windowToValidate = MoveWindowInStack(pWin, pNextSib);
  273. ResizeChildrenWinSize(pWin, x - oldpt.x, y - oldpt.y, 0, 0);
  274. if (WasViewable)
  275. {
  276. if (pLayerWin == pWin)
  277. anyMarked |= (*pScreen->MarkOverlappedWindows)
  278. (pWin, windowToValidate, (WindowPtr *)NULL);
  279. else
  280. anyMarked |= (*pScreen->MarkOverlappedWindows)
  281. (pWin, pLayerWin, (WindowPtr *)NULL);
  282. if (anyMarked)
  283. {
  284. (*pScreen->ValidateTree)(pLayerWin->parent, NullWindow, kind);
  285. (* pWin->drawable.pScreen->CopyWindow)(pWin, oldpt, oldRegion);
  286. REGION_DESTROY(oldRegion);
  287. /* XXX need to retile border if ParentRelative origin */
  288. (*pScreen->HandleExposures)(pLayerWin->parent);
  289. }
  290. if (anyMarked && pScreen->PostValidateTree)
  291. (*pScreen->PostValidateTree)(pLayerWin->parent, NullWindow, kind);
  292. }
  293. if (pWin->realized)
  294. WindowsRestructured ();
  295. }
  296. /*
  297. * pValid is a region of the screen which has been
  298. * successfully copied -- recomputed exposed regions for affected windows
  299. */
  300. static int
  301. miRecomputeExposures (
  302. register WindowPtr pWin,
  303. pointer value) /* must conform to VisitWindowProcPtr */
  304. {
  305. RegionPtr pValid = (RegionPtr)value;
  306. if (pWin->valdata)
  307. {
  308. /*
  309. * compute exposed regions of this window
  310. */
  311. REGION_SUBTRACT(&pWin->valdata->after.exposed,
  312. &pWin->clipList, pValid);
  313. /*
  314. * compute exposed regions of the border
  315. */
  316. REGION_SUBTRACT(&pWin->valdata->after.borderExposed,
  317. &pWin->borderClip, &pWin->winSize);
  318. REGION_SUBTRACT(&pWin->valdata->after.borderExposed,
  319. &pWin->valdata->after.borderExposed, pValid);
  320. return WT_WALKCHILDREN;
  321. }
  322. return WT_NOMATCH;
  323. }
  324. void
  325. miSlideAndSizeWindow(pWin, x, y, w, h, pSib)
  326. WindowPtr pWin;
  327. int x,y;
  328. unsigned int w, h;
  329. WindowPtr pSib;
  330. {
  331. WindowPtr pParent;
  332. Bool WasViewable = (Bool)(pWin->viewable);
  333. unsigned short width = pWin->drawable.width,
  334. height = pWin->drawable.height;
  335. short oldx = pWin->drawable.x,
  336. oldy = pWin->drawable.y;
  337. int bw = wBorderWidth (pWin);
  338. short dw, dh;
  339. DDXPointRec oldpt;
  340. RegionPtr oldRegion = NULL;
  341. Bool anyMarked = FALSE;
  342. ScreenPtr pScreen;
  343. WindowPtr pFirstChange;
  344. WindowPtr pChild;
  345. RegionPtr gravitate[StaticGravity + 1];
  346. unsigned g;
  347. int nx, ny; /* destination x,y */
  348. int newx, newy; /* new inner window position */
  349. RegionPtr pRegion = NULL;
  350. RegionPtr destClip; /* portions of destination already written */
  351. RegionPtr oldWinClip = NULL; /* old clip list for window */
  352. RegionPtr borderVisible = NullRegion; /* visible area of the border */
  353. RegionPtr bsExposed = NullRegion; /* backing store exposures */
  354. Bool shrunk = FALSE; /* shrunk in an inner dimension */
  355. Bool moved = FALSE; /* window position changed */
  356. WindowPtr pLayerWin;
  357. /* if this is a root window, can't be resized */
  358. if (!(pParent = pWin->parent))
  359. return ;
  360. pScreen = pWin->drawable.pScreen;
  361. newx = pParent->drawable.x + x + bw;
  362. newy = pParent->drawable.y + y + bw;
  363. if (WasViewable)
  364. {
  365. anyMarked = FALSE;
  366. /*
  367. * save the visible region of the window
  368. */
  369. oldRegion = REGION_CREATE(NullBox, 1);
  370. REGION_COPY(oldRegion, &pWin->winSize);
  371. /*
  372. * categorize child windows into regions to be moved
  373. */
  374. for (g = 0; g <= StaticGravity; g++)
  375. gravitate[g] = (RegionPtr) NULL;
  376. for (pChild = pWin->firstChild; pChild; pChild = pChild->nextSib)
  377. {
  378. g = pChild->winGravity;
  379. if (g != UnmapGravity)
  380. {
  381. if (!gravitate[g])
  382. gravitate[g] = REGION_CREATE(NullBox, 1);
  383. REGION_UNION(gravitate[g],
  384. gravitate[g], &pChild->borderClip);
  385. }
  386. else
  387. {
  388. UnmapWindow(pChild, TRUE);
  389. anyMarked = TRUE;
  390. }
  391. }
  392. anyMarked |= (*pScreen->MarkOverlappedWindows)(pWin, pWin,
  393. &pLayerWin);
  394. oldWinClip = NULL;
  395. if (pWin->bitGravity != ForgetGravity)
  396. {
  397. oldWinClip = REGION_CREATE(NullBox, 1);
  398. REGION_COPY(oldWinClip, &pWin->clipList);
  399. }
  400. /*
  401. * if the window is changing size, borderExposed
  402. * can't be computed correctly without some help.
  403. */
  404. if (pWin->drawable.height > h || pWin->drawable.width > w)
  405. shrunk = TRUE;
  406. if (newx != oldx || newy != oldy)
  407. moved = TRUE;
  408. if ((pWin->drawable.height != h || pWin->drawable.width != w) &&
  409. HasBorder (pWin))
  410. {
  411. borderVisible = REGION_CREATE(NullBox, 1);
  412. /* for tiled borders, we punt and draw the whole thing */
  413. if (pWin->borderIsPixel || !moved)
  414. {
  415. if (shrunk || moved)
  416. REGION_SUBTRACT(borderVisible,
  417. &pWin->borderClip,
  418. &pWin->winSize);
  419. else
  420. REGION_COPY(borderVisible,
  421. &pWin->borderClip);
  422. }
  423. }
  424. }
  425. pWin->origin.x = x + bw;
  426. pWin->origin.y = y + bw;
  427. pWin->drawable.height = h;
  428. pWin->drawable.width = w;
  429. x = pWin->drawable.x = newx;
  430. y = pWin->drawable.y = newy;
  431. SetWinSize (pWin);
  432. SetBorderSize (pWin);
  433. dw = (int)w - (int)width;
  434. dh = (int)h - (int)height;
  435. ResizeChildrenWinSize(pWin, x - oldx, y - oldy, dw, dh);
  436. /* let the hardware adjust background and border pixmaps, if any */
  437. (*pScreen->PositionWindow)(pWin, x, y);
  438. pFirstChange = MoveWindowInStack(pWin, pSib);
  439. if (WasViewable)
  440. {
  441. pRegion = REGION_CREATE(NullBox, 1);
  442. if (pLayerWin == pWin)
  443. anyMarked |= (*pScreen->MarkOverlappedWindows)(pWin, pFirstChange,
  444. (WindowPtr *)NULL);
  445. else
  446. anyMarked |= (*pScreen->MarkOverlappedWindows)(pWin, pLayerWin,
  447. (WindowPtr *)NULL);
  448. if (pWin->valdata)
  449. {
  450. pWin->valdata->before.resized = TRUE;
  451. pWin->valdata->before.borderVisible = borderVisible;
  452. }
  453. if (anyMarked)
  454. (*pScreen->ValidateTree)(pLayerWin->parent, pFirstChange, VTOther);
  455. /*
  456. * the entire window is trashed unless bitGravity
  457. * recovers portions of it
  458. */
  459. REGION_COPY(&pWin->valdata->after.exposed, &pWin->clipList);
  460. }
  461. GravityTranslate (x, y, oldx, oldy, dw, dh, pWin->bitGravity, &nx, &ny);
  462. if (WasViewable)
  463. {
  464. /* avoid the border */
  465. if (HasBorder (pWin))
  466. {
  467. int offx, offy, dx, dy;
  468. /* kruft to avoid double translates for each gravity */
  469. offx = 0;
  470. offy = 0;
  471. for (g = 0; g <= StaticGravity; g++)
  472. {
  473. if (!gravitate[g])
  474. continue;
  475. /* align winSize to gravitate[g].
  476. * winSize is in new coordinates,
  477. * gravitate[g] is still in old coordinates */
  478. GravityTranslate (x, y, oldx, oldy, dw, dh, g, &nx, &ny);
  479. dx = (oldx - nx) - offx;
  480. dy = (oldy - ny) - offy;
  481. if (dx || dy)
  482. {
  483. REGION_TRANSLATE(&pWin->winSize, dx, dy);
  484. offx += dx;
  485. offy += dy;
  486. }
  487. REGION_INTERSECT(gravitate[g], gravitate[g],
  488. &pWin->winSize);
  489. }
  490. /* get winSize back where it belongs */
  491. if (offx || offy)
  492. REGION_TRANSLATE(&pWin->winSize, -offx, -offy);
  493. }
  494. /*
  495. * add screen bits to the appropriate bucket
  496. */
  497. if (oldWinClip)
  498. {
  499. /*
  500. * clip to new clipList
  501. */
  502. REGION_COPY(pRegion, oldWinClip);
  503. REGION_TRANSLATE(pRegion, nx - oldx, ny - oldy);
  504. REGION_INTERSECT(oldWinClip, pRegion, &pWin->clipList);
  505. /*
  506. * don't step on any gravity bits which will be copied after this
  507. * region. Note -- this assumes that the regions will be copied
  508. * in gravity order.
  509. */
  510. for (g = pWin->bitGravity + 1; g <= StaticGravity; g++)
  511. {
  512. if (gravitate[g])
  513. REGION_SUBTRACT(oldWinClip, oldWinClip,
  514. gravitate[g]);
  515. }
  516. REGION_TRANSLATE(oldWinClip, oldx - nx, oldy - ny);
  517. g = pWin->bitGravity;
  518. if (!gravitate[g])
  519. gravitate[g] = oldWinClip;
  520. else
  521. {
  522. REGION_UNION(gravitate[g], gravitate[g], oldWinClip);
  523. REGION_DESTROY(oldWinClip);
  524. }
  525. }
  526. /*
  527. * move the bits on the screen
  528. */
  529. destClip = NULL;
  530. for (g = 0; g <= StaticGravity; g++)
  531. {
  532. if (!gravitate[g])
  533. continue;
  534. GravityTranslate (x, y, oldx, oldy, dw, dh, g, &nx, &ny);
  535. oldpt.x = oldx + (x - nx);
  536. oldpt.y = oldy + (y - ny);
  537. /* Note that gravitate[g] is *translated* by CopyWindow */
  538. /* only copy the remaining useful bits */
  539. REGION_INTERSECT(gravitate[g], gravitate[g], oldRegion);
  540. /* clip to not overwrite already copied areas */
  541. if (destClip) {
  542. REGION_TRANSLATE(destClip, oldpt.x - x, oldpt.y - y);
  543. REGION_SUBTRACT(gravitate[g], gravitate[g], destClip);
  544. REGION_TRANSLATE(destClip, x - oldpt.x, y - oldpt.y);
  545. }
  546. /* and move those bits */
  547. if (oldpt.x != x || oldpt.y != y
  548. )
  549. {
  550. (*pWin->drawable.pScreen->CopyWindow)(pWin, oldpt, gravitate[g]);
  551. }
  552. /* remove any overwritten bits from the remaining useful bits */
  553. REGION_SUBTRACT(oldRegion, oldRegion, gravitate[g]);
  554. /*
  555. * recompute exposed regions of child windows
  556. */
  557. for (pChild = pWin->firstChild; pChild; pChild = pChild->nextSib)
  558. {
  559. if (pChild->winGravity != g)
  560. continue;
  561. REGION_INTERSECT(pRegion,
  562. &pChild->borderClip, gravitate[g]);
  563. TraverseTree (pChild, miRecomputeExposures, (pointer)pRegion);
  564. }
  565. /*
  566. * remove the successfully copied regions of the
  567. * window from its exposed region
  568. */
  569. if (g == pWin->bitGravity)
  570. REGION_SUBTRACT(&pWin->valdata->after.exposed,
  571. &pWin->valdata->after.exposed, gravitate[g]);
  572. if (!destClip)
  573. destClip = gravitate[g];
  574. else
  575. {
  576. REGION_UNION(destClip, destClip, gravitate[g]);
  577. REGION_DESTROY(gravitate[g]);
  578. }
  579. }
  580. REGION_DESTROY(oldRegion);
  581. REGION_DESTROY(pRegion);
  582. if (destClip)
  583. REGION_DESTROY(destClip);
  584. if (bsExposed)
  585. {
  586. RegionPtr valExposed = NullRegion;
  587. if (pWin->valdata)
  588. valExposed = &pWin->valdata->after.exposed;
  589. (*pScreen->WindowExposures) (pWin, valExposed, bsExposed);
  590. if (valExposed)
  591. REGION_EMPTY(valExposed);
  592. REGION_DESTROY(bsExposed);
  593. }
  594. if (anyMarked)
  595. (*pScreen->HandleExposures)(pLayerWin->parent);
  596. if (anyMarked && pScreen->PostValidateTree)
  597. (*pScreen->PostValidateTree)(pLayerWin->parent, pFirstChange,
  598. VTOther);
  599. }
  600. else if (bsExposed)
  601. {
  602. (*pScreen->WindowExposures) (pWin, NullRegion, bsExposed);
  603. REGION_DESTROY(bsExposed);
  604. }
  605. if (pWin->realized)
  606. WindowsRestructured ();
  607. }
  608. WindowPtr
  609. miGetLayerWindow(pWin)
  610. WindowPtr pWin;
  611. {
  612. return pWin->firstChild;
  613. }
  614. /******
  615. *
  616. * miSetShape
  617. * The border/window shape has changed. Recompute winSize/borderSize
  618. * and send appropriate exposure events
  619. */
  620. _X_EXPORT void
  621. miSetShape(pWin)
  622. WindowPtr pWin;
  623. {
  624. Bool WasViewable = (Bool)(pWin->viewable);
  625. ScreenPtr pScreen = pWin->drawable.pScreen;
  626. Bool anyMarked = FALSE;
  627. WindowPtr pLayerWin;
  628. if (WasViewable)
  629. {
  630. anyMarked = (*pScreen->MarkOverlappedWindows)(pWin, pWin,
  631. &pLayerWin);
  632. if (pWin->valdata)
  633. {
  634. if (HasBorder (pWin))
  635. {
  636. RegionPtr borderVisible;
  637. borderVisible = REGION_CREATE(NullBox, 1);
  638. REGION_SUBTRACT(borderVisible,
  639. &pWin->borderClip, &pWin->winSize);
  640. pWin->valdata->before.borderVisible = borderVisible;
  641. }
  642. pWin->valdata->before.resized = TRUE;
  643. }
  644. }
  645. SetWinSize (pWin);
  646. SetBorderSize (pWin);
  647. ResizeChildrenWinSize(pWin, 0, 0, 0, 0);
  648. if (WasViewable)
  649. {
  650. anyMarked |= (*pScreen->MarkOverlappedWindows)(pWin, pWin,
  651. (WindowPtr *)NULL);
  652. if (anyMarked)
  653. (*pScreen->ValidateTree)(pLayerWin->parent, NullWindow, VTOther);
  654. }
  655. if (WasViewable)
  656. {
  657. if (anyMarked)
  658. (*pScreen->HandleExposures)(pLayerWin->parent);
  659. if (anyMarked && pScreen->PostValidateTree)
  660. (*pScreen->PostValidateTree)(pLayerWin->parent, NullWindow, VTOther);
  661. }
  662. if (pWin->realized)
  663. WindowsRestructured ();
  664. CheckCursorConfinement(pWin);
  665. }
  666. /* Keeps the same inside(!) origin */
  667. _X_EXPORT void
  668. miChangeBorderWidth(pWin, width)
  669. WindowPtr pWin;
  670. unsigned int width;
  671. {
  672. int oldwidth;
  673. Bool anyMarked = FALSE;
  674. ScreenPtr pScreen;
  675. Bool WasViewable = (Bool)(pWin->viewable);
  676. Bool HadBorder;
  677. WindowPtr pLayerWin;
  678. oldwidth = wBorderWidth (pWin);
  679. if (oldwidth == width)
  680. return;
  681. HadBorder = HasBorder(pWin);
  682. pScreen = pWin->drawable.pScreen;
  683. if (WasViewable && width < oldwidth)
  684. anyMarked = (*pScreen->MarkOverlappedWindows)(pWin, pWin, &pLayerWin);
  685. pWin->borderWidth = width;
  686. SetBorderSize (pWin);
  687. if (WasViewable)
  688. {
  689. if (width > oldwidth)
  690. {
  691. anyMarked = (*pScreen->MarkOverlappedWindows)(pWin, pWin,
  692. &pLayerWin);
  693. /*
  694. * save the old border visible region to correctly compute
  695. * borderExposed.
  696. */
  697. if (pWin->valdata && HadBorder)
  698. {
  699. RegionPtr borderVisible;
  700. borderVisible = REGION_CREATE(NULL, 1);
  701. REGION_SUBTRACT(borderVisible,
  702. &pWin->borderClip, &pWin->winSize);
  703. pWin->valdata->before.borderVisible = borderVisible;
  704. }
  705. }
  706. if (anyMarked)
  707. {
  708. (*pScreen->ValidateTree)(pLayerWin->parent, pLayerWin, VTOther);
  709. (*pScreen->HandleExposures)(pLayerWin->parent);
  710. }
  711. if (anyMarked && pScreen->PostValidateTree)
  712. (*pScreen->PostValidateTree)(pLayerWin->parent, pLayerWin,
  713. VTOther);
  714. }
  715. if (pWin->realized)
  716. WindowsRestructured ();
  717. }
  718. void
  719. miMarkUnrealizedWindow(pChild, pWin, fromConfigure)
  720. WindowPtr pChild;
  721. WindowPtr pWin;
  722. Bool fromConfigure;
  723. {
  724. if ((pChild != pWin) || fromConfigure)
  725. {
  726. REGION_EMPTY(&pChild->clipList);
  727. if (pChild->drawable.pScreen->ClipNotify)
  728. (* pChild->drawable.pScreen->ClipNotify)(pChild, 0, 0);
  729. REGION_EMPTY(&pChild->borderClip);
  730. }
  731. }
  732. _X_EXPORT void
  733. miSegregateChildren(WindowPtr pWin, RegionPtr pReg, int depth)
  734. {
  735. WindowPtr pChild;
  736. for (pChild = pWin->firstChild; pChild; pChild = pChild->nextSib)
  737. {
  738. if (pChild->drawable.depth == depth)
  739. REGION_UNION(pReg, pReg, &pChild->borderClip);
  740. if (pChild->firstChild)
  741. miSegregateChildren(pChild, pReg, depth);
  742. }
  743. }