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 #ifdef HAVE_DIX_CONFIG_H
28 #include <dix-config.h>
33 #include <X11/Xproto.h>
39 /***====================================================================***/
42 _XkbFreeGeomLeafElems(Bool freeAll
,
45 unsigned short *num_inout
,
46 unsigned short *sz_inout
,
47 char **elems
, unsigned int elem_sz
)
49 if ((freeAll
) || (*elems
== NULL
)) {
50 *num_inout
= *sz_inout
= 0;
56 if ((first
>= (*num_inout
)) || (first
< 0) || (count
< 1))
59 if (first
+ count
>= (*num_inout
)) {
60 /* truncating the array is easy */
68 extra
= ((*num_inout
) - (first
+ count
)) * elem_sz
;
70 memmove(&ptr
[first
* elem_sz
], &ptr
[(first
+ count
) * elem_sz
],
72 (*num_inout
) -= count
;
77 typedef void (*ContentsClearFunc
) (char * /* priv */
81 _XkbFreeGeomNonLeafElems(Bool freeAll
,
84 unsigned short *num_inout
,
85 unsigned short *sz_inout
,
87 unsigned int elem_sz
, ContentsClearFunc freeFunc
)
96 else if ((first
>= (*num_inout
)) || (first
< 0) || (count
< 1))
98 else if (first
+ count
> (*num_inout
))
99 count
= (*num_inout
) - first
;
105 ptr
+= first
* elem_sz
;
106 for (i
= 0; i
< count
; i
++) {
112 (*num_inout
) = (*sz_inout
) = 0;
116 else if (first
+ count
>= (*num_inout
))
119 i
= ((*num_inout
) - (first
+ count
)) * elem_sz
;
121 memmove(&ptr
[first
* elem_sz
], &ptr
[(first
+ count
) * elem_sz
], i
);
122 (*num_inout
) -= count
;
127 /***====================================================================***/
130 _XkbClearProperty(char *prop_in
)
132 XkbPropertyPtr prop
= (XkbPropertyPtr
) prop_in
;
142 XkbFreeGeomProperties(XkbGeometryPtr geom
, int first
, int count
, Bool freeAll
)
144 _XkbFreeGeomNonLeafElems(freeAll
, first
, count
,
145 &geom
->num_properties
, &geom
->sz_properties
,
146 (char **) &geom
->properties
,
147 sizeof(XkbPropertyRec
), _XkbClearProperty
);
151 /***====================================================================***/
154 XkbFreeGeomKeyAliases(XkbGeometryPtr geom
, int first
, int count
, Bool freeAll
)
156 _XkbFreeGeomLeafElems(freeAll
, first
, count
,
157 &geom
->num_key_aliases
, &geom
->sz_key_aliases
,
158 (char **) &geom
->key_aliases
, sizeof(XkbKeyAliasRec
));
162 /***====================================================================***/
165 _XkbClearColor(char *color_in
)
167 XkbColorPtr color
= (XkbColorPtr
) color_in
;
174 XkbFreeGeomColors(XkbGeometryPtr geom
, int first
, int count
, Bool freeAll
)
176 _XkbFreeGeomNonLeafElems(freeAll
, first
, count
,
177 &geom
->num_colors
, &geom
->sz_colors
,
178 (char **) &geom
->colors
,
179 sizeof(XkbColorRec
), _XkbClearColor
);
183 /***====================================================================***/
186 XkbFreeGeomPoints(XkbOutlinePtr outline
, int first
, int count
, Bool freeAll
)
188 _XkbFreeGeomLeafElems(freeAll
, first
, count
,
189 &outline
->num_points
, &outline
->sz_points
,
190 (char **) &outline
->points
, sizeof(XkbPointRec
));
194 /***====================================================================***/
197 _XkbClearOutline(char *outline_in
)
199 XkbOutlinePtr outline
= (XkbOutlinePtr
) outline_in
;
201 if (outline
->points
!= NULL
)
202 XkbFreeGeomPoints(outline
, 0, outline
->num_points
, TRUE
);
207 XkbFreeGeomOutlines(XkbShapePtr shape
, int first
, int count
, Bool freeAll
)
209 _XkbFreeGeomNonLeafElems(freeAll
, first
, count
,
210 &shape
->num_outlines
, &shape
->sz_outlines
,
211 (char **) &shape
->outlines
,
212 sizeof(XkbOutlineRec
), _XkbClearOutline
);
217 /***====================================================================***/
220 _XkbClearShape(char *shape_in
)
222 XkbShapePtr shape
= (XkbShapePtr
) shape_in
;
225 XkbFreeGeomOutlines(shape
, 0, shape
->num_outlines
, TRUE
);
230 XkbFreeGeomShapes(XkbGeometryPtr geom
, int first
, int count
, Bool freeAll
)
232 _XkbFreeGeomNonLeafElems(freeAll
, first
, count
,
233 &geom
->num_shapes
, &geom
->sz_shapes
,
234 (char **) &geom
->shapes
,
235 sizeof(XkbShapeRec
), _XkbClearShape
);
239 /***====================================================================***/
242 XkbFreeGeomOverlayKeys(XkbOverlayRowPtr row
, int first
, int count
, Bool freeAll
)
244 _XkbFreeGeomLeafElems(freeAll
, first
, count
,
245 &row
->num_keys
, &row
->sz_keys
,
246 (char **) &row
->keys
, sizeof(XkbOverlayKeyRec
));
250 /***====================================================================***/
253 XkbFreeGeomKeys(XkbRowPtr row
, int first
, int count
, Bool freeAll
)
255 _XkbFreeGeomLeafElems(freeAll
, first
, count
,
256 &row
->num_keys
, &row
->sz_keys
,
257 (char **) &row
->keys
, sizeof(XkbKeyRec
));
261 /***====================================================================***/
264 _XkbClearRow(char *row_in
)
266 XkbRowPtr row
= (XkbRowPtr
) row_in
;
268 if (row
->keys
!= NULL
)
269 XkbFreeGeomKeys(row
, 0, row
->num_keys
, TRUE
);
274 XkbFreeGeomRows(XkbSectionPtr section
, int first
, int count
, Bool freeAll
)
276 _XkbFreeGeomNonLeafElems(freeAll
, first
, count
,
277 §ion
->num_rows
, §ion
->sz_rows
,
278 (char **) §ion
->rows
,
279 sizeof(XkbRowRec
), _XkbClearRow
);
282 /***====================================================================***/
285 _XkbClearSection(char *section_in
)
287 XkbSectionPtr section
= (XkbSectionPtr
) section_in
;
289 if (section
->rows
!= NULL
)
290 XkbFreeGeomRows(section
, 0, section
->num_rows
, TRUE
);
291 if (section
->doodads
!= NULL
) {
292 XkbFreeGeomDoodads(section
->doodads
, section
->num_doodads
, TRUE
);
293 section
->doodads
= NULL
;
299 XkbFreeGeomSections(XkbGeometryPtr geom
, int first
, int count
, Bool freeAll
)
301 _XkbFreeGeomNonLeafElems(freeAll
, first
, count
,
302 &geom
->num_sections
, &geom
->sz_sections
,
303 (char **) &geom
->sections
,
304 sizeof(XkbSectionRec
), _XkbClearSection
);
308 /***====================================================================***/
311 _XkbClearDoodad(char *doodad_in
)
313 XkbDoodadPtr doodad
= (XkbDoodadPtr
) doodad_in
;
315 switch (doodad
->any
.type
) {
318 free(doodad
->text
.text
);
319 doodad
->text
.text
= NULL
;
320 free(doodad
->text
.font
);
321 doodad
->text
.font
= NULL
;
326 free(doodad
->logo
.logo_name
);
327 doodad
->logo
.logo_name
= NULL
;
335 XkbFreeGeomDoodads(XkbDoodadPtr doodads
, int nDoodads
, Bool freeAll
)
338 register XkbDoodadPtr doodad
;
341 for (i
= 0, doodad
= doodads
; i
< nDoodads
; i
++, doodad
++) {
342 _XkbClearDoodad((char *) doodad
);
351 XkbFreeGeometry(XkbGeometryPtr geom
, unsigned which
, Bool freeMap
)
356 which
= XkbGeomAllMask
;
357 if ((which
& XkbGeomPropertiesMask
) && (geom
->properties
!= NULL
))
358 XkbFreeGeomProperties(geom
, 0, geom
->num_properties
, TRUE
);
359 if ((which
& XkbGeomColorsMask
) && (geom
->colors
!= NULL
))
360 XkbFreeGeomColors(geom
, 0, geom
->num_colors
, TRUE
);
361 if ((which
& XkbGeomShapesMask
) && (geom
->shapes
!= NULL
))
362 XkbFreeGeomShapes(geom
, 0, geom
->num_shapes
, TRUE
);
363 if ((which
& XkbGeomSectionsMask
) && (geom
->sections
!= NULL
))
364 XkbFreeGeomSections(geom
, 0, geom
->num_sections
, TRUE
);
365 if ((which
& XkbGeomDoodadsMask
) && (geom
->doodads
!= NULL
)) {
366 XkbFreeGeomDoodads(geom
->doodads
, geom
->num_doodads
, TRUE
);
367 geom
->doodads
= NULL
;
368 geom
->num_doodads
= geom
->sz_doodads
= 0;
370 if ((which
& XkbGeomKeyAliasesMask
) && (geom
->key_aliases
!= NULL
))
371 XkbFreeGeomKeyAliases(geom
, 0, geom
->num_key_aliases
, TRUE
);
373 free(geom
->label_font
);
374 geom
->label_font
= NULL
;
380 /***====================================================================***/
383 * Resize and clear an XKB geometry item array. The array size may
384 * grow or shrink unlike in _XkbGeomAlloc.
386 * @param buffer[in,out] buffer to reallocate and clear
387 * @param szItems[in] currently allocated item count for "buffer"
388 * @param nrItems[in] required item count for "buffer"
389 * @param itemSize[in] size of a single item in "buffer"
390 * @param clearance[in] items to clear after reallocation
394 * @return TRUE if reallocation succeeded. Otherwise FALSE is returned
395 * and contents of "buffer" aren't touched.
398 XkbGeomRealloc(void **buffer
, int szItems
, int nrItems
,
399 int itemSize
, XkbGeomClearance clearance
)
404 /* Check validity of arguments. */
408 if (!((items
&& (szItems
> 0)) || (!items
&& !szItems
)))
410 /* Check if there is need to resize. */
411 if (nrItems
!= szItems
)
412 if (!(items
= realloc(items
, nrItems
* itemSize
)))
414 /* Clear specified items to zero. */
416 case XKB_GEOM_CLEAR_EXCESS
:
417 clearBegin
= szItems
;
419 case XKB_GEOM_CLEAR_ALL
:
422 case XKB_GEOM_CLEAR_NONE
:
424 clearBegin
= nrItems
;
427 if (items
&& (clearBegin
< nrItems
))
428 memset((char *) items
+ (clearBegin
* itemSize
), 0,
429 (nrItems
- clearBegin
) * itemSize
);
435 _XkbGeomAlloc(void **old
,
437 unsigned short *total
, int num_new
, size_t sz_elem
)
444 if ((*num
) + num_new
<= (*total
))
447 *total
= (*num
) + num_new
;
449 if (!XkbGeomRealloc(old
, *num
, *total
, sz_elem
, XKB_GEOM_CLEAR_EXCESS
)) {
459 #define _XkbAllocProps(g,n) _XkbGeomAlloc((void *)&(g)->properties,\
460 &(g)->num_properties,&(g)->sz_properties,\
461 (n),sizeof(XkbPropertyRec))
462 #define _XkbAllocColors(g,n) _XkbGeomAlloc((void *)&(g)->colors,\
463 &(g)->num_colors,&(g)->sz_colors,\
464 (n),sizeof(XkbColorRec))
465 #define _XkbAllocShapes(g,n) _XkbGeomAlloc((void *)&(g)->shapes,\
466 &(g)->num_shapes,&(g)->sz_shapes,\
467 (n),sizeof(XkbShapeRec))
468 #define _XkbAllocSections(g,n) _XkbGeomAlloc((void *)&(g)->sections,\
469 &(g)->num_sections,&(g)->sz_sections,\
470 (n),sizeof(XkbSectionRec))
471 #define _XkbAllocDoodads(g,n) _XkbGeomAlloc((void *)&(g)->doodads,\
472 &(g)->num_doodads,&(g)->sz_doodads,\
473 (n),sizeof(XkbDoodadRec))
474 #define _XkbAllocKeyAliases(g,n) _XkbGeomAlloc((void *)&(g)->key_aliases,\
475 &(g)->num_key_aliases,&(g)->sz_key_aliases,\
476 (n),sizeof(XkbKeyAliasRec))
478 #define _XkbAllocOutlines(s,n) _XkbGeomAlloc((void *)&(s)->outlines,\
479 &(s)->num_outlines,&(s)->sz_outlines,\
480 (n),sizeof(XkbOutlineRec))
481 #define _XkbAllocRows(s,n) _XkbGeomAlloc((void *)&(s)->rows,\
482 &(s)->num_rows,&(s)->sz_rows,\
483 (n),sizeof(XkbRowRec))
484 #define _XkbAllocPoints(o,n) _XkbGeomAlloc((void *)&(o)->points,\
485 &(o)->num_points,&(o)->sz_points,\
486 (n),sizeof(XkbPointRec))
487 #define _XkbAllocKeys(r,n) _XkbGeomAlloc((void *)&(r)->keys,\
488 &(r)->num_keys,&(r)->sz_keys,\
489 (n),sizeof(XkbKeyRec))
490 #define _XkbAllocOverlays(s,n) _XkbGeomAlloc((void *)&(s)->overlays,\
491 &(s)->num_overlays,&(s)->sz_overlays,\
492 (n),sizeof(XkbOverlayRec))
493 #define _XkbAllocOverlayRows(o,n) _XkbGeomAlloc((void *)&(o)->rows,\
494 &(o)->num_rows,&(o)->sz_rows,\
495 (n),sizeof(XkbOverlayRowRec))
496 #define _XkbAllocOverlayKeys(r,n) _XkbGeomAlloc((void *)&(r)->keys,\
497 &(r)->num_keys,&(r)->sz_keys,\
498 (n),sizeof(XkbOverlayKeyRec))
501 XkbAllocGeometry(XkbDescPtr xkb
, XkbGeometrySizesPtr sizes
)
506 if (xkb
->geom
== NULL
) {
507 xkb
->geom
= calloc(1, sizeof(XkbGeometryRec
));
512 if ((sizes
->which
& XkbGeomPropertiesMask
) &&
513 ((rtrn
= _XkbAllocProps(geom
, sizes
->num_properties
)) != Success
)) {
516 if ((sizes
->which
& XkbGeomColorsMask
) &&
517 ((rtrn
= _XkbAllocColors(geom
, sizes
->num_colors
)) != Success
)) {
520 if ((sizes
->which
& XkbGeomShapesMask
) &&
521 ((rtrn
= _XkbAllocShapes(geom
, sizes
->num_shapes
)) != Success
)) {
524 if ((sizes
->which
& XkbGeomSectionsMask
) &&
525 ((rtrn
= _XkbAllocSections(geom
, sizes
->num_sections
)) != Success
)) {
528 if ((sizes
->which
& XkbGeomDoodadsMask
) &&
529 ((rtrn
= _XkbAllocDoodads(geom
, sizes
->num_doodads
)) != Success
)) {
532 if ((sizes
->which
& XkbGeomKeyAliasesMask
) &&
534 _XkbAllocKeyAliases(geom
, sizes
->num_key_aliases
)) != Success
)) {
539 XkbFreeGeometry(geom
, XkbGeomAllMask
, TRUE
);
544 /***====================================================================***/
547 XkbAddGeomProperty(XkbGeometryPtr geom
, char *name
, char *value
)
550 register XkbPropertyPtr prop
;
552 if ((!geom
) || (!name
) || (!value
))
554 for (i
= 0, prop
= geom
->properties
; i
< geom
->num_properties
; i
++, prop
++) {
555 if ((prop
->name
) && (strcmp(name
, prop
->name
) == 0)) {
557 prop
->value
= strdup(value
);
561 if ((geom
->num_properties
>= geom
->sz_properties
) &&
562 (_XkbAllocProps(geom
, 1) != Success
)) {
565 prop
= &geom
->properties
[geom
->num_properties
];
566 prop
->name
= strdup(name
);
569 prop
->value
= strdup(value
);
575 geom
->num_properties
++;
580 XkbAddGeomKeyAlias(XkbGeometryPtr geom
, char *aliasStr
, char *realStr
)
583 register XkbKeyAliasPtr alias
;
585 if ((!geom
) || (!aliasStr
) || (!realStr
) || (!aliasStr
[0]) || (!realStr
[0]))
587 for (i
= 0, alias
= geom
->key_aliases
; i
< geom
->num_key_aliases
;
589 if (strncmp(alias
->alias
, aliasStr
, XkbKeyNameLength
) == 0) {
590 memset(alias
->real
, 0, XkbKeyNameLength
);
591 strncpy(alias
->real
, realStr
, XkbKeyNameLength
);
595 if ((geom
->num_key_aliases
>= geom
->sz_key_aliases
) &&
596 (_XkbAllocKeyAliases(geom
, 1) != Success
)) {
599 alias
= &geom
->key_aliases
[geom
->num_key_aliases
];
600 memset(alias
, 0, sizeof(XkbKeyAliasRec
));
601 strncpy(alias
->alias
, aliasStr
, XkbKeyNameLength
);
602 strncpy(alias
->real
, realStr
, XkbKeyNameLength
);
603 geom
->num_key_aliases
++;
608 XkbAddGeomColor(XkbGeometryPtr geom
, char *spec
, unsigned int pixel
)
611 register XkbColorPtr color
;
613 if ((!geom
) || (!spec
))
615 for (i
= 0, color
= geom
->colors
; i
< geom
->num_colors
; i
++, color
++) {
616 if ((color
->spec
) && (strcmp(color
->spec
, spec
) == 0)) {
617 color
->pixel
= pixel
;
621 if ((geom
->num_colors
>= geom
->sz_colors
) &&
622 (_XkbAllocColors(geom
, 1) != Success
)) {
625 color
= &geom
->colors
[geom
->num_colors
];
626 color
->pixel
= pixel
;
627 color
->spec
= strdup(spec
);
635 XkbAddGeomOutline(XkbShapePtr shape
, int sz_points
)
637 XkbOutlinePtr outline
;
639 if ((!shape
) || (sz_points
< 0))
641 if ((shape
->num_outlines
>= shape
->sz_outlines
) &&
642 (_XkbAllocOutlines(shape
, 1) != Success
)) {
645 outline
= &shape
->outlines
[shape
->num_outlines
];
646 memset(outline
, 0, sizeof(XkbOutlineRec
));
647 if ((sz_points
> 0) && (_XkbAllocPoints(outline
, sz_points
) != Success
))
649 shape
->num_outlines
++;
654 XkbAddGeomShape(XkbGeometryPtr geom
, Atom name
, int sz_outlines
)
659 if ((!geom
) || (!name
) || (sz_outlines
< 0))
661 if (geom
->num_shapes
> 0) {
662 for (shape
= geom
->shapes
, i
= 0; i
< geom
->num_shapes
; i
++, shape
++) {
663 if (name
== shape
->name
)
667 if ((geom
->num_shapes
>= geom
->sz_shapes
) &&
668 (_XkbAllocShapes(geom
, 1) != Success
))
670 shape
= &geom
->shapes
[geom
->num_shapes
];
671 memset(shape
, 0, sizeof(XkbShapeRec
));
672 if ((sz_outlines
> 0) && (_XkbAllocOutlines(shape
, sz_outlines
) != Success
))
675 shape
->primary
= shape
->approx
= NULL
;
681 XkbAddGeomKey(XkbRowPtr row
)
687 if ((row
->num_keys
>= row
->sz_keys
) && (_XkbAllocKeys(row
, 1) != Success
))
689 key
= &row
->keys
[row
->num_keys
++];
690 memset(key
, 0, sizeof(XkbKeyRec
));
695 XkbAddGeomRow(XkbSectionPtr section
, int sz_keys
)
699 if ((!section
) || (sz_keys
< 0))
701 if ((section
->num_rows
>= section
->sz_rows
) &&
702 (_XkbAllocRows(section
, 1) != Success
))
704 row
= §ion
->rows
[section
->num_rows
];
705 memset(row
, 0, sizeof(XkbRowRec
));
706 if ((sz_keys
> 0) && (_XkbAllocKeys(row
, sz_keys
) != Success
))
713 XkbAddGeomSection(XkbGeometryPtr geom
,
714 Atom name
, int sz_rows
, int sz_doodads
, int sz_over
)
717 XkbSectionPtr section
;
719 if ((!geom
) || (name
== None
) || (sz_rows
< 0))
721 for (i
= 0, section
= geom
->sections
; i
< geom
->num_sections
;
723 if (section
->name
!= name
)
725 if (((sz_rows
> 0) && (_XkbAllocRows(section
, sz_rows
) != Success
)) ||
727 (_XkbAllocDoodads(section
, sz_doodads
) != Success
)) ||
728 ((sz_over
> 0) && (_XkbAllocOverlays(section
, sz_over
) != Success
)))
732 if ((geom
->num_sections
>= geom
->sz_sections
) &&
733 (_XkbAllocSections(geom
, 1) != Success
))
735 section
= &geom
->sections
[geom
->num_sections
];
736 if ((sz_rows
> 0) && (_XkbAllocRows(section
, sz_rows
) != Success
))
738 if ((sz_doodads
> 0) && (_XkbAllocDoodads(section
, sz_doodads
) != Success
)) {
741 section
->rows
= NULL
;
742 section
->sz_rows
= section
->num_rows
= 0;
746 section
->name
= name
;
747 geom
->num_sections
++;
752 XkbAddGeomDoodad(XkbGeometryPtr geom
, XkbSectionPtr section
, Atom name
)
754 XkbDoodadPtr old
, doodad
;
755 register int i
, nDoodads
;
757 if ((!geom
) || (name
== None
))
759 if ((section
!= NULL
) && (section
->num_doodads
> 0)) {
760 old
= section
->doodads
;
761 nDoodads
= section
->num_doodads
;
765 nDoodads
= geom
->num_doodads
;
767 for (i
= 0, doodad
= old
; i
< nDoodads
; i
++, doodad
++) {
768 if (doodad
->any
.name
== name
)
772 if ((section
->num_doodads
>= geom
->sz_doodads
) &&
773 (_XkbAllocDoodads(section
, 1) != Success
)) {
776 doodad
= §ion
->doodads
[section
->num_doodads
++];
779 if ((geom
->num_doodads
>= geom
->sz_doodads
) &&
780 (_XkbAllocDoodads(geom
, 1) != Success
))
782 doodad
= &geom
->doodads
[geom
->num_doodads
++];
784 memset(doodad
, 0, sizeof(XkbDoodadRec
));
785 doodad
->any
.name
= name
;
790 XkbAddGeomOverlayKey(XkbOverlayPtr overlay
,
791 XkbOverlayRowPtr row
, char *over
, char *under
)
794 XkbOverlayKeyPtr key
;
795 XkbSectionPtr section
;
799 if ((!overlay
) || (!row
) || (!over
) || (!under
))
801 section
= overlay
->section_under
;
802 if (row
->row_under
>= section
->num_rows
)
804 row_under
= §ion
->rows
[row
->row_under
];
805 for (i
= 0, found
= FALSE
; i
< row_under
->num_keys
; i
++) {
806 if (strncmp(under
, row_under
->keys
[i
].name
.name
, XkbKeyNameLength
) == 0) {
813 if ((row
->num_keys
>= row
->sz_keys
) &&
814 (_XkbAllocOverlayKeys(row
, 1) != Success
))
816 key
= &row
->keys
[row
->num_keys
];
817 strncpy(key
->under
.name
, under
, XkbKeyNameLength
);
818 strncpy(key
->over
.name
, over
, XkbKeyNameLength
);
824 XkbAddGeomOverlayRow(XkbOverlayPtr overlay
, int row_under
, int sz_keys
)
827 XkbOverlayRowPtr row
;
829 if ((!overlay
) || (sz_keys
< 0))
831 if (row_under
>= overlay
->section_under
->num_rows
)
833 for (i
= 0; i
< overlay
->num_rows
; i
++) {
834 if (overlay
->rows
[i
].row_under
== row_under
) {
835 row
= &overlay
->rows
[i
];
836 if ((row
->sz_keys
< sz_keys
) &&
837 (_XkbAllocOverlayKeys(row
, sz_keys
) != Success
)) {
840 return &overlay
->rows
[i
];
843 if ((overlay
->num_rows
>= overlay
->sz_rows
) &&
844 (_XkbAllocOverlayRows(overlay
, 1) != Success
))
846 row
= &overlay
->rows
[overlay
->num_rows
];
847 memset(row
, 0, sizeof(XkbOverlayRowRec
));
848 if ((sz_keys
> 0) && (_XkbAllocOverlayKeys(row
, sz_keys
) != Success
))
850 row
->row_under
= row_under
;
856 XkbAddGeomOverlay(XkbSectionPtr section
, Atom name
, int sz_rows
)
859 XkbOverlayPtr overlay
;
861 if ((!section
) || (name
== None
) || (sz_rows
== 0))
864 for (i
= 0, overlay
= section
->overlays
; i
< section
->num_overlays
;
866 if (overlay
->name
== name
) {
868 (_XkbAllocOverlayRows(overlay
, sz_rows
) != Success
))
873 if ((section
->num_overlays
>= section
->sz_overlays
) &&
874 (_XkbAllocOverlays(section
, 1) != Success
))
876 overlay
= §ion
->overlays
[section
->num_overlays
];
877 if ((sz_rows
> 0) && (_XkbAllocOverlayRows(overlay
, sz_rows
) != Success
))
879 overlay
->name
= name
;
880 overlay
->section_under
= section
;
881 section
->num_overlays
++;