abouttreesummaryrefslogcommitdiff
path: root/srcs
diff options
context:
space:
mode:
authorJules Aguillon2025-01-12 19:16:04 +0100
committerJules Aguillon2025-01-12 19:16:04 +0100
commitbffc76907a2237323a3e810bd6043c9f811cf16f (patch)
tree9d2326b283cf2222c7ca23d4d4cd27c5413c8262 /srcs
parentca05c073d27e6e5faaf46970ae76d89a7e69a44a (diff)
downloadunexpected-keyboard-bffc76907a2237323a3e810bd6043c9f811cf16f.tar.gz
unexpected-keyboard-bffc76907a2237323a3e810bd6043c9f811cf16f.zip
Add cursor_up and cursor_down slider keys
Implement up and down cursor movement slider. This is not added to any layout yet due to the undesirable behavior when moving the focus out of the text box being edited.
Diffstat (limited to 'srcs')
-rw-r--r--srcs/juloo.keyboard2/KeyEventHandler.java75
-rw-r--r--srcs/juloo.keyboard2/KeyValue.java6
2 files changed, 46 insertions, 35 deletions
diff --git a/srcs/juloo.keyboard2/KeyEventHandler.java b/srcs/juloo.keyboard2/KeyEventHandler.java
index 45db719..471fad0 100644
--- a/srcs/juloo.keyboard2/KeyEventHandler.java
+++ b/srcs/juloo.keyboard2/KeyEventHandler.java
@@ -262,12 +262,15 @@ public final class KeyEventHandler
return conn.getExtractedText(_move_cursor_req, 0);
}
+ /** [repeatition] might be negative, in which case the direction is reversed. */
void handle_slider(KeyValue.Slider s, int repeatition)
{
switch (s)
{
case Cursor_left: move_cursor(-repeatition); break;
case Cursor_right: move_cursor(repeatition); break;
+ case Cursor_up: move_cursor_vertical(-repeatition); break;
+ case Cursor_down: move_cursor_vertical(repeatition); break;
}
}
@@ -283,47 +286,51 @@ public final class KeyEventHandler
ExtractedText et = get_cursor_pos(conn);
int system_mods =
KeyEvent.META_CTRL_ON | KeyEvent.META_ALT_ON | KeyEvent.META_META_ON;
- // Fallback to sending key events
- if (_move_cursor_force_fallback || et == null
- || (_meta_state & system_mods) != 0)
+ // Fallback to sending key events if system modifiers are activated or
+ // ExtractedText is not supported, for example on Termux.
+ if (!_move_cursor_force_fallback && et != null
+ && (_meta_state & system_mods) == 0)
{
- move_cursor_fallback(d);
- return;
- }
- int sel_start = et.selectionStart;
- int sel_end = et.selectionEnd;
- // Continue expanding the selection even if shift is not pressed
- if (sel_end != sel_start)
- {
- sel_end += d;
- if (sel_end == sel_start) // Avoid making the selection empty
+ int sel_start = et.selectionStart;
+ int sel_end = et.selectionEnd;
+ // Continue expanding the selection even if shift is not pressed
+ if (sel_end != sel_start)
+ {
+ sel_end += d;
+ if (sel_end == sel_start) // Avoid making the selection empty
+ sel_end += d;
+ }
+ else
+ {
sel_end += d;
+ // Leave 'sel_start' where it is if shift is pressed
+ if ((_meta_state & KeyEvent.META_SHIFT_ON) == 0)
+ sel_start = sel_end;
+ }
+ if (conn.setSelection(sel_start, sel_end))
+ return; // [setSelection] succeeded, don't fallback to key events
}
+ if (d < 0)
+ send_key_down_up_repeat(KeyEvent.KEYCODE_DPAD_LEFT, -d);
else
- {
- sel_end += d;
- // Leave 'sel_start' where it is if shift is pressed
- if ((_meta_state & KeyEvent.META_SHIFT_ON) == 0)
- sel_start = sel_end;
- }
- if (!conn.setSelection(sel_start, sel_end))
- move_cursor_fallback(d);
+ send_key_down_up_repeat(KeyEvent.KEYCODE_DPAD_RIGHT, d);
}
- /** Send arrow keys as a fallback for editors that do not support
- [getExtractedText] like Termux. */
- void move_cursor_fallback(int d)
+ /** Move the cursor up and down. This sends UP and DOWN key events that might
+ make the focus exit the text box. */
+ void move_cursor_vertical(int d)
{
- while (d < 0)
- {
- send_key_down_up(KeyEvent.KEYCODE_DPAD_LEFT);
- d++;
- }
- while (d > 0)
- {
- send_key_down_up(KeyEvent.KEYCODE_DPAD_RIGHT);
- d--;
- }
+ if (d < 0)
+ send_key_down_up_repeat(KeyEvent.KEYCODE_DPAD_UP, -d);
+ else
+ send_key_down_up_repeat(KeyEvent.KEYCODE_DPAD_DOWN, d);
+ }
+
+ /** Repeat calls to [send_key_down_up]. */
+ void send_key_down_up_repeat(int event_code, int repeat)
+ {
+ while (repeat-- > 0)
+ send_key_down_up(event_code);
}
public static interface IReceiver
diff --git a/srcs/juloo.keyboard2/KeyValue.java b/srcs/juloo.keyboard2/KeyValue.java
index 389bbac..3e8b7ff 100644
--- a/srcs/juloo.keyboard2/KeyValue.java
+++ b/srcs/juloo.keyboard2/KeyValue.java
@@ -687,6 +687,8 @@ public final class KeyValue implements Comparable<KeyValue>
case "redo": return editingKey(0xE037, Editing.REDO);
case "cursor_left": return sliderKey(Slider.Cursor_left, 1);
case "cursor_right": return sliderKey(Slider.Cursor_right, 1);
+ case "cursor_up": return sliderKey(Slider.Cursor_up, 1);
+ case "cursor_down": return sliderKey(Slider.Cursor_down, 1);
// These keys are not used
case "replaceText": return editingKey("repl", Editing.REPLACE);
case "textAssist": return editingKey(0xE038, Editing.ASSIST);
@@ -805,7 +807,9 @@ public final class KeyValue implements Comparable<KeyValue>
public static enum Slider
{
Cursor_left(0xE008),
- Cursor_right(0xE006);
+ Cursor_right(0xE006),
+ Cursor_up(0xE005),
+ Cursor_down(0xE007);
final String symbol;