abouttreesummaryrefslogcommitdiff
diff options
context:
space:
mode:
-rw-r--r--res/xml/bottom_row.xml2
-rw-r--r--srcs/juloo.keyboard2/Config.java2
-rw-r--r--srcs/juloo.keyboard2/KeyboardData.java20
-rw-r--r--srcs/juloo.keyboard2/Pointers.java65
4 files changed, 79 insertions, 10 deletions
diff --git a/res/xml/bottom_row.xml b/res/xml/bottom_row.xml
index 64673fc..f9ec6f3 100644
--- a/res/xml/bottom_row.xml
+++ b/res/xml/bottom_row.xml
@@ -2,7 +2,7 @@
<row height="0.95">
<key width="1.8" key0="ctrl" key1="loc switch_greekmath" key2="loc meta" key4="switch_numeric"/>
<key width="1.2" key0="fn" key1="loc alt" key2="change_method" key3="switch_emoji" key4="config"/>
- <key width="4.0" key0="space" key1="switch_second" edgekeys="true"/>
+ <key width="4.0" key0="space" key1="switch_second" key3="left" key2="right" edgekeys="true" slider="true"/>
<key width="1.2" key1="up" key2="right" key3="left" key4="down" edgekeys="true"/>
<key width="1.8" key0="enter" key2="action"/>
</row>
diff --git a/srcs/juloo.keyboard2/Config.java b/srcs/juloo.keyboard2/Config.java
index b8580e6..b9546b2 100644
--- a/srcs/juloo.keyboard2/Config.java
+++ b/srcs/juloo.keyboard2/Config.java
@@ -29,6 +29,7 @@ final class Config
// From the 'numpad_layout' option, also apply to the numeric pane.
public boolean inverse_numpad = false;
public float swipe_dist_px;
+ public float slide_step_px;
public boolean vibrateEnabled;
public long longPressTimeout;
public long longPressInterval;
@@ -118,6 +119,7 @@ final class Config
float swipe_scaling = Math.min(dm.widthPixels, dm.heightPixels) / 10.f * dpi_ratio;
float swipe_dist_value = Float.valueOf(_prefs.getString("swipe_dist", "15"));
swipe_dist_px = swipe_dist_value / 25.f * swipe_scaling;
+ slide_step_px = swipe_dist_px / 4.f;
vibrateEnabled = _prefs.getBoolean("vibrate_enabled", true);
longPressTimeout = _prefs.getInt("longpress_timeout", 600);
longPressInterval = _prefs.getInt("longpress_interval", 65);
diff --git a/srcs/juloo.keyboard2/KeyboardData.java b/srcs/juloo.keyboard2/KeyboardData.java
index 550af40..542c173 100644
--- a/srcs/juloo.keyboard2/KeyboardData.java
+++ b/srcs/juloo.keyboard2/KeyboardData.java
@@ -285,9 +285,13 @@ class KeyboardData
public final float shift;
/** Put keys 1 to 4 on the edges instead of the corners. */
public final boolean edgekeys;
+ /** Keys 2 and 3 are repeated as the finger moves laterally on the key.
+ Used for the left and right arrow keys on the space bar. */
+ public final boolean slider;
+ /** String printed on the keys. It has no other effect. */
public final String indication;
- protected Key(Corner k0, Corner k1, Corner k2, Corner k3, Corner k4, float w, float s, boolean e, String i)
+ protected Key(Corner k0, Corner k1, Corner k2, Corner k3, Corner k4, float w, float s, boolean e, boolean sl, String i)
{
key0 = k0;
key1 = k1;
@@ -297,6 +301,7 @@ class KeyboardData
width = w;
shift = s;
edgekeys = e;
+ slider = sl;
indication = i;
}
@@ -310,17 +315,18 @@ class KeyboardData
float width = attribute_float(parser, "width", 1f);
float shift = attribute_float(parser, "shift", 0.f);
boolean edgekeys = attribute_bool(parser, "edgekeys", false);
+ boolean slider = attribute_bool(parser, "slider", false);
String indication = parser.getAttributeValue(null, "indication");
while (parser.next() != XmlPullParser.END_TAG)
continue ;
- return new Key(k0, k1, k2, k3, k4, width, shift, edgekeys, indication);
+ return new Key(k0, k1, k2, k3, k4, width, shift, edgekeys, slider, indication);
}
/** New key with the width multiplied by 's'. */
public Key scaleWidth(float s)
{
return new Key(key0, key1, key2, key3, key4, width * s, shift, edgekeys,
- indication);
+ slider, indication);
}
public KeyValue getKeyValue(int i)
@@ -350,12 +356,14 @@ class KeyboardData
case 3: k3 = k; break;
case 4: k4 = k; break;
}
- return new Key(k0, k1, k2, k3, k4, width, shift, edgekeys, indication);
+ return new Key(k0, k1, k2, k3, k4, width, shift, edgekeys, slider,
+ indication);
}
public Key withShift(float s)
{
- return new Key(key0, key1, key2, key3, key4, width, s, edgekeys, indication);
+ return new Key(key0, key1, key2, key3, key4, width, s, edgekeys, slider,
+ indication);
}
/**
@@ -464,7 +472,7 @@ class KeyboardData
{
return new Key(apply_key0(k.key0), apply(k.key1), apply(k.key2),
apply(k.key3), apply(k.key4), k.width, k.shift, k.edgekeys,
- k.indication);
+ k.slider, k.indication);
}
protected Corner apply_key0(Corner c)
diff --git a/srcs/juloo.keyboard2/Pointers.java b/srcs/juloo.keyboard2/Pointers.java
index 448fd4c..9ce34a2 100644
--- a/srcs/juloo.keyboard2/Pointers.java
+++ b/srcs/juloo.keyboard2/Pointers.java
@@ -147,6 +147,10 @@ public final class Pointers implements Handler.Callback
public void onTouchDown(float x, float y, int pointerId, KeyboardData.Key key)
{
+ // Ignore new presses while a sliding key is active. On some devices, ghost
+ // touch events can happen while the pointer travels on top of other keys.
+ if (isSliding())
+ return;
// Don't take latched modifiers into account if an other key is pressed.
// The other key already "own" the latched modifiers and will clear them.
Modifiers mods = getModifiers(isOtherPointerDown());
@@ -198,11 +202,16 @@ public final class Pointers implements Handler.Callback
// The position in a IME windows is clampled to view.
// For a better up swipe behaviour, set the y position to a negative value when clamped.
if (y == 0.0) y = -400;
-
float dx = x - ptr.downX;
float dy = y - ptr.downY;
- float dist = Math.abs(dx) + Math.abs(dy);
+ if (ptr.sliding)
+ {
+ onTouchMove_sliding(ptr, dx);
+ return;
+ }
+
+ float dist = Math.abs(dx) + Math.abs(dy);
int direction;
if (dist < _config.swipe_dist_px)
{
@@ -228,9 +237,21 @@ public final class Pointers implements Handler.Callback
KeyValue newValue = getKeyAtDirection(ptr, direction);
if (newValue != null && (ptr.value == null || !newValue.equals(ptr.value)))
{
- int old_flags = ptr.flags;
ptr.value = newValue;
ptr.flags = newValue.getFlags();
+ // Sliding mode is entered when key2 or key3 is down on a slider key.
+ if (ptr.key.slider)
+ {
+ switch (direction)
+ {
+ case 1:
+ case 8:
+ case 4:
+ case 5:
+ startSliding(ptr, dy);
+ break;
+ }
+ }
_handler.onPointerDown(true);
}
}
@@ -287,6 +308,14 @@ public final class Pointers implements Handler.Callback
_handler.onPointerFlagsChanged(shouldVibrate);
}
+ boolean isSliding()
+ {
+ for (Pointer ptr : _ptrs)
+ if (ptr.sliding)
+ return true;
+ return false;
+ }
+
// Key repeat
/** Message from [_keyrepeat_handler]. */
@@ -344,6 +373,30 @@ public final class Pointers implements Handler.Callback
return true;
}
+ // Sliding
+
+ void startSliding(Pointer ptr, float initial_dy)
+ {
+ stopKeyRepeat(ptr);
+ ptr.sliding = true;
+ ptr.sliding_count = (int)(initial_dy / _config.slide_step_px);
+ }
+
+ /** Handle move events for sliding pointers. [dx] is distance travelled from
+ [downX]. */
+ void onTouchMove_sliding(Pointer ptr, float dx)
+ {
+ int count = (int)(dx / _config.slide_step_px);
+ if (count == ptr.sliding_count)
+ return;
+ KeyValue newValue = handleKV(
+ (count < ptr.sliding_count) ? ptr.key.key3 : ptr.key.key2,
+ ptr.modifiers);
+ ptr.sliding_count = count;
+ ptr.value = newValue;
+ if (newValue != null)
+ _handler.onPointerHold(newValue, ptr.modifiers);
+ }
private static final class Pointer
{
@@ -363,6 +416,10 @@ public final class Pointers implements Handler.Callback
public int flags;
/** Identify timeout messages. */
public int timeoutWhat;
+ /** Whether the pointer is "sliding" laterally on a key. */
+ public boolean sliding;
+ /** Number of event already caused by sliding. */
+ public int sliding_count;
public Pointer(int p, KeyboardData.Key k, KeyValue v, float x, float y, Modifiers m)
{
@@ -375,6 +432,8 @@ public final class Pointers implements Handler.Callback
modifiers = m;
flags = (v == null) ? 0 : v.getFlags();
timeoutWhat = -1;
+ sliding = false;
+ sliding_count = 0;
}
}