diff options
| author | Jules Aguillon | 2025-04-15 00:05:52 +0200 |
|---|---|---|
| committer | Jules Aguillon | 2025-04-15 00:05:52 +0200 |
| commit | 460e5214a20a381af9b18273372477389927f3fc (patch) | |
| tree | 184aeaaecba4794a6e1df5700131f8ae397f9e65 /srcs/juloo.keyboard2/KeyboardData.java | |
| parent | 5ae3ec05e7dbf5ad023e5121a5f12900d14098a0 (diff) | |
| download | unexpected-keyboard-460e5214a20a381af9b18273372477389927f3fc.tar.gz unexpected-keyboard-460e5214a20a381af9b18273372477389927f3fc.zip | |
Add class Modmap and test KeyModifier
Diffstat (limited to 'srcs/juloo.keyboard2/KeyboardData.java')
| -rw-r--r-- | srcs/juloo.keyboard2/KeyboardData.java | 65 |
1 files changed, 23 insertions, 42 deletions
diff --git a/srcs/juloo.keyboard2/KeyboardData.java b/srcs/juloo.keyboard2/KeyboardData.java index e4a7506..f5cc87e 100644 --- a/srcs/juloo.keyboard2/KeyboardData.java +++ b/srcs/juloo.keyboard2/KeyboardData.java @@ -260,7 +260,7 @@ public final class KeyboardData case "modmap": if (modmap != null) throw error(parser, "Multiple '<modmap>' are not allowed"); - modmap = Modmap.parse(parser); + modmap = parse_modmap(parser); break; default: throw error(parser, "Expecting tag <row>, got <" + parser.getName() + ">"); @@ -555,53 +555,34 @@ public final class KeyboardData } } - public static class Modmap + public static Modmap parse_modmap(XmlPullParser parser) throws Exception { - public final Map<KeyValue, KeyValue> shift; - public final Map<KeyValue, KeyValue> fn; - public final Map<KeyValue, KeyValue> ctrl; - - public Modmap(Map<KeyValue, KeyValue> s, Map<KeyValue, KeyValue> f, Map<KeyValue, KeyValue> c) - { - shift = s; - fn = f; - ctrl = c; - } - - public static Modmap parse(XmlPullParser parser) throws Exception + Modmap mm = new Modmap(); + while (next_tag(parser)) { - HashMap<KeyValue, KeyValue> shift = new HashMap<KeyValue, KeyValue>(); - HashMap<KeyValue, KeyValue> fn = new HashMap<KeyValue, KeyValue>(); - HashMap<KeyValue, KeyValue> ctrl = new HashMap<KeyValue, KeyValue>(); - while (next_tag(parser)) + Modmap.M m; + switch (parser.getName()) { - switch (parser.getName()) - { - case "shift": - parse_mapping(parser, shift); - break; - case "fn": - parse_mapping(parser, fn); - break; - case "ctrl": - parse_mapping(parser, ctrl); - break; - default: - throw error(parser, "Expecting tag <shift> or <fn>, got <" + parser.getName() + ">"); - } + case "shift": m = Modmap.M.Shift; break; + case "fn": m = Modmap.M.Fn; break; + case "ctrl": m = Modmap.M.Ctrl; break; + default: + throw error(parser, "Expecting tag <shift> or <fn>, got <" + + parser.getName() + ">"); } - - return new Modmap(shift, fn, ctrl); + parse_modmap_mapping(parser, mm, m); } + return mm; + } - private static void parse_mapping(XmlPullParser parser, Map<KeyValue, KeyValue> dst) throws Exception - { - KeyValue a = KeyValue.getKeyByName(parser.getAttributeValue(null, "a")); - KeyValue b = KeyValue.getKeyByName(parser.getAttributeValue(null, "b")); - while (parser.next() != XmlPullParser.END_TAG) - continue; - dst.put(a, b); - } + private static void parse_modmap_mapping(XmlPullParser parser, Modmap mm, + Modmap.M m) throws Exception + { + KeyValue a = KeyValue.getKeyByName(parser.getAttributeValue(null, "a")); + KeyValue b = KeyValue.getKeyByName(parser.getAttributeValue(null, "b")); + while (parser.next() != XmlPullParser.END_TAG) + continue; + mm.add(m, a, b); } /** Position of a key on the layout. */ |
