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>
41 /***===================================================================***/
44 XkbAllocCompatMap(XkbDescPtr xkb
, unsigned which
, unsigned nSI
)
46 XkbCompatMapPtr compat
;
47 XkbSymInterpretRec
*prev_interpret
;
52 if (xkb
->compat
->size_si
>= nSI
)
55 compat
->size_si
= nSI
;
56 if (compat
->sym_interpret
== NULL
)
58 prev_interpret
= compat
->sym_interpret
;
59 compat
->sym_interpret
= realloc(compat
->sym_interpret
,
60 nSI
* sizeof(XkbSymInterpretRec
));
61 if (compat
->sym_interpret
== NULL
) {
63 compat
->size_si
= compat
->num_si
= 0;
66 if (compat
->num_si
!= 0) {
67 memset(&compat
->sym_interpret
[compat
->num_si
], 0,
69 compat
->num_si
) * sizeof(XkbSymInterpretRec
));
73 compat
= calloc(1, sizeof(XkbCompatMapRec
));
77 compat
->sym_interpret
= calloc(nSI
, sizeof(XkbSymInterpretRec
));
78 if (!compat
->sym_interpret
) {
83 compat
->size_si
= nSI
;
85 memset((char *) &compat
->groups
[0], 0,
86 XkbNumKbdGroups
* sizeof(XkbModsRec
));
92 XkbFreeCompatMap(XkbDescPtr xkb
, unsigned which
, Bool freeMap
)
94 register XkbCompatMapPtr compat
;
96 if ((xkb
== NULL
) || (xkb
->compat
== NULL
))
100 which
= XkbAllCompatMask
;
101 if (which
& XkbGroupCompatMask
)
102 memset((char *) &compat
->groups
[0], 0,
103 XkbNumKbdGroups
* sizeof(XkbModsRec
));
104 if (which
& XkbSymInterpMask
) {
105 if ((compat
->sym_interpret
) && (compat
->size_si
> 0))
106 free(compat
->sym_interpret
);
107 compat
->size_si
= compat
->num_si
= 0;
108 compat
->sym_interpret
= NULL
;
117 /***===================================================================***/
120 XkbAllocNames(XkbDescPtr xkb
, unsigned which
, int nTotalRG
, int nTotalAliases
)
126 if (xkb
->names
== NULL
) {
127 xkb
->names
= calloc(1, sizeof(XkbNamesRec
));
128 if (xkb
->names
== NULL
)
132 if ((which
& XkbKTLevelNamesMask
) && (xkb
->map
!= NULL
) &&
133 (xkb
->map
->types
!= NULL
)) {
137 type
= xkb
->map
->types
;
138 for (i
= 0; i
< xkb
->map
->num_types
; i
++, type
++) {
139 if (type
->level_names
== NULL
) {
140 type
->level_names
= calloc(type
->num_levels
, sizeof(Atom
));
141 if (type
->level_names
== NULL
)
146 if ((which
& XkbKeyNamesMask
) && (names
->keys
== NULL
)) {
147 if ((!XkbIsLegalKeycode(xkb
->min_key_code
)) ||
148 (!XkbIsLegalKeycode(xkb
->max_key_code
)) ||
149 (xkb
->max_key_code
< xkb
->min_key_code
))
151 names
->keys
= calloc((xkb
->max_key_code
+ 1), sizeof(XkbKeyNameRec
));
152 if (names
->keys
== NULL
)
155 if ((which
& XkbKeyAliasesMask
) && (nTotalAliases
> 0)) {
156 if (names
->key_aliases
== NULL
) {
157 names
->key_aliases
= calloc(nTotalAliases
, sizeof(XkbKeyAliasRec
));
159 else if (nTotalAliases
> names
->num_key_aliases
) {
160 XkbKeyAliasRec
*prev_aliases
= names
->key_aliases
;
162 names
->key_aliases
= realloc(names
->key_aliases
,
164 sizeof(XkbKeyAliasRec
));
165 if (names
->key_aliases
!= NULL
) {
166 memset(&names
->key_aliases
[names
->num_key_aliases
], 0,
168 names
->num_key_aliases
) * sizeof(XkbKeyAliasRec
));
174 if (names
->key_aliases
== NULL
) {
175 names
->num_key_aliases
= 0;
178 names
->num_key_aliases
= nTotalAliases
;
180 if ((which
& XkbRGNamesMask
) && (nTotalRG
> 0)) {
181 if (names
->radio_groups
== NULL
) {
182 names
->radio_groups
= calloc(nTotalRG
, sizeof(Atom
));
184 else if (nTotalRG
> names
->num_rg
) {
185 Atom
*prev_radio_groups
= names
->radio_groups
;
187 names
->radio_groups
= realloc(names
->radio_groups
,
188 nTotalRG
* sizeof(Atom
));
189 if (names
->radio_groups
!= NULL
) {
190 memset(&names
->radio_groups
[names
->num_rg
], 0,
191 (nTotalRG
- names
->num_rg
) * sizeof(Atom
));
194 free(prev_radio_groups
);
197 if (names
->radio_groups
== NULL
)
199 names
->num_rg
= nTotalRG
;
205 XkbFreeNames(XkbDescPtr xkb
, unsigned which
, Bool freeMap
)
209 if ((xkb
== NULL
) || (xkb
->names
== NULL
))
213 which
= XkbAllNamesMask
;
214 if (which
& XkbKTLevelNamesMask
) {
215 XkbClientMapPtr map
= xkb
->map
;
217 if ((map
!= NULL
) && (map
->types
!= NULL
)) {
219 register XkbKeyTypePtr type
;
222 for (i
= 0; i
< map
->num_types
; i
++, type
++) {
223 free(type
->level_names
);
224 type
->level_names
= NULL
;
228 if ((which
& XkbKeyNamesMask
) && (names
->keys
!= NULL
)) {
233 if ((which
& XkbKeyAliasesMask
) && (names
->key_aliases
)) {
234 free(names
->key_aliases
);
235 names
->key_aliases
= NULL
;
236 names
->num_key_aliases
= 0;
238 if ((which
& XkbRGNamesMask
) && (names
->radio_groups
)) {
239 free(names
->radio_groups
);
240 names
->radio_groups
= NULL
;
250 /***===================================================================***/
253 XkbAllocControls(XkbDescPtr xkb
, unsigned which
)
258 if (xkb
->ctrls
== NULL
) {
259 xkb
->ctrls
= calloc(1, sizeof(XkbControlsRec
));
266 /*ARGSUSED*/ static void
267 XkbFreeControls(XkbDescPtr xkb
, unsigned which
, Bool freeMap
)
269 if (freeMap
&& (xkb
!= NULL
) && (xkb
->ctrls
!= NULL
)) {
276 /***===================================================================***/
279 XkbAllocIndicatorMaps(XkbDescPtr xkb
)
283 if (xkb
->indicators
== NULL
) {
284 xkb
->indicators
= calloc(1, sizeof(XkbIndicatorRec
));
285 if (!xkb
->indicators
)
292 XkbFreeIndicatorMaps(XkbDescPtr xkb
)
294 if ((xkb
!= NULL
) && (xkb
->indicators
!= NULL
)) {
295 free(xkb
->indicators
);
296 xkb
->indicators
= NULL
;
301 /***====================================================================***/
304 XkbAllocKeyboard(void)
308 xkb
= calloc(1, sizeof(XkbDescRec
));
310 xkb
->device_spec
= XkbUseCoreKbd
;
315 XkbFreeKeyboard(XkbDescPtr xkb
, unsigned which
, Bool freeAll
)
320 which
= XkbAllComponentsMask
;
321 if (which
& XkbClientMapMask
)
322 XkbFreeClientMap(xkb
, XkbAllClientInfoMask
, TRUE
);
323 if (which
& XkbServerMapMask
)
324 XkbFreeServerMap(xkb
, XkbAllServerInfoMask
, TRUE
);
325 if (which
& XkbCompatMapMask
)
326 XkbFreeCompatMap(xkb
, XkbAllCompatMask
, TRUE
);
327 if (which
& XkbIndicatorMapMask
)
328 XkbFreeIndicatorMaps(xkb
);
329 if (which
& XkbNamesMask
)
330 XkbFreeNames(xkb
, XkbAllNamesMask
, TRUE
);
331 if ((which
& XkbGeometryMask
) && (xkb
->geom
!= NULL
)) {
332 XkbFreeGeometry(xkb
->geom
, XkbGeomAllMask
, TRUE
);
333 /* PERHAPS BONGHITS etc */
336 if (which
& XkbControlsMask
)
337 XkbFreeControls(xkb
, XkbAllControlsMask
, TRUE
);
343 /***====================================================================***/
346 XkbFreeComponentNames(XkbComponentNamesPtr names
, Bool freeNames
)
349 free(names
->keycodes
);
352 free(names
->symbols
);
353 free(names
->geometry
);
354 memset(names
, 0, sizeof(XkbComponentNamesRec
));