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.
28 #include "xkbcommon/xkbcommon.h"
29 #include "XKBcommonint.h"
30 #include <X11/extensions/XKB.h>
33 XkbcAllocCompatMap(struct xkb_keymap * xkb, unsigned which, unsigned nSI)
35 struct xkb_compat_map * compat;
36 struct xkb_sym_interpret *prev_interpret;
42 if (xkb->compat->size_si >= nSI)
46 compat->size_si = nSI;
47 if (!compat->sym_interpret)
50 prev_interpret = compat->sym_interpret;
51 compat->sym_interpret = uTypedRecalloc(compat->sym_interpret,
53 struct xkb_sym_interpret);
54 if (!compat->sym_interpret) {
56 compat->size_si = compat->num_si = 0;
63 compat = uTypedCalloc(1, struct xkb_compat_map);
68 compat->sym_interpret = uTypedCalloc(nSI, struct xkb_sym_interpret);
69 if (!compat->sym_interpret) {
74 compat->size_si = nSI;
76 memset(&compat->groups[0], 0, XkbNumKbdGroups * sizeof(struct xkb_mods));
84 XkbcFreeCompatMap(struct xkb_keymap * xkb)
86 struct xkb_compat_map * compat;
88 if (!xkb || !xkb->compat)
93 free(compat->sym_interpret);
99 XkbcAllocNames(struct xkb_keymap * xkb, unsigned which, unsigned nTotalAliases)
101 struct xkb_names * names;
107 xkb->names = uTypedCalloc(1, struct xkb_names);
113 if ((which & XkbKTLevelNamesMask) && xkb->map && xkb->map->types) {
115 struct xkb_key_type * type;
117 type = xkb->map->types;
118 for (i = 0; i < xkb->map->num_types; i++, type++) {
119 if (!type->level_names) {
120 type->level_names = uTypedCalloc(type->num_levels, const char *);
121 if (!type->level_names)
127 if ((which & XkbKeyNamesMask) && !names->keys) {
128 if (!xkb_keymap_keycode_range_is_legal(xkb))
131 names->keys = uTypedCalloc(xkb->max_key_code + 1, struct xkb_key_name);
136 if ((which & XkbKeyAliasesMask) && (nTotalAliases > 0)) {
137 if (!names->key_aliases)
138 names->key_aliases = uTypedCalloc(nTotalAliases,
139 struct xkb_key_alias);
140 else if (nTotalAliases > names->num_key_aliases) {
141 struct xkb_key_alias *prev_aliases = names->key_aliases;
143 names->key_aliases = uTypedRecalloc(names->key_aliases,
144 names->num_key_aliases,
146 struct xkb_key_alias);
147 if (!names->key_aliases)
151 if (!names->key_aliases) {
152 names->num_key_aliases = 0;
156 names->num_key_aliases = nTotalAliases;
163 XkbcFreeNames(struct xkb_keymap * xkb)
165 struct xkb_names * names;
166 struct xkb_client_map * map;
169 if (!xkb || !xkb->names)
175 if (map && map->types) {
176 struct xkb_key_type * type = map->types;
178 for (i = 0; i < map->num_types; i++, type++) {
180 for (j = 0; j < type->num_levels; j++)
181 free(UNCONSTIFY(type->level_names[i]));
182 free(type->level_names);
183 type->level_names = NULL;
187 for (i = 0; i < XkbNumVirtualMods; i++)
188 free(UNCONSTIFY(names->vmods[i]));
189 for (i = 0; i < XkbNumIndicators; i++)
190 free(UNCONSTIFY(names->indicators[i]));
191 for (i = 0; i < XkbNumKbdGroups; i++)
192 free(UNCONSTIFY(names->groups[i]));
195 free(names->key_aliases);
201 XkbcAllocControls(struct xkb_keymap * xkb, unsigned which)
207 xkb->ctrls = uTypedCalloc(1, struct xkb_controls);
212 if (!xkb->ctrls->per_key_repeat) {
213 xkb->ctrls->per_key_repeat = uTypedCalloc(xkb->max_key_code << 3,
215 if (!xkb->ctrls->per_key_repeat)
223 XkbcFreeControls(struct xkb_keymap * xkb)
225 if (xkb && xkb->ctrls) {
226 free(xkb->ctrls->per_key_repeat);
233 XkbcAllocIndicatorMaps(struct xkb_keymap * xkb)
238 if (!xkb->indicators) {
239 xkb->indicators = uTypedCalloc(1, struct xkb_indicator);
240 if (!xkb->indicators)
248 XkbcFreeIndicatorMaps(struct xkb_keymap * xkb)
251 free(xkb->indicators);
252 xkb->indicators = NULL;
257 XkbcAllocKeyboard(struct xkb_context *context)
259 struct xkb_keymap *xkb;
261 xkb = uTypedCalloc(1, struct xkb_keymap);
266 xkb->context = xkb_context_ref(context);
272 XkbcFreeKeyboard(struct xkb_keymap * xkb)
277 XkbcFreeClientMap(xkb);
278 XkbcFreeServerMap(xkb);
279 XkbcFreeCompatMap(xkb);
280 XkbcFreeIndicatorMaps(xkb);
282 XkbcFreeControls(xkb);
283 xkb_context_unref(xkb->context);