Commit edc0aef57dd633b504581d2c6e4bee9fe6d3acbf

Ran Benita 2013-02-08T13:21:27

text: take xkb_mod_set instead of the entire keymap The modifier printing functions only need the modifier information, they don't care about keys or leds, etc. 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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
diff --git a/src/keymap-priv.c b/src/keymap-priv.c
index 83d8894..2dd2e7b 100644
--- a/src/keymap-priv.c
+++ b/src/keymap-priv.c
@@ -124,13 +124,13 @@ XkbEscapeMapName(char *name)
 }
 
 xkb_mod_index_t
-XkbModNameToIndex(const struct xkb_keymap *keymap, xkb_atom_t name,
+XkbModNameToIndex(const struct xkb_mod_set *mods, xkb_atom_t name,
                   enum mod_type type)
 {
     xkb_mod_index_t i;
     const struct xkb_mod *mod;
 
-    darray_enumerate(i, mod, keymap->mods.mods)
+    darray_enumerate(i, mod, mods->mods)
         if ((mod->type & type) && name == mod->name)
             return i;
 
diff --git a/src/keymap.c b/src/keymap.c
index fba8b18..678bd01 100644
--- a/src/keymap.c
+++ b/src/keymap.c
@@ -291,7 +291,7 @@ xkb_keymap_mod_get_index(struct xkb_keymap *keymap, const char *name)
     if (atom == XKB_ATOM_NONE)
         return XKB_MOD_INVALID;
 
-    return XkbModNameToIndex(keymap, atom, MOD_BOTH);
+    return XkbModNameToIndex(&keymap->mods, atom, MOD_BOTH);
 }
 
 /**
diff --git a/src/keymap.h b/src/keymap.h
index d84ea70..76c4923 100644
--- a/src/keymap.h
+++ b/src/keymap.h
@@ -431,7 +431,7 @@ void
 XkbEscapeMapName(char *name);
 
 xkb_mod_index_t
-XkbModNameToIndex(const struct xkb_keymap *keymap, xkb_atom_t name,
+XkbModNameToIndex(const struct xkb_mod_set *mods, xkb_atom_t name,
                   enum mod_type type);
 
 xkb_layout_index_t
diff --git a/src/text.c b/src/text.c
index a70c3d9..8d26d19 100644
--- a/src/text.c
+++ b/src/text.c
@@ -207,16 +207,16 @@ const LookupEntry symInterpretMatchMaskNames[] = {
 };
 
 const char *
-ModIndexText(const struct xkb_keymap *keymap, xkb_mod_index_t ndx)
+ModIndexText(struct xkb_context *ctx, const struct xkb_mod_set *mods,
+             xkb_mod_index_t ndx)
 {
     if (ndx == XKB_MOD_INVALID)
         return "none";
 
-    if (ndx >= darray_size(keymap->mods.mods))
+    if (ndx >= darray_size(mods->mods))
         return NULL;
 
-    return xkb_atom_text(keymap->ctx,
-                         darray_item(keymap->mods.mods, ndx).name);
+    return xkb_atom_text(ctx, darray_item(mods->mods, ndx).name);
 }
 
 const char *
@@ -251,7 +251,8 @@ SIMatchText(enum xkb_match_operation type)
 }
 
 const char *
-ModMaskText(const struct xkb_keymap *keymap, xkb_mod_mask_t mask)
+ModMaskText(struct xkb_context *ctx, const struct xkb_mod_set *mods,
+            xkb_mod_mask_t mask)
 {
     char buf[1024];
     size_t pos = 0;
@@ -264,7 +265,7 @@ ModMaskText(const struct xkb_keymap *keymap, xkb_mod_mask_t mask)
     if (mask == MOD_REAL_MASK_ALL)
         return "all";
 
-    darray_enumerate(i, mod, keymap->mods.mods) {
+    darray_enumerate(i, mod, mods->mods) {
         int ret;
 
         if (!(mask & (1u << i)))
@@ -272,14 +273,14 @@ ModMaskText(const struct xkb_keymap *keymap, xkb_mod_mask_t mask)
 
         ret = snprintf(buf + pos, sizeof(buf) - pos, "%s%s",
                        pos == 0 ? "" : "+",
-                       xkb_atom_text(keymap->ctx, mod->name));
+                       xkb_atom_text(ctx, mod->name));
         if (ret <= 0 || pos + ret >= sizeof(buf))
             break;
         else
             pos += ret;
     }
 
-    return strcpy(xkb_context_get_buffer(keymap->ctx, pos + 1), buf);
+    return strcpy(xkb_context_get_buffer(ctx, pos + 1), buf);
 }
 
 const char *
diff --git a/src/text.h b/src/text.h
index 5b28e1f..584dea6 100644
--- a/src/text.h
+++ b/src/text.h
@@ -48,10 +48,12 @@ extern const LookupEntry actionTypeNames[];
 extern const LookupEntry symInterpretMatchMaskNames[];
 
 const char *
-ModMaskText(const struct xkb_keymap *keymap, xkb_mod_mask_t mask);
+ModMaskText(struct xkb_context *ctx, const struct xkb_mod_set *mods,
+            xkb_mod_mask_t mask);
 
 const char *
-ModIndexText(const struct xkb_keymap *keymap, xkb_mod_index_t ndx);
+ModIndexText(struct xkb_context *ctx, const struct xkb_mod_set *mods,
+             xkb_mod_index_t ndx);
 
 const char *
 ActionTypeText(enum xkb_action_type type);
diff --git a/src/xkbcomp/compat.c b/src/xkbcomp/compat.c
index 1251917..5ee5424 100644
--- a/src/xkbcomp/compat.c
+++ b/src/xkbcomp/compat.c
@@ -105,7 +105,7 @@ siText(SymInterpInfo *si, CompatInfo *info)
     snprintf(buf, 128, "%s+%s(%s)",
              KeysymText(info->ctx, si->interp.sym),
              SIMatchText(si->interp.match),
-             ModMaskText(info->keymap, si->interp.mods));
+             ModMaskText(info->ctx, &info->keymap->mods, si->interp.mods));
 
     return buf;
 }
diff --git a/src/xkbcomp/expr.c b/src/xkbcomp/expr.c
index 4c31205..6d5087d 100644
--- a/src/xkbcomp/expr.c
+++ b/src/xkbcomp/expr.c
@@ -112,7 +112,7 @@ LookupModMask(struct xkb_context *ctx, const void *priv, xkb_atom_t field,
         return true;
     }
 
-    ndx = XkbModNameToIndex(keymap, field, mod_type);
+    ndx = XkbModNameToIndex(&keymap->mods, field, mod_type);
     if (ndx == XKB_MOD_INVALID)
         return false;
 
@@ -665,7 +665,7 @@ ExprResolveMod(struct xkb_keymap *keymap, const ExprDef *def,
     }
 
     name = def->ident.ident;
-    ndx = XkbModNameToIndex(keymap, name, mod_type);
+    ndx = XkbModNameToIndex(&keymap->mods, name, mod_type);
     if (ndx == XKB_MOD_INVALID) {
         log_err(keymap->ctx,
                 "Cannot resolve virtual modifier: "
diff --git a/src/xkbcomp/keymap-dump.c b/src/xkbcomp/keymap-dump.c
index 9e3f3e8..a5d7877 100644
--- a/src/xkbcomp/keymap-dump.c
+++ b/src/xkbcomp/keymap-dump.c
@@ -205,7 +205,7 @@ write_types(struct xkb_keymap *keymap, struct buf *buf)
                   xkb_atom_text(keymap->ctx, type->name));
 
         write_buf(buf, "\t\tmodifiers= %s;\n",
-                  ModMaskText(keymap, type->mods.mods));
+                  ModMaskText(keymap->ctx, &keymap->mods, type->mods.mods));
 
         for (unsigned j = 0; j < type->num_entries; j++) {
             const char *str;
@@ -218,13 +218,14 @@ write_types(struct xkb_keymap *keymap, struct buf *buf)
             if (entry->level == 0 && entry->preserve.mods == 0)
                 continue;
 
-            str = ModMaskText(keymap, entry->mods.mods);
+            str = ModMaskText(keymap->ctx, &keymap->mods, entry->mods.mods);
             write_buf(buf, "\t\tmap[%s]= Level%u;\n",
                       str, entry->level + 1);
 
             if (entry->preserve.mods)
                 write_buf(buf, "\t\tpreserve[%s]= %s;\n",
-                          str, ModMaskText(keymap, entry->preserve.mods));
+                          str, ModMaskText(keymap->ctx, &keymap->mods,
+                                           entry->preserve.mods));
         }
 
         for (xkb_level_index_t n = 0; n < type->num_levels; n++)
@@ -261,7 +262,7 @@ write_led_map(struct xkb_keymap *keymap, struct buf *buf,
                       LedStateMaskText(keymap->ctx, led->which_mods));
         }
         write_buf(buf, "\t\tmodifiers= %s;\n",
-                  ModMaskText(keymap, led->mods.mods));
+                  ModMaskText(keymap->ctx, &keymap->mods, led->mods.mods));
     }
 
     if (led->ctrls) {
@@ -309,7 +310,8 @@ write_action(struct xkb_keymap *keymap, struct buf *buf,
         if (action->mods.flags & ACTION_MODS_LOOKUP_MODMAP)
             args = "modMapMods";
         else
-            args = ModMaskText(keymap, action->mods.mods.mods);
+            args = ModMaskText(keymap->ctx, &keymap->mods,
+                               action->mods.mods.mods);
         write_buf(buf, "%s%s(modifiers=%s%s%s%s)%s", prefix, type, args,
                   (action->type != ACTION_TYPE_MOD_LOCK && (action->mods.flags & ACTION_LOCK_CLEAR)) ? ",clearLocks" : "",
                   (action->type != ACTION_TYPE_MOD_LOCK && (action->mods.flags & ACTION_LATCH_TO_LOCK)) ? ",latchToLock" : "",
@@ -422,11 +424,12 @@ write_compat(struct xkb_keymap *keymap, struct buf *buf)
         write_buf(buf, "\tinterpret %s+%s(%s) {\n",
                   si->sym ? KeysymText(keymap->ctx, si->sym) : "Any",
                   SIMatchText(si->match),
-                  ModMaskText(keymap, si->mods));
+                  ModMaskText(keymap->ctx, &keymap->mods, si->mods));
 
         if (si->virtual_mod != XKB_MOD_INVALID)
             write_buf(buf, "\t\tvirtualModifier= %s;\n",
-                      ModIndexText(keymap, si->virtual_mod));
+                      ModIndexText(keymap->ctx, &keymap->mods,
+                                   si->virtual_mod));
 
         if (si->level_one_only)
             write_buf(buf, "\t\tuseModMapMods=level1;\n");
@@ -534,7 +537,7 @@ write_key(struct xkb_keymap *keymap, struct buf *buf,
 
     if (key->vmodmap && (key->explicit & EXPLICIT_VMODMAP))
         write_buf(buf, "\n\t\tvirtualMods= %s,",
-                    ModMaskText(keymap, key->vmodmap));
+                  ModMaskText(keymap->ctx, &keymap->mods, key->vmodmap));
 
     switch (key->out_of_range_group_action) {
     case RANGE_SATURATE:
diff --git a/src/xkbcomp/symbols.c b/src/xkbcomp/symbols.c
index 541d320..21abfe7 100644
--- a/src/xkbcomp/symbols.c
+++ b/src/xkbcomp/symbols.c
@@ -457,15 +457,15 @@ AddModMapEntry(SymbolsInfo *info, ModMapEntry *new)
                     "Symbol \"%s\" added to modifier map for multiple modifiers; "
                     "Using %s, ignoring %s\n",
                     KeysymText(info->ctx, new->u.keySym),
-                    ModIndexText(info->keymap, use),
-                    ModIndexText(info->keymap, ignore));
+                    ModIndexText(info->ctx, &info->keymap->mods, use),
+                    ModIndexText(info->ctx, &info->keymap->mods, ignore));
         else
             log_err(info->ctx,
                     "Key \"%s\" added to modifier map for multiple modifiers; "
                     "Using %s, ignoring %s\n",
                     KeyNameText(info->ctx, new->u.keyName),
-                    ModIndexText(info->keymap, use),
-                    ModIndexText(info->keymap, ignore));
+                    ModIndexText(info->ctx, &info->keymap->mods, use),
+                    ModIndexText(info->ctx, &info->keymap->mods, ignore));
 
         old->modifier = use;
         return true;
@@ -1139,7 +1139,7 @@ HandleModMapDef(SymbolsInfo *info, ModMapDef *def)
     bool ok;
     struct xkb_context *ctx = info->ctx;
 
-    ndx = XkbModNameToIndex(info->keymap, def->modifier, MOD_REAL);
+    ndx = XkbModNameToIndex(&info->keymap->mods, def->modifier, MOD_REAL);
     if (ndx == XKB_MOD_INVALID) {
         log_err(info->ctx,
                 "Illegal modifier map definition; "
@@ -1168,7 +1168,7 @@ HandleModMapDef(SymbolsInfo *info, ModMapDef *def)
             log_err(info->ctx,
                     "Modmap entries may contain only key names or keysyms; "
                     "Illegal definition for %s modifier ignored\n",
-                    ModIndexText(info->keymap, tmp.modifier));
+                    ModIndexText(info->ctx, &info->keymap->mods, tmp.modifier));
             continue;
         }
 
@@ -1501,7 +1501,7 @@ CopyModMapDef(SymbolsInfo *info, ModMapEntry *entry)
                     "Key %s not found in keycodes; "
                     "Modifier map entry for %s not updated\n",
                     KeyNameText(keymap->ctx, entry->u.keyName),
-                    ModIndexText(info->keymap, entry->modifier));
+                    ModIndexText(info->ctx, &info->keymap->mods, entry->modifier));
             return false;
         }
     }
@@ -1512,7 +1512,7 @@ CopyModMapDef(SymbolsInfo *info, ModMapEntry *entry)
                     "Key \"%s\" not found in symbol map; "
                     "Modifier map entry for %s not updated\n",
                     KeysymText(info->ctx, entry->u.keySym),
-                    ModIndexText(info->keymap, entry->modifier));
+                    ModIndexText(info->ctx, &info->keymap->mods, entry->modifier));
             return false;
         }
     }
diff --git a/src/xkbcomp/types.c b/src/xkbcomp/types.c
index d5a0380..4ef9397 100644
--- a/src/xkbcomp/types.c
+++ b/src/xkbcomp/types.c
@@ -62,7 +62,7 @@ typedef struct {
 static inline const char *
 MapEntryTxt(KeyTypesInfo *info, struct xkb_key_type_entry *entry)
 {
-    return ModMaskText(info->keymap, entry->mods.mods);
+    return ModMaskText(info->ctx, &info->keymap->mods, entry->mods.mods);
 }
 
 static inline const char *
@@ -74,7 +74,7 @@ TypeTxt(KeyTypesInfo *info, KeyTypeInfo *type)
 static inline const char *
 TypeMaskTxt(KeyTypesInfo *info, KeyTypeInfo *type)
 {
-    return ModMaskText(info->keymap, type->mods);
+    return ModMaskText(info->ctx, &info->keymap->mods, type->mods);
 }
 
 static inline bool
@@ -262,7 +262,7 @@ SetModifiers(KeyTypesInfo *info, KeyTypeInfo *type, ExprDef *arrayNdx,
                  "Using %s, ignoring %s\n",
                  xkb_atom_text(info->ctx, type->name),
                  TypeMaskTxt(info, type),
-                 ModMaskText(info->keymap, mods));
+                 ModMaskText(info->ctx, &info->keymap->mods, mods));
         return false;
     }
 
@@ -341,7 +341,8 @@ SetMapEntry(KeyTypesInfo *info, KeyTypeInfo *type, ExprDef *arrayNdx,
                 "Map entry for unused modifiers in %s; "
                 "Using %s instead of %s\n",
                 TypeTxt(info, type),
-                ModMaskText(info->keymap, entry.mods.mods & type->mods),
+                ModMaskText(info->ctx, &info->keymap->mods,
+                            entry.mods.mods & type->mods),
                 MapEntryTxt(info, &entry));
         entry.mods.mods &= type->mods;
     }
@@ -382,7 +383,7 @@ AddPreserve(KeyTypesInfo *info, KeyTypeInfo *type,
             log_vrb(info->ctx, 10,
                     "Identical definitions for preserve[%s] in %s; "
                     "Ignored\n",
-                    ModMaskText(info->keymap, mods),
+                    ModMaskText(info->ctx, &info->keymap->mods, mods),
                     TypeTxt(info, type));
             return true;
         }
@@ -391,10 +392,10 @@ AddPreserve(KeyTypesInfo *info, KeyTypeInfo *type,
         log_vrb(info->ctx, 1,
                 "Multiple definitions for preserve[%s] in %s; "
                 "Using %s, ignoring %s\n",
-                ModMaskText(info->keymap, mods),
+                ModMaskText(info->ctx, &info->keymap->mods, mods),
                 TypeTxt(info, type),
-                ModMaskText(info->keymap, preserve_mods),
-                ModMaskText(info->keymap, entry->preserve.mods));
+                ModMaskText(info->ctx, &info->keymap->mods, preserve_mods),
+                ModMaskText(info->ctx, &info->keymap->mods, entry->preserve.mods));
 
         entry->preserve.mods = preserve_mods;
         return true;
@@ -428,9 +429,9 @@ SetPreserve(KeyTypesInfo *info, KeyTypeInfo *type, ExprDef *arrayNdx,
     if (mods & ~type->mods) {
         const char *before, *after;
 
-        before = ModMaskText(info->keymap, mods);
+        before = ModMaskText(info->ctx, &info->keymap->mods, mods);
         mods &= type->mods;
-        after = ModMaskText(info->keymap, mods);
+        after = ModMaskText(info->ctx, &info->keymap->mods, mods);
 
         log_vrb(info->ctx, 1,
                 "Preserve for modifiers not used by the %s type; "
@@ -442,7 +443,7 @@ SetPreserve(KeyTypesInfo *info, KeyTypeInfo *type, ExprDef *arrayNdx,
         log_err(info->ctx,
                 "Preserve value in a key type is not a modifier mask; "
                 "Ignoring preserve[%s] in type %s\n",
-                ModMaskText(info->keymap, mods),
+                ModMaskText(info->ctx, &info->keymap->mods, mods),
                 TypeTxt(info, type));
         return false;
     }
@@ -450,14 +451,14 @@ SetPreserve(KeyTypesInfo *info, KeyTypeInfo *type, ExprDef *arrayNdx,
     if (preserve_mods & ~mods) {
         const char *before, *after;
 
-        before = ModMaskText(info->keymap, preserve_mods);
+        before = ModMaskText(info->ctx, &info->keymap->mods, preserve_mods);
         preserve_mods &= mods;
-        after = ModMaskText(info->keymap, preserve_mods);
+        after = ModMaskText(info->ctx, &info->keymap->mods, preserve_mods);
 
         log_vrb(info->ctx, 1,
                 "Illegal value for preserve[%s] in type %s; "
                 "Converted %s to %s\n",
-                ModMaskText(info->keymap, mods),
+                ModMaskText(info->ctx, &info->keymap->mods, mods),
                 TypeTxt(info, type), before, after);
     }
 
diff --git a/src/xkbcomp/vmod.c b/src/xkbcomp/vmod.c
index 95b86bd..d523913 100644
--- a/src/xkbcomp/vmod.c
+++ b/src/xkbcomp/vmod.c
@@ -80,8 +80,8 @@ HandleVModDef(struct xkb_keymap *keymap, VModDef *stmt,
                          "Virtual modifier %s defined multiple times; "
                          "Using %s, ignoring %s\n",
                          xkb_atom_text(keymap->ctx, stmt->name),
-                         ModMaskText(keymap, use),
-                         ModMaskText(keymap, ignore));
+                         ModMaskText(keymap->ctx, &keymap->mods, use),
+                         ModMaskText(keymap->ctx, &keymap->mods, ignore));
 
                 mapping = use;
             }