2006-11-26 11:13:41 -07: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_DIX_CONFIG_H
|
|
|
|
#include <dix-config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <X11/X.h>
|
|
|
|
#include <X11/Xproto.h>
|
|
|
|
#include "misc.h"
|
|
|
|
#include "inputstr.h"
|
2007-11-24 10:55:21 -07:00
|
|
|
#include <xkbsrv.h>
|
2008-11-02 08:26:08 -07:00
|
|
|
#include "xkbgeom.h"
|
2010-07-27 13:02:24 -06:00
|
|
|
#include <os.h>
|
|
|
|
#include <string.h>
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
/***===================================================================***/
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
Status
|
|
|
|
XkbAllocCompatMap(XkbDescPtr xkb,unsigned which,unsigned nSI)
|
|
|
|
{
|
|
|
|
XkbCompatMapPtr compat;
|
|
|
|
XkbSymInterpretRec *prev_interpret;
|
|
|
|
|
|
|
|
if (!xkb)
|
|
|
|
return BadMatch;
|
|
|
|
if (xkb->compat) {
|
|
|
|
if (xkb->compat->size_si>=nSI)
|
|
|
|
return Success;
|
|
|
|
compat= xkb->compat;
|
|
|
|
compat->size_si= nSI;
|
|
|
|
if (compat->sym_interpret==NULL)
|
|
|
|
compat->num_si= 0;
|
|
|
|
prev_interpret = compat->sym_interpret;
|
2010-12-05 08:36:02 -07:00
|
|
|
compat->sym_interpret= realloc(compat->sym_interpret,
|
2010-07-27 13:02:24 -06:00
|
|
|
nSI * sizeof(XkbSymInterpretRec));
|
2006-11-26 11:13:41 -07:00
|
|
|
if (compat->sym_interpret==NULL) {
|
2010-12-05 08:36:02 -07:00
|
|
|
free(prev_interpret);
|
2006-11-26 11:13:41 -07:00
|
|
|
compat->size_si= compat->num_si= 0;
|
|
|
|
return BadAlloc;
|
|
|
|
}
|
|
|
|
if (compat->num_si!=0) {
|
2010-07-27 13:02:24 -06:00
|
|
|
memset(&compat->sym_interpret[compat->num_si], 0,
|
|
|
|
(compat->size_si - compat->num_si) * sizeof(XkbSymInterpretRec));
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
return Success;
|
|
|
|
}
|
2010-12-05 08:36:02 -07:00
|
|
|
compat= calloc(1, sizeof(XkbCompatMapRec));
|
2006-11-26 11:13:41 -07:00
|
|
|
if (compat==NULL)
|
|
|
|
return BadAlloc;
|
|
|
|
if (nSI>0) {
|
2010-12-05 08:36:02 -07:00
|
|
|
compat->sym_interpret= calloc(nSI, sizeof(XkbSymInterpretRec));
|
2006-11-26 11:13:41 -07:00
|
|
|
if (!compat->sym_interpret) {
|
2010-12-05 08:36:02 -07:00
|
|
|
free(compat);
|
2006-11-26 11:13:41 -07:00
|
|
|
return BadAlloc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
compat->size_si= nSI;
|
|
|
|
compat->num_si= 0;
|
2010-12-05 08:36:02 -07:00
|
|
|
memset((char *)&compat->groups[0], 0, XkbNumKbdGroups*sizeof(XkbModsRec));
|
2006-11-26 11:13:41 -07:00
|
|
|
xkb->compat= compat;
|
|
|
|
return Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
XkbFreeCompatMap(XkbDescPtr xkb,unsigned which,Bool freeMap)
|
|
|
|
{
|
|
|
|
register XkbCompatMapPtr compat;
|
|
|
|
|
|
|
|
if ((xkb==NULL)||(xkb->compat==NULL))
|
|
|
|
return;
|
|
|
|
compat= xkb->compat;
|
|
|
|
if (freeMap)
|
|
|
|
which= XkbAllCompatMask;
|
|
|
|
if (which&XkbGroupCompatMask)
|
2010-12-05 08:36:02 -07:00
|
|
|
memset((char *)&compat->groups[0], 0, XkbNumKbdGroups*sizeof(XkbModsRec));
|
2006-11-26 11:13:41 -07:00
|
|
|
if (which&XkbSymInterpMask) {
|
|
|
|
if ((compat->sym_interpret)&&(compat->size_si>0))
|
2010-12-05 08:36:02 -07:00
|
|
|
free(compat->sym_interpret);
|
2006-11-26 11:13:41 -07:00
|
|
|
compat->size_si= compat->num_si= 0;
|
|
|
|
compat->sym_interpret= NULL;
|
|
|
|
}
|
|
|
|
if (freeMap) {
|
2010-12-05 08:36:02 -07:00
|
|
|
free(compat);
|
2006-11-26 11:13:41 -07:00
|
|
|
xkb->compat= NULL;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***===================================================================***/
|
|
|
|
|
|
|
|
Status
|
|
|
|
XkbAllocNames(XkbDescPtr xkb,unsigned which,int nTotalRG,int nTotalAliases)
|
|
|
|
{
|
|
|
|
XkbNamesPtr names;
|
|
|
|
|
|
|
|
if (xkb==NULL)
|
|
|
|
return BadMatch;
|
|
|
|
if (xkb->names==NULL) {
|
2010-12-05 08:36:02 -07:00
|
|
|
xkb->names = calloc(1, sizeof(XkbNamesRec));
|
2006-11-26 11:13:41 -07:00
|
|
|
if (xkb->names==NULL)
|
|
|
|
return BadAlloc;
|
|
|
|
}
|
|
|
|
names= xkb->names;
|
|
|
|
if ((which&XkbKTLevelNamesMask)&&(xkb->map!=NULL)&&(xkb->map->types!=NULL)){
|
|
|
|
register int i;
|
|
|
|
XkbKeyTypePtr type;
|
|
|
|
|
|
|
|
type= xkb->map->types;
|
|
|
|
for (i=0;i<xkb->map->num_types;i++,type++) {
|
|
|
|
if (type->level_names==NULL) {
|
2010-12-05 08:36:02 -07:00
|
|
|
type->level_names= calloc(type->num_levels, sizeof(Atom));
|
2006-11-26 11:13:41 -07:00
|
|
|
if (type->level_names==NULL)
|
|
|
|
return BadAlloc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((which&XkbKeyNamesMask)&&(names->keys==NULL)) {
|
|
|
|
if ((!XkbIsLegalKeycode(xkb->min_key_code))||
|
|
|
|
(!XkbIsLegalKeycode(xkb->max_key_code))||
|
|
|
|
(xkb->max_key_code<xkb->min_key_code))
|
|
|
|
return BadValue;
|
2010-12-05 08:36:02 -07:00
|
|
|
names->keys= calloc((xkb->max_key_code+1), sizeof(XkbKeyNameRec));
|
2006-11-26 11:13:41 -07:00
|
|
|
if (names->keys==NULL)
|
|
|
|
return BadAlloc;
|
|
|
|
}
|
|
|
|
if ((which&XkbKeyAliasesMask)&&(nTotalAliases>0)) {
|
|
|
|
if (names->key_aliases==NULL) {
|
2010-12-05 08:36:02 -07:00
|
|
|
names->key_aliases= calloc(nTotalAliases, sizeof(XkbKeyAliasRec));
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
else if (nTotalAliases>names->num_key_aliases) {
|
|
|
|
XkbKeyAliasRec *prev_aliases = names->key_aliases;
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
names->key_aliases= realloc(names->key_aliases,
|
2010-07-27 13:02:24 -06:00
|
|
|
nTotalAliases * sizeof(XkbKeyAliasRec));
|
2006-11-26 11:13:41 -07:00
|
|
|
if (names->key_aliases!=NULL) {
|
2010-07-27 13:02:24 -06:00
|
|
|
memset(&names->key_aliases[names->num_key_aliases], 0,
|
|
|
|
(nTotalAliases - names->num_key_aliases) * sizeof(XkbKeyAliasRec));
|
2006-11-26 11:13:41 -07:00
|
|
|
} else {
|
2010-12-05 08:36:02 -07:00
|
|
|
free(prev_aliases);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (names->key_aliases==NULL) {
|
|
|
|
names->num_key_aliases= 0;
|
|
|
|
return BadAlloc;
|
|
|
|
}
|
|
|
|
names->num_key_aliases= nTotalAliases;
|
|
|
|
}
|
|
|
|
if ((which&XkbRGNamesMask)&&(nTotalRG>0)) {
|
|
|
|
if (names->radio_groups==NULL) {
|
2010-12-05 08:36:02 -07:00
|
|
|
names->radio_groups= calloc(nTotalRG, sizeof(Atom));
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
else if (nTotalRG>names->num_rg) {
|
|
|
|
Atom *prev_radio_groups = names->radio_groups;
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
names->radio_groups= realloc(names->radio_groups,
|
2010-07-27 13:02:24 -06:00
|
|
|
nTotalRG * sizeof(Atom));
|
2006-11-26 11:13:41 -07:00
|
|
|
if (names->radio_groups!=NULL) {
|
2010-07-27 13:02:24 -06:00
|
|
|
memset(&names->radio_groups[names->num_rg], 0,
|
|
|
|
(nTotalRG - names->num_rg) * sizeof(Atom));
|
2006-11-26 11:13:41 -07:00
|
|
|
} else {
|
2010-12-05 08:36:02 -07:00
|
|
|
free(prev_radio_groups);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (names->radio_groups==NULL)
|
|
|
|
return BadAlloc;
|
|
|
|
names->num_rg= nTotalRG;
|
|
|
|
}
|
|
|
|
return Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
XkbFreeNames(XkbDescPtr xkb,unsigned which,Bool freeMap)
|
|
|
|
{
|
|
|
|
XkbNamesPtr names;
|
|
|
|
|
|
|
|
if ((xkb==NULL)||(xkb->names==NULL))
|
|
|
|
return;
|
|
|
|
names= xkb->names;
|
|
|
|
if (freeMap)
|
|
|
|
which= XkbAllNamesMask;
|
|
|
|
if (which&XkbKTLevelNamesMask) {
|
|
|
|
XkbClientMapPtr map= xkb->map;
|
|
|
|
if ((map!=NULL)&&(map->types!=NULL)) {
|
|
|
|
register int i;
|
|
|
|
register XkbKeyTypePtr type;
|
|
|
|
type= map->types;
|
|
|
|
for (i=0;i<map->num_types;i++,type++) {
|
|
|
|
if (type->level_names!=NULL) {
|
2010-12-05 08:36:02 -07:00
|
|
|
free(type->level_names);
|
2006-11-26 11:13:41 -07:00
|
|
|
type->level_names= NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((which&XkbKeyNamesMask)&&(names->keys!=NULL)) {
|
2010-12-05 08:36:02 -07:00
|
|
|
free(names->keys);
|
2006-11-26 11:13:41 -07:00
|
|
|
names->keys= NULL;
|
|
|
|
names->num_keys= 0;
|
|
|
|
}
|
|
|
|
if ((which&XkbKeyAliasesMask)&&(names->key_aliases)){
|
2010-12-05 08:36:02 -07:00
|
|
|
free(names->key_aliases);
|
2006-11-26 11:13:41 -07:00
|
|
|
names->key_aliases=NULL;
|
|
|
|
names->num_key_aliases=0;
|
|
|
|
}
|
|
|
|
if ((which&XkbRGNamesMask)&&(names->radio_groups)) {
|
2010-12-05 08:36:02 -07:00
|
|
|
free(names->radio_groups);
|
2006-11-26 11:13:41 -07:00
|
|
|
names->radio_groups= NULL;
|
|
|
|
names->num_rg= 0;
|
|
|
|
}
|
|
|
|
if (freeMap) {
|
2010-12-05 08:36:02 -07:00
|
|
|
free(names);
|
2006-11-26 11:13:41 -07:00
|
|
|
xkb->names= NULL;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***===================================================================***/
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
Status
|
|
|
|
XkbAllocControls(XkbDescPtr xkb,unsigned which)
|
|
|
|
{
|
|
|
|
if (xkb==NULL)
|
|
|
|
return BadMatch;
|
|
|
|
|
|
|
|
if (xkb->ctrls==NULL) {
|
2010-12-05 08:36:02 -07:00
|
|
|
xkb->ctrls= calloc(1, sizeof(XkbControlsRec));
|
2006-11-26 11:13:41 -07:00
|
|
|
if (!xkb->ctrls)
|
|
|
|
return BadAlloc;
|
|
|
|
}
|
|
|
|
return Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
2007-11-24 10:55:21 -07:00
|
|
|
static void
|
2006-11-26 11:13:41 -07:00
|
|
|
XkbFreeControls(XkbDescPtr xkb,unsigned which,Bool freeMap)
|
|
|
|
{
|
|
|
|
if (freeMap && (xkb!=NULL) && (xkb->ctrls!=NULL)) {
|
2010-12-05 08:36:02 -07:00
|
|
|
free(xkb->ctrls);
|
2006-11-26 11:13:41 -07:00
|
|
|
xkb->ctrls= NULL;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***===================================================================***/
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
Status
|
2006-11-26 11:13:41 -07:00
|
|
|
XkbAllocIndicatorMaps(XkbDescPtr xkb)
|
|
|
|
{
|
|
|
|
if (xkb==NULL)
|
|
|
|
return BadMatch;
|
|
|
|
if (xkb->indicators==NULL) {
|
2010-12-05 08:36:02 -07:00
|
|
|
xkb->indicators= calloc(1, sizeof(XkbIndicatorRec));
|
2006-11-26 11:13:41 -07:00
|
|
|
if (!xkb->indicators)
|
|
|
|
return BadAlloc;
|
|
|
|
}
|
|
|
|
return Success;
|
|
|
|
}
|
|
|
|
|
2007-11-24 10:55:21 -07:00
|
|
|
static void
|
2006-11-26 11:13:41 -07:00
|
|
|
XkbFreeIndicatorMaps(XkbDescPtr xkb)
|
|
|
|
{
|
|
|
|
if ((xkb!=NULL)&&(xkb->indicators!=NULL)) {
|
2010-12-05 08:36:02 -07:00
|
|
|
free(xkb->indicators);
|
2006-11-26 11:13:41 -07:00
|
|
|
xkb->indicators= NULL;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***====================================================================***/
|
|
|
|
|
|
|
|
XkbDescRec *
|
|
|
|
XkbAllocKeyboard(void)
|
|
|
|
{
|
|
|
|
XkbDescRec *xkb;
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
xkb = calloc(1, sizeof(XkbDescRec));
|
2006-11-26 11:13:41 -07:00
|
|
|
if (xkb)
|
|
|
|
xkb->device_spec= XkbUseCoreKbd;
|
|
|
|
return xkb;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
XkbFreeKeyboard(XkbDescPtr xkb,unsigned which,Bool freeAll)
|
|
|
|
{
|
|
|
|
if (xkb==NULL)
|
|
|
|
return;
|
|
|
|
if (freeAll)
|
|
|
|
which= XkbAllComponentsMask;
|
|
|
|
if (which&XkbClientMapMask)
|
2010-07-27 13:02:24 -06:00
|
|
|
XkbFreeClientMap(xkb,XkbAllClientInfoMask,TRUE);
|
2006-11-26 11:13:41 -07:00
|
|
|
if (which&XkbServerMapMask)
|
2010-07-27 13:02:24 -06:00
|
|
|
XkbFreeServerMap(xkb,XkbAllServerInfoMask,TRUE);
|
2006-11-26 11:13:41 -07:00
|
|
|
if (which&XkbCompatMapMask)
|
2010-07-27 13:02:24 -06:00
|
|
|
XkbFreeCompatMap(xkb,XkbAllCompatMask,TRUE);
|
2006-11-26 11:13:41 -07:00
|
|
|
if (which&XkbIndicatorMapMask)
|
|
|
|
XkbFreeIndicatorMaps(xkb);
|
|
|
|
if (which&XkbNamesMask)
|
2010-07-27 13:02:24 -06:00
|
|
|
XkbFreeNames(xkb,XkbAllNamesMask,TRUE);
|
2007-11-24 10:55:21 -07:00
|
|
|
if ((which&XkbGeometryMask) && (xkb->geom!=NULL)) {
|
2010-07-27 13:02:24 -06:00
|
|
|
XkbFreeGeometry(xkb->geom,XkbGeomAllMask,TRUE);
|
2007-11-24 10:55:21 -07:00
|
|
|
/* PERHAPS BONGHITS etc */
|
|
|
|
xkb->geom = NULL;
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
if (which&XkbControlsMask)
|
2010-07-27 13:02:24 -06:00
|
|
|
XkbFreeControls(xkb,XkbAllControlsMask,TRUE);
|
2006-11-26 11:13:41 -07:00
|
|
|
if (freeAll)
|
2010-12-05 08:36:02 -07:00
|
|
|
free(xkb);
|
2006-11-26 11:13:41 -07:00
|
|
|
return;
|
|
|
|
}
|