/* * mipointer.c */ /* 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 MPX /* * MPX additions: * Copyright © 2006 Peter Hutterer * License see above. * Author: Peter Hutterer * */ #endif #ifdef HAVE_DIX_CONFIG_H #include #endif # define NEED_EVENTS # include # include # include # include "misc.h" # include "windowstr.h" # include "pixmapstr.h" # include "mi.h" # include "scrnintstr.h" # include "mipointrst.h" # include "cursorstr.h" # include "dixstruct.h" # include "inputstr.h" _X_EXPORT int miPointerScreenIndex; static unsigned long miPointerGeneration = 0; #define GetScreenPrivate(s) ((miPointerScreenPtr) ((s)->devPrivates[miPointerScreenIndex].ptr)) #define SetupScreen(s) miPointerScreenPtr pScreenPriv = GetScreenPrivate(s) /* * until more than one pointer device exists. */ static miPointerRec miPointer; #ifdef MPX /* Multipointers */ static miPointerRec miMPPointers[MAX_DEVICES]; /* Check if the given device is a MP device. */ _X_EXPORT Bool IsMPDev(DeviceIntPtr pDev) { return (pDev && pDev->isMPDev && pDev->id < MAX_DEVICES); } #endif static Bool miPointerRealizeCursor(ScreenPtr pScreen, CursorPtr pCursor); static Bool miPointerUnrealizeCursor(ScreenPtr pScreen, CursorPtr pCursor); static Bool miPointerDisplayCursor(ScreenPtr pScreen, CursorPtr pCursor); static void miPointerConstrainCursor(DeviceIntPtr pDev, ScreenPtr pScreen, BoxPtr pBox); static void miPointerPointerNonInterestBox(ScreenPtr pScreen, BoxPtr pBox); static void miPointerCursorLimits(ScreenPtr pScreen, CursorPtr pCursor, BoxPtr pHotBox, BoxPtr pTopLeftBox); static Bool miPointerSetCursorPosition(ScreenPtr pScreen, int x, int y, Bool generateEvent); static Bool miPointerCloseScreen(int index, ScreenPtr pScreen); static void miPointerMove(ScreenPtr pScreen, int x, int y, unsigned long time); _X_EXPORT Bool miPointerInitialize (pScreen, spriteFuncs, screenFuncs, waitForUpdate) ScreenPtr pScreen; miPointerSpriteFuncPtr spriteFuncs; miPointerScreenFuncPtr screenFuncs; Bool waitForUpdate; { #ifdef MPX int mpPtrIdx = 0; /* loop counter */ #endif miPointerScreenPtr pScreenPriv; if (miPointerGeneration != serverGeneration) { miPointerScreenIndex = AllocateScreenPrivateIndex(); if (miPointerScreenIndex < 0) return FALSE; miPointerGeneration = serverGeneration; } pScreenPriv = (miPointerScreenPtr) xalloc (sizeof (miPointerScreenRec)); if (!pScreenPriv) return FALSE; pScreenPriv->spriteFuncs = spriteFuncs; pScreenPriv->screenFuncs = screenFuncs; /* * check for uninitialized methods */ if (!screenFuncs->EnqueueEvent) screenFuncs->EnqueueEvent = mieqEnqueue; if (!screenFuncs->NewEventScreen) screenFuncs->NewEventScreen = mieqSwitchScreen; pScreenPriv->waitForUpdate = waitForUpdate; pScreenPriv->showTransparent = FALSE; pScreenPriv->CloseScreen = pScreen->CloseScreen; pScreen->CloseScreen = miPointerCloseScreen; pScreen->devPrivates[miPointerScreenIndex].ptr = (pointer) pScreenPriv; /* * set up screen cursor method table */ pScreen->ConstrainCursor = miPointerConstrainCursor; pScreen->CursorLimits = miPointerCursorLimits; pScreen->DisplayCursor = miPointerDisplayCursor; pScreen->RealizeCursor = miPointerRealizeCursor; pScreen->UnrealizeCursor = miPointerUnrealizeCursor; pScreen->SetCursorPosition = miPointerSetCursorPosition; pScreen->RecolorCursor = miRecolorCursor; pScreen->PointerNonInterestBox = miPointerPointerNonInterestBox; /* * set up the pointer object */ miPointer.pScreen = NULL; miPointer.pSpriteScreen = NULL; miPointer.pCursor = NULL; miPointer.pSpriteCursor = NULL; miPointer.limits.x1 = 0; miPointer.limits.x2 = 32767; miPointer.limits.y1 = 0; miPointer.limits.y2 = 32767; miPointer.confined = FALSE; miPointer.x = 0; miPointer.y = 0; #ifdef MPX /* * Set up pointer objects for multipointer devices. */ while(mpPtrIdx < MAX_DEVICES) { miMPPointers[mpPtrIdx].pScreen = NULL; miMPPointers[mpPtrIdx].pSpriteScreen = NULL; miMPPointers[mpPtrIdx].pCursor = NULL; miMPPointers[mpPtrIdx].pSpriteCursor = NULL; miMPPointers[mpPtrIdx].limits.x1 = 0; miMPPointers[mpPtrIdx].limits.x2 = 32767; miMPPointers[mpPtrIdx].limits.y1 = 0; miMPPointers[mpPtrIdx].limits.y2 = 32767; miMPPointers[mpPtrIdx].confined = FALSE; miMPPointers[mpPtrIdx].x = 0; miMPPointers[mpPtrIdx].y = 0; mpPtrIdx++; } #endif return TRUE; } static Bool miPointerCloseScreen (index, pScreen) int index; ScreenPtr pScreen; { int mpPointerIdx = 0; SetupScreen(pScreen); if (pScreen == miPointer.pScreen) miPointer.pScreen = 0; if (pScreen == miPointer.pSpriteScreen) miPointer.pSpriteScreen = 0; #ifdef MPX while(mpPointerIdx < MAX_DEVICES) { if (pScreen == miMPPointers[mpPointerIdx].pScreen) miMPPointers[mpPointerIdx].pScreen = 0; if (pScreen == miMPPointers[mpPointerIdx].pSpriteScreen) miMPPointers[mpPointerIdx].pSpriteScreen = 0; mpPointerIdx++; } #endif pScreen->CloseScreen = pScreenPriv->CloseScreen; xfree ((pointer) pScreenPriv); return (*pScreen->CloseScreen) (index, pScreen); } /* * DIX/DDX interface routines */ static Bool miPointerRealizeCursor (pScreen, pCursor) ScreenPtr pScreen; CursorPtr pCursor; { DeviceIntPtr pDev = inputInfo.pointer; SetupScreen(pScreen); return (*pScreenPriv->spriteFuncs->RealizeCursor) (pDev, pScreen, pCursor); } static Bool miPointerUnrealizeCursor (pScreen, pCursor) ScreenPtr pScreen; CursorPtr pCursor; { DeviceIntPtr pDev = inputInfo.pointer; SetupScreen(pScreen); return (*pScreenPriv->spriteFuncs->UnrealizeCursor) (pDev, pScreen, pCursor); } static Bool miPointerDisplayCursor (pScreen, pCursor) ScreenPtr pScreen; CursorPtr pCursor; { #ifdef MPX int mpPtrIdx = 0; while (mpPtrIdx < MAX_DEVICES) { miMPPointers[mpPtrIdx].pCursor = pCursor; miMPPointers[mpPtrIdx].pScreen = pScreen; mpPtrIdx++; } #endif miPointer.pCursor = pCursor; miPointer.pScreen = pScreen; miPointerUpdateSprite(inputInfo.pointer); return TRUE; } static void miPointerConstrainCursor (pDev, pScreen, pBox) DeviceIntPtr pDev; ScreenPtr pScreen; BoxPtr pBox; { #ifdef MPX if (IsMPDev(pDev)) { miMPPointers[pDev->id].limits = *pBox; } #endif miPointer.limits = *pBox; miPointer.confined = PointerConfinedToScreen(); } /*ARGSUSED*/ static void miPointerPointerNonInterestBox (pScreen, pBox) ScreenPtr pScreen; BoxPtr pBox; { /* until DIX uses this, this will remain a stub */ } /*ARGSUSED*/ static void miPointerCursorLimits(pScreen, pCursor, pHotBox, pTopLeftBox) ScreenPtr pScreen; CursorPtr pCursor; BoxPtr pHotBox; BoxPtr pTopLeftBox; { *pTopLeftBox = *pHotBox; } static Bool GenerateEvent; static Bool miPointerSetCursorPosition(pScreen, x, y, generateEvent) ScreenPtr pScreen; int x, y; Bool generateEvent; { SetupScreen (pScreen); GenerateEvent = generateEvent; /* device dependent - must pend signal and call miPointerWarpCursor */ (*pScreenPriv->screenFuncs->WarpCursor) (pScreen, x, y); if (!generateEvent) miPointerUpdateSprite(inputInfo.pointer); return TRUE; } /* Once signals are ignored, the WarpCursor function can call this */ _X_EXPORT void miPointerWarpCursor (pScreen, x, y) ScreenPtr pScreen; int x, y; { DeviceIntPtr pDev = inputInfo.pointer; SetupScreen (pScreen); if (miPointer.pScreen != pScreen) (*pScreenPriv->screenFuncs->NewEventScreen) (pScreen, TRUE); if (GenerateEvent) { miPointerMoved (pDev, pScreen, x, y, GetTimeInMillis()); } else { /* everything from miPointerMove except the event and history */ if (!pScreenPriv->waitForUpdate && pScreen == miPointer.pSpriteScreen) { miPointer.devx = x; miPointer.devy = y; if(!miPointer.pCursor->bits->emptyMask) (*pScreenPriv->spriteFuncs->MoveCursor) (pDev, pScreen, x, y); } miPointer.x = x; miPointer.y = y; miPointer.pScreen = pScreen; } } /* * Pointer/CursorDisplay interface routines */ /* * miPointerUpdate * * Syncronize the sprite with the cursor - called from ProcessInputEvents */ void miPointerUpdate () { miPointerUpdateSprite(inputInfo.pointer); } void miPointerUpdateSprite (DeviceIntPtr pDev) { ScreenPtr pScreen; miPointerScreenPtr pScreenPriv; CursorPtr pCursor; int x, y, devx, devy; miPointerPtr pointer; #ifdef MPX if (!pDev || !(pDev->coreEvents || pDev == inputInfo.pointer || pDev->isMPDev)) #else if (!pDev || !(pDev->coreEvents || pDev == inputInfo.pointer)) #endif return; #ifdef MPX if (IsMPDev(pDev)) pointer = &miMPPointers[pDev->id]; else pointer = &miPointer; #endif pScreen = pointer->pScreen; if (!pScreen) return; x = pointer->x; y = pointer->y; devx = pointer->devx; devy = pointer->devy; pScreenPriv = GetScreenPrivate (pScreen); /* * if the cursor has switched screens, disable the sprite * on the old screen */ if (pScreen != pointer->pSpriteScreen) { if (pointer->pSpriteScreen) { miPointerScreenPtr pOldPriv; pOldPriv = GetScreenPrivate (pointer->pSpriteScreen); if (pointer->pCursor) { (*pOldPriv->spriteFuncs->SetCursor) (pDev, pointer->pSpriteScreen, NullCursor, 0, 0); } (*pOldPriv->screenFuncs->CrossScreen) (pointer->pSpriteScreen, FALSE); } (*pScreenPriv->screenFuncs->CrossScreen) (pScreen, TRUE); (*pScreenPriv->spriteFuncs->SetCursor) (pDev, pScreen, pointer->pCursor, x, y); pointer->devx = x; pointer->devy = y; pointer->pSpriteCursor = pointer->pCursor; pointer->pSpriteScreen = pScreen; } /* * if the cursor has changed, display the new one */ else if (pointer->pCursor != pointer->pSpriteCursor) { pCursor = pointer->pCursor; if (pCursor->bits->emptyMask && !pScreenPriv->showTransparent) pCursor = NullCursor; (*pScreenPriv->spriteFuncs->SetCursor) (pDev, pScreen, pCursor, x, y); pointer->devx = x; pointer->devy = y; pointer->pSpriteCursor = pointer->pCursor; } else if (x != devx || y != devy) { pointer->devx = x; pointer->devy = y; if(!pointer->pCursor->bits->emptyMask) (*pScreenPriv->spriteFuncs->MoveCursor) (pDev, pScreen, x, y); } } /* * miPointerDeltaCursor. The pointer has moved dx,dy from it's previous * position. */ void miPointerDeltaCursor (int dx, int dy, unsigned long time) { int x = miPointer.x + dx, y = miPointer.y + dy; miPointerSetPosition(inputInfo.pointer, &x, &y, time); } void miPointerSetNewScreen(int screen_no, int x, int y) { miPointerSetScreen(inputInfo.pointer, screen_no, x, y); } void miPointerSetScreen(DeviceIntPtr pDev, int screen_no, int x, int y) { miPointerScreenPtr pScreenPriv; ScreenPtr pScreen; pScreen = screenInfo.screens[screen_no]; pScreenPriv = GetScreenPrivate (pScreen); (*pScreenPriv->screenFuncs->NewEventScreen) (pScreen, FALSE); NewCurrentScreen (pScreen, x, y); #ifdef MPX if (IsMPDev(pDev)) { miMPPointers[pDev->id].limits.x2 = pScreen->width; miMPPointers[pDev->id].limits.y2 = pScreen->height; } #endif { miPointer.limits.x2 = pScreen->width; miPointer.limits.y2 = pScreen->height; } } _X_EXPORT ScreenPtr miPointerCurrentScreen () { return miPointerGetScreen(inputInfo.pointer); } _X_EXPORT ScreenPtr miPointerGetScreen(DeviceIntPtr pDev) { #ifdef MPX if (IsMPDev(pDev)) return miMPPointers[pDev->id].pScreen; #endif return miPointer.pScreen; } /* Move the pointer to x, y on the current screen, update the sprite, and * the motion history. Generates no events. Does not return changed x * and y if they are clipped; use miPointerSetPosition instead. */ _X_EXPORT void miPointerAbsoluteCursor (int x, int y, unsigned long time) { miPointerSetPosition(inputInfo.pointer, &x, &y, time); } _X_EXPORT void miPointerSetPosition(DeviceIntPtr pDev, int *x, int *y, unsigned long time) { miPointerScreenPtr pScreenPriv; ScreenPtr pScreen; ScreenPtr newScreen; miPointerPtr pointer; #ifdef MPX if (IsMPDev(pDev)) pointer = &(miMPPointers[pDev->id]); else #endif pointer = &miPointer; pScreen = pointer->pScreen; if (!pScreen) return; /* called before ready */ #ifdef MPX if (!pDev || !(pDev->coreEvents || pDev == inputInfo.pointer || pDev->isMPDev)) #else if (!pDev || !(pDev->coreEvents || pDev == inputInfo.pointer)) #endif return; if (*x < 0 || *x >= pScreen->width || *y < 0 || *y >= pScreen->height) { pScreenPriv = GetScreenPrivate (pScreen); if (!pointer->confined) { newScreen = pScreen; (*pScreenPriv->screenFuncs->CursorOffScreen) (&newScreen, x, y); if (newScreen != pScreen) { pScreen = newScreen; (*pScreenPriv->screenFuncs->NewEventScreen) (pScreen, FALSE); pScreenPriv = GetScreenPrivate (pScreen); /* Smash the confine to the new screen */ pointer->limits.x2 = pScreen->width; pointer->limits.y2 = pScreen->height; } } } /* Constrain the sprite to the current limits. */ if (*x < pointer->limits.x1) *x = pointer->limits.x1; if (*x >= pointer->limits.x2) *x = pointer->limits.x2 - 1; if (*y < pointer->limits.y1) *y = pointer->limits.y1; if (*y >= pointer->limits.y2) *y = pointer->limits.y2 - 1; if (pointer->x == *x && pointer->y == *y && pointer->pScreen == pScreen) return; miPointerMoved(pDev, pScreen, *x, *y, time); } _X_EXPORT void miPointerPosition (int *x, int *y) { miPointerGetPosition(inputInfo.pointer, x, y); } _X_EXPORT void miPointerGetPosition(DeviceIntPtr pDev, int *x, int *y) { #ifdef MPX if (IsMPDev(pDev)) { *x = miMPPointers[pDev->id].x; *y = miMPPointers[pDev->id].y; } else #endif { *x = miPointer.x; *y = miPointer.y; } } void miPointerMove (ScreenPtr pScreen, int x, int y, unsigned long time) { miPointerMoved(inputInfo.pointer, pScreen, x, y, time); } /* Move the pointer on the current screen, and update the sprite. */ void miPointerMoved (DeviceIntPtr pDev, ScreenPtr pScreen, int x, int y, unsigned long time) { miPointerPtr pointer; SetupScreen(pScreen); #ifdef MPX if (IsMPDev(pDev)) pointer = &miMPPointers[pDev->id]; else #endif pointer = &miPointer; if (pDev && (pDev->coreEvents || pDev == inputInfo.pointer #ifdef MPX || pDev->isMPDev #endif ) && !pScreenPriv->waitForUpdate && pScreen == miPointer.pSpriteScreen) { pointer->devx = x; pointer->devy = y; if(!pointer->pCursor->bits->emptyMask) (*pScreenPriv->spriteFuncs->MoveCursor) (pDev, pScreen, x, y); } pointer->x = x; pointer->y = y; pointer->pScreen = pScreen; }