3 * Functions for recalculating window clip lists. Main function
7 Copyright 1987, 1988, 1989, 1998 The Open Group
9 Permission to use, copy, modify, distribute, and sell this software and its
10 documentation for any purpose is hereby granted without fee, provided that
11 the above copyright notice appear in all copies and that both that
12 copyright notice and this permission notice appear in supporting
15 The above copyright notice and this permission notice shall be included in
16 all copies or substantial portions of the Software.
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 Except as contained in this notice, the name of The Open Group shall not be
26 used in advertising or otherwise to promote the sale, use or other dealings
27 in this Software without prior written authorization from The Open Group.
30 * Copyright 1987, 1988, 1989 by
31 * Digital Equipment Corporation, Maynard, Massachusetts,
35 * Permission to use, copy, modify, and distribute this software and its
36 * documentation for any purpose and without fee is hereby granted,
37 * provided that the above copyright notice appear in all copies and that
38 * both that copyright notice and this permission notice appear in
39 * supporting documentation, and that the name of Digital not be
40 * used in advertising or publicity pertaining to distribution of the
41 * software without specific, written prior permission.
43 * DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
44 * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
45 * DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
46 * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
47 * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
48 * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
51 ******************************************************************/
53 /* The panoramix components contained the following notice */
54 /*****************************************************************
56 Copyright (c) 1991, 1997 Digital Equipment Corporation, Maynard, Massachusetts.
58 Permission is hereby granted, free of charge, to any person obtaining a copy
59 of this software and associated documentation files (the "Software"), to deal
60 in the Software without restriction, including without limitation the rights
61 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
62 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.
67 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
68 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
69 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
70 DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR ANY CLAIM, DAMAGES, INCLUDING,
71 BUT NOT LIMITED TO CONSEQUENTIAL OR INCIDENTAL DAMAGES, OR OTHER LIABILITY,
72 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
73 IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
75 Except as contained in this notice, the name of Digital Equipment Corporation
76 shall not be used in advertising or otherwise to promote the sale, use or other
77 dealings in this Software without prior written authorization from Digital
78 Equipment Corporation.
80 ******************************************************************/
83 * Aug '86: Susan Angebranndt -- original code
84 * July '87: Adam de Boor -- substantially modified and commented
85 * Summer '89: Joel McCormack -- so fast you wouldn't believe it possible.
86 * In particular, much improved code for window mapping and
88 * Bob Scheifler -- avoid miComputeClips for unmapped windows,
91 #ifdef HAVE_DIX_CONFIG_H
92 #include <dix-config.h>
96 #include "scrnintstr.h"
98 #include "windowstr.h"
100 #include "regionstr.h"
101 #include "mivalidate.h"
106 * Compute the visibility of a shaped window
109 miShapedWindowIn(RegionPtr universe
, RegionPtr bounding
,
110 BoxPtr rect
, int x
, int y
)
115 Bool someIn
, someOut
;
116 int t
, x1
, y1
, x2
, y2
;
118 nbox
= RegionNumRects(bounding
);
119 boundBox
= RegionRects(bounding
);
120 someIn
= someOut
= FALSE
;
126 if ((t
= boundBox
->x1
+ x
) < x1
)
129 if ((t
= boundBox
->y1
+ y
) < y1
)
132 if ((t
= boundBox
->x2
+ x
) > x2
)
135 if ((t
= boundBox
->y2
+ y
) > y2
)
142 switch (RegionContainsRect(universe
, &box
)) {
163 static GetRedirectBorderClipProcPtr miGetRedirectBorderClipProc
;
164 static SetRedirectBorderClipProcPtr miSetRedirectBorderClipProc
;
167 miRegisterRedirectBorderClipProc(SetRedirectBorderClipProcPtr setBorderClip
,
168 GetRedirectBorderClipProcPtr getBorderClip
)
170 miSetRedirectBorderClipProc
= setBorderClip
;
171 miGetRedirectBorderClipProc
= getBorderClip
;
175 * Manual redirected windows are treated as transparent; they do not obscure
176 * siblings or parent windows
180 #define TreatAsTransparent(w) ((w)->redirectDraw == RedirectDrawManual)
182 #define TreatAsTransparent(w) FALSE
185 #define HasParentRelativeBorder(w) (!(w)->borderIsPixel && \
187 (w)->backgroundState == ParentRelative)
190 *-----------------------------------------------------------------------
192 * Recompute the clipList, borderClip, exposed and borderExposed
193 * regions for pParent and its children. Only viewable windows are
194 * taken into account.
200 * clipList, borderClip, exposed and borderExposed are altered.
201 * A VisibilityNotify event may be generated on the parent window.
203 *-----------------------------------------------------------------------
206 miComputeClips(WindowPtr pParent
,
208 RegionPtr universe
, VTKind kind
, RegionPtr exposed
)
209 { /* for intermediate calculations */
211 RegionRec childUniverse
;
215 RegionRec childUnion
;
217 RegionPtr borderVisible
;
220 * Figure out the new visibility of this window.
221 * The extent of the universe should be the same as the extent of
222 * the borderSize region. If the window is unobscured, this rectangle
223 * will be completely inside the universe (the universe will cover it
224 * completely). If the window is completely obscured, none of the
225 * universe will cover the rectangle.
227 borderSize
.x1
= pParent
->drawable
.x
- wBorderWidth(pParent
);
228 borderSize
.y1
= pParent
->drawable
.y
- wBorderWidth(pParent
);
229 dx
= (int) pParent
->drawable
.x
+ (int) pParent
->drawable
.width
+
230 wBorderWidth(pParent
);
234 dy
= (int) pParent
->drawable
.y
+ (int) pParent
->drawable
.height
+
235 wBorderWidth(pParent
);
242 * In redirected drawing case, reset universe to borderSize
244 if (pParent
->redirectDraw
!= RedirectDrawNone
) {
245 if (miSetRedirectBorderClipProc
) {
246 if (TreatAsTransparent(pParent
))
247 RegionEmpty(universe
);
248 (*miSetRedirectBorderClipProc
) (pParent
, universe
);
250 RegionCopy(universe
, &pParent
->borderSize
);
254 oldVis
= pParent
->visibility
;
255 switch (RegionContainsRect(universe
, &borderSize
)) {
257 newVis
= VisibilityUnobscured
;
260 newVis
= VisibilityPartiallyObscured
;
264 if ((pBounding
= wBoundingShape(pParent
))) {
265 switch (miShapedWindowIn(universe
, pBounding
,
268 pParent
->drawable
.y
)) {
270 newVis
= VisibilityUnobscured
;
273 newVis
= VisibilityFullyObscured
;
280 newVis
= VisibilityFullyObscured
;
283 pParent
->visibility
= newVis
;
284 if (oldVis
!= newVis
&&
286 eventMask
| wOtherEventMasks(pParent
)) & VisibilityChangeMask
))
287 SendVisibilityNotify(pParent
);
289 dx
= pParent
->drawable
.x
- pParent
->valdata
->before
.oldAbsCorner
.x
;
290 dy
= pParent
->drawable
.y
- pParent
->valdata
->before
.oldAbsCorner
.y
;
293 * avoid computations when dealing with simple operations
302 if ((oldVis
== newVis
) &&
303 ((oldVis
== VisibilityFullyObscured
) ||
304 (oldVis
== VisibilityUnobscured
))) {
307 if (pChild
->viewable
) {
308 if (pChild
->visibility
!= VisibilityFullyObscured
) {
309 RegionTranslate(&pChild
->borderClip
, dx
, dy
);
310 RegionTranslate(&pChild
->clipList
, dx
, dy
);
311 pChild
->drawable
.serialNumber
= NEXT_SERIAL_NUMBER
;
312 if (pScreen
->ClipNotify
)
313 (*pScreen
->ClipNotify
) (pChild
, dx
, dy
);
316 if (pChild
->valdata
) {
317 RegionNull(&pChild
->valdata
->after
.borderExposed
);
318 if (HasParentRelativeBorder(pChild
)) {
319 RegionSubtract(&pChild
->valdata
->after
.
320 borderExposed
, &pChild
->borderClip
,
323 RegionNull(&pChild
->valdata
->after
.exposed
);
325 if (pChild
->firstChild
) {
326 pChild
= pChild
->firstChild
;
330 while (!pChild
->nextSib
&& (pChild
!= pParent
))
331 pChild
= pChild
->parent
;
332 if (pChild
== pParent
)
334 pChild
= pChild
->nextSib
;
341 * To calculate exposures correctly, we have to translate the old
342 * borderClip and clipList regions to the window's new location so there
343 * is a correspondence between pieces of the new and old clipping regions.
347 * We translate the old clipList because that will be exposed or copied
348 * if gravity is right.
350 RegionTranslate(&pParent
->borderClip
, dx
, dy
);
351 RegionTranslate(&pParent
->clipList
, dx
, dy
);
355 RegionEmpty(&pParent
->borderClip
);
356 RegionEmpty(&pParent
->clipList
);
360 borderVisible
= pParent
->valdata
->before
.borderVisible
;
361 RegionNull(&pParent
->valdata
->after
.borderExposed
);
362 RegionNull(&pParent
->valdata
->after
.exposed
);
365 * Since the borderClip must not be clipped by the children, we do
366 * the border exposure first...
368 * 'universe' is the window's borderClip. To figure the exposures, remove
369 * the area that used to be exposed from the new.
370 * This leaves a region of pieces that weren't exposed before.
373 if (HasBorder(pParent
)) {
376 * when the border changes shape, the old visible portions
377 * of the border will be saved by DIX in borderVisible --
378 * use that region and destroy it
380 RegionSubtract(exposed
, universe
, borderVisible
);
381 RegionDestroy(borderVisible
);
384 RegionSubtract(exposed
, universe
, &pParent
->borderClip
);
386 if (HasParentRelativeBorder(pParent
) && (dx
|| dy
))
387 RegionSubtract(&pParent
->valdata
->after
.borderExposed
,
388 universe
, &pParent
->winSize
);
390 RegionSubtract(&pParent
->valdata
->after
.borderExposed
,
391 exposed
, &pParent
->winSize
);
393 RegionCopy(&pParent
->borderClip
, universe
);
396 * To get the right clipList for the parent, and to make doubly sure
397 * that no child overlaps the parent's border, we remove the parent's
398 * border from the universe before proceeding.
401 RegionIntersect(universe
, universe
, &pParent
->winSize
);
404 RegionCopy(&pParent
->borderClip
, universe
);
406 if ((pChild
= pParent
->firstChild
) && pParent
->mapped
) {
407 RegionNull(&childUniverse
);
408 RegionNull(&childUnion
);
409 if ((pChild
->drawable
.y
< pParent
->lastChild
->drawable
.y
) ||
410 ((pChild
->drawable
.y
== pParent
->lastChild
->drawable
.y
) &&
411 (pChild
->drawable
.x
< pParent
->lastChild
->drawable
.x
))) {
412 for (; pChild
; pChild
= pChild
->nextSib
) {
413 if (pChild
->viewable
&& !TreatAsTransparent(pChild
))
414 RegionAppend(&childUnion
, &pChild
->borderSize
);
418 for (pChild
= pParent
->lastChild
; pChild
; pChild
= pChild
->prevSib
) {
419 if (pChild
->viewable
&& !TreatAsTransparent(pChild
))
420 RegionAppend(&childUnion
, &pChild
->borderSize
);
423 RegionValidate(&childUnion
, &overlap
);
425 for (pChild
= pParent
->firstChild
; pChild
; pChild
= pChild
->nextSib
) {
426 if (pChild
->viewable
) {
428 * If the child is viewable, we want to remove its extents
429 * from the current universe, but we only re-clip it if
432 if (pChild
->valdata
) {
434 * Figure out the new universe from the child's
435 * perspective and recurse.
437 RegionIntersect(&childUniverse
,
438 universe
, &pChild
->borderSize
);
439 miComputeClips(pChild
, pScreen
, &childUniverse
, kind
,
443 * Once the child has been processed, we remove its extents
444 * from the current universe, thus denying its space to any
447 if (overlap
&& !TreatAsTransparent(pChild
))
448 RegionSubtract(universe
, universe
, &pChild
->borderSize
);
452 RegionSubtract(universe
, universe
, &childUnion
);
453 RegionUninit(&childUnion
);
454 RegionUninit(&childUniverse
);
455 } /* if any children */
458 * 'universe' now contains the new clipList for the parent window.
460 * To figure the exposure of the window we subtract the old clip from the
461 * new, just as for the border.
464 if (oldVis
== VisibilityFullyObscured
|| oldVis
== VisibilityNotViewable
) {
465 RegionCopy(&pParent
->valdata
->after
.exposed
, universe
);
467 else if (newVis
!= VisibilityFullyObscured
&&
468 newVis
!= VisibilityNotViewable
) {
469 RegionSubtract(&pParent
->valdata
->after
.exposed
,
470 universe
, &pParent
->clipList
);
473 /* HACK ALERT - copying contents of regions, instead of regions */
477 tmp
= pParent
->clipList
;
478 pParent
->clipList
= *universe
;
483 RegionCopy(&pParent
->clipList
, universe
);
486 pParent
->drawable
.serialNumber
= NEXT_SERIAL_NUMBER
;
488 if (pScreen
->ClipNotify
)
489 (*pScreen
->ClipNotify
) (pParent
, dx
, dy
);
493 miTreeObscured(WindowPtr pParent
)
500 if (pChild
->viewable
) {
501 oldVis
= pChild
->visibility
;
502 if (oldVis
!= (pChild
->visibility
= VisibilityFullyObscured
) &&
504 eventMask
| wOtherEventMasks(pChild
)) & VisibilityChangeMask
))
505 SendVisibilityNotify(pChild
);
506 if (pChild
->firstChild
) {
507 pChild
= pChild
->firstChild
;
511 while (!pChild
->nextSib
&& (pChild
!= pParent
))
512 pChild
= pChild
->parent
;
513 if (pChild
== pParent
)
515 pChild
= pChild
->nextSib
;
520 *-----------------------------------------------------------------------
522 * Recomputes the clip list for pParent and all its inferiors.
528 * The clipList, borderClip, exposed, and borderExposed regions for
529 * each marked window are altered.
532 * This routine assumes that all affected windows have been marked
533 * (valdata created) and their winSize and borderSize regions
534 * adjusted to correspond to their new positions. The borderClip and
535 * clipList regions should not have been touched.
537 * The top-most level is treated differently from all lower levels
538 * because pParent is unchanged. For the top level, we merge the
539 * regions taken up by the marked children back into the clipList
540 * for pParent, thus forming a region from which the marked children
541 * can claim their areas. For lower levels, where the old clipList
542 * and borderClip are invalid, we can't do this and have to do the
543 * extra operations done in miComputeClips, but this is much faster
544 * e.g. when only one child has moved...
546 *-----------------------------------------------------------------------
549 miValidateTree(WindowPtr pParent
, /* Parent to validate */
550 WindowPtr pChild
, /* First child of pParent that was
552 VTKind kind
/* What kind of configuration caused call */
555 RegionRec totalClip
; /* Total clipping region available to
556 * the marked children. pParent's clipList
557 * merged with the borderClips of all
558 * the marked children. */
559 RegionRec childClip
; /* The new borderClip for the current
561 RegionRec childUnion
; /* the space covered by borderSize for
562 * all marked children */
563 RegionRec exposed
; /* For intermediate calculations */
570 pScreen
= pParent
->drawable
.pScreen
;
571 if (pChild
== NullWindow
)
572 pChild
= pParent
->firstChild
;
574 RegionNull(&childClip
);
575 RegionNull(&exposed
);
578 * compute the area of the parent window occupied
579 * by the marked children + the parent itself. This
580 * is the area which can be divied up among the marked
581 * children in their new configuration.
583 RegionNull(&totalClip
);
585 if (RegionBroken(&pParent
->clipList
) && !RegionBroken(&pParent
->borderClip
)) {
588 * When rebuilding clip lists after out of memory,
589 * assume everything is busted.
592 RegionCopy(&totalClip
, &pParent
->borderClip
);
593 RegionIntersect(&totalClip
, &totalClip
, &pParent
->winSize
);
595 for (pWin
= pParent
->firstChild
; pWin
!= pChild
; pWin
= pWin
->nextSib
) {
596 if (pWin
->viewable
&& !TreatAsTransparent(pWin
))
597 RegionSubtract(&totalClip
, &totalClip
, &pWin
->borderSize
);
599 for (pWin
= pChild
; pWin
; pWin
= pWin
->nextSib
)
600 if (pWin
->valdata
&& pWin
->viewable
)
603 RegionEmpty(&pParent
->clipList
);
606 if ((pChild
->drawable
.y
< pParent
->lastChild
->drawable
.y
) ||
607 ((pChild
->drawable
.y
== pParent
->lastChild
->drawable
.y
) &&
608 (pChild
->drawable
.x
< pParent
->lastChild
->drawable
.x
))) {
610 for (pWin
= pChild
; pWin
; pWin
= pWin
->nextSib
) {
612 RegionPtr pBorderClip
= &pWin
->borderClip
;
615 if (pWin
->redirectDraw
!= RedirectDrawNone
&&
616 miGetRedirectBorderClipProc
)
617 pBorderClip
= (*miGetRedirectBorderClipProc
) (pWin
);
619 RegionAppend(&totalClip
, pBorderClip
);
627 pWin
= pParent
->lastChild
;
630 RegionPtr pBorderClip
= &pWin
->borderClip
;
633 if (pWin
->redirectDraw
!= RedirectDrawNone
&&
634 miGetRedirectBorderClipProc
)
635 pBorderClip
= (*miGetRedirectBorderClipProc
) (pWin
);
637 RegionAppend(&totalClip
, pBorderClip
);
643 pWin
= pWin
->prevSib
;
646 RegionValidate(&totalClip
, &overlap
);
650 * Now go through the children of the root and figure their new
651 * borderClips from the totalClip, passing that off to miComputeClips
652 * to handle recursively. Once that's done, we remove the child
653 * from the totalClip to clip any siblings below it.
657 if (kind
!= VTStack
) {
658 RegionUnion(&totalClip
, &totalClip
, &pParent
->clipList
);
661 * precompute childUnion to discover whether any of them
662 * overlap. This seems redundant, but performance studies
663 * have demonstrated that the cost of this loop is
664 * lower than the cost of multiple Subtracts in the
667 RegionNull(&childUnion
);
669 for (pWin
= pChild
; pWin
; pWin
= pWin
->nextSib
)
670 if (pWin
->valdata
&& pWin
->viewable
&&
671 !TreatAsTransparent(pWin
))
672 RegionAppend(&childUnion
, &pWin
->borderSize
);
675 pWin
= pParent
->lastChild
;
677 if (pWin
->valdata
&& pWin
->viewable
&&
678 !TreatAsTransparent(pWin
))
679 RegionAppend(&childUnion
, &pWin
->borderSize
);
682 pWin
= pWin
->prevSib
;
685 RegionValidate(&childUnion
, &overlap
);
687 RegionUninit(&childUnion
);
691 for (pWin
= pChild
; pWin
!= NullWindow
; pWin
= pWin
->nextSib
) {
692 if (pWin
->viewable
) {
694 RegionIntersect(&childClip
, &totalClip
, &pWin
->borderSize
);
695 miComputeClips(pWin
, pScreen
, &childClip
, kind
, &exposed
);
696 if (overlap
&& !TreatAsTransparent(pWin
)) {
697 RegionSubtract(&totalClip
, &totalClip
, &pWin
->borderSize
);
700 else if (pWin
->visibility
== VisibilityNotViewable
) {
701 miTreeObscured(pWin
);
706 RegionEmpty(&pWin
->clipList
);
707 if (pScreen
->ClipNotify
)
708 (*pScreen
->ClipNotify
) (pWin
, 0, 0);
709 RegionEmpty(&pWin
->borderClip
);
710 pWin
->valdata
= NULL
;
715 RegionUninit(&childClip
);
717 RegionSubtract(&totalClip
, &totalClip
, &childUnion
);
718 RegionUninit(&childUnion
);
721 RegionNull(&pParent
->valdata
->after
.exposed
);
722 RegionNull(&pParent
->valdata
->after
.borderExposed
);
725 * each case below is responsible for updating the
726 * clipList and serial number for the parent window
734 * totalClip contains the new clipList for the parent. Figure out
735 * exposures and obscures as per miComputeClips and reset the parent's
738 RegionSubtract(&pParent
->valdata
->after
.exposed
,
739 &totalClip
, &pParent
->clipList
);
742 RegionCopy(&pParent
->clipList
, &totalClip
);
743 pParent
->drawable
.serialNumber
= NEXT_SERIAL_NUMBER
;
747 RegionUninit(&totalClip
);
748 RegionUninit(&exposed
);
749 if (pScreen
->ClipNotify
)
750 (*pScreen
->ClipNotify
) (pParent
, 0, 0);