3 Copyright 1998, 1998 The Open Group
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
11 The above copyright notice and this permission notice shall be included
12 in all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 OTHER DEALINGS IN THE SOFTWARE.
22 Except as contained in this notice, the name of The Open Group shall
23 not be used in advertising or otherwise to promote the sale, use or
24 other dealings in this Software without prior written authorization
29 /***********************************************************************
31 * Request to query the state of an extension input device.
35 #ifdef HAVE_DIX_CONFIG_H
36 #include <dix-config.h>
39 #include "inputstr.h" /* DeviceIntPtr */
40 #include "windowstr.h" /* window structure */
41 #include <X11/extensions/XI.h>
42 #include <X11/extensions/XIproto.h>
44 #include "exglobals.h"
50 /***********************************************************************
52 * This procedure allows a client to query the state of a device.
57 SProcXQueryDeviceState(ClientPtr client
)
59 REQUEST(xQueryDeviceStateReq
);
60 swaps(&stuff
->length
);
61 return (ProcXQueryDeviceState(client
));
64 /***********************************************************************
66 * This procedure allows frozen events to be routed.
71 ProcXQueryDeviceState(ClientPtr client
)
83 xQueryDeviceStateReply rep
;
87 REQUEST(xQueryDeviceStateReq
);
88 REQUEST_SIZE_MATCH(xQueryDeviceStateReq
);
90 rc
= dixLookupDevice(&dev
, stuff
->deviceid
, client
, DixReadAccess
);
91 if (rc
!= Success
&& rc
!= BadAccess
)
95 if (v
!= NULL
&& v
->motionHintWindow
!= NULL
)
96 MaybeStopDeviceHint(dev
, client
);
100 total_length
+= sizeof(xKeyState
);
106 total_length
+= sizeof(xButtonState
);
111 total_length
+= (sizeof(xValuatorState
) + (v
->numAxes
* sizeof(int)));
114 buf
= (char *) calloc(total_length
, 1);
120 tk
= (xKeyState
*) buf
;
121 tk
->class = KeyClass
;
122 tk
->length
= sizeof(xKeyState
);
123 tk
->num_keys
= k
->xkbInfo
->desc
->max_key_code
-
124 k
->xkbInfo
->desc
->min_key_code
+ 1;
126 for (i
= 0; i
< 32; i
++)
127 tk
->keys
[i
] = k
->down
[i
];
128 buf
+= sizeof(xKeyState
);
132 tb
= (xButtonState
*) buf
;
133 tb
->class = ButtonClass
;
134 tb
->length
= sizeof(xButtonState
);
135 tb
->num_buttons
= b
->numButtons
;
137 memcpy(tb
->buttons
, b
->down
, sizeof(b
->down
));
138 buf
+= sizeof(xButtonState
);
142 tv
= (xValuatorState
*) buf
;
143 tv
->class = ValuatorClass
;
144 tv
->length
= sizeof(xValuatorState
) + v
->numAxes
* 4;
145 tv
->num_valuators
= v
->numAxes
;
146 tv
->mode
= valuator_get_mode(dev
, 0);
147 tv
->mode
|= (dev
->proximity
&&
148 !dev
->proximity
->in_proximity
) ? OutOfProximity
: 0;
149 buf
+= sizeof(xValuatorState
);
150 for (i
= 0, values
= v
->axisVal
; i
< v
->numAxes
; i
++) {
152 *((int *) buf
) = *values
;
154 if (client
->swapped
) {
161 rep
= (xQueryDeviceStateReply
) {
163 .RepType
= X_QueryDeviceState
,
164 .sequenceNumber
= client
->sequence
,
165 .length
= bytes_to_int32(total_length
),
166 .num_classes
= num_classes
168 WriteReplyToClient(client
, sizeof(xQueryDeviceStateReply
), &rep
);
169 if (total_length
> 0)
170 WriteToClient(client
, total_length
, savbuf
);
175 /***********************************************************************
177 * This procedure writes the reply for the XQueryDeviceState function,
178 * if the client and server have a different byte ordering.
183 SRepXQueryDeviceState(ClientPtr client
, int size
, xQueryDeviceStateReply
* rep
)
185 swaps(&rep
->sequenceNumber
);
187 WriteToClient(client
, size
, rep
);