File: rootlessCommon.c

package info (click to toggle)
vnc4 4.1.1%2BX4.3.0-31
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 171,548 kB
  • ctags: 288,231
  • sloc: ansic: 2,205,256; cpp: 56,016; sh: 38,092; pascal: 13,773; asm: 12,656; tcl: 9,182; lisp: 7,831; perl: 3,338; makefile: 2,957; yacc: 2,902; objc: 2,698; xml: 2,614; python: 2,383; lex: 1,477; awk: 901; csh: 58; sed: 50
file content (262 lines) | stat: -rw-r--r-- 8,054 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
/*
 * Common rootless definitions and code
 *
 * Greg Parker     gparker@cs.stanford.edu
 */
/* $XFree86: xc/programs/Xserver/hw/darwin/quartz_1.3/rootlessCommon.c,v 1.1 2002/03/28 02:21:20 torrey Exp $ */

#include "rootlessCommon.h"


RegionRec rootlessHugeRoot = {{-32767, -32767, 32767, 32767}, NULL};


// Returns the top-level parent of pWindow.
// The root is the top-level parent of itself, even though the root is
// not otherwise considered to be a top-level window.
WindowPtr TopLevelParent(WindowPtr pWindow)
{
    WindowPtr top = pWindow;

    if (IsRoot(pWindow)) return pWindow; // root is top-level parent of itself
    while (top && ! IsTopLevel(top)) top = top->parent;
    return top;
}


// Returns TRUE if this window is visible inside a frame
// (e.g. it is visible and has a top-level or root parent)
Bool IsFramedWindow(WindowPtr pWin)
{
    WindowPtr top;

    if (! pWin->realized) return FALSE;
    top = TopLevelParent(pWin);
    return (top && WINREC(top));
}


// Move the given pixmap's base address to where pixel (0, 0)
// would be if the pixmap's actual data started at (x, y)
void SetPixmapBaseToScreen(PixmapPtr pix, int x, int y)
{
    pix->devPrivate.ptr = (char *)(pix->devPrivate.ptr) -
        (pix->drawable.bitsPerPixel/8 * x + y*pix->devKind);
}


// Update pWindow's pixmap.
// This needs to be called every time a window moves relative to
// its top-level parent, or the parent's pixmap data is reallocated.
// Three cases:
//  * window is top-level with no existing pixmap: make one
//  * window is top-level with existing pixmap: update it in place
//  * window is descendant of top-level: point to top-level's pixmap
void UpdatePixmap(WindowPtr pWindow)
{
    WindowPtr top = TopLevelParent(pWindow);
    RootlessWindowRec *winRec;
    ScreenPtr pScreen = pWindow->drawable.pScreen;
    PixmapPtr pix;

    RL_DEBUG_MSG("update pixmap (win 0x%x)", pWindow);

    // Don't use IsFramedWindow(); window is unrealized during RealizeWindow().

    if (! top) {
        RL_DEBUG_MSG("no parent\n");
        return;
    }
    winRec = WINREC(top);
    if (!winRec) {
        RL_DEBUG_MSG("not framed\n");
        return;
    }

    if (pWindow == top) {
        // This is the top window. Update its pixmap.
        if (winRec->pixmap == NULL) {
            // Allocate a new pixmap.
            pix = GetScratchPixmapHeader(pScreen,
                                         winRec->frame.w, winRec->frame.h,
                                         winRec->frame.depth,
                                         winRec->frame.bitsPerPixel,
                                         winRec->frame.bytesPerRow,
                                         winRec->frame.pixelData);
            SetPixmapBaseToScreen(pix, winRec->frame.x, winRec->frame.y);
            pScreen->SetWindowPixmap(pWindow, pix);
            winRec->pixmap = pix;
        } else {
            // Update existing pixmap. Update in place so we don't have to
            // change the children's pixmaps.
            pix = winRec->pixmap;
            pScreen->ModifyPixmapHeader(pix,
                                        winRec->frame.w, winRec->frame.h,
                                        winRec->frame.depth,
                                        winRec->frame.bitsPerPixel,
                                        winRec->frame.bytesPerRow,
                                        winRec->frame.pixelData);
            SetPixmapBaseToScreen(pix, winRec->frame.x, winRec->frame.y);
        }
    } else {
        // This is not the top window. Point to the parent's pixmap.
        pix = winRec->pixmap;
        pScreen->SetWindowPixmap(pWindow, pix);
    }

    RL_DEBUG_MSG("done\n");
}


#ifdef SHAPE

// boundingShape = outside border (like borderClip)
// clipShape = inside border (like clipList)
// Both are in window-local coordinates
// We only care about boundingShape (fixme true?)

// RootlessReallySetShape is used in several places other than SetShape.
// Most importantly, SetShape is often called on unmapped windows, so we
// have to wait until the window is mapped to reshape the frame.
static void RootlessReallySetShape(WindowPtr pWin)
{
    RootlessWindowRec *winRec = WINREC(pWin);
    ScreenPtr pScreen = pWin->drawable.pScreen;
    RegionRec newShape;

    if (IsRoot(pWin)) return;
    if (!IsTopLevel(pWin)) return;
    if (!winRec) return;

    if (wBoundingShape(pWin)) {
        // wBoundingShape is relative to *inner* origin of window.
        // Translate by borderWidth to get the outside-relative position.
        REGION_INIT(pScreen, &newShape, NullBox, 0);
        REGION_COPY(pScreen, &newShape, wBoundingShape(pWin));
        REGION_TRANSLATE(pScreen, &newShape, pWin->borderWidth,
                         pWin->borderWidth);
    } else {
        newShape.data = NULL;
        newShape.extents.x1 = 0;
        newShape.extents.y1 = 0;
        newShape.extents.x2 = winRec->frame.w;
        newShape.extents.y2 = winRec->frame.h;
    }
    RL_DEBUG_MSG("reshaping...");
    RL_DEBUG_MSG("numrects %d, extents %d %d %d %d ",
                 REGION_NUM_RECTS(&newShape),
                 newShape.extents.x1, newShape.extents.y1,
                 newShape.extents.x2, newShape.extents.y2);
    CallFrameProc(pScreen, ReshapeFrame,(pScreen, &winRec->frame, &newShape));
    REGION_UNINIT(pScreen, &newShape);
}

#endif // SHAPE


// pRegion is GLOBAL
void
RootlessDamageRegion(WindowPtr pWindow, RegionPtr pRegion)
{
    pWindow = TopLevelParent(pWindow);
    if (!pWindow) {
        RL_DEBUG_MSG("RootlessDamageRegion: window is not framed\n");
    } else if (!WINREC(pWindow)) {
        RL_DEBUG_MSG("RootlessDamageRegion: top-level window not a frame\n");
    } else {
        REGION_UNION((pWindow)->drawable.pScreen, &WINREC(pWindow)->damage,
                     &WINREC(pWindow)->damage, (pRegion));
    }
}


// pBox is GLOBAL
void
RootlessDamageBox(WindowPtr pWindow, BoxPtr pBox)
{
    RegionRec region;

    REGION_INIT(pWindow->drawable.pScreen, &region, pBox, 1);
    RootlessDamageRegion(pWindow, &region);
}


// (x, y, w, h) is in window-local coordinates.
void
RootlessDamageRect(WindowPtr pWindow, int x, int y, int w, int h)
{
    BoxRec box;
    RegionRec region;

    x += pWindow->drawable.x;
    y += pWindow->drawable.y;
    box.x1 = x;
    box.x2 = x + w;
    box.y1 = y;
    box.y2 = y + h;
    REGION_INIT(pWindow->drawable.pScreen, &region, &box, 1);
    RootlessDamageRegion(pWindow, &region);
}

#ifdef SHAPE

void
RootlessDamageShape(WindowPtr pWin)
{
    RootlessWindowRec *winRec = WINREC(pWin);

    // We only care about the shape of top-level framed windows.
    if (IsRoot(pWin)) return;
    if (!IsTopLevel(pWin)) return;
    if (!winRec) return;

    winRec->shapeDamage = TRUE;
}

#endif // SHAPE

void
RootlessRedisplay(WindowPtr pWindow)
{
    RootlessWindowRec *winRec = WINREC(pWindow);
    ScreenPtr pScreen = pWindow->drawable.pScreen;

#ifdef SHAPE
    if (winRec->shapeDamage) {
        // Reshape the window. This will also update the entire window.
        RootlessReallySetShape(pWindow);
       REGION_EMPTY(pScreen, &winRec->damage);
       winRec->shapeDamage = FALSE;
    }
    else
#endif // SHAPE
    if (REGION_NOTEMPTY(pScreen, &winRec->damage)) {
        REGION_INTERSECT(pScreen, &winRec->damage, &winRec->damage,
                          &pWindow->borderSize);

        // move region to window local coords
        REGION_TRANSLATE(pScreen, &winRec->damage,
                         -winRec->frame.x, -winRec->frame.y);
        CallFrameProc(pScreen, UpdateRegion,
                      (pScreen, &winRec->frame, &winRec->damage));
        REGION_EMPTY(pScreen, &winRec->damage);
    }
}


void
RootlessRedisplayScreen(ScreenPtr pScreen)
{
    WindowPtr root = WindowTable[pScreen->myNum];

    if (root) {
        WindowPtr win;

        RootlessRedisplay(root);
        for (win = root->firstChild; win; win = win->nextSib) {
            if (WINREC(win)) {
                RootlessRedisplay(win);
            }
        }
    }
}