2 * Copyright © 2009 Red Hat, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
23 * Author: Peter Hutterer
26 /***********************************************************************
28 * Request to grab or ungrab input device.
32 #ifdef HAVE_DIX_CONFIG_H
33 #include <dix-config.h>
36 #include "inputstr.h" /* DeviceIntPtr */
37 #include "windowstr.h" /* window structure */
38 #include <X11/extensions/XI2.h>
39 #include <X11/extensions/XI2proto.h>
41 #include "exglobals.h" /* BadDevice */
43 #include "xigrabdev.h"
44 #include "inpututils.h"
47 SProcXIGrabDevice(ClientPtr client
)
49 REQUEST(xXIGrabDeviceReq
);
51 swaps(&stuff
->length
);
52 swaps(&stuff
->deviceid
);
53 swapl(&stuff
->grab_window
);
54 swapl(&stuff
->cursor
);
56 swaps(&stuff
->mask_len
);
58 return ProcXIGrabDevice(client
);
62 ProcXIGrabDevice(ClientPtr client
)
65 xXIGrabDeviceReply rep
;
68 GrabMask mask
= { 0 };
70 unsigned int keyboard_mode
;
71 unsigned int pointer_mode
;
73 REQUEST(xXIGrabDeviceReq
);
74 REQUEST_AT_LEAST_SIZE(xXIGrabDeviceReq
);
76 ret
= dixLookupDevice(&dev
, stuff
->deviceid
, client
, DixGrabAccess
);
81 stuff
->paired_device_mode
= GrabModeAsync
;
83 if (IsKeyboardDevice(dev
)) {
84 keyboard_mode
= stuff
->grab_mode
;
85 pointer_mode
= stuff
->paired_device_mode
;
88 keyboard_mode
= stuff
->paired_device_mode
;
89 pointer_mode
= stuff
->grab_mode
;
92 if (XICheckInvalidMaskBits(client
, (unsigned char *) &stuff
[1],
93 stuff
->mask_len
* 4) != Success
)
96 mask
.xi2mask
= xi2mask_new();
100 mask_len
= min(xi2mask_mask_size(mask
.xi2mask
), stuff
->mask_len
* 4);
101 /* FIXME: I think the old code was broken here */
102 xi2mask_set_one_mask(mask
.xi2mask
, dev
->id
, (unsigned char *) &stuff
[1],
105 ret
= GrabDevice(client
, dev
, pointer_mode
,
110 &mask
, XI2
, stuff
->cursor
, None
/* confineTo */ ,
113 xi2mask_free(&mask
.xi2mask
);
118 rep
= (xXIGrabDeviceReply
) {
120 .RepType
= X_XIGrabDevice
,
121 .sequenceNumber
= client
->sequence
,
126 WriteReplyToClient(client
, sizeof(rep
), &rep
);
131 SProcXIUngrabDevice(ClientPtr client
)
133 REQUEST(xXIUngrabDeviceReq
);
135 swaps(&stuff
->length
);
136 swaps(&stuff
->deviceid
);
139 return ProcXIUngrabDevice(client
);
143 ProcXIUngrabDevice(ClientPtr client
)
150 REQUEST(xXIUngrabDeviceReq
);
152 ret
= dixLookupDevice(&dev
, stuff
->deviceid
, client
, DixGetAttrAccess
);
156 grab
= dev
->deviceGrab
.grab
;
158 time
= ClientTimeToServerTime(stuff
->time
);
159 if ((CompareTimeStamps(time
, currentTime
) != LATER
) &&
160 (CompareTimeStamps(time
, dev
->deviceGrab
.grabTime
) != EARLIER
) &&
161 (grab
) && SameClient(grab
, client
) && grab
->grabtype
== XI2
)
162 (*dev
->deviceGrab
.DeactivateGrab
) (dev
);
168 SRepXIGrabDevice(ClientPtr client
, int size
, xXIGrabDeviceReply
* rep
)
170 swaps(&rep
->sequenceNumber
);
172 WriteToClient(client
, size
, rep
);