Debian Codegraph @

src/XChgDCtl.c

raw
1 /************************************************************
2
3 Copyright 1989, 1998 The Open Group
4
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.
10
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
13
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.
20
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.
24
25 Copyright 1989 by Hewlett-Packard Company, Palo Alto, California.
26
27 All Rights Reserved
28
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.
36
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.
44
45 ********************************************************/
46
47 /***********************************************************************
48 *
49 * XChangeDeviceControl - Change the control attributes of an extension
50 * input device.
51 *
52 */
53
54 #ifdef HAVE_CONFIG_H
55 #include <config.h>
56 #endif
57
58 #include <X11/extensions/XI.h>
59 #include <X11/extensions/XIproto.h>
60 #include <X11/Xlibint.h>
61 #include <X11/extensions/XInput.h>
62 #include <X11/extensions/extutil.h>
63 #include "XIint.h"
64
65 int
66 XChangeDeviceControl(
67 register Display *dpy,
68 XDevice *dev,
69 int control,
70 XDeviceControl *d)
71 {
72 int length;
73 xChangeDeviceControlReq *req;
74 xChangeDeviceControlReply rep;
75 XExtDisplayInfo *info = XInput_find_display(dpy);
76
77 LockDisplay(dpy);
78 if (_XiCheckExtInit(dpy, XInput_Add_XChangeDeviceControl, info) == -1)
79 return (NoSuchExtension);
80
81 GetReq(ChangeDeviceControl, req);
82 req->reqType = info->codes->major_opcode;
83 req->ReqType = X_ChangeDeviceControl;
84 req->deviceid = dev->device_id;
85 req->control = control;
86
87 switch (control) {
88 case DEVICE_RESOLUTION:
89 {
90 XDeviceResolutionControl *R;
91 xDeviceResolutionCtl r;
92
93 R = (XDeviceResolutionControl *) d;
94 r.control = DEVICE_RESOLUTION;
95 r.length = sizeof(xDeviceResolutionCtl) +
96 R->num_valuators * sizeof(int);
97 r.first_valuator = R->first_valuator;
98 r.num_valuators = R->num_valuators;
99 req->length += ((unsigned)(r.length + 3) >> 2);
100 length = sizeof(xDeviceResolutionCtl);
101 Data(dpy, (char *)&r, length);
102 length = r.num_valuators * sizeof(int);
103 Data(dpy, (char *)R->resolutions, length);
104 if (!_XReply(dpy, (xReply *) & rep, 0, xTrue)) {
105 UnlockDisplay(dpy);
106 SyncHandle();
107 return (NoSuchExtension);
108 } else {
109 UnlockDisplay(dpy);
110 SyncHandle();
111 return (rep.status);
112 }
113 }
114 case DEVICE_ABS_CALIB:
115 {
116 XDeviceAbsCalibControl *C = (XDeviceAbsCalibControl *) d;
117 xDeviceAbsCalibCtl c;
118
119 c.control = DEVICE_ABS_CALIB;
120 c.length = sizeof(c);
121 c.min_x = C->min_x;
122 c.max_x = C->max_x;
123 c.min_y = C->min_y;
124 c.max_y = C->max_y;
125 c.flip_x = C->flip_x;
126 c.flip_y = C->flip_y;
127 c.rotation = C->rotation;
128 c.button_threshold = C->button_threshold;
129
130 req->length += (sizeof(c) + 3) >> 2;
131 Data(dpy, (char *) &c, sizeof(c));
132
133 if (!_XReply(dpy, (xReply *) &rep, 0, xTrue)) {
134 UnlockDisplay(dpy);
135 SyncHandle();
136 return NoSuchExtension;
137 }
138 else {
139 UnlockDisplay(dpy);
140 SyncHandle();
141 return rep.status;
142 }
143 }
144 case DEVICE_ABS_AREA:
145 {
146 XDeviceAbsAreaControl *A = (XDeviceAbsAreaControl *) d;
147 xDeviceAbsAreaCtl a;
148
149 a.control = DEVICE_ABS_AREA;
150 a.length = sizeof(a);
151 a.offset_x = A->offset_x;
152 a.offset_y = A->offset_y;
153 a.width = A->width;
154 a.height = A->height;
155 a.screen = A->screen;
156 a.following = A->following;
157
158 req->length += (sizeof(a) + 3) >> 2;
159 Data(dpy, (char *) &a, sizeof(a));
160
161 if (!_XReply(dpy, (xReply *) &rep, 0, xTrue)) {
162 UnlockDisplay(dpy);
163 SyncHandle();
164 return NoSuchExtension;
165 }
166 else {
167 UnlockDisplay(dpy);
168 SyncHandle();
169 return rep.status;
170 }
171 }
172 case DEVICE_CORE:
173 {
174 XDeviceCoreControl *C = (XDeviceCoreControl *) d;
175 xDeviceCoreCtl c;
176
177 c.control = DEVICE_CORE;
178 c.length = sizeof(c);
179 c.status = C->status;
180
181 req->length += (sizeof(c) + 3) >> 2;
182 Data (dpy, (char *) &c, sizeof(c));
183
184 if (!_XReply(dpy, (xReply *) &rep, 0, xTrue)) {
185 UnlockDisplay(dpy);
186 SyncHandle();
187 return NoSuchExtension;
188 }
189 else {
190 UnlockDisplay(dpy);
191 SyncHandle();
192 return rep.status;
193 }
194 }
195 case DEVICE_ENABLE:
196 {
197 XDeviceEnableControl *E = (XDeviceEnableControl *) d;
198 xDeviceEnableCtl e;
199
200 e.control = DEVICE_ENABLE;
201 e.length = sizeof(e);
202 e.enable = E->enable;
203
204 req->length += (sizeof(e) + 3) >> 2;
205 Data (dpy, (char *) &e, sizeof(e));
206
207 if (!_XReply(dpy, (xReply *) &rep, 0, xTrue)) {
208 UnlockDisplay(dpy);
209 SyncHandle();
210 return NoSuchExtension;
211 }
212 else {
213 UnlockDisplay(dpy);
214 SyncHandle();
215 return rep.status;
216 }
217 }
218 default:
219 {
220 xDeviceCtl u;
221
222 u.control = d->control;
223 u.length = d->length - sizeof(int);
224 length = ((unsigned)(u.length + 3) >> 2);
225 req->length += length;
226 length <<= 2;
227 Data(dpy, (char *)&u, length);
228 }
229 }
230
231 UnlockDisplay(dpy);
232 SyncHandle();
233 return (Success);
234 }