|
|
|
|
@@ -3,6 +3,7 @@ package com.termux.app;
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
import android.media.AudioManager;
|
|
|
|
|
import android.support.v4.widget.DrawerLayout;
|
|
|
|
|
import android.util.Log;
|
|
|
|
|
import android.view.Gravity;
|
|
|
|
|
import android.view.InputDevice;
|
|
|
|
|
import android.view.KeyEvent;
|
|
|
|
|
@@ -54,27 +55,31 @@ public final class TermuxKeyListener implements TerminalKeyListener {
|
|
|
|
|
mActivity.getDrawer().setDrawerLockMode(copyMode ? DrawerLayout.LOCK_MODE_LOCKED_CLOSED : DrawerLayout.LOCK_MODE_UNLOCKED);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void returnOnFinishedSession(TerminalSession currentSession) {
|
|
|
|
|
// Return pressed with finished session - remove it.
|
|
|
|
|
currentSession.finishIfRunning();
|
|
|
|
|
|
|
|
|
|
TermuxService service = mActivity.mTermService;
|
|
|
|
|
|
|
|
|
|
int index = service.removeTermSession(currentSession);
|
|
|
|
|
mActivity.mListViewAdapter.notifyDataSetChanged();
|
|
|
|
|
if (mActivity.mTermService.getSessions().isEmpty()) {
|
|
|
|
|
// There are no sessions to show, so finish the activity.
|
|
|
|
|
mActivity.finish();
|
|
|
|
|
} else {
|
|
|
|
|
if (index >= service.getSessions().size()) {
|
|
|
|
|
index = service.getSessions().size() - 1;
|
|
|
|
|
}
|
|
|
|
|
mActivity.switchToSession(service.getSessions().get(index));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onKeyDown(int keyCode, KeyEvent e, TerminalSession currentSession) {
|
|
|
|
|
if (handleVirtualKeys(keyCode, e, true)) return true;
|
|
|
|
|
|
|
|
|
|
TermuxService service = mActivity.mTermService;
|
|
|
|
|
|
|
|
|
|
if (keyCode == KeyEvent.KEYCODE_ENTER && !currentSession.isRunning()) {
|
|
|
|
|
// Return pressed with finished session - remove it.
|
|
|
|
|
currentSession.finishIfRunning();
|
|
|
|
|
|
|
|
|
|
int index = service.removeTermSession(currentSession);
|
|
|
|
|
mActivity.mListViewAdapter.notifyDataSetChanged();
|
|
|
|
|
if (mActivity.mTermService.getSessions().isEmpty()) {
|
|
|
|
|
// There are no sessions to show, so finish the activity.
|
|
|
|
|
mActivity.finish();
|
|
|
|
|
} else {
|
|
|
|
|
if (index >= service.getSessions().size()) {
|
|
|
|
|
index = service.getSessions().size() - 1;
|
|
|
|
|
}
|
|
|
|
|
mActivity.switchToSession(service.getSessions().get(index));
|
|
|
|
|
}
|
|
|
|
|
returnOnFinishedSession(currentSession);
|
|
|
|
|
return true;
|
|
|
|
|
} else if (e.isCtrlPressed() && e.isShiftPressed()) {
|
|
|
|
|
// Get the unmodified code point:
|
|
|
|
|
@@ -111,6 +116,7 @@ public final class TermuxKeyListener implements TerminalKeyListener {
|
|
|
|
|
mActivity.changeFontSize(false);
|
|
|
|
|
} else if (unicodeChar >= '1' && unicodeChar <= '9') {
|
|
|
|
|
int num = unicodeChar - '1';
|
|
|
|
|
TermuxService service = mActivity.mTermService;
|
|
|
|
|
if (service.getSessions().size() > num)
|
|
|
|
|
mActivity.switchToSession(service.getSessions().get(num));
|
|
|
|
|
}
|
|
|
|
|
@@ -237,6 +243,11 @@ public final class TermuxKeyListener implements TerminalKeyListener {
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
} else if (ctrlDown) {
|
|
|
|
|
if (codePoint == 106 /* Ctrl+j or \n */ && !session.isRunning()) {
|
|
|
|
|
returnOnFinishedSession(session);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<TermuxPreferences.KeyboardShortcut> shortcuts = mActivity.mSettings.shortcuts;
|
|
|
|
|
if (!shortcuts.isEmpty()) {
|
|
|
|
|
for (int i = shortcuts.size() - 1; i >= 0; i--) {
|
|
|
|
|
|