2010-07-27 13:02:24 -06:00
|
|
|
/*
|
|
|
|
* Copyright © 2009 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
*
|
|
|
|
* Request to grab or ungrab input device.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_DIX_CONFIG_H
|
|
|
|
#include <dix-config.h>
|
|
|
|
#endif
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
#include "inputstr.h" /* DeviceIntPtr */
|
|
|
|
#include "windowstr.h" /* window structure */
|
2010-07-27 13:02:24 -06:00
|
|
|
#include <X11/extensions/XI2.h>
|
|
|
|
#include <X11/extensions/XI2proto.h>
|
|
|
|
#include "swaprep.h"
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
#include "exglobals.h" /* BadDevice */
|
2010-07-27 13:02:24 -06:00
|
|
|
#include "exevents.h"
|
|
|
|
#include "xipassivegrab.h"
|
|
|
|
#include "dixgrabs.h"
|
2011-11-05 07:32:40 -06:00
|
|
|
#include "misc.h"
|
2012-06-10 07:21:05 -06:00
|
|
|
#include "inpututils.h"
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2019-07-27 01:57:06 -06:00
|
|
|
int _X_COLD
|
2010-07-27 13:02:24 -06:00
|
|
|
SProcXIPassiveGrabDevice(ClientPtr client)
|
|
|
|
{
|
|
|
|
int i;
|
2013-06-07 11:28:45 -06:00
|
|
|
uint32_t *mods;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
REQUEST(xXIPassiveGrabDeviceReq);
|
2014-12-09 10:58:52 -07:00
|
|
|
REQUEST_AT_LEAST_SIZE(xXIPassiveGrabDeviceReq);
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
swaps(&stuff->length);
|
|
|
|
swaps(&stuff->deviceid);
|
|
|
|
swapl(&stuff->grab_window);
|
|
|
|
swapl(&stuff->cursor);
|
|
|
|
swapl(&stuff->time);
|
|
|
|
swapl(&stuff->detail);
|
|
|
|
swaps(&stuff->mask_len);
|
|
|
|
swaps(&stuff->num_modifiers);
|
|
|
|
|
2014-12-09 10:58:52 -07:00
|
|
|
REQUEST_FIXED_SIZE(xXIPassiveGrabDeviceReq,
|
|
|
|
((uint32_t) stuff->mask_len + stuff->num_modifiers) *4);
|
2014-05-02 13:27:46 -06:00
|
|
|
mods = (uint32_t *) &stuff[1] + stuff->mask_len;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
|
|
|
for (i = 0; i < stuff->num_modifiers; i++, mods++) {
|
2013-06-07 11:28:45 -06:00
|
|
|
swapl(mods);
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return ProcXIPassiveGrabDevice(client);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ProcXIPassiveGrabDevice(ClientPtr client)
|
|
|
|
{
|
|
|
|
DeviceIntPtr dev, mod_dev;
|
2013-06-07 11:28:45 -06:00
|
|
|
xXIPassiveGrabDeviceReply rep = {
|
|
|
|
.repType = X_Reply,
|
|
|
|
.RepType = X_XIPassiveGrabDevice,
|
|
|
|
.sequenceNumber = client->sequence,
|
|
|
|
.length = 0,
|
|
|
|
.num_modifiers = 0
|
|
|
|
};
|
2010-07-27 13:02:24 -06:00
|
|
|
int i, ret = Success;
|
|
|
|
uint32_t *modifiers;
|
2019-07-27 01:57:06 -06:00
|
|
|
xXIGrabModifierInfo *modifiers_failed = NULL;
|
2012-06-10 07:21:05 -06:00
|
|
|
GrabMask mask = { 0 };
|
2010-07-27 13:02:24 -06:00
|
|
|
GrabParameters param;
|
|
|
|
void *tmp;
|
|
|
|
int mask_len;
|
|
|
|
|
|
|
|
REQUEST(xXIPassiveGrabDeviceReq);
|
2014-12-09 10:58:52 -07:00
|
|
|
REQUEST_FIXED_SIZE(xXIPassiveGrabDeviceReq,
|
|
|
|
((uint32_t) stuff->mask_len + stuff->num_modifiers) * 4);
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
if (stuff->deviceid == XIAllDevices)
|
|
|
|
dev = inputInfo.all_devices;
|
|
|
|
else if (stuff->deviceid == XIAllMasterDevices)
|
|
|
|
dev = inputInfo.all_master_devices;
|
2012-06-10 07:21:05 -06:00
|
|
|
else {
|
2010-07-27 13:02:24 -06:00
|
|
|
ret = dixLookupDevice(&dev, stuff->deviceid, client, DixGrabAccess);
|
2012-06-10 07:21:05 -06:00
|
|
|
if (ret != Success) {
|
2011-11-05 07:32:40 -06:00
|
|
|
client->errorValue = stuff->deviceid;
|
2010-07-27 13:02:24 -06:00
|
|
|
return ret;
|
2011-11-05 07:32:40 -06:00
|
|
|
}
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if (stuff->grab_type != XIGrabtypeButton &&
|
|
|
|
stuff->grab_type != XIGrabtypeKeycode &&
|
|
|
|
stuff->grab_type != XIGrabtypeEnter &&
|
2012-06-10 07:21:05 -06:00
|
|
|
stuff->grab_type != XIGrabtypeFocusIn &&
|
|
|
|
stuff->grab_type != XIGrabtypeTouchBegin) {
|
2010-07-27 13:02:24 -06:00
|
|
|
client->errorValue = stuff->grab_type;
|
|
|
|
return BadValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((stuff->grab_type == XIGrabtypeEnter ||
|
2012-06-10 07:21:05 -06:00
|
|
|
stuff->grab_type == XIGrabtypeFocusIn ||
|
|
|
|
stuff->grab_type == XIGrabtypeTouchBegin) && stuff->detail != 0) {
|
2010-07-27 13:02:24 -06:00
|
|
|
client->errorValue = stuff->detail;
|
|
|
|
return BadValue;
|
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (stuff->grab_type == XIGrabtypeTouchBegin &&
|
|
|
|
(stuff->grab_mode != XIGrabModeTouch ||
|
|
|
|
stuff->paired_device_mode != GrabModeAsync)) {
|
|
|
|
client->errorValue = stuff->grab_mode;
|
|
|
|
return BadValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (XICheckInvalidMaskBits(client, (unsigned char *) &stuff[1],
|
2010-07-27 13:02:24 -06:00
|
|
|
stuff->mask_len * 4) != Success)
|
|
|
|
return BadValue;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
mask.xi2mask = xi2mask_new();
|
|
|
|
if (!mask.xi2mask)
|
|
|
|
return BadAlloc;
|
|
|
|
|
|
|
|
mask_len = min(xi2mask_mask_size(mask.xi2mask), stuff->mask_len * 4);
|
|
|
|
xi2mask_set_one_mask(mask.xi2mask, stuff->deviceid,
|
|
|
|
(unsigned char *) &stuff[1], mask_len * 4);
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
memset(¶m, 0, sizeof(param));
|
2012-06-10 07:21:05 -06:00
|
|
|
param.grabtype = XI2;
|
2010-07-27 13:02:24 -06:00
|
|
|
param.ownerEvents = stuff->owner_events;
|
|
|
|
param.grabWindow = stuff->grab_window;
|
|
|
|
param.cursor = stuff->cursor;
|
|
|
|
|
2012-01-31 00:52:35 -07:00
|
|
|
if (IsKeyboardDevice(dev)) {
|
|
|
|
param.this_device_mode = stuff->grab_mode;
|
|
|
|
param.other_devices_mode = stuff->paired_device_mode;
|
2012-06-10 07:21:05 -06:00
|
|
|
}
|
|
|
|
else {
|
2012-01-31 00:52:35 -07:00
|
|
|
param.this_device_mode = stuff->paired_device_mode;
|
|
|
|
param.other_devices_mode = stuff->grab_mode;
|
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (stuff->cursor != None) {
|
|
|
|
ret = dixLookupResourceByType(&tmp, stuff->cursor,
|
|
|
|
RT_CURSOR, client, DixUseAccess);
|
|
|
|
if (ret != Success) {
|
|
|
|
client->errorValue = stuff->cursor;
|
|
|
|
goto out;
|
|
|
|
}
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
ret =
|
|
|
|
dixLookupWindow((WindowPtr *) &tmp, stuff->grab_window, client,
|
|
|
|
DixSetAttrAccess);
|
|
|
|
if (ret != Success)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
ret = CheckGrabValues(client, ¶m);
|
|
|
|
if (ret != Success)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
modifiers = (uint32_t *) &stuff[1] + stuff->mask_len;
|
|
|
|
modifiers_failed =
|
|
|
|
calloc(stuff->num_modifiers, sizeof(xXIGrabModifierInfo));
|
|
|
|
if (!modifiers_failed) {
|
|
|
|
ret = BadAlloc;
|
|
|
|
goto out;
|
|
|
|
}
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
mod_dev = (IsFloating(dev)) ? dev : GetMaster(dev, MASTER_KEYBOARD);
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
for (i = 0; i < stuff->num_modifiers; i++, modifiers++) {
|
|
|
|
uint8_t status = Success;
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
param.modifiers = *modifiers;
|
2014-05-02 13:27:46 -06:00
|
|
|
ret = CheckGrabValues(client, ¶m);
|
|
|
|
if (ret != Success)
|
|
|
|
goto out;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
switch (stuff->grab_type) {
|
|
|
|
case XIGrabtypeButton:
|
|
|
|
status = GrabButton(client, dev, mod_dev, stuff->detail,
|
|
|
|
¶m, XI2, &mask);
|
|
|
|
break;
|
|
|
|
case XIGrabtypeKeycode:
|
|
|
|
status = GrabKey(client, dev, mod_dev, stuff->detail,
|
|
|
|
¶m, XI2, &mask);
|
|
|
|
break;
|
|
|
|
case XIGrabtypeEnter:
|
|
|
|
case XIGrabtypeFocusIn:
|
|
|
|
status = GrabWindow(client, dev, stuff->grab_type, ¶m, &mask);
|
|
|
|
break;
|
|
|
|
case XIGrabtypeTouchBegin:
|
|
|
|
status = GrabTouch(client, dev, mod_dev, ¶m, &mask);
|
|
|
|
break;
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (status != GrabSuccess) {
|
2010-07-27 13:02:24 -06:00
|
|
|
xXIGrabModifierInfo *info = modifiers_failed + rep.num_modifiers;
|
|
|
|
|
|
|
|
info->status = status;
|
|
|
|
info->modifiers = *modifiers;
|
2011-11-05 07:32:40 -06:00
|
|
|
if (client->swapped)
|
2012-06-10 07:21:05 -06:00
|
|
|
swapl(&info->modifiers);
|
2011-11-05 07:32:40 -06:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
rep.num_modifiers++;
|
2011-11-05 07:32:40 -06:00
|
|
|
rep.length += bytes_to_int32(sizeof(xXIGrabModifierInfo));
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
WriteReplyToClient(client, sizeof(rep), &rep);
|
|
|
|
if (rep.num_modifiers)
|
2013-06-07 11:28:45 -06:00
|
|
|
WriteToClient(client, rep.length * 4, modifiers_failed);
|
2011-11-05 07:32:40 -06:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
out:
|
2019-07-27 01:57:06 -06:00
|
|
|
free(modifiers_failed);
|
2012-06-10 07:21:05 -06:00
|
|
|
xi2mask_free(&mask.xi2mask);
|
2010-07-27 13:02:24 -06:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-07-27 01:57:06 -06:00
|
|
|
void _X_COLD
|
2010-07-27 13:02:24 -06:00
|
|
|
SRepXIPassiveGrabDevice(ClientPtr client, int size,
|
|
|
|
xXIPassiveGrabDeviceReply * rep)
|
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
swaps(&rep->sequenceNumber);
|
|
|
|
swapl(&rep->length);
|
|
|
|
swaps(&rep->num_modifiers);
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2013-06-07 11:28:45 -06:00
|
|
|
WriteToClient(client, size, rep);
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
|
2019-07-27 01:57:06 -06:00
|
|
|
int _X_COLD
|
2010-07-27 13:02:24 -06:00
|
|
|
SProcXIPassiveUngrabDevice(ClientPtr client)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
uint32_t *modifiers;
|
|
|
|
|
|
|
|
REQUEST(xXIPassiveUngrabDeviceReq);
|
2014-12-09 10:58:52 -07:00
|
|
|
REQUEST_AT_LEAST_SIZE(xXIPassiveUngrabDeviceReq);
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
swaps(&stuff->length);
|
|
|
|
swapl(&stuff->grab_window);
|
|
|
|
swaps(&stuff->deviceid);
|
|
|
|
swapl(&stuff->detail);
|
|
|
|
swaps(&stuff->num_modifiers);
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2014-12-09 10:58:52 -07:00
|
|
|
REQUEST_FIXED_SIZE(xXIPassiveUngrabDeviceReq,
|
|
|
|
((uint32_t) stuff->num_modifiers) << 2);
|
2012-06-10 07:21:05 -06:00
|
|
|
modifiers = (uint32_t *) &stuff[1];
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
for (i = 0; i < stuff->num_modifiers; i++, modifiers++)
|
2012-06-10 07:21:05 -06:00
|
|
|
swapl(modifiers);
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
return ProcXIPassiveUngrabDevice(client);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ProcXIPassiveUngrabDevice(ClientPtr client)
|
|
|
|
{
|
|
|
|
DeviceIntPtr dev, mod_dev;
|
|
|
|
WindowPtr win;
|
2012-06-10 07:21:05 -06:00
|
|
|
GrabPtr tempGrab;
|
|
|
|
uint32_t *modifiers;
|
2010-07-27 13:02:24 -06:00
|
|
|
int i, rc;
|
|
|
|
|
|
|
|
REQUEST(xXIPassiveUngrabDeviceReq);
|
2014-12-09 10:58:52 -07:00
|
|
|
REQUEST_FIXED_SIZE(xXIPassiveUngrabDeviceReq,
|
|
|
|
((uint32_t) stuff->num_modifiers) << 2);
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
if (stuff->deviceid == XIAllDevices)
|
|
|
|
dev = inputInfo.all_devices;
|
|
|
|
else if (stuff->deviceid == XIAllMasterDevices)
|
|
|
|
dev = inputInfo.all_master_devices;
|
2012-06-10 07:21:05 -06:00
|
|
|
else {
|
2011-11-05 07:32:40 -06:00
|
|
|
rc = dixLookupDevice(&dev, stuff->deviceid, client, DixGrabAccess);
|
|
|
|
if (rc != Success)
|
2012-06-10 07:21:05 -06:00
|
|
|
return rc;
|
2011-11-05 07:32:40 -06:00
|
|
|
}
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
if (stuff->grab_type != XIGrabtypeButton &&
|
|
|
|
stuff->grab_type != XIGrabtypeKeycode &&
|
|
|
|
stuff->grab_type != XIGrabtypeEnter &&
|
2012-06-10 07:21:05 -06:00
|
|
|
stuff->grab_type != XIGrabtypeFocusIn &&
|
|
|
|
stuff->grab_type != XIGrabtypeTouchBegin) {
|
2010-07-27 13:02:24 -06:00
|
|
|
client->errorValue = stuff->grab_type;
|
|
|
|
return BadValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((stuff->grab_type == XIGrabtypeEnter ||
|
2012-06-10 07:21:05 -06:00
|
|
|
stuff->grab_type == XIGrabtypeFocusIn ||
|
|
|
|
stuff->grab_type == XIGrabtypeTouchBegin) && stuff->detail != 0) {
|
2010-07-27 13:02:24 -06:00
|
|
|
client->errorValue = stuff->detail;
|
|
|
|
return BadValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = dixLookupWindow(&win, stuff->grab_window, client, DixSetAttrAccess);
|
|
|
|
if (rc != Success)
|
|
|
|
return rc;
|
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
mod_dev = (IsFloating(dev)) ? dev : GetMaster(dev, MASTER_KEYBOARD);
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2013-09-28 09:36:30 -06:00
|
|
|
tempGrab = AllocGrab(NULL);
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!tempGrab)
|
|
|
|
return BadAlloc;
|
|
|
|
|
|
|
|
tempGrab->resource = client->clientAsMask;
|
|
|
|
tempGrab->device = dev;
|
|
|
|
tempGrab->window = win;
|
|
|
|
switch (stuff->grab_type) {
|
|
|
|
case XIGrabtypeButton:
|
|
|
|
tempGrab->type = XI_ButtonPress;
|
|
|
|
break;
|
|
|
|
case XIGrabtypeKeycode:
|
|
|
|
tempGrab->type = XI_KeyPress;
|
|
|
|
break;
|
|
|
|
case XIGrabtypeEnter:
|
|
|
|
tempGrab->type = XI_Enter;
|
|
|
|
break;
|
|
|
|
case XIGrabtypeFocusIn:
|
|
|
|
tempGrab->type = XI_FocusIn;
|
|
|
|
break;
|
|
|
|
case XIGrabtypeTouchBegin:
|
|
|
|
tempGrab->type = XI_TouchBegin;
|
|
|
|
break;
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
tempGrab->grabtype = XI2;
|
|
|
|
tempGrab->modifierDevice = mod_dev;
|
|
|
|
tempGrab->modifiersDetail.pMask = NULL;
|
|
|
|
tempGrab->detail.exact = stuff->detail;
|
|
|
|
tempGrab->detail.pMask = NULL;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
modifiers = (uint32_t *) &stuff[1];
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
for (i = 0; i < stuff->num_modifiers; i++, modifiers++) {
|
|
|
|
tempGrab->modifiersDetail.exact = *modifiers;
|
|
|
|
DeletePassiveGrabFromList(tempGrab);
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
FreeGrab(tempGrab);
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
return Success;
|
|
|
|
}
|