XGetFCtl.c revision c27c18e8
1/************************************************************ 2 3Copyright 1989, 1998 The Open Group 4 5Permission to use, copy, modify, distribute, and sell this software and its 6documentation for any purpose is hereby granted without fee, provided that 7the above copyright notice appear in all copies and that both that 8copyright notice and this permission notice appear in supporting 9documentation. 10 11The above copyright notice and this permission notice shall be included in 12all copies or substantial portions of the Software. 13 14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 18AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 21Except as contained in this notice, the name of The Open Group shall not be 22used in advertising or otherwise to promote the sale, use or other dealings 23in this Software without prior written authorization from The Open Group. 24 25Copyright 1989 by Hewlett-Packard Company, Palo Alto, California. 26 27 All Rights Reserved 28 29Permission to use, copy, modify, and distribute this software and its 30documentation for any purpose and without fee is hereby granted, 31provided that the above copyright notice appear in all copies and that 32both that copyright notice and this permission notice appear in 33supporting documentation, and that the name of Hewlett-Packard not be 34used in advertising or publicity pertaining to distribution of the 35software without specific, written prior permission. 36 37HEWLETT-PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 38ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 39HEWLETT-PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 40ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 41WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 42ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 43SOFTWARE. 44 45********************************************************/ 46 47/*********************************************************************** 48 * 49 * XGetFeedbackControl - get the feedback attributes of an extension device. 50 * 51 */ 52 53#include <X11/extensions/XI.h> 54#include <X11/extensions/XIproto.h> 55#include <X11/Xlibint.h> 56#include <X11/Xlib.h> 57#include <X11/extensions/XInput.h> 58#include <X11/extensions/extutil.h> 59#include "XIint.h" 60 61XFeedbackState * 62XGetFeedbackControl( 63 register Display *dpy, 64 XDevice *dev, 65 int *num_feedbacks) 66{ 67 int size = 0; 68 int nbytes, i; 69 XFeedbackState *Feedback = NULL; 70 XFeedbackState *Sav = NULL; 71 xFeedbackState *f = NULL; 72 xFeedbackState *sav = NULL; 73 xGetFeedbackControlReq *req; 74 xGetFeedbackControlReply rep; 75 XExtDisplayInfo *info = XInput_find_display(dpy); 76 77 LockDisplay(dpy); 78 if (_XiCheckExtInit(dpy, XInput_Initial_Release, info) == -1) 79 return ((XFeedbackState *) NoSuchExtension); 80 81 GetReq(GetFeedbackControl, req); 82 req->reqType = info->codes->major_opcode; 83 req->ReqType = X_GetFeedbackControl; 84 req->deviceid = dev->device_id; 85 86 if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) { 87 UnlockDisplay(dpy); 88 SyncHandle(); 89 return (XFeedbackState *) NULL; 90 } 91 if (rep.length > 0) { 92 *num_feedbacks = rep.num_feedbacks; 93 nbytes = (long)rep.length << 2; 94 f = (xFeedbackState *) Xmalloc((unsigned)nbytes); 95 if (!f) { 96 _XEatData(dpy, (unsigned long)nbytes); 97 UnlockDisplay(dpy); 98 SyncHandle(); 99 return (XFeedbackState *) NULL; 100 } 101 sav = f; 102 _XRead(dpy, (char *)f, nbytes); 103 104 for (i = 0; i < *num_feedbacks; i++) { 105 switch (f->class) { 106 case KbdFeedbackClass: 107 size += sizeof(XKbdFeedbackState); 108 break; 109 case PtrFeedbackClass: 110 size += sizeof(XPtrFeedbackState); 111 break; 112 case IntegerFeedbackClass: 113 size += sizeof(XIntegerFeedbackState); 114 break; 115 case StringFeedbackClass: 116 { 117 xStringFeedbackState *strf = (xStringFeedbackState *) f; 118 119 size += sizeof(XStringFeedbackState) + 120 (strf->num_syms_supported * sizeof(KeySym)); 121 } 122 break; 123 case LedFeedbackClass: 124 size += sizeof(XLedFeedbackState); 125 break; 126 case BellFeedbackClass: 127 size += sizeof(XBellFeedbackState); 128 break; 129 default: 130 size += f->length; 131 break; 132 } 133 f = (xFeedbackState *) ((char *)f + f->length); 134 } 135 136 Feedback = (XFeedbackState *) Xmalloc((unsigned)size); 137 if (!Feedback) { 138 UnlockDisplay(dpy); 139 SyncHandle(); 140 return (XFeedbackState *) NULL; 141 } 142 Sav = Feedback; 143 144 f = sav; 145 for (i = 0; i < *num_feedbacks; i++) { 146 switch (f->class) { 147 case KbdFeedbackClass: 148 { 149 xKbdFeedbackState *k; 150 XKbdFeedbackState *K; 151 152 k = (xKbdFeedbackState *) f; 153 K = (XKbdFeedbackState *) Feedback; 154 155 K->class = k->class; 156 K->length = sizeof(XKbdFeedbackState); 157 K->id = k->id; 158 K->click = k->click; 159 K->percent = k->percent; 160 K->pitch = k->pitch; 161 K->duration = k->duration; 162 K->led_mask = k->led_mask; 163 K->global_auto_repeat = k->global_auto_repeat; 164 memcpy((char *)&K->auto_repeats[0], 165 (char *)&k->auto_repeats[0], 32); 166 break; 167 } 168 case PtrFeedbackClass: 169 { 170 xPtrFeedbackState *p; 171 XPtrFeedbackState *P; 172 173 p = (xPtrFeedbackState *) f; 174 P = (XPtrFeedbackState *) Feedback; 175 176 P->class = p->class; 177 P->length = sizeof(XPtrFeedbackState); 178 P->id = p->id; 179 P->accelNum = p->accelNum; 180 P->accelDenom = p->accelDenom; 181 P->threshold = p->threshold; 182 break; 183 } 184 case IntegerFeedbackClass: 185 { 186 xIntegerFeedbackState *i; 187 XIntegerFeedbackState *I; 188 189 i = (xIntegerFeedbackState *) f; 190 I = (XIntegerFeedbackState *) Feedback; 191 192 I->class = i->class; 193 I->length = sizeof(XIntegerFeedbackState); 194 I->id = i->id; 195 I->resolution = i->resolution; 196 I->minVal = i->min_value; 197 I->maxVal = i->max_value; 198 break; 199 } 200 case StringFeedbackClass: 201 { 202 xStringFeedbackState *s; 203 XStringFeedbackState *S; 204 205 s = (xStringFeedbackState *) f; 206 S = (XStringFeedbackState *) Feedback; 207 208 S->class = s->class; 209 S->length = sizeof(XStringFeedbackState) + 210 (s->num_syms_supported * sizeof(KeySym)); 211 S->id = s->id; 212 S->max_symbols = s->max_symbols; 213 S->num_syms_supported = s->num_syms_supported; 214 S->syms_supported = (KeySym *) (S + 1); 215 memcpy((char *)S->syms_supported, (char *)(s + 1), 216 (S->num_syms_supported * sizeof(KeySym))); 217 break; 218 } 219 case LedFeedbackClass: 220 { 221 xLedFeedbackState *l; 222 XLedFeedbackState *L; 223 224 l = (xLedFeedbackState *) f; 225 L = (XLedFeedbackState *) Feedback; 226 227 L->class = l->class; 228 L->length = sizeof(XLedFeedbackState); 229 L->id = l->id; 230 L->led_values = l->led_values; 231 L->led_mask = l->led_mask; 232 break; 233 } 234 case BellFeedbackClass: 235 { 236 xBellFeedbackState *b; 237 XBellFeedbackState *B; 238 239 b = (xBellFeedbackState *) f; 240 B = (XBellFeedbackState *) Feedback; 241 242 B->class = b->class; 243 B->length = sizeof(XBellFeedbackState); 244 B->id = b->id; 245 B->percent = b->percent; 246 B->pitch = b->pitch; 247 B->duration = b->duration; 248 break; 249 } 250 default: 251 break; 252 } 253 f = (xFeedbackState *) ((char *)f + f->length); 254 Feedback = (XFeedbackState *) ((char *)Feedback + Feedback->length); 255 } 256 XFree((char *)sav); 257 } 258 259 UnlockDisplay(dpy); 260 SyncHandle(); 261 return (Sav); 262} 263 264void 265XFreeFeedbackList(XFeedbackState *list) 266{ 267 XFree((char *)list); 268} 269