diff options
Diffstat (limited to 'xorg-server/mi')
-rw-r--r-- | xorg-server/mi/makefile | 39 | ||||
-rw-r--r-- | xorg-server/mi/miarc.c | 4 | ||||
-rw-r--r-- | xorg-server/mi/micmap.c | 17 | ||||
-rw-r--r-- | xorg-server/mi/micoord.h | 8 | ||||
-rw-r--r-- | xorg-server/mi/midispcur.c | 1184 | ||||
-rw-r--r-- | xorg-server/mi/mieq.c | 995 | ||||
-rw-r--r-- | xorg-server/mi/miinitext.c | 3 | ||||
-rw-r--r-- | xorg-server/mi/mioverlay.c | 4 | ||||
-rw-r--r-- | xorg-server/mi/mipointrst.h | 114 | ||||
-rw-r--r-- | xorg-server/mi/misprite.c | 13 | ||||
-rw-r--r-- | xorg-server/mi/miwideline.c | 4 |
11 files changed, 1227 insertions, 1158 deletions
diff --git a/xorg-server/mi/makefile b/xorg-server/mi/makefile new file mode 100644 index 000000000..7067c62e8 --- /dev/null +++ b/xorg-server/mi/makefile @@ -0,0 +1,39 @@ +CSRCS=miarc.c \ + mibitblt.c \ + micmap.c \ + micopy.c \ + micursor.c \ + midash.c \ + midispcur.c \ + mieq.c \ + miexpose.c \ + mifillarc.c \ + mifillrct.c \ + mifpolycon.c \ + migc.c \ + miglblt.c \ + mioverlay.c \ + mipointer.c \ + mipoly.c \ + mipolycon.c \ + mipolygen.c \ + mipolypnt.c \ + mipolyrect.c \ + mipolyseg.c \ + mipolytext.c \ + mipolyutil.c \ + mipushpxl.c \ + miscrinit.c \ + mispans.c \ + misprite.c \ + mivaltree.c \ + miwideline.c \ + miwindow.c \ + mizerarc.c \ + mizerclip.c \ + mizerline.c \ + miinitext.c + +LIBRARY=libmi + + diff --git a/xorg-server/mi/miarc.c b/xorg-server/mi/miarc.c index c564eb3db..06fc4085b 100644 --- a/xorg-server/mi/miarc.c +++ b/xorg-server/mi/miarc.c @@ -64,6 +64,10 @@ SOFTWARE. #include "mifillarc.h"
#include <X11/Xfuncproto.h>
+#ifdef _MSC_VER
+#define hypot _hypot
+#endif
+
static double miDsin(double a);
static double miDcos(double a);
static double miDasin(double v);
diff --git a/xorg-server/mi/micmap.c b/xorg-server/mi/micmap.c index 87d4248d0..a92d4fd6d 100644 --- a/xorg-server/mi/micmap.c +++ b/xorg-server/mi/micmap.c @@ -126,18 +126,29 @@ miInitializeColormap(ColormapPtr pmap) unsigned limr, limg, limb;
limr = pVisual->redMask >> pVisual->offsetRed;
- limg = pVisual->greenMask >> pVisual->offsetGreen;
- limb = pVisual->blueMask >> pVisual->offsetBlue;
- for(i = 0; i <= maxent; i++)
+ for(i = 0; i <= min(limr,maxent); i++)
{
/* rescale to [0..65535] then rgb bits */
pmap->red[i].co.local.red =
((((i * 65535) / limr) >> shift) * 65535) / lim;
+ }
+ for(; i <= maxent; i++) pmap->red[i].co.local.red = 65535;
+ limg = pVisual->greenMask >> pVisual->offsetGreen;
+ for(i = 0; i <= min(limg,maxent); i++)
+ {
+ /* rescale to [0..65535] then rgb bits */
pmap->green[i].co.local.green =
((((i * 65535) / limg) >> shift) * 65535) / lim;
+ }
+ for(; i <= maxent; i++) pmap->green[i].co.local.green = 65535;
+ limb = pVisual->blueMask >> pVisual->offsetBlue;
+ for(i = 0; i <= min(limb,maxent); i++)
+ {
+ /* rescale to [0..65535] then rgb bits */
pmap->blue[i].co.local.blue =
((((i * 65535) / limb) >> shift) * 65535) / lim;
}
+ for(; i <= maxent; i++) pmap->blue[i].co.local.blue = 65535;
}
else if (pVisual->class == StaticColor)
{
diff --git a/xorg-server/mi/micoord.h b/xorg-server/mi/micoord.h index e6d814fc8..fe4adac56 100644 --- a/xorg-server/mi/micoord.h +++ b/xorg-server/mi/micoord.h @@ -55,14 +55,14 @@ #endif #if IMAGE_BYTE_ORDER == MSBFirst -#define intToCoord(i,x,y) (((x) = GetHighWord(i)), ((y) = (int) ((short) (i)))) +#define intToCoord(i,x,y) (((x) = GetHighWord(i)), ((y) = (int) ((short) ((i)&0xffff)))) #define coordToInt(x,y) (((x) << 16) | ((y) & 0xffff)) #define intToX(i) (GetHighWord(i)) -#define intToY(i) ((int) ((short) i)) +#define intToY(i) ((int) ((short) ((i)&0xffff))) #else -#define intToCoord(i,x,y) (((x) = (int) ((short) (i))), ((y) = GetHighWord(i))) +#define intToCoord(i,x,y) (((x) = (int) ((short) ((i)&0xffff))), ((y) = GetHighWord(i))) #define coordToInt(x,y) (((y) << 16) | ((x) & 0xffff)) -#define intToX(i) ((int) ((short) (i))) +#define intToX(i) ((int) ((short) ((i)&0xffff))) #define intToY(i) (GetHighWord(i)) #endif diff --git a/xorg-server/mi/midispcur.c b/xorg-server/mi/midispcur.c index 9b3e87a57..3ae157fa3 100644 --- a/xorg-server/mi/midispcur.c +++ b/xorg-server/mi/midispcur.c @@ -1,592 +1,592 @@ -/* - * midispcur.c - * - * machine independent cursor display routines - */ - - -/* - -Copyright 1989, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from The Open Group. -*/ - -#ifdef HAVE_DIX_CONFIG_H -#include <dix-config.h> -#endif - -# include <X11/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" - -#ifdef ARGB_CURSOR -# include "picturestr.h" -#endif - -# include "inputstr.h" - -/* per-screen private data */ -static DevPrivateKeyRec miDCScreenKeyRec; -#define miDCScreenKey (&miDCScreenKeyRec) -static DevScreenPrivateKeyRec miDCCursorBitsKeyRec; -#define miDCCursorBitsKey (&miDCCursorBitsKeyRec) -static DevScreenPrivateKeyRec miDCDeviceKeyRec; -#define miDCDeviceKey (&miDCDeviceKeyRec) - -static Bool miDCCloseScreen(int index, ScreenPtr pScreen); - -/* per device private data */ -typedef struct { - GCPtr pSourceGC, pMaskGC; - GCPtr pSaveGC, pRestoreGC; - PixmapPtr pSave; -#ifdef ARGB_CURSOR - PicturePtr pRootPicture; -#endif -} miDCBufferRec, *miDCBufferPtr; - -#define miGetDCDevice(dev, screen) \ - ((DevHasCursor(dev)) ? \ - (miDCBufferPtr)dixLookupScreenPrivate(&dev->devPrivates, miDCDeviceKey, screen) : \ - (miDCBufferPtr)dixLookupScreenPrivate(&GetMaster(dev, MASTER_POINTER)->devPrivates, miDCDeviceKey, screen)) - -/* - * The core pointer buffer will point to the index of the virtual core pointer - * in the pCursorBuffers array. - */ -typedef struct { - CloseScreenProcPtr CloseScreen; -} miDCScreenRec, *miDCScreenPtr; - -#define miGetDCScreen(s) ((miDCScreenPtr)(dixLookupPrivate(&(s)->devPrivates, miDCScreenKey))) - -/* per-cursor per-screen private data */ -typedef struct { - PixmapPtr sourceBits; /* source bits */ - PixmapPtr maskBits; /* mask bits */ -#ifdef ARGB_CURSOR - PicturePtr pPicture; -#endif -} miDCCursorRec, *miDCCursorPtr; - -Bool -miDCInitialize (ScreenPtr pScreen, miPointerScreenFuncPtr screenFuncs) -{ - miDCScreenPtr pScreenPriv; - - if (!dixRegisterPrivateKey(&miDCScreenKeyRec, PRIVATE_SCREEN, 0) || - !dixRegisterScreenPrivateKey(&miDCCursorBitsKeyRec, pScreen, PRIVATE_CURSOR_BITS, 0) || - !dixRegisterScreenPrivateKey(&miDCDeviceKeyRec, pScreen, PRIVATE_DEVICE, 0)) - return FALSE; - - pScreenPriv = malloc(sizeof (miDCScreenRec)); - if (!pScreenPriv) - return FALSE; - - pScreenPriv->CloseScreen = pScreen->CloseScreen; - pScreen->CloseScreen = miDCCloseScreen; - - dixSetPrivate(&pScreen->devPrivates, miDCScreenKey, pScreenPriv); - - if (!miSpriteInitialize (pScreen, screenFuncs)) - { - free((pointer) pScreenPriv); - return FALSE; - } - return TRUE; -} - -static Bool -miDCCloseScreen (int index, ScreenPtr pScreen) -{ - miDCScreenPtr pScreenPriv; - - pScreenPriv = (miDCScreenPtr)dixLookupPrivate(&pScreen->devPrivates, - miDCScreenKey); - pScreen->CloseScreen = pScreenPriv->CloseScreen; - free((pointer) pScreenPriv); - return (*pScreen->CloseScreen) (index, pScreen); -} - -Bool -miDCRealizeCursor (ScreenPtr pScreen, CursorPtr pCursor) -{ - if (pCursor->bits->refcnt <= 1) - dixSetScreenPrivate(&pCursor->bits->devPrivates, miDCCursorBitsKey, pScreen, NULL); - return TRUE; -} - -#ifdef ARGB_CURSOR -#define EnsurePicture(picture,draw,win) (picture || miDCMakePicture(&picture,draw,win)) - -static VisualPtr -miDCGetWindowVisual (WindowPtr pWin) -{ - ScreenPtr pScreen = pWin->drawable.pScreen; - VisualID vid = wVisual (pWin); - int i; - - for (i = 0; i < pScreen->numVisuals; i++) - if (pScreen->visuals[i].vid == vid) - return &pScreen->visuals[i]; - return 0; -} - -static PicturePtr -miDCMakePicture (PicturePtr *ppPicture, DrawablePtr pDraw, WindowPtr pWin) -{ - ScreenPtr pScreen = pDraw->pScreen; - VisualPtr pVisual; - PictFormatPtr pFormat; - XID subwindow_mode = IncludeInferiors; - PicturePtr pPicture; - int error; - - pVisual = miDCGetWindowVisual (pWin); - if (!pVisual) - return 0; - pFormat = PictureMatchVisual (pScreen, pDraw->depth, pVisual); - if (!pFormat) - return 0; - pPicture = CreatePicture (0, pDraw, pFormat, - CPSubwindowMode, &subwindow_mode, - serverClient, &error); - *ppPicture = pPicture; - return pPicture; -} -#endif - -static miDCCursorPtr -miDCRealize (ScreenPtr pScreen, CursorPtr pCursor) -{ - miDCCursorPtr pPriv; - GCPtr pGC; - ChangeGCVal gcvals; - - pPriv = malloc(sizeof (miDCCursorRec)); - if (!pPriv) - return NULL; -#ifdef ARGB_CURSOR - if (pCursor->bits->argb) - { - PixmapPtr pPixmap; - PictFormatPtr pFormat; - int error; - - pFormat = PictureMatchFormat (pScreen, 32, PICT_a8r8g8b8); - if (!pFormat) - { - free((pointer) pPriv); - return NULL; - } - - pPriv->sourceBits = 0; - pPriv->maskBits = 0; - pPixmap = (*pScreen->CreatePixmap) (pScreen, pCursor->bits->width, - pCursor->bits->height, 32, - CREATE_PIXMAP_USAGE_SCRATCH); - if (!pPixmap) - { - free((pointer) pPriv); - return NULL; - } - pGC = GetScratchGC (32, pScreen); - if (!pGC) - { - (*pScreen->DestroyPixmap) (pPixmap); - free((pointer) pPriv); - return NULL; - } - ValidateGC (&pPixmap->drawable, pGC); - (*pGC->ops->PutImage) (&pPixmap->drawable, pGC, 32, - 0, 0, pCursor->bits->width, - pCursor->bits->height, - 0, ZPixmap, (char *) pCursor->bits->argb); - FreeScratchGC (pGC); - pPriv->pPicture = CreatePicture (0, &pPixmap->drawable, - pFormat, 0, 0, serverClient, &error); - (*pScreen->DestroyPixmap) (pPixmap); - if (!pPriv->pPicture) - { - free((pointer) pPriv); - return NULL; - } - dixSetScreenPrivate(&pCursor->bits->devPrivates, miDCCursorBitsKey, pScreen, pPriv); - return pPriv; - } - pPriv->pPicture = 0; -#endif - pPriv->sourceBits = (*pScreen->CreatePixmap) (pScreen, pCursor->bits->width, pCursor->bits->height, 1, 0); - if (!pPriv->sourceBits) - { - free((pointer) pPriv); - return NULL; - } - pPriv->maskBits = (*pScreen->CreatePixmap) (pScreen, pCursor->bits->width, pCursor->bits->height, 1, 0); - if (!pPriv->maskBits) - { - (*pScreen->DestroyPixmap) (pPriv->sourceBits); - free((pointer) pPriv); - return NULL; - } - dixSetScreenPrivate(&pCursor->bits->devPrivates, miDCCursorBitsKey, pScreen, pPriv); - - /* create the two sets of bits, clipping as appropriate */ - - pGC = GetScratchGC (1, pScreen); - if (!pGC) - { - (void) miDCUnrealizeCursor (pScreen, pCursor); - return 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.val = GXand; - ChangeGC (NullClient, 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.val = GXcopy; - ChangeGC (NullClient, 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.val = GXandInverted; - ChangeGC (NullClient, 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; -} - -Bool -miDCUnrealizeCursor (ScreenPtr pScreen, CursorPtr pCursor) -{ - miDCCursorPtr pPriv; - - pPriv = (miDCCursorPtr)dixLookupScreenPrivate(&pCursor->bits->devPrivates, - miDCCursorBitsKey, pScreen); - if (pPriv && (pCursor->bits->refcnt <= 1)) - { - if (pPriv->sourceBits) - (*pScreen->DestroyPixmap) (pPriv->sourceBits); - if (pPriv->maskBits) - (*pScreen->DestroyPixmap) (pPriv->maskBits); -#ifdef ARGB_CURSOR - if (pPriv->pPicture) - FreePicture (pPriv->pPicture, 0); -#endif - free((pointer) pPriv); - dixSetScreenPrivate(&pCursor->bits->devPrivates, miDCCursorBitsKey, pScreen, NULL); - } - return TRUE; -} - -static void -miDCPutBits ( - DrawablePtr pDrawable, - miDCCursorPtr pPriv, - GCPtr sourceGC, - GCPtr maskGC, - int x_org, - int y_org, - unsigned w, - unsigned h, - unsigned long source, - unsigned long mask) -{ - ChangeGCVal gcval; - int x, y; - - if (sourceGC->fgPixel != source) - { - gcval.val = source; - ChangeGC (NullClient, sourceGC, GCForeground, &gcval); - } - if (sourceGC->serialNumber != pDrawable->serialNumber) - ValidateGC (pDrawable, sourceGC); - - if(sourceGC->miTranslate) - { - x = pDrawable->x + x_org; - y = pDrawable->y + y_org; - } - else - { - x = x_org; - y = y_org; - } - - (*sourceGC->ops->PushPixels) (sourceGC, pPriv->sourceBits, pDrawable, w, h, x, y); - if (maskGC->fgPixel != mask) - { - gcval.val = mask; - ChangeGC (NullClient, maskGC, GCForeground, &gcval); - } - if (maskGC->serialNumber != pDrawable->serialNumber) - ValidateGC (pDrawable, maskGC); - - if(maskGC->miTranslate) - { - x = pDrawable->x + x_org; - y = pDrawable->y + y_org; - } - else - { - x = x_org; - y = y_org; - } - - (*maskGC->ops->PushPixels) (maskGC, pPriv->maskBits, pDrawable, w, h, x, y); -} - -static GCPtr -miDCMakeGC(WindowPtr pWin) -{ - GCPtr pGC; - int status; - XID gcvals[2]; - - gcvals[0] = IncludeInferiors; - gcvals[1] = FALSE; - pGC = CreateGC((DrawablePtr)pWin, - GCSubwindowMode|GCGraphicsExposures, gcvals, &status, - (XID)0, serverClient); - return pGC; -} - - -Bool -miDCPutUpCursor (DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor, - int x, int y, unsigned long source, unsigned long mask) -{ - miDCScreenPtr pScreenPriv; - miDCCursorPtr pPriv; - miDCBufferPtr pBuffer; - WindowPtr pWin; - - pPriv = (miDCCursorPtr)dixLookupScreenPrivate(&pCursor->bits->devPrivates, - miDCCursorBitsKey, pScreen); - if (!pPriv) - { - pPriv = miDCRealize(pScreen, pCursor); - if (!pPriv) - return FALSE; - } - pScreenPriv = (miDCScreenPtr)dixLookupPrivate(&pScreen->devPrivates, - miDCScreenKey); - pWin = pScreen->root; - pBuffer = miGetDCDevice(pDev, pScreen); - -#ifdef ARGB_CURSOR - if (pPriv->pPicture) - { - if (!EnsurePicture(pBuffer->pRootPicture, &pWin->drawable, pWin)) - return FALSE; - CompositePicture (PictOpOver, - pPriv->pPicture, - NULL, - pBuffer->pRootPicture, - 0, 0, 0, 0, - x, y, - pCursor->bits->width, - pCursor->bits->height); - } - else -#endif - { - miDCPutBits ((DrawablePtr)pWin, pPriv, - pBuffer->pSourceGC, pBuffer->pMaskGC, - x, y, pCursor->bits->width, pCursor->bits->height, - source, mask); - } - return TRUE; -} - -Bool -miDCSaveUnderCursor (DeviceIntPtr pDev, ScreenPtr pScreen, - int x, int y, int w, int h) -{ - miDCScreenPtr pScreenPriv; - miDCBufferPtr pBuffer; - PixmapPtr pSave; - WindowPtr pWin; - GCPtr pGC; - - pScreenPriv = (miDCScreenPtr)dixLookupPrivate(&pScreen->devPrivates, - miDCScreenKey); - pBuffer = miGetDCDevice(pDev, pScreen); - - pSave = pBuffer->pSave; - pWin = pScreen->root; - if (!pSave || pSave->drawable.width < w || pSave->drawable.height < h) - { - if (pSave) - (*pScreen->DestroyPixmap) (pSave); - pBuffer->pSave = pSave = - (*pScreen->CreatePixmap) (pScreen, w, h, pScreen->rootDepth, 0); - if (!pSave) - return FALSE; - } - - pGC = pBuffer->pSaveGC; - if (pSave->drawable.serialNumber != pGC->serialNumber) - ValidateGC ((DrawablePtr) pSave, pGC); - (*pGC->ops->CopyArea) ((DrawablePtr) pWin, (DrawablePtr) pSave, pGC, - x, y, w, h, 0, 0); - return TRUE; -} - -Bool -miDCRestoreUnderCursor (DeviceIntPtr pDev, ScreenPtr pScreen, - int x, int y, int w, int h) -{ - miDCScreenPtr pScreenPriv; - miDCBufferPtr pBuffer; - PixmapPtr pSave; - WindowPtr pWin; - GCPtr pGC; - - pScreenPriv = (miDCScreenPtr)dixLookupPrivate(&pScreen->devPrivates, - miDCScreenKey); - pBuffer = miGetDCDevice(pDev, pScreen); - pSave = pBuffer->pSave; - - pWin = pScreen->root; - if (!pSave) - return FALSE; - - pGC = pBuffer->pRestoreGC; - if (pWin->drawable.serialNumber != pGC->serialNumber) - ValidateGC ((DrawablePtr) pWin, pGC); - (*pGC->ops->CopyArea) ((DrawablePtr) pSave, (DrawablePtr) pWin, pGC, - 0, 0, w, h, x, y); - return TRUE; -} - -Bool -miDCDeviceInitialize(DeviceIntPtr pDev, ScreenPtr pScreen) -{ - miDCBufferPtr pBuffer; - WindowPtr pWin; - int i; - - if (!DevHasCursor(pDev)) - return TRUE; - - for (i = 0; i < screenInfo.numScreens; i++) - { - pScreen = screenInfo.screens[i]; - - pBuffer = calloc(1, sizeof(miDCBufferRec)); - if (!pBuffer) - goto failure; - - dixSetScreenPrivate(&pDev->devPrivates, miDCDeviceKey, pScreen, pBuffer); - pWin = pScreen->root; - - pBuffer->pSourceGC = miDCMakeGC(pWin); - if (!pBuffer->pSourceGC) - goto failure; - - pBuffer->pMaskGC = miDCMakeGC(pWin); - if (!pBuffer->pMaskGC) - goto failure; - - pBuffer->pSaveGC = miDCMakeGC(pWin); - if (!pBuffer->pSaveGC) - goto failure; - - pBuffer->pRestoreGC = miDCMakeGC(pWin); - if (!pBuffer->pRestoreGC) - goto failure; - -#ifdef ARGB_CURSOR - pBuffer->pRootPicture = NULL; -#endif - - /* (re)allocated lazily depending on the cursor size */ - pBuffer->pSave = NULL; - } - - return TRUE; - -failure: - - miDCDeviceCleanup(pDev, pScreen); - - return FALSE; -} - -void -miDCDeviceCleanup(DeviceIntPtr pDev, ScreenPtr pScreen) -{ - miDCBufferPtr pBuffer; - int i; - - if (DevHasCursor(pDev)) - { - for (i = 0; i < screenInfo.numScreens; i++) - { - pScreen = screenInfo.screens[i]; - - pBuffer = miGetDCDevice(pDev, pScreen); - - if (pBuffer) - { - if (pBuffer->pSourceGC) FreeGC(pBuffer->pSourceGC, (GContext) 0); - if (pBuffer->pMaskGC) FreeGC(pBuffer->pMaskGC, (GContext) 0); - if (pBuffer->pSaveGC) FreeGC(pBuffer->pSaveGC, (GContext) 0); - if (pBuffer->pRestoreGC) FreeGC(pBuffer->pRestoreGC, (GContext) 0); - -#ifdef ARGB_CURSOR - /* If a pRootPicture was allocated for a root window, it - * is freed when that root window is destroyed, so don't - * free it again here. */ -#endif - - if (pBuffer->pSave) (*pScreen->DestroyPixmap)(pBuffer->pSave); - - free(pBuffer); - dixSetScreenPrivate(&pDev->devPrivates, miDCDeviceKey, pScreen, NULL); - } - } - } -} +/*
+ * midispcur.c
+ *
+ * machine independent cursor display routines
+ */
+
+
+/*
+
+Copyright 1989, 1998 The Open Group
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+*/
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+# include <X11/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"
+
+#ifdef ARGB_CURSOR
+# include "picturestr.h"
+#endif
+
+# include "inputstr.h"
+
+/* per-screen private data */
+static DevPrivateKeyRec miDCScreenKeyRec;
+#define miDCScreenKey (&miDCScreenKeyRec)
+static DevScreenPrivateKeyRec miDCCursorBitsKeyRec;
+#define miDCCursorBitsKey (&miDCCursorBitsKeyRec)
+static DevScreenPrivateKeyRec miDCDeviceKeyRec;
+#define miDCDeviceKey (&miDCDeviceKeyRec)
+
+static Bool miDCCloseScreen(int index, ScreenPtr pScreen);
+
+/* per device private data */
+typedef struct {
+ GCPtr pSourceGC, pMaskGC;
+ GCPtr pSaveGC, pRestoreGC;
+ PixmapPtr pSave;
+#ifdef ARGB_CURSOR
+ PicturePtr pRootPicture;
+#endif
+} miDCBufferRec, *miDCBufferPtr;
+
+#define miGetDCDevice(dev, screen) \
+ ((DevHasCursor(dev)) ? \
+ (miDCBufferPtr)dixLookupScreenPrivate(&dev->devPrivates, miDCDeviceKey, screen) : \
+ (miDCBufferPtr)dixLookupScreenPrivate(&GetMaster(dev, MASTER_POINTER)->devPrivates, miDCDeviceKey, screen))
+
+/*
+ * The core pointer buffer will point to the index of the virtual core pointer
+ * in the pCursorBuffers array.
+ */
+typedef struct {
+ CloseScreenProcPtr CloseScreen;
+} miDCScreenRec, *miDCScreenPtr;
+
+#define miGetDCScreen(s) ((miDCScreenPtr)(dixLookupPrivate(&(s)->devPrivates, miDCScreenKey)))
+
+/* per-cursor per-screen private data */
+typedef struct {
+ PixmapPtr sourceBits; /* source bits */
+ PixmapPtr maskBits; /* mask bits */
+#ifdef ARGB_CURSOR
+ PicturePtr pPicture;
+#endif
+} miDCCursorRec, *miDCCursorPtr;
+
+Bool
+miDCInitialize (ScreenPtr pScreen, miPointerScreenFuncPtr screenFuncs)
+{
+ miDCScreenPtr pScreenPriv;
+
+ if (!dixRegisterPrivateKey(&miDCScreenKeyRec, PRIVATE_SCREEN, 0) ||
+ !dixRegisterScreenPrivateKey(&miDCCursorBitsKeyRec, pScreen, PRIVATE_CURSOR_BITS, 0) ||
+ !dixRegisterScreenPrivateKey(&miDCDeviceKeyRec, pScreen, PRIVATE_DEVICE, 0))
+ return FALSE;
+
+ pScreenPriv = malloc(sizeof (miDCScreenRec));
+ if (!pScreenPriv)
+ return FALSE;
+
+ pScreenPriv->CloseScreen = pScreen->CloseScreen;
+ pScreen->CloseScreen = miDCCloseScreen;
+
+ dixSetPrivate(&pScreen->devPrivates, miDCScreenKey, pScreenPriv);
+
+ if (!miSpriteInitialize (pScreen, screenFuncs))
+ {
+ free((pointer) pScreenPriv);
+ return FALSE;
+ }
+ return TRUE;
+}
+
+static Bool
+miDCCloseScreen (int index, ScreenPtr pScreen)
+{
+ miDCScreenPtr pScreenPriv;
+
+ pScreenPriv = (miDCScreenPtr)dixLookupPrivate(&pScreen->devPrivates,
+ miDCScreenKey);
+ pScreen->CloseScreen = pScreenPriv->CloseScreen;
+ free((pointer) pScreenPriv);
+ return (*pScreen->CloseScreen) (index, pScreen);
+}
+
+Bool
+miDCRealizeCursor (ScreenPtr pScreen, CursorPtr pCursor)
+{
+ if (pCursor->bits->refcnt <= 1)
+ dixSetScreenPrivate(&pCursor->bits->devPrivates, miDCCursorBitsKey, pScreen, NULL);
+ return TRUE;
+}
+
+#ifdef ARGB_CURSOR
+#define EnsurePicture(picture,draw,win) (picture || miDCMakePicture(&picture,draw,win))
+
+static VisualPtr
+miDCGetWindowVisual (WindowPtr pWin)
+{
+ ScreenPtr pScreen = pWin->drawable.pScreen;
+ VisualID vid = wVisual (pWin);
+ int i;
+
+ for (i = 0; i < pScreen->numVisuals; i++)
+ if (pScreen->visuals[i].vid == vid)
+ return &pScreen->visuals[i];
+ return 0;
+}
+
+static PicturePtr
+miDCMakePicture (PicturePtr *ppPicture, DrawablePtr pDraw, WindowPtr pWin)
+{
+ ScreenPtr pScreen = pDraw->pScreen;
+ VisualPtr pVisual;
+ PictFormatPtr pFormat;
+ XID subwindow_mode = IncludeInferiors;
+ PicturePtr pPicture;
+ int error;
+
+ pVisual = miDCGetWindowVisual (pWin);
+ if (!pVisual)
+ return 0;
+ pFormat = PictureMatchVisual (pScreen, pDraw->depth, pVisual);
+ if (!pFormat)
+ return 0;
+ pPicture = CreatePicture (0, pDraw, pFormat,
+ CPSubwindowMode, &subwindow_mode,
+ serverClient, &error);
+ *ppPicture = pPicture;
+ return pPicture;
+}
+#endif
+
+static miDCCursorPtr
+miDCRealize (ScreenPtr pScreen, CursorPtr pCursor)
+{
+ miDCCursorPtr pPriv;
+ GCPtr pGC;
+ ChangeGCVal gcvals;
+
+ pPriv = malloc(sizeof (miDCCursorRec));
+ if (!pPriv)
+ return NULL;
+#ifdef ARGB_CURSOR
+ if (pCursor->bits->argb)
+ {
+ PixmapPtr pPixmap;
+ PictFormatPtr pFormat;
+ int error;
+
+ pFormat = PictureMatchFormat (pScreen, 32, PICT_a8r8g8b8);
+ if (!pFormat)
+ {
+ free((pointer) pPriv);
+ return NULL;
+ }
+
+ pPriv->sourceBits = 0;
+ pPriv->maskBits = 0;
+ pPixmap = (*pScreen->CreatePixmap) (pScreen, pCursor->bits->width,
+ pCursor->bits->height, 32,
+ CREATE_PIXMAP_USAGE_SCRATCH);
+ if (!pPixmap)
+ {
+ free((pointer) pPriv);
+ return NULL;
+ }
+ pGC = GetScratchGC (32, pScreen);
+ if (!pGC)
+ {
+ (*pScreen->DestroyPixmap) (pPixmap);
+ free((pointer) pPriv);
+ return NULL;
+ }
+ ValidateGC (&pPixmap->drawable, pGC);
+ (*pGC->ops->PutImage) (&pPixmap->drawable, pGC, 32,
+ 0, 0, pCursor->bits->width,
+ pCursor->bits->height,
+ 0, ZPixmap, (char *) pCursor->bits->argb);
+ FreeScratchGC (pGC);
+ pPriv->pPicture = CreatePicture (0, &pPixmap->drawable,
+ pFormat, 0, 0, serverClient, &error);
+ (*pScreen->DestroyPixmap) (pPixmap);
+ if (!pPriv->pPicture)
+ {
+ free((pointer) pPriv);
+ return NULL;
+ }
+ dixSetScreenPrivate(&pCursor->bits->devPrivates, miDCCursorBitsKey, pScreen, pPriv);
+ return pPriv;
+ }
+ pPriv->pPicture = 0;
+#endif
+ pPriv->sourceBits = (*pScreen->CreatePixmap) (pScreen, pCursor->bits->width, pCursor->bits->height, 1, 0);
+ if (!pPriv->sourceBits)
+ {
+ free((pointer) pPriv);
+ return NULL;
+ }
+ pPriv->maskBits = (*pScreen->CreatePixmap) (pScreen, pCursor->bits->width, pCursor->bits->height, 1, 0);
+ if (!pPriv->maskBits)
+ {
+ (*pScreen->DestroyPixmap) (pPriv->sourceBits);
+ free((pointer) pPriv);
+ return NULL;
+ }
+ dixSetScreenPrivate(&pCursor->bits->devPrivates, miDCCursorBitsKey, pScreen, pPriv);
+
+ /* create the two sets of bits, clipping as appropriate */
+
+ pGC = GetScratchGC (1, pScreen);
+ if (!pGC)
+ {
+ (void) miDCUnrealizeCursor (pScreen, pCursor);
+ return 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.val = GXand;
+ ChangeGC (NullClient, 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.val = GXcopy;
+ ChangeGC (NullClient, 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.val = GXandInverted;
+ ChangeGC (NullClient, 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;
+}
+
+Bool
+miDCUnrealizeCursor (ScreenPtr pScreen, CursorPtr pCursor)
+{
+ miDCCursorPtr pPriv;
+
+ pPriv = (miDCCursorPtr)dixLookupScreenPrivate(&pCursor->bits->devPrivates,
+ miDCCursorBitsKey, pScreen);
+ if (pPriv && (pCursor->bits->refcnt <= 1))
+ {
+ if (pPriv->sourceBits)
+ (*pScreen->DestroyPixmap) (pPriv->sourceBits);
+ if (pPriv->maskBits)
+ (*pScreen->DestroyPixmap) (pPriv->maskBits);
+#ifdef ARGB_CURSOR
+ if (pPriv->pPicture)
+ FreePicture (pPriv->pPicture, 0);
+#endif
+ free((pointer) pPriv);
+ dixSetScreenPrivate(&pCursor->bits->devPrivates, miDCCursorBitsKey, pScreen, NULL);
+ }
+ return TRUE;
+}
+
+static void
+miDCPutBits (
+ DrawablePtr pDrawable,
+ miDCCursorPtr pPriv,
+ GCPtr sourceGC,
+ GCPtr maskGC,
+ int x_org,
+ int y_org,
+ unsigned w,
+ unsigned h,
+ unsigned long source,
+ unsigned long mask)
+{
+ ChangeGCVal gcval;
+ int x, y;
+
+ if (sourceGC->fgPixel != source)
+ {
+ gcval.val = source;
+ ChangeGC (NullClient, sourceGC, GCForeground, &gcval);
+ }
+ if (sourceGC->serialNumber != pDrawable->serialNumber)
+ ValidateGC (pDrawable, sourceGC);
+
+ if(sourceGC->miTranslate)
+ {
+ x = pDrawable->x + x_org;
+ y = pDrawable->y + y_org;
+ }
+ else
+ {
+ x = x_org;
+ y = y_org;
+ }
+
+ (*sourceGC->ops->PushPixels) (sourceGC, pPriv->sourceBits, pDrawable, w, h, x, y);
+ if (maskGC->fgPixel != mask)
+ {
+ gcval.val = mask;
+ ChangeGC (NullClient, maskGC, GCForeground, &gcval);
+ }
+ if (maskGC->serialNumber != pDrawable->serialNumber)
+ ValidateGC (pDrawable, maskGC);
+
+ if(maskGC->miTranslate)
+ {
+ x = pDrawable->x + x_org;
+ y = pDrawable->y + y_org;
+ }
+ else
+ {
+ x = x_org;
+ y = y_org;
+ }
+
+ (*maskGC->ops->PushPixels) (maskGC, pPriv->maskBits, pDrawable, w, h, x, y);
+}
+
+static GCPtr
+miDCMakeGC(WindowPtr pWin)
+{
+ GCPtr pGC;
+ int status;
+ XID gcvals[2];
+
+ gcvals[0] = IncludeInferiors;
+ gcvals[1] = FALSE;
+ pGC = CreateGC((DrawablePtr)pWin,
+ GCSubwindowMode|GCGraphicsExposures, gcvals, &status,
+ (XID)0, serverClient);
+ return pGC;
+}
+
+
+Bool
+miDCPutUpCursor (DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor,
+ int x, int y, unsigned long source, unsigned long mask)
+{
+ miDCScreenPtr pScreenPriv;
+ miDCCursorPtr pPriv;
+ miDCBufferPtr pBuffer;
+ WindowPtr pWin;
+
+ pPriv = (miDCCursorPtr)dixLookupScreenPrivate(&pCursor->bits->devPrivates,
+ miDCCursorBitsKey, pScreen);
+ if (!pPriv)
+ {
+ pPriv = miDCRealize(pScreen, pCursor);
+ if (!pPriv)
+ return FALSE;
+ }
+ pScreenPriv = (miDCScreenPtr)dixLookupPrivate(&pScreen->devPrivates,
+ miDCScreenKey);
+ pWin = pScreen->root;
+ pBuffer = miGetDCDevice(pDev, pScreen);
+
+#ifdef ARGB_CURSOR
+ if (pPriv->pPicture)
+ {
+ if (!EnsurePicture(pBuffer->pRootPicture, &pWin->drawable, pWin))
+ return FALSE;
+ CompositePicture (PictOpOver,
+ pPriv->pPicture,
+ NULL,
+ pBuffer->pRootPicture,
+ 0, 0, 0, 0,
+ x, y,
+ pCursor->bits->width,
+ pCursor->bits->height);
+ }
+ else
+#endif
+ {
+ miDCPutBits ((DrawablePtr)pWin, pPriv,
+ pBuffer->pSourceGC, pBuffer->pMaskGC,
+ x, y, pCursor->bits->width, pCursor->bits->height,
+ source, mask);
+ }
+ return TRUE;
+}
+
+Bool
+miDCSaveUnderCursor (DeviceIntPtr pDev, ScreenPtr pScreen,
+ int x, int y, int w, int h)
+{
+ miDCScreenPtr pScreenPriv;
+ miDCBufferPtr pBuffer;
+ PixmapPtr pSave;
+ WindowPtr pWin;
+ GCPtr pGC;
+
+ pScreenPriv = (miDCScreenPtr)dixLookupPrivate(&pScreen->devPrivates,
+ miDCScreenKey);
+ pBuffer = miGetDCDevice(pDev, pScreen);
+
+ pSave = pBuffer->pSave;
+ pWin = pScreen->root;
+ if (!pSave || pSave->drawable.width < w || pSave->drawable.height < h)
+ {
+ if (pSave)
+ (*pScreen->DestroyPixmap) (pSave);
+ pBuffer->pSave = pSave =
+ (*pScreen->CreatePixmap) (pScreen, w, h, pScreen->rootDepth, 0);
+ if (!pSave)
+ return FALSE;
+ }
+
+ pGC = pBuffer->pSaveGC;
+ if (pSave->drawable.serialNumber != pGC->serialNumber)
+ ValidateGC ((DrawablePtr) pSave, pGC);
+ (*pGC->ops->CopyArea) ((DrawablePtr) pWin, (DrawablePtr) pSave, pGC,
+ x, y, w, h, 0, 0);
+ return TRUE;
+}
+
+Bool
+miDCRestoreUnderCursor (DeviceIntPtr pDev, ScreenPtr pScreen,
+ int x, int y, int w, int h)
+{
+ miDCScreenPtr pScreenPriv;
+ miDCBufferPtr pBuffer;
+ PixmapPtr pSave;
+ WindowPtr pWin;
+ GCPtr pGC;
+
+ pScreenPriv = (miDCScreenPtr)dixLookupPrivate(&pScreen->devPrivates,
+ miDCScreenKey);
+ pBuffer = miGetDCDevice(pDev, pScreen);
+ pSave = pBuffer->pSave;
+
+ pWin = pScreen->root;
+ if (!pSave)
+ return FALSE;
+
+ pGC = pBuffer->pRestoreGC;
+ if (pWin->drawable.serialNumber != pGC->serialNumber)
+ ValidateGC ((DrawablePtr) pWin, pGC);
+ (*pGC->ops->CopyArea) ((DrawablePtr) pSave, (DrawablePtr) pWin, pGC,
+ 0, 0, w, h, x, y);
+ return TRUE;
+}
+
+Bool
+miDCDeviceInitialize(DeviceIntPtr pDev, ScreenPtr pScreen)
+{
+ miDCBufferPtr pBuffer;
+ WindowPtr pWin;
+ int i;
+
+ if (!DevHasCursor(pDev))
+ return TRUE;
+
+ for (i = 0; i < screenInfo.numScreens; i++)
+ {
+ pScreen = screenInfo.screens[i];
+
+ pBuffer = calloc(1, sizeof(miDCBufferRec));
+ if (!pBuffer)
+ goto failure;
+
+ dixSetScreenPrivate(&pDev->devPrivates, miDCDeviceKey, pScreen, pBuffer);
+ pWin = pScreen->root;
+
+ pBuffer->pSourceGC = miDCMakeGC(pWin);
+ if (!pBuffer->pSourceGC)
+ goto failure;
+
+ pBuffer->pMaskGC = miDCMakeGC(pWin);
+ if (!pBuffer->pMaskGC)
+ goto failure;
+
+ pBuffer->pSaveGC = miDCMakeGC(pWin);
+ if (!pBuffer->pSaveGC)
+ goto failure;
+
+ pBuffer->pRestoreGC = miDCMakeGC(pWin);
+ if (!pBuffer->pRestoreGC)
+ goto failure;
+
+#ifdef ARGB_CURSOR
+ pBuffer->pRootPicture = NULL;
+#endif
+
+ /* (re)allocated lazily depending on the cursor size */
+ pBuffer->pSave = NULL;
+ }
+
+ return TRUE;
+
+failure:
+
+ miDCDeviceCleanup(pDev, pScreen);
+
+ return FALSE;
+}
+
+void
+miDCDeviceCleanup(DeviceIntPtr pDev, ScreenPtr pScreen)
+{
+ miDCBufferPtr pBuffer;
+ int i;
+
+ if (DevHasCursor(pDev))
+ {
+ for (i = 0; i < screenInfo.numScreens; i++)
+ {
+ pScreen = screenInfo.screens[i];
+
+ pBuffer = miGetDCDevice(pDev, pScreen);
+
+ if (pBuffer)
+ {
+ if (pBuffer->pSourceGC) FreeGC(pBuffer->pSourceGC, (GContext) 0);
+ if (pBuffer->pMaskGC) FreeGC(pBuffer->pMaskGC, (GContext) 0);
+ if (pBuffer->pSaveGC) FreeGC(pBuffer->pSaveGC, (GContext) 0);
+ if (pBuffer->pRestoreGC) FreeGC(pBuffer->pRestoreGC, (GContext) 0);
+
+#ifdef ARGB_CURSOR
+ /* If a pRootPicture was allocated for a root window, it
+ * is freed when that root window is destroyed, so don't
+ * free it again here. */
+#endif
+
+ if (pBuffer->pSave) (*pScreen->DestroyPixmap)(pBuffer->pSave);
+
+ free(pBuffer);
+ dixSetScreenPrivate(&pDev->devPrivates, miDCDeviceKey, pScreen, NULL);
+ }
+ }
+ }
+}
diff --git a/xorg-server/mi/mieq.c b/xorg-server/mi/mieq.c index 08a0c8758..a8daf572b 100644 --- a/xorg-server/mi/mieq.c +++ b/xorg-server/mi/mieq.c @@ -1,497 +1,498 @@ -/* - * -Copyright 1990, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from The Open Group. - * - * Author: Keith Packard, MIT X Consortium - */ - -/* - * mieq.c - * - * Machine independent event queue - * - */ - -#if HAVE_DIX_CONFIG_H -#include <dix-config.h> -#endif - -# include <X11/X.h> -# include <X11/Xmd.h> -# include <X11/Xproto.h> -# include "misc.h" -# include "windowstr.h" -# include "pixmapstr.h" -# include "inputstr.h" -# include "mi.h" -# include "mipointer.h" -# include "scrnintstr.h" -# include <X11/extensions/XI.h> -# include <X11/extensions/XIproto.h> -# include <X11/extensions/geproto.h> -# include "extinit.h" -# include "exglobals.h" -# include "eventstr.h" - -#ifdef DPMSExtension -# include "dpmsproc.h" -# include <X11/extensions/dpmsconst.h> -#endif - -#define QUEUE_SIZE 512 - -#define EnqueueScreen(dev) dev->spriteInfo->sprite->pEnqueueScreen -#define DequeueScreen(dev) dev->spriteInfo->sprite->pDequeueScreen - -typedef struct _Event { - EventListPtr events; - ScreenPtr pScreen; - DeviceIntPtr pDev; /* device this event _originated_ from */ -} EventRec, *EventPtr; - -typedef struct _EventQueue { - HWEventQueueType head, tail; /* long for SetInputCheck */ - CARD32 lastEventTime; /* to avoid time running backwards */ - int lastMotion; /* device ID if last event motion? */ - EventRec events[QUEUE_SIZE]; /* static allocation for signals */ - mieqHandler handlers[128]; /* custom event handler */ -} EventQueueRec, *EventQueuePtr; - -static EventQueueRec miEventQueue; - -#ifdef XQUARTZ -#include <pthread.h> -static pthread_mutex_t miEventQueueMutex = PTHREAD_MUTEX_INITIALIZER; - -extern BOOL serverInitComplete; -extern pthread_mutex_t serverInitCompleteMutex; -extern pthread_cond_t serverInitCompleteCond; - -static inline void wait_for_server_init(void) { - /* If the server hasn't finished initializing, wait for it... */ - if(!serverInitComplete) { - pthread_mutex_lock(&serverInitCompleteMutex); - while(!serverInitComplete) - pthread_cond_wait(&serverInitCompleteCond, &serverInitCompleteMutex); - pthread_mutex_unlock(&serverInitCompleteMutex); - } -} -#endif - -Bool -mieqInit(void) -{ - int i; - - miEventQueue.head = miEventQueue.tail = 0; - miEventQueue.lastEventTime = GetTimeInMillis (); - miEventQueue.lastMotion = FALSE; - for (i = 0; i < 128; i++) - miEventQueue.handlers[i] = NULL; - for (i = 0; i < QUEUE_SIZE; i++) - { - if (miEventQueue.events[i].events == NULL) { - EventListPtr evlist = InitEventList(1); - if (!evlist) - FatalError("Could not allocate event queue.\n"); - miEventQueue.events[i].events = evlist; - } - } - - SetInputCheck(&miEventQueue.head, &miEventQueue.tail); - return TRUE; -} - -void -mieqFini(void) -{ - int i; - for (i = 0; i < QUEUE_SIZE; i++) - { - if (miEventQueue.events[i].events != NULL) { - FreeEventList(miEventQueue.events[i].events, 1); - miEventQueue.events[i].events = NULL; - } - } -} - -/* - * Must be reentrant with ProcessInputEvents. Assumption: mieqEnqueue - * will never be interrupted. If this is called from both signal - * handlers and regular code, make sure the signal is suspended when - * called from regular code. - */ - -void -mieqEnqueue(DeviceIntPtr pDev, InternalEvent *e) -{ - unsigned int oldtail = miEventQueue.tail; - EventListPtr evt; - int isMotion = 0; - int evlen; - Time time; - -#ifdef XQUARTZ - wait_for_server_init(); - pthread_mutex_lock(&miEventQueueMutex); -#endif - - CHECKEVENT(e); - - /* avoid merging events from different devices */ - if (e->any.type == ET_Motion) - isMotion = pDev->id; - - if (isMotion && isMotion == miEventQueue.lastMotion && - oldtail != miEventQueue.head) { - oldtail = (oldtail - 1) % QUEUE_SIZE; - } - else { - static int stuck = 0; - /* Toss events which come in late. Usually this means your server's - * stuck in an infinite loop somewhere, but SIGIO is still getting - * handled. */ - if (((oldtail + 1) % QUEUE_SIZE) == miEventQueue.head) { - if (!stuck) { - ErrorF("[mi] EQ overflowing. The server is probably stuck " - "in an infinite loop.\n"); - xorg_backtrace(); - stuck = 1; - } -#ifdef XQUARTZ - pthread_mutex_unlock(&miEventQueueMutex); -#endif - return; - } - stuck = 0; - } - - evlen = e->any.length; - evt = miEventQueue.events[oldtail].events; - if (evt->evlen < evlen) - { - evt->evlen = evlen; - evt->event = realloc(evt->event, evt->evlen); - if (!evt->event) - { - ErrorF("[mi] Running out of memory. Tossing event.\n"); -#ifdef XQUARTZ - pthread_mutex_unlock(&miEventQueueMutex); -#endif - return; - } - } - - memcpy(evt->event, e, evlen); - - time = e->any.time; - /* Make sure that event times don't go backwards - this - * is "unnecessary", but very useful. */ - if (time < miEventQueue.lastEventTime && - miEventQueue.lastEventTime - time < 10000) - e->any.time = miEventQueue.lastEventTime; - - miEventQueue.lastEventTime = ((InternalEvent*)evt->event)->any.time; - miEventQueue.events[oldtail].pScreen = pDev ? EnqueueScreen(pDev) : NULL; - miEventQueue.events[oldtail].pDev = pDev; - - miEventQueue.lastMotion = isMotion; - miEventQueue.tail = (oldtail + 1) % QUEUE_SIZE; -#ifdef XQUARTZ - pthread_mutex_unlock(&miEventQueueMutex); -#endif -} - -void -mieqSwitchScreen(DeviceIntPtr pDev, ScreenPtr pScreen, Bool fromDIX) -{ -#ifdef XQUARTZ - pthread_mutex_lock(&miEventQueueMutex); -#endif - EnqueueScreen(pDev) = pScreen; - if (fromDIX) - DequeueScreen(pDev) = pScreen; -#ifdef XQUARTZ - pthread_mutex_unlock(&miEventQueueMutex); -#endif -} - -void -mieqSetHandler(int event, mieqHandler handler) -{ -#ifdef XQUARTZ - pthread_mutex_lock(&miEventQueueMutex); -#endif - if (handler && miEventQueue.handlers[event]) - ErrorF("[mi] mieq: warning: overriding existing handler %p with %p for " - "event %d\n", miEventQueue.handlers[event], handler, event); - - miEventQueue.handlers[event] = handler; -#ifdef XQUARTZ - pthread_mutex_unlock(&miEventQueueMutex); -#endif -} - -/** - * Change the device id of the given event to the given device's id. - */ -static void -ChangeDeviceID(DeviceIntPtr dev, InternalEvent* event) -{ - switch(event->any.type) - { - case ET_Motion: - case ET_KeyPress: - case ET_KeyRelease: - case ET_ButtonPress: - case ET_ButtonRelease: - case ET_ProximityIn: - case ET_ProximityOut: - case ET_Hierarchy: - case ET_DeviceChanged: - event->device_event.deviceid = dev->id; - break; -#if XFreeXDGA - case ET_DGAEvent: - break; -#endif - case ET_RawKeyPress: - case ET_RawKeyRelease: - case ET_RawButtonPress: - case ET_RawButtonRelease: - case ET_RawMotion: - event->raw_event.deviceid = dev->id; - break; - default: - ErrorF("[mi] Unknown event type (%d), cannot change id.\n", - event->any.type); - } -} - -static void -FixUpEventForMaster(DeviceIntPtr mdev, DeviceIntPtr sdev, - InternalEvent* original, InternalEvent *master) -{ - CHECKEVENT(original); - CHECKEVENT(master); - /* Ensure chained button mappings, i.e. that the detail field is the - * value of the mapped button on the SD, not the physical button */ - if (original->any.type == ET_ButtonPress || - original->any.type == ET_ButtonRelease) - { - int btn = original->device_event.detail.button; - if (!sdev->button) - return; /* Should never happen */ - - master->device_event.detail.button = sdev->button->map[btn]; - } -} - -/** - * Copy the given event into master. - * @param sdev The slave device the original event comes from - * @param original The event as it came from the EQ - * @param copy The event after being copied - * @return The master device or NULL if the device is a floating slave. - */ -DeviceIntPtr -CopyGetMasterEvent(DeviceIntPtr sdev, - InternalEvent* original, InternalEvent *copy) -{ - DeviceIntPtr mdev; - int len = original->any.length; - int type = original->any.type; - int mtype; /* which master type? */ - - CHECKEVENT(original); - - /* ET_XQuartz has sdev == NULL */ - if (!sdev || IsMaster(sdev) || IsFloating(sdev)) - return NULL; - -#if XFreeXDGA - if (type == ET_DGAEvent) - type = original->dga_event.subtype; -#endif - - switch(type) - { - case ET_KeyPress: - case ET_KeyRelease: - mtype = MASTER_KEYBOARD; - break; - case ET_ButtonPress: - case ET_ButtonRelease: - case ET_Motion: - case ET_ProximityIn: - case ET_ProximityOut: - mtype = MASTER_POINTER; - break; - default: - mtype = MASTER_ATTACHED; - break; - } - - mdev = GetMaster(sdev, mtype); - memcpy(copy, original, len); - ChangeDeviceID(mdev, copy); - FixUpEventForMaster(mdev, sdev, original, copy); - - return mdev; -} - - -/** - * Post the given @event through the device hierarchy, as appropriate. - * Use this function if an event must be posted for a given device during the - * usual event processing cycle. - */ -void -mieqProcessDeviceEvent(DeviceIntPtr dev, - InternalEvent *event, - ScreenPtr screen) -{ - mieqHandler handler; - int x = 0, y = 0; - DeviceIntPtr master; - InternalEvent mevent; /* master event */ - - CHECKEVENT(event); - - /* Custom event handler */ - handler = miEventQueue.handlers[event->any.type]; - - switch (event->any.type) { - /* Catch events that include valuator information and check if they - * are changing the screen */ - case ET_Motion: - case ET_KeyPress: - case ET_KeyRelease: - case ET_ButtonPress: - case ET_ButtonRelease: - if (dev && screen && screen != DequeueScreen(dev) && !handler) { - DequeueScreen(dev) = screen; - x = event->device_event.root_x; - y = event->device_event.root_y; - NewCurrentScreen (dev, DequeueScreen(dev), x, y); - } - break; - default: - break; - } - master = CopyGetMasterEvent(dev, event, &mevent); - - if (master) - master->lastSlave = dev; - - /* If someone's registered a custom event handler, let them - * steal it. */ - if (handler) - { - int screenNum = dev && DequeueScreen(dev) ? DequeueScreen(dev)->myNum : (screen ? screen->myNum : 0); - handler(screenNum, event, dev); - /* Check for the SD's master in case the device got detached - * during event processing */ - if (master && !IsFloating(dev)) - handler(screenNum, &mevent, master); - } else - { - /* process slave first, then master */ - dev->public.processInputProc(event, dev); - - /* Check for the SD's master in case the device got detached - * during event processing */ - if (master && !IsFloating(dev)) - master->public.processInputProc(&mevent, master); - } -} - -/* Call this from ProcessInputEvents(). */ -void -mieqProcessInputEvents(void) -{ - EventRec *e = NULL; - int evlen; - ScreenPtr screen; - static InternalEvent *event = NULL; - static size_t event_size = 0; - DeviceIntPtr dev = NULL, - master = NULL; - -#ifdef XQUARTZ - pthread_mutex_lock(&miEventQueueMutex); -#endif - - while (miEventQueue.head != miEventQueue.tail) { - e = &miEventQueue.events[miEventQueue.head]; - - evlen = e->events->evlen; - if(evlen > event_size) - { - event = realloc(event, evlen); - event_size = evlen; - } - - - if (!event) - FatalError("[mi] No memory left for event processing.\n"); - - memcpy(event, e->events->event, evlen); - - - dev = e->pDev; - screen = e->pScreen; - - miEventQueue.head = (miEventQueue.head + 1) % QUEUE_SIZE; - -#ifdef XQUARTZ - pthread_mutex_unlock(&miEventQueueMutex); -#endif - - master = (dev) ? GetMaster(dev, MASTER_ATTACHED) : NULL; - - if (screenIsSaved == SCREEN_SAVER_ON) - dixSaveScreens (serverClient, SCREEN_SAVER_OFF, ScreenSaverReset); -#ifdef DPMSExtension - else if (DPMSPowerLevel != DPMSModeOn) - SetScreenSaverTimer(); - - if (DPMSPowerLevel != DPMSModeOn) - DPMSSet(serverClient, DPMSModeOn); -#endif - - mieqProcessDeviceEvent(dev, event, screen); - - /* Update the sprite now. Next event may be from different device. */ - if (event->any.type == ET_Motion && master) - miPointerUpdateSprite(dev); - -#ifdef XQUARTZ - pthread_mutex_lock(&miEventQueueMutex); -#endif - } -#ifdef XQUARTZ - pthread_mutex_unlock(&miEventQueueMutex); -#endif -} - +/*
+ *
+Copyright 1990, 1998 The Open Group
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+ *
+ * Author: Keith Packard, MIT X Consortium
+ */
+
+/*
+ * mieq.c
+ *
+ * Machine independent event queue
+ *
+ */
+
+#if HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+# include <X11/X.h>
+# include <X11/Xmd.h>
+# include <X11/Xproto.h>
+# include "misc.h"
+# include "windowstr.h"
+# include "pixmapstr.h"
+# include "inputstr.h"
+# include "mi.h"
+# include "mipointer.h"
+# include "scrnintstr.h"
+# include <X11/extensions/XI.h>
+# include <X11/extensions/XIproto.h>
+# include <X11/extensions/geproto.h>
+# include "extinit.h"
+# include "exglobals.h"
+# include "eventstr.h"
+
+#ifdef DPMSExtension
+# include "dpmsproc.h"
+# include <X11/extensions/dpmsconst.h>
+#endif
+
+#define QUEUE_SIZE 512
+
+#define EnqueueScreen(dev) dev->spriteInfo->sprite->pEnqueueScreen
+#define DequeueScreen(dev) dev->spriteInfo->sprite->pDequeueScreen
+
+typedef struct _Event {
+ EventListPtr events;
+ ScreenPtr pScreen;
+ DeviceIntPtr pDev; /* device this event _originated_ from */
+} EventRec, *EventPtr;
+
+typedef struct _EventQueue {
+ HWEventQueueType head, tail; /* long for SetInputCheck */
+ CARD32 lastEventTime; /* to avoid time running backwards */
+ int lastMotion; /* device ID if last event motion? */
+ EventRec events[QUEUE_SIZE]; /* static allocation for signals */
+ mieqHandler handlers[128]; /* custom event handler */
+} EventQueueRec, *EventQueuePtr;
+
+static EventQueueRec miEventQueue;
+
+#ifdef XQUARTZ
+#include <pthread.h>
+static pthread_mutex_t miEventQueueMutex = PTHREAD_MUTEX_INITIALIZER;
+
+extern BOOL serverInitComplete;
+extern pthread_mutex_t serverInitCompleteMutex;
+extern pthread_cond_t serverInitCompleteCond;
+
+static inline void wait_for_server_init(void) {
+ /* If the server hasn't finished initializing, wait for it... */
+ if(!serverInitComplete) {
+ pthread_mutex_lock(&serverInitCompleteMutex);
+ while(!serverInitComplete)
+ pthread_cond_wait(&serverInitCompleteCond, &serverInitCompleteMutex);
+ pthread_mutex_unlock(&serverInitCompleteMutex);
+ }
+}
+#endif
+
+Bool
+mieqInit(void)
+{
+ int i;
+
+ miEventQueue.head = miEventQueue.tail = 0;
+ miEventQueue.lastEventTime = GetTimeInMillis ();
+ miEventQueue.lastMotion = FALSE;
+ for (i = 0; i < 128; i++)
+ miEventQueue.handlers[i] = NULL;
+ for (i = 0; i < QUEUE_SIZE; i++)
+ {
+ if (miEventQueue.events[i].events == NULL) {
+ EventListPtr evlist = InitEventList(1);
+ if (!evlist)
+ FatalError("Could not allocate event queue.\n");
+ miEventQueue.events[i].events = evlist;
+ }
+ }
+
+ SetInputCheck(&miEventQueue.head, &miEventQueue.tail);
+ return TRUE;
+}
+
+void
+mieqFini(void)
+{
+ int i;
+ for (i = 0; i < QUEUE_SIZE; i++)
+ {
+ if (miEventQueue.events[i].events != NULL) {
+ FreeEventList(miEventQueue.events[i].events, 1);
+ miEventQueue.events[i].events = NULL;
+ }
+ }
+}
+
+/*
+ * Must be reentrant with ProcessInputEvents. Assumption: mieqEnqueue
+ * will never be interrupted. If this is called from both signal
+ * handlers and regular code, make sure the signal is suspended when
+ * called from regular code.
+ */
+
+void
+mieqEnqueue(DeviceIntPtr pDev, InternalEvent *e)
+{
+ unsigned int oldtail = miEventQueue.tail;
+ EventListPtr evt;
+ int isMotion = 0;
+ int evlen;
+ Time time;
+
+#ifdef XQUARTZ
+ wait_for_server_init();
+ pthread_mutex_lock(&miEventQueueMutex);
+#endif
+
+ CHECKEVENT(e);
+
+ /* avoid merging events from different devices */
+ if (e->any.type == ET_Motion)
+ isMotion = pDev->id;
+
+ if (isMotion && isMotion == miEventQueue.lastMotion &&
+ oldtail != miEventQueue.head) {
+ oldtail = (oldtail - 1) % QUEUE_SIZE;
+ }
+ else {
+ static int stuck = 0;
+ /* Toss events which come in late. Usually this means your server's
+ * stuck in an infinite loop somewhere, but SIGIO is still getting
+ * handled. */
+ if (((oldtail + 1) % QUEUE_SIZE) == miEventQueue.head) {
+ if (!stuck) {
+ ErrorF("[mi] EQ overflowing. The server is probably stuck "
+ "in an infinite loop.\n");
+ xorg_backtrace();
+ stuck = 1;
+ }
+#ifdef XQUARTZ
+ pthread_mutex_unlock(&miEventQueueMutex);
+#endif
+ return;
+ }
+ stuck = 0;
+ }
+
+ evlen = e->any.length;
+ evt = miEventQueue.events[oldtail].events;
+ if (evt->evlen < evlen)
+ {
+ evt->evlen = evlen;
+ evt->event = realloc(evt->event, evt->evlen);
+ if (!evt->event)
+ {
+ ErrorF("[mi] Running out of memory. Tossing event.\n");
+#ifdef XQUARTZ
+ pthread_mutex_unlock(&miEventQueueMutex);
+#endif
+ return;
+ }
+ }
+
+ memcpy(evt->event, e, evlen);
+
+ time = e->any.time;
+ /* Make sure that event times don't go backwards - this
+ * is "unnecessary", but very useful. */
+ if (time < miEventQueue.lastEventTime &&
+ miEventQueue.lastEventTime - time < 10000)
+ e->any.time = miEventQueue.lastEventTime;
+
+ miEventQueue.lastEventTime = ((InternalEvent*)evt->event)->any.time;
+ miEventQueue.events[oldtail].pScreen = pDev ? EnqueueScreen(pDev) : NULL;
+ miEventQueue.events[oldtail].pDev = pDev;
+
+ miEventQueue.lastMotion = isMotion;
+ miEventQueue.tail = (oldtail + 1) % QUEUE_SIZE;
+#ifdef XQUARTZ
+ pthread_mutex_unlock(&miEventQueueMutex);
+#endif
+}
+
+void
+mieqSwitchScreen(DeviceIntPtr pDev, ScreenPtr pScreen, Bool fromDIX)
+{
+#ifdef XQUARTZ
+ pthread_mutex_lock(&miEventQueueMutex);
+#endif
+ EnqueueScreen(pDev) = pScreen;
+ if (fromDIX)
+ DequeueScreen(pDev) = pScreen;
+#ifdef XQUARTZ
+ pthread_mutex_unlock(&miEventQueueMutex);
+#endif
+}
+
+void
+mieqSetHandler(int event, mieqHandler handler)
+{
+#ifdef XQUARTZ
+ pthread_mutex_lock(&miEventQueueMutex);
+#endif
+ if (handler && miEventQueue.handlers[event])
+ ErrorF("[mi] mieq: warning: overriding existing handler %p with %p for "
+ "event %d\n", miEventQueue.handlers[event], handler, event);
+
+ miEventQueue.handlers[event] = handler;
+#ifdef XQUARTZ
+ pthread_mutex_unlock(&miEventQueueMutex);
+#endif
+}
+
+/**
+ * Change the device id of the given event to the given device's id.
+ */
+static void
+ChangeDeviceID(DeviceIntPtr dev, InternalEvent* event)
+{
+ switch(event->any.type)
+ {
+ case ET_Motion:
+ case ET_KeyPress:
+ case ET_KeyRelease:
+ case ET_ButtonPress:
+ case ET_ButtonRelease:
+ case ET_ProximityIn:
+ case ET_ProximityOut:
+ case ET_Hierarchy:
+ case ET_DeviceChanged:
+ event->device_event.deviceid = dev->id;
+ break;
+#if XFreeXDGA
+ case ET_DGAEvent:
+ break;
+#endif
+ case ET_RawKeyPress:
+ case ET_RawKeyRelease:
+ case ET_RawButtonPress:
+ case ET_RawButtonRelease:
+ case ET_RawMotion:
+ event->raw_event.deviceid = dev->id;
+ break;
+ default:
+ ErrorF("[mi] Unknown event type (%d), cannot change id.\n",
+ event->any.type);
+ }
+}
+
+static void
+FixUpEventForMaster(DeviceIntPtr mdev, DeviceIntPtr sdev,
+ InternalEvent* original, InternalEvent *master)
+{
+ CHECKEVENT(original);
+ CHECKEVENT(master);
+ /* Ensure chained button mappings, i.e. that the detail field is the
+ * value of the mapped button on the SD, not the physical button */
+ if (original->any.type == ET_ButtonPress ||
+ original->any.type == ET_ButtonRelease)
+ {
+ int btn = original->device_event.detail.button;
+ if (!sdev->button)
+ return; /* Should never happen */
+
+ master->device_event.detail.button = sdev->button->map[btn];
+ }
+}
+
+/**
+ * Copy the given event into master.
+ * @param sdev The slave device the original event comes from
+ * @param original The event as it came from the EQ
+ * @param copy The event after being copied
+ * @return The master device or NULL if the device is a floating slave.
+ */
+DeviceIntPtr
+CopyGetMasterEvent(DeviceIntPtr sdev,
+ InternalEvent* original, InternalEvent *copy)
+{
+ DeviceIntPtr mdev;
+ int len = original->any.length;
+ int type = original->any.type;
+ int mtype; /* which master type? */
+
+ CHECKEVENT(original);
+
+ /* ET_XQuartz has sdev == NULL */
+ if (!sdev || IsMaster(sdev) || IsFloating(sdev))
+ return NULL;
+
+#if XFreeXDGA
+ if (type == ET_DGAEvent)
+ type = original->dga_event.subtype;
+#endif
+
+ switch(type)
+ {
+ case ET_KeyPress:
+ case ET_KeyRelease:
+ mtype = MASTER_KEYBOARD;
+ break;
+ case ET_ButtonPress:
+ case ET_ButtonRelease:
+ case ET_Motion:
+ case ET_ProximityIn:
+ case ET_ProximityOut:
+ mtype = MASTER_POINTER;
+ break;
+ default:
+ mtype = MASTER_ATTACHED;
+ break;
+ }
+
+ mdev = GetMaster(sdev, mtype);
+ memcpy(copy, original, len);
+ ChangeDeviceID(mdev, copy);
+ FixUpEventForMaster(mdev, sdev, original, copy);
+
+ return mdev;
+}
+
+
+/**
+ * Post the given @event through the device hierarchy, as appropriate.
+ * Use this function if an event must be posted for a given device during the
+ * usual event processing cycle.
+ */
+void
+mieqProcessDeviceEvent(DeviceIntPtr dev,
+ InternalEvent *event,
+ ScreenPtr screen)
+{
+ mieqHandler handler;
+ int x = 0, y = 0;
+ DeviceIntPtr master;
+ InternalEvent mevent; /* master event */
+
+ CHECKEVENT(event);
+
+ /* Custom event handler */
+ handler = miEventQueue.handlers[event->any.type];
+
+ switch (event->any.type) {
+ /* Catch events that include valuator information and check if they
+ * are changing the screen */
+ case ET_Motion:
+ case ET_KeyPress:
+ case ET_KeyRelease:
+ case ET_ButtonPress:
+ case ET_ButtonRelease:
+ if (dev && screen && dev->spriteInfo->sprite && screen != DequeueScreen(dev) && !handler) {
+ DequeueScreen(dev) = screen;
+ x = event->device_event.root_x;
+ y = event->device_event.root_y;
+ NewCurrentScreen (dev, DequeueScreen(dev), x, y);
+ }
+ break;
+ default:
+ break;
+ }
+ master = CopyGetMasterEvent(dev, event, &mevent);
+
+ if (master)
+ master->lastSlave = dev;
+
+ /* If someone's registered a custom event handler, let them
+ * steal it. */
+ if (handler)
+ {
+ int screenNum = dev && DequeueScreen(dev) ? DequeueScreen(dev)->myNum : (screen ? screen->myNum : 0);
+ handler(screenNum, event, dev);
+ /* Check for the SD's master in case the device got detached
+ * during event processing */
+ if (master && !IsFloating(dev))
+ handler(screenNum, &mevent, master);
+ } else
+ {
+ /* process slave first, then master */
+ dev->public.processInputProc(event, dev);
+
+ /* Check for the SD's master in case the device got detached
+ * during event processing */
+ if (master && !IsFloating(dev))
+ master->public.processInputProc(&mevent, master);
+ }
+}
+
+/* Call this from ProcessInputEvents(). */
+void
+mieqProcessInputEvents(void)
+{
+ EventRec *e = NULL;
+ int evlen;
+ ScreenPtr screen;
+ static InternalEvent *event = NULL;
+ static size_t event_size = 0;
+ DeviceIntPtr dev = NULL,
+ master = NULL;
+
+#ifdef XQUARTZ
+ pthread_mutex_lock(&miEventQueueMutex);
+#endif
+
+ while (miEventQueue.head != miEventQueue.tail) {
+ e = &miEventQueue.events[miEventQueue.head];
+
+ evlen = e->events->evlen;
+ if(evlen > event_size)
+ {
+ event = realloc(event, evlen);
+ event_size=evlen;
+
+
+ if (!event)
+ FatalError("[mi] No memory left for event processing.\n");
+ }
+
+
+ memcpy(event, e->events->event, evlen);
+
+
+ dev = e->pDev;
+ screen = e->pScreen;
+
+ miEventQueue.head = (miEventQueue.head + 1) % QUEUE_SIZE;
+
+#ifdef XQUARTZ
+ pthread_mutex_unlock(&miEventQueueMutex);
+#endif
+
+ master = (dev) ? GetMaster(dev, MASTER_ATTACHED) : NULL;
+
+ if (screenIsSaved == SCREEN_SAVER_ON)
+ dixSaveScreens (serverClient, SCREEN_SAVER_OFF, ScreenSaverReset);
+#ifdef DPMSExtension
+ else if (DPMSPowerLevel != DPMSModeOn)
+ SetScreenSaverTimer();
+
+ if (DPMSPowerLevel != DPMSModeOn)
+ DPMSSet(serverClient, DPMSModeOn);
+#endif
+
+ mieqProcessDeviceEvent(dev, event, screen);
+
+ /* Update the sprite now. Next event may be from different device. */
+ if (event->any.type == ET_Motion && master)
+ miPointerUpdateSprite(dev);
+
+#ifdef XQUARTZ
+ pthread_mutex_lock(&miEventQueueMutex);
+#endif
+ }
+#ifdef XQUARTZ
+ pthread_mutex_unlock(&miEventQueueMutex);
+#endif
+}
+
diff --git a/xorg-server/mi/miinitext.c b/xorg-server/mi/miinitext.c index 4499f377c..29903973f 100644 --- a/xorg-server/mi/miinitext.c +++ b/xorg-server/mi/miinitext.c @@ -467,7 +467,10 @@ InitExtensions(int argc, char *argv[]) #ifdef GLXEXT if (serverGeneration == 1) + { GlxPushProvider(&__glXDRISWRastProvider); + glxWinPushNativeProvider(); + } if (!noGlxExtension) GlxExtensionInit(); #endif } diff --git a/xorg-server/mi/mioverlay.c b/xorg-server/mi/mioverlay.c index 76484c275..78f5d787b 100644 --- a/xorg-server/mi/mioverlay.c +++ b/xorg-server/mi/mioverlay.c @@ -3,6 +3,10 @@ #include <dix-config.h>
#endif
+#ifdef CreateWindow
+#undef CreateWindow
+#endif
+
#include <X11/X.h>
#include "scrnintstr.h"
#include <X11/extensions/shapeproto.h>
diff --git a/xorg-server/mi/mipointrst.h b/xorg-server/mi/mipointrst.h index c912a17da..109a44c88 100644 --- a/xorg-server/mi/mipointrst.h +++ b/xorg-server/mi/mipointrst.h @@ -1,57 +1,57 @@ -/* - * mipointrst.h - * - */ - - -/* - -Copyright 1989, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from The Open Group. -*/ - -#ifndef MIPOINTRST_H -#define MIPOINTRST_H - -#include "mipointer.h" -#include "scrnintstr.h" - -typedef struct { - ScreenPtr pScreen; /* current screen */ - ScreenPtr pSpriteScreen;/* screen containing current sprite */ - CursorPtr pCursor; /* current cursor */ - CursorPtr pSpriteCursor;/* cursor on screen */ - BoxRec limits; /* current constraints */ - Bool confined; /* pointer can't change screens */ - int x, y; /* hot spot location */ - int devx, devy; /* sprite position */ - Bool generateEvent; /* generate an event during warping? */ -} miPointerRec, *miPointerPtr; - -typedef struct { - miPointerSpriteFuncPtr spriteFuncs; /* sprite-specific methods */ - miPointerScreenFuncPtr screenFuncs; /* screen-specific methods */ - CloseScreenProcPtr CloseScreen; - Bool waitForUpdate; /* don't move cursor in SIGIO */ - Bool showTransparent; /* show empty cursors */ -} miPointerScreenRec, *miPointerScreenPtr; -#endif /* MIPOINTRST_H */ +/*
+ * mipointrst.h
+ *
+ */
+
+
+/*
+
+Copyright 1989, 1998 The Open Group
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+*/
+
+#ifndef MIPOINTRST_H
+#define MIPOINTRST_H
+
+#include "mipointer.h"
+#include "scrnintstr.h"
+
+typedef struct {
+ ScreenPtr pScreen; /* current screen */
+ ScreenPtr pSpriteScreen;/* screen containing current sprite */
+ CursorPtr pCursor; /* current cursor */
+ CursorPtr pSpriteCursor;/* cursor on screen */
+ BoxRec limits; /* current constraints */
+ Bool confined; /* pointer can't change screens */
+ int x, y; /* hot spot location */
+ int devx, devy; /* sprite position */
+ Bool generateEvent; /* generate an event during warping? */
+} miPointerRec, *miPointerPtr;
+
+typedef struct {
+ miPointerSpriteFuncPtr spriteFuncs; /* sprite-specific methods */
+ miPointerScreenFuncPtr screenFuncs; /* screen-specific methods */
+ CloseScreenProcPtr CloseScreen;
+ Bool waitForUpdate; /* don't move cursor in SIGIO */
+ Bool showTransparent; /* show empty cursors */
+} miPointerScreenRec, *miPointerScreenPtr;
+#endif /* MIPOINTRST_H */
diff --git a/xorg-server/mi/misprite.c b/xorg-server/mi/misprite.c index 0b47592f0..64c6ce47b 100644 --- a/xorg-server/mi/misprite.c +++ b/xorg-server/mi/misprite.c @@ -506,7 +506,7 @@ miSpriteSourceValidate (DrawablePtr pDrawable, int x, int y, int width, if (DevHasCursor(pDev))
{
pCursorInfo = MISPRITE(pDev);
- if (pCursorInfo->isUp && pCursorInfo->pScreen == pScreen &&
+ if (pCursorInfo && pCursorInfo->isUp && pCursorInfo->pScreen == pScreen &&
ORG_OVERLAP(&pCursorInfo->saved, pDrawable->x, pDrawable->y,
x, y, width, height))
{
@@ -541,7 +541,7 @@ miSpriteCopyWindow (WindowPtr pWindow, DDXPointRec ptOldOrg, RegionPtr prgnSrc) /*
* Damage will take care of destination check
*/
- if (pCursorInfo->isUp && pCursorInfo->pScreen == pScreen &&
+ if (pCursorInfo && pCursorInfo->isUp && pCursorInfo->pScreen == pScreen &&
RegionContainsRect(prgnSrc, &pCursorInfo->saved) != rgnOUT)
{
SPRITE_DEBUG (("CopyWindow remove\n"));
@@ -628,9 +628,12 @@ miSpriteInstallColormap (ColormapPtr pMap) if (DevHasCursor(pDev))
{
pCursorInfo = MISPRITE(pDev);
- pCursorInfo->checkPixels = TRUE;
- if (pCursorInfo->isUp && pCursorInfo->pScreen == pScreen)
- miSpriteRemoveCursor(pDev, pScreen);
+ if (pCursorInfo)
+ {
+ pCursorInfo->checkPixels = TRUE;
+ if (pCursorInfo->isUp && pCursorInfo->pScreen == pScreen)
+ miSpriteRemoveCursor(pDev, pScreen);
+ }
}
}
diff --git a/xorg-server/mi/miwideline.c b/xorg-server/mi/miwideline.c index 3158e10cb..2d27dd7dc 100644 --- a/xorg-server/mi/miwideline.c +++ b/xorg-server/mi/miwideline.c @@ -45,6 +45,10 @@ from The Open Group. #include <math.h>
#undef _XOPEN_SOURCE
#endif
+#ifdef _MSC_VER
+#define hypot _hypot
+#endif
+
#include <X11/X.h>
#include "windowstr.h"
#include "gcstruct.h"
|