abouttreesummaryrefslogcommitdiff
path: root/srcs/juloo.keyboard2/Pointers.java
diff options
context:
space:
mode:
authorJules Aguillon2024-01-26 00:17:51 +0100
committerJules Aguillon2024-01-26 00:17:51 +0100
commitc5f2c0b727c0ef70a76e897402e0247f148553fc (patch)
tree80cbfd0435cbf29270485dee02fbebc85ec862e0 /srcs/juloo.keyboard2/Pointers.java
parentfb27f8d36f09e51e1988fb335e3fd9f34acb434e (diff)
downloadunexpected-keyboard-c5f2c0b727c0ef70a76e897402e0247f148553fc.tar.gz
unexpected-keyboard-c5f2c0b727c0ef70a76e897402e0247f148553fc.zip
Send down event for modifiers on time
This allows to use modifiers in combination with other inputs like a mouse click, for example under termux-x11. The key down event and notification about modifiers changing are sent down to KeyEventHandler. A mutable state remember for which modifier down events have been sent. When pressing down a modifier with one finger and typing with the other, it might appear that the modifier is released after the first time an other key is pressed and then pressed and released for the following keys. This prevents unintentionally type two modified keys instead of one when the second key is pressed while the other is not yet released.
Diffstat (limited to 'srcs/juloo.keyboard2/Pointers.java')
-rw-r--r--srcs/juloo.keyboard2/Pointers.java66
1 files changed, 65 insertions, 1 deletions
diff --git a/srcs/juloo.keyboard2/Pointers.java b/srcs/juloo.keyboard2/Pointers.java
index 00a2e3b..9f4bb6d 100644
--- a/srcs/juloo.keyboard2/Pointers.java
+++ b/srcs/juloo.keyboard2/Pointers.java
@@ -2,8 +2,10 @@ package juloo.keyboard2;
import android.os.Handler;
import android.os.Message;
-import java.util.Arrays;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
/**
* Manage pointers (fingers) on the screen and long presses.
@@ -95,6 +97,7 @@ public final class Pointers implements Handler.Callback
if (locked)
ptr.flags |= KeyValue.FLAG_LOCKED;
_ptrs.add(ptr);
+ _handler.onPointerFlagsChanged(false);
}
public void remove_fake_pointer(KeyValue kv, KeyboardData.Key key)
@@ -102,6 +105,7 @@ public final class Pointers implements Handler.Callback
Pointer ptr = getLatched(key, kv);
if (ptr != null && (ptr.flags & KeyValue.FLAG_FAKE_PTR) != 0)
removePtr(ptr);
+ _handler.onPointerFlagsChanged(false);
}
// Receiving events
@@ -483,6 +487,12 @@ public final class Pointers implements Handler.Callback
return (Arrays.binarySearch(_mods, 0, _size, m) >= 0);
}
+ /** Returns the activated modifiers that are not in [m2]. */
+ public Iterator<KeyValue.Modifier> diff(Modifiers m2)
+ {
+ return new ModifiersDiffIterator(this, m2);
+ }
+
@Override
public int hashCode() { return Arrays.hashCode(_mods); }
@Override
@@ -514,6 +524,60 @@ public final class Pointers implements Handler.Callback
}
return new Modifiers(mods, size);
}
+
+ /** Returns modifiers that are in [m1_] but not in [m2_]. */
+ static final class ModifiersDiffIterator
+ implements Iterator<KeyValue.Modifier>
+ {
+ Modifiers m1;
+ int i1 = 0;
+ Modifiers m2;
+ int i2 = 0;
+
+ public ModifiersDiffIterator(Modifiers m1_, Modifiers m2_)
+ {
+ m1 = m1_;
+ m2 = m2_;
+ advance();
+ }
+
+ public boolean hasNext()
+ {
+ return i1 < m1._size;
+ }
+
+ public KeyValue.Modifier next()
+ {
+ if (i1 >= m1._size)
+ throw new NoSuchElementException();
+ KeyValue.Modifier m = m1._mods[i1];
+ i1++;
+ advance();
+ return m;
+ }
+
+ /** Advance to the next element if [i1] is not a valid element. The end
+ is reached when [i1 = m1.size()]. */
+ void advance()
+ {
+ while (i1 < m1.size())
+ {
+ KeyValue.Modifier m = m1._mods[i1];
+ while (true)
+ {
+ if (i2 >= m2._size)
+ return;
+ int d = m.compareTo(m2._mods[i2]);
+ if (d < 0)
+ return;
+ i2++;
+ if (d == 0)
+ break;
+ }
+ i1++;
+ }
+ }
+ }
}
public interface IPointerEventHandler