Skip to content

Commit 7f20a06

Browse files
committed
add horisontal swipes
1 parent 661c375 commit 7f20a06

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

terminal-emulator/src/main/java/com/termux/terminal/TerminalEmulator.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ public final class TerminalEmulator {
3737
public static final int MOUSE_LEFT_BUTTON_MOVED = 32;
3838
public static final int MOUSE_WHEELUP_BUTTON = 64;
3939
public static final int MOUSE_WHEELDOWN_BUTTON = 65;
40+
41+
public static final int MOUSE_WHEEL_LEFT = 66;
42+
public static final int MOUSE_WHEEL_RIGHT = 67;
4043

4144
/** Used for invalid data - http://en.wikipedia.org/wiki/Replacement_character#Replacement_character */
4245
public static final int UNICODE_REPLACEMENT_CHAR = 0xFFFD;

terminal-view/src/main/java/com/termux/view/TerminalView.java

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public final class TerminalView extends View {
8181

8282
/** What was left in from scrolling movement. */
8383
float mScrollRemainder;
84+
float mScrollXRemainder;
8485

8586
/** If non-zero, this is the last unicode code point received if that was a combining character. */
8687
int mCombiningAccent;
@@ -104,6 +105,7 @@ public TerminalView(Context context, AttributeSet attributes) { // NO_UCD (unuse
104105
@Override
105106
public boolean onUp(MotionEvent event) {
106107
mScrollRemainder = 0.0f;
108+
mScrollXRemainder = 0.0f;
107109
if (mEmulator != null && mEmulator.isMouseTrackingActive() && !event.isFromSource(InputDevice.SOURCE_MOUSE) && !isSelectingText() && !scrolledWithFinger) {
108110
// Quick event processing when mouse tracking is active - do not wait for check of double tapping
109111
// for zooming.
@@ -143,6 +145,12 @@ public boolean onScroll(MotionEvent e, float distanceX, float distanceY) {
143145
int deltaRows = (int) (distanceY / mRenderer.mFontLineSpacing);
144146
mScrollRemainder = distanceY - deltaRows * mRenderer.mFontLineSpacing;
145147
doScroll(e, deltaRows);
148+
149+
distanceX += mScrollXRemainder;
150+
int deltaCols = (int) (distanceX / mRenderer.mFontWidth);
151+
mScrollXRemainder = distanceX - deltaCols * mRenderer.mFontWidth;
152+
//mClient.logError("scrolll", distanceY, distanceX);
153+
doScrollH(e, deltaCols);
146154
}
147155
return true;
148156
}
@@ -166,6 +174,7 @@ public boolean onFling(final MotionEvent e2, float velocityX, float velocityY) {
166174
if (mouseTrackingAtStartOfFling) {
167175
mScroller.fling(0, 0, 0, -(int) (velocityY * SCALE), 0, 0, -mEmulator.mRows / 2, mEmulator.mRows / 2);
168176
} else {
177+
//this doesn't fling in less
169178
mScroller.fling(0, mTopRow, 0, -(int) (velocityY * SCALE), 0, 0, -mEmulator.getScreen().getActiveTranscriptRows(), 0);
170179
}
171180

@@ -519,7 +528,11 @@ void sendMouseEventCode(MotionEvent e, int button, boolean pressed) {
519528
int[] columnAndRow = getColumnAndRow(e, false);
520529
int x = columnAndRow[0] + 1;
521530
int y = columnAndRow[1] + 1;
522-
if (pressed && (button == TerminalEmulator.MOUSE_WHEELDOWN_BUTTON || button == TerminalEmulator.MOUSE_WHEELUP_BUTTON)) {
531+
if (pressed && (button == TerminalEmulator.MOUSE_WHEELDOWN_BUTTON
532+
|| button == TerminalEmulator.MOUSE_WHEELUP_BUTTON
533+
|| button == TerminalEmulator.MOUSE_WHEEL_LEFT
534+
|| button == TerminalEmulator.MOUSE_WHEEL_RIGHT
535+
)) {
523536
if (mMouseStartDownTime == e.getDownTime()) {
524537
x = mMouseScrollStartX;
525538
y = mMouseScrollStartY;
@@ -549,6 +562,26 @@ void doScroll(MotionEvent event, int rowsDown) {
549562
}
550563
}
551564
}
565+
566+
void doScrollH(MotionEvent event, int cols) {
567+
boolean left = cols < 0;
568+
int amount = Math.abs(cols);
569+
for (int i = 0; i < amount; i++) {
570+
if (mEmulator.isMouseTrackingActive()) {
571+
sendMouseEventCode(event, left ? TerminalEmulator.MOUSE_WHEEL_LEFT : TerminalEmulator.MOUSE_WHEEL_RIGHT, true);
572+
} else if (mEmulator.isAlternateBufferActive()) {
573+
/* less is broken let me know if it works elsewhere @john-peterson
574+
handleKeyCode(left ? KeyEvent.KEYCODE_DPAD_LEFT : KeyEvent.KEYCODE_DPAD_RIGHT, 0);
575+
*/
576+
} else {
577+
/*
578+
mTopRow = Math.min(0, Math.max(-(mEmulator.getScreen().getActiveTranscriptRows()), mTopRow + (up ? -1 : 1)));
579+
if (!awakenScrollBars())
580+
invalidate();
581+
*/
582+
}
583+
}
584+
}
552585

553586
/** Overriding {@link View#onGenericMotionEvent(MotionEvent)}. */
554587
@Override

0 commit comments

Comments
 (0)