From c5f2c0b727c0ef70a76e897402e0247f148553fc Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Fri, 26 Jan 2024 00:17:51 +0100 Subject: 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. --- srcs/juloo.keyboard2/Keyboard2View.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'srcs/juloo.keyboard2/Keyboard2View.java') diff --git a/srcs/juloo.keyboard2/Keyboard2View.java b/srcs/juloo.keyboard2/Keyboard2View.java index f9712e1..a4cfeb0 100644 --- a/srcs/juloo.keyboard2/Keyboard2View.java +++ b/srcs/juloo.keyboard2/Keyboard2View.java @@ -125,7 +125,6 @@ public class Keyboard2View extends View return; // Don't remove locked pointers _pointers.remove_fake_pointer(_shift_kv, _shift_key); } - invalidate(); } public KeyValue modifyKey(KeyValue k, Pointers.Modifiers mods) @@ -144,6 +143,7 @@ public class Keyboard2View extends View public void onPointerDown(KeyValue k, boolean isSwipe) { + updateFlags(); _config.handler.key_down(k, isSwipe); invalidate(); vibrate(); @@ -151,17 +151,22 @@ public class Keyboard2View extends View public void onPointerUp(KeyValue k, Pointers.Modifiers mods) { + // [key_up] must be called before [updateFlags]. The latter might disable + // flags. _config.handler.key_up(k, mods); + updateFlags(); invalidate(); } public void onPointerHold(KeyValue k, Pointers.Modifiers mods) { _config.handler.key_up(k, mods); + updateFlags(); } public void onPointerFlagsChanged(boolean shouldVibrate) { + updateFlags(); invalidate(); if (shouldVibrate) vibrate(); @@ -170,6 +175,7 @@ public class Keyboard2View extends View private void updateFlags() { _mods = _pointers.getModifiers(); + _config.handler.mods_changed(_mods); } @Override @@ -287,7 +293,6 @@ public class Keyboard2View extends View @Override protected void onDraw(Canvas canvas) { - updateFlags(); // Set keyboard background opacity getBackground().setAlpha(_config.keyboardOpacity); // Set keys opacity -- cgit v1.2.3