2010-07-27 13:02:24 -06:00
|
|
|
/*
|
|
|
|
* Copyright 2008 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
* paragraph) 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 AUTHORS OR COPYRIGHT HOLDERS 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.
|
|
|
|
*
|
|
|
|
* Author: Peter Hutterer
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_DIX_CONFIG_H
|
|
|
|
#include <dix-config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "dixstruct.h"
|
|
|
|
#include "windowstr.h"
|
|
|
|
#include "exglobals.h"
|
|
|
|
#include "exevents.h"
|
|
|
|
#include <X11/extensions/XI2proto.h>
|
2012-06-10 07:21:05 -06:00
|
|
|
#include "inpututils.h"
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
#include "xiselectev.h"
|
|
|
|
|
2013-06-07 11:28:45 -06:00
|
|
|
/**
|
|
|
|
* Ruleset:
|
|
|
|
* - if A has XIAllDevices, B may select on device X
|
|
|
|
* - If A has XIAllDevices, B may select on XIAllMasterDevices
|
|
|
|
* - If A has XIAllMasterDevices, B may select on device X
|
|
|
|
* - If A has XIAllMasterDevices, B may select on XIAllDevices
|
|
|
|
* - if A has device X, B may select on XIAllDevices/XIAllMasterDevices
|
|
|
|
*/
|
|
|
|
static int check_for_touch_selection_conflicts(ClientPtr B, WindowPtr win, int deviceid)
|
|
|
|
{
|
|
|
|
OtherInputMasks *inputMasks = wOtherInputMasks(win);
|
|
|
|
InputClients *A = NULL;
|
|
|
|
|
|
|
|
if (inputMasks)
|
|
|
|
A = inputMasks->inputClients;
|
|
|
|
for (; A; A = A->next) {
|
|
|
|
DeviceIntPtr tmp;
|
|
|
|
|
|
|
|
if (CLIENT_ID(A->resource) == B->index)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (deviceid == XIAllDevices)
|
|
|
|
tmp = inputInfo.all_devices;
|
|
|
|
else if (deviceid == XIAllMasterDevices)
|
|
|
|
tmp = inputInfo.all_master_devices;
|
|
|
|
else
|
|
|
|
dixLookupDevice(&tmp, deviceid, serverClient, DixReadAccess);
|
|
|
|
if (!tmp)
|
|
|
|
return BadImplementation; /* this shouldn't happen */
|
|
|
|
|
|
|
|
/* A has XIAllDevices */
|
|
|
|
if (xi2mask_isset_for_device(A->xi2mask, inputInfo.all_devices, XI_TouchBegin)) {
|
|
|
|
if (deviceid == XIAllDevices)
|
|
|
|
return BadAccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* A has XIAllMasterDevices */
|
|
|
|
if (xi2mask_isset_for_device(A->xi2mask, inputInfo.all_master_devices, XI_TouchBegin)) {
|
|
|
|
if (deviceid == XIAllMasterDevices)
|
|
|
|
return BadAccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* A has this device */
|
|
|
|
if (xi2mask_isset_for_device(A->xi2mask, tmp, XI_TouchBegin))
|
|
|
|
return BadAccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
/**
|
|
|
|
* Check the given mask (in len bytes) for invalid mask bits.
|
|
|
|
* Invalid mask bits are any bits above XI2LastEvent.
|
|
|
|
*
|
|
|
|
* @return BadValue if at least one invalid bit is set or Success otherwise.
|
|
|
|
*/
|
2012-06-10 07:21:05 -06:00
|
|
|
int
|
|
|
|
XICheckInvalidMaskBits(ClientPtr client, unsigned char *mask, int len)
|
2010-07-27 13:02:24 -06:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
if (len >= XIMaskLen(XI2LASTEVENT)) {
|
2010-07-27 13:02:24 -06:00
|
|
|
int i;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
|
|
|
for (i = XI2LASTEVENT + 1; i < len * 8; i++) {
|
|
|
|
if (BitIsOn(mask, i)) {
|
2011-11-05 07:32:40 -06:00
|
|
|
client->errorValue = i;
|
2010-07-27 13:02:24 -06:00
|
|
|
return BadValue;
|
2011-11-05 07:32:40 -06:00
|
|
|
}
|
|
|
|
}
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
SProcXISelectEvents(ClientPtr client)
|
|
|
|
{
|
|
|
|
int i;
|
2014-12-09 10:58:52 -07:00
|
|
|
int len;
|
2012-06-10 07:21:05 -06:00
|
|
|
xXIEventMask *evmask;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
REQUEST(xXISelectEventsReq);
|
2012-06-10 07:21:05 -06:00
|
|
|
swaps(&stuff->length);
|
2010-07-27 13:02:24 -06:00
|
|
|
REQUEST_AT_LEAST_SIZE(xXISelectEventsReq);
|
2012-06-10 07:21:05 -06:00
|
|
|
swapl(&stuff->win);
|
|
|
|
swaps(&stuff->num_masks);
|
|
|
|
|
2014-12-09 10:58:52 -07:00
|
|
|
len = stuff->length - bytes_to_int32(sizeof(xXISelectEventsReq));
|
2012-06-10 07:21:05 -06:00
|
|
|
evmask = (xXIEventMask *) &stuff[1];
|
|
|
|
for (i = 0; i < stuff->num_masks; i++) {
|
2014-12-09 10:58:52 -07:00
|
|
|
if (len < bytes_to_int32(sizeof(xXIEventMask)))
|
|
|
|
return BadLength;
|
|
|
|
len -= bytes_to_int32(sizeof(xXIEventMask));
|
2012-06-10 07:21:05 -06:00
|
|
|
swaps(&evmask->deviceid);
|
|
|
|
swaps(&evmask->mask_len);
|
2014-12-09 10:58:52 -07:00
|
|
|
if (len < evmask->mask_len)
|
|
|
|
return BadLength;
|
|
|
|
len -= evmask->mask_len;
|
2012-06-10 07:21:05 -06:00
|
|
|
evmask =
|
|
|
|
(xXIEventMask *) (((char *) &evmask[1]) + evmask->mask_len * 4);
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return (ProcXISelectEvents(client));
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ProcXISelectEvents(ClientPtr client)
|
|
|
|
{
|
|
|
|
int rc, num_masks;
|
|
|
|
WindowPtr win;
|
|
|
|
DeviceIntPtr dev;
|
|
|
|
DeviceIntRec dummy;
|
|
|
|
xXIEventMask *evmask;
|
|
|
|
int *types = NULL;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
REQUEST(xXISelectEventsReq);
|
|
|
|
REQUEST_AT_LEAST_SIZE(xXISelectEventsReq);
|
|
|
|
|
|
|
|
if (stuff->num_masks == 0)
|
|
|
|
return BadValue;
|
|
|
|
|
|
|
|
rc = dixLookupWindow(&win, stuff->win, client, DixReceiveAccess);
|
|
|
|
if (rc != Success)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
len = sz_xXISelectEventsReq;
|
|
|
|
|
|
|
|
/* check request validity */
|
2012-06-10 07:21:05 -06:00
|
|
|
evmask = (xXIEventMask *) &stuff[1];
|
2010-07-27 13:02:24 -06:00
|
|
|
num_masks = stuff->num_masks;
|
2012-06-10 07:21:05 -06:00
|
|
|
while (num_masks--) {
|
2010-07-27 13:02:24 -06:00
|
|
|
len += sizeof(xXIEventMask) + evmask->mask_len * 4;
|
|
|
|
|
|
|
|
if (bytes_to_int32(len) > stuff->length)
|
|
|
|
return BadLength;
|
|
|
|
|
|
|
|
if (evmask->deviceid != XIAllDevices &&
|
|
|
|
evmask->deviceid != XIAllMasterDevices)
|
|
|
|
rc = dixLookupDevice(&dev, evmask->deviceid, client, DixUseAccess);
|
|
|
|
else {
|
|
|
|
/* XXX: XACE here? */
|
|
|
|
}
|
|
|
|
if (rc != Success)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
/* hierarchy event mask is not allowed on devices */
|
2012-06-10 07:21:05 -06:00
|
|
|
if (evmask->deviceid != XIAllDevices && evmask->mask_len >= 1) {
|
|
|
|
unsigned char *bits = (unsigned char *) &evmask[1];
|
|
|
|
|
|
|
|
if (BitIsOn(bits, XI_HierarchyChanged)) {
|
2011-11-05 07:32:40 -06:00
|
|
|
client->errorValue = XI_HierarchyChanged;
|
2010-07-27 13:02:24 -06:00
|
|
|
return BadValue;
|
2011-11-05 07:32:40 -06:00
|
|
|
}
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Raw events may only be selected on root windows */
|
2012-06-10 07:21:05 -06:00
|
|
|
if (win->parent && evmask->mask_len >= 1) {
|
|
|
|
unsigned char *bits = (unsigned char *) &evmask[1];
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
if (BitIsOn(bits, XI_RawKeyPress) ||
|
|
|
|
BitIsOn(bits, XI_RawKeyRelease) ||
|
|
|
|
BitIsOn(bits, XI_RawButtonPress) ||
|
|
|
|
BitIsOn(bits, XI_RawButtonRelease) ||
|
2012-06-10 07:21:05 -06:00
|
|
|
BitIsOn(bits, XI_RawMotion) ||
|
|
|
|
BitIsOn(bits, XI_RawTouchBegin) ||
|
|
|
|
BitIsOn(bits, XI_RawTouchUpdate) ||
|
|
|
|
BitIsOn(bits, XI_RawTouchEnd)) {
|
2011-11-05 07:32:40 -06:00
|
|
|
client->errorValue = XI_RawKeyPress;
|
2010-07-27 13:02:24 -06:00
|
|
|
return BadValue;
|
2011-11-05 07:32:40 -06:00
|
|
|
}
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (evmask->mask_len >= 1) {
|
|
|
|
unsigned char *bits = (unsigned char *) &evmask[1];
|
|
|
|
|
|
|
|
/* All three touch events must be selected at once */
|
|
|
|
if ((BitIsOn(bits, XI_TouchBegin) ||
|
|
|
|
BitIsOn(bits, XI_TouchUpdate) ||
|
|
|
|
BitIsOn(bits, XI_TouchOwnership) ||
|
|
|
|
BitIsOn(bits, XI_TouchEnd)) &&
|
|
|
|
(!BitIsOn(bits, XI_TouchBegin) ||
|
|
|
|
!BitIsOn(bits, XI_TouchUpdate) ||
|
|
|
|
!BitIsOn(bits, XI_TouchEnd))) {
|
|
|
|
client->errorValue = XI_TouchBegin;
|
|
|
|
return BadValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Only one client per window may select for touch events on the
|
|
|
|
* same devices, including master devices.
|
|
|
|
* XXX: This breaks if a device goes from floating to attached. */
|
|
|
|
if (BitIsOn(bits, XI_TouchBegin)) {
|
2013-06-07 11:28:45 -06:00
|
|
|
rc = check_for_touch_selection_conflicts(client,
|
|
|
|
win,
|
|
|
|
evmask->deviceid);
|
|
|
|
if (rc != Success)
|
|
|
|
return rc;
|
2012-06-10 07:21:05 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (XICheckInvalidMaskBits(client, (unsigned char *) &evmask[1],
|
2010-07-27 13:02:24 -06:00
|
|
|
evmask->mask_len * 4) != Success)
|
|
|
|
return BadValue;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
evmask =
|
|
|
|
(xXIEventMask *) (((unsigned char *) evmask) +
|
|
|
|
evmask->mask_len * 4);
|
2010-07-27 13:02:24 -06:00
|
|
|
evmask++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bytes_to_int32(len) != stuff->length)
|
|
|
|
return BadLength;
|
|
|
|
|
|
|
|
/* Set masks on window */
|
2012-06-10 07:21:05 -06:00
|
|
|
evmask = (xXIEventMask *) &stuff[1];
|
2010-07-27 13:02:24 -06:00
|
|
|
num_masks = stuff->num_masks;
|
2012-06-10 07:21:05 -06:00
|
|
|
while (num_masks--) {
|
2010-07-27 13:02:24 -06:00
|
|
|
if (evmask->deviceid == XIAllDevices ||
|
2012-06-10 07:21:05 -06:00
|
|
|
evmask->deviceid == XIAllMasterDevices) {
|
2010-07-27 13:02:24 -06:00
|
|
|
dummy.id = evmask->deviceid;
|
|
|
|
dev = &dummy;
|
2012-06-10 07:21:05 -06:00
|
|
|
}
|
|
|
|
else
|
2010-07-27 13:02:24 -06:00
|
|
|
dixLookupDevice(&dev, evmask->deviceid, client, DixUseAccess);
|
|
|
|
if (XISetEventMask(dev, win, client, evmask->mask_len * 4,
|
2012-06-10 07:21:05 -06:00
|
|
|
(unsigned char *) &evmask[1]) != Success)
|
2010-07-27 13:02:24 -06:00
|
|
|
return BadAlloc;
|
2012-06-10 07:21:05 -06:00
|
|
|
evmask =
|
|
|
|
(xXIEventMask *) (((unsigned char *) evmask) +
|
|
|
|
evmask->mask_len * 4);
|
2010-07-27 13:02:24 -06:00
|
|
|
evmask++;
|
|
|
|
}
|
|
|
|
|
|
|
|
RecalculateDeliverableEvents(win);
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
free(types);
|
2010-07-27 13:02:24 -06:00
|
|
|
return Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
SProcXIGetSelectedEvents(ClientPtr client)
|
|
|
|
{
|
|
|
|
REQUEST(xXIGetSelectedEventsReq);
|
2012-06-10 07:21:05 -06:00
|
|
|
swaps(&stuff->length);
|
2010-07-27 13:02:24 -06:00
|
|
|
REQUEST_SIZE_MATCH(xXIGetSelectedEventsReq);
|
2012-06-10 07:21:05 -06:00
|
|
|
swapl(&stuff->win);
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
return (ProcXIGetSelectedEvents(client));
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ProcXIGetSelectedEvents(ClientPtr client)
|
|
|
|
{
|
|
|
|
int rc, i;
|
|
|
|
WindowPtr win;
|
|
|
|
char *buffer = NULL;
|
|
|
|
xXIGetSelectedEventsReply reply;
|
|
|
|
OtherInputMasks *masks;
|
|
|
|
InputClientsPtr others = NULL;
|
|
|
|
xXIEventMask *evmask = NULL;
|
|
|
|
DeviceIntPtr dev;
|
|
|
|
|
|
|
|
REQUEST(xXIGetSelectedEventsReq);
|
|
|
|
REQUEST_SIZE_MATCH(xXIGetSelectedEventsReq);
|
|
|
|
|
|
|
|
rc = dixLookupWindow(&win, stuff->win, client, DixGetAttrAccess);
|
|
|
|
if (rc != Success)
|
|
|
|
return rc;
|
|
|
|
|
2013-06-07 11:28:45 -06:00
|
|
|
reply = (xXIGetSelectedEventsReply) {
|
|
|
|
.repType = X_Reply,
|
|
|
|
.RepType = X_XIGetSelectedEvents,
|
|
|
|
.sequenceNumber = client->sequence,
|
|
|
|
.length = 0,
|
|
|
|
.num_masks = 0
|
|
|
|
};
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
masks = wOtherInputMasks(win);
|
2012-06-10 07:21:05 -06:00
|
|
|
if (masks) {
|
|
|
|
for (others = wOtherInputMasks(win)->inputClients; others;
|
|
|
|
others = others->next) {
|
|
|
|
if (SameClient(others, client)) {
|
2010-07-27 13:02:24 -06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!others) {
|
2010-07-27 13:02:24 -06:00
|
|
|
WriteReplyToClient(client, sizeof(xXIGetSelectedEventsReply), &reply);
|
|
|
|
return Success;
|
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
buffer =
|
|
|
|
calloc(MAXDEVICES, sizeof(xXIEventMask) + pad_to_int32(XI2MASKSIZE));
|
2010-07-27 13:02:24 -06:00
|
|
|
if (!buffer)
|
|
|
|
return BadAlloc;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
evmask = (xXIEventMask *) buffer;
|
|
|
|
for (i = 0; i < MAXDEVICES; i++) {
|
2010-07-27 13:02:24 -06:00
|
|
|
int j;
|
2012-06-10 07:21:05 -06:00
|
|
|
const unsigned char *devmask = xi2mask_get_one_mask(others->xi2mask, i);
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (i > 2) {
|
2010-07-27 13:02:24 -06:00
|
|
|
rc = dixLookupDevice(&dev, i, client, DixGetAttrAccess);
|
|
|
|
if (rc != Success)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
for (j = xi2mask_mask_size(others->xi2mask) - 1; j >= 0; j--) {
|
|
|
|
if (devmask[j] != 0) {
|
|
|
|
int mask_len = (j + 4) / 4; /* j is an index, hence + 4, not + 3 */
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
evmask->deviceid = i;
|
|
|
|
evmask->mask_len = mask_len;
|
|
|
|
reply.num_masks++;
|
2012-06-10 07:21:05 -06:00
|
|
|
reply.length += sizeof(xXIEventMask) / 4 + evmask->mask_len;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (client->swapped) {
|
|
|
|
swaps(&evmask->deviceid);
|
|
|
|
swaps(&evmask->mask_len);
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(&evmask[1], devmask, j + 1);
|
2012-06-10 07:21:05 -06:00
|
|
|
evmask = (xXIEventMask *) ((char *) evmask +
|
|
|
|
sizeof(xXIEventMask) + mask_len * 4);
|
2010-07-27 13:02:24 -06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
WriteReplyToClient(client, sizeof(xXIGetSelectedEventsReply), &reply);
|
|
|
|
|
|
|
|
if (reply.num_masks)
|
|
|
|
WriteToClient(client, reply.length * 4, buffer);
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
free(buffer);
|
2010-07-27 13:02:24 -06:00
|
|
|
return Success;
|
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
void
|
|
|
|
SRepXIGetSelectedEvents(ClientPtr client,
|
|
|
|
int len, xXIGetSelectedEventsReply * rep)
|
2010-07-27 13:02:24 -06:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
swaps(&rep->sequenceNumber);
|
|
|
|
swapl(&rep->length);
|
|
|
|
swaps(&rep->num_masks);
|
2013-06-07 11:28:45 -06:00
|
|
|
WriteToClient(client, len, rep);
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|