abouttreesummaryrefslogcommitdiff
path: root/srcs/juloo.keyboard2
diff options
context:
space:
mode:
authorJules Aguillon2025-02-27 23:53:42 +0100
committerJules Aguillon2025-02-27 23:53:42 +0100
commit466e0b82189352ee931916b22494f638fabc9aa3 (patch)
tree8acfb89d4e53571cfa5c7b20f7cc1b6b6c9f5755 /srcs/juloo.keyboard2
parent75fdc2bfa9cfe7ad5b743105c3679e2fdc3110e3 (diff)
downloadunexpected-keyboard-466e0b82189352ee931916b22494f638fabc9aa3.tar.gz
unexpected-keyboard-466e0b82189352ee931916b22494f638fabc9aa3.zip
KeyValue: Don't wrap keys into a macro when possible
Many kind of KeyValues don't need to be wrapped into a Macro to show a specific symbol. This is especially useful as Macro keys are not affected by modifiers. The parser is changed to have a fast-path when a key value is not a macro.
Diffstat (limited to 'srcs/juloo.keyboard2')
-rw-r--r--srcs/juloo.keyboard2/KeyValue.java31
-rw-r--r--srcs/juloo.keyboard2/KeyValueParser.java10
2 files changed, 33 insertions, 8 deletions
diff --git a/srcs/juloo.keyboard2/KeyValue.java b/srcs/juloo.keyboard2/KeyValue.java
index b2ef5db..7cad9eb 100644
--- a/srcs/juloo.keyboard2/KeyValue.java
+++ b/srcs/juloo.keyboard2/KeyValue.java
@@ -250,7 +250,26 @@ public final class KeyValue implements Comparable<KeyValue>
public KeyValue withFlags(int f)
{
- return new KeyValue(_payload, (_code & KIND_BITS), (_code & VALUE_BITS), f);
+ return new KeyValue(_payload, (_code & ~FLAGS_BITS) | (f & FLAGS_BITS));
+ }
+
+ public KeyValue withSymbol(String symbol)
+ {
+ switch (getKind())
+ {
+ case Char:
+ case Keyevent:
+ case Event:
+ case Compose_pending:
+ case Hangul_initial:
+ case Hangul_medial:
+ case Modifier:
+ case Editing:
+ case Placeholder:
+ return new KeyValue(symbol, _code);
+ default:
+ return makeMacro(symbol, new KeyValue[]{ this }, 0);
+ }
}
@Override
@@ -294,13 +313,17 @@ public final class KeyValue implements Comparable<KeyValue>
return "[KeyValue " + getKind().toString() + "+" + getFlags() + "+" + value + " \"" + getString() + "\"]";
}
- /** [value] is an unsigned integer. */
- private KeyValue(Comparable p, int kind, int value, int flags)
+ private KeyValue(Comparable p, int code)
{
if (p == null)
throw new NullPointerException("KeyValue payload cannot be null");
_payload = p;
- _code = (kind & KIND_BITS) | (flags & FLAGS_BITS) | (value & VALUE_BITS);
+ _code = code;
+ }
+
+ private KeyValue(Comparable p, int kind, int value, int flags)
+ {
+ this(p, (kind & KIND_BITS) | (flags & FLAGS_BITS) | (value & VALUE_BITS));
}
public KeyValue(Comparable p, Kind k, int v, int f)
diff --git a/srcs/juloo.keyboard2/KeyValueParser.java b/srcs/juloo.keyboard2/KeyValueParser.java
index 488f5d3..92d1ee5 100644
--- a/srcs/juloo.keyboard2/KeyValueParser.java
+++ b/srcs/juloo.keyboard2/KeyValueParser.java
@@ -41,15 +41,17 @@ public final class KeyValueParser
if (symbol_ends == input_len) // String key
return KeyValue.makeStringKey(input);
String symbol = input.substring(0, symbol_ends);
- ArrayList<KeyValue> keydefs = new ArrayList<KeyValue>();
init();
Matcher m = KEYDEF_TOKEN.matcher(input);
m.region(symbol_ends + 1, input_len);
+ KeyValue first_key = parse_key_def(m);
+ if (!parse_comma(m)) // Input is a single key def with a specified symbol
+ return first_key.withSymbol(symbol);
+ // Input is a macro
+ ArrayList<KeyValue> keydefs = new ArrayList<KeyValue>();
+ keydefs.add(first_key);
do { keydefs.add(parse_key_def(m)); }
while (parse_comma(m));
- for (KeyValue k : keydefs)
- if (k == null)
- parseError("Contains null key", m);
return KeyValue.makeMacro(symbol, keydefs.toArray(new KeyValue[]{}), 0);
}