📄 midispcur.c
字号:
/* * midispcur.c * * machine independent cursor display routines *//* $XConsortium: midispcur.c,v 5.14 94/04/17 20:27:28 dpw Exp $ *//*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.*/#define NEED_EVENTS# include "X.h"# include "misc.h"# include "input.h"# include "cursorstr.h"# include "windowstr.h"# include "regionstr.h"# include "dixstruct.h"# include "scrnintstr.h"# include "servermd.h"# include "mipointer.h"# include "misprite.h"# include "gcstruct.h"extern WindowPtr *WindowTable;/* per-screen private data */static int miDCScreenIndex;static unsigned long miDCGeneration = 0;static Bool miDCCloseScreen();typedef struct { GCPtr pSourceGC, pMaskGC; GCPtr pSaveGC, pRestoreGC; GCPtr pMoveGC; GCPtr pPixSourceGC, pPixMaskGC; CloseScreenProcPtr CloseScreen; PixmapPtr pSave, pTemp;} miDCScreenRec, *miDCScreenPtr;/* per-cursor per-screen private data */typedef struct { PixmapPtr sourceBits; /* source bits */ PixmapPtr maskBits; /* mask bits */} miDCCursorRec, *miDCCursorPtr;/* * sprite/cursor method table */static Bool miDCRealizeCursor(), miDCUnrealizeCursor();static Bool miDCPutUpCursor(), miDCSaveUnderCursor();static Bool miDCRestoreUnderCursor(), miDCMoveCursor();static Bool miDCChangeSave();static miSpriteCursorFuncRec miDCFuncs = { miDCRealizeCursor, miDCUnrealizeCursor, miDCPutUpCursor, miDCSaveUnderCursor, miDCRestoreUnderCursor, miDCMoveCursor, miDCChangeSave,};BoolmiDCInitialize (pScreen, screenFuncs) ScreenPtr pScreen; miPointerScreenFuncPtr screenFuncs;{ miDCScreenPtr pScreenPriv; if (miDCGeneration != serverGeneration) { miDCScreenIndex = AllocateScreenPrivateIndex (); if (miDCScreenIndex < 0) return FALSE; miDCGeneration = serverGeneration; } pScreenPriv = (miDCScreenPtr) xalloc (sizeof (miDCScreenRec)); if (!pScreenPriv) return FALSE; /* * initialize the entire private structure to zeros */ pScreenPriv->pSourceGC = pScreenPriv->pMaskGC = pScreenPriv->pSaveGC = pScreenPriv->pRestoreGC = pScreenPriv->pMoveGC = pScreenPriv->pPixSourceGC = pScreenPriv->pPixMaskGC = NULL; pScreenPriv->pSave = pScreenPriv->pTemp = NULL; pScreenPriv->CloseScreen = pScreen->CloseScreen; pScreen->CloseScreen = miDCCloseScreen; pScreen->devPrivates[miDCScreenIndex].ptr = (pointer) pScreenPriv; if (!miSpriteInitialize (pScreen, &miDCFuncs, screenFuncs)) { xfree ((pointer) pScreenPriv); return FALSE; } return TRUE;}#define tossGC(gc) (gc ? FreeGC (gc, (GContext) 0) : 0)#define tossPix(pix) (pix ? (*pScreen->DestroyPixmap) (pix) : TRUE)static BoolmiDCCloseScreen (index, pScreen) ScreenPtr pScreen;{ miDCScreenPtr pScreenPriv; pScreenPriv = (miDCScreenPtr) pScreen->devPrivates[miDCScreenIndex].ptr; pScreen->CloseScreen = pScreenPriv->CloseScreen; tossGC (pScreenPriv->pSourceGC); tossGC (pScreenPriv->pMaskGC); tossGC (pScreenPriv->pSaveGC); tossGC (pScreenPriv->pRestoreGC); tossGC (pScreenPriv->pMoveGC); tossGC (pScreenPriv->pPixSourceGC); tossGC (pScreenPriv->pPixMaskGC); tossPix (pScreenPriv->pSave); tossPix (pScreenPriv->pTemp); xfree ((pointer) pScreenPriv); return (*pScreen->CloseScreen) (index, pScreen);}static BoolmiDCRealizeCursor (pScreen, pCursor) ScreenPtr pScreen; CursorPtr pCursor;{ if (pCursor->bits->refcnt <= 1) pCursor->bits->devPriv[pScreen->myNum] = (pointer)NULL; return TRUE;}static miDCCursorPtrmiDCRealize (pScreen, pCursor) ScreenPtr pScreen; CursorPtr pCursor;{ miDCCursorPtr pPriv; GCPtr pGC; XID gcvals[3]; pPriv = (miDCCursorPtr) xalloc (sizeof (miDCCursorRec)); if (!pPriv) return (miDCCursorPtr)NULL; pPriv->sourceBits = (*pScreen->CreatePixmap) (pScreen, pCursor->bits->width, pCursor->bits->height, 1); if (!pPriv->sourceBits) { xfree ((pointer) pPriv); return (miDCCursorPtr)NULL; } pPriv->maskBits = (*pScreen->CreatePixmap) (pScreen, pCursor->bits->width, pCursor->bits->height, 1); if (!pPriv->maskBits) { (*pScreen->DestroyPixmap) (pPriv->sourceBits); xfree ((pointer) pPriv); return (miDCCursorPtr)NULL; } pCursor->bits->devPriv[pScreen->myNum] = (pointer) pPriv; /* create the two sets of bits, clipping as appropriate */ pGC = GetScratchGC (1, pScreen); if (!pGC) { (void) miDCUnrealizeCursor (pScreen, pCursor); return (miDCCursorPtr)NULL; } ValidateGC ((DrawablePtr)pPriv->sourceBits, pGC); (*pGC->ops->PutImage) ((DrawablePtr)pPriv->sourceBits, pGC, 1, 0, 0, pCursor->bits->width, pCursor->bits->height, 0, XYPixmap, (char *)pCursor->bits->source); gcvals[0] = GXand; ChangeGC (pGC, GCFunction, gcvals); ValidateGC ((DrawablePtr)pPriv->sourceBits, pGC); (*pGC->ops->PutImage) ((DrawablePtr)pPriv->sourceBits, pGC, 1, 0, 0, pCursor->bits->width, pCursor->bits->height, 0, XYPixmap, (char *)pCursor->bits->mask); /* mask bits -- pCursor->mask & ~pCursor->source */ gcvals[0] = GXcopy; ChangeGC (pGC, GCFunction, gcvals); ValidateGC ((DrawablePtr)pPriv->maskBits, pGC); (*pGC->ops->PutImage) ((DrawablePtr)pPriv->maskBits, pGC, 1, 0, 0, pCursor->bits->width, pCursor->bits->height, 0, XYPixmap, (char *)pCursor->bits->mask); gcvals[0] = GXandInverted; ChangeGC (pGC, GCFunction, gcvals); ValidateGC ((DrawablePtr)pPriv->maskBits, pGC); (*pGC->ops->PutImage) ((DrawablePtr)pPriv->maskBits, pGC, 1, 0, 0, pCursor->bits->width, pCursor->bits->height, 0, XYPixmap, (char *)pCursor->bits->source); FreeScratchGC (pGC); return pPriv;}static BoolmiDCUnrealizeCursor (pScreen, pCursor) ScreenPtr pScreen; CursorPtr pCursor;{ miDCCursorPtr pPriv; pPriv = (miDCCursorPtr) pCursor->bits->devPriv[pScreen->myNum]; if (pPriv && (pCursor->bits->refcnt <= 1)) { (*pScreen->DestroyPixmap) (pPriv->sourceBits); (*pScreen->DestroyPixmap) (pPriv->maskBits); xfree ((pointer) pPriv); pCursor->bits->devPriv[pScreen->myNum] = (pointer)NULL; } return TRUE;}static voidmiDCPutBits (pDrawable, pPriv, sourceGC, maskGC, x, y, w, h, source, mask) DrawablePtr pDrawable; GCPtr sourceGC, maskGC; int x, y; unsigned w, h; miDCCursorPtr pPriv; unsigned long source, mask;{ XID gcvals[1]; if (sourceGC->fgPixel != source) { gcvals[0] = source; DoChangeGC (sourceGC, GCForeground, gcvals, 0); } if (sourceGC->serialNumber != pDrawable->serialNumber) ValidateGC (pDrawable, sourceGC); (*sourceGC->ops->PushPixels) (sourceGC, pPriv->sourceBits, pDrawable, w, h, x, y); if (maskGC->fgPixel != mask) { gcvals[0] = mask; DoChangeGC (maskGC, GCForeground, gcvals, 0); } if (maskGC->serialNumber != pDrawable->serialNumber) ValidateGC (pDrawable, maskGC); (*maskGC->ops->PushPixels) (maskGC, pPriv->maskBits, pDrawable, w, h, x, y);}#define EnsureGC(gc,win) (gc || miDCMakeGC(&gc, win))static GCPtrmiDCMakeGC(ppGC, pWin) GCPtr *ppGC; WindowPtr pWin;{ GCPtr pGC; int status; XID gcvals[2]; gcvals[0] = IncludeInferiors; gcvals[1] = FALSE; pGC = CreateGC((DrawablePtr)pWin, GCSubwindowMode|GCGraphicsExposures, gcvals, &status); if (pGC) (*pWin->drawable.pScreen->DrawGuarantee) (pWin, pGC, GuaranteeVisBack); *ppGC = pGC; return pGC;}static BoolmiDCPutUpCursor (pScreen, pCursor, x, y, source, mask) ScreenPtr pScreen; CursorPtr pCursor; int x, y; unsigned long source, mask;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -