Skip to content

Commit 10d6eaa

Browse files
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`.
1 parent 319446f commit 10d6eaa

File tree

5 files changed

+40
-45
lines changed

5 files changed

+40
-45
lines changed

app/src/main/java/com/termux/app/TermuxViewClient.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,16 @@ public boolean shouldBackButtonBeMappedToEscape() {
5252
return mActivity.mProperties.isBackKeyTheEscapeKey();
5353
}
5454

55+
@Override
56+
public boolean shouldEnforeCharBasedInput() {
57+
return mActivity.mProperties.isEnforcingCharBasedInput();
58+
}
59+
60+
@Override
61+
public boolean shouldUseCtrlSpaceWorkaround() {
62+
return mActivity.mProperties.isUsingCtrlSpaceWorkaround();
63+
}
64+
5565
@Override
5666
public void copyModeChanged(boolean copyMode) {
5767
// Disable drawer while copying.

app/src/main/java/com/termux/app/settings/properties/TermuxPropertyConstants.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,22 @@ public final class TermuxPropertyConstants {
6161

6262

6363

64+
/** 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 */
65+
public static final String KEY_ENFORCE_CHAR_BASED_INPUT = "enforce-char-based-input"; // Default: "enforce-char-based-input"
66+
67+
68+
69+
6470
/** Defines the key for whether to use black UI */
6571
public static final String KEY_USE_BLACK_UI = "use-black-ui"; // Default: "use-black-ui"
6672

6773

6874

75+
/** Defines the key for whether to use ctrl space workaround to fix the issue where ctrl+space does not work on some ROMs */
76+
public static final String KEY_USE_CTRL_SPACE_WORKAROUND = "ctrl-space-workaround"; // Default: "ctrl-space-workaround"
77+
78+
79+
6980
/** Defines the key for whether to use fullscreen */
7081
public static final String KEY_USE_FULLSCREEN = "fullscreen"; // Default: "fullscreen"
7182

@@ -155,8 +166,10 @@ public final class TermuxPropertyConstants {
155166
* */
156167
public static final Set<String> TERMUX_PROPERTIES_LIST = new HashSet<>(Arrays.asList(
157168
// boolean
169+
KEY_ENFORCE_CHAR_BASED_INPUT,
158170
KEY_USE_BACK_KEY_AS_ESCAPE_KEY,
159171
KEY_USE_BLACK_UI,
172+
KEY_USE_CTRL_SPACE_WORKAROUND,
160173
KEY_USE_FULLSCREEN,
161174
KEY_USE_FULLSCREEN_WORKAROUND,
162175
KEY_VIRTUAL_VOLUME_KEYS_DISABLED,
@@ -183,6 +196,8 @@ public final class TermuxPropertyConstants {
183196
* default: false
184197
* */
185198
public static final Set<String> TERMUX_DEFAULT_BOOLEAN_BEHAVIOUR_PROPERTIES_LIST = new HashSet<>(Arrays.asList(
199+
KEY_ENFORCE_CHAR_BASED_INPUT,
200+
KEY_USE_CTRL_SPACE_WORKAROUND,
186201
KEY_USE_FULLSCREEN,
187202
KEY_USE_FULLSCREEN_WORKAROUND,
188203
TermuxConstants.PROP_ALLOW_EXTERNAL_APPS

app/src/main/java/com/termux/app/settings/properties/TermuxSharedProperties.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,10 @@ public static String getExtraKeysStyleInternalPropertyValueFromValue(String valu
485485

486486

487487

488+
public boolean isEnforcingCharBasedInput() {
489+
return (boolean) getInternalPropertyValue(TermuxPropertyConstants.KEY_ENFORCE_CHAR_BASED_INPUT, true);
490+
}
491+
488492
public boolean isBackKeyTheEscapeKey() {
489493
return (boolean) getInternalPropertyValue(TermuxPropertyConstants.KEY_USE_BACK_KEY_AS_ESCAPE_KEY, true);
490494
}
@@ -493,6 +497,10 @@ public boolean isUsingBlackUI() {
493497
return (boolean) getInternalPropertyValue(TermuxPropertyConstants.KEY_USE_BLACK_UI, true);
494498
}
495499

500+
public boolean isUsingCtrlSpaceWorkaround() {
501+
return (boolean) getInternalPropertyValue(TermuxPropertyConstants.KEY_USE_CTRL_SPACE_WORKAROUND, true);
502+
}
503+
496504
public boolean isUsingFullScreen() {
497505
return (boolean) getInternalPropertyValue(TermuxPropertyConstants.KEY_USE_FULLSCREEN, true);
498506
}

terminal-view/src/main/java/com/termux/view/TerminalView.java

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,6 @@
3737
import com.termux.terminal.TerminalSession;
3838
import com.termux.view.textselection.TextSelectionCursorController;
3939

40-
import java.io.File;
41-
import java.io.FileInputStream;
42-
import java.io.InputStreamReader;
43-
import java.nio.charset.StandardCharsets;
44-
import java.util.Properties;
45-
4640
/** View displaying and interacting with a {@link TerminalSession}. */
4741
public final class TerminalView extends View {
4842

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

247241
@Override
248242
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
249-
Properties props = getProperties();
250-
251-
if (props.getProperty("enforce-char-based-input", "false").equals("true")) {
243+
if (mClient.shouldEnforeCharBasedInput()) {
252244
// Some keyboards seems do not reset the internal state on TYPE_NULL.
253245
// Affects mostly Samsung stock keyboards.
254246
// https://github.com/termux/termux-app/issues/686
@@ -529,8 +521,6 @@ public boolean onTouchEvent(MotionEvent event) {
529521

530522
@Override
531523
public boolean onKeyPreIme(int keyCode, KeyEvent event) {
532-
Properties props = getProperties();
533-
534524
if (LOG_KEY_EVENTS)
535525
Log.i(EmulatorDebug.LOG_TAG, "onKeyPreIme(keyCode=" + keyCode + ", event=" + event + ")");
536526
if (keyCode == KeyEvent.KEYCODE_BACK) {
@@ -546,9 +536,9 @@ public boolean onKeyPreIme(int keyCode, KeyEvent event) {
546536
return onKeyUp(keyCode, event);
547537
}
548538
}
549-
} else if (props.getProperty("ctrl-space-workaround", "false").equals("true") &&
539+
} else if (mClient.shouldUseCtrlSpaceWorkaround() &&
550540
keyCode == KeyEvent.KEYCODE_SPACE && event.isCtrlPressed()) {
551-
/* ctrl + space does not work on some ROMs without this workaround.
541+
/* ctrl+space does not work on some ROMs without this workaround.
552542
However, this breaks it on devices where it works out of the box. */
553543
return onKeyDown(keyCode, event);
554544
}
@@ -961,36 +951,4 @@ public void updateFloatingToolbarVisibility(MotionEvent event) {
961951
}
962952
}
963953

964-
965-
966-
967-
968-
private Properties getProperties() {
969-
File propsFile;
970-
Properties props = new Properties();
971-
String possiblePropLocations[] = {
972-
getContext().getFilesDir() + "/home/.termux/termux.properties",
973-
getContext().getFilesDir() + "/home/.config/termux/termux.properties"
974-
};
975-
976-
propsFile = new File(possiblePropLocations[0]);
977-
int i = 0;
978-
while (!propsFile.exists() && i < possiblePropLocations.length) {
979-
propsFile = new File(possiblePropLocations[i]);
980-
i += 1;
981-
}
982-
983-
try {
984-
if (propsFile.isFile() && propsFile.canRead()) {
985-
try (FileInputStream in = new FileInputStream(propsFile)) {
986-
props.load(new InputStreamReader(in, StandardCharsets.UTF_8));
987-
}
988-
}
989-
} catch (Exception e) {
990-
Log.e("termux", "Error loading props", e);
991-
}
992-
993-
return props;
994-
}
995-
996954
}

terminal-view/src/main/java/com/termux/view/TerminalViewClient.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ public interface TerminalViewClient {
2525

2626
boolean shouldBackButtonBeMappedToEscape();
2727

28+
boolean shouldEnforeCharBasedInput();
29+
30+
boolean shouldUseCtrlSpaceWorkaround();
31+
2832
void copyModeChanged(boolean copyMode);
2933

3034
boolean onKeyDown(int keyCode, KeyEvent e, TerminalSession session);

0 commit comments

Comments
 (0)