diff --git a/app/src/main/java/com/termux/app/TermuxViewClient.java b/app/src/main/java/com/termux/app/TermuxViewClient.java index b6eea4d3..1af1622e 100644 --- a/app/src/main/java/com/termux/app/TermuxViewClient.java +++ b/app/src/main/java/com/termux/app/TermuxViewClient.java @@ -52,6 +52,16 @@ public final class TermuxViewClient implements TerminalViewClient { return mActivity.mProperties.isBackKeyTheEscapeKey(); } + @Override + public boolean shouldEnforeCharBasedInput() { + return mActivity.mProperties.isEnforcingCharBasedInput(); + } + + @Override + public boolean shouldUseCtrlSpaceWorkaround() { + return mActivity.mProperties.isUsingCtrlSpaceWorkaround(); + } + @Override public void copyModeChanged(boolean copyMode) { // Disable drawer while copying. diff --git a/app/src/main/java/com/termux/app/settings/properties/TermuxPropertyConstants.java b/app/src/main/java/com/termux/app/settings/properties/TermuxPropertyConstants.java index 859eeb5f..9b8731a6 100644 --- a/app/src/main/java/com/termux/app/settings/properties/TermuxPropertyConstants.java +++ b/app/src/main/java/com/termux/app/settings/properties/TermuxPropertyConstants.java @@ -61,11 +61,22 @@ public final class TermuxPropertyConstants { + /** Defines the key for whether to enforce character based input to fix the issue where for some devices like Samsung, the letters might not appear until enter is pressed */ + public static final String KEY_ENFORCE_CHAR_BASED_INPUT = "enforce-char-based-input"; // Default: "enforce-char-based-input" + + + + /** Defines the key for whether to use black UI */ public static final String KEY_USE_BLACK_UI = "use-black-ui"; // Default: "use-black-ui" + /** Defines the key for whether to use ctrl space workaround to fix the issue where ctrl+space does not work on some ROMs */ + public static final String KEY_USE_CTRL_SPACE_WORKAROUND = "ctrl-space-workaround"; // Default: "ctrl-space-workaround" + + + /** Defines the key for whether to use fullscreen */ public static final String KEY_USE_FULLSCREEN = "fullscreen"; // Default: "fullscreen" @@ -155,8 +166,10 @@ public final class TermuxPropertyConstants { * */ public static final Set TERMUX_PROPERTIES_LIST = new HashSet<>(Arrays.asList( // boolean + KEY_ENFORCE_CHAR_BASED_INPUT, KEY_USE_BACK_KEY_AS_ESCAPE_KEY, KEY_USE_BLACK_UI, + KEY_USE_CTRL_SPACE_WORKAROUND, KEY_USE_FULLSCREEN, KEY_USE_FULLSCREEN_WORKAROUND, KEY_VIRTUAL_VOLUME_KEYS_DISABLED, @@ -183,6 +196,8 @@ public final class TermuxPropertyConstants { * default: false * */ public static final Set TERMUX_DEFAULT_BOOLEAN_BEHAVIOUR_PROPERTIES_LIST = new HashSet<>(Arrays.asList( + KEY_ENFORCE_CHAR_BASED_INPUT, + KEY_USE_CTRL_SPACE_WORKAROUND, KEY_USE_FULLSCREEN, KEY_USE_FULLSCREEN_WORKAROUND, TermuxConstants.PROP_ALLOW_EXTERNAL_APPS diff --git a/app/src/main/java/com/termux/app/settings/properties/TermuxSharedProperties.java b/app/src/main/java/com/termux/app/settings/properties/TermuxSharedProperties.java index 4e2e9c7d..7e8ccdd8 100644 --- a/app/src/main/java/com/termux/app/settings/properties/TermuxSharedProperties.java +++ b/app/src/main/java/com/termux/app/settings/properties/TermuxSharedProperties.java @@ -485,6 +485,10 @@ public class TermuxSharedProperties implements SharedPropertiesParser { + public boolean isEnforcingCharBasedInput() { + return (boolean) getInternalPropertyValue(TermuxPropertyConstants.KEY_ENFORCE_CHAR_BASED_INPUT, true); + } + public boolean isBackKeyTheEscapeKey() { return (boolean) getInternalPropertyValue(TermuxPropertyConstants.KEY_USE_BACK_KEY_AS_ESCAPE_KEY, true); } @@ -493,6 +497,10 @@ public class TermuxSharedProperties implements SharedPropertiesParser { return (boolean) getInternalPropertyValue(TermuxPropertyConstants.KEY_USE_BLACK_UI, true); } + public boolean isUsingCtrlSpaceWorkaround() { + return (boolean) getInternalPropertyValue(TermuxPropertyConstants.KEY_USE_CTRL_SPACE_WORKAROUND, true); + } + public boolean isUsingFullScreen() { return (boolean) getInternalPropertyValue(TermuxPropertyConstants.KEY_USE_FULLSCREEN, true); } 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 383e3bf6..b9d18e69 100644 --- a/terminal-view/src/main/java/com/termux/view/TerminalView.java +++ b/terminal-view/src/main/java/com/termux/view/TerminalView.java @@ -37,12 +37,6 @@ import com.termux.terminal.TerminalEmulator; import com.termux.terminal.TerminalSession; import com.termux.view.textselection.TextSelectionCursorController; -import java.io.File; -import java.io.FileInputStream; -import java.io.InputStreamReader; -import java.nio.charset.StandardCharsets; -import java.util.Properties; - /** View displaying and interacting with a {@link TerminalSession}. */ public final class TerminalView extends View { @@ -246,9 +240,7 @@ public final class TerminalView extends View { @Override public InputConnection onCreateInputConnection(EditorInfo outAttrs) { - Properties props = getProperties(); - - if (props.getProperty("enforce-char-based-input", "false").equals("true")) { + if (mClient.shouldEnforeCharBasedInput()) { // Some keyboards seems do not reset the internal state on TYPE_NULL. // Affects mostly Samsung stock keyboards. // https://github.com/termux/termux-app/issues/686 @@ -529,8 +521,6 @@ 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) { @@ -546,9 +536,9 @@ public final class TerminalView extends View { return onKeyUp(keyCode, event); } } - } else if (props.getProperty("ctrl-space-workaround", "false").equals("true") && + } else if (mClient.shouldUseCtrlSpaceWorkaround() && keyCode == KeyEvent.KEYCODE_SPACE && event.isCtrlPressed()) { - /* ctrl + space does not work on some ROMs without this workaround. + /* 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); } @@ -961,36 +951,4 @@ 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 = 0; - 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; - } - } diff --git a/terminal-view/src/main/java/com/termux/view/TerminalViewClient.java b/terminal-view/src/main/java/com/termux/view/TerminalViewClient.java index d2b62fa1..390e9157 100644 --- a/terminal-view/src/main/java/com/termux/view/TerminalViewClient.java +++ b/terminal-view/src/main/java/com/termux/view/TerminalViewClient.java @@ -25,6 +25,10 @@ public interface TerminalViewClient { boolean shouldBackButtonBeMappedToEscape(); + boolean shouldEnforeCharBasedInput(); + + boolean shouldUseCtrlSpaceWorkaround(); + void copyModeChanged(boolean copyMode); boolean onKeyDown(int keyCode, KeyEvent e, TerminalSession session);