]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - glsdk/xserver.git/blob - Xi/chgdctl.c
Imported Upstream version 1.11.4
[glsdk/xserver.git] / Xi / chgdctl.c
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 /********************************************************************
48  *
49  *  Change Device control attributes for an extension device.
50  *
51  */
53 #ifdef HAVE_DIX_CONFIG_H
54 #include <dix-config.h>
55 #endif
57 #include "inputstr.h"   /* DeviceIntPtr      */
58 #include <X11/extensions/XI.h>
59 #include <X11/extensions/XIproto.h>     /* control constants */
60 #include "XIstubs.h"
62 #include "exglobals.h"
63 #include "exevents.h"
65 #include "chgdctl.h"
67 /***********************************************************************
68  *
69  * This procedure changes the control attributes for an extension device,
70  * for clients on machines with a different byte ordering than the server.
71  *
72  */
74 int
75 SProcXChangeDeviceControl(ClientPtr client)
76 {
77     char n;
78     xDeviceCtl *ctl;
80     REQUEST(xChangeDeviceControlReq);
81     swaps(&stuff->length, n);
82     REQUEST_AT_LEAST_SIZE(xChangeDeviceControlReq);
83     swaps(&stuff->control, n);
84     ctl = (xDeviceCtl*)&stuff[1];
85     swaps(&ctl->control, n);
86     swaps(&ctl->length, n);
87     switch(stuff->control) {
88         case DEVICE_ABS_CALIB:
89         case DEVICE_ABS_AREA:
90         case DEVICE_CORE:
91         case DEVICE_ENABLE:
92         case DEVICE_RESOLUTION:
93             /* hmm. beer. *drool* */
94             break;
96     }
97     return (ProcXChangeDeviceControl(client));
98 }
100 /***********************************************************************
101  *
102  * Change the control attributes.
103  *
104  */
106 int
107 ProcXChangeDeviceControl(ClientPtr client)
109     unsigned len;
110     int i, status, ret = BadValue;
111     DeviceIntPtr dev;
112     xDeviceResolutionCtl *r;
113     xChangeDeviceControlReply rep;
114     AxisInfoPtr a;
115     CARD32 *resolution;
116     xDeviceEnableCtl *e;
117     devicePresenceNotify dpn;
119     REQUEST(xChangeDeviceControlReq);
120     REQUEST_AT_LEAST_SIZE(xChangeDeviceControlReq);
122     len = stuff->length - bytes_to_int32(sizeof(xChangeDeviceControlReq));
123     ret = dixLookupDevice(&dev, stuff->deviceid, client, DixManageAccess);
124     if (ret != Success)
125         goto out;
127     rep.repType = X_Reply;
128     rep.RepType = X_ChangeDeviceControl;
129     rep.length = 0;
130     rep.sequenceNumber = client->sequence;
132     switch (stuff->control) {
133     case DEVICE_RESOLUTION:
134         r = (xDeviceResolutionCtl *) & stuff[1];
135         if ((len < bytes_to_int32(sizeof(xDeviceResolutionCtl))) ||
136             (len != bytes_to_int32(sizeof(xDeviceResolutionCtl)) + r->num_valuators)) {
137             ret = BadLength;
138             goto out;
139         }
140         if (!dev->valuator) {
141             ret = BadMatch;
142             goto out;
143         }
144         if ((dev->deviceGrab.grab) && !SameClient(dev->deviceGrab.grab, client)) {
145             rep.status = AlreadyGrabbed;
146             ret = Success;
147             goto out;
148         }
149         resolution = (CARD32 *) (r + 1);
150         if (r->first_valuator + r->num_valuators > dev->valuator->numAxes) {
151             ret = BadValue;
152             goto out;
153         }
154         status = ChangeDeviceControl(client, dev, (xDeviceCtl *) r);
155         if (status == Success) {
156             a = &dev->valuator->axes[r->first_valuator];
157             for (i = 0; i < r->num_valuators; i++)
158                 if (*(resolution + i) < (a + i)->min_resolution ||
159                     *(resolution + i) > (a + i)->max_resolution)
160                     return BadValue;
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;
170         }
171         break;
172     case DEVICE_ABS_CALIB:
173     case DEVICE_ABS_AREA:
174         /* Calibration is now done through properties, and never had any effect
175          * on anything (in the open-source world). Thus, be honest. */
176         ret = BadMatch;
177         break;
178     case DEVICE_CORE:
179         /* Sorry, no device core switching no more. If you want a device to
180          * send core events, attach it to a master device */
181         ret = BadMatch;
182         break;
183     case DEVICE_ENABLE:
184         e = (xDeviceEnableCtl *)&stuff[1];
186         status = ChangeDeviceControl(client, dev, (xDeviceCtl *) e);
188         if (status == Success) {
189             if (e->enable)
190                 EnableDevice(dev, TRUE);
191             else
192                 DisableDevice(dev, TRUE);
193             ret = Success;
194         } else if (status == DeviceBusy) {
195             rep.status = DeviceBusy;
196             ret = Success;
197         } else {
198             ret = BadMatch;
199         }
201         break;
202     default:
203         ret = BadValue;
204     }
206 out:
207     if (ret == Success) {
208         dpn.type = DevicePresenceNotify;
209         dpn.time = currentTime.milliseconds;
210         dpn.devchange = DeviceControlChanged;
211         dpn.deviceid = dev->id;
212         dpn.control = stuff->control;
213         SendEventToAllWindows(dev, DevicePresenceNotifyMask,
214                               (xEvent *) &dpn, 1);
216         WriteReplyToClient(client, sizeof(xChangeDeviceControlReply), &rep);
217     }
219     return ret;
222 /***********************************************************************
223  *
224  * This procedure writes the reply for the xChangeDeviceControl function,
225  * if the client and server have a different byte ordering.
226  *
227  */
229 void
230 SRepXChangeDeviceControl(ClientPtr client, int size,
231                          xChangeDeviceControlReply * rep)
233     char n;
235     swaps(&rep->sequenceNumber, n);
236     swapl(&rep->length, n);
237     WriteToClient(client, size, (char *)rep);