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.
31 #include "xkbcommon/xkbcommon.h"
32 #include "XKBcommonint.h"
33 #include <X11/extensions/XKB.h>
36 XkbcAllocCompatMap(struct xkb_desc * xkb, unsigned which, unsigned nSI)
38 struct xkb_compat_map * compat;
39 struct xkb_sym_interpret *prev_interpret;
45 if (xkb->compat->size_si >= nSI)
49 compat->size_si = nSI;
50 if (!compat->sym_interpret)
53 prev_interpret = compat->sym_interpret;
54 compat->sym_interpret = uTypedRecalloc(compat->sym_interpret,
56 struct xkb_sym_interpret);
57 if (!compat->sym_interpret) {
59 compat->size_si = compat->num_si = 0;
66 compat = uTypedCalloc(1, struct xkb_compat_map);
71 compat->sym_interpret = uTypedCalloc(nSI, struct xkb_sym_interpret);
72 if (!compat->sym_interpret) {
77 compat->size_si = nSI;
79 memset(&compat->groups[0], 0, XkbNumKbdGroups * sizeof(struct xkb_mods));
87 XkbcFreeCompatMap(struct xkb_desc * xkb)
89 struct xkb_compat_map * compat;
91 if (!xkb || !xkb->compat)
96 free(compat->sym_interpret);
102 XkbcAllocNames(struct xkb_desc * xkb, unsigned which, unsigned nTotalAliases)
104 struct xkb_names * names;
110 xkb->names = uTypedCalloc(1, struct xkb_names);
116 if ((which & XkbKTLevelNamesMask) && xkb->map && xkb->map->types) {
118 struct xkb_key_type * type;
120 type = xkb->map->types;
121 for (i = 0; i < xkb->map->num_types; i++, type++) {
122 if (!type->level_names) {
123 type->level_names = uTypedCalloc(type->num_levels, const char *);
124 if (!type->level_names)
130 if ((which & XkbKeyNamesMask) && !names->keys) {
131 if (!xkb_keymap_keycode_range_is_legal(xkb))
134 names->keys = uTypedCalloc(xkb->max_key_code + 1, struct xkb_key_name);
139 if ((which & XkbKeyAliasesMask) && (nTotalAliases > 0)) {
140 if (!names->key_aliases)
141 names->key_aliases = uTypedCalloc(nTotalAliases,
142 struct xkb_key_alias);
143 else if (nTotalAliases > names->num_key_aliases) {
144 struct xkb_key_alias *prev_aliases = names->key_aliases;
146 names->key_aliases = uTypedRecalloc(names->key_aliases,
147 names->num_key_aliases,
149 struct xkb_key_alias);
150 if (!names->key_aliases)
154 if (!names->key_aliases) {
155 names->num_key_aliases = 0;
159 names->num_key_aliases = nTotalAliases;
166 XkbcFreeNames(struct xkb_desc * xkb)
168 struct xkb_names * names;
169 struct xkb_client_map * map;
172 if (!xkb || !xkb->names)
178 if (map && map->types) {
179 struct xkb_key_type * type = map->types;
181 for (i = 0; i < map->num_types; i++, type++) {
183 for (j = 0; j < type->num_levels; j++)
184 free(UNCONSTIFY(type->level_names[i]));
185 free(type->level_names);
186 type->level_names = NULL;
190 for (i = 0; i < XkbNumVirtualMods; i++)
191 free(UNCONSTIFY(names->vmods[i]));
192 for (i = 0; i < XkbNumIndicators; i++)
193 free(UNCONSTIFY(names->indicators[i]));
194 for (i = 0; i < XkbNumKbdGroups; i++)
195 free(UNCONSTIFY(names->groups[i]));
198 free(names->key_aliases);
204 XkbcAllocControls(struct xkb_desc * xkb, unsigned which)
210 xkb->ctrls = uTypedCalloc(1, struct xkb_controls);
215 if (!xkb->ctrls->per_key_repeat) {
216 xkb->ctrls->per_key_repeat = uTypedCalloc(xkb->max_key_code << 3,
218 if (!xkb->ctrls->per_key_repeat)
226 XkbcFreeControls(struct xkb_desc * xkb)
228 if (xkb && xkb->ctrls) {
229 free(xkb->ctrls->per_key_repeat);
236 XkbcAllocIndicatorMaps(struct xkb_desc * xkb)
241 if (!xkb->indicators) {
242 xkb->indicators = uTypedCalloc(1, struct xkb_indicator);
243 if (!xkb->indicators)
251 XkbcFreeIndicatorMaps(struct xkb_desc * xkb)
254 free(xkb->indicators);
255 xkb->indicators = NULL;
260 XkbcAllocKeyboard(struct xkb_context *context)
262 struct xkb_desc *xkb;
264 xkb = uTypedCalloc(1, struct xkb_desc);
269 xkb_context_ref(context);
270 xkb->context = context;
276 XkbcFreeKeyboard(struct xkb_desc * xkb)
281 XkbcFreeClientMap(xkb);
282 XkbcFreeServerMap(xkb);
283 XkbcFreeCompatMap(xkb);
284 XkbcFreeIndicatorMaps(xkb);
286 XkbcFreeControls(xkb);
287 xkb_context_unref(xkb->context);