malloc/misc/xkb: Coding style cleanup
parent
5315e5d14a
commit
fe94593d02
77
src/malloc.c
77
src/malloc.c
|
@ -230,57 +230,66 @@ XkbcAllocServerMap(XkbcDescPtr xkb, unsigned which, unsigned nNewActions)
|
|||
}
|
||||
|
||||
int
|
||||
XkbcCopyKeyType(XkbKeyTypePtr from,XkbKeyTypePtr into)
|
||||
XkbcCopyKeyType(XkbKeyTypePtr from, XkbKeyTypePtr into)
|
||||
{
|
||||
if ((!from)||(!into))
|
||||
return BadMatch;
|
||||
if (!from || !into)
|
||||
return BadMatch;
|
||||
|
||||
if (into->map) {
|
||||
_XkbFree(into->map);
|
||||
into->map= NULL;
|
||||
_XkbFree(into->map);
|
||||
into->map = NULL;
|
||||
}
|
||||
if (into->preserve) {
|
||||
_XkbFree(into->preserve);
|
||||
into->preserve= NULL;
|
||||
_XkbFree(into->preserve);
|
||||
into->preserve= NULL;
|
||||
}
|
||||
if (into->level_names) {
|
||||
_XkbFree(into->level_names);
|
||||
into->level_names= NULL;
|
||||
_XkbFree(into->level_names);
|
||||
into->level_names = NULL;
|
||||
}
|
||||
*into= *from;
|
||||
if ((from->map)&&(into->map_count>0)) {
|
||||
into->map= _XkbTypedCalloc(into->map_count,XkbKTMapEntryRec);
|
||||
if (!into->map)
|
||||
return BadAlloc;
|
||||
memcpy(into->map,from->map,into->map_count*sizeof(XkbKTMapEntryRec));
|
||||
|
||||
*into = *from;
|
||||
|
||||
if (from->map && (into->map_count > 0)) {
|
||||
into->map = _XkbTypedCalloc(into->map_count, XkbKTMapEntryRec);
|
||||
if (!into->map)
|
||||
return BadAlloc;
|
||||
memcpy(into->map, from->map,
|
||||
into->map_count * sizeof(XkbKTMapEntryRec));
|
||||
}
|
||||
if ((from->preserve)&&(into->map_count>0)) {
|
||||
into->preserve= _XkbTypedCalloc(into->map_count,XkbModsRec);
|
||||
if (!into->preserve)
|
||||
return BadAlloc;
|
||||
memcpy(into->preserve,from->preserve,
|
||||
into->map_count*sizeof(XkbModsRec));
|
||||
|
||||
if (from->preserve && (into->map_count > 0)) {
|
||||
into->preserve = _XkbTypedCalloc(into->map_count, XkbModsRec);
|
||||
if (!into->preserve)
|
||||
return BadAlloc;
|
||||
memcpy(into->preserve, from->preserve,
|
||||
into->map_count * sizeof(XkbModsRec));
|
||||
}
|
||||
if ((from->level_names)&&(into->num_levels>0)) {
|
||||
into->level_names= _XkbTypedCalloc(into->num_levels,Atom);
|
||||
if (!into->level_names)
|
||||
return BadAlloc;
|
||||
memcpy(into->level_names,from->level_names,
|
||||
into->num_levels*sizeof(Atom));
|
||||
|
||||
if (from->level_names && (into->num_levels > 0)) {
|
||||
into->level_names = _XkbTypedCalloc(into->num_levels, Atom);
|
||||
if (!into->level_names)
|
||||
return BadAlloc;
|
||||
memcpy(into->level_names, from->level_names,
|
||||
into->num_levels * sizeof(Atom));
|
||||
}
|
||||
|
||||
return Success;
|
||||
}
|
||||
|
||||
int
|
||||
XkbcCopyKeyTypes(XkbKeyTypePtr from,XkbKeyTypePtr into,int num_types)
|
||||
XkbcCopyKeyTypes(XkbKeyTypePtr from, XkbKeyTypePtr into, int num_types)
|
||||
{
|
||||
register int i,rtrn;
|
||||
int i, rtrn;
|
||||
|
||||
if ((!from)||(!into)||(num_types<0))
|
||||
return BadMatch;
|
||||
for (i=0;i<num_types;i++) {
|
||||
if ((rtrn= XkbcCopyKeyType(from++,into++))!=Success)
|
||||
return rtrn;
|
||||
if (!from || !into || (num_types < 0))
|
||||
return BadMatch;
|
||||
|
||||
for (i = 0; i < num_types; i++) {
|
||||
if ((rtrn = XkbcCopyKeyType(from++, into++)) != Success)
|
||||
return rtrn;
|
||||
}
|
||||
|
||||
return Success;
|
||||
}
|
||||
|
||||
|
|
189
src/misc.c
189
src/misc.c
|
@ -31,117 +31,132 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include "X11/extensions/XKBcommon.h"
|
||||
#include "XKBcommonint.h"
|
||||
|
||||
#define mapSize(m) (sizeof(m)/sizeof(XkbKTMapEntryRec))
|
||||
static XkbKTMapEntryRec map2Level[]= {
|
||||
{ True, ShiftMask, {1, ShiftMask, 0} }
|
||||
#define mapSize(m) (sizeof(m) / sizeof(XkbKTMapEntryRec))
|
||||
static XkbKTMapEntryRec map2Level[]= {
|
||||
{ True, ShiftMask, {1, ShiftMask, 0} }
|
||||
};
|
||||
|
||||
static XkbKTMapEntryRec mapAlpha[]= {
|
||||
{ True, ShiftMask, { 1, ShiftMask, 0 } },
|
||||
{ True, LockMask, { 0, LockMask, 0 } }
|
||||
static XkbKTMapEntryRec mapAlpha[]= {
|
||||
{ True, ShiftMask, { 1, ShiftMask, 0 } },
|
||||
{ True, LockMask, { 0, LockMask, 0 } }
|
||||
};
|
||||
|
||||
static XkbModsRec preAlpha[]= {
|
||||
{ 0, 0, 0 },
|
||||
{ LockMask, LockMask, 0 }
|
||||
static XkbModsRec preAlpha[]= {
|
||||
{ 0, 0, 0 },
|
||||
{ LockMask, LockMask, 0 }
|
||||
};
|
||||
|
||||
#define NL_VMOD_MASK 0
|
||||
#define NL_VMOD_MASK 0
|
||||
static XkbKTMapEntryRec mapKeypad[]= {
|
||||
{ True, ShiftMask, { 1, ShiftMask, 0 } },
|
||||
{ False, 0, { 1, 0, NL_VMOD_MASK } }
|
||||
{ True, ShiftMask, { 1, ShiftMask, 0 } },
|
||||
{ False, 0, { 1, 0, NL_VMOD_MASK } }
|
||||
};
|
||||
|
||||
static XkbKeyTypeRec canonicalTypes[XkbNumRequiredTypes] = {
|
||||
{ { 0, 0, 0 },
|
||||
1, /* num_levels */
|
||||
0, /* map_count */
|
||||
NULL, NULL,
|
||||
None, NULL
|
||||
},
|
||||
{ { ShiftMask, ShiftMask, 0 },
|
||||
2, /* num_levels */
|
||||
mapSize(map2Level), /* map_count */
|
||||
map2Level, NULL,
|
||||
None, NULL
|
||||
},
|
||||
{ { ShiftMask|LockMask, ShiftMask|LockMask, 0 },
|
||||
2, /* num_levels */
|
||||
mapSize(mapAlpha), /* map_count */
|
||||
mapAlpha, preAlpha,
|
||||
None, NULL
|
||||
},
|
||||
{ { ShiftMask, ShiftMask, NL_VMOD_MASK },
|
||||
2, /* num_levels */
|
||||
mapSize(mapKeypad), /* map_count */
|
||||
mapKeypad, NULL,
|
||||
None, NULL
|
||||
}
|
||||
static XkbKeyTypeRec canonicalTypes[XkbNumRequiredTypes] = {
|
||||
{ { 0, 0, 0 },
|
||||
1, /* num_levels */
|
||||
0, /* map_count */
|
||||
NULL, NULL,
|
||||
None, NULL
|
||||
},
|
||||
{ { ShiftMask, ShiftMask, 0 },
|
||||
2, /* num_levels */
|
||||
mapSize(map2Level), /* map_count */
|
||||
map2Level, NULL,
|
||||
None, NULL
|
||||
},
|
||||
{ { ShiftMask|LockMask, ShiftMask|LockMask, 0 },
|
||||
2, /* num_levels */
|
||||
mapSize(mapAlpha), /* map_count */
|
||||
mapAlpha, preAlpha,
|
||||
None, NULL
|
||||
},
|
||||
{ { ShiftMask, ShiftMask, NL_VMOD_MASK },
|
||||
2, /* num_levels */
|
||||
mapSize(mapKeypad), /* map_count */
|
||||
mapKeypad, NULL,
|
||||
None, NULL
|
||||
}
|
||||
};
|
||||
|
||||
int
|
||||
XkbcInitCanonicalKeyTypes(XkbcDescPtr xkb,unsigned which,int keypadVMod)
|
||||
XkbcInitCanonicalKeyTypes(XkbcDescPtr xkb, unsigned which, int keypadVMod)
|
||||
{
|
||||
XkbClientMapPtr map;
|
||||
XkbKeyTypePtr from,to;
|
||||
int rtrn;
|
||||
XkbClientMapPtr map;
|
||||
XkbKeyTypePtr from,to;
|
||||
int rtrn;
|
||||
|
||||
if (!xkb)
|
||||
return BadMatch;
|
||||
rtrn= XkbcAllocClientMap(xkb,XkbKeyTypesMask,XkbNumRequiredTypes);
|
||||
if (rtrn!=Success)
|
||||
return rtrn;
|
||||
return BadMatch;
|
||||
|
||||
rtrn= XkbcAllocClientMap(xkb, XkbKeyTypesMask, XkbNumRequiredTypes);
|
||||
if (rtrn != Success)
|
||||
return rtrn;
|
||||
|
||||
map= xkb->map;
|
||||
if ((which&XkbAllRequiredTypes)==0)
|
||||
return Success;
|
||||
rtrn= Success;
|
||||
from= canonicalTypes;
|
||||
to= map->types;
|
||||
if (which&XkbOneLevelMask)
|
||||
rtrn= XkbcCopyKeyType(&from[XkbOneLevelIndex],&to[XkbOneLevelIndex]);
|
||||
if ((which&XkbTwoLevelMask)&&(rtrn==Success))
|
||||
rtrn= XkbcCopyKeyType(&from[XkbTwoLevelIndex],&to[XkbTwoLevelIndex]);
|
||||
if ((which&XkbAlphabeticMask)&&(rtrn==Success))
|
||||
rtrn= XkbcCopyKeyType(&from[XkbAlphabeticIndex],&to[XkbAlphabeticIndex]);
|
||||
if ((which&XkbKeypadMask)&&(rtrn==Success)) {
|
||||
XkbKeyTypePtr type;
|
||||
rtrn= XkbcCopyKeyType(&from[XkbKeypadIndex],&to[XkbKeypadIndex]);
|
||||
type= &to[XkbKeypadIndex];
|
||||
if ((keypadVMod>=0)&&(keypadVMod<XkbNumVirtualMods)&&(rtrn==Success)) {
|
||||
type->mods.vmods= (1<<keypadVMod);
|
||||
type->map[0].active= True;
|
||||
type->map[0].mods.mask= ShiftMask;
|
||||
type->map[0].mods.real_mods= ShiftMask;
|
||||
type->map[0].mods.vmods= 0;
|
||||
type->map[0].level= 1;
|
||||
type->map[1].active= False;
|
||||
type->map[1].mods.mask= 0;
|
||||
type->map[1].mods.real_mods= 0;
|
||||
type->map[1].mods.vmods= (1<<keypadVMod);
|
||||
type->map[1].level= 1;
|
||||
}
|
||||
if ((which & XkbAllRequiredTypes) == 0)
|
||||
return Success;
|
||||
|
||||
rtrn = Success;
|
||||
from = canonicalTypes;
|
||||
to = map->types;
|
||||
|
||||
if (which & XkbOneLevelMask)
|
||||
rtrn = XkbcCopyKeyType(&from[XkbOneLevelIndex], &to[XkbOneLevelIndex]);
|
||||
|
||||
if ((which & XkbTwoLevelMask) && (rtrn == Success))
|
||||
rtrn = XkbcCopyKeyType(&from[XkbTwoLevelIndex], &to[XkbTwoLevelIndex]);
|
||||
|
||||
if ((which & XkbAlphabeticMask) && (rtrn == Success))
|
||||
rtrn = XkbcCopyKeyType(&from[XkbAlphabeticIndex],
|
||||
&to[XkbAlphabeticIndex]);
|
||||
|
||||
if ((which & XkbKeypadMask) && (rtrn == Success)) {
|
||||
XkbKeyTypePtr type;
|
||||
|
||||
rtrn = XkbcCopyKeyType(&from[XkbKeypadIndex], &to[XkbKeypadIndex]);
|
||||
type = &to[XkbKeypadIndex];
|
||||
|
||||
if ((keypadVMod >= 0) && (keypadVMod < XkbNumVirtualMods) &&
|
||||
(rtrn == Success)) {
|
||||
type->mods.vmods = (1 << keypadVMod);
|
||||
type->map[0].active = True;
|
||||
type->map[0].mods.mask = ShiftMask;
|
||||
type->map[0].mods.real_mods = ShiftMask;
|
||||
type->map[0].mods.vmods = 0;
|
||||
type->map[0].level = 1;
|
||||
type->map[1].active = False;
|
||||
type->map[1].mods.mask = 0;
|
||||
type->map[1].mods.real_mods = 0;
|
||||
type->map[1].mods.vmods = (1 << keypadVMod);
|
||||
type->map[1].level = 1;
|
||||
}
|
||||
}
|
||||
|
||||
return Success;
|
||||
}
|
||||
|
||||
Bool
|
||||
XkbcVirtualModsToReal(XkbcDescPtr xkb,unsigned virtual_mask,unsigned *mask_rtrn)
|
||||
XkbcVirtualModsToReal(XkbcDescPtr xkb, unsigned virtual_mask,
|
||||
unsigned *mask_rtrn)
|
||||
{
|
||||
register int i,bit;
|
||||
register unsigned mask;
|
||||
int i, bit;
|
||||
unsigned mask;
|
||||
|
||||
if (xkb==NULL)
|
||||
return False;
|
||||
if (virtual_mask==0) {
|
||||
*mask_rtrn= 0;
|
||||
return True;
|
||||
if (!xkb)
|
||||
return False;
|
||||
if (virtual_mask == 0) {
|
||||
*mask_rtrn = 0;
|
||||
return True;
|
||||
}
|
||||
if (xkb->server==NULL)
|
||||
return False;
|
||||
for (i=mask=0,bit=1;i<XkbNumVirtualMods;i++,bit<<=1) {
|
||||
if (virtual_mask&bit)
|
||||
mask|= xkb->server->vmods[i];
|
||||
if (!xkb->server)
|
||||
return False;
|
||||
|
||||
for (i = mask = 0, bit = 1; i < XkbNumVirtualMods; i++, bit <<= 1) {
|
||||
if (virtual_mask & bit)
|
||||
mask |= xkb->server->vmods[i];
|
||||
}
|
||||
*mask_rtrn= mask;
|
||||
|
||||
*mask_rtrn = mask;
|
||||
return True;
|
||||
}
|
||||
|
|
71
src/xkb.c
71
src/xkb.c
|
@ -32,47 +32,46 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include "XKBcommonint.h"
|
||||
|
||||
Bool
|
||||
XkbcComputeEffectiveMap( XkbcDescPtr xkb,
|
||||
XkbKeyTypePtr type,
|
||||
unsigned char * map_rtrn)
|
||||
XkbcComputeEffectiveMap(XkbcDescPtr xkb, XkbKeyTypePtr type,
|
||||
unsigned char *map_rtrn)
|
||||
{
|
||||
register int i;
|
||||
unsigned tmp;
|
||||
XkbKTMapEntryPtr entry = NULL;
|
||||
int i;
|
||||
unsigned tmp;
|
||||
XkbKTMapEntryPtr entry = NULL;
|
||||
|
||||
if ((!xkb)||(!type)||(!xkb->server))
|
||||
return False;
|
||||
if (!xkb || !type || !xkb->server)
|
||||
return False;
|
||||
|
||||
if (type->mods.vmods!=0) {
|
||||
if (!XkbcVirtualModsToReal(xkb,type->mods.vmods,&tmp))
|
||||
return False;
|
||||
if (type->mods.vmods != 0) {
|
||||
if (!XkbcVirtualModsToReal(xkb, type->mods.vmods, &tmp))
|
||||
return False;
|
||||
|
||||
type->mods.mask= tmp|type->mods.real_mods;
|
||||
entry= type->map;
|
||||
for (i=0;i<type->map_count;i++,entry++) {
|
||||
tmp= 0;
|
||||
if (entry->mods.vmods!=0) {
|
||||
if (!XkbcVirtualModsToReal(xkb,entry->mods.vmods,&tmp))
|
||||
return False;
|
||||
if (tmp==0) {
|
||||
entry->active= False;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
entry->active= True;
|
||||
entry->mods.mask= (entry->mods.real_mods|tmp)&type->mods.mask;
|
||||
}
|
||||
type->mods.mask = tmp | type->mods.real_mods;
|
||||
entry = type->map;
|
||||
for (i = 0; i < type->map_count; i++, entry++) {
|
||||
tmp = 0;
|
||||
if (entry->mods.vmods != 0) {
|
||||
if (!XkbcVirtualModsToReal(xkb, entry->mods.vmods, &tmp))
|
||||
return False;
|
||||
if (tmp == 0) {
|
||||
entry->active = False;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
entry->active = True;
|
||||
entry->mods.mask = (entry->mods.real_mods | tmp) & type->mods.mask;
|
||||
}
|
||||
}
|
||||
else {
|
||||
type->mods.mask= type->mods.real_mods;
|
||||
}
|
||||
if (map_rtrn!=NULL) {
|
||||
bzero(map_rtrn,type->mods.mask+1);
|
||||
for (i=0;i<type->map_count;i++) {
|
||||
if (entry->active) {
|
||||
map_rtrn[type->map[i].mods.mask]= type->map[i].level;
|
||||
}
|
||||
}
|
||||
else
|
||||
type->mods.mask = type->mods.real_mods;
|
||||
|
||||
if (map_rtrn) {
|
||||
bzero(map_rtrn, type->mods.mask + 1);
|
||||
for (i = 0; i < type->map_count; i++) {
|
||||
if (entry->active)
|
||||
map_rtrn[type->map[i].mods.mask] = type->map[i].level;
|
||||
}
|
||||
}
|
||||
|
||||
return True;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue