From f77c88633e78469efe67ea5097941e22b330c5eb Mon Sep 17 00:00:00 2001 From: agnostic-apollo Date: Sun, 20 Jun 2021 05:57:57 +0500 Subject: [PATCH] Fix issue where terminal cursor blinking would not automatically start again if termux activity is started after device display timeout with double tap and not power button. Fixes #2138 --- .../app/terminal/TermuxTerminalViewClient.java | 9 +++++++++ .../main/java/com/termux/view/TerminalView.java | 17 ++++++++++------- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/termux/app/terminal/TermuxTerminalViewClient.java b/app/src/main/java/com/termux/app/terminal/TermuxTerminalViewClient.java index 6d49e9cc..99f2d8ef 100644 --- a/app/src/main/java/com/termux/app/terminal/TermuxTerminalViewClient.java +++ b/app/src/main/java/com/termux/app/terminal/TermuxTerminalViewClient.java @@ -98,6 +98,15 @@ public class TermuxTerminalViewClient extends TermuxTerminalViewClientBase { setSoftKeyboardState(true, false); mTerminalCursorBlinkerStateAlreadySet = false; + + if (mActivity.getTerminalView().mEmulator != null) { + // Start terminal cursor blinking if enabled + // If emulator is already set, then start blinker now, otherwise wait for onEmulatorSet() + // event to start it. This is needed since onEmulatorSet() may not be called after + // TermuxActivity is started after device display timeout with double tap and not power button. + setTerminalCursorBlinkerState(true); + mTerminalCursorBlinkerStateAlreadySet = 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 84756fed..dc86207c 100644 --- a/terminal-view/src/main/java/com/termux/view/TerminalView.java +++ b/terminal-view/src/main/java/com/termux/view/TerminalView.java @@ -881,13 +881,16 @@ public final class TerminalView extends View { * {@link #TERMINAL_CURSOR_BLINK_RATE_MIN} and {@link #TERMINAL_CURSOR_BLINK_RATE_MAX}. * * This should be called when the view holding this activity is resumed or stopped so that - * cursor blinker does not run when activity is not visible. Ensure that {@link #mEmulator} - * is set when you call this to start cursor blinking by waiting for {@link TerminalViewClient#onEmulatorSet()} - * event after calling {@link #attachSession(TerminalSession)} for the first session added in the - * activity, otherwise blinking will not start. Do not call this directly after - * {@link #attachSession(TerminalSession)} since {@link #updateSize()} may return without - * setting {@link #mEmulator} since width/height may be 0. Its called again in - * {@link #onSizeChanged(int, int, int, int)}. + * cursor blinker does not run when activity is not visible. If you call this on onResume() + * to start cursor blinking, then ensure that {@link #mEmulator} is set, otherwise wait for the + * {@link TerminalViewClient#onEmulatorSet()} event after calling {@link #attachSession(TerminalSession)} + * for the first session added in the activity since blinking will not start if {@link #mEmulator} + * is not set, like if activity is started again after exiting it with double back press. Do not + * call this directly after {@link #attachSession(TerminalSession)} since {@link #updateSize()} + * may return without setting {@link #mEmulator} since width/height may be 0. Its called again in + * {@link #onSizeChanged(int, int, int, int)}. Calling on onResume() if emulator is already set + * is necessary, since onEmulatorSet() may not be called after activity is started after device + * display timeout with double tap and not power button. * * It should also be called on the * {@link com.termux.terminal.TerminalSessionClient#onTerminalCursorStateChange(boolean)}