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 ********************************************************/
35 #include "XKBlibint.h"
36 #include <X11/extensions/XKBgeom.h>
37 #include <X11/extensions/XKBproto.h>
40 #define MINSHORT -32768
43 #define MAXSHORT 32767
46 /***====================================================================***/
48 #define _SizeCountedString(s) ((s)?XkbPaddedSize(2+strlen(s)):4)
51 _WriteCountedString(char *wire,char *str)
55 len= (str?strlen(str):0);
59 memcpy(&wire[2],str,len);
60 wire+= XkbPaddedSize(len+2);
65 _SizeGeomProperties(XkbGeometryPtr geom)
70 for (size=i=0,prop=geom->properties;i<geom->num_properties;i++,prop++) {
71 size+= _SizeCountedString(prop->name);
72 size+= _SizeCountedString(prop->value);
78 _SizeGeomColors(XkbGeometryPtr geom)
81 register XkbColorPtr color;
83 for (i=size=0,color=geom->colors;i<geom->num_colors;i++,color++) {
84 size+= _SizeCountedString(color->spec);
90 _SizeGeomShapes(XkbGeometryPtr geom)
93 register XkbShapePtr shape;
95 for (i=size=0,shape=geom->shapes;i<geom->num_shapes;i++,shape++) {
97 register XkbOutlinePtr ol;
98 size+= SIZEOF(xkbShapeWireDesc);
99 for (n=0,ol=shape->outlines;n<shape->num_outlines;n++,ol++) {
100 size+= SIZEOF(xkbOutlineWireDesc);
101 size+= ol->num_points*SIZEOF(xkbPointWireDesc);
108 _SizeGeomDoodads(int num_doodads,XkbDoodadPtr doodad)
112 for (i=size=0;i<num_doodads;i++,doodad++) {
113 size+= SIZEOF(xkbAnyDoodadWireDesc);
114 if (doodad->any.type==XkbTextDoodad) {
115 size+= _SizeCountedString(doodad->text.text);
116 size+= _SizeCountedString(doodad->text.font);
118 else if (doodad->any.type==XkbLogoDoodad) {
119 size+= _SizeCountedString(doodad->logo.logo_name);
126 _SizeGeomSections(XkbGeometryPtr geom)
129 XkbSectionPtr section;
131 for (i=size=0,section=geom->sections;i<geom->num_sections;i++,section++) {
132 size+= SIZEOF(xkbSectionWireDesc);
136 for (r=0,row=section->rows;r<section->num_rows;row++,r++) {
137 size+= SIZEOF(xkbRowWireDesc);
138 size+= row->num_keys*SIZEOF(xkbKeyWireDesc);
141 if (section->doodads)
142 size+= _SizeGeomDoodads(section->num_doodads,section->doodads);
143 if (section->overlays) {
146 for (o=0,ol=section->overlays;o<section->num_overlays;o++,ol++) {
148 XkbOverlayRowPtr row;
149 size+= SIZEOF(xkbOverlayWireDesc);
150 for (r=0,row=ol->rows;r<ol->num_rows;r++,row++) {
151 size+= SIZEOF(xkbOverlayRowWireDesc);
152 size+= row->num_keys*SIZEOF(xkbOverlayKeyWireDesc);
161 _SizeGeomKeyAliases(XkbGeometryPtr geom)
163 return geom->num_key_aliases*(2*XkbKeyNameLength);
166 /***====================================================================***/
169 _WriteGeomProperties(char *wire,XkbGeometryPtr geom)
172 register XkbPropertyPtr prop;
174 for (i=0,prop=geom->properties;i<geom->num_properties;i++,prop++) {
175 wire= _WriteCountedString(wire,prop->name);
176 wire= _WriteCountedString(wire,prop->value);
182 _WriteGeomColors(char *wire,XkbGeometryPtr geom)
185 register XkbColorPtr color;
187 for (i=0,color=geom->colors;i<geom->num_colors;i++,color++) {
188 wire= _WriteCountedString(wire,color->spec);
194 _WriteGeomShapes(char *wire,XkbGeometryPtr geom)
198 xkbShapeWireDesc * shapeWire;
200 for (i=0,shape=geom->shapes;i<geom->num_shapes;i++,shape++) {
203 xkbOutlineWireDesc * olWire;
204 shapeWire= (xkbShapeWireDesc *)wire;
205 shapeWire->name= shape->name;
206 shapeWire->nOutlines= shape->num_outlines;
207 if (shape->primary!=NULL)
208 shapeWire->primaryNdx= XkbOutlineIndex(shape,shape->primary);
209 else shapeWire->primaryNdx= XkbNoShape;
210 if (shape->approx!=NULL)
211 shapeWire->approxNdx= XkbOutlineIndex(shape,shape->approx);
212 else shapeWire->approxNdx= XkbNoShape;
213 wire= (char *)&shapeWire[1];
214 for (o=0,ol=shape->outlines;o<shape->num_outlines;o++,ol++) {
217 xkbPointWireDesc * ptWire;
218 olWire= (xkbOutlineWireDesc *)wire;
219 olWire->nPoints= ol->num_points;
220 olWire->cornerRadius= ol->corner_radius;
221 wire= (char *)&olWire[1];
222 ptWire= (xkbPointWireDesc *)wire;
223 for (p=0,pt=ol->points;p<ol->num_points;p++,pt++) {
227 wire= (char *)&ptWire[ol->num_points];
234 _WriteGeomDoodads(char *wire,int num_doodads,XkbDoodadPtr doodad)
237 xkbDoodadWireDesc * doodadWire;
239 for (i=0;i<num_doodads;i++,doodad++) {
240 doodadWire= (xkbDoodadWireDesc *)wire;
241 wire= (char *)&doodadWire[1];
242 bzero(doodadWire,SIZEOF(xkbDoodadWireDesc));
243 doodadWire->any.name= doodad->any.name;
244 doodadWire->any.type= doodad->any.type;
245 doodadWire->any.priority= doodad->any.priority;
246 doodadWire->any.top= doodad->any.top;
247 doodadWire->any.left= doodad->any.left;
248 doodadWire->any.angle= doodad->any.angle;
249 switch (doodad->any.type) {
250 case XkbOutlineDoodad:
252 doodadWire->shape.colorNdx= doodad->shape.color_ndx;
253 doodadWire->shape.shapeNdx= doodad->shape.shape_ndx;
256 doodadWire->text.width= doodad->text.width;
257 doodadWire->text.height= doodad->text.height;
258 doodadWire->text.colorNdx= doodad->text.color_ndx;
259 wire= _WriteCountedString(wire,doodad->text.text);
260 wire= _WriteCountedString(wire,doodad->text.font);
262 case XkbIndicatorDoodad:
263 doodadWire->indicator.shapeNdx= doodad->indicator.shape_ndx;
264 doodadWire->indicator.onColorNdx=doodad->indicator.on_color_ndx;
265 doodadWire->indicator.offColorNdx=
266 doodad->indicator.off_color_ndx;
269 doodadWire->logo.colorNdx= doodad->logo.color_ndx;
270 doodadWire->logo.shapeNdx= doodad->logo.shape_ndx;
271 wire= _WriteCountedString(wire,doodad->logo.logo_name);
281 _WriteGeomOverlay(char *wire,XkbOverlayPtr ol)
284 XkbOverlayRowPtr row;
285 xkbOverlayWireDesc * olWire;
287 olWire= (xkbOverlayWireDesc *)wire;
288 olWire->name= ol->name;
289 olWire->nRows= ol->num_rows;
290 wire= (char *)&olWire[1];
291 for (r=0,row=ol->rows;r<ol->num_rows;r++,row++) {
293 XkbOverlayKeyPtr key;
294 xkbOverlayRowWireDesc * rowWire;
295 rowWire= (xkbOverlayRowWireDesc *)wire;
296 rowWire->rowUnder= row->row_under;
297 rowWire->nKeys= row->num_keys;
298 wire= (char *)&rowWire[1];
299 for (k=0,key=row->keys;k<row->num_keys;k++,key++) {
300 xkbOverlayKeyWireDesc * keyWire;
301 keyWire= (xkbOverlayKeyWireDesc *)wire;
302 memcpy(keyWire->over,key->over.name,XkbKeyNameLength);
303 memcpy(keyWire->under,key->under.name,XkbKeyNameLength);
304 wire= (char *)&keyWire[1];
311 _WriteGeomSections(char *wire,XkbGeometryPtr geom)
314 XkbSectionPtr section;
315 xkbSectionWireDesc * sectionWire;
317 for (i=0,section=geom->sections;i<geom->num_sections;i++,section++) {
318 sectionWire= (xkbSectionWireDesc *)wire;
319 sectionWire->name= section->name;
320 sectionWire->top= section->top;
321 sectionWire->left= section->left;
322 sectionWire->width= section->width;
323 sectionWire->height= section->height;
324 sectionWire->angle= section->angle;
325 sectionWire->priority= section->priority;
326 sectionWire->nRows= section->num_rows;
327 sectionWire->nDoodads= section->num_doodads;
328 sectionWire->nOverlays= section->num_overlays;
330 wire= (char *)§ionWire[1];
334 xkbRowWireDesc * rowWire;
335 for (r=0,row=section->rows;r<section->num_rows;r++,row++) {
336 rowWire= (xkbRowWireDesc *)wire;
337 rowWire->top= row->top;
338 rowWire->left= row->left;
339 rowWire->nKeys= row->num_keys;
340 rowWire->vertical= row->vertical;
342 wire= (char *)&rowWire[1];
346 xkbKeyWireDesc * keyWire;
347 keyWire= (xkbKeyWireDesc *)wire;
348 for (k=0,key=row->keys;k<row->num_keys;k++,key++) {
349 memcpy(keyWire[k].name,key->name.name,XkbKeyNameLength);
350 keyWire[k].gap= key->gap;
351 keyWire[k].shapeNdx= key->shape_ndx;
352 keyWire[k].colorNdx= key->color_ndx;
354 wire= (char *)&keyWire[row->num_keys];
358 if (section->doodads) {
359 wire= _WriteGeomDoodads(wire,
360 section->num_doodads,section->doodads);
362 if (section->overlays) {
364 for (o=0;o<section->num_overlays;o++) {
365 wire= _WriteGeomOverlay(wire,§ion->overlays[o]);
373 _WriteGeomKeyAliases(char *wire,XkbGeometryPtr geom)
377 sz= geom->num_key_aliases*(XkbKeyNameLength*2);
379 memcpy(wire,(char *)geom->key_aliases,sz);
385 /***====================================================================***/
388 _SendSetGeometry(Display *dpy,XkbGeometryPtr geom,xkbSetGeometryReq *req)
394 sz+= _SizeCountedString(geom->label_font);
395 sz+= _SizeGeomProperties(geom);
396 sz+= _SizeGeomColors(geom);
397 sz+= _SizeGeomShapes(geom);
398 sz+= _SizeGeomSections(geom);
399 sz+= _SizeGeomDoodads(geom->num_doodads,geom->doodads);
400 sz+= _SizeGeomKeyAliases(geom);
401 req->length+= (sz/4);
402 if (sz < (dpy->bufmax - dpy->buffer)) {
403 BufAlloc(char *,wire,sz);
407 tbuf= _XAllocTemp(dpy,sz);
412 wire= _WriteCountedString(wire,geom->label_font);
413 if (geom->num_properties>0)
414 wire= _WriteGeomProperties(wire,geom);
415 if (geom->num_colors>0)
416 wire= _WriteGeomColors(wire,geom);
417 if (geom->num_shapes>0)
418 wire= _WriteGeomShapes(wire,geom);
419 if (geom->num_sections>0)
420 wire= _WriteGeomSections(wire,geom);
421 if (geom->num_doodads>0)
422 wire= _WriteGeomDoodads(wire,geom->num_doodads,geom->doodads);
423 if (geom->num_key_aliases>0)
424 wire= _WriteGeomKeyAliases(wire,geom);
427 _XFreeTemp(dpy,tbuf,sz);
432 /***====================================================================***/
435 XkbSetGeometry(Display *dpy,unsigned deviceSpec,XkbGeometryPtr geom)
437 xkbSetGeometryReq *req;
440 if ( (!geom) || (dpy->flags & XlibDisplayNoXkb) ||
441 (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
445 GetReq(kbSetGeometry, req);
446 req->reqType = dpy->xkb_info->codes->major_opcode;
447 req->xkbReqType = X_kbSetGeometry;
448 req->deviceSpec = deviceSpec;
449 req->nShapes= geom->num_shapes;
450 req->nSections= geom->num_sections;
451 req->name= geom->name;
452 req->widthMM= geom->width_mm;
453 req->heightMM= geom->height_mm;
454 req->nProperties= geom->num_properties;
455 req->nColors= geom->num_colors;
456 req->nDoodads= geom->num_doodads;
457 req->nKeyAliases= geom->num_key_aliases;
458 req->baseColorNdx= (geom->base_color-geom->colors);
459 req->labelColorNdx= (geom->label_color-geom->colors);
461 ret = _SendSetGeometry(dpy,geom,req);