1 /************************************************************
2 Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
4 Permission to use, copy, modify, and distribute this
5 software and its documentation for any purpose and without
6 fee is hereby granted, provided that the above copyright
7 notice appear in all copies and that both that copyright
8 notice and this permission notice appear in supporting
9 documentation, and that the name of Silicon Graphics not be
10 used in advertising or publicity pertaining to distribution
11 of the software without specific prior written permission.
12 Silicon Graphics makes no representation about the suitability
13 of this software for any purpose. It is provided "as is"
14 without any express or implied warranty.
16 SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
17 SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
18 AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
19 GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
20 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
21 DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
22 OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
23 THE USE OR PERFORMANCE OF THIS SOFTWARE.
25 ********************************************************/
27 #define NEED_MAP_READERS
32 #include <X11/extensions/XKBproto.h>
33 #include "XKBlibint.h"
36 XkbGetIndicatorState(Display *dpy,unsigned deviceSpec,unsigned *pStateRtrn)
38 register xkbGetIndicatorStateReq *req;
39 xkbGetIndicatorStateReply rep;
43 if ((dpy->flags & XlibDisplayNoXkb) ||
44 (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
48 GetReq(kbGetIndicatorState, req);
49 req->reqType = xkbi->codes->major_opcode;
50 req->xkbReqType = X_kbGetIndicatorState;
51 req->deviceSpec = deviceSpec;
52 ok=_XReply(dpy, (xReply *)&rep, 0, xFalse);
53 if (ok && (pStateRtrn!=NULL))
54 *pStateRtrn= rep.state;
57 return (ok?Success:BadImplementation);
61 _XkbReadGetIndicatorMapReply( Display * dpy,
62 xkbGetIndicatorMapReply * rep,
69 if ((!xkb->indicators)&&(XkbAllocIndicatorMaps(xkb)!=Success))
71 leds= xkb->indicators;
73 leds->phys_indicators = rep->realIndicators;
76 if (!_XkbInitReadBuffer(dpy,&buf,(int)rep->length*4))
79 *nread_rtrn= (int)rep->length*4;
82 left= (int)rep->which;
83 for (i=0,bit=1;(i<XkbNumIndicators)&&(left);i++,bit<<=1) {
85 xkbIndicatorMapWireDesc *wire;
86 wire= (xkbIndicatorMapWireDesc *)
87 _XkbGetReadBufferPtr(&buf,
88 SIZEOF(xkbIndicatorMapWireDesc));
90 _XkbFreeReadBuffer(&buf);
93 leds->maps[i].flags= wire->flags;
94 leds->maps[i].which_groups= wire->whichGroups;
95 leds->maps[i].groups= wire->groups;
96 leds->maps[i].which_mods= wire->whichMods;
97 leds->maps[i].mods.mask= wire->mods;
98 leds->maps[i].mods.real_mods= wire->realMods;
99 leds->maps[i].mods.vmods= wire->virtualMods;
100 leds->maps[i].ctrls= wire->ctrls;
105 left= _XkbFreeReadBuffer(&buf);
111 XkbGetIndicatorMap(Display *dpy,unsigned long which,XkbDescPtr xkb)
113 register xkbGetIndicatorMapReq * req;
114 xkbGetIndicatorMapReply rep;
118 if ((dpy->flags & XlibDisplayNoXkb) ||
119 (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
121 if ((!which)||(!xkb))
125 xkbi = dpy->xkb_info;
126 if (!xkb->indicators) {
127 xkb->indicators = _XkbTypedCalloc(1,XkbIndicatorRec);
128 if (!xkb->indicators) {
134 GetReq(kbGetIndicatorMap, req);
135 req->reqType = xkbi->codes->major_opcode;
136 req->xkbReqType = X_kbGetIndicatorMap;
137 req->deviceSpec = xkb->device_spec;
138 req->which = (CARD32)which;
139 if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
144 status= _XkbReadGetIndicatorMapReply(dpy,&rep,xkb,NULL);
151 XkbSetIndicatorMap(Display *dpy,unsigned long which,XkbDescPtr xkb)
153 register xkbSetIndicatorMapReq *req;
156 xkbIndicatorMapWireDesc *wire;
159 if ((dpy->flags & XlibDisplayNoXkb) ||
160 (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
162 if ((!xkb)||(!which)||(!xkb->indicators))
165 xkbi = dpy->xkb_info;
166 GetReq(kbSetIndicatorMap, req);
167 req->reqType = xkbi->codes->major_opcode;
168 req->xkbReqType = X_kbSetIndicatorMap;
169 req->deviceSpec = xkb->device_spec;
170 req->which = (CARD32)which;
171 for (i=nMaps=0,bit=1;i<32;i++,bit<<=1) {
175 req->length+= (nMaps*sizeof(XkbIndicatorMapRec))/4;
176 BufAlloc(xkbIndicatorMapWireDesc *,wire,
177 (nMaps*SIZEOF(xkbIndicatorMapWireDesc)));
178 for (i=0,bit=1;i<32;i++,bit<<=1) {
180 wire->flags= xkb->indicators->maps[i].flags;
181 wire->whichGroups= xkb->indicators->maps[i].which_groups;
182 wire->groups= xkb->indicators->maps[i].groups;
183 wire->whichMods= xkb->indicators->maps[i].which_mods;
184 wire->mods= xkb->indicators->maps[i].mods.real_mods;
185 wire->virtualMods= xkb->indicators->maps[i].mods.vmods;
186 wire->ctrls= xkb->indicators->maps[i].ctrls;
196 XkbGetNamedDeviceIndicator( Display * dpy,
203 XkbIndicatorMapPtr pMapRtrn,
206 register xkbGetNamedIndicatorReq *req;
207 xkbGetNamedIndicatorReply rep;
210 if ((dpy->flags & XlibDisplayNoXkb) || (name==None) ||
211 (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
214 xkbi = dpy->xkb_info;
215 GetReq(kbGetNamedIndicator, req);
216 req->reqType = xkbi->codes->major_opcode;
217 req->xkbReqType = X_kbGetNamedIndicator;
218 req->deviceSpec = device;
219 req->ledClass = class;
221 req->indicator = (CARD32)name;
222 if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
229 if ((!rep.found)||(!rep.supported))
233 if (pStateRtrn!=NULL)
235 if (pMapRtrn!=NULL) {
236 pMapRtrn->flags= rep.flags;
237 pMapRtrn->which_groups= rep.whichGroups;
238 pMapRtrn->groups= rep.groups;
239 pMapRtrn->which_mods= rep.whichMods;
240 pMapRtrn->mods.mask= rep.mods;
241 pMapRtrn->mods.real_mods= rep.realMods;
242 pMapRtrn->mods.vmods= rep.virtualMods;
243 pMapRtrn->ctrls= rep.ctrls;
246 *pRealRtrn= rep.realIndicator;
251 XkbGetNamedIndicator( Display * dpy,
255 XkbIndicatorMapPtr pMapRtrn,
258 return XkbGetNamedDeviceIndicator(dpy,XkbUseCoreKbd,
259 XkbDfltXIClass,XkbDfltXIId,
260 name,pNdxRtrn,pStateRtrn,
265 XkbSetNamedDeviceIndicator( Display * dpy,
273 XkbIndicatorMapPtr pMap)
275 register xkbSetNamedIndicatorReq *req;
278 if ((dpy->flags & XlibDisplayNoXkb) || (name==None) ||
279 (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
282 xkbi = dpy->xkb_info;
283 GetReq(kbSetNamedIndicator, req);
284 req->reqType = xkbi->codes->major_opcode;
285 req->xkbReqType = X_kbSetNamedIndicator;
286 req->deviceSpec = device;
287 req->ledClass = class;
289 req->indicator= (CARD32)name;
290 req->setState= changeState;
296 req->createMap= createNewMap;
297 req->flags= pMap->flags;
298 req->whichGroups= pMap->which_groups;
299 req->groups= pMap->groups;
300 req->whichMods= pMap->which_mods;
301 req->realMods= pMap->mods.real_mods;
302 req->virtualMods= pMap->mods.vmods;
303 req->ctrls= pMap->ctrls;
307 req->createMap= False;
322 XkbSetNamedIndicator( Display * dpy,
327 XkbIndicatorMapPtr pMap)
329 return XkbSetNamedDeviceIndicator(dpy,XkbUseCoreKbd,
330 XkbDfltXIClass,XkbDfltXIId,
331 name,changeState,state,