2009-03-19 17:57:01 -06:00
|
|
|
/*
|
|
|
|
Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
|
|
|
|
|
|
|
|
Permission to use, copy, modify, and distribute this
|
|
|
|
software and its documentation for any purpose and without
|
|
|
|
fee is hereby granted, provided that the above copyright
|
|
|
|
notice appear in all copies and that both that copyright
|
|
|
|
notice and this permission notice appear in supporting
|
|
|
|
documentation, and that the name of Silicon Graphics not be
|
|
|
|
used in advertising or publicity pertaining to distribution
|
|
|
|
of the software without specific prior written permission.
|
|
|
|
Silicon Graphics makes no representation about the suitability
|
|
|
|
of this software for any purpose. It is provided "as is"
|
|
|
|
without any express or implied warranty.
|
|
|
|
|
|
|
|
SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
|
|
|
|
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
|
|
AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
|
|
|
|
GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
|
|
|
|
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
|
|
|
|
DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
|
|
|
|
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
|
|
|
|
THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
2009-04-08 08:46:25 -06:00
|
|
|
#include "xkballoc.h"
|
|
|
|
#include "xkbgeom.h"
|
2009-03-05 19:20:15 -07:00
|
|
|
#include "X11/extensions/XKBcommon.h"
|
|
|
|
#include "XKBcommonint.h"
|
2009-03-19 17:57:01 -06:00
|
|
|
#include <X11/extensions/XKB.h>
|
|
|
|
|
|
|
|
int
|
2009-03-25 16:41:21 -06:00
|
|
|
XkbcAllocCompatMap(XkbcDescPtr xkb, unsigned which, unsigned nSI)
|
2009-03-19 17:57:01 -06:00
|
|
|
{
|
2010-06-16 22:56:08 -06:00
|
|
|
XkbcCompatMapPtr compat;
|
|
|
|
XkbcSymInterpretRec *prev_interpret;
|
2009-03-19 17:57:01 -06:00
|
|
|
|
|
|
|
if (!xkb)
|
2009-03-25 16:41:21 -06:00
|
|
|
return BadMatch;
|
|
|
|
|
2009-03-19 17:57:01 -06:00
|
|
|
if (xkb->compat) {
|
2009-03-25 16:41:21 -06:00
|
|
|
if (xkb->compat->size_si >= nSI)
|
|
|
|
return Success;
|
|
|
|
|
|
|
|
compat = xkb->compat;
|
|
|
|
compat->size_si = nSI;
|
|
|
|
if (!compat->sym_interpret)
|
|
|
|
compat->num_si = 0;
|
|
|
|
|
|
|
|
prev_interpret = compat->sym_interpret;
|
|
|
|
compat->sym_interpret = _XkbTypedRealloc(compat->sym_interpret,
|
2010-06-16 22:56:08 -06:00
|
|
|
nSI, XkbcSymInterpretRec);
|
2009-03-25 16:41:21 -06:00
|
|
|
if (!compat->sym_interpret) {
|
|
|
|
_XkbFree(prev_interpret);
|
|
|
|
compat->size_si = compat->num_si = 0;
|
|
|
|
return BadAlloc;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (compat->num_si != 0)
|
|
|
|
_XkbClearElems(compat->sym_interpret, compat->num_si,
|
2010-06-16 22:56:08 -06:00
|
|
|
compat->size_si - 1, XkbcSymInterpretRec);
|
2009-03-25 16:41:21 -06:00
|
|
|
|
|
|
|
return Success;
|
|
|
|
}
|
|
|
|
|
2010-06-16 22:56:08 -06:00
|
|
|
compat = _XkbTypedCalloc(1, XkbcCompatMapRec);
|
2009-03-25 16:41:21 -06:00
|
|
|
if (!compat)
|
|
|
|
return BadAlloc;
|
|
|
|
|
|
|
|
if (nSI > 0) {
|
2010-06-16 22:56:08 -06:00
|
|
|
compat->sym_interpret = _XkbTypedCalloc(nSI, XkbcSymInterpretRec);
|
2009-03-25 16:41:21 -06:00
|
|
|
if (!compat->sym_interpret) {
|
|
|
|
_XkbFree(compat);
|
|
|
|
return BadAlloc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
compat->size_si = nSI;
|
|
|
|
compat->num_si = 0;
|
2010-06-23 09:25:10 -06:00
|
|
|
bzero(&compat->groups[0], XkbNumKbdGroups * sizeof(XkbcModsRec));
|
2009-03-25 16:41:21 -06:00
|
|
|
xkb->compat = compat;
|
|
|
|
|
2009-03-19 17:57:01 -06:00
|
|
|
return Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2009-03-25 16:41:21 -06:00
|
|
|
XkbcFreeCompatMap(XkbcDescPtr xkb, unsigned which, Bool freeMap)
|
2009-03-19 17:57:01 -06:00
|
|
|
{
|
2010-06-16 22:56:08 -06:00
|
|
|
XkbcCompatMapPtr compat;
|
2009-03-19 17:57:01 -06:00
|
|
|
|
2009-03-25 16:41:21 -06:00
|
|
|
if (!xkb || !xkb->compat)
|
|
|
|
return;
|
|
|
|
|
|
|
|
compat = xkb->compat;
|
2009-03-19 17:57:01 -06:00
|
|
|
if (freeMap)
|
2009-03-25 16:41:21 -06:00
|
|
|
which = XkbAllCompatMask;
|
|
|
|
|
|
|
|
if (which & XkbGroupCompatMask)
|
2010-06-23 09:25:10 -06:00
|
|
|
bzero(&compat->groups[0], XkbNumKbdGroups * sizeof(XkbcModsRec));
|
2009-03-25 16:41:21 -06:00
|
|
|
|
|
|
|
if (which & XkbSymInterpMask) {
|
|
|
|
if (compat->sym_interpret && (compat->size_si > 0))
|
|
|
|
_XkbFree(compat->sym_interpret);
|
|
|
|
compat->size_si = compat->num_si = 0;
|
|
|
|
compat->sym_interpret = NULL;
|
2009-03-19 17:57:01 -06:00
|
|
|
}
|
2009-03-25 16:41:21 -06:00
|
|
|
|
2009-03-19 17:57:01 -06:00
|
|
|
if (freeMap) {
|
2009-03-25 16:41:21 -06:00
|
|
|
_XkbFree(compat);
|
|
|
|
xkb->compat = NULL;
|
2009-03-19 17:57:01 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2009-03-25 16:41:21 -06:00
|
|
|
XkbcAllocNames(XkbcDescPtr xkb, unsigned which, int nTotalRG, int nTotalAliases)
|
2009-03-19 17:57:01 -06:00
|
|
|
{
|
2010-06-21 07:28:34 -06:00
|
|
|
XkbcNamesPtr names;
|
2009-03-25 16:41:21 -06:00
|
|
|
|
|
|
|
if (!xkb)
|
|
|
|
return BadMatch;
|
|
|
|
|
|
|
|
if (!xkb->names) {
|
2010-06-21 07:28:34 -06:00
|
|
|
xkb->names = _XkbTypedCalloc(1, XkbcNamesRec);
|
2009-03-25 16:41:21 -06:00
|
|
|
if (!xkb->names)
|
|
|
|
return BadAlloc;
|
|
|
|
}
|
|
|
|
names = xkb->names;
|
|
|
|
|
|
|
|
if ((which & XkbKTLevelNamesMask) && xkb->map && xkb->map->types) {
|
|
|
|
int i;
|
2010-06-21 07:28:34 -06:00
|
|
|
XkbcKeyTypePtr type;
|
2009-03-25 16:41:21 -06:00
|
|
|
|
|
|
|
type = xkb->map->types;
|
|
|
|
for (i = 0; i < xkb->map->num_types; i++, type++) {
|
|
|
|
if (!type->level_names) {
|
2010-06-16 20:16:09 -06:00
|
|
|
type->level_names = _XkbTypedCalloc(type->num_levels, CARD32);
|
2009-03-25 16:41:21 -06:00
|
|
|
if (!type->level_names)
|
|
|
|
return BadAlloc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-04 09:52:17 -06:00
|
|
|
if ((which & XkbKeyNamesMask) && !names->keys) {
|
2009-03-25 16:41:21 -06:00
|
|
|
if ((!XkbIsLegalKeycode(xkb->min_key_code)) ||
|
|
|
|
(!XkbIsLegalKeycode(xkb->max_key_code)) ||
|
|
|
|
(xkb->max_key_code < xkb->min_key_code))
|
|
|
|
return BadValue;
|
|
|
|
|
|
|
|
names->keys = _XkbTypedCalloc(xkb->max_key_code + 1, XkbKeyNameRec);
|
|
|
|
if (!names->keys)
|
|
|
|
return BadAlloc;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((which & XkbKeyAliasesMask) && (nTotalAliases > 0)) {
|
|
|
|
if (!names->key_aliases)
|
|
|
|
names->key_aliases = _XkbTypedCalloc(nTotalAliases,
|
|
|
|
XkbKeyAliasRec);
|
|
|
|
else if (nTotalAliases > names->num_key_aliases) {
|
|
|
|
XkbKeyAliasRec *prev_aliases = names->key_aliases;
|
|
|
|
|
|
|
|
names->key_aliases = _XkbTypedRealloc(names->key_aliases,
|
|
|
|
nTotalAliases,
|
|
|
|
XkbKeyAliasRec);
|
|
|
|
if (names->key_aliases)
|
|
|
|
_XkbClearElems(names->key_aliases, names->num_key_aliases,
|
|
|
|
nTotalAliases - 1, XkbKeyAliasRec);
|
|
|
|
else
|
|
|
|
_XkbFree(prev_aliases);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!names->key_aliases) {
|
|
|
|
names->num_key_aliases = 0;
|
|
|
|
return BadAlloc;
|
|
|
|
}
|
|
|
|
|
|
|
|
names->num_key_aliases = nTotalAliases;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((which & XkbRGNamesMask) && (nTotalRG > 0)) {
|
|
|
|
if (!names->radio_groups)
|
2010-06-16 20:16:09 -06:00
|
|
|
names->radio_groups = _XkbTypedCalloc(nTotalRG, CARD32);
|
2009-03-25 16:41:21 -06:00
|
|
|
else if (nTotalRG > names->num_rg) {
|
2010-06-16 20:16:09 -06:00
|
|
|
CARD32 *prev_radio_groups = names->radio_groups;
|
2009-03-25 16:41:21 -06:00
|
|
|
|
|
|
|
names->radio_groups = _XkbTypedRealloc(names->radio_groups,
|
2010-06-16 20:16:09 -06:00
|
|
|
nTotalRG, CARD32);
|
2009-03-25 16:41:21 -06:00
|
|
|
if (names->radio_groups)
|
|
|
|
_XkbClearElems(names->radio_groups, names->num_rg,
|
2010-06-16 20:16:09 -06:00
|
|
|
nTotalRG - 1, CARD32);
|
2009-03-25 16:41:21 -06:00
|
|
|
else
|
|
|
|
_XkbFree(prev_radio_groups);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!names->radio_groups)
|
|
|
|
return BadAlloc;
|
|
|
|
|
|
|
|
names->num_rg = nTotalRG;
|
2009-03-19 17:57:01 -06:00
|
|
|
}
|
2009-03-25 16:41:21 -06:00
|
|
|
|
2009-03-19 17:57:01 -06:00
|
|
|
return Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-03-25 16:41:21 -06:00
|
|
|
XkbcFreeNames(XkbcDescPtr xkb, unsigned which, Bool freeMap)
|
2009-03-19 17:57:01 -06:00
|
|
|
{
|
2010-06-21 07:28:34 -06:00
|
|
|
XkbcNamesPtr names;
|
2009-03-25 16:41:21 -06:00
|
|
|
|
|
|
|
if (!xkb || !xkb->names)
|
|
|
|
return;
|
2009-03-19 17:57:01 -06:00
|
|
|
|
2009-03-25 16:41:21 -06:00
|
|
|
names = xkb->names;
|
2009-03-19 17:57:01 -06:00
|
|
|
if (freeMap)
|
2009-03-25 16:41:21 -06:00
|
|
|
which = XkbAllNamesMask;
|
|
|
|
|
|
|
|
if (which & XkbKTLevelNamesMask) {
|
2010-06-16 20:16:09 -06:00
|
|
|
XkbcClientMapPtr map = xkb->map;
|
2009-03-25 16:41:21 -06:00
|
|
|
|
|
|
|
if (map && map->types) {
|
|
|
|
int i;
|
2010-06-21 07:28:34 -06:00
|
|
|
XkbcKeyTypePtr type = map->types;
|
2009-03-25 16:41:21 -06:00
|
|
|
|
|
|
|
for (i = 0; i < map->num_types; i++, type++) {
|
|
|
|
if (type->level_names) {
|
|
|
|
_XkbFree(type->level_names);
|
|
|
|
type->level_names = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-03-19 17:57:01 -06:00
|
|
|
}
|
2009-03-25 16:41:21 -06:00
|
|
|
|
|
|
|
if ((which & XkbKeyNamesMask) && names->keys) {
|
|
|
|
_XkbFree(names->keys);
|
|
|
|
names->keys = NULL;
|
|
|
|
names->num_keys = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((which & XkbKeyAliasesMask) && names->key_aliases) {
|
|
|
|
_XkbFree(names->key_aliases);
|
|
|
|
names->key_aliases = NULL;
|
|
|
|
names->num_key_aliases = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((which & XkbRGNamesMask) && names->radio_groups) {
|
|
|
|
_XkbFree(names->radio_groups);
|
|
|
|
names->radio_groups = NULL;
|
|
|
|
names->num_rg = 0;
|
|
|
|
}
|
|
|
|
|
2009-03-19 17:57:01 -06:00
|
|
|
if (freeMap) {
|
2009-03-25 16:41:21 -06:00
|
|
|
_XkbFree(names);
|
|
|
|
xkb->names = NULL;
|
2009-03-19 17:57:01 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2009-03-25 16:41:21 -06:00
|
|
|
XkbcAllocControls(XkbcDescPtr xkb, unsigned which)
|
2009-03-19 17:57:01 -06:00
|
|
|
{
|
2009-03-25 16:41:21 -06:00
|
|
|
if (!xkb)
|
|
|
|
return BadMatch;
|
2009-03-19 17:57:01 -06:00
|
|
|
|
2009-03-25 16:41:21 -06:00
|
|
|
if (!xkb->ctrls) {
|
|
|
|
xkb->ctrls = _XkbTypedCalloc(1, XkbControlsRec);
|
|
|
|
if (!xkb->ctrls)
|
|
|
|
return BadAlloc;
|
2009-03-19 17:57:01 -06:00
|
|
|
}
|
2009-03-25 16:41:21 -06:00
|
|
|
|
2009-03-19 17:57:01 -06:00
|
|
|
return Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-03-25 16:41:21 -06:00
|
|
|
XkbcFreeControls(XkbcDescPtr xkb, unsigned which, Bool freeMap)
|
2009-03-19 17:57:01 -06:00
|
|
|
{
|
2009-03-25 16:41:21 -06:00
|
|
|
if (freeMap && xkb && xkb->ctrls) {
|
|
|
|
_XkbFree(xkb->ctrls);
|
|
|
|
xkb->ctrls = NULL;
|
2009-03-19 17:57:01 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
XkbcAllocIndicatorMaps(XkbcDescPtr xkb)
|
|
|
|
{
|
2009-03-25 16:41:21 -06:00
|
|
|
if (!xkb)
|
|
|
|
return BadMatch;
|
|
|
|
|
|
|
|
if (!xkb->indicators) {
|
|
|
|
xkb->indicators = _XkbTypedCalloc(1, XkbIndicatorRec);
|
|
|
|
if (!xkb->indicators)
|
|
|
|
return BadAlloc;
|
2009-03-19 17:57:01 -06:00
|
|
|
}
|
2009-03-25 16:41:21 -06:00
|
|
|
|
2009-03-19 17:57:01 -06:00
|
|
|
return Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
XkbcFreeIndicatorMaps(XkbcDescPtr xkb)
|
|
|
|
{
|
2009-03-25 16:41:21 -06:00
|
|
|
if (xkb && xkb->indicators) {
|
|
|
|
_XkbFree(xkb->indicators);
|
|
|
|
xkb->indicators = NULL;
|
2009-03-19 17:57:01 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-25 16:41:21 -06:00
|
|
|
XkbcDescRec *
|
2009-03-19 17:57:01 -06:00
|
|
|
XkbcAllocKeyboard(void)
|
|
|
|
{
|
2009-03-25 16:41:21 -06:00
|
|
|
XkbcDescRec *xkb;
|
2009-03-19 17:57:01 -06:00
|
|
|
|
2009-03-25 16:41:21 -06:00
|
|
|
xkb = _XkbTypedCalloc(1, XkbcDescRec);
|
2009-03-19 17:57:01 -06:00
|
|
|
if (xkb)
|
2009-03-25 16:41:21 -06:00
|
|
|
xkb->device_spec = XkbUseCoreKbd;
|
2009-03-19 17:57:01 -06:00
|
|
|
return xkb;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-03-25 16:41:21 -06:00
|
|
|
XkbcFreeKeyboard(XkbcDescPtr xkb, unsigned which, Bool freeAll)
|
2009-03-19 17:57:01 -06:00
|
|
|
{
|
2009-03-25 16:41:21 -06:00
|
|
|
if (!xkb)
|
|
|
|
return;
|
|
|
|
|
2009-03-19 17:57:01 -06:00
|
|
|
if (freeAll)
|
2009-03-25 16:41:21 -06:00
|
|
|
which = XkbAllComponentsMask;
|
|
|
|
|
|
|
|
if (which & XkbClientMapMask)
|
|
|
|
XkbcFreeClientMap(xkb, XkbAllClientInfoMask, True);
|
|
|
|
if (which & XkbServerMapMask)
|
|
|
|
XkbcFreeServerMap(xkb, XkbAllServerInfoMask, True);
|
|
|
|
if (which & XkbCompatMapMask)
|
|
|
|
XkbcFreeCompatMap(xkb, XkbAllCompatMask, True);
|
|
|
|
if (which & XkbIndicatorMapMask)
|
|
|
|
XkbcFreeIndicatorMaps(xkb);
|
|
|
|
if (which & XkbNamesMask)
|
|
|
|
XkbcFreeNames(xkb, XkbAllNamesMask, True);
|
|
|
|
if ((which & XkbGeometryMask) && xkb->geom)
|
|
|
|
XkbcFreeGeometry(xkb->geom, XkbGeomAllMask, True);
|
|
|
|
if (which & XkbControlsMask)
|
|
|
|
XkbcFreeControls(xkb, XkbAllControlsMask, True);
|
2009-03-19 17:57:01 -06:00
|
|
|
if (freeAll)
|
2009-03-25 16:41:21 -06:00
|
|
|
_XkbFree(xkb);
|
2009-03-19 17:57:01 -06:00
|
|
|
}
|