abouttreesummaryrefslogcommitdiff
path: root/srcs
diff options
context:
space:
mode:
authorJules Aguillon2025-01-12 23:24:04 +0100
committerJules Aguillon2025-01-12 23:24:04 +0100
commite3f9341ed1ad35000cb14f92eb26687a429b548d (patch)
tree41ec0fa1f20d5379ae781427eb9412f95c4db2a8 /srcs
parent3ea5c8d6b7a1211cddbbbfc2de8a7c08151a7e71 (diff)
downloadunexpected-keyboard-e3f9341ed1ad35000cb14f92eb26687a429b548d.tar.gz
unexpected-keyboard-e3f9341ed1ad35000cb14f92eb26687a429b548d.zip
Refactor: KeyValue: Simplify StringWithSymbol
This removes the Complex key kind and class by making StringWithSymbol a new kind of key.
Diffstat (limited to 'srcs')
-rw-r--r--srcs/juloo.keyboard2/KeyEventHandler.java12
-rw-r--r--srcs/juloo.keyboard2/KeyValue.java83
2 files changed, 24 insertions, 71 deletions
diff --git a/srcs/juloo.keyboard2/KeyEventHandler.java b/srcs/juloo.keyboard2/KeyEventHandler.java
index 471fad0..eba488a 100644
--- a/srcs/juloo.keyboard2/KeyEventHandler.java
+++ b/srcs/juloo.keyboard2/KeyEventHandler.java
@@ -100,7 +100,7 @@ public final class KeyEventHandler
_recv.set_compose_pending(true);
break;
case Slider: handle_slider(key.getSlider(), key.getSliderRepeat()); break;
- case Complex: send_complex_key(key.getComplexKind(), key.getComplex()); break;
+ case StringWithSymbol: send_text(key.getStringWithSymbol()); break;
}
update_meta_state(old_mods);
}
@@ -219,16 +219,6 @@ public final class KeyEventHandler
conn.performContextMenuAction(id);
}
- void send_complex_key(KeyValue.Complex.Kind kind, KeyValue.Complex val)
- {
- switch (kind)
- {
- case StringWithSymbol:
- send_text(((KeyValue.Complex.StringWithSymbol)val).str);
- break;
- }
- }
-
@SuppressLint("InlinedApi")
void handle_editing_key(KeyValue.Editing ev)
{
diff --git a/srcs/juloo.keyboard2/KeyValue.java b/srcs/juloo.keyboard2/KeyValue.java
index 359d1d3..fea03fa 100644
--- a/srcs/juloo.keyboard2/KeyValue.java
+++ b/srcs/juloo.keyboard2/KeyValue.java
@@ -90,10 +90,11 @@ public final class KeyValue implements Comparable<KeyValue>
public static enum Kind
{
- Char, String, Keyevent, Event, Compose_pending, Hangul_initial,
- Hangul_medial, Modifier, Editing, Placeholder,
+ Char, Keyevent, Event, Compose_pending, Hangul_initial, Hangul_medial,
+ Modifier, Editing, Placeholder,
+ String, // [_payload] is also the string to output, value is unused.
Slider, // [_payload] is a [KeyValue.Slider], value is slider repeatition.
- Complex, // [_payload] is a [KeyValue.Complex], value is [Complex.Kind].
+ StringWithSymbol, // [_payload] is a [KeyValue.StringWithSymbol], value is unused.
}
private static final int FLAGS_OFFSET = 19;
@@ -131,10 +132,7 @@ public final class KeyValue implements Comparable<KeyValue>
check((((Kind.values().length - 1) << KIND_OFFSET) & ~KIND_BITS) == 0);
}
- /**
- * [_payload.toString()] is the symbol that is rendered on the keyboard.
- * For keys of kind [String], this is also the string to output.
- */
+ /** [_payload.toString()] is the symbol that is rendered on the keyboard. */
private final Comparable _payload;
/** This field encodes three things: Kind (KIND_BITS), flags (FLAGS_BITS) and
@@ -225,16 +223,10 @@ public final class KeyValue implements Comparable<KeyValue>
return ((int)(short)(_code & VALUE_BITS));
}
- /** Defined only when [getKind() == Kind.Complex]. */
- public Complex getComplex()
- {
- return (Complex)_payload;
- }
-
- /** Defined only when [getKind() == Kind.Complex]. */
- public Complex.Kind getComplexKind()
+ /** Defined only when [getKind() == Kind.StringWithSymbol]. */
+ public String getStringWithSymbol()
{
- return Complex.Kind.values()[(_code & VALUE_BITS)];
+ return ((StringWithSymbol)_payload).str;
}
/* Update the char and the symbol. */
@@ -303,11 +295,6 @@ public final class KeyValue implements Comparable<KeyValue>
_code = (kind & KIND_BITS) | (flags & FLAGS_BITS) | (value & VALUE_BITS);
}
- private KeyValue(Complex p, Complex.Kind value, int flags)
- {
- this(p, Kind.Complex, value.ordinal(), flags);
- }
-
public KeyValue(Comparable p, Kind k, int v, int f)
{
this(p, (k.ordinal() << KIND_OFFSET), v, f);
@@ -463,8 +450,8 @@ public final class KeyValue implements Comparable<KeyValue>
public static KeyValue makeStringKeyWithSymbol(String str, String symbol, int flags)
{
- return new KeyValue(new Complex.StringWithSymbol(str, symbol),
- Complex.Kind.StringWithSymbol, flags);
+ return new KeyValue(new StringWithSymbol(str, symbol),
+ Kind.StringWithSymbol, 0, flags);
}
/** Make a modifier key for passing to [KeyModifier]. */
@@ -753,50 +740,26 @@ public final class KeyValue implements Comparable<KeyValue>
throw new RuntimeException("Assertion failure");
}
- public static abstract class Complex implements Comparable<Complex>
+ public static final class StringWithSymbol implements Comparable<StringWithSymbol>
{
- public abstract String getSymbol();
+ public final String str;
+ final String _symbol;
- /** [compareTo] can assume that [snd] is an instance of the same class. */
- @Override
- public abstract int compareTo(Complex snd);
-
- @Override
- public String toString()
+ public StringWithSymbol(String _str, String _sym)
{
- return getSymbol();
+ str = _str;
+ _symbol = _sym;
}
- /** [hashCode] will be called on this class. */
-
- /** The kind is stored in the [value] field of the key. */
- public static enum Kind
- {
- StringWithSymbol,
- }
+ @Override
+ public String toString() { return _symbol; }
- public static final class StringWithSymbol extends Complex
+ @Override
+ public int compareTo(StringWithSymbol snd)
{
- public final String str;
- private final String _symbol;
-
- public StringWithSymbol(String _str, String _sym)
- {
- str = _str;
- _symbol = _sym;
- }
-
- @Override
- public String getSymbol() { return _symbol; }
-
- @Override
- public int compareTo(Complex _snd)
- {
- StringWithSymbol snd = (StringWithSymbol)_snd;
- int d = str.compareTo(snd.str);
- if (d != 0) return d;
- return _symbol.compareTo(snd._symbol);
- }
+ int d = str.compareTo(snd.str);
+ if (d != 0) return d;
+ return _symbol.compareTo(snd._symbol);
}
};