Skip to content

Commit

Permalink
Fix issue where terminal cursor blinking would not automatically star…
Browse files Browse the repository at this point in the history
…t again if termux activity was restarted after exiting it with double back press
  • Loading branch information
agnostic-apollo committed Jun 10, 2021
1 parent f545ebf commit e119d34
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public class TermuxTerminalViewClient extends TermuxTerminalViewClientBase {
private boolean mShowSoftKeyboardIgnoreOnce;
private boolean mShowSoftKeyboardWithDelayOnce;

private boolean mTerminalCursorBlinkerStateAlreadySet;

private static final String LOG_TAG = "TermuxTerminalViewClient";

public TermuxTerminalViewClient(TermuxActivity activity, TermuxTerminalSessionClient termuxTerminalSessionClient) {
Expand Down Expand Up @@ -95,8 +97,7 @@ public void onResume() {
// Show the soft keyboard if required
setSoftKeyboardState(true, false);

// Start terminal cursor blinking if enabled
setTerminalCursorBlinkerState(true);
mTerminalCursorBlinkerStateAlreadySet = false;
}

/**
Expand All @@ -118,6 +119,23 @@ public void onReload() {
setTerminalCursorBlinkerState(true);
}

/**
* Should be called when {@link com.termux.view.TerminalView#mEmulator}
*/
@Override
public void onEmulatorSet() {
if (!mTerminalCursorBlinkerStateAlreadySet) {
// Start terminal cursor blinking if enabled
// We need to wait for the first session to be attached that's set in
// TermuxActivity.onServiceConnected() and then the multiple calls to TerminalView.updateSize()
// where the final one eventually sets the mEmulator when width/height is not 0. Otherwise
// blinker will not start again if TermuxActivity is started again after exiting it with
// double back press. Check TerminalView.setTerminalCursorBlinkerState().
setTerminalCursorBlinkerState(true);
mTerminalCursorBlinkerStateAlreadySet = true;
}
}



@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ public TerminalEmulator(TerminalOutput session, int columns, int rows, Integer t
public void updateTerminalSessionClient(TerminalSessionClient client) {
mClient = client;
setCursorStyle();
setCursorBlinkState(true);
}

public TerminalBuffer getScreen() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,7 @@ public void updateSize() {
if (mEmulator == null || (newColumns != mEmulator.mColumns || newRows != mEmulator.mRows)) {
mTermSession.updateSize(newColumns, newRows);
mEmulator = mTermSession.getEmulator();
mClient.onEmulatorSet();

mTopRow = 0;
scrollTo(0, 0);
Expand Down Expand Up @@ -880,7 +881,13 @@ public synchronized boolean setTerminalCursorBlinkerRate(int blinkRate) {
* {@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.
* 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)}.
*
* It should also be called on the
* {@link com.termux.terminal.TerminalSessionClient#onTerminalCursorStateChange(boolean)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public interface TerminalViewClient {
boolean onCodePoint(int codePoint, boolean ctrlDown, TerminalSession session);


void onEmulatorSet();


void logError(String tag, String message);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ public boolean onCodePoint(int codePoint, boolean ctrlDown, TerminalSession sess
return false;
}

@Override
public void onEmulatorSet() {

}

@Override
public void logError(String tag, String message) {
Logger.logError(tag, message);
Expand Down

0 comments on commit e119d34

Please sign in to comment.