From b467b68f7b47a2c65fc4530221223f07bcd9a37d Mon Sep 17 00:00:00 2001 From: Henrik Grimler Date: Fri, 1 Jan 2021 17:27:05 +0100 Subject: [PATCH 1/2] terminal-view: mv code to get properties to its own function --- .../java/com/termux/view/TerminalView.java | 43 +++++++++++++------ 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/terminal-view/src/main/java/com/termux/view/TerminalView.java b/terminal-view/src/main/java/com/termux/view/TerminalView.java index b9df06f9..84285bca 100644 --- a/terminal-view/src/main/java/com/termux/view/TerminalView.java +++ b/terminal-view/src/main/java/com/termux/view/TerminalView.java @@ -255,20 +255,7 @@ public final class TerminalView extends View { @Override public InputConnection onCreateInputConnection(EditorInfo outAttrs) { - File propsFile = new File(getContext().getFilesDir() + "/home/.termux/termux.properties"); - if (!propsFile.exists()) - propsFile = new File(getContext().getFilesDir() + "/home/.config/termux/termux.properties"); - - Properties props = new Properties(); - try { - if (propsFile.isFile() && propsFile.canRead()) { - try (FileInputStream in = new FileInputStream(propsFile)) { - props.load(new InputStreamReader(in, StandardCharsets.UTF_8)); - } - } - } catch (Exception e) { - Log.e("termux", "Error loading props", e); - } + Properties props = getProperties(); if (props.getProperty("enforce-char-based-input", "false").equals("true")) { // Some keyboards seems do not reset the internal state on TYPE_NULL. @@ -1544,6 +1531,34 @@ public final class TerminalView extends View { } } + private Properties getProperties() { + File propsFile; + Properties props = new Properties(); + String possiblePropLocations[] = { + getContext().getFilesDir() + "/home/.termux/termux.properties", + getContext().getFilesDir() + "/home/.config/termux/termux.properties" + }; + + propsFile = new File(possiblePropLocations[0]); + int i = 1; + while (!propsFile.exists() && i <= possiblePropLocations.length) { + propsFile = new File(possiblePropLocations[i]); + i += 1; + } + + try { + if (propsFile.isFile() && propsFile.canRead()) { + try (FileInputStream in = new FileInputStream(propsFile)) { + props.load(new InputStreamReader(in, StandardCharsets.UTF_8)); + } + } + } catch (Exception e) { + Log.e("termux", "Error loading props", e); + } + + return props; + } + @RequiresApi(api = Build.VERSION_CODES.O) @Override public void autofill(AutofillValue value) { From f1e973f0d2000957a21387a8ee2f65bd08c776fb Mon Sep 17 00:00:00 2001 From: Henrik Grimler Date: Tue, 7 Jul 2020 18:04:47 +0200 Subject: [PATCH 2/2] terminal-view: add "ctrl-space-workaround" property Makes it possible to run ctrl+space with hardware keyboards on devices/ROMs where it otherwise is broken. On devices where it already works this workaround breaks ctrl+space though. Where to add this fix was investigated and found by @5bodnar. --- .../src/main/java/com/termux/view/TerminalView.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/terminal-view/src/main/java/com/termux/view/TerminalView.java b/terminal-view/src/main/java/com/termux/view/TerminalView.java index 84285bca..43392523 100644 --- a/terminal-view/src/main/java/com/termux/view/TerminalView.java +++ b/terminal-view/src/main/java/com/termux/view/TerminalView.java @@ -539,6 +539,8 @@ public final class TerminalView extends View { @Override public boolean onKeyPreIme(int keyCode, KeyEvent event) { + Properties props = getProperties(); + if (LOG_KEY_EVENTS) Log.i(EmulatorDebug.LOG_TAG, "onKeyPreIme(keyCode=" + keyCode + ", event=" + event + ")"); if (keyCode == KeyEvent.KEYCODE_BACK) { @@ -554,6 +556,11 @@ public final class TerminalView extends View { return onKeyUp(keyCode, event); } } + } else if (props.getProperty("ctrl-space-workaround", "false").equals("true") && + keyCode == KeyEvent.KEYCODE_SPACE && event.isCtrlPressed()) { + /* ctrl + space does not work on some ROMs without this workaround. + However, this breaks it on devices where it works out of the box. */ + return onKeyDown(keyCode, event); } return super.onKeyPreIme(keyCode, event); }