Commit 424de613af4c0a8121213bbee8c4fdd8364612e5

Ran Benita 2012-10-05T22:46:21

Keep real and virtual mods in the same table in the keymap We change the keymap->vmods array into keymap->mods, and change it's member type from struct xkb_vmod to struct xkb_mod. This table now includes the real modifiers in the first 8 places. To distinguish between them, we add an enum mod_type to struct xkb_mod. Besides being a more reasonable approach, this enables us to share some code later, remove XKB_NUM_CORE_MODS (though the 0xff mask still appears in a few places), and prepares us to flat out remove the distinction in the future. This commit just does the conversion. 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
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
diff --git a/src/keymap-dump.c b/src/keymap-dump.c
index 38b8c95..261562a 100644
--- a/src/keymap-dump.c
+++ b/src/keymap-dump.c
@@ -127,15 +127,18 @@ err:
 static bool
 write_vmods(struct xkb_keymap *keymap, struct buf *buf)
 {
-    const struct xkb_vmod *vmod;
+    const struct xkb_mod *mod;
     xkb_mod_index_t num_vmods = 0;
 
-    darray_foreach(vmod, keymap->vmods) {
+    darray_foreach(mod, keymap->mods) {
+        if (mod->type != MOD_VIRT)
+            continue;
+
         if (num_vmods == 0)
             write_buf(buf, "\t\tvirtual_modifiers ");
         else
             write_buf(buf, ",");
-        write_buf(buf, "%s", xkb_atom_text(keymap->ctx, vmod->name));
+        write_buf(buf, "%s", xkb_atom_text(keymap->ctx, mod->name));
         num_vmods++;
     }
 
@@ -523,10 +526,10 @@ write_compat(struct xkb_keymap *keymap, struct buf *buf)
                   VModMaskText(keymap, interp->mods));
 
         if (interp->virtual_mod != XKB_MOD_INVALID) {
-            xkb_mod_index_t idx = interp->virtual_mod - XKB_NUM_CORE_MODS;
+            xkb_mod_index_t idx = interp->virtual_mod;
             write_buf(buf, "\t\t\tvirtualModifier= %s;\n",
                       xkb_atom_text(keymap->ctx,
-                                    darray_item(keymap->vmods, idx).name));
+                                    darray_item(keymap->mods, idx).name));
         }
 
         if (interp->match & MATCH_LEVEL_ONE_ONLY)
@@ -724,17 +727,18 @@ write_symbols(struct xkb_keymap *keymap, struct buf *buf)
     }
 
     xkb_foreach_key(key, keymap) {
-        xkb_mod_index_t mod;
+        xkb_mod_index_t i;
+        const struct xkb_mod *mod;
 
         if (key->modmap == 0)
             continue;
 
-        for (mod = 0; mod < XKB_NUM_CORE_MODS; mod++) {
-            if (!(key->modmap & (1 << mod)))
+        darray_enumerate(i, mod, keymap->mods) {
+            if (!(key->modmap & (1 << i)))
                 continue;
 
             write_buf(buf, "\t\tmodifier_map %s { %s };\n",
-                      ModIndexToName(mod),
+                      xkb_atom_text(keymap->ctx, mod->name),
                       KeyNameText(keymap->ctx, key->name));
         }
     }
diff --git a/src/keymap.c b/src/keymap.c
index 0471e3a..a54169a 100644
--- a/src/keymap.c
+++ b/src/keymap.c
@@ -107,7 +107,7 @@ xkb_keymap_unref(struct xkb_keymap *keymap)
     darray_free(keymap->sym_interpret);
     darray_free(keymap->key_aliases);
     darray_free(keymap->group_names);
-    darray_free(keymap->vmods);
+    darray_free(keymap->mods);
     free(keymap->keycodes_section_name);
     free(keymap->symbols_section_name);
     free(keymap->types_section_name);
@@ -122,9 +122,7 @@ xkb_keymap_unref(struct xkb_keymap *keymap)
 XKB_EXPORT xkb_mod_index_t
 xkb_keymap_num_mods(struct xkb_keymap *keymap)
 {
-    /* We always have all the core modifiers (for now), plus any virtual
-     * modifiers we may have defined. */
-    return XKB_NUM_CORE_MODS + darray_size(keymap->vmods);
+    return darray_size(keymap->mods);
 }
 
 /**
@@ -133,20 +131,10 @@ xkb_keymap_num_mods(struct xkb_keymap *keymap)
 XKB_EXPORT const char *
 xkb_keymap_mod_get_name(struct xkb_keymap *keymap, xkb_mod_index_t idx)
 {
-    const char *name;
-    const struct xkb_vmod *vmod;
-
-    if (idx >= xkb_keymap_num_mods(keymap))
+    if (idx >= darray_size(keymap->mods))
         return NULL;
 
-    /* First try to find a legacy modifier name.  If that fails, try to
-     * find a virtual mod name. */
-    name = ModIndexToName(idx);
-    if (name)
-        return name;
-
-    vmod = &darray_item(keymap->vmods, idx - XKB_NUM_CORE_MODS);
-    return xkb_atom_text(keymap->ctx, vmod->name);
+    return xkb_atom_text(keymap->ctx, darray_item(keymap->mods, idx).name);
 }
 
 /**
@@ -157,19 +145,15 @@ xkb_keymap_mod_get_index(struct xkb_keymap *keymap, const char *name)
 {
     xkb_mod_index_t i;
     xkb_atom_t atom;
-    const struct xkb_vmod *vmod;
-
-    i = ModNameToIndex(name);
-    if (i != XKB_MOD_INVALID)
-        return i;
+    const struct xkb_mod *mod;
 
     atom = xkb_atom_lookup(keymap->ctx, name);
     if (atom == XKB_ATOM_NONE)
         return XKB_MOD_INVALID;
 
-    darray_enumerate(i, vmod, keymap->vmods)
-        if (vmod->name == atom)
-            return i + XKB_NUM_CORE_MODS;
+    darray_enumerate(i, mod, keymap->mods)
+        if (mod->name == atom)
+            return i;
 
     return XKB_MOD_INVALID;
 }
diff --git a/src/keymap.h b/src/keymap.h
index f50b091..0bc6509 100644
--- a/src/keymap.h
+++ b/src/keymap.h
@@ -103,13 +103,17 @@
  */
 #define XKB_NUM_GROUPS 4
 
-/* Don't allow more vmods than we can hold in xkb_mod_mask_t. */
-#define XKB_MAX_VIRTUAL_MODS \
-    ((xkb_mod_index_t) (sizeof(xkb_mod_mask_t) * 8 - XKB_NUM_CORE_MODS))
+/* Don't allow more modifiers than we can hold in xkb_mod_mask_t. */
+#define XKB_MAX_MODS ((xkb_mod_index_t) (sizeof(xkb_mod_mask_t) * 8))
 
 /* These should all be dynamic. */
 #define XKB_NUM_INDICATORS 32
-#define XKB_NUM_CORE_MODS 8
+
+enum mod_type {
+    MOD_REAL = (1 << 0),
+    MOD_VIRT = (1 << 1),
+    MOD_BOTH = (MOD_REAL | MOD_VIRT),
+};
 
 enum xkb_action_type {
     ACTION_TYPE_NONE = 0,
@@ -358,8 +362,9 @@ struct xkb_key {
 
 typedef darray(xkb_atom_t) darray_xkb_atom_t;
 
-struct xkb_vmod {
+struct xkb_mod {
     xkb_atom_t name;
+    enum mod_type type;
     xkb_mod_mask_t mapping; /* vmod -> real mod mapping */
 };
 
@@ -386,7 +391,7 @@ struct xkb_keymap {
 
     darray(struct xkb_sym_interpret) sym_interpret;
 
-    darray(struct xkb_vmod) vmods;
+    darray(struct xkb_mod) mods;
 
     /* Number of groups in the key with the most groups. */
     xkb_layout_index_t num_groups;
diff --git a/src/text.c b/src/text.c
index c9f5cf9..eea3059 100644
--- a/src/text.c
+++ b/src/text.c
@@ -233,7 +233,7 @@ GetBuffer(size_t size)
 
 /* Get a mod mask's text, where the mask is in rmods+vmods format. */
 const char *
-VModMaskText(struct xkb_keymap *keymap, xkb_mod_mask_t cmask)
+VModMaskText(struct xkb_keymap *keymap, xkb_mod_mask_t mask)
 {
     xkb_mod_index_t i;
     xkb_mod_mask_t rmask, vmask;
@@ -241,15 +241,16 @@ VModMaskText(struct xkb_keymap *keymap, xkb_mod_mask_t cmask)
     const char *mm = NULL;
     char *rtrn, *str;
     char buf[BUFFER_SIZE];
+    const struct xkb_mod *mod;
 
-    rmask = cmask & 0xff;
-    vmask = cmask & (~0xff);
+    rmask = mask & 0xff;
+    vmask = mask & (~0xff);
 
     if (rmask == 0 && vmask == 0)
         return "none";
 
     if (rmask != 0)
-        mm = ModMaskText(rmask);
+        mm = ModMaskText(keymap, rmask);
 
     if (vmask == 0)
         return mm;
@@ -258,16 +259,18 @@ VModMaskText(struct xkb_keymap *keymap, xkb_mod_mask_t cmask)
     buf[0] = '\0';
     rem = BUFFER_SIZE;
 
-    for (i = 0; i < darray_size(keymap->vmods) && rem > 1; i++) {
-        const char *name;
-
-        if (!(vmask & (1 << (i + XKB_NUM_CORE_MODS))))
+    darray_enumerate(i, mod, keymap->mods) {
+        if (mod->type != MOD_VIRT || !(vmask & (1 << i)))
             continue;
 
-        name = xkb_atom_text(keymap->ctx, darray_item(keymap->vmods, i).name);
-        len = snprintf(str, rem, "%s%s", (str != buf) ? "+" : "", name);
+        len = snprintf(str, rem, "%s%s",
+                       (str != buf) ? "+" : "",
+                       xkb_atom_text(keymap->ctx, mod->name));
         rem -= len;
         str += len;
+
+        if (rem <= 1)
+            break;
     }
 
     str = buf;
@@ -286,70 +289,51 @@ VModMaskText(struct xkb_keymap *keymap, xkb_mod_mask_t cmask)
     return rtrn;
 }
 
-/*
- * IMPORTATNT
- * The indices used for the legacy core modifiers is derived from
- * the order of the names in this table. It matches the values
- * ShiftMapIndex, LockMapIndex, etc. from X11/X.h. Take note before
- * changing.
- */
-static const char *modNames[XKB_NUM_CORE_MODS] = {
-    "Shift",
-    "Lock",
-    "Control",
-    "Mod1",
-    "Mod2",
-    "Mod3",
-    "Mod4",
-    "Mod5",
-};
-
 xkb_mod_index_t
-ModNameToIndex(const char *name)
+ModNameToIndex(const struct xkb_keymap *keymap, xkb_atom_t name)
 {
     xkb_mod_index_t i;
+    const struct xkb_mod *mod;
 
-    for (i = 0; i < XKB_NUM_CORE_MODS; i++)
-        if (istreq(name, modNames[i]))
+    darray_enumerate(i, mod, keymap->mods)
+        if (mod->type == MOD_REAL && name == mod->name)
             return i;
 
     return XKB_MOD_INVALID;
 }
 
-const char *
-ModIndexToName(xkb_mod_index_t ndx)
+xkb_atom_t
+ModIndexToName(struct xkb_keymap *keymap, xkb_mod_index_t ndx)
 {
-    if (ndx < XKB_NUM_CORE_MODS)
-        return modNames[ndx];
-    return NULL;
+    if (ndx >= darray_size(keymap->mods) ||
+        darray_item(keymap->mods, ndx).type != MOD_REAL)
+        return XKB_ATOM_NONE;
+
+    return darray_item(keymap->mods, ndx).name;
 }
 
 const char *
-ModIndexText(xkb_mod_index_t ndx)
+ModIndexText(struct xkb_keymap *keymap, xkb_mod_index_t ndx)
 {
-    const char *name;
-    char *buf;
+    xkb_atom_t name;
 
-    name = ModIndexToName(ndx);
+    name = ModIndexToName(keymap, ndx);
     if (name)
-        return name;
+        return xkb_atom_text(keymap->ctx, name);
 
     if (ndx == XKB_MOD_INVALID)
         return "none";
 
-    buf = GetBuffer(32);
-    snprintf(buf, 32, "ILLEGAL_%02x", ndx);
-
-    return buf;
+    return "illegal";
 }
 
-/* Gets the text for the real modifiers only. */
 const char *
-ModMaskText(xkb_mod_mask_t mask)
+ModMaskText(struct xkb_keymap *keymap, xkb_mod_mask_t mask)
 {
-    int i, rem;
-    xkb_mod_index_t bit;
+    xkb_mod_index_t i;
+    int len, rem;
     char *str, *buf;
+    const struct xkb_mod *mod;
 
     if ((mask & 0xff) == 0xff)
         return "all";
@@ -361,16 +345,18 @@ ModMaskText(xkb_mod_mask_t mask)
     buf = GetBuffer(rem);
     str = buf;
     buf[0] = '\0';
-    for (i = 0, bit = 1; i < XKB_NUM_CORE_MODS && rem > 1; i++, bit <<= 1) {
-        int len;
-
-        if (!(mask & bit))
+    darray_enumerate(i, mod, keymap->mods) {
+        if (mod->type != MOD_REAL || !(mask & (1 << i)))
             continue;
 
         len = snprintf(str, rem, "%s%s",
-                       (str != buf ?  "+" : ""), modNames[i]);
+                       (str != buf ?  "+" : ""),
+                       ModIndexText(keymap, i));
         rem -= len;
         str += len;
+
+        if (rem <= 1)
+            break;
     }
 
     return buf;
diff --git a/src/text.h b/src/text.h
index 3058aa9..5c257d1 100644
--- a/src/text.h
+++ b/src/text.h
@@ -48,19 +48,19 @@ extern const LookupEntry actionTypeNames[];
 extern const LookupEntry symInterpretMatchMaskNames[];
 
 const char *
-VModMaskText(struct xkb_keymap *keymap, xkb_mod_mask_t cmask);
+VModMaskText(struct xkb_keymap *keymap, xkb_mod_mask_t mask);
 
 xkb_mod_index_t
-ModNameToIndex(const char *name);
+ModNameToIndex(const struct xkb_keymap *keymap, xkb_atom_t name);
 
-const char *
-ModIndexToName(xkb_mod_index_t ndx);
+xkb_atom_t
+ModIndexToName(struct xkb_keymap *keymap, xkb_mod_index_t ndx);
 
 const char *
-ModIndexText(xkb_mod_index_t ndx);
+ModIndexText(struct xkb_keymap *keymap, xkb_mod_index_t ndx);
 
 const char *
-ModMaskText(xkb_mod_mask_t mask);
+ModMaskText(struct xkb_keymap *keymap, xkb_mod_mask_t mask);
 
 const char *
 ActionTypeText(enum xkb_action_type type);
diff --git a/src/xkbcomp/compat.c b/src/xkbcomp/compat.c
index 0c94346..5678074 100644
--- a/src/xkbcomp/compat.c
+++ b/src/xkbcomp/compat.c
@@ -210,7 +210,7 @@ siText(SymInterpInfo *si, CompatInfo *info)
     snprintf(buf, sizeof(buf), "%s+%s(%s)",
              KeysymText(si->interp.sym),
              SIMatchText(si->interp.match),
-             ModMaskText(si->interp.mods));
+             ModMaskText(info->keymap, si->interp.mods));
     return buf;
 }
 
@@ -394,7 +394,7 @@ ResolveStateAndPredicate(ExprDef *expr, enum xkb_match_operation *pred_rtrn,
         }
     }
 
-    return ExprResolveModMask(info->keymap->ctx, expr, mods_rtrn);
+    return ExprResolveModMask(info->keymap, expr, mods_rtrn);
 }
 
 /***====================================================================***/
diff --git a/src/xkbcomp/expr.c b/src/xkbcomp/expr.c
index d3e167f..f5caa58 100644
--- a/src/xkbcomp/expr.c
+++ b/src/xkbcomp/expr.c
@@ -85,8 +85,8 @@ static bool
 LookupModIndex(struct xkb_context *ctx, const void *priv, xkb_atom_t field,
                enum expr_value_type type, xkb_mod_index_t *val_rtrn)
 {
-    const char *name = xkb_atom_text(ctx, field);
-    *val_rtrn = ModNameToIndex(name);
+    const struct xkb_keymap *keymap = priv;
+    *val_rtrn = ModNameToIndex(keymap, field);
     return (*val_rtrn != XKB_MOD_INVALID);
 }
 
@@ -96,6 +96,7 @@ LookupModMask(struct xkb_context *ctx, const void *priv, xkb_atom_t field,
 {
     const char *str;
     xkb_mod_index_t ndx;
+    const struct xkb_keymap *keymap = priv;
 
     if (type != EXPR_TYPE_INT)
         return false;
@@ -106,7 +107,7 @@ LookupModMask(struct xkb_context *ctx, const void *priv, xkb_atom_t field,
         *val_rtrn  = 0xff;
     else if (istreq(str, "none"))
         *val_rtrn = 0;
-    else if (LookupModIndex(ctx, priv, field, type, &ndx))
+    else if (LookupModIndex(ctx, keymap, field, type, &ndx))
         *val_rtrn = (1 << ndx);
     else
         return false;
@@ -618,25 +619,28 @@ ExprResolveMask(struct xkb_context *ctx, const ExprDef *expr,
 }
 
 bool
-ExprResolveModMask(struct xkb_context *ctx, const ExprDef *expr,
+ExprResolveModMask(struct xkb_keymap *keymap, const ExprDef *expr,
                    xkb_mod_mask_t *mask_rtrn)
 {
-    return ExprResolveMaskLookup(ctx, expr, mask_rtrn, LookupModMask, NULL);
+    return ExprResolveMaskLookup(keymap->ctx, expr, mask_rtrn, LookupModMask,
+                                 keymap);
 }
 
 static bool
-LookupVModIndex(const struct xkb_keymap *keymap, xkb_atom_t field,
-                enum expr_value_type type, xkb_mod_index_t *val_rtrn)
+LookupVModIndex(struct xkb_context *ctx, const void *priv,
+                xkb_atom_t field, enum expr_value_type type,
+                xkb_mod_index_t *val_rtrn)
 {
-    const struct xkb_vmod *vmod;
+    const struct xkb_mod *mod;
     xkb_mod_index_t i;
+    const struct xkb_keymap *keymap = priv;
 
     if (type != EXPR_TYPE_INT)
         return false;
 
-    darray_enumerate(i, vmod, keymap->vmods) {
-        if (vmod->name == field) {
-            *val_rtrn = XKB_NUM_CORE_MODS + i;
+    darray_enumerate(i, mod, keymap->mods) {
+        if (mod->type == MOD_VIRT && mod->name == field) {
+            *val_rtrn = i;
             return true;
         }
     }
@@ -649,11 +653,12 @@ LookupVModMask(struct xkb_context *ctx, const void *priv, xkb_atom_t field,
                enum expr_value_type type, xkb_mod_mask_t *val_rtrn)
 {
     xkb_mod_index_t ndx;
+    const struct xkb_keymap *keymap = priv;
 
-    if (LookupModMask(ctx, NULL, field, type, val_rtrn)) {
+    if (LookupModMask(ctx, keymap, field, type, val_rtrn)) {
         return true;
     }
-    else if (LookupVModIndex(priv, field, type, &ndx)) {
+    else if (LookupVModIndex(ctx, keymap, field, type, &ndx)) {
         *val_rtrn = (1 << ndx);
         return true;
     }
@@ -661,7 +666,6 @@ LookupVModMask(struct xkb_context *ctx, const void *priv, xkb_atom_t field,
     return false;
 }
 
-
 bool
 ExprResolveVModMask(struct xkb_keymap *keymap, const ExprDef *expr,
                     xkb_mod_mask_t *mask_rtrn)
@@ -698,7 +702,7 @@ bool
 ExprResolveVMod(struct xkb_keymap *keymap, const ExprDef *def,
                 xkb_mod_index_t *ndx_rtrn)
 {
-    const struct xkb_vmod *vmod;
+    const struct xkb_mod *mod;
     xkb_mod_index_t i;
     xkb_atom_t name = def->value.str;
 
@@ -710,9 +714,9 @@ ExprResolveVMod(struct xkb_keymap *keymap, const ExprDef *def,
         return false;
     }
 
-    darray_enumerate(i, vmod, keymap->vmods) {
-        if (vmod->name == name) {
-            *ndx_rtrn = XKB_NUM_CORE_MODS + i;
+    darray_enumerate(i, mod, keymap->mods) {
+        if (mod->type == MOD_VIRT && mod->name == name) {
+            *ndx_rtrn = i;
             return true;
         }
     }
diff --git a/src/xkbcomp/expr.h b/src/xkbcomp/expr.h
index 14a6179..bab70cc 100644
--- a/src/xkbcomp/expr.h
+++ b/src/xkbcomp/expr.h
@@ -33,7 +33,7 @@ ExprResolveLhs(struct xkb_context *ctx, const ExprDef *expr,
                ExprDef **index_rtrn);
 
 bool
-ExprResolveModMask(struct xkb_context *ctx, const ExprDef *expr,
+ExprResolveModMask(struct xkb_keymap *keymap, const ExprDef *expr,
                    xkb_mod_mask_t *mask_rtrn);
 
 bool
diff --git a/src/xkbcomp/keymap.c b/src/xkbcomp/keymap.c
index 52198d1..81e584e 100644
--- a/src/xkbcomp/keymap.c
+++ b/src/xkbcomp/keymap.c
@@ -32,15 +32,15 @@
 static void
 ComputeEffectiveMask(struct xkb_keymap *keymap, struct xkb_mods *mods)
 {
-    const struct xkb_vmod *vmod;
+    const struct xkb_mod *mod;
     xkb_mod_index_t i;
 
     /* The effective mask is only real mods for now. */
     mods->mask = mods->mods & 0xff;
 
-    darray_enumerate(i, vmod, keymap->vmods)
-        if (mods->mods & (1 << (i + XKB_NUM_CORE_MODS)))
-            mods->mask |= vmod->mapping;
+    darray_enumerate(i, mod, keymap->mods)
+        if (mod->type == MOD_VIRT && mods->mods & (1 << i))
+            mods->mask |= mod->mapping;
 }
 
 static void
@@ -78,7 +78,7 @@ static const struct xkb_sym_interpret *
 FindInterpForKey(struct xkb_keymap *keymap, const struct xkb_key *key,
                  xkb_layout_index_t group, xkb_level_index_t level)
 {
-    struct xkb_sym_interpret *interp;
+    const struct xkb_sym_interpret *interp;
     const xkb_keysym_t *syms;
     int num_syms;
 
@@ -184,7 +184,7 @@ ApplyInterpsToKey(struct xkb_keymap *keymap, struct xkb_key *key)
 static bool
 UpdateDerivedKeymapFields(struct xkb_keymap *keymap)
 {
-    struct xkb_vmod *vmod;
+    struct xkb_mod *mod;
     xkb_led_index_t led;
     unsigned int i, j;
     struct xkb_key *key;
@@ -195,11 +195,11 @@ UpdateDerivedKeymapFields(struct xkb_keymap *keymap)
         if (!ApplyInterpsToKey(keymap, key))
             return false;
 
-    /* Update keymap->vmods, the virtual -> real mod mapping. */
+    /* Update keymap->mods, the virtual -> real mod mapping. */
     xkb_foreach_key(key, keymap)
-        darray_enumerate(i, vmod, keymap->vmods)
-            if (key->vmodmap & (1 << (XKB_NUM_CORE_MODS + i)))
-                vmod->mapping |= key->modmap;
+        darray_enumerate(i, mod, keymap->mods)
+            if (mod->type == MOD_VIRT && key->vmodmap & (1 << i))
+                mod->mapping |= key->modmap;
 
     /* Now update the level masks for all the types to reflect the vmods. */
     for (i = 0; i < keymap->num_types; i++) {
@@ -229,6 +229,28 @@ UpdateDerivedKeymapFields(struct xkb_keymap *keymap)
     return true;
 }
 
+static bool
+UpdateBuiltinKeymapFields(struct xkb_keymap *keymap)
+{
+    struct xkb_context *ctx = keymap->ctx;
+
+    /*
+     * Add predefined (AKA real, core, X11) modifiers.
+     * The order is important!
+     */
+    darray_appends(keymap->mods,
+        { .name = xkb_atom_intern(ctx, "Shift"),   .type = MOD_REAL },
+        { .name = xkb_atom_intern(ctx, "Lock"),    .type = MOD_REAL },
+        { .name = xkb_atom_intern(ctx, "Control"), .type = MOD_REAL },
+        { .name = xkb_atom_intern(ctx, "Mod1"),    .type = MOD_REAL },
+        { .name = xkb_atom_intern(ctx, "Mod2"),    .type = MOD_REAL },
+        { .name = xkb_atom_intern(ctx, "Mod3"),    .type = MOD_REAL },
+        { .name = xkb_atom_intern(ctx, "Mod4"),    .type = MOD_REAL },
+        { .name = xkb_atom_intern(ctx, "Mod5"),    .type = MOD_REAL });
+
+    return true;
+}
+
 typedef bool (*compile_file_fn)(XkbFile *file,
                                 struct xkb_keymap *keymap,
                                 enum merge_mode merge);
@@ -294,6 +316,9 @@ CompileKeymap(XkbFile *file, struct xkb_keymap *keymap, enum merge_mode merge)
     if (!ok)
         return false;
 
+    if (!UpdateBuiltinKeymapFields(keymap))
+        return false;
+
     /* Compile sections. */
     for (type = FIRST_KEYMAP_FILE_TYPE;
          type <= LAST_KEYMAP_FILE_TYPE;
diff --git a/src/xkbcomp/symbols.c b/src/xkbcomp/symbols.c
index 2324550..14d7668 100644
--- a/src/xkbcomp/symbols.c
+++ b/src/xkbcomp/symbols.c
@@ -440,7 +440,7 @@ AddKeySymbols(SymbolsInfo *info, KeyInfo *keyi)
 }
 
 static bool
-AddModMapEntry(SymbolsInfo * info, ModMapEntry * new)
+AddModMapEntry(SymbolsInfo *info, ModMapEntry *new)
 {
     ModMapEntry *mm;
     bool clobber;
@@ -462,8 +462,9 @@ AddModMapEntry(SymbolsInfo * info, ModMapEntry * new)
                 log_err(info->keymap->ctx,
                         "%s added to symbol map for multiple modifiers; "
                         "Using %s, ignoring %s.\n",
-                        KeysymText(new->u.keySym), ModIndexText(use),
-                        ModIndexText(ignore));
+                        KeysymText(new->u.keySym),
+                        ModIndexText(info->keymap, use),
+                        ModIndexText(info->keymap, ignore));
                 mm->modifier = use;
             }
             return true;
@@ -484,7 +485,8 @@ AddModMapEntry(SymbolsInfo * info, ModMapEntry * new)
                         "Key %s added to map for multiple modifiers; "
                         "Using %s, ignoring %s.\n",
                         KeyNameText(info->keymap->ctx, new->u.keyName),
-                        ModIndexText(use), ModIndexText(ignore));
+                        ModIndexText(info->keymap, use),
+                        ModIndexText(info->keymap, ignore));
                 mm->modifier = use;
             }
             return true;
@@ -1209,7 +1211,7 @@ HandleModMapDef(SymbolsInfo *info, ModMapDef *def)
     bool ok;
     struct xkb_context *ctx = info->keymap->ctx;
 
-    ndx = ModNameToIndex(xkb_atom_text(ctx, def->modifier));
+    ndx = ModNameToIndex(info->keymap, def->modifier);
     if (ndx == XKB_MOD_INVALID) {
         log_err(info->keymap->ctx,
                 "Illegal modifier map definition; "
@@ -1236,7 +1238,7 @@ HandleModMapDef(SymbolsInfo *info, ModMapDef *def)
             log_err(info->keymap->ctx,
                     "Modmap entries may contain only key names or keysyms; "
                     "Illegal definition for %s modifier ignored\n",
-                    ModIndexText(tmp.modifier));
+                    ModIndexText(info->keymap, tmp.modifier));
             continue;
         }
 
@@ -1571,7 +1573,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(entry->modifier));
+                    ModIndexText(info->keymap, entry->modifier));
             return false;
         }
     }
@@ -1582,7 +1584,7 @@ CopyModMapDef(SymbolsInfo *info, ModMapEntry *entry)
                     "Key \"%s\" not found in symbol map; "
                     "Modifier map entry for %s not updated\n",
                     KeysymText(entry->u.keySym),
-                    ModIndexText(entry->modifier));
+                    ModIndexText(info->keymap, entry->modifier));
             return false;
         }
     }
diff --git a/src/xkbcomp/vmod.c b/src/xkbcomp/vmod.c
index 5e8a6c5..206e162 100644
--- a/src/xkbcomp/vmod.c
+++ b/src/xkbcomp/vmod.c
@@ -33,37 +33,37 @@ bool
 HandleVModDef(struct xkb_keymap *keymap, VModDef *stmt)
 {
     xkb_mod_index_t i;
-    const char *name;
-    const struct xkb_vmod *vmod;
-    struct xkb_vmod new;
+    const struct xkb_mod *mod;
+    struct xkb_mod new;
 
     if (stmt->value)
         log_err(keymap->ctx,
                 "Support for setting a value in a virtual_modifiers statement has been removed; "
                 "Value ignored\n");
 
-    name = xkb_atom_text(keymap->ctx, stmt->name);
-    if (ModNameToIndex(name) != XKB_MOD_INVALID) {
-        log_err(keymap->ctx,
-                "Can't add a virtual modifier named \"%s\"; "
-                "there is already a non-virtual modifier with this name! Ignored\n",
-                name);
-        return false;
-    }
+    darray_enumerate(i, mod, keymap->mods) {
+        if (mod->name == stmt->name) {
+            if (mod->type == MOD_VIRT)
+                return true;
 
-    darray_enumerate(i, vmod, keymap->vmods)
-        if (vmod->name == stmt->name)
-            return true;
+            log_err(keymap->ctx,
+                    "Can't add a virtual modifier named \"%s\"; "
+                    "there is already a non-virtual modifier with this name! Ignored\n",
+                    xkb_atom_text(keymap->ctx, mod->name));
+            return false;
+        }
+    }
 
-    if (darray_size(keymap->vmods) >= XKB_MAX_VIRTUAL_MODS) {
+    if (darray_size(keymap->mods) >= XKB_MAX_MODS) {
         log_err(keymap->ctx,
-                "Too many virtual modifiers defined (maximum %d)\n",
-                XKB_MAX_VIRTUAL_MODS);
+                "Too many modifiers defined (maximum %d)\n",
+                XKB_MAX_MODS);
         return false;
     }
 
     new.name = stmt->name;
     new.mapping = 0;
-    darray_append(keymap->vmods, new);
+    new.type = MOD_VIRT;
+    darray_append(keymap->mods, new);
     return true;
 }