2006-11-26 11:13:41 -07:00
|
|
|
/*
|
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
Copyright 1992, 1998 The Open Group
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
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.
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
The above copyright notice and this permission notice shall be included
|
|
|
|
in all copies or substantial portions of the Software.
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
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.
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
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.
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
*/
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
#ifdef HAVE_DIX_CONFIG_H
|
|
|
|
#include <dix-config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <X11/X.h>
|
|
|
|
#include <X11/Xproto.h>
|
2010-07-27 13:02:24 -06:00
|
|
|
#include <X11/Xatom.h>
|
2006-11-26 11:13:41 -07:00
|
|
|
#include "misc.h"
|
|
|
|
#include "os.h"
|
|
|
|
#include "dixstruct.h"
|
|
|
|
#include "extnsionst.h"
|
|
|
|
#include "windowstr.h"
|
|
|
|
#include "inputstr.h"
|
|
|
|
#include "scrnintstr.h"
|
|
|
|
#include "dixevents.h"
|
|
|
|
#include "sleepuntil.h"
|
2009-09-06 13:44:18 -06:00
|
|
|
#include "mi.h"
|
2010-07-27 13:02:24 -06:00
|
|
|
#include "xkbsrv.h"
|
|
|
|
#include "xkbstr.h"
|
2010-04-13 13:54:46 -06:00
|
|
|
#include <X11/extensions/xtestproto.h>
|
2006-11-26 11:13:41 -07:00
|
|
|
#include <X11/extensions/XI.h>
|
|
|
|
#include <X11/extensions/XIproto.h>
|
2010-07-27 13:02:24 -06:00
|
|
|
#include "exglobals.h"
|
|
|
|
#include "mipointer.h"
|
|
|
|
#include "xserver-properties.h"
|
|
|
|
#include "exevents.h"
|
2011-11-05 07:32:40 -06:00
|
|
|
#include "eventstr.h"
|
|
|
|
#include "inpututils.h"
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2013-06-07 11:28:45 -06:00
|
|
|
#include "extinit.h"
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
/* XTest events are sent during request processing and may be interruped by
|
|
|
|
* a SIGIO. We need a separate event list to avoid events overwriting each
|
|
|
|
* other's memory */
|
2012-06-10 07:21:05 -06:00
|
|
|
static InternalEvent *xtest_evlist;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* xtestpointer
|
|
|
|
* is the virtual pointer for XTest. It is the first slave
|
|
|
|
* device of the VCP.
|
|
|
|
* xtestkeyboard
|
|
|
|
* is the virtual keyboard for XTest. It is the first slave
|
|
|
|
* device of the VCK
|
|
|
|
*
|
|
|
|
* Neither of these devices can be deleted.
|
|
|
|
*/
|
|
|
|
DeviceIntPtr xtestpointer, xtestkeyboard;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
#ifdef PANORAMIX
|
|
|
|
#include "panoramiX.h"
|
|
|
|
#include "panoramiXsrv.h"
|
|
|
|
#endif
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
static int XTestSwapFakeInput(ClientPtr /* client */ ,
|
|
|
|
xReq * /* req */
|
|
|
|
);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
static int
|
2010-07-27 13:02:24 -06:00
|
|
|
ProcXTestGetVersion(ClientPtr client)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2013-06-07 11:28:45 -06:00
|
|
|
xXTestGetVersionReply rep = {
|
|
|
|
.type = X_Reply,
|
|
|
|
.sequenceNumber = client->sequence,
|
|
|
|
.length = 0,
|
|
|
|
.majorVersion = XTestMajorVersion,
|
|
|
|
.minorVersion = XTestMinorVersion
|
|
|
|
};
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
REQUEST_SIZE_MATCH(xXTestGetVersionReq);
|
2013-06-07 11:28:45 -06:00
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
if (client->swapped) {
|
2012-06-10 07:21:05 -06:00
|
|
|
swaps(&rep.sequenceNumber);
|
|
|
|
swaps(&rep.minorVersion);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2013-06-07 11:28:45 -06:00
|
|
|
WriteToClient(client, sizeof(xXTestGetVersionReply), &rep);
|
2010-12-05 08:36:02 -07:00
|
|
|
return Success;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2010-07-27 13:02:24 -06:00
|
|
|
ProcXTestCompareCursor(ClientPtr client)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
REQUEST(xXTestCompareCursorReq);
|
|
|
|
xXTestCompareCursorReply rep;
|
|
|
|
WindowPtr pWin;
|
|
|
|
CursorPtr pCursor;
|
2012-06-10 07:21:05 -06:00
|
|
|
int rc;
|
2009-09-06 13:44:18 -06:00
|
|
|
DeviceIntPtr ptr = PickPointer(client);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
REQUEST_SIZE_MATCH(xXTestCompareCursorReq);
|
2008-11-02 08:26:08 -07:00
|
|
|
rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess);
|
2007-11-24 10:55:21 -07:00
|
|
|
if (rc != Success)
|
|
|
|
return rc;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
|
|
|
if (!ptr)
|
|
|
|
return BadAccess;
|
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
if (stuff->cursor == None)
|
2009-09-06 13:44:18 -06:00
|
|
|
pCursor = NullCursor;
|
2006-11-26 11:13:41 -07:00
|
|
|
else if (stuff->cursor == XTestCurrentCursor)
|
2009-09-06 13:44:18 -06:00
|
|
|
pCursor = GetSpriteCursor(ptr);
|
2006-11-26 11:13:41 -07:00
|
|
|
else {
|
2014-09-27 11:52:59 -06:00
|
|
|
rc = dixLookupResourceByType((void **) &pCursor, stuff->cursor,
|
2012-06-10 07:21:05 -06:00
|
|
|
RT_CURSOR, client, DixReadAccess);
|
|
|
|
if (rc != Success) {
|
2009-09-06 13:44:18 -06:00
|
|
|
client->errorValue = stuff->cursor;
|
2010-12-05 08:36:02 -07:00
|
|
|
return rc;
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2013-06-07 11:28:45 -06:00
|
|
|
rep = (xXTestCompareCursorReply) {
|
|
|
|
.type = X_Reply,
|
|
|
|
.sequenceNumber = client->sequence,
|
|
|
|
.length = 0,
|
|
|
|
.same = (wCursor(pWin) == pCursor)
|
|
|
|
};
|
2006-11-26 11:13:41 -07:00
|
|
|
if (client->swapped) {
|
2012-06-10 07:21:05 -06:00
|
|
|
swaps(&rep.sequenceNumber);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2013-06-07 11:28:45 -06:00
|
|
|
WriteToClient(client, sizeof(xXTestCompareCursorReply), &rep);
|
2010-12-05 08:36:02 -07:00
|
|
|
return Success;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2010-07-27 13:02:24 -06:00
|
|
|
ProcXTestFakeInput(ClientPtr client)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
REQUEST(xXTestFakeInputReq);
|
2007-11-24 10:55:21 -07:00
|
|
|
int nev, n, type, rc;
|
2006-11-26 11:13:41 -07:00
|
|
|
xEvent *ev;
|
|
|
|
DeviceIntPtr dev = NULL;
|
|
|
|
WindowPtr root;
|
|
|
|
Bool extension = FALSE;
|
2011-11-05 07:32:40 -06:00
|
|
|
ValuatorMask mask;
|
2012-06-10 07:21:05 -06:00
|
|
|
int valuators[MAX_VALUATORS] = { 0 };
|
2009-09-06 13:44:18 -06:00
|
|
|
int numValuators = 0;
|
|
|
|
int firstValuator = 0;
|
|
|
|
int nevents = 0;
|
|
|
|
int i;
|
|
|
|
int base = 0;
|
|
|
|
int flags = 0;
|
2010-07-27 13:02:24 -06:00
|
|
|
int need_ptr_update = 1;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
nev = (stuff->length << 2) - sizeof(xReq);
|
|
|
|
if ((nev % sizeof(xEvent)) || !nev)
|
2009-09-06 13:44:18 -06:00
|
|
|
return BadLength;
|
2006-11-26 11:13:41 -07:00
|
|
|
nev /= sizeof(xEvent);
|
|
|
|
UpdateCurrentTime();
|
2012-06-10 07:21:05 -06:00
|
|
|
ev = (xEvent *) &((xReq *) stuff)[1];
|
2006-11-26 11:13:41 -07:00
|
|
|
type = ev->u.u.type & 0177;
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (type >= EXTENSION_EVENT_BASE) {
|
2009-09-06 13:44:18 -06:00
|
|
|
extension = TRUE;
|
|
|
|
|
|
|
|
/* check device */
|
|
|
|
rc = dixLookupDevice(&dev, stuff->deviceid & 0177, client,
|
2012-06-10 07:21:05 -06:00
|
|
|
DixWriteAccess);
|
|
|
|
if (rc != Success) {
|
2009-09-06 13:44:18 -06:00
|
|
|
client->errorValue = stuff->deviceid & 0177;
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check type */
|
|
|
|
type -= DeviceValuator;
|
|
|
|
switch (type) {
|
2012-06-10 07:21:05 -06:00
|
|
|
case XI_DeviceKeyPress:
|
|
|
|
case XI_DeviceKeyRelease:
|
|
|
|
if (!dev->key) {
|
|
|
|
client->errorValue = ev->u.u.type;
|
|
|
|
return BadValue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case XI_DeviceButtonPress:
|
|
|
|
case XI_DeviceButtonRelease:
|
|
|
|
if (!dev->button) {
|
|
|
|
client->errorValue = ev->u.u.type;
|
|
|
|
return BadValue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case XI_DeviceMotionNotify:
|
|
|
|
if (!dev->valuator) {
|
2009-09-06 13:44:18 -06:00
|
|
|
client->errorValue = ev->u.u.type;
|
|
|
|
return BadValue;
|
2012-06-10 07:21:05 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case XI_ProximityIn:
|
|
|
|
case XI_ProximityOut:
|
|
|
|
if (!dev->proximity) {
|
|
|
|
client->errorValue = ev->u.u.type;
|
|
|
|
return BadValue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
client->errorValue = ev->u.u.type;
|
|
|
|
return BadValue;
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/* check validity */
|
|
|
|
if (nev == 1 && type == XI_DeviceMotionNotify)
|
2012-06-10 07:21:05 -06:00
|
|
|
return BadLength; /* DevMotion must be followed by DevValuator */
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (type == XI_DeviceMotionNotify) {
|
|
|
|
firstValuator = ((deviceValuator *) (ev + 1))->first_valuator;
|
|
|
|
if (firstValuator > dev->valuator->numAxes) {
|
2009-09-06 13:44:18 -06:00
|
|
|
client->errorValue = ev->u.u.type;
|
|
|
|
return BadValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ev->u.u.detail == xFalse)
|
|
|
|
flags |= POINTER_ABSOLUTE;
|
2012-06-10 07:21:05 -06:00
|
|
|
}
|
|
|
|
else {
|
2009-09-06 13:44:18 -06:00
|
|
|
firstValuator = 0;
|
|
|
|
flags |= POINTER_ABSOLUTE;
|
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (nev > 1 && !dev->valuator) {
|
2013-06-07 11:28:45 -06:00
|
|
|
client->errorValue = firstValuator;
|
2009-09-06 13:44:18 -06:00
|
|
|
return BadValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check validity of valuator events */
|
|
|
|
base = firstValuator;
|
2012-06-10 07:21:05 -06:00
|
|
|
for (n = 1; n < nev; n++) {
|
2013-06-07 11:28:45 -06:00
|
|
|
deviceValuator *dv = (deviceValuator *) (ev + n);
|
2012-06-10 07:21:05 -06:00
|
|
|
if (dv->type != DeviceValuator) {
|
2009-09-06 13:44:18 -06:00
|
|
|
client->errorValue = dv->type;
|
|
|
|
return BadValue;
|
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
if (dv->first_valuator != base) {
|
2009-09-06 13:44:18 -06:00
|
|
|
client->errorValue = dv->first_valuator;
|
|
|
|
return BadValue;
|
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
switch (dv->num_valuators) {
|
|
|
|
case 6:
|
|
|
|
valuators[base + 5] = dv->valuator5;
|
|
|
|
case 5:
|
|
|
|
valuators[base + 4] = dv->valuator4;
|
|
|
|
case 4:
|
|
|
|
valuators[base + 3] = dv->valuator3;
|
|
|
|
case 3:
|
|
|
|
valuators[base + 2] = dv->valuator2;
|
|
|
|
case 2:
|
|
|
|
valuators[base + 1] = dv->valuator1;
|
|
|
|
case 1:
|
|
|
|
valuators[base] = dv->valuator0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
client->errorValue = dv->num_valuators;
|
|
|
|
return BadValue;
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
base += dv->num_valuators;
|
|
|
|
numValuators += dv->num_valuators;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (firstValuator + numValuators > dev->valuator->numAxes) {
|
2009-09-06 13:44:18 -06:00
|
|
|
client->errorValue = dv->num_valuators;
|
|
|
|
return BadValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
type = type - XI_DeviceKeyPress + KeyPress;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
}
|
|
|
|
else {
|
2009-09-06 13:44:18 -06:00
|
|
|
if (nev != 1)
|
|
|
|
return BadLength;
|
2012-06-10 07:21:05 -06:00
|
|
|
switch (type) {
|
|
|
|
case KeyPress:
|
|
|
|
case KeyRelease:
|
|
|
|
dev = PickKeyboard(client);
|
|
|
|
break;
|
|
|
|
case ButtonPress:
|
|
|
|
case ButtonRelease:
|
|
|
|
dev = PickPointer(client);
|
|
|
|
break;
|
|
|
|
case MotionNotify:
|
|
|
|
dev = PickPointer(client);
|
|
|
|
valuators[0] = ev->u.keyButtonPointer.rootX;
|
|
|
|
valuators[1] = ev->u.keyButtonPointer.rootY;
|
|
|
|
numValuators = 2;
|
|
|
|
firstValuator = 0;
|
|
|
|
if (ev->u.u.detail == xFalse)
|
2013-06-07 11:28:45 -06:00
|
|
|
flags = POINTER_ABSOLUTE | POINTER_DESKTOP;
|
2012-06-10 07:21:05 -06:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
client->errorValue = ev->u.u.type;
|
|
|
|
return BadValue;
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
/* Technically the protocol doesn't allow for BadAccess here but
|
|
|
|
* this can only happen when all MDs are disabled. */
|
|
|
|
if (!dev)
|
|
|
|
return BadAccess;
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
dev = GetXTestDevice(dev);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
/* If the event has a time set, wait for it to pass */
|
2012-06-10 07:21:05 -06:00
|
|
|
if (ev->u.keyButtonPointer.time) {
|
2009-09-06 13:44:18 -06:00
|
|
|
TimeStamp activateTime;
|
|
|
|
CARD32 ms;
|
|
|
|
|
|
|
|
activateTime = currentTime;
|
|
|
|
ms = activateTime.milliseconds + ev->u.keyButtonPointer.time;
|
|
|
|
if (ms < activateTime.milliseconds)
|
|
|
|
activateTime.months++;
|
|
|
|
activateTime.milliseconds = ms;
|
|
|
|
ev->u.keyButtonPointer.time = 0;
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
/* see mbuf.c:QueueDisplayRequest (from the deprecated Multibuffer
|
|
|
|
* extension) for code similar to this */
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!ClientSleepUntil(client, &activateTime, NULL, NULL)) {
|
2009-09-06 13:44:18 -06:00
|
|
|
return BadAlloc;
|
|
|
|
}
|
|
|
|
/* swap the request back so we can simply re-execute it */
|
2012-06-10 07:21:05 -06:00
|
|
|
if (client->swapped) {
|
|
|
|
(void) XTestSwapFakeInput(client, (xReq *) stuff);
|
|
|
|
swaps(&stuff->length);
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
ResetCurrentRequest(client);
|
2009-09-06 13:44:18 -06:00
|
|
|
client->sequence--;
|
|
|
|
return Success;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
switch (type) {
|
|
|
|
case KeyPress:
|
|
|
|
case KeyRelease:
|
|
|
|
if (!dev->key)
|
|
|
|
return BadDevice;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (ev->u.u.detail < dev->key->xkbInfo->desc->min_key_code ||
|
|
|
|
ev->u.u.detail > dev->key->xkbInfo->desc->max_key_code) {
|
|
|
|
client->errorValue = ev->u.u.detail;
|
|
|
|
return BadValue;
|
|
|
|
}
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
need_ptr_update = 0;
|
|
|
|
break;
|
|
|
|
case MotionNotify:
|
|
|
|
if (!dev->valuator)
|
|
|
|
return BadDevice;
|
|
|
|
|
|
|
|
if (!(extension || ev->u.keyButtonPointer.root == None)) {
|
|
|
|
rc = dixLookupWindow(&root, ev->u.keyButtonPointer.root,
|
|
|
|
client, DixGetAttrAccess);
|
|
|
|
if (rc != Success)
|
|
|
|
return rc;
|
|
|
|
if (root->parent) {
|
|
|
|
client->errorValue = ev->u.keyButtonPointer.root;
|
2009-09-06 13:44:18 -06:00
|
|
|
return BadValue;
|
|
|
|
}
|
2013-06-07 11:28:45 -06:00
|
|
|
|
|
|
|
/* Add the root window's offset to the valuators */
|
|
|
|
if ((flags & POINTER_ABSOLUTE) && firstValuator <= 1 && numValuators > 0) {
|
|
|
|
if (firstValuator == 0)
|
|
|
|
valuators[0] += root->drawable.pScreen->x;
|
|
|
|
if (firstValuator < 2 && firstValuator + numValuators > 1)
|
|
|
|
valuators[1 - firstValuator] += root->drawable.pScreen->y;
|
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
}
|
|
|
|
if (ev->u.u.detail != xTrue && ev->u.u.detail != xFalse) {
|
|
|
|
client->errorValue = ev->u.u.detail;
|
|
|
|
return BadValue;
|
|
|
|
}
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
/* FIXME: Xinerama! */
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
break;
|
|
|
|
case ButtonPress:
|
|
|
|
case ButtonRelease:
|
|
|
|
if (!dev->button)
|
|
|
|
return BadDevice;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!ev->u.u.detail || ev->u.u.detail > dev->button->numButtons) {
|
|
|
|
client->errorValue = ev->u.u.detail;
|
|
|
|
return BadValue;
|
|
|
|
}
|
|
|
|
break;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
if (screenIsSaved == SCREEN_SAVER_ON)
|
2009-09-06 13:44:18 -06:00
|
|
|
dixSaveScreens(serverClient, SCREEN_SAVER_OFF, ScreenSaverReset);
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
switch (type) {
|
|
|
|
case MotionNotify:
|
|
|
|
valuator_mask_set_range(&mask, firstValuator, numValuators, valuators);
|
|
|
|
nevents = GetPointerEvents(xtest_evlist, dev, type, 0, flags, &mask);
|
|
|
|
break;
|
|
|
|
case ButtonPress:
|
|
|
|
case ButtonRelease:
|
|
|
|
valuator_mask_set_range(&mask, firstValuator, numValuators, valuators);
|
|
|
|
nevents = GetPointerEvents(xtest_evlist, dev, type, ev->u.u.detail,
|
|
|
|
flags, &mask);
|
|
|
|
break;
|
|
|
|
case KeyPress:
|
|
|
|
case KeyRelease:
|
|
|
|
nevents =
|
|
|
|
GetKeyboardEvents(xtest_evlist, dev, type, ev->u.u.detail, NULL);
|
|
|
|
break;
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < nevents; i++)
|
2013-06-07 11:28:45 -06:00
|
|
|
mieqProcessDeviceEvent(dev, &xtest_evlist[i], miPointerGetScreen(inputInfo.pointer));
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
if (need_ptr_update)
|
|
|
|
miPointerUpdateSprite(dev);
|
2010-12-05 08:36:02 -07:00
|
|
|
return Success;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2010-07-27 13:02:24 -06:00
|
|
|
ProcXTestGrabControl(ClientPtr client)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
REQUEST(xXTestGrabControlReq);
|
|
|
|
|
|
|
|
REQUEST_SIZE_MATCH(xXTestGrabControlReq);
|
2012-06-10 07:21:05 -06:00
|
|
|
if ((stuff->impervious != xTrue) && (stuff->impervious != xFalse)) {
|
2009-09-06 13:44:18 -06:00
|
|
|
client->errorValue = stuff->impervious;
|
2010-12-05 08:36:02 -07:00
|
|
|
return BadValue;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
if (stuff->impervious)
|
2009-09-06 13:44:18 -06:00
|
|
|
MakeClientGrabImpervious(client);
|
2006-11-26 11:13:41 -07:00
|
|
|
else
|
2009-09-06 13:44:18 -06:00
|
|
|
MakeClientGrabPervious(client);
|
2010-12-05 08:36:02 -07:00
|
|
|
return Success;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2012-06-10 07:21:05 -06:00
|
|
|
ProcXTestDispatch(ClientPtr client)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
REQUEST(xReq);
|
2012-06-10 07:21:05 -06:00
|
|
|
switch (stuff->data) {
|
|
|
|
case X_XTestGetVersion:
|
|
|
|
return ProcXTestGetVersion(client);
|
|
|
|
case X_XTestCompareCursor:
|
|
|
|
return ProcXTestCompareCursor(client);
|
|
|
|
case X_XTestFakeInput:
|
|
|
|
return ProcXTestFakeInput(client);
|
|
|
|
case X_XTestGrabControl:
|
|
|
|
return ProcXTestGrabControl(client);
|
|
|
|
default:
|
|
|
|
return BadRequest;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2010-07-27 13:02:24 -06:00
|
|
|
SProcXTestGetVersion(ClientPtr client)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
REQUEST(xXTestGetVersionReq);
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
swaps(&stuff->length);
|
2006-11-26 11:13:41 -07:00
|
|
|
REQUEST_SIZE_MATCH(xXTestGetVersionReq);
|
2012-06-10 07:21:05 -06:00
|
|
|
swaps(&stuff->minorVersion);
|
2006-11-26 11:13:41 -07:00
|
|
|
return ProcXTestGetVersion(client);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2010-07-27 13:02:24 -06:00
|
|
|
SProcXTestCompareCursor(ClientPtr client)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
REQUEST(xXTestCompareCursorReq);
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
swaps(&stuff->length);
|
2006-11-26 11:13:41 -07:00
|
|
|
REQUEST_SIZE_MATCH(xXTestCompareCursorReq);
|
2012-06-10 07:21:05 -06:00
|
|
|
swapl(&stuff->window);
|
|
|
|
swapl(&stuff->cursor);
|
2006-11-26 11:13:41 -07:00
|
|
|
return ProcXTestCompareCursor(client);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2012-06-10 07:21:05 -06:00
|
|
|
XTestSwapFakeInput(ClientPtr client, xReq * req)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2009-09-06 13:44:18 -06:00
|
|
|
int nev;
|
|
|
|
xEvent *ev;
|
2006-11-26 11:13:41 -07:00
|
|
|
xEvent sev;
|
|
|
|
EventSwapPtr proc;
|
|
|
|
|
|
|
|
nev = ((req->length << 2) - sizeof(xReq)) / sizeof(xEvent);
|
2012-06-10 07:21:05 -06:00
|
|
|
for (ev = (xEvent *) &req[1]; --nev >= 0; ev++) {
|
2009-09-06 13:44:18 -06:00
|
|
|
/* Swap event */
|
|
|
|
proc = EventSwapVector[ev->u.u.type & 0177];
|
|
|
|
/* no swapping proc; invalid event type? */
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!proc || proc == NotImplemented) {
|
2009-09-06 13:44:18 -06:00
|
|
|
client->errorValue = ev->u.u.type;
|
|
|
|
return BadValue;
|
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
(*proc) (ev, &sev);
|
2009-09-06 13:44:18 -06:00
|
|
|
*ev = sev;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
return Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2010-07-27 13:02:24 -06:00
|
|
|
SProcXTestFakeInput(ClientPtr client)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2009-09-06 13:44:18 -06:00
|
|
|
int n;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
REQUEST(xReq);
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
swaps(&stuff->length);
|
2006-11-26 11:13:41 -07:00
|
|
|
n = XTestSwapFakeInput(client, stuff);
|
|
|
|
if (n != Success)
|
2009-09-06 13:44:18 -06:00
|
|
|
return n;
|
2006-11-26 11:13:41 -07:00
|
|
|
return ProcXTestFakeInput(client);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2010-07-27 13:02:24 -06:00
|
|
|
SProcXTestGrabControl(ClientPtr client)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
REQUEST(xXTestGrabControlReq);
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
swaps(&stuff->length);
|
2006-11-26 11:13:41 -07:00
|
|
|
REQUEST_SIZE_MATCH(xXTestGrabControlReq);
|
|
|
|
return ProcXTestGrabControl(client);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2012-06-10 07:21:05 -06:00
|
|
|
SProcXTestDispatch(ClientPtr client)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
REQUEST(xReq);
|
2012-06-10 07:21:05 -06:00
|
|
|
switch (stuff->data) {
|
|
|
|
case X_XTestGetVersion:
|
|
|
|
return SProcXTestGetVersion(client);
|
|
|
|
case X_XTestCompareCursor:
|
|
|
|
return SProcXTestCompareCursor(client);
|
|
|
|
case X_XTestFakeInput:
|
|
|
|
return SProcXTestFakeInput(client);
|
|
|
|
case X_XTestGrabControl:
|
|
|
|
return SProcXTestGrabControl(client);
|
|
|
|
default:
|
|
|
|
return BadRequest;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
}
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Allocate an virtual slave device for xtest events, this
|
|
|
|
* is a slave device to inputInfo master devices
|
|
|
|
*/
|
2012-06-10 07:21:05 -06:00
|
|
|
void
|
|
|
|
InitXTestDevices(void)
|
2010-07-27 13:02:24 -06:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
if (AllocXTestDevice(serverClient, "Virtual core",
|
|
|
|
&xtestpointer, &xtestkeyboard,
|
|
|
|
inputInfo.pointer, inputInfo.keyboard) != Success)
|
|
|
|
FatalError("Failed to allocate XTest devices");
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
if (ActivateDevice(xtestpointer, TRUE) != Success ||
|
|
|
|
ActivateDevice(xtestkeyboard, TRUE) != Success)
|
|
|
|
FatalError("Failed to activate XTest core devices.");
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!EnableDevice(xtestpointer, TRUE) || !EnableDevice(xtestkeyboard, TRUE))
|
2010-07-27 13:02:24 -06:00
|
|
|
FatalError("Failed to enable XTest core devices.");
|
|
|
|
|
|
|
|
AttachDevice(NULL, xtestpointer, inputInfo.pointer);
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
AttachDevice(NULL, xtestkeyboard, inputInfo.keyboard);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Don't allow changing the XTest property.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
DeviceSetXTestProperty(DeviceIntPtr dev, Atom property,
|
2012-06-10 07:21:05 -06:00
|
|
|
XIPropertyValuePtr prop, BOOL checkonly)
|
2010-07-27 13:02:24 -06:00
|
|
|
{
|
|
|
|
if (property == XIGetKnownProperty(XI_PROP_XTEST_DEVICE))
|
|
|
|
return BadAccess;
|
|
|
|
|
|
|
|
return Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allocate a device pair that is initialised as a slave
|
|
|
|
* device with properties that identify the devices as belonging
|
|
|
|
* to XTest subsystem.
|
|
|
|
* This only creates the pair, Activate/Enable Device
|
|
|
|
* still need to be called.
|
|
|
|
*/
|
2012-06-10 07:21:05 -06:00
|
|
|
int
|
|
|
|
AllocXTestDevice(ClientPtr client, const char *name,
|
|
|
|
DeviceIntPtr *ptr, DeviceIntPtr *keybd,
|
|
|
|
DeviceIntPtr master_ptr, DeviceIntPtr master_keybd)
|
2010-07-27 13:02:24 -06:00
|
|
|
{
|
|
|
|
int retval;
|
2012-06-10 07:21:05 -06:00
|
|
|
char *xtestname;
|
2010-07-27 13:02:24 -06:00
|
|
|
char dummy = 1;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (asprintf(&xtestname, "%s XTEST", name) == -1)
|
|
|
|
return BadAlloc;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
retval =
|
|
|
|
AllocDevicePair(client, xtestname, ptr, keybd, CorePointerProc,
|
|
|
|
CoreKeyboardProc, FALSE);
|
|
|
|
if (retval == Success) {
|
|
|
|
(*ptr)->xtest_master_id = master_ptr->id;
|
|
|
|
(*keybd)->xtest_master_id = master_keybd->id;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
XIChangeDeviceProperty(*ptr, XIGetKnownProperty(XI_PROP_XTEST_DEVICE),
|
2012-06-10 07:21:05 -06:00
|
|
|
XA_INTEGER, 8, PropModeReplace, 1, &dummy,
|
|
|
|
FALSE);
|
|
|
|
XISetDevicePropertyDeletable(*ptr,
|
|
|
|
XIGetKnownProperty(XI_PROP_XTEST_DEVICE),
|
|
|
|
FALSE);
|
2010-07-27 13:02:24 -06:00
|
|
|
XIRegisterPropertyHandler(*ptr, DeviceSetXTestProperty, NULL, NULL);
|
|
|
|
XIChangeDeviceProperty(*keybd, XIGetKnownProperty(XI_PROP_XTEST_DEVICE),
|
2012-06-10 07:21:05 -06:00
|
|
|
XA_INTEGER, 8, PropModeReplace, 1, &dummy,
|
|
|
|
FALSE);
|
|
|
|
XISetDevicePropertyDeletable(*keybd,
|
|
|
|
XIGetKnownProperty(XI_PROP_XTEST_DEVICE),
|
|
|
|
FALSE);
|
2010-07-27 13:02:24 -06:00
|
|
|
XIRegisterPropertyHandler(*keybd, DeviceSetXTestProperty, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
free(xtestname);
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If master is NULL, return TRUE if the given device is an xtest device or
|
|
|
|
* FALSE otherwise.
|
|
|
|
* If master is not NULL, return TRUE if the given device is this master's
|
|
|
|
* xtest device.
|
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
IsXTestDevice(DeviceIntPtr dev, DeviceIntPtr master)
|
|
|
|
{
|
|
|
|
if (IsMaster(dev))
|
2010-12-05 08:36:02 -07:00
|
|
|
return FALSE;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
/* deviceid 0 is reserved for XIAllDevices, non-zero mid means XTest
|
|
|
|
* device */
|
2010-12-05 08:36:02 -07:00
|
|
|
if (master)
|
2012-06-10 07:21:05 -06:00
|
|
|
return dev->xtest_master_id == master->id;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
return dev->xtest_master_id != 0;
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return The X Test virtual device for the given master.
|
|
|
|
*/
|
|
|
|
DeviceIntPtr
|
|
|
|
GetXTestDevice(DeviceIntPtr master)
|
|
|
|
{
|
|
|
|
DeviceIntPtr it;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
for (it = inputInfo.devices; it; it = it->next) {
|
2010-07-27 13:02:24 -06:00
|
|
|
if (IsXTestDevice(it, master))
|
|
|
|
return it;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This only happens if master is a slave device. don't do that */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
static void
|
2012-06-10 07:21:05 -06:00
|
|
|
XTestExtensionTearDown(ExtensionEntry * e)
|
2011-11-05 07:32:40 -06:00
|
|
|
{
|
|
|
|
FreeEventList(xtest_evlist, GetMaximumEventsNum());
|
|
|
|
xtest_evlist = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-06-07 11:28:45 -06:00
|
|
|
XTestExtensionInit(void)
|
2011-11-05 07:32:40 -06:00
|
|
|
{
|
|
|
|
AddExtension(XTestExtensionName, 0, 0,
|
2012-06-10 07:21:05 -06:00
|
|
|
ProcXTestDispatch, SProcXTestDispatch,
|
|
|
|
XTestExtensionTearDown, StandardMinorOpcode);
|
2011-11-05 07:32:40 -06:00
|
|
|
|
|
|
|
xtest_evlist = InitEventList(GetMaximumEventsNum());
|
|
|
|
}
|