Skip to content

Commit

Permalink
Make TerminalView agnostic of "termux.properties" files.
Browse files Browse the repository at this point in the history
`TerminalView` will use the `TerminalViewClient` interface implemented by `TermuxViewClient` in termux-app to get "enforce-char-based-input" and "ctrl-space-workaround" property values. It will also not read the file every time it needs to get the property value and will get it from the in-memory cache of `TermuxSharedProperties`.
  • Loading branch information
agnostic-apollo committed Mar 11, 2021
1 parent 319446f commit 10d6eaa
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 45 deletions.
10 changes: 10 additions & 0 deletions app/src/main/java/com/termux/app/TermuxViewClient.java
Expand Up @@ -52,6 +52,16 @@ public boolean shouldBackButtonBeMappedToEscape() {
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.
Expand Down
Expand Up @@ -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"

Expand Down Expand Up @@ -155,8 +166,10 @@ public final class TermuxPropertyConstants {
* */
public static final Set<String> 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,
Expand All @@ -183,6 +196,8 @@ public final class TermuxPropertyConstants {
* default: false
* */
public static final Set<String> 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
Expand Down
Expand Up @@ -485,6 +485,10 @@ public static String getExtraKeysStyleInternalPropertyValueFromValue(String valu



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);
}
Expand All @@ -493,6 +497,10 @@ public boolean isUsingBlackUI() {
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);
}
Expand Down
48 changes: 3 additions & 45 deletions terminal-view/src/main/java/com/termux/view/TerminalView.java
Expand Up @@ -37,12 +37,6 @@
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 {

Expand Down Expand Up @@ -246,9 +240,7 @@ public boolean attachSession(TerminalSession session) {

@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
Expand Down Expand Up @@ -529,8 +521,6 @@ public boolean onTouchEvent(MotionEvent event) {

@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) {
Expand All @@ -546,9 +536,9 @@ public boolean onKeyPreIme(int keyCode, KeyEvent event) {
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);
}
Expand Down Expand Up @@ -961,36 +951,4 @@ public void updateFloatingToolbarVisibility(MotionEvent event) {
}
}





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;
}

}
Expand Up @@ -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);
Expand Down

0 comments on commit 10d6eaa

Please sign in to comment.