Changed: Do not modify code points for virtual or soft keyboard events

Closes #2799
This commit is contained in:
agnostic-apollo
2022-05-29 22:44:57 +05:00
parent c1c46dfcfc
commit 231ecff5f0
2 changed files with 28 additions and 19 deletions

View File

@@ -83,6 +83,12 @@ public final class TerminalView extends View {
private final boolean mAccessibilityEnabled; private final boolean mAccessibilityEnabled;
/** The {@link KeyEvent} is generated from a virtual keyboard, like manually with the {@link KeyEvent#KeyEvent(int, int)} constructor. */
public final static int KEY_EVENT_SOURCE_VIRTUAL_KEYBOARD = KeyCharacterMap.VIRTUAL_KEYBOARD; // -1
/** The {@link KeyEvent} is generated from a non-physical device, like if 0 value is returned by {@link KeyEvent#getDeviceId()}. */
public final static int KEY_EVENT_SOURCE_SOFT_KEYBOARD = 0;
private static final String LOG_TAG = "TerminalView"; private static final String LOG_TAG = "TerminalView";
public TerminalView(Context context, AttributeSet attributes) { // NO_UCD (unused code) public TerminalView(Context context, AttributeSet attributes) { // NO_UCD (unused code)
@@ -380,7 +386,7 @@ public final class TerminalView extends View {
} }
} }
inputCodePoint(codePoint, ctrlHeld, false); inputCodePoint(KEY_EVENT_SOURCE_SOFT_KEYBOARD, codePoint, ctrlHeld, false);
} }
} }
@@ -755,7 +761,7 @@ public final class TerminalView extends View {
if ((result & KeyCharacterMap.COMBINING_ACCENT) != 0) { if ((result & KeyCharacterMap.COMBINING_ACCENT) != 0) {
// If entered combining accent previously, write it out: // If entered combining accent previously, write it out:
if (mCombiningAccent != 0) if (mCombiningAccent != 0)
inputCodePoint(mCombiningAccent, controlDown, leftAltDown); inputCodePoint(event.getDeviceId(), mCombiningAccent, controlDown, leftAltDown);
mCombiningAccent = result & KeyCharacterMap.COMBINING_ACCENT_MASK; mCombiningAccent = result & KeyCharacterMap.COMBINING_ACCENT_MASK;
} else { } else {
if (mCombiningAccent != 0) { if (mCombiningAccent != 0) {
@@ -763,7 +769,7 @@ public final class TerminalView extends View {
if (combinedChar > 0) result = combinedChar; if (combinedChar > 0) result = combinedChar;
mCombiningAccent = 0; mCombiningAccent = 0;
} }
inputCodePoint(result, controlDown, leftAltDown); inputCodePoint(event.getDeviceId(), result, controlDown, leftAltDown);
} }
if (mCombiningAccent != oldCombiningAccent) invalidate(); if (mCombiningAccent != oldCombiningAccent) invalidate();
@@ -771,9 +777,9 @@ public final class TerminalView extends View {
return true; return true;
} }
public void inputCodePoint(int codePoint, boolean controlDownFromEvent, boolean leftAltDownFromEvent) { public void inputCodePoint(int eventSource, int codePoint, boolean controlDownFromEvent, boolean leftAltDownFromEvent) {
if (TERMINAL_VIEW_KEY_LOGGING_ENABLED) { if (TERMINAL_VIEW_KEY_LOGGING_ENABLED) {
mClient.logInfo(LOG_TAG, "inputCodePoint(codePoint=" + codePoint + ", controlDownFromEvent=" + controlDownFromEvent + ", leftAltDownFromEvent=" mClient.logInfo(LOG_TAG, "inputCodePoint(eventSource=" + eventSource + ", codePoint=" + codePoint + ", controlDownFromEvent=" + controlDownFromEvent + ", leftAltDownFromEvent="
+ leftAltDownFromEvent + ")"); + leftAltDownFromEvent + ")");
} }
@@ -813,6 +819,8 @@ public final class TerminalView extends View {
} }
if (codePoint > -1) { if (codePoint > -1) {
// If not virtual or soft keyboard.
if (eventSource > KEY_EVENT_SOURCE_SOFT_KEYBOARD) {
// Work around bluetooth keyboards sending funny unicode characters instead // Work around bluetooth keyboards sending funny unicode characters instead
// of the more normal ones from ASCII that terminal programs expect - the // of the more normal ones from ASCII that terminal programs expect - the
// desire to input the original characters should be low. // desire to input the original characters should be low.
@@ -827,6 +835,7 @@ public final class TerminalView extends View {
codePoint = 0x005E; // CIRCUMFLEX ACCENT (^). codePoint = 0x005E; // CIRCUMFLEX ACCENT (^).
break; break;
} }
}
// If left alt, send escape before the code point to make e.g. Alt+B and Alt+F work in readline: // If left alt, send escape before the code point to make e.g. Alt+B and Alt+F work in readline:
mTermSession.writeCodePoint(altDown, codePoint); mTermSession.writeCodePoint(altDown, codePoint);

View File

@@ -67,7 +67,7 @@ public class TerminalExtraKeys implements ExtraKeysView.IExtraKeysView {
// not a control char // not a control char
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
key.codePoints().forEach(codePoint -> { key.codePoints().forEach(codePoint -> {
mTerminalView.inputCodePoint(codePoint, ctrlDown, altDown); mTerminalView.inputCodePoint(TerminalView.KEY_EVENT_SOURCE_VIRTUAL_KEYBOARD, codePoint, ctrlDown, altDown);
}); });
} else { } else {
TerminalSession session = mTerminalView.getCurrentSession(); TerminalSession session = mTerminalView.getCurrentSession();