xserver-multidpi/mi/mipointer.c

581 lines
16 KiB
C
Raw Normal View History

2003-11-14 16:54:54 +01:00
/*
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.
*/
/*
* MPX additions:
* Copyright © 2006 Peter Hutterer
* License see above.
* Author: Peter Hutterer <peter@cs.unisa.edu.au>
*
*/
2003-11-14 16:54:54 +01:00
#ifdef HAVE_DIX_CONFIG_H
#include <dix-config.h>
#endif
2003-11-14 16:54:54 +01:00
# define NEED_EVENTS
# include <X11/X.h>
# include <X11/Xmd.h>
# include <X11/Xproto.h>
2003-11-14 16:54:54 +01:00
# 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"
2003-11-14 16:54:54 +01:00
_X_EXPORT int miPointerScreenIndex;
2003-11-14 16:54:54 +01:00
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 miPointerPtr miCorePointer;
2003-11-14 16:54:54 +01:00
/* Multipointers
* ID of a device == index in this array.
*/
static miPointerRec miPointers[MAX_DEVICES];
#define MIPOINTER(dev) \
(DevHasCursor((dev))) ? &miPointers[(dev)->id] : miCorePointer
static Bool miPointerRealizeCursor(DeviceIntPtr pDev, ScreenPtr pScreen,
CursorPtr pCursor);
static Bool miPointerUnrealizeCursor(DeviceIntPtr pDev, ScreenPtr pScreen,
CursorPtr pCursor);
static Bool miPointerDisplayCursor(DeviceIntPtr pDev, ScreenPtr pScreen,
CursorPtr pCursor);
2006-11-21 05:16:00 +01:00
static void miPointerConstrainCursor(DeviceIntPtr pDev, ScreenPtr pScreen,
BoxPtr pBox);
static void miPointerPointerNonInterestBox(DeviceIntPtr pDev,
ScreenPtr pScreen, BoxPtr pBox);
static void miPointerCursorLimits(DeviceIntPtr pDev, ScreenPtr pScreen,
CursorPtr pCursor, BoxPtr pHotBox,
BoxPtr pTopLeftBox);
static Bool miPointerSetCursorPosition(DeviceIntPtr pDev, ScreenPtr pScreen,
int x, int y,
2003-11-14 17:49:22 +01:00
Bool generateEvent);
static Bool miPointerCloseScreen(int index, ScreenPtr pScreen);
static void miPointerMove(DeviceIntPtr pDev, ScreenPtr pScreen,
int x, int y,
unsigned long time);
2003-11-14 16:54:54 +01:00
static xEvent* events; /* for WarpPointer MotionNotifies */
_X_EXPORT Bool
2003-11-14 16:54:54 +01:00
miPointerInitialize (pScreen, spriteFuncs, screenFuncs, waitForUpdate)
ScreenPtr pScreen;
miPointerSpriteFuncPtr spriteFuncs;
miPointerScreenFuncPtr screenFuncs;
Bool waitForUpdate;
{
miPointerScreenPtr pScreenPriv;
miPointerPtr pPointer;
int ptrIdx;
2003-11-14 16:54:54 +01:00
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;
2003-11-14 17:49:22 +01:00
pScreenPriv->showTransparent = FALSE;
2003-11-14 16:54:54 +01:00
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;
2003-11-14 16:54:54 +01:00
/*
* set up the pointer object
* virtual core pointer ID is always 1, so we let it point to the matching
* index in the array.
2003-11-14 16:54:54 +01:00
*/
miCorePointer = &miPointers[1];
for(ptrIdx = 0; ptrIdx < MAX_DEVICES; ptrIdx++)
{
pPointer = &miPointers[ptrIdx];
pPointer->pScreen = NULL;
pPointer->pSpriteScreen = NULL;
pPointer->pCursor = NULL;
pPointer->pSpriteCursor = NULL;
pPointer->limits.x1 = 0;
pPointer->limits.x2 = 32767;
pPointer->limits.y1 = 0;
pPointer->limits.y2 = 32767;
pPointer->confined = FALSE;
pPointer->x = 0;
pPointer->y = 0;
}
events = NULL;
2003-11-14 16:54:54 +01:00
return TRUE;
}
static Bool
miPointerCloseScreen (index, pScreen)
int index;
ScreenPtr pScreen;
{
miPointerPtr pPointer;
int ptrIdx;
2003-11-14 16:54:54 +01:00
SetupScreen(pScreen);
for(ptrIdx = 0; ptrIdx < MAX_DEVICES; ptrIdx++)
{
pPointer = &miPointers[ptrIdx];
if (pScreen == pPointer->pScreen)
pPointer->pScreen = 0;
if (pScreen == pPointer->pSpriteScreen)
pPointer->pSpriteScreen = 0;
}
2003-11-14 16:54:54 +01:00
pScreen->CloseScreen = pScreenPriv->CloseScreen;
xfree ((pointer) pScreenPriv);
xfree ((pointer) events);
events = NULL;
2003-11-14 16:54:54 +01:00
return (*pScreen->CloseScreen) (index, pScreen);
}
/*
* DIX/DDX interface routines
*/
static Bool
miPointerRealizeCursor (pDev, pScreen, pCursor)
DeviceIntPtr pDev;
ScreenPtr pScreen;
CursorPtr pCursor;
2003-11-14 16:54:54 +01:00
{
SetupScreen(pScreen);
return (*pScreenPriv->spriteFuncs->RealizeCursor) (pDev, pScreen, pCursor);
2003-11-14 16:54:54 +01:00
}
static Bool
miPointerUnrealizeCursor (pDev, pScreen, pCursor)
DeviceIntPtr pDev;
ScreenPtr pScreen;
CursorPtr pCursor;
2003-11-14 16:54:54 +01:00
{
SetupScreen(pScreen);
return (*pScreenPriv->spriteFuncs->UnrealizeCursor) (pDev, pScreen, pCursor);
2003-11-14 16:54:54 +01:00
}
static Bool
miPointerDisplayCursor (pDev, pScreen, pCursor)
DeviceIntPtr pDev;
ScreenPtr pScreen;
CursorPtr pCursor;
2003-11-14 16:54:54 +01:00
{
miPointerPtr pPointer = MIPOINTER(pDev);
pPointer->pCursor = pCursor;
pPointer->pScreen = pScreen;
miPointerUpdateSprite(pDev);
2003-11-14 16:54:54 +01:00
return TRUE;
}
static void
2006-11-21 05:16:00 +01:00
miPointerConstrainCursor (pDev, pScreen, pBox)
DeviceIntPtr pDev;
2003-11-14 16:54:54 +01:00
ScreenPtr pScreen;
BoxPtr pBox;
{
miPointerPtr pPointer = MIPOINTER(pDev);
pPointer->limits = *pBox;
pPointer->confined = PointerConfinedToScreen(pDev);
2003-11-14 16:54:54 +01:00
}
/*ARGSUSED*/
static void
miPointerPointerNonInterestBox (pDev, pScreen, pBox)
DeviceIntPtr pDev;
ScreenPtr pScreen;
BoxPtr pBox;
2003-11-14 16:54:54 +01:00
{
/* until DIX uses this, this will remain a stub */
}
/*ARGSUSED*/
static void
miPointerCursorLimits(pDev, pScreen, pCursor, pHotBox, pTopLeftBox)
DeviceIntPtr pDev;
ScreenPtr pScreen;
CursorPtr pCursor;
BoxPtr pHotBox;
BoxPtr pTopLeftBox;
2003-11-14 16:54:54 +01:00
{
*pTopLeftBox = *pHotBox;
}
static Bool GenerateEvent;
static Bool
miPointerSetCursorPosition(pDev, pScreen, x, y, generateEvent)
DeviceIntPtr pDev;
ScreenPtr pScreen;
int x, y;
Bool generateEvent;
2003-11-14 16:54:54 +01:00
{
SetupScreen (pScreen);
GenerateEvent = generateEvent;
/* device dependent - must pend signal and call miPointerWarpCursor */
(*pScreenPriv->screenFuncs->WarpCursor) (pDev, pScreen, x, y);
2003-11-14 16:54:54 +01:00
if (!generateEvent)
miPointerUpdateSprite(pDev);
2003-11-14 16:54:54 +01:00
return TRUE;
}
/* Once signals are ignored, the WarpCursor function can call this */
_X_EXPORT void
miPointerWarpCursor (pDev, pScreen, x, y)
DeviceIntPtr pDev;
ScreenPtr pScreen;
int x, y;
2003-11-14 16:54:54 +01:00
{
miPointerPtr pPointer = MIPOINTER(pDev);
2003-11-14 16:54:54 +01:00
SetupScreen (pScreen);
if (pPointer->pScreen != pScreen)
2003-11-14 16:54:54 +01:00
(*pScreenPriv->screenFuncs->NewEventScreen) (pScreen, TRUE);
if (GenerateEvent)
{
miPointerMove (pDev, pScreen, x, y, GetTimeInMillis());
2003-11-14 16:54:54 +01:00
}
else
{
/* everything from miPointerMove except the event and history */
if (!pScreenPriv->waitForUpdate && pScreen == pPointer->pSpriteScreen)
2003-11-14 16:54:54 +01:00
{
pPointer->devx = x;
pPointer->devy = y;
if(!pPointer->pCursor->bits->emptyMask)
(*pScreenPriv->spriteFuncs->MoveCursor) (pDev, pScreen, x, y);
2003-11-14 16:54:54 +01:00
}
pPointer->x = x;
pPointer->y = y;
pPointer->pScreen = pScreen;
2003-11-14 16:54:54 +01:00
}
}
/*
* Pointer/CursorDisplay interface routines
*/
/*
* miPointerUpdate
*
* Syncronize the sprite with the cursor - called from ProcessInputEvents
*/
void
miPointerUpdate ()
{
miPointerUpdateSprite(inputInfo.pointer);
}
void
miPointerUpdateSprite (DeviceIntPtr pDev)
2003-11-14 16:54:54 +01:00
{
ScreenPtr pScreen;
miPointerScreenPtr pScreenPriv;
2003-11-14 17:49:22 +01:00
CursorPtr pCursor;
2003-11-14 16:54:54 +01:00
int x, y, devx, devy;
miPointerPtr pPointer;
2003-11-14 16:54:54 +01:00
if (!pDev || pDev == inputInfo.pointer || !pDev->coreEvents)
return;
pPointer = MIPOINTER(pDev);
pScreen = pPointer->pScreen;
if (!pScreen)
return;
x = pPointer->x;
y = pPointer->y;
devx = pPointer->devx;
devy = pPointer->devy;
2003-11-14 16:54:54 +01:00
pScreenPriv = GetScreenPrivate (pScreen);
/*
* if the cursor has switched screens, disable the sprite
* on the old screen
*/
if (pScreen != pPointer->pSpriteScreen)
2003-11-14 16:54:54 +01:00
{
if (pPointer->pSpriteScreen)
2003-11-14 16:54:54 +01:00
{
miPointerScreenPtr pOldPriv;
pOldPriv = GetScreenPrivate (pPointer->pSpriteScreen);
if (pPointer->pCursor)
2003-11-14 16:54:54 +01:00
{
(*pOldPriv->spriteFuncs->SetCursor)
(pDev, pPointer->pSpriteScreen, NullCursor, 0, 0);
2003-11-14 16:54:54 +01:00
}
(*pOldPriv->screenFuncs->CrossScreen) (pPointer->pSpriteScreen, FALSE);
2003-11-14 16:54:54 +01:00
}
(*pScreenPriv->screenFuncs->CrossScreen) (pScreen, TRUE);
(*pScreenPriv->spriteFuncs->SetCursor)
(pDev, pScreen, pPointer->pCursor, x, y);
pPointer->devx = x;
pPointer->devy = y;
pPointer->pSpriteCursor = pPointer->pCursor;
pPointer->pSpriteScreen = pScreen;
2003-11-14 16:54:54 +01:00
}
/*
* if the cursor has changed, display the new one
*/
else if (pPointer->pCursor != pPointer->pSpriteCursor)
2003-11-14 16:54:54 +01:00
{
pCursor = pPointer->pCursor;
2003-11-14 17:49:22 +01:00
if (pCursor->bits->emptyMask && !pScreenPriv->showTransparent)
pCursor = NullCursor;
(*pScreenPriv->spriteFuncs->SetCursor) (pDev, pScreen, pCursor, x, y);
2003-11-14 17:49:22 +01:00
pPointer->devx = x;
pPointer->devy = y;
pPointer->pSpriteCursor = pPointer->pCursor;
2003-11-14 16:54:54 +01:00
}
else if (x != devx || y != devy)
{
pPointer->devx = x;
pPointer->devy = y;
if(!pPointer->pCursor->bits->emptyMask)
(*pScreenPriv->spriteFuncs->MoveCursor) (pDev, pScreen, x, y);
2003-11-14 16:54:54 +01:00
}
}
/*
* miPointerDeltaCursor. The pointer has moved dx,dy from it's previous
* position.
*/
void
miPointerDeltaCursor (int dx, int dy, unsigned long time)
2003-11-14 16:54:54 +01:00
{
int x = miCorePointer->x + dx, y = miCorePointer->y + dy;
miPointerSetPosition(inputInfo.pointer, &x, &y, time);
2003-11-14 16:54:54 +01:00
}
2003-11-14 17:49:22 +01:00
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)
2003-11-14 17:49:22 +01:00
{
miPointerScreenPtr pScreenPriv;
ScreenPtr pScreen;
miPointerPtr pPointer = MIPOINTER(pDev);
2003-11-14 17:49:22 +01:00
pScreen = screenInfo.screens[screen_no];
pScreenPriv = GetScreenPrivate (pScreen);
(*pScreenPriv->screenFuncs->NewEventScreen) (pScreen, FALSE);
NewCurrentScreen (pDev, pScreen, x, y);
pPointer->limits.x2 = pScreen->width;
pPointer->limits.y2 = pScreen->height;
2003-11-14 17:49:22 +01:00
}
_X_EXPORT ScreenPtr
2003-11-14 17:49:22 +01:00
miPointerCurrentScreen ()
{
return miPointerGetScreen(inputInfo.pointer);
2003-11-14 17:49:22 +01:00
}
_X_EXPORT ScreenPtr
miPointerGetScreen(DeviceIntPtr pDev)
{
miPointerPtr pPointer = MIPOINTER(pDev);
return pPointer->pScreen;
}
2003-11-14 16:54:54 +01:00
/* 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);
}
2007-03-25 23:56:32 +02:00
/* Move the pointer on the current screen, and update the sprite. */
static void
miPointerMoved (DeviceIntPtr pDev, ScreenPtr pScreen, int x, int y,
unsigned long time)
{
miPointerPtr pPointer = MIPOINTER(pDev);
2007-03-25 23:56:32 +02:00
SetupScreen(pScreen);
if (pDev && (pDev->coreEvents || pDev == inputInfo.pointer)
&& !pScreenPriv->waitForUpdate && pScreen == pPointer->pSpriteScreen)
2007-03-25 23:56:32 +02:00
{
pPointer->devx = x;
pPointer->devy = y;
if(!pPointer->pCursor->bits->emptyMask)
(*pScreenPriv->spriteFuncs->MoveCursor) (pDev, pScreen, x, y);
2007-03-25 23:56:32 +02:00
}
pPointer->x = x;
pPointer->y = y;
pPointer->pScreen = pScreen;
2007-03-25 23:56:32 +02:00
}
_X_EXPORT void
miPointerSetPosition(DeviceIntPtr pDev, int *x, int *y, unsigned long time)
2003-11-14 16:54:54 +01:00
{
miPointerScreenPtr pScreenPriv;
ScreenPtr pScreen;
ScreenPtr newScreen;
miPointerPtr pPointer = MIPOINTER(pDev);
pScreen = pPointer->pScreen;
2003-11-14 16:54:54 +01:00
if (!pScreen)
return; /* called before ready */
if (!pDev || !(pDev->coreEvents || pDev == inputInfo.pointer))
return;
if (*x < 0 || *x >= pScreen->width || *y < 0 || *y >= pScreen->height)
2003-11-14 16:54:54 +01:00
{
pScreenPriv = GetScreenPrivate (pScreen);
if (!pPointer->confined)
2003-11-14 16:54:54 +01:00
{
newScreen = pScreen;
(*pScreenPriv->screenFuncs->CursorOffScreen) (&newScreen, x, y);
2003-11-14 16:54:54 +01:00
if (newScreen != pScreen)
{
pScreen = newScreen;
(*pScreenPriv->screenFuncs->NewEventScreen) (pScreen, FALSE);
pScreenPriv = GetScreenPrivate (pScreen);
/* Smash the confine to the new screen */
pPointer->limits.x2 = pScreen->width;
pPointer->limits.y2 = pScreen->height;
2003-11-14 16:54:54 +01:00
}
}
}
/* Constrain the sprite to the current limits. */
if (*x < pPointer->limits.x1)
*x = pPointer->limits.x1;
if (*x >= pPointer->limits.x2)
*x = pPointer->limits.x2 - 1;
if (*y < pPointer->limits.y1)
*y = pPointer->limits.y1;
if (*y >= pPointer->limits.y2)
*y = pPointer->limits.y2 - 1;
if (pPointer->x == *x && pPointer->y == *y &&
pPointer->pScreen == pScreen)
return;
miPointerMoved(pDev, pScreen, *x, *y, time);
2003-11-14 16:54:54 +01:00
}
_X_EXPORT void
miPointerPosition (int *x, int *y)
{
miPointerGetPosition(inputInfo.pointer, x, y);
}
_X_EXPORT void
miPointerGetPosition(DeviceIntPtr pDev, int *x, int *y)
2003-11-14 16:54:54 +01:00
{
miPointerPtr pPointer = MIPOINTER(pDev);
*x = pPointer->x;
*y = pPointer->y;
2003-11-14 16:54:54 +01:00
}
void
miPointerMove (DeviceIntPtr pDev, ScreenPtr pScreen, int x, int y, unsigned long time)
{
int i, nevents;
int valuators[2];
miPointerMoved(pDev, pScreen, x, y, time);
/* generate motion notify */
valuators[0] = x;
valuators[1] = y;
if (!events)
{
events = (xEvent*)xcalloc(sizeof(xEvent), GetMaximumEventsNum());
if (!events)
{
FatalError("Could not allocate event store.\n");
return;
}
}
nevents = GetPointerEvents(events, pDev, MotionNotify, 0, POINTER_ABSOLUTE, 0, 2, valuators);
for (i = 0; i < nevents; i++)
mieqEnqueue(pDev, &events[i]);
}