mirror of
https://github.com/fankes/termux-app.git
synced 2025-09-06 02:35:19 +08:00
Make TerminalView agnostic of "termux.properties" files.
`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`.
This commit is contained in:
@@ -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.
|
||||
|
@@ -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<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,
|
||||
@@ -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
|
||||
|
@@ -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);
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user