static int ProcShapeOffset(ClientPtr client) { WindowPtr pWin; REQUEST(xShapeOffsetReq); RegionPtr srcRgn; int rc; REQUEST_SIZE_MATCH(xShapeOffsetReq); UpdateCurrentTime(); rc = dixLookupWindow(&pWin, stuff->dest, client, DixSetAttrAccess); if (rc != Success) return rc; switch (stuff->destKind) { case ShapeBounding: srcRgn = wBoundingShape(pWin); break; case ShapeClip: srcRgn = wClipShape(pWin); break; case ShapeInput: srcRgn = wInputShape(pWin); break; default: client->errorValue = stuff->destKind; return BadValue; } if (srcRgn) { RegionTranslate(srcRgn, stuff->xOff, stuff->yOff); (*pWin->drawable.pScreen->SetShape) (pWin, stuff->destKind); } SendShapeNotify(pWin, (int) stuff->destKind); return Success; }
int ProcXFixesCreateRegionFromWindow (ClientPtr client) { RegionPtr pRegion; Bool copy = TRUE; WindowPtr pWin; REQUEST (xXFixesCreateRegionFromWindowReq); REQUEST_SIZE_MATCH (xXFixesCreateRegionFromWindowReq); LEGAL_NEW_RESOURCE (stuff->region, client); pWin = (WindowPtr) LookupIDByType (stuff->window, RT_WINDOW); if (!pWin) { client->errorValue = stuff->window; return BadWindow; } switch (stuff->kind) { case WindowRegionBounding: #ifdef SHAPE pRegion = wBoundingShape(pWin); if (!pRegion) #endif { pRegion = CreateBoundingShape (pWin); copy = FALSE; } break; case WindowRegionClip: #ifdef SHAPE pRegion = wClipShape(pWin); if (!pRegion) #endif { pRegion = CreateClipShape (pWin); copy = FALSE; } break; default: client->errorValue = stuff->kind; return BadValue; } if (copy && pRegion) pRegion = XFixesRegionCopy (pRegion); if (!pRegion) return BadAlloc; if (!AddResource (stuff->region, RegionResType, (pointer) pRegion)) return BadAlloc; return(client->noClientException); }
int ProcXFixesCreateRegionFromWindow (ClientPtr client) { RegionPtr pRegion; Bool copy = TRUE; WindowPtr pWin; int rc; REQUEST (xXFixesCreateRegionFromWindowReq); REQUEST_SIZE_MATCH (xXFixesCreateRegionFromWindowReq); LEGAL_NEW_RESOURCE (stuff->region, client); rc = dixLookupResourceByType((pointer *)&pWin, stuff->window, RT_WINDOW, client, DixGetAttrAccess); if (rc != Success) { client->errorValue = stuff->window; return rc; } switch (stuff->kind) { case WindowRegionBounding: pRegion = wBoundingShape(pWin); if (!pRegion) { pRegion = CreateBoundingShape (pWin); copy = FALSE; } break; case WindowRegionClip: pRegion = wClipShape(pWin); if (!pRegion) { pRegion = CreateClipShape (pWin); copy = FALSE; } break; default: client->errorValue = stuff->kind; return BadValue; } if (copy && pRegion) pRegion = XFixesRegionCopy (pRegion); if (!pRegion) return BadAlloc; if (!AddResource (stuff->region, RegionResType, (pointer) pRegion)) return BadAlloc; return Success; }
static int ProcShapeGetRectangles(ClientPtr client) { REQUEST(xShapeGetRectanglesReq); WindowPtr pWin; xShapeGetRectanglesReply rep; xRectangle *rects; int nrects, i, rc; RegionPtr region; REQUEST_SIZE_MATCH(xShapeGetRectanglesReq); rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess); if (rc != Success) return rc; switch (stuff->kind) { case ShapeBounding: region = wBoundingShape(pWin); break; case ShapeClip: region = wClipShape(pWin); break; case ShapeInput: region = wInputShape(pWin); break; default: client->errorValue = stuff->kind; return BadValue; } if (!region) { nrects = 1; rects = malloc(sizeof(xRectangle)); if (!rects) return BadAlloc; switch (stuff->kind) { case ShapeBounding: rects->x = -(int) wBorderWidth(pWin); rects->y = -(int) wBorderWidth(pWin); rects->width = pWin->drawable.width + wBorderWidth(pWin); rects->height = pWin->drawable.height + wBorderWidth(pWin); break; case ShapeClip: rects->x = 0; rects->y = 0; rects->width = pWin->drawable.width; rects->height = pWin->drawable.height; break; case ShapeInput: rects->x = -(int) wBorderWidth(pWin); rects->y = -(int) wBorderWidth(pWin); rects->width = pWin->drawable.width + wBorderWidth(pWin); rects->height = pWin->drawable.height + wBorderWidth(pWin); break; } } else { BoxPtr box; nrects = RegionNumRects(region); box = RegionRects(region); rects = malloc(nrects * sizeof(xRectangle)); if (!rects && nrects) return BadAlloc; for (i = 0; i < nrects; i++, box++) { rects[i].x = box->x1; rects[i].y = box->y1; rects[i].width = box->x2 - box->x1; rects[i].height = box->y2 - box->y1; } } rep.type = X_Reply; rep.sequenceNumber = client->sequence; rep.length = bytes_to_int32(nrects * sizeof(xRectangle)); rep.ordering = YXBanded; rep.nrects = nrects; if (client->swapped) { swaps(&rep.sequenceNumber); swapl(&rep.length); swapl(&rep.nrects); SwapShorts((short *) rects, (unsigned long) nrects * 4); } WriteToClient(client, sizeof(rep), (char *) &rep); WriteToClient(client, nrects * sizeof(xRectangle), (char *) rects); free(rects); return Success; }
void SendShapeNotify(WindowPtr pWin, int which) { ShapeEventPtr *pHead, pShapeEvent; xShapeNotifyEvent se; BoxRec extents; RegionPtr region; BYTE shaped; int rc; rc = dixLookupResourceByType((pointer *) &pHead, pWin->drawable.id, ShapeEventType, serverClient, DixReadAccess); if (rc != Success) return; switch (which) { case ShapeBounding: region = wBoundingShape(pWin); if (region) { extents = *RegionExtents(region); shaped = xTrue; } else { extents.x1 = -wBorderWidth(pWin); extents.y1 = -wBorderWidth(pWin); extents.x2 = pWin->drawable.width + wBorderWidth(pWin); extents.y2 = pWin->drawable.height + wBorderWidth(pWin); shaped = xFalse; } break; case ShapeClip: region = wClipShape(pWin); if (region) { extents = *RegionExtents(region); shaped = xTrue; } else { extents.x1 = 0; extents.y1 = 0; extents.x2 = pWin->drawable.width; extents.y2 = pWin->drawable.height; shaped = xFalse; } break; case ShapeInput: region = wInputShape(pWin); if (region) { extents = *RegionExtents(region); shaped = xTrue; } else { extents.x1 = -wBorderWidth(pWin); extents.y1 = -wBorderWidth(pWin); extents.x2 = pWin->drawable.width + wBorderWidth(pWin); extents.y2 = pWin->drawable.height + wBorderWidth(pWin); shaped = xFalse; } break; default: return; } for (pShapeEvent = *pHead; pShapeEvent; pShapeEvent = pShapeEvent->next) { se.type = ShapeNotify + ShapeEventBase; se.kind = which; se.window = pWin->drawable.id; se.x = extents.x1; se.y = extents.y1; se.width = extents.x2 - extents.x1; se.height = extents.y2 - extents.y1; se.time = currentTime.milliseconds; se.shaped = shaped; WriteEventsToClient(pShapeEvent->client, 1, (xEvent *) &se); } }
static int ProcShapeQueryExtents(ClientPtr client) { REQUEST(xShapeQueryExtentsReq); WindowPtr pWin; xShapeQueryExtentsReply rep; BoxRec extents, *pExtents; int rc; RegionPtr region; REQUEST_SIZE_MATCH(xShapeQueryExtentsReq); rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess); if (rc != Success) return rc; memset(&rep, 0, sizeof(xShapeQueryExtentsReply)); rep.type = X_Reply; rep.length = 0; rep.sequenceNumber = client->sequence; rep.boundingShaped = (wBoundingShape(pWin) != 0); rep.clipShaped = (wClipShape(pWin) != 0); if ((region = wBoundingShape(pWin))) { /* this is done in two steps because of a compiler bug on SunOS 4.1.3 */ pExtents = RegionExtents(region); extents = *pExtents; } else { extents.x1 = -wBorderWidth(pWin); extents.y1 = -wBorderWidth(pWin); extents.x2 = pWin->drawable.width + wBorderWidth(pWin); extents.y2 = pWin->drawable.height + wBorderWidth(pWin); } rep.xBoundingShape = extents.x1; rep.yBoundingShape = extents.y1; rep.widthBoundingShape = extents.x2 - extents.x1; rep.heightBoundingShape = extents.y2 - extents.y1; if ((region = wClipShape(pWin))) { /* this is done in two steps because of a compiler bug on SunOS 4.1.3 */ pExtents = RegionExtents(region); extents = *pExtents; } else { extents.x1 = 0; extents.y1 = 0; extents.x2 = pWin->drawable.width; extents.y2 = pWin->drawable.height; } rep.xClipShape = extents.x1; rep.yClipShape = extents.y1; rep.widthClipShape = extents.x2 - extents.x1; rep.heightClipShape = extents.y2 - extents.y1; if (client->swapped) { swaps(&rep.sequenceNumber); swapl(&rep.length); swaps(&rep.xBoundingShape); swaps(&rep.yBoundingShape); swaps(&rep.widthBoundingShape); swaps(&rep.heightBoundingShape); swaps(&rep.xClipShape); swaps(&rep.yClipShape); swaps(&rep.widthClipShape); swaps(&rep.heightClipShape); } WriteToClient(client, sizeof(xShapeQueryExtentsReply), (char *) &rep); return Success; }
static int ProcShapeCombine(ClientPtr client) { WindowPtr pSrcWin, pDestWin; REQUEST(xShapeCombineReq); RegionPtr srcRgn; RegionPtr *destRgn; CreateDftPtr createDefault; CreateDftPtr createSrc; RegionPtr tmp; int rc; REQUEST_SIZE_MATCH(xShapeCombineReq); UpdateCurrentTime(); rc = dixLookupWindow(&pDestWin, stuff->dest, client, DixSetAttrAccess); if (rc != Success) return rc; if (!pDestWin->optional) MakeWindowOptional(pDestWin); switch (stuff->destKind) { case ShapeBounding: createDefault = CreateBoundingShape; break; case ShapeClip: createDefault = CreateClipShape; break; case ShapeInput: createDefault = CreateBoundingShape; break; default: client->errorValue = stuff->destKind; return BadValue; } rc = dixLookupWindow(&pSrcWin, stuff->src, client, DixGetAttrAccess); if (rc != Success) return rc; switch (stuff->srcKind) { case ShapeBounding: srcRgn = wBoundingShape(pSrcWin); createSrc = CreateBoundingShape; break; case ShapeClip: srcRgn = wClipShape(pSrcWin); createSrc = CreateClipShape; break; case ShapeInput: srcRgn = wInputShape(pSrcWin); createSrc = CreateBoundingShape; break; default: client->errorValue = stuff->srcKind; return BadValue; } if (pSrcWin->drawable.pScreen != pDestWin->drawable.pScreen) { return BadMatch; } if (srcRgn) { tmp = RegionCreate((BoxPtr) 0, 0); RegionCopy(tmp, srcRgn); srcRgn = tmp; } else srcRgn = (*createSrc) (pSrcWin); if (!pDestWin->optional) MakeWindowOptional(pDestWin); switch (stuff->destKind) { case ShapeBounding: destRgn = &pDestWin->optional->boundingShape; break; case ShapeClip: destRgn = &pDestWin->optional->clipShape; break; case ShapeInput: destRgn = &pDestWin->optional->inputShape; break; default: return BadValue; } return RegionOperate(client, pDestWin, (int) stuff->destKind, destRgn, srcRgn, (int) stuff->op, stuff->xOff, stuff->yOff, createDefault); }
RegionPtr miHandleExposures(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable, GCPtr pGC, int srcx, int srcy, int width, int height, int dstx, int dsty) { RegionPtr prgnSrcClip; /* drawable-relative source clip */ RegionRec rgnSrcRec; RegionPtr prgnDstClip; /* drawable-relative dest clip */ RegionRec rgnDstRec; BoxRec srcBox; /* unclipped source */ RegionRec rgnExposed; /* exposed region, calculated source- relative, made dst relative to intersect with visible parts of dest and send events to client, and then screen relative to paint the window background */ WindowPtr pSrcWin; BoxRec expBox = { 0, }; Bool extents; /* avoid work if we can */ if (!pGC->graphicsExposures && pDstDrawable->type == DRAWABLE_PIXMAP) return NULL; srcBox.x1 = srcx; srcBox.y1 = srcy; srcBox.x2 = srcx + width; srcBox.y2 = srcy + height; if (pSrcDrawable->type != DRAWABLE_PIXMAP) { BoxRec TsrcBox; TsrcBox.x1 = srcx + pSrcDrawable->x; TsrcBox.y1 = srcy + pSrcDrawable->y; TsrcBox.x2 = TsrcBox.x1 + width; TsrcBox.y2 = TsrcBox.y1 + height; pSrcWin = (WindowPtr) pSrcDrawable; if (pGC->subWindowMode == IncludeInferiors) { prgnSrcClip = NotClippedByChildren(pSrcWin); if ((RegionContainsRect(prgnSrcClip, &TsrcBox)) == rgnIN) { RegionDestroy(prgnSrcClip); return NULL; } } else { if ((RegionContainsRect(&pSrcWin->clipList, &TsrcBox)) == rgnIN) return NULL; prgnSrcClip = &rgnSrcRec; RegionNull(prgnSrcClip); RegionCopy(prgnSrcClip, &pSrcWin->clipList); } RegionTranslate(prgnSrcClip, -pSrcDrawable->x, -pSrcDrawable->y); } else { BoxRec box; if ((srcBox.x1 >= 0) && (srcBox.y1 >= 0) && (srcBox.x2 <= pSrcDrawable->width) && (srcBox.y2 <= pSrcDrawable->height)) return NULL; box.x1 = 0; box.y1 = 0; box.x2 = pSrcDrawable->width; box.y2 = pSrcDrawable->height; prgnSrcClip = &rgnSrcRec; RegionInit(prgnSrcClip, &box, 1); pSrcWin = NULL; } if (pDstDrawable == pSrcDrawable) { prgnDstClip = prgnSrcClip; } else if (pDstDrawable->type != DRAWABLE_PIXMAP) { if (pGC->subWindowMode == IncludeInferiors) { prgnDstClip = NotClippedByChildren((WindowPtr) pDstDrawable); } else { prgnDstClip = &rgnDstRec; RegionNull(prgnDstClip); RegionCopy(prgnDstClip, &((WindowPtr) pDstDrawable)->clipList); } RegionTranslate(prgnDstClip, -pDstDrawable->x, -pDstDrawable->y); } else { BoxRec box; box.x1 = 0; box.y1 = 0; box.x2 = pDstDrawable->width; box.y2 = pDstDrawable->height; prgnDstClip = &rgnDstRec; RegionInit(prgnDstClip, &box, 1); } /* drawable-relative source region */ RegionInit(&rgnExposed, &srcBox, 1); /* now get the hidden parts of the source box */ RegionSubtract(&rgnExposed, &rgnExposed, prgnSrcClip); /* move them over the destination */ RegionTranslate(&rgnExposed, dstx - srcx, dsty - srcy); /* intersect with visible areas of dest */ RegionIntersect(&rgnExposed, &rgnExposed, prgnDstClip); /* intersect with client clip region. */ if (pGC->clientClip) RegionIntersect(&rgnExposed, &rgnExposed, pGC->clientClip); /* * If we have LOTS of rectangles, we decide to take the extents * and force an exposure on that. This should require much less * work overall, on both client and server. This is cheating, but * isn't prohibited by the protocol ("spontaneous combustion" :-) * for windows. */ extents = pGC->graphicsExposures && (RegionNumRects(&rgnExposed) > RECTLIMIT) && (pDstDrawable->type != DRAWABLE_PIXMAP); if (pSrcWin) { RegionPtr region; if (!(region = wClipShape(pSrcWin))) region = wBoundingShape(pSrcWin); /* * If you try to CopyArea the extents of a shaped window, compacting the * exposed region will undo all our work! */ if (extents && pSrcWin && region && (RegionContainsRect(region, &srcBox) != rgnIN)) extents = FALSE; } if (extents) { expBox = *RegionExtents(&rgnExposed); RegionReset(&rgnExposed, &expBox); } if ((pDstDrawable->type != DRAWABLE_PIXMAP) && (((WindowPtr) pDstDrawable)->backgroundState != None)) { WindowPtr pWin = (WindowPtr) pDstDrawable; /* make the exposed area screen-relative */ RegionTranslate(&rgnExposed, pDstDrawable->x, pDstDrawable->y); if (extents) { /* PaintWindow doesn't clip, so we have to */ RegionIntersect(&rgnExposed, &rgnExposed, &pWin->clipList); } pDstDrawable->pScreen->PaintWindow((WindowPtr) pDstDrawable, &rgnExposed, PW_BACKGROUND); if (extents) { RegionReset(&rgnExposed, &expBox); } else RegionTranslate(&rgnExposed, -pDstDrawable->x, -pDstDrawable->y); } if (prgnDstClip == &rgnDstRec) { RegionUninit(prgnDstClip); } else if (prgnDstClip != prgnSrcClip) { RegionDestroy(prgnDstClip); } if (prgnSrcClip == &rgnSrcRec) { RegionUninit(prgnSrcClip); } else { RegionDestroy(prgnSrcClip); } if (pGC->graphicsExposures) { /* don't look */ RegionPtr exposed = RegionCreate(NullBox, 0); *exposed = rgnExposed; return exposed; } else { RegionUninit(&rgnExposed); return NULL; } }