xkbcomp: seperate keymap-copying code from Compile functions
Signed-off-by: Ran Benita <ran234@gmail.com>master
parent
6738d30036
commit
eaa50c450b
|
@ -1006,7 +1006,7 @@ CopyInterps(CompatInfo *info, bool needSymbol, unsigned pred)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static void
|
||||||
CopyIndicatorMapDefs(CompatInfo *info)
|
CopyIndicatorMapDefs(CompatInfo *info)
|
||||||
{
|
{
|
||||||
LEDInfo *led;
|
LEDInfo *led;
|
||||||
|
@ -1066,6 +1066,25 @@ CopyIndicatorMapDefs(CompatInfo *info)
|
||||||
im->mods.mods = led->mods;
|
im->mods.mods = led->mods;
|
||||||
im->ctrls = led->ctrls;
|
im->ctrls = led->ctrls;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
CopyCompatToKeymap(struct xkb_keymap *keymap, CompatInfo *info)
|
||||||
|
{
|
||||||
|
keymap->compat_section_name = strdup_safe(info->name);
|
||||||
|
|
||||||
|
if (!darray_empty(info->interps)) {
|
||||||
|
CopyInterps(info, true, XkbSI_Exactly);
|
||||||
|
CopyInterps(info, true, XkbSI_AllOf | XkbSI_NoneOf);
|
||||||
|
CopyInterps(info, true, XkbSI_AnyOf);
|
||||||
|
CopyInterps(info, true, XkbSI_AnyOfOrNone);
|
||||||
|
CopyInterps(info, false, XkbSI_Exactly);
|
||||||
|
CopyInterps(info, false, XkbSI_AllOf | XkbSI_NoneOf);
|
||||||
|
CopyInterps(info, false, XkbSI_AnyOf);
|
||||||
|
CopyInterps(info, false, XkbSI_AnyOfOrNone);
|
||||||
|
}
|
||||||
|
|
||||||
|
CopyIndicatorMapDefs(info);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1081,26 +1100,11 @@ CompileCompatMap(XkbFile *file, struct xkb_keymap *keymap,
|
||||||
info.ledDflt.merge = merge;
|
info.ledDflt.merge = merge;
|
||||||
|
|
||||||
HandleCompatMapFile(&info, file, merge);
|
HandleCompatMapFile(&info, file, merge);
|
||||||
|
|
||||||
if (info.errorCount != 0)
|
if (info.errorCount != 0)
|
||||||
goto err_info;
|
goto err_info;
|
||||||
|
|
||||||
if (info.name)
|
if (!CopyCompatToKeymap(keymap, &info))
|
||||||
keymap->compat_section_name = strdup(info.name);
|
goto err_info;
|
||||||
|
|
||||||
if (!darray_empty(info.interps)) {
|
|
||||||
CopyInterps(&info, true, XkbSI_Exactly);
|
|
||||||
CopyInterps(&info, true, XkbSI_AllOf | XkbSI_NoneOf);
|
|
||||||
CopyInterps(&info, true, XkbSI_AnyOf);
|
|
||||||
CopyInterps(&info, true, XkbSI_AnyOfOrNone);
|
|
||||||
CopyInterps(&info, false, XkbSI_Exactly);
|
|
||||||
CopyInterps(&info, false, XkbSI_AllOf | XkbSI_NoneOf);
|
|
||||||
CopyInterps(&info, false, XkbSI_AnyOf);
|
|
||||||
CopyInterps(&info, false, XkbSI_AnyOfOrNone);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!CopyIndicatorMapDefs(&info))
|
|
||||||
info.errorCount++;
|
|
||||||
|
|
||||||
ClearCompatInfo(&info);
|
ClearCompatInfo(&info);
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -860,7 +860,7 @@ HandleKeycodesFile(KeyNamesInfo *info, XkbFile *file, enum merge_mode merge)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static void
|
||||||
ApplyAliases(KeyNamesInfo *info, struct xkb_keymap *keymap)
|
ApplyAliases(KeyNamesInfo *info, struct xkb_keymap *keymap)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
@ -932,6 +932,37 @@ out:
|
||||||
list_foreach_safe(alias, next, &info->aliases, entry)
|
list_foreach_safe(alias, next, &info->aliases, entry)
|
||||||
free(alias);
|
free(alias);
|
||||||
list_init(&info->aliases);
|
list_init(&info->aliases);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
CopyKeyNamesToKeymap(struct xkb_keymap *keymap, KeyNamesInfo *info)
|
||||||
|
{
|
||||||
|
xkb_keycode_t kc;
|
||||||
|
IndicatorNameInfo *ii;
|
||||||
|
|
||||||
|
if (info->explicitMin > 0)
|
||||||
|
keymap->min_key_code = info->explicitMin;
|
||||||
|
else
|
||||||
|
keymap->min_key_code = info->computedMin;
|
||||||
|
|
||||||
|
if (info->explicitMax > 0)
|
||||||
|
keymap->max_key_code = info->explicitMax;
|
||||||
|
else
|
||||||
|
keymap->max_key_code = info->computedMax;
|
||||||
|
|
||||||
|
darray_resize0(keymap->keys, keymap->max_key_code + 1);
|
||||||
|
for (kc = info->computedMin; kc <= info->computedMax; kc++)
|
||||||
|
LongToKeyName(darray_item(info->names, kc),
|
||||||
|
XkbKey(keymap, kc)->name);
|
||||||
|
|
||||||
|
keymap->keycodes_section_name = strdup_safe(info->name);
|
||||||
|
|
||||||
|
list_foreach(ii, &info->leds, entry)
|
||||||
|
keymap->indicator_names[ii->ndx - 1] =
|
||||||
|
xkb_atom_text(keymap->ctx, ii->name);
|
||||||
|
|
||||||
|
ApplyAliases(info, keymap);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -949,41 +980,16 @@ bool
|
||||||
CompileKeycodes(XkbFile *file, struct xkb_keymap *keymap,
|
CompileKeycodes(XkbFile *file, struct xkb_keymap *keymap,
|
||||||
enum merge_mode merge)
|
enum merge_mode merge)
|
||||||
{
|
{
|
||||||
xkb_keycode_t kc;
|
KeyNamesInfo info;
|
||||||
KeyNamesInfo info; /* contains all the info after parsing */
|
|
||||||
IndicatorNameInfo *ii;
|
|
||||||
|
|
||||||
InitKeyNamesInfo(&info, keymap->ctx, file->id);
|
InitKeyNamesInfo(&info, keymap->ctx, file->id);
|
||||||
|
|
||||||
HandleKeycodesFile(&info, file, merge);
|
HandleKeycodesFile(&info, file, merge);
|
||||||
|
|
||||||
/* all the keys are now stored in info */
|
|
||||||
|
|
||||||
if (info.errorCount != 0)
|
if (info.errorCount != 0)
|
||||||
goto err_info;
|
goto err_info;
|
||||||
|
|
||||||
if (info.explicitMin > 0) /* if "minimum" statement was present */
|
if (!CopyKeyNamesToKeymap(keymap, &info))
|
||||||
keymap->min_key_code = info.explicitMin;
|
goto err_info;
|
||||||
else
|
|
||||||
keymap->min_key_code = info.computedMin;
|
|
||||||
|
|
||||||
if (info.explicitMax > 0) /* if "maximum" statement was present */
|
|
||||||
keymap->max_key_code = info.explicitMax;
|
|
||||||
else
|
|
||||||
keymap->max_key_code = info.computedMax;
|
|
||||||
|
|
||||||
darray_resize0(keymap->keys, keymap->max_key_code + 1);
|
|
||||||
for (kc = info.computedMin; kc <= info.computedMax; kc++)
|
|
||||||
LongToKeyName(darray_item(info.names, kc),
|
|
||||||
XkbKey(keymap, kc)->name);
|
|
||||||
|
|
||||||
keymap->keycodes_section_name = strdup_safe(info.name);
|
|
||||||
|
|
||||||
list_foreach(ii, &info.leds, entry)
|
|
||||||
keymap->indicator_names[ii->ndx - 1] =
|
|
||||||
xkb_atom_text(keymap->ctx, ii->name);
|
|
||||||
|
|
||||||
ApplyAliases(&info, keymap);
|
|
||||||
|
|
||||||
ClearKeyNamesInfo(&info);
|
ClearKeyNamesInfo(&info);
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -847,7 +847,7 @@ HandleKeyTypesFile(KeyTypesInfo *info, XkbFile *file, enum merge_mode merge)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static void
|
||||||
CopyDefToKeyType(KeyTypesInfo *info, KeyTypeInfo *def,
|
CopyDefToKeyType(KeyTypesInfo *info, KeyTypeInfo *def,
|
||||||
struct xkb_key_type *type)
|
struct xkb_key_type *type)
|
||||||
{
|
{
|
||||||
|
@ -859,40 +859,27 @@ CopyDefToKeyType(KeyTypesInfo *info, KeyTypeInfo *def,
|
||||||
type->name = def->name;
|
type->name = def->name;
|
||||||
type->level_names = darray_mem(def->level_names, 0);
|
type->level_names = darray_mem(def->level_names, 0);
|
||||||
darray_init(def->level_names);
|
darray_init(def->level_names);
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
static bool
|
||||||
CompileKeyTypes(XkbFile *file, struct xkb_keymap *keymap,
|
CopyKeyTypesToKeymap(struct xkb_keymap *keymap, KeyTypesInfo *info)
|
||||||
enum merge_mode merge)
|
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
unsigned int num_types;
|
unsigned int num_types;
|
||||||
KeyTypesInfo info;
|
|
||||||
KeyTypeInfo *def;
|
KeyTypeInfo *def;
|
||||||
|
|
||||||
InitKeyTypesInfo(&info, keymap, file->id);
|
num_types = info->num_types ? info->num_types : 1;
|
||||||
|
|
||||||
HandleKeyTypesFile(&info, file, merge);
|
|
||||||
|
|
||||||
if (info.errorCount != 0)
|
|
||||||
goto err_info;
|
|
||||||
|
|
||||||
if (info.name)
|
|
||||||
keymap->types_section_name = strdup(info.name);
|
|
||||||
|
|
||||||
num_types = info.num_types ? info.num_types : 1;
|
|
||||||
keymap->types = calloc(num_types, sizeof(*keymap->types));
|
keymap->types = calloc(num_types, sizeof(*keymap->types));
|
||||||
if (!keymap->types)
|
if (!keymap->types)
|
||||||
goto err_info;
|
return false;
|
||||||
|
|
||||||
keymap->num_types = num_types;
|
keymap->num_types = num_types;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If no types were specified, a default unnamed one-level type is
|
* If no types were specified, a default unnamed one-level type is
|
||||||
* used for all keys.
|
* used for all keys.
|
||||||
*/
|
*/
|
||||||
if (info.num_types == 0) {
|
if (info->num_types == 0) {
|
||||||
KeyTypeInfo dflt = {
|
KeyTypeInfo dflt = {
|
||||||
.name = xkb_atom_intern(keymap->ctx, "default"),
|
.name = xkb_atom_intern(keymap->ctx, "default"),
|
||||||
.mods = 0,
|
.mods = 0,
|
||||||
|
@ -901,15 +888,33 @@ CompileKeyTypes(XkbFile *file, struct xkb_keymap *keymap,
|
||||||
.level_names = darray_new(),
|
.level_names = darray_new(),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!CopyDefToKeyType(&info, &dflt, &keymap->types[0]))
|
CopyDefToKeyType(info, &dflt, &keymap->types[0]);
|
||||||
goto err_info;
|
|
||||||
} else {
|
} else {
|
||||||
i = 0;
|
i = 0;
|
||||||
list_foreach(def, &info.types, entry)
|
list_foreach(def, &info->types, entry)
|
||||||
if (!CopyDefToKeyType(&info, def, &keymap->types[i++]))
|
CopyDefToKeyType(info, def, &keymap->types[i++]);
|
||||||
goto err_info;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
keymap->types_section_name = strdup_safe(info->name);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
CompileKeyTypes(XkbFile *file, struct xkb_keymap *keymap,
|
||||||
|
enum merge_mode merge)
|
||||||
|
{
|
||||||
|
KeyTypesInfo info;
|
||||||
|
|
||||||
|
InitKeyTypesInfo(&info, keymap, file->id);
|
||||||
|
|
||||||
|
HandleKeyTypesFile(&info, file, merge);
|
||||||
|
if (info.errorCount != 0)
|
||||||
|
goto err_info;
|
||||||
|
|
||||||
|
if (!CopyKeyTypesToKeymap(keymap, &info))
|
||||||
|
goto err_info;
|
||||||
|
|
||||||
FreeKeyTypesInfo(&info);
|
FreeKeyTypesInfo(&info);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue