📄 shape.c
字号:
/************************************************************Copyright (c) 1989 X ConsortiumPermission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included inall copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER INAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR INCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.Except as contained in this notice, the name of the X Consortium shall not beused in advertising or otherwise to promote the sale, use or other dealingsin this Software without prior written authorization from the X Consortium.********************************************************//* $TOG: shape.c /main/37 1997/05/22 10:11:40 kaleb $ *//* $XFree86: xc/programs/Xserver/Xext/shape.c,v 3.1.2.1 1997/05/23 12:19:34 dawes Exp $ */#define NEED_REPLIES#define NEED_EVENTS#include <stdio.h>#include "X.h"#include "Xproto.h"#include "misc.h"#include "os.h"#include "windowstr.h"#include "scrnintstr.h"#include "pixmapstr.h"#include "extnsionst.h"#include "dixstruct.h"#include "resource.h"#include "opaque.h"#define _SHAPE_SERVER_ /* don't want Xlib structures */#include "shapestr.h"#include "regionstr.h"#include "gcstruct.h"typedef RegionPtr (*CreateDftPtr)(#if NeedNestedPrototypes WindowPtr /* pWin */#endif );static int ShapeFreeClient(#if NeedFunctionPrototypes pointer /* data */, XID /* id */#endif );static int ShapeFreeEvents(#if NeedFunctionPrototypes pointer /* data */, XID /* id */#endif );static void SendShapeNotify(#if NeedFunctionPrototypes WindowPtr /* pWin */, int /* which */#endif );static void ShapeResetProc(#if NeedFunctionPrototypes ExtensionEntry * /* extEntry */#endif );static void SShapeNotifyEvent(#if NeedFunctionPrototypes xShapeNotifyEvent * /* from */, xShapeNotifyEvent * /* to */#endif );static intRegionOperate (#if NeedFunctionPrototypes ClientPtr /* client */, WindowPtr /* pWin */, int /* kind */, RegionPtr * /* destRgnp */, RegionPtr /* srcRgn */, int /* op */, int /* xoff */, int /* yoff */, CreateDftPtr /* create */#endif );#if NeedFunctionPrototypes#define CREATE_PROC(func) RegionPtr func(WindowPtr /* pWin */)#else#define CREATE_PROC(func) RegionPtr func(/* WindowPtr pWin */)#endifstatic CREATE_PROC(CreateBoundingShape);static CREATE_PROC(CreateClipShape);#undef CREATE_PROCstatic DISPATCH_PROC(ProcShapeCombine);static DISPATCH_PROC(ProcShapeDispatch);static DISPATCH_PROC(ProcShapeGetRectangles);static DISPATCH_PROC(ProcShapeInputSelected);static DISPATCH_PROC(ProcShapeMask);static DISPATCH_PROC(ProcShapeOffset);static DISPATCH_PROC(ProcShapeQueryExtents);static DISPATCH_PROC(ProcShapeQueryVersion);static DISPATCH_PROC(ProcShapeRectangles);static DISPATCH_PROC(ProcShapeSelectInput);static DISPATCH_PROC(SProcShapeCombine);static DISPATCH_PROC(SProcShapeDispatch);static DISPATCH_PROC(SProcShapeGetRectangles);static DISPATCH_PROC(SProcShapeInputSelected);static DISPATCH_PROC(SProcShapeMask);static DISPATCH_PROC(SProcShapeOffset);static DISPATCH_PROC(SProcShapeQueryExtents);static DISPATCH_PROC(SProcShapeQueryVersion);static DISPATCH_PROC(SProcShapeRectangles);static DISPATCH_PROC(SProcShapeSelectInput);static unsigned char ShapeReqCode = 0;static int ShapeEventBase = 0;static RESTYPE ClientType, EventType; /* resource types for event masks *//* * each window has a list of clients requesting * ShapeNotify events. Each client has a resource * for each window it selects ShapeNotify input for, * this resource is used to delete the ShapeNotifyRec * entry from the per-window queue. */typedef struct _ShapeEvent *ShapeEventPtr;typedef struct _ShapeEvent { ShapeEventPtr next; ClientPtr client; WindowPtr window; XID clientResource;} ShapeEventRec;/**************** * ShapeExtensionInit * * Called from InitExtensions in main() or from QueryExtension() if the * extension is dynamically loaded. * ****************/voidShapeExtensionInit(){ ExtensionEntry *extEntry; ClientType = CreateNewResourceType(ShapeFreeClient); EventType = CreateNewResourceType(ShapeFreeEvents); if (ClientType && EventType && (extEntry = AddExtension(SHAPENAME, ShapeNumberEvents, 0, ProcShapeDispatch, SProcShapeDispatch, ShapeResetProc, StandardMinorOpcode))) { ShapeReqCode = (unsigned char)extEntry->base; ShapeEventBase = extEntry->eventBase; EventSwapVector[ShapeEventBase] = (EventSwapPtr) SShapeNotifyEvent; }}/*ARGSUSED*/static voidShapeResetProc (extEntry)ExtensionEntry *extEntry;{}static intRegionOperate (client, pWin, kind, destRgnp, srcRgn, op, xoff, yoff, create) ClientPtr client; WindowPtr pWin; int kind; RegionPtr *destRgnp, srcRgn; int op; int xoff, yoff; CreateDftPtr create; /* creates a reasonable *destRgnp */{ ScreenPtr pScreen = pWin->drawable.pScreen; if (srcRgn && (xoff || yoff)) REGION_TRANSLATE(pScreen, srcRgn, xoff, yoff); if (!pWin->parent) { if (srcRgn) REGION_DESTROY(pScreen, srcRgn); return Success; } switch (op) { case ShapeSet: if (*destRgnp) REGION_DESTROY(pScreen, *destRgnp); *destRgnp = srcRgn; srcRgn = 0; break; case ShapeUnion: if (*destRgnp && srcRgn) REGION_UNION(pScreen, *destRgnp, *destRgnp, srcRgn); break; case ShapeIntersect: if (*destRgnp && srcRgn) REGION_INTERSECT(pScreen, *destRgnp, *destRgnp, srcRgn); else { *destRgnp = srcRgn; srcRgn = 0; } break; case ShapeSubtract: if (!*destRgnp) *destRgnp = (*create)(pWin); if (srcRgn) REGION_SUBTRACT(pScreen, *destRgnp, *destRgnp, srcRgn); break; case ShapeInvert: if (!*destRgnp) *destRgnp = REGION_CREATE(pScreen, (BoxPtr) 0, 0); else if (srcRgn) REGION_SUBTRACT(pScreen, *destRgnp, srcRgn, *destRgnp); break; default: client->errorValue = op; return BadValue; } if (srcRgn) REGION_DESTROY(pScreen, srcRgn); (*pScreen->SetShape) (pWin); SendShapeNotify (pWin, kind); return Success;}static RegionPtrCreateBoundingShape (pWin) WindowPtr pWin;{ BoxRec extents; extents.x1 = -wBorderWidth (pWin); extents.y1 = -wBorderWidth (pWin); extents.x2 = pWin->drawable.width + wBorderWidth (pWin); extents.y2 = pWin->drawable.height + wBorderWidth (pWin); return REGION_CREATE(pWin->drawable.pScreen, &extents, 1);}static RegionPtrCreateClipShape (pWin) WindowPtr pWin;{ BoxRec extents; extents.x1 = 0; extents.y1 = 0; extents.x2 = pWin->drawable.width; extents.y2 = pWin->drawable.height; return REGION_CREATE(pWin->drawable.pScreen, &extents, 1);}static intProcShapeQueryVersion (client) register ClientPtr client;{ xShapeQueryVersionReply rep; register int n; REQUEST_SIZE_MATCH (xShapeQueryVersionReq); rep.type = X_Reply; rep.length = 0; rep.sequenceNumber = client->sequence; rep.majorVersion = SHAPE_MAJOR_VERSION; rep.minorVersion = SHAPE_MINOR_VERSION; if (client->swapped) { swaps(&rep.sequenceNumber, n); swapl(&rep.length, n); swaps(&rep.majorVersion, n); swaps(&rep.minorVersion, n); } WriteToClient(client, sizeof (xShapeQueryVersionReply), (char *)&rep); return (client->noClientException);}/***************** * ProcShapeRectangles * *****************/static intProcShapeRectangles (client) register ClientPtr client;{ WindowPtr pWin; ScreenPtr pScreen; REQUEST(xShapeRectanglesReq); xRectangle *prects; int nrects, ctype; RegionPtr srcRgn; RegionPtr *destRgn; CreateDftPtr createDefault; int destBounding; REQUEST_AT_LEAST_SIZE (xShapeRectanglesReq); UpdateCurrentTime(); pWin = LookupWindow (stuff->dest, client); if (!pWin) return BadWindow; switch (stuff->destKind) { case ShapeBounding: destBounding = 1; createDefault = CreateBoundingShape; break; case ShapeClip: destBounding = 0; createDefault = CreateClipShape; break; default: client->errorValue = stuff->destKind; return BadValue; } if ((stuff->ordering != Unsorted) && (stuff->ordering != YSorted) && (stuff->ordering != YXSorted) && (stuff->ordering != YXBanded)) { client->errorValue = stuff->ordering; return BadValue; } pScreen = pWin->drawable.pScreen; nrects = ((stuff->length << 2) - sizeof(xShapeRectanglesReq)); if (nrects & 4) return BadLength; nrects >>= 3; prects = (xRectangle *) &stuff[1]; ctype = VerifyRectOrder(nrects, prects, (int)stuff->ordering); if (ctype < 0) return BadMatch; srcRgn = RECTS_TO_REGION(pScreen, nrects, prects, ctype); if (!pWin->optional) MakeWindowOptional (pWin); if (destBounding) destRgn = &pWin->optional->boundingShape; else destRgn = &pWin->optional->clipShape; return RegionOperate (client, pWin, (int)stuff->destKind, destRgn, srcRgn, (int)stuff->op, stuff->xOff, stuff->yOff, createDefault);}/************** * ProcShapeMask **************/static intProcShapeMask (client) register ClientPtr client;{ WindowPtr pWin; ScreenPtr pScreen; REQUEST(xShapeMaskReq); RegionPtr srcRgn; RegionPtr *destRgn; PixmapPtr pPixmap; CreateDftPtr createDefault; int destBounding; REQUEST_SIZE_MATCH (xShapeMaskReq); UpdateCurrentTime(); pWin = SecurityLookupWindow (stuff->dest, client, SecurityWriteAccess); if (!pWin) return BadWindow; switch (stuff->destKind) { case ShapeBounding: destBounding = 1; createDefault = CreateBoundingShape; break; case ShapeClip: destBounding = 0; createDefault = CreateClipShape; break; default: client->errorValue = stuff->destKind; return BadValue; } pScreen = pWin->drawable.pScreen; if (stuff->src == None) srcRgn = 0; else { pPixmap = (PixmapPtr) SecurityLookupIDByType(client, stuff->src, RT_PIXMAP, SecurityReadAccess); if (!pPixmap) return BadPixmap; if (pPixmap->drawable.pScreen != pScreen || pPixmap->drawable.depth != 1) return BadMatch; srcRgn = BITMAP_TO_REGION(pScreen, pPixmap); if (!srcRgn) return BadAlloc; } if (!pWin->optional) MakeWindowOptional (pWin); if (destBounding) destRgn = &pWin->optional->boundingShape; else destRgn = &pWin->optional->clipShape; return RegionOperate (client, pWin, (int)stuff->destKind, destRgn, srcRgn, (int)stuff->op, stuff->xOff, stuff->yOff, createDefault);}/************ * ProcShapeCombine ************/static intProcShapeCombine (client) register ClientPtr client;{ WindowPtr pSrcWin, pDestWin; ScreenPtr pScreen; REQUEST(xShapeCombineReq); RegionPtr srcRgn; RegionPtr *destRgn; CreateDftPtr createDefault; CreateDftPtr createSrc; RegionPtr tmp; int destBounding; REQUEST_SIZE_MATCH (xShapeCombineReq); UpdateCurrentTime(); pDestWin = LookupWindow (stuff->dest, client); if (!pDestWin) return BadWindow; if (!pDestWin->optional) MakeWindowOptional (pDestWin); switch (stuff->destKind) { case ShapeBounding: destBounding = 1; createDefault = CreateBoundingShape; break; case ShapeClip: destBounding = 0; createDefault = CreateClipShape; break; default: client->errorValue = stuff->destKind; return BadValue; } pScreen = pDestWin->drawable.pScreen; pSrcWin = LookupWindow (stuff->src, client); if (!pSrcWin) return BadWindow; switch (stuff->srcKind) { case ShapeBounding: srcRgn = wBoundingShape (pSrcWin); createSrc = CreateBoundingShape; break; case ShapeClip: srcRgn = wClipShape (pSrcWin); createSrc = CreateClipShape; break; default: client->errorValue = stuff->srcKind; return BadValue; } if (pSrcWin->drawable.pScreen != pScreen) { return BadMatch; } if (srcRgn) { tmp = REGION_CREATE(pScreen, (BoxPtr) 0, 0); REGION_COPY(pScreen, tmp, srcRgn); srcRgn = tmp; } else srcRgn = (*createSrc) (pSrcWin); if (!pDestWin->optional) MakeWindowOptional (pDestWin); if (destBounding) destRgn = &pDestWin->optional->boundingShape; else destRgn = &pDestWin->optional->clipShape; return RegionOperate (client, pDestWin, (int)stuff->destKind, destRgn, srcRgn, (int)stuff->op, stuff->xOff, stuff->yOff, createDefault);}/************* * ProcShapeOffset *************/static intProcShapeOffset (client) register ClientPtr client;{ WindowPtr pWin; ScreenPtr pScreen; REQUEST(xShapeOffsetReq); RegionPtr srcRgn; REQUEST_SIZE_MATCH (xShapeOffsetReq); UpdateCurrentTime(); pWin = LookupWindow (stuff->dest, client); if (!pWin) return BadWindow; switch (stuff->destKind) { case ShapeBounding: srcRgn = wBoundingShape (pWin); break; case ShapeClip: srcRgn = wClipShape(pWin); break; default: client->errorValue = stuff->destKind; return BadValue; } pScreen = pWin->drawable.pScreen; if (srcRgn) { REGION_TRANSLATE(pScreen, srcRgn, stuff->xOff, stuff->yOff); (*pScreen->SetShape) (pWin); } SendShapeNotify (pWin, (int)stuff->destKind); return Success;}static intProcShapeQueryExtents (client) register ClientPtr client;{ REQUEST(xShapeQueryExtentsReq); WindowPtr pWin; xShapeQueryExtentsReply rep; BoxRec extents, *pExtents; register int n; REQUEST_SIZE_MATCH (xShapeQueryExtentsReq); pWin = LookupWindow (stuff->window, client); if (!pWin) return BadWindow; rep.type = X_Reply; rep.length = 0; rep.sequenceNumber = client->sequence;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -