keymap-dump: combine modifier_map's with the same modifier A bit less efficient, but makes for shorter, nicer output. 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
diff --git a/src/xkbcomp/keymap-dump.c b/src/xkbcomp/keymap-dump.c
index 775be0f..0b3d50a 100644
--- a/src/xkbcomp/keymap-dump.c
+++ b/src/xkbcomp/keymap-dump.c
@@ -598,6 +598,8 @@ write_symbols(struct xkb_keymap *keymap, struct buf *buf)
{
const struct xkb_key *key;
xkb_layout_index_t group;
+ xkb_mod_index_t i;
+ const struct xkb_mod *mod;
if (keymap->symbols_section_name)
write_buf(buf, "xkb_symbols \"%s\" {\n",
@@ -617,18 +619,21 @@ write_symbols(struct xkb_keymap *keymap, struct buf *buf)
if (key->num_groups > 0)
write_key(keymap, buf, key);
- xkb_keys_foreach(key, keymap) {
- xkb_mod_index_t i;
- const struct xkb_mod *mod;
-
- if (key->modmap == 0)
- continue;
-
- xkb_mods_enumerate(i, mod, &keymap->mods)
- if (key->modmap & (1u << i))
- write_buf(buf, "\tmodifier_map %s { %s };\n",
- xkb_atom_text(keymap->ctx, mod->name),
+ xkb_mods_enumerate(i, mod, &keymap->mods) {
+ bool had_any = false;
+ xkb_keys_foreach(key, keymap) {
+ if (key->modmap & (1u << i)) {
+ if (!had_any)
+ write_buf(buf, "\tmodifier_map %s { ",
+ xkb_atom_text(keymap->ctx, mod->name));
+ write_buf(buf, "%s%s",
+ had_any ? ", " : "",
KeyNameText(keymap->ctx, key->name));
+ had_any = true;
+ }
+ }
+ if (had_any)
+ write_buf(buf, " };\n");
}
write_buf(buf, "};\n\n");
diff --git a/test/data/keymaps/host.xkb b/test/data/keymaps/host.xkb
index 2c0f589..3b10467 100644
--- a/test/data/keymaps/host.xkb
+++ b/test/data/keymaps/host.xkb
@@ -1664,20 +1664,13 @@ xkb_symbols "pc_us_pt_2_us_3_inet(evdev)_group(shift_caps_toggle)_compose(ralt)"
key <I244> { [ XF86Battery ] };
key <I245> { [ XF86Bluetooth ] };
key <I246> { [ XF86WLAN ] };
- modifier_map Control { <LCTL> };
- modifier_map Shift { <LFSH> };
- modifier_map Shift { <RTSH> };
- modifier_map Mod1 { <LALT> };
+ modifier_map Shift { <LFSH>, <RTSH> };
modifier_map Lock { <CAPS> };
+ modifier_map Control { <LCTL>, <RCTL> };
+ modifier_map Mod1 { <LALT>, <META> };
modifier_map Mod2 { <NMLK> };
- modifier_map Mod5 { <LVL3> };
- modifier_map Control { <RCTL> };
- modifier_map Mod4 { <LWIN> };
- modifier_map Mod4 { <RWIN> };
- modifier_map Mod5 { <MDSW> };
- modifier_map Mod1 { <META> };
- modifier_map Mod4 { <SUPR> };
- modifier_map Mod4 { <HYPR> };
+ modifier_map Mod4 { <LWIN>, <RWIN>, <SUPR>, <HYPR> };
+ modifier_map Mod5 { <LVL3>, <MDSW> };
};
};
diff --git a/test/data/keymaps/stringcomp.data b/test/data/keymaps/stringcomp.data
index 119fb99..b9639c0 100644
--- a/test/data/keymaps/stringcomp.data
+++ b/test/data/keymaps/stringcomp.data
@@ -1900,21 +1900,14 @@ xkb_symbols "pc_us_ru_2_ca(multix)_3_de(neo)_4_inet(evdev)" {
key <I244> { [ XF86Battery ] };
key <I245> { [ XF86Bluetooth ] };
key <I246> { [ XF86WLAN ] };
- modifier_map Control { <LCTL> };
- modifier_map Shift { <LFSH> };
- modifier_map Shift { <RTSH> };
- modifier_map Mod1 { <LALT> };
+ modifier_map Shift { <LFSH>, <RTSH> };
modifier_map Lock { <CAPS> };
+ modifier_map Control { <LCTL> };
+ modifier_map Mod1 { <LALT>, <RALT>, <META> };
modifier_map Mod2 { <NMLK> };
- modifier_map Mod5 { <LVL3> };
modifier_map Mod3 { <RCTL> };
- modifier_map Mod1 { <RALT> };
- modifier_map Mod4 { <LWIN> };
- modifier_map Mod4 { <RWIN> };
- modifier_map Mod5 { <MDSW> };
- modifier_map Mod1 { <META> };
- modifier_map Mod4 { <SUPR> };
- modifier_map Mod4 { <HYPR> };
+ modifier_map Mod4 { <LWIN>, <RWIN>, <SUPR>, <HYPR> };
+ modifier_map Mod5 { <LVL3>, <MDSW> };
};
};