Skip to content

Commit c6b4114

Browse files
Fix issue where a colour tint/highlight would be added to the terminal
This would happen when soft keyboard was to be disabled or hidden at startup and a hardware keyboard was attached and user started typing on hardware keyboard without tapping on the terminal first.
1 parent cce6dfe commit c6b4114

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

app/src/main/java/com/termux/app/terminal/TermuxTerminalViewClient.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -484,15 +484,22 @@ public void onToggleSoftKeyboardRequest() {
484484
}
485485

486486
public void setSoftKeyboardState(boolean isStartup, boolean isReloadTermuxProperties) {
487-
boolean noRequestFocus = false;
487+
boolean noShowKeyboard = false;
488+
489+
// Requesting terminal view focus is necessary regardless of if soft keyboard is to be
490+
// disabled or hidden at startup, otherwise if hardware keyboard is attached and user
491+
// starts typing on hardware keyboard without tapping on the terminal first, then a colour
492+
// tint will be added to the terminal as highlight for the focussed view. Test with a light
493+
// theme.
488494

489495
// If soft keyboard is disabled by user for Termux (check function docs for Termux behaviour info)
490496
if (KeyboardUtils.shouldSoftKeyboardBeDisabled(mActivity,
491497
mActivity.getPreferences().isSoftKeyboardEnabled(),
492498
mActivity.getPreferences().isSoftKeyboardEnabledOnlyIfNoHardware())) {
493499
Logger.logVerbose(LOG_TAG, "Maintaining disabled soft keyboard");
494500
KeyboardUtils.disableSoftKeyboard(mActivity, mActivity.getTerminalView());
495-
noRequestFocus = true;
501+
mActivity.getTerminalView().requestFocus();
502+
noShowKeyboard = true;
496503
// Delay is only required if onCreate() is called like when Termux app is exited with
497504
// double back press, not when Termux app is switched back from another app and keyboard
498505
// toggle is pressed to enable keyboard
@@ -508,10 +515,12 @@ public void setSoftKeyboardState(boolean isStartup, boolean isReloadTermuxProper
508515
// If soft keyboard is to be hidden on startup
509516
if (isStartup && mActivity.getProperties().shouldSoftKeyboardBeHiddenOnStartup()) {
510517
Logger.logVerbose(LOG_TAG, "Hiding soft keyboard on startup");
511-
KeyboardUtils.hideSoftKeyboard(mActivity, mActivity.getTerminalView());
512518
// Required to keep keyboard hidden when Termux app is switched back from another app
513519
KeyboardUtils.setSoftKeyboardAlwaysHiddenFlags(mActivity);
514-
noRequestFocus = true;
520+
521+
KeyboardUtils.hideSoftKeyboard(mActivity, mActivity.getTerminalView());
522+
mActivity.getTerminalView().requestFocus();
523+
noShowKeyboard = true;
515524
// Required to keep keyboard hidden on app startup
516525
mShowSoftKeyboardIgnoreOnce = true;
517526
}
@@ -541,7 +550,7 @@ public void onFocusChange(View view, boolean hasFocus) {
541550

542551
// Do not force show soft keyboard if termux-reload-settings command was run with hardware keyboard
543552
// or soft keyboard is to be hidden or is disabled
544-
if (!isReloadTermuxProperties && !noRequestFocus) {
553+
if (!isReloadTermuxProperties && !noShowKeyboard) {
545554
// Request focus for TerminalView
546555
// Also show the keyboard, since onFocusChange will not be called if TerminalView already
547556
// had focus on startup to show the keyboard, like when opening url with context menu

0 commit comments

Comments
 (0)