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 * XGetFeedbackControl - get the feedback attributes of an extension device.
57 #include <X11/extensions/XI.h>
58 #include <X11/extensions/XIproto.h>
59 #include <X11/Xlibint.h>
61 #include <X11/extensions/XInput.h>
62 #include <X11/extensions/extutil.h>
68 register Display *dpy,
72 XFeedbackState *Feedback = NULL;
73 XFeedbackState *Sav = NULL;
74 xFeedbackState *f = NULL;
75 xFeedbackState *sav = NULL;
76 xGetFeedbackControlReq *req;
77 xGetFeedbackControlReply rep;
78 XExtDisplayInfo *info = XInput_find_display(dpy);
81 if (_XiCheckExtInit(dpy, XInput_Initial_Release, info) == -1)
82 return ((XFeedbackState *) NoSuchExtension);
84 GetReq(GetFeedbackControl, req);
85 req->reqType = info->codes->major_opcode;
86 req->ReqType = X_GetFeedbackControl;
87 req->deviceid = dev->device_id;
89 if (!_XReply(dpy, (xReply *) & rep, 0, xFalse))
97 *num_feedbacks = rep.num_feedbacks;
99 if (rep.length < (INT_MAX >> 2)) {
100 nbytes = rep.length << 2;
104 _XEatDataWords(dpy, rep.length);
108 _XRead(dpy, (char *)f, nbytes);
110 for (i = 0; i < *num_feedbacks; i++) {
111 if (f->length > nbytes)
116 case KbdFeedbackClass:
117 size += sizeof(XKbdFeedbackState);
119 case PtrFeedbackClass:
120 size += sizeof(XPtrFeedbackState);
122 case IntegerFeedbackClass:
123 size += sizeof(XIntegerFeedbackState);
125 case StringFeedbackClass:
127 xStringFeedbackState *strf = (xStringFeedbackState *) f;
128 size += sizeof(XStringFeedbackState) +
129 (strf->num_syms_supported * sizeof(KeySym));
132 case LedFeedbackClass:
133 size += sizeof(XLedFeedbackState);
135 case BellFeedbackClass:
136 size += sizeof(XBellFeedbackState);
144 f = (xFeedbackState *) ((char *)f + f->length);
147 Feedback = Xmalloc(size);
154 for (i = 0; i < *num_feedbacks; i++) {
156 case KbdFeedbackClass:
158 xKbdFeedbackState *k;
159 XKbdFeedbackState *K;
161 k = (xKbdFeedbackState *) f;
162 K = (XKbdFeedbackState *) Feedback;
165 K->length = sizeof(XKbdFeedbackState);
168 K->percent = k->percent;
170 K->duration = k->duration;
171 K->led_mask = k->led_mask;
172 K->global_auto_repeat = k->global_auto_repeat;
173 memcpy((char *)&K->auto_repeats[0],
174 (char *)&k->auto_repeats[0], 32);
177 case PtrFeedbackClass:
179 xPtrFeedbackState *p;
180 XPtrFeedbackState *P;
182 p = (xPtrFeedbackState *) f;
183 P = (XPtrFeedbackState *) Feedback;
186 P->length = sizeof(XPtrFeedbackState);
188 P->accelNum = p->accelNum;
189 P->accelDenom = p->accelDenom;
190 P->threshold = p->threshold;
193 case IntegerFeedbackClass:
195 xIntegerFeedbackState *ifs;
196 XIntegerFeedbackState *I;
198 ifs = (xIntegerFeedbackState *) f;
199 I = (XIntegerFeedbackState *) Feedback;
201 I->class = ifs->class;
202 I->length = sizeof(XIntegerFeedbackState);
204 I->resolution = ifs->resolution;
205 I->minVal = ifs->min_value;
206 I->maxVal = ifs->max_value;
209 case StringFeedbackClass:
211 xStringFeedbackState *s;
212 XStringFeedbackState *S;
214 s = (xStringFeedbackState *) f;
215 S = (XStringFeedbackState *) Feedback;
218 S->length = sizeof(XStringFeedbackState) +
219 (s->num_syms_supported * sizeof(KeySym));
221 S->max_symbols = s->max_symbols;
222 S->num_syms_supported = s->num_syms_supported;
223 S->syms_supported = (KeySym *) (S + 1);
224 memcpy((char *)S->syms_supported, (char *)(s + 1),
225 (S->num_syms_supported * sizeof(KeySym)));
228 case LedFeedbackClass:
230 xLedFeedbackState *l;
231 XLedFeedbackState *L;
233 l = (xLedFeedbackState *) f;
234 L = (XLedFeedbackState *) Feedback;
237 L->length = sizeof(XLedFeedbackState);
239 L->led_values = l->led_values;
240 L->led_mask = l->led_mask;
243 case BellFeedbackClass:
245 xBellFeedbackState *b;
246 XBellFeedbackState *B;
248 b = (xBellFeedbackState *) f;
249 B = (XBellFeedbackState *) Feedback;
252 B->length = sizeof(XBellFeedbackState);
254 B->percent = b->percent;
256 B->duration = b->duration;
262 f = (xFeedbackState *) ((char *)f + f->length);
263 Feedback = (XFeedbackState *) ((char *)Feedback + Feedback->length);
275 XFreeFeedbackList(XFeedbackState *list)