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 = _XkbTypedRealloc(compat->sym_interpret,
55 nSI, struct xkb_sym_interpret);
56 if (!compat->sym_interpret) {
58 compat->size_si = compat->num_si = 0;
62 if (compat->num_si != 0)
63 _XkbClearElems(compat->sym_interpret, compat->num_si,
64 compat->size_si - 1, struct xkb_sym_interpret);
69 compat = _XkbTypedCalloc(1, struct xkb_compat_map);
74 compat->sym_interpret = _XkbTypedCalloc(nSI, struct xkb_sym_interpret);
75 if (!compat->sym_interpret) {
80 compat->size_si = nSI;
82 memset(&compat->groups[0], 0, XkbNumKbdGroups * sizeof(struct xkb_mods));
90 XkbcFreeCompatMap(struct xkb_desc * xkb)
92 struct xkb_compat_map * compat;
94 if (!xkb || !xkb->compat)
99 free(compat->sym_interpret);
105 XkbcAllocNames(struct xkb_desc * xkb, unsigned which, int nTotalRG, int nTotalAliases)
107 struct xkb_names * names;
113 xkb->names = _XkbTypedCalloc(1, struct xkb_names);
119 if ((which & XkbKTLevelNamesMask) && xkb->map && xkb->map->types) {
121 struct xkb_key_type * type;
123 type = xkb->map->types;
124 for (i = 0; i < xkb->map->num_types; i++, type++) {
125 if (!type->level_names) {
126 type->level_names = _XkbTypedCalloc(type->num_levels, uint32_t);
127 if (!type->level_names)
133 if ((which & XkbKeyNamesMask) && !names->keys) {
134 if (!xkb_keymap_keycode_range_is_legal(xkb))
137 names->keys = _XkbTypedCalloc(xkb->max_key_code + 1, struct xkb_key_name);
142 if ((which & XkbKeyAliasesMask) && (nTotalAliases > 0)) {
143 if (!names->key_aliases)
144 names->key_aliases = _XkbTypedCalloc(nTotalAliases,
145 struct xkb_key_alias);
146 else if (nTotalAliases > names->num_key_aliases) {
147 struct xkb_key_alias *prev_aliases = names->key_aliases;
149 names->key_aliases = _XkbTypedRealloc(names->key_aliases,
151 struct xkb_key_alias);
152 if (names->key_aliases)
153 _XkbClearElems(names->key_aliases, names->num_key_aliases,
154 nTotalAliases - 1, struct xkb_key_alias);
159 if (!names->key_aliases) {
160 names->num_key_aliases = 0;
164 names->num_key_aliases = nTotalAliases;
167 if ((which & XkbRGNamesMask) && (nTotalRG > 0)) {
168 if (!names->radio_groups)
169 names->radio_groups = _XkbTypedCalloc(nTotalRG, uint32_t);
170 else if (nTotalRG > names->num_rg) {
171 uint32_t *prev_radio_groups = names->radio_groups;
173 names->radio_groups = _XkbTypedRealloc(names->radio_groups,
175 if (names->radio_groups)
176 _XkbClearElems(names->radio_groups, names->num_rg,
177 nTotalRG - 1, uint32_t);
179 free(prev_radio_groups);
182 if (!names->radio_groups)
185 names->num_rg = nTotalRG;
192 XkbcFreeNames(struct xkb_desc * xkb)
194 struct xkb_names * names;
195 struct xkb_client_map * map;
197 if (!xkb || !xkb->names)
203 if (map && map->types) {
205 struct xkb_key_type * type = map->types;
207 for (i = 0; i < map->num_types; i++, type++) {
208 free(type->level_names);
209 type->level_names = NULL;
214 free(names->key_aliases);
215 free(names->radio_groups);
221 XkbcAllocControls(struct xkb_desc * xkb, unsigned which)
227 xkb->ctrls = _XkbTypedCalloc(1, struct xkb_controls);
232 if (!xkb->ctrls->per_key_repeat) {
233 xkb->ctrls->per_key_repeat = _XkbTypedCalloc(xkb->max_key_code << 3,
235 if (!xkb->ctrls->per_key_repeat)
243 XkbcFreeControls(struct xkb_desc * xkb)
245 if (xkb && xkb->ctrls) {
246 free(xkb->ctrls->per_key_repeat);
253 XkbcAllocIndicatorMaps(struct xkb_desc * xkb)
258 if (!xkb->indicators) {
259 xkb->indicators = _XkbTypedCalloc(1, struct xkb_indicator);
260 if (!xkb->indicators)
268 XkbcFreeIndicatorMaps(struct xkb_desc * xkb)
271 free(xkb->indicators);
272 xkb->indicators = NULL;
277 XkbcAllocKeyboard(void)
279 struct xkb_desc *xkb;
281 xkb = _XkbTypedCalloc(1, struct xkb_desc);
283 xkb->device_spec = XkbUseCoreKbd;
288 XkbcFreeKeyboard(struct xkb_desc * xkb)
293 XkbcFreeClientMap(xkb);
294 XkbcFreeServerMap(xkb);
295 XkbcFreeCompatMap(xkb);
296 XkbcFreeIndicatorMaps(xkb);
298 XkbcFreeGeometry(xkb);
299 XkbcFreeControls(xkb);