1 /************************************************************
3 Copyright 1989, 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 in
12 all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 Except as contained in this notice, the name of The Open Group shall not be
22 used in advertising or otherwise to promote the sale, use or other dealings
23 in this Software without prior written authorization from The Open Group.
25 Copyright 1989 by Hewlett-Packard Company, Palo Alto, California.
29 Permission to use, copy, modify, and distribute this software and its
30 documentation for any purpose and without fee is hereby granted,
31 provided that the above copyright notice appear in all copies and that
32 both that copyright notice and this permission notice appear in
33 supporting documentation, and that the name of Hewlett-Packard not be
34 used in advertising or publicity pertaining to distribution of the
35 software without specific, written prior permission.
37 HEWLETT-PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
38 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
39 HEWLETT-PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
40 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
41 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
42 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
45 ********************************************************/
47 /********************************************************************
49 * Get Device control attributes for an extension device.
53 #define NEED_EVENTS /* for inputstr.h */
55 #ifdef HAVE_DIX_CONFIG_H
56 #include <dix-config.h>
59 #include <X11/X.h> /* for inputstr.h */
60 #include <X11/Xproto.h> /* Request macro */
61 #include "inputstr.h" /* DeviceIntPtr */
62 #include <X11/extensions/XI.h>
63 #include <X11/extensions/XIproto.h>
64 #include "extnsionst.h"
65 #include "extinit.h" /* LookupDeviceIntRec */
66 #include "exglobals.h"
70 /***********************************************************************
72 * This procedure gets the control attributes for an extension device,
73 * for clients on machines with a different byte ordering than the server.
78 SProcXGetDeviceControl(ClientPtr client
)
82 REQUEST(xGetDeviceControlReq
);
83 swaps(&stuff
->length
, n
);
84 REQUEST_SIZE_MATCH(xGetDeviceControlReq
);
85 swaps(&stuff
->control
, n
);
86 return (ProcXGetDeviceControl(client
));
89 /***********************************************************************
91 * This procedure copies DeviceResolution data, swapping if necessary.
96 CopySwapDeviceResolution(ClientPtr client
, ValuatorClassPtr v
, char *buf
,
101 xDeviceResolutionState
*r
;
104 r
= (xDeviceResolutionState
*) buf
;
105 r
->control
= DEVICE_RESOLUTION
;
107 r
->num_valuators
= v
->numAxes
;
108 buf
+= sizeof(xDeviceResolutionState
);
110 for (i
= 0, a
= v
->axes
; i
< v
->numAxes
; i
++, a
++)
111 *iptr
++ = a
->resolution
;
112 for (i
= 0, a
= v
->axes
; i
< v
->numAxes
; i
++, a
++)
113 *iptr
++ = a
->min_resolution
;
114 for (i
= 0, a
= v
->axes
; i
< v
->numAxes
; i
++, a
++)
115 *iptr
++ = a
->max_resolution
;
116 if (client
->swapped
) {
117 swaps(&r
->control
, n
);
118 swaps(&r
->length
, n
);
119 swapl(&r
->num_valuators
, n
);
121 for (i
= 0; i
< (3 * v
->numAxes
); i
++, iptr
++) {
127 static void CopySwapDeviceAbsCalib (ClientPtr client
, AbsoluteClassPtr dts
,
131 xDeviceAbsCalibState
*calib
= (xDeviceAbsCalibState
*) buf
;
133 calib
->control
= DEVICE_ABS_CALIB
;
134 calib
->length
= sizeof(calib
);
135 calib
->min_x
= dts
->min_x
;
136 calib
->max_x
= dts
->max_x
;
137 calib
->min_y
= dts
->min_y
;
138 calib
->max_y
= dts
->max_y
;
139 calib
->flip_x
= dts
->flip_x
;
140 calib
->flip_y
= dts
->flip_y
;
141 calib
->rotation
= dts
->rotation
;
142 calib
->button_threshold
= dts
->button_threshold
;
144 if (client
->swapped
) {
145 swaps(&calib
->control
, n
);
146 swaps(&calib
->length
, n
);
147 swapl(&calib
->min_x
, n
);
148 swapl(&calib
->max_x
, n
);
149 swapl(&calib
->min_y
, n
);
150 swapl(&calib
->max_y
, n
);
151 swapl(&calib
->flip_x
, n
);
152 swapl(&calib
->flip_y
, n
);
153 swapl(&calib
->rotation
, n
);
154 swapl(&calib
->button_threshold
, n
);
158 static void CopySwapDeviceAbsArea (ClientPtr client
, AbsoluteClassPtr dts
,
162 xDeviceAbsAreaState
*area
= (xDeviceAbsAreaState
*) buf
;
164 area
->control
= DEVICE_ABS_AREA
;
165 area
->length
= sizeof(area
);
166 area
->offset_x
= dts
->offset_x
;
167 area
->offset_y
= dts
->offset_y
;
168 area
->width
= dts
->width
;
169 area
->height
= dts
->height
;
170 area
->screen
= dts
->screen
;
171 area
->following
= dts
->following
;
173 if (client
->swapped
) {
174 swaps(&area
->control
, n
);
175 swaps(&area
->length
, n
);
176 swapl(&area
->offset_x
, n
);
177 swapl(&area
->offset_y
, n
);
178 swapl(&area
->width
, n
);
179 swapl(&area
->height
, n
);
180 swapl(&area
->screen
, n
);
181 swapl(&area
->following
, n
);
185 static void CopySwapDeviceCore (ClientPtr client
, DeviceIntPtr dev
, char *buf
)
188 xDeviceCoreState
*c
= (xDeviceCoreState
*) buf
;
190 c
->control
= DEVICE_CORE
;
191 c
->length
= sizeof(c
);
192 c
->status
= dev
->coreEvents
;
193 c
->iscore
= (dev
== inputInfo
.keyboard
|| dev
== inputInfo
.pointer
);
195 if (client
->swapped
) {
196 swaps(&c
->control
, n
);
197 swaps(&c
->length
, n
);
198 swaps(&c
->status
, n
);
202 static void CopySwapDeviceEnable (ClientPtr client
, DeviceIntPtr dev
, char *buf
)
205 xDeviceEnableState
*e
= (xDeviceEnableState
*) buf
;
207 e
->control
= DEVICE_ENABLE
;
208 e
->length
= sizeof(e
);
209 e
->enable
= dev
->enabled
;
211 if (client
->swapped
) {
212 swaps(&e
->control
, n
);
213 swaps(&e
->length
, n
);
214 swaps(&e
->enable
, n
);
218 /***********************************************************************
220 * This procedure writes the reply for the xGetDeviceControl function,
221 * if the client and server have a different byte ordering.
226 SRepXGetDeviceControl(ClientPtr client
, int size
, xGetDeviceControlReply
* rep
)
230 swaps(&rep
->sequenceNumber
, n
);
231 swapl(&rep
->length
, n
);
232 WriteToClient(client
, size
, (char *)rep
);
235 /***********************************************************************
237 * Get the state of the specified device control.
242 ProcXGetDeviceControl(ClientPtr client
)
244 int total_length
= 0;
247 xGetDeviceControlReply rep
;
249 REQUEST(xGetDeviceControlReq
);
250 REQUEST_SIZE_MATCH(xGetDeviceControlReq
);
252 dev
= LookupDeviceIntRec(stuff
->deviceid
);
254 SendErrorToClient(client
, IReqCode
, X_GetDeviceControl
, 0, BadDevice
);
258 rep
.repType
= X_Reply
;
259 rep
.RepType
= X_GetDeviceControl
;
261 rep
.sequenceNumber
= client
->sequence
;
263 switch (stuff
->control
) {
264 case DEVICE_RESOLUTION
:
265 if (!dev
->valuator
) {
266 SendErrorToClient(client
, IReqCode
, X_GetDeviceControl
, 0,
270 total_length
= sizeof(xDeviceResolutionState
) +
271 (3 * sizeof(int) * dev
->valuator
->numAxes
);
273 case DEVICE_ABS_CALIB
:
274 if (!dev
->absolute
) {
275 SendErrorToClient(client
, IReqCode
, X_GetDeviceControl
, 0,
280 total_length
= sizeof(xDeviceAbsCalibCtl
);
282 case DEVICE_ABS_AREA
:
283 if (!dev
->absolute
) {
284 SendErrorToClient(client
, IReqCode
, X_GetDeviceControl
, 0,
289 total_length
= sizeof(xDeviceAbsAreaCtl
);
292 total_length
= sizeof(xDeviceCoreCtl
);
295 total_length
= sizeof(xDeviceEnableCtl
);
298 SendErrorToClient(client
, IReqCode
, X_GetDeviceControl
, 0, BadValue
);
302 buf
= (char *)xalloc(total_length
);
304 SendErrorToClient(client
, IReqCode
, X_GetDeviceControl
, 0, BadAlloc
);
309 switch (stuff
->control
) {
310 case DEVICE_RESOLUTION
:
311 CopySwapDeviceResolution(client
, dev
->valuator
, buf
, total_length
);
313 case DEVICE_ABS_CALIB
:
314 CopySwapDeviceAbsCalib(client
, dev
->absolute
, buf
);
316 case DEVICE_ABS_AREA
:
317 CopySwapDeviceAbsArea(client
, dev
->absolute
, buf
);
320 CopySwapDeviceCore(client
, dev
, buf
);
323 CopySwapDeviceEnable(client
, dev
, buf
);
329 rep
.length
= (total_length
+ 3) >> 2;
330 WriteReplyToClient(client
, sizeof(xGetDeviceControlReply
), &rep
);
331 WriteToClient(client
, total_length
, savbuf
);