Skip to content

Commit

Permalink
add horisontal swipes
Browse files Browse the repository at this point in the history
  • Loading branch information
john-peterson committed Aug 17, 2024
1 parent 661c375 commit 23329e8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
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
35 changes: 34 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,11 @@ 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_WHEELUP_BUTTON
|| button == TerminalEmulator.MOUSE_WHEEL_LEFT
|| button == TerminalEmulator.MOUSE_WHEEL_RIGHT
)) {
if (mMouseStartDownTime == e.getDownTime()) {
x = mMouseScrollStartX;
y = mMouseScrollStartY;
Expand Down Expand Up @@ -549,6 +562,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

0 comments on commit 23329e8

Please sign in to comment.