From a6f9c72eb3b68380d13ed7ff8b2366cb64b9ac52 Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Sat, 22 Feb 2025 11:41:13 +0100 Subject: [PATCH] Add 'delete_word' and 'forward_delete_word' keys These keys are the equivalent of ctrl+backspace and ctrl+delete, respectively. They can be reached with Gesture+backspace and Gesture+delete respectively. --- assets/special_font.ttf | Bin 20868 -> 22924 bytes doc/Possible-key-values.md | 14 ++++++------ srcs/juloo.keyboard2/KeyEventHandler.java | 25 +++++++++++++--------- srcs/juloo.keyboard2/KeyModifier.java | 7 ++++++ srcs/juloo.keyboard2/KeyValue.java | 4 ++++ srcs/special_font/01B.svg | 18 ++++++++++++++++ srcs/special_font/01C.svg | 18 ++++++++++++++++ 7 files changed, 70 insertions(+), 16 deletions(-) create mode 100644 srcs/special_font/01B.svg create mode 100644 srcs/special_font/01C.svg diff --git a/assets/special_font.ttf b/assets/special_font.ttf index c21ad2977549c297a76c1beb0c54a1ef005821af..da9274adb9db4a3ffc960e438cc4dea2b62ec241 100644 GIT binary patch delta 2551 zcmZo!%-FM;v7UjEfq{XCp@D&!!NEUR-^grh&?W{3Mh~E9LUL|mf$@1uCk6&)8wLg@ zv*fZ81qMZ?N(Khj5}-UwdSY?G|NlUp43RBBK1X^^W!m%&3obA)u(>cW_-bUNCZ;q- zzyAl6I|IaK89)K{hs>*h=Cc6#DjB&YkrkqkB&&b|D}Z=XPJVJ?^1 z3K(`W9R|v20Qm}eiMgo>m5P2048b`-2T2y>7ne*5{Sw8%5ZVEBMPir4 z^~5{Ge@SFW9Fw$=oFw@}Do*Nzw2pL(^gS6rnH{nkvQy+Z`R7F(#)HKwlY&K!z=Bc;(zn(>dX(^*4V;o~T1B0rvnmV(x z8ndyOxGl4}Et5HjL`GB*ffxcJ>uF#*$lXBq+cBCOvoQ&qiLr|ai1IP2D=8@JF{|q_ zssknLn8b`(75Nz1>*W~56`4i6m6V*krNbj6)fg!P!3v6;n%oh>UMtj$Seflq%>Qv& z2+0dbvB}pdh%VLTR+QA`WHSESuh^^zL`;Q=_4DTaJCeX?TD_Gbd&$;ZPe>;dAqAAl z6SN7c%4;caxFpmN= zr~@#e>oF~5%37O zSOyWrrU;)JCUHdeBqMLugE9-=JP4PCGvLJmU6Y|5y{CJxM{a*XCi3dVNK z<_5yR*wJHRQ)X2JW>8>0Rb;C6=GNnO@)q;skHnQG$PgzZ{RKP9$wyfHeWqs22Fl@# z-^_&+1f*E^i7wUS0_E?&XPF8i`TK8wy6I(;e@A>6#f)*djSTy7m_(lNptYaIwc46b@*=#ITX3dy9c~$7K$t7XeHb;dUF#!NkkbFG= diff --git a/doc/Possible-key-values.md b/doc/Possible-key-values.md index a5defef..0898341 100644 --- a/doc/Possible-key-values.md +++ b/doc/Possible-key-values.md @@ -87,12 +87,14 @@ These keys are sent to apps, which are free to ignore them. The keyboard does no ## Keyboard editing actions In contrast, these keys perform editing on the text without sending anything to the app. -Value | Meaning -:----------------- | :------ -`cursor_left` | Moves the cursor to the left with the slider gesture. -`cursor_right` | Moves the cursor to the right with the slider gesture. -`cursor_up` | Moves the cursor up with the slider gesture. Warning: this might make the cursor leave the text box. -`cursor_down` | Moves the cursor down with the slider gesture. Warning: this might make the cursor leave the text box. +Value | Meaning +:-------------------- | :------ +`cursor_left` | Moves the cursor to the left with the slider gesture. +`cursor_right` | Moves the cursor to the right with the slider gesture. +`cursor_up` | Moves the cursor up with the slider gesture. Warning: this might make the cursor leave the text box. +`cursor_down` | Moves the cursor down with the slider gesture. Warning: this might make the cursor leave the text box. +`delete_word` | Delete the word to the left of the cursor. +`forward_delete_word` | Delete the word to the right of the cursor. ## Whitespace Value | Meaning diff --git a/srcs/juloo.keyboard2/KeyEventHandler.java b/srcs/juloo.keyboard2/KeyEventHandler.java index 09efd59..a841c30 100644 --- a/srcs/juloo.keyboard2/KeyEventHandler.java +++ b/srcs/juloo.keyboard2/KeyEventHandler.java @@ -146,11 +146,11 @@ public final class KeyEventHandler if (down) { _meta_state = _meta_state | meta_flags; - send_keyevent(KeyEvent.ACTION_DOWN, eventCode); + send_keyevent(KeyEvent.ACTION_DOWN, eventCode, _meta_state); } else { - send_keyevent(KeyEvent.ACTION_UP, eventCode); + send_keyevent(KeyEvent.ACTION_UP, eventCode, _meta_state); _meta_state = _meta_state & ~meta_flags; } } @@ -181,25 +181,28 @@ public final class KeyEventHandler } } - /* - * Don't set KeyEvent.FLAG_SOFT_KEYBOARD. - */ void send_key_down_up(int keyCode) { - send_keyevent(KeyEvent.ACTION_DOWN, keyCode); - send_keyevent(KeyEvent.ACTION_UP, keyCode); + send_key_down_up(keyCode, _meta_state); } - void send_keyevent(int eventAction, int eventCode) + /** Ignores currently pressed system modifiers. */ + void send_key_down_up(int keyCode, int metaState) + { + send_keyevent(KeyEvent.ACTION_DOWN, keyCode, metaState); + send_keyevent(KeyEvent.ACTION_UP, keyCode, metaState); + } + + void send_keyevent(int eventAction, int eventCode, int metaState) { InputConnection conn = _recv.getCurrentInputConnection(); if (conn == null) return; conn.sendKeyEvent(new KeyEvent(1, 1, eventAction, eventCode, 0, - _meta_state, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, + metaState, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE)); if (eventAction == KeyEvent.ACTION_UP) - _autocap.event_sent(eventCode, _meta_state); + _autocap.event_sent(eventCode, metaState); } void send_text(CharSequence text) @@ -236,6 +239,8 @@ public final class KeyEventHandler case REPLACE: send_context_menu_action(android.R.id.replaceText); break; case ASSIST: send_context_menu_action(android.R.id.textAssist); break; case AUTOFILL: send_context_menu_action(android.R.id.autofill); break; + case DELETE_WORD: send_key_down_up(KeyEvent.KEYCODE_DEL, KeyEvent.META_CTRL_ON | KeyEvent.META_CTRL_LEFT_ON); break; + case FORWARD_DELETE_WORD: send_key_down_up(KeyEvent.KEYCODE_FORWARD_DEL, KeyEvent.META_CTRL_ON | KeyEvent.META_CTRL_LEFT_ON); break; } } diff --git a/srcs/juloo.keyboard2/KeyModifier.java b/srcs/juloo.keyboard2/KeyModifier.java index c9de407..bb33cca 100644 --- a/srcs/juloo.keyboard2/KeyModifier.java +++ b/srcs/juloo.keyboard2/KeyModifier.java @@ -381,6 +381,13 @@ public final class KeyModifier case SHIFT: name = "capslock"; break; } break; + case Keyevent: + switch (k.getKeyevent()) + { + case KeyEvent.KEYCODE_DEL: name = "delete_word"; break; + case KeyEvent.KEYCODE_FORWARD_DEL: name = "forward_delete_word"; break; + } + break; } return (name == null) ? k : KeyValue.getKeyByName(name); } diff --git a/srcs/juloo.keyboard2/KeyValue.java b/srcs/juloo.keyboard2/KeyValue.java index 2c5a03b..413520d 100644 --- a/srcs/juloo.keyboard2/KeyValue.java +++ b/srcs/juloo.keyboard2/KeyValue.java @@ -75,6 +75,8 @@ public final class KeyValue implements Comparable SHARE, ASSIST, AUTOFILL, + DELETE_WORD, + FORWARD_DELETE_WORD, } public static enum Placeholder @@ -707,6 +709,8 @@ public final class KeyValue implements Comparable case "pasteAsPlainText": return editingKey(0xE035, Editing.PASTE_PLAIN); case "undo": return editingKey(0xE036, Editing.UNDO); case "redo": return editingKey(0xE037, Editing.REDO); + case "delete_word": return editingKey(0xE01B, Editing.DELETE_WORD); + case "forward_delete_word": return editingKey(0xE01C, Editing.FORWARD_DELETE_WORD); 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); diff --git a/srcs/special_font/01B.svg b/srcs/special_font/01B.svg new file mode 100644 index 0000000..cd4d245 --- /dev/null +++ b/srcs/special_font/01B.svg @@ -0,0 +1,18 @@ + + + + + + + diff --git a/srcs/special_font/01C.svg b/srcs/special_font/01C.svg new file mode 100644 index 0000000..a92bd85 --- /dev/null +++ b/srcs/special_font/01C.svg @@ -0,0 +1,18 @@ + + + + + + +