abouttreesummaryrefslogcommitdiff
path: root/srcs/juloo.keyboard2/KeyValue.java
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/KeyValue.java
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/KeyValue.java')
-rw-r--r--srcs/juloo.keyboard2/KeyValue.java31
1 files changed, 27 insertions, 4 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)