allow for <fn ...> in <modmap> (#626)

This commit is contained in:
alotbsol555 2024-05-02 12:09:39 +02:00 committed by GitHub
parent c7ed2bcae9
commit 82e0840568
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 27 additions and 4 deletions

View File

@ -165,6 +165,12 @@ public final class KeyModifier
private static KeyValue apply_fn(KeyValue k) private static KeyValue apply_fn(KeyValue k)
{ {
if (_modmap != null)
{
KeyValue mapped = _modmap.fn.get(k);
if (mapped != null)
return mapped;
}
String name = null; String name = null;
switch (k.getKind()) switch (k.getKind())
{ {

View File

@ -515,18 +515,35 @@ public final class KeyboardData
public static class Modmap public static class Modmap
{ {
public final Map<KeyValue, KeyValue> shift; public final Map<KeyValue, KeyValue> shift;
public final Map<KeyValue, KeyValue> fn;
public Modmap(Map<KeyValue, KeyValue> s) public Modmap(Map<KeyValue, KeyValue> s, Map<KeyValue, KeyValue> f)
{ {
shift = s; shift = s;
fn = f;
} }
public static Modmap parse(XmlPullParser parser) throws Exception public static Modmap parse(XmlPullParser parser) throws Exception
{ {
HashMap<KeyValue, KeyValue> shift = new HashMap<KeyValue, KeyValue>(); HashMap<KeyValue, KeyValue> shift = new HashMap<KeyValue, KeyValue>();
while (expect_tag(parser, "shift")) HashMap<KeyValue, KeyValue> fn = new HashMap<KeyValue, KeyValue>();
while (next_tag(parser))
{
switch (parser.getName())
{
case "shift":
parse_mapping(parser, shift); parse_mapping(parser, shift);
return new Modmap(shift); break;
case "fn":
parse_mapping(parser, fn);
break;
default:
throw error(parser, "Expecting tag <shift> or <fn>, got <" + parser.getName() + ">");
}
}
return new Modmap(shift, fn);
} }
private static void parse_mapping(XmlPullParser parser, Map<KeyValue, KeyValue> dst) throws Exception private static void parse_mapping(XmlPullParser parser, Map<KeyValue, KeyValue> dst) throws Exception