abouttreesummaryrefslogcommitdiff
path: root/srcs
diff options
context:
space:
mode:
Diffstat (limited to 'srcs')
-rw-r--r--srcs/juloo.keyboard2/KeyboardData.java53
1 files changed, 34 insertions, 19 deletions
diff --git a/srcs/juloo.keyboard2/KeyboardData.java b/srcs/juloo.keyboard2/KeyboardData.java
index 25110ef..d4228e7 100644
--- a/srcs/juloo.keyboard2/KeyboardData.java
+++ b/srcs/juloo.keyboard2/KeyboardData.java
@@ -399,24 +399,37 @@ public final class KeyboardData
indication = i;
}
- /** Write the parsed key into [ks] at [index]. Doesn't write if the
- attribute is not present. Return flags that can be aggregated into the
- value for [keysflags]. */
- static int parse_key_attr(XmlPullParser parser, String attr, KeyValue[] ks,
+ /** Read a key value attribute that have a synonym. Having both synonyms
+ present at the same time is an error.
+ Returns [null] if the attributes are not present. */
+ static String get_key_attr(XmlPullParser parser, String syn1, String syn2)
+ throws Exception
+ {
+ String name1 = parser.getAttributeValue(null, syn1);
+ String name2 = parser.getAttributeValue(null, syn2);
+ if (name1 != null && name2 != null)
+ throw error(parser,
+ "'"+syn1+"' and '"+syn2+"' are synonyms and cannot be passed at the same time.");
+ return (name1 == null) ? name2 : name1;
+ }
+
+ /** Parse the key description [key_attr] and write into [ks] at [index].
+ Returns flags that can be aggregated into the value for [keysflags].
+ [key_attr] can be [null] for convenience. */
+ static int parse_key_attr(XmlPullParser parser, String key_val, KeyValue[] ks,
int index)
throws Exception
{
- String name = parser.getAttributeValue(null, attr);
- int flags = 0;
- if (name == null)
+ if (key_val == null)
return 0;
- String name_loc = stripPrefix(name, "loc ");
+ int flags = 0;
+ String name_loc = stripPrefix(key_val, "loc ");
if (name_loc != null)
{
flags |= F_LOC;
- name = name_loc;
+ key_val = name_loc;
}
- ks[index] = KeyValue.getKeyByName(name);
+ ks[index] = KeyValue.getKeyByName(key_val);
return (flags << index);
}
@@ -429,15 +442,17 @@ public final class KeyboardData
{
KeyValue[] ks = new KeyValue[9];
int keysflags = 0;
- keysflags |= parse_key_attr(parser, "key0", ks, 0);
- keysflags |= parse_key_attr(parser, "key1", ks, 1);
- keysflags |= parse_key_attr(parser, "key2", ks, 2);
- keysflags |= parse_key_attr(parser, "key3", ks, 3);
- keysflags |= parse_key_attr(parser, "key4", ks, 4);
- keysflags |= parse_key_attr(parser, "key5", ks, 5);
- keysflags |= parse_key_attr(parser, "key6", ks, 6);
- keysflags |= parse_key_attr(parser, "key7", ks, 7);
- keysflags |= parse_key_attr(parser, "key8", ks, 8);
+ keysflags |= parse_key_attr(parser, parser.getAttributeValue(null, "key0"), ks, 0);
+ /* Swipe gestures (key1-key8 diagram above), with compass-point synonyms. */
+ keysflags |= parse_key_attr(parser, get_key_attr(parser, "key1", "nw"), ks, 1);
+ keysflags |= parse_key_attr(parser, get_key_attr(parser, "key2", "ne"), ks, 2);
+ keysflags |= parse_key_attr(parser, get_key_attr(parser, "key3", "sw"), ks, 3);
+ keysflags |= parse_key_attr(parser, get_key_attr(parser, "key4", "se"), ks, 4);
+ keysflags |= parse_key_attr(parser, get_key_attr(parser, "key5", "w"), ks, 5);
+ keysflags |= parse_key_attr(parser, get_key_attr(parser, "key6", "e"), ks, 6);
+ keysflags |= parse_key_attr(parser, get_key_attr(parser, "key7", "n"), ks, 7);
+ keysflags |= parse_key_attr(parser, get_key_attr(parser, "key8", "s"), ks, 8);
+ /* Other key attributes */
float width = attribute_float(parser, "width", 1f);
float shift = attribute_float(parser, "shift", 0.f);
boolean slider = attribute_bool(parser, "slider", false);