First import
[xorg_rtime.git] / xorg-server-1.4 / Xi / chgdctl.c
blob9676fb747fa09fd4db6344355737b6f895675e84
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
9 documentation.
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.
27 All Rights Reserved
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
43 SOFTWARE.
45 ********************************************************/
47 /********************************************************************
49 * Change Device control attributes for an extension device.
53 #define NEED_EVENTS /* for inputstr.h */
54 #define NEED_REPLIES
55 #ifdef HAVE_DIX_CONFIG_H
56 #include <dix-config.h>
57 #endif
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> /* control constants */
64 #include "XIstubs.h"
66 #include "extnsionst.h"
67 #include "extinit.h" /* LookupDeviceIntRec */
68 #include "exglobals.h"
69 #include "exevents.h"
71 #include "chgdctl.h"
73 /***********************************************************************
75 * This procedure changes the control attributes for an extension device,
76 * for clients on machines with a different byte ordering than the server.
80 int
81 SProcXChangeDeviceControl(ClientPtr client)
83 char n;
85 REQUEST(xChangeDeviceControlReq);
86 swaps(&stuff->length, n);
87 REQUEST_AT_LEAST_SIZE(xChangeDeviceControlReq);
88 swaps(&stuff->control, n);
89 return (ProcXChangeDeviceControl(client));
92 /***********************************************************************
94 * Change the control attributes.
98 int
99 ProcXChangeDeviceControl(ClientPtr client)
101 unsigned len;
102 int i, status, ret = BadValue;
103 DeviceIntPtr dev;
104 xDeviceResolutionCtl *r;
105 xChangeDeviceControlReply rep;
106 AxisInfoPtr a;
107 CARD32 *resolution;
108 xDeviceAbsCalibCtl *calib;
109 xDeviceAbsAreaCtl *area;
110 xDeviceCoreCtl *c;
111 xDeviceEnableCtl *e;
112 devicePresenceNotify dpn;
114 REQUEST(xChangeDeviceControlReq);
115 REQUEST_AT_LEAST_SIZE(xChangeDeviceControlReq);
117 len = stuff->length - (sizeof(xChangeDeviceControlReq) >> 2);
118 dev = LookupDeviceIntRec(stuff->deviceid);
119 if (dev == NULL) {
120 ret = BadDevice;
121 goto out;
124 rep.repType = X_Reply;
125 rep.RepType = X_ChangeDeviceControl;
126 rep.length = 0;
127 rep.sequenceNumber = client->sequence;
129 switch (stuff->control) {
130 case DEVICE_RESOLUTION:
131 r = (xDeviceResolutionCtl *) & stuff[1];
132 if ((len < (sizeof(xDeviceResolutionCtl) >> 2)) ||
133 (len != (sizeof(xDeviceResolutionCtl) >> 2) + r->num_valuators)) {
134 ret = BadLength;
135 goto out;
137 if (!dev->valuator) {
138 ret = BadMatch;
139 goto out;
141 if ((dev->grab) && !SameClient(dev->grab, client)) {
142 rep.status = AlreadyGrabbed;
143 ret = Success;
144 goto out;
146 resolution = (CARD32 *) (r + 1);
147 if (r->first_valuator + r->num_valuators > dev->valuator->numAxes) {
148 ret = BadValue;
149 goto out;
151 status = ChangeDeviceControl(client, dev, (xDeviceCtl *) r);
152 if (status == Success) {
153 a = &dev->valuator->axes[r->first_valuator];
154 for (i = 0; i < r->num_valuators; i++)
155 if (*(resolution + i) < (a + i)->min_resolution ||
156 *(resolution + i) > (a + i)->max_resolution) {
157 SendErrorToClient(client, IReqCode,
158 X_ChangeDeviceControl, 0, BadValue);
159 return Success;
161 for (i = 0; i < r->num_valuators; i++)
162 (a++)->resolution = *resolution++;
164 ret = Success;
165 } else if (status == DeviceBusy) {
166 rep.status = DeviceBusy;
167 ret = Success;
168 } else {
169 ret = BadMatch;
171 break;
172 case DEVICE_ABS_CALIB:
173 calib = (xDeviceAbsCalibCtl *)&stuff[1];
175 if (calib->button_threshold < 0 || calib->button_threshold > 255) {
176 ret = BadValue;
177 goto out;
180 status = ChangeDeviceControl(client, dev, (xDeviceCtl *) calib);
182 if (status == Success) {
183 dev->absolute->min_x = calib->min_x;
184 dev->absolute->max_x = calib->max_x;
185 dev->absolute->min_y = calib->min_y;
186 dev->absolute->max_y = calib->max_y;
187 dev->absolute->flip_x = calib->flip_x;
188 dev->absolute->flip_y = calib->flip_y;
189 dev->absolute->rotation = calib->rotation;
190 dev->absolute->button_threshold = calib->button_threshold;
191 ret = Success;
192 } else if (status == DeviceBusy || status == BadValue) {
193 rep.status = status;
194 ret = Success;
195 } else {
196 ret = BadMatch;
199 break;
200 case DEVICE_ABS_AREA:
201 area = (xDeviceAbsAreaCtl *)&stuff[1];
203 status = ChangeDeviceControl(client, dev, (xDeviceCtl *) area);
205 if (status == Success) {
206 dev->absolute->offset_x = area->offset_x;
207 dev->absolute->offset_y = area->offset_y;
208 dev->absolute->width = area->width;
209 dev->absolute->height = area->height;
210 dev->absolute->screen = area->screen;
211 dev->absolute->following = area->following;
212 ret = Success;
213 } else if (status == DeviceBusy || status == BadValue) {
214 rep.status = status;
215 ret = Success;
216 } else {
217 ret = Success;
220 break;
221 case DEVICE_CORE:
222 c = (xDeviceCoreCtl *)&stuff[1];
224 status = ChangeDeviceControl(client, dev, (xDeviceCtl *) c);
226 if (status == Success) {
227 dev->coreEvents = c->status;
228 ret = Success;
229 } else if (status == DeviceBusy) {
230 rep.status = DeviceBusy;
231 ret = Success;
232 } else {
233 ret = BadMatch;
236 break;
237 case DEVICE_ENABLE:
238 e = (xDeviceEnableCtl *)&stuff[1];
240 status = ChangeDeviceControl(client, dev, (xDeviceCtl *) e);
242 if (status == Success) {
243 if (e->enable)
244 EnableDevice(dev);
245 else
246 DisableDevice(dev);
247 ret = Success;
248 } else if (status == DeviceBusy) {
249 rep.status = DeviceBusy;
250 ret = Success;
251 } else {
252 ret = BadMatch;
255 break;
256 default:
257 ret = BadValue;
260 out:
261 if (ret == Success) {
262 dpn.type = DevicePresenceNotify;
263 dpn.time = currentTime.milliseconds;
264 dpn.devchange = 1;
265 dpn.deviceid = dev->id;
266 dpn.control = stuff->control;
267 SendEventToAllWindows(dev, DevicePresenceNotifyMask,
268 (xEvent *) &dpn, 1);
270 WriteReplyToClient(client, sizeof(xChangeDeviceControlReply), &rep);
272 else {
273 SendErrorToClient(client, IReqCode, X_ChangeDeviceControl, 0, ret);
276 return Success;
279 /***********************************************************************
281 * This procedure writes the reply for the xChangeDeviceControl function,
282 * if the client and server have a different byte ordering.
286 void
287 SRepXChangeDeviceControl(ClientPtr client, int size,
288 xChangeDeviceControlReply * rep)
290 char n;
292 swaps(&rep->sequenceNumber, n);
293 swapl(&rep->length, n);
294 WriteToClient(client, size, (char *)rep);