compat: ignore "group" (compatibility) statements Group compatibility statements are like the following: group 3 = AltGr; This currently results in: keymap->groups[2].mask = <real mod mapped from AltGr vmod> And we don't do any thing with this value later. The reason it exists in XKB is to support non-XKB clients (i.e. XKB support disabled entirely in the server), which do not know the concept of "group", and use some modifier to distinguish between the first and second keyboard layouts (usually with the AltGr key). We don't care about all of that, so we can forget about it. One artifact of this removal is that xkb_map_num_groups no longer works, because it counted through keymap->groups (this wasn't entirely correct BTW). Instead we add a new num_groups member to the keymap, which just hold the maximum among the xkb_key's num_groups. This also means we don't have to compute anything just to get the number of groups. Signed-off-by: Ran Benita <ran234@gmail.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
diff --git a/src/keymap-dump.c b/src/keymap-dump.c
index 897bf21..1722d78 100644
--- a/src/keymap-dump.c
+++ b/src/keymap-dump.c
@@ -577,16 +577,6 @@ write_compat(struct xkb_keymap *keymap, struct buf *buf)
write_buf(buf, "\t\t};\n");
}
- for (i = 0; i < XkbNumKbdGroups; i++) {
- struct xkb_mods *gc;
-
- gc = &keymap->groups[i];
- if (gc->mods == 0)
- continue;
- write_buf(buf, "\t\tgroup %d = %s;\n", i + 1,
- VModMaskText(keymap, gc->mods));
- }
-
for (i = 0; i < XkbNumIndicators; i++) {
struct xkb_indicator_map *map = &keymap->indicators[i];
if (map->flags == 0 && map->which_groups == 0 &&
diff --git a/src/map.c b/src/map.c
index 9d65ba7..532d00d 100644
--- a/src/map.c
+++ b/src/map.c
@@ -168,14 +168,7 @@ xkb_map_mod_get_index(struct xkb_keymap *keymap, const char *name)
XKB_EXPORT xkb_group_index_t
xkb_map_num_groups(struct xkb_keymap *keymap)
{
- xkb_group_index_t ret = 0;
- xkb_group_index_t i;
-
- for (i = 0; i < XkbNumKbdGroups; i++)
- if (keymap->groups[i].mask)
- ret++;
-
- return ret;
+ return keymap->num_groups;
}
/**
diff --git a/src/utils.h b/src/utils.h
index 89beca6..0f7a384 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -67,6 +67,9 @@ isempty(const char *s)
return s == NULL || s[0] == '\0';
}
+#define MIN(a, b) ((a) < (b) ? (a) : (b))
+#define MAX(a, b) ((a) > (b) ? (a) : (b))
+
/* Compiler Attributes */
#if defined(__GNUC__) && (__GNUC__ >= 4) && !defined(__CYGWIN__)
diff --git a/src/xkb-priv.h b/src/xkb-priv.h
index f61e2a5..cfa4183 100644
--- a/src/xkb-priv.h
+++ b/src/xkb-priv.h
@@ -365,7 +365,8 @@ struct xkb_keymap {
xkb_mod_mask_t vmods[XkbNumVirtualMods];
const char *vmod_names[XkbNumVirtualMods];
- struct xkb_mods groups[XkbNumKbdGroups];
+ /* Number of groups in the key with the most groups. */
+ xkb_group_index_t num_groups;
const char *group_names[XkbNumKbdGroups];
struct xkb_indicator_map indicators[XkbNumIndicators];
diff --git a/src/xkbcomp/compat.c b/src/xkbcomp/compat.c
index ea7d692..349f902 100644
--- a/src/xkbcomp/compat.c
+++ b/src/xkbcomp/compat.c
@@ -173,13 +173,6 @@ typedef struct _LEDInfo {
unsigned int ctrls;
} LEDInfo;
-typedef struct _GroupCompatInfo {
- unsigned file_id;
- enum merge_mode merge;
- bool defined;
- xkb_mod_mask_t mods;
-} GroupCompatInfo;
-
typedef struct _CompatInfo {
char *name;
unsigned file_id;
@@ -188,7 +181,6 @@ typedef struct _CompatInfo {
struct list interps;
SymInterpInfo dflt;
LEDInfo ledDflt;
- GroupCompatInfo groupCompat[XkbNumKbdGroups];
darray(LEDInfo) leds;
VModInfo vmods;
ActionInfo *act;
@@ -274,8 +266,6 @@ InitCompatInfo(CompatInfo *info, struct xkb_keymap *keymap, unsigned file_id)
info->ledDflt.file_id = file_id;
info->ledDflt.defined = 0;
info->ledDflt.merge = MERGE_OVERRIDE;
- memset(&info->groupCompat[0], 0,
- XkbNumKbdGroups * sizeof(GroupCompatInfo));
darray_init(info->leds);
InitVModInfo(&info->vmods, keymap);
}
@@ -298,8 +288,6 @@ ClearCompatInfo(CompatInfo *info)
info->nInterps = 0;
list_foreach_safe(si, next_si, &info->interps, entry)
free(si);
- memset(&info->groupCompat[0], 0,
- XkbNumKbdGroups * sizeof(GroupCompatInfo));
darray_free(info->leds);
FreeActionInfo(info->act);
info->act = NULL;
@@ -422,27 +410,6 @@ AddInterp(CompatInfo *info, SymInterpInfo *new)
return true;
}
-static bool
-AddGroupCompat(CompatInfo *info, xkb_group_index_t group, GroupCompatInfo *new)
-{
- GroupCompatInfo *gc;
- int verbosity = xkb_get_log_verbosity(info->keymap->ctx);
-
- gc = &info->groupCompat[group];
- if (gc->mods == new->mods)
- return true;
-
- if ((gc->file_id == new->file_id && verbosity > 0) || verbosity > 9)
- log_warn(info->keymap->ctx,
- "Compat map for group %u redefined; "
- "Using %s definition\n",
- group + 1, (new->merge == MERGE_AUGMENT ? "old" : "new"));
-
- if (new->defined && (new->merge != MERGE_AUGMENT || !gc->defined))
- *gc = *new;
-
- return true;
-}
/***====================================================================***/
@@ -594,8 +561,6 @@ MergeIncludedCompatMaps(CompatInfo *into, CompatInfo *from,
{
SymInterpInfo *si, *next_si;
LEDInfo *led;
- GroupCompatInfo *gcm;
- xkb_group_index_t i;
if (from->errorCount > 0) {
into->errorCount += from->errorCount;
@@ -613,13 +578,6 @@ MergeIncludedCompatMaps(CompatInfo *into, CompatInfo *from,
into->errorCount++;
}
- for (i = 0; i < XkbNumKbdGroups; i++) {
- gcm = &from->groupCompat[i];
- gcm->merge = (merge == MERGE_DEFAULT ? gcm->merge : merge);
- if (!AddGroupCompat(into, i, gcm))
- into->errorCount++;
- }
-
darray_foreach(led, from->leds) {
led->merge = (merge == MERGE_DEFAULT ? led->merge : merge);
if (!AddIndicatorMap(into, led))
@@ -1000,37 +958,6 @@ HandleInterpDef(CompatInfo *info, InterpDef *def, enum merge_mode merge)
}
static bool
-HandleGroupCompatDef(CompatInfo *info, GroupCompatDef *def,
- enum merge_mode merge)
-{
- GroupCompatInfo tmp;
-
- merge = (def->merge == MERGE_DEFAULT ? merge : def->merge);
-
- if (def->group < 1 || def->group > XkbNumKbdGroups) {
- log_err(info->keymap->ctx,
- "Keyboard group must be in the range 1..%u; "
- "Compatibility map for illegal group %u ignored\n",
- XkbNumKbdGroups, def->group);
- return false;
- }
-
- tmp.file_id = info->file_id;
- tmp.merge = merge;
-
- if (!ExprResolveVModMask(info->keymap, def->def, &tmp.mods)) {
- log_err(info->keymap->ctx,
- "Expected a modifier mask in group compatibility definition; "
- "Ignoring illegal compatibility map for group %u\n",
- def->group);
- return false;
- }
-
- tmp.defined = true;
- return AddGroupCompat(info, def->group - 1, &tmp);
-}
-
-static bool
HandleIndicatorMapDef(CompatInfo *info, IndicatorMapDef *def,
enum merge_mode merge)
{
@@ -1093,7 +1020,10 @@ HandleCompatMapFile(CompatInfo *info, XkbFile *file, enum merge_mode merge)
ok = HandleInterpDef(info, (InterpDef *) stmt, merge);
break;
case STMT_GROUP_COMPAT:
- ok = HandleGroupCompatDef(info, (GroupCompatDef *) stmt, merge);
+ log_dbg(info->keymap->ctx,
+ "The \"group\" statement in compat is unsupported; "
+ "Ignored\n");
+ ok = true;
break;
case STMT_INDICATOR_MAP:
ok = HandleIndicatorMapDef(info, (IndicatorMapDef *) stmt, merge);
@@ -1208,9 +1138,7 @@ bool
CompileCompatMap(XkbFile *file, struct xkb_keymap *keymap,
enum merge_mode merge)
{
- xkb_group_index_t i;
CompatInfo info;
- GroupCompatInfo *gcm;
InitCompatInfo(&info, keymap, file->id);
info.dflt.merge = merge;
@@ -1237,12 +1165,6 @@ CompileCompatMap(XkbFile *file, struct xkb_keymap *keymap,
CopyInterps(&info, false, XkbSI_AnyOfOrNone);
}
- for (i = 0; i < XkbNumKbdGroups; i++) {
- gcm = &info.groupCompat[i];
- if (gcm->file_id != 0 || gcm->mods != 0)
- keymap->groups[i].mods = gcm->mods;
- }
-
if (!CopyIndicatorMapDefs(&info))
info.errorCount++;
@@ -1445,7 +1367,6 @@ bool
UpdateModifiersFromCompat(struct xkb_keymap *keymap)
{
xkb_mod_index_t vmod;
- xkb_group_index_t grp;
xkb_led_index_t led;
unsigned int i, j;
struct xkb_key *key;
@@ -1490,13 +1411,13 @@ UpdateModifiersFromCompat(struct xkb_keymap *keymap)
UpdateActionMods(keymap, &key->actions[i], key->modmap);
}
- /* Update group modifiers. */
- for (grp = 0; grp < XkbNumKbdGroups; grp++)
- ComputeEffectiveMask(keymap, &keymap->groups[grp]);
-
/* Update vmod -> indicator maps. */
for (led = 0; led < XkbNumIndicators; led++)
ComputeEffectiveMask(keymap, &keymap->indicators[led].mods);
+ /* Find maximum number of groups out of all keys in the keymap. */
+ xkb_foreach_key(key, keymap)
+ keymap->num_groups = MAX(keymap->num_groups, key->num_groups);
+
return true;
}
diff --git a/test/data/keymaps/stringcomp.data b/test/data/keymaps/stringcomp.data
index 110cece..42ff170 100644
--- a/test/data/keymaps/stringcomp.data
+++ b/test/data/keymaps/stringcomp.data
@@ -1050,9 +1050,6 @@ xkb_keymap {
interpret Any+AnyOf(all) {
action= SetMods(modifiers=modMapMods,clearLocks);
};
- group 2 = AltGr;
- group 3 = AltGr;
- group 4 = AltGr;
indicator "Caps Lock" {
whichModState= locked;
modifiers= Lock;