Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add horisontal swipes #4108

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public final class TerminalEmulator {
public static final int MOUSE_LEFT_BUTTON_MOVED = 32;
public static final int MOUSE_WHEELUP_BUTTON = 64;
public static final int MOUSE_WHEELDOWN_BUTTON = 65;

public static final int MOUSE_WHEEL_LEFT = 66;
public static final int MOUSE_WHEEL_RIGHT = 67;

/** Used for invalid data - http://en.wikipedia.org/wiki/Replacement_character#Replacement_character */
public static final int UNICODE_REPLACEMENT_CHAR = 0xFFFD;
Expand Down
31 changes: 30 additions & 1 deletion terminal-view/src/main/java/com/termux/view/TerminalView.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public final class TerminalView extends View {

/** What was left in from scrolling movement. */
float mScrollRemainder;
float mScrollXRemainder;

/** If non-zero, this is the last unicode code point received if that was a combining character. */
int mCombiningAccent;
Expand All @@ -104,6 +105,7 @@ public TerminalView(Context context, AttributeSet attributes) { // NO_UCD (unuse
@Override
public boolean onUp(MotionEvent event) {
mScrollRemainder = 0.0f;
mScrollXRemainder = 0.0f;
if (mEmulator != null && mEmulator.isMouseTrackingActive() && !event.isFromSource(InputDevice.SOURCE_MOUSE) && !isSelectingText() && !scrolledWithFinger) {
// Quick event processing when mouse tracking is active - do not wait for check of double tapping
// for zooming.
Expand Down Expand Up @@ -143,6 +145,12 @@ public boolean onScroll(MotionEvent e, float distanceX, float distanceY) {
int deltaRows = (int) (distanceY / mRenderer.mFontLineSpacing);
mScrollRemainder = distanceY - deltaRows * mRenderer.mFontLineSpacing;
doScroll(e, deltaRows);

distanceX += mScrollXRemainder;
int deltaCols = (int) (distanceX / mRenderer.mFontWidth);
mScrollXRemainder = distanceX - deltaCols * mRenderer.mFontWidth;
//mClient.logError("scrolll", distanceY, distanceX);
doScrollX(e, deltaCols);
}
return true;
}
Expand All @@ -166,6 +174,7 @@ public boolean onFling(final MotionEvent e2, float velocityX, float velocityY) {
if (mouseTrackingAtStartOfFling) {
mScroller.fling(0, 0, 0, -(int) (velocityY * SCALE), 0, 0, -mEmulator.mRows / 2, mEmulator.mRows / 2);
} else {
//this doesn't fling in less
mScroller.fling(0, mTopRow, 0, -(int) (velocityY * SCALE), 0, 0, -mEmulator.getScreen().getActiveTranscriptRows(), 0);
}

Expand Down Expand Up @@ -519,7 +528,7 @@ void sendMouseEventCode(MotionEvent e, int button, boolean pressed) {
int[] columnAndRow = getColumnAndRow(e, false);
int x = columnAndRow[0] + 1;
int y = columnAndRow[1] + 1;
if (pressed && (button == TerminalEmulator.MOUSE_WHEELDOWN_BUTTON || button == TerminalEmulator.MOUSE_WHEELUP_BUTTON)) {
if (pressed && (button >= TerminalEmulator.MOUSE_WHEELDOWN_BUTTON && button <= TerminalEmulator.MOUSE_WHEEL_RIGHT)) {
if (mMouseStartDownTime == e.getDownTime()) {
x = mMouseScrollStartX;
y = mMouseScrollStartY;
Expand Down Expand Up @@ -549,6 +558,26 @@ void doScroll(MotionEvent event, int rowsDown) {
}
}
}

void doScrollX(MotionEvent event, int cols) {
boolean left = cols < 0;
int amount = Math.abs(cols);
for (int i = 0; i < amount; i++) {
if (mEmulator.isMouseTrackingActive()) {
sendMouseEventCode(event, left ? TerminalEmulator.MOUSE_WHEEL_LEFT : TerminalEmulator.MOUSE_WHEEL_RIGHT, true);
} else if (mEmulator.isAlternateBufferActive()) {
/* less is broken let me know if it works elsewhere @john-peterson
handleKeyCode(left ? KeyEvent.KEYCODE_DPAD_LEFT : KeyEvent.KEYCODE_DPAD_RIGHT, 0);
*/
} else {
/*
mTopRow = Math.min(0, Math.max(-(mEmulator.getScreen().getActiveTranscriptRows()), mTopRow + (up ? -1 : 1)));
if (!awakenScrollBars())
invalidate();
*/
}
}
}

/** Overriding {@link View#onGenericMotionEvent(MotionEvent)}. */
@Override
Expand Down