diff options
author | Jeremy Klein <jlklein@google.com> | 2015-09-25 13:45:38 -0700 |
---|---|---|
committer | Jeremy Klein <jlklein@google.com> | 2015-10-01 14:56:39 -0700 |
commit | 4b2ce2fd665595e610523c62c928835c046ecabe (patch) | |
tree | b0a6a4e7fb726e0445abd0d5cd558d469255eb67 /app/src/main/java/org/connectbot/ConsoleActivity.java | |
parent | f5ff9f7bda5d05434471050533d404452275a38e (diff) | |
download | connectbot-4b2ce2fd665595e610523c62c928835c046ecabe.tar.gz connectbot-4b2ce2fd665595e610523c62c928835c046ecabe.tar.bz2 connectbot-4b2ce2fd665595e610523c62c928835c046ecabe.zip |
Forward mouseevents to the terminal when appropriate.
Only handle mouse events locally if shift is held.
Partially fixes #225. Still need to figure out mouse wheel forwarding
and proper copy support when the terminal is handling selection itself
(ie in an editor).
Diffstat (limited to 'app/src/main/java/org/connectbot/ConsoleActivity.java')
-rw-r--r-- | app/src/main/java/org/connectbot/ConsoleActivity.java | 75 |
1 files changed, 58 insertions, 17 deletions
diff --git a/app/src/main/java/org/connectbot/ConsoleActivity.java b/app/src/main/java/org/connectbot/ConsoleActivity.java index 5258bef..2f926e1 100644 --- a/app/src/main/java/org/connectbot/ConsoleActivity.java +++ b/app/src/main/java/org/connectbot/ConsoleActivity.java @@ -30,6 +30,7 @@ import org.connectbot.service.TerminalKeyListener; import org.connectbot.service.TerminalManager; import org.connectbot.util.PreferenceConstants; +import android.annotation.TargetApi; import android.app.AlertDialog; import android.app.Dialog; import android.content.ComponentName; @@ -743,31 +744,39 @@ public class ConsoleActivity extends AppCompatActivity implements BridgeDisconne pager.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { + TerminalBridge bridge = adapter.getCurrentTerminalView().bridge; + int row = (int) Math.floor(event.getY() / bridge.charHeight); + int col = (int) Math.floor(event.getX() / bridge.charWidth); // Handle mouse-specific actions. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH && - MotionEventCompat.getSource(event) == InputDevice.SOURCE_MOUSE && - event.getAction() == MotionEvent.ACTION_DOWN) { - switch (event.getButtonState()) { - case MotionEvent.BUTTON_PRIMARY: - // Automatically start copy mode if using a mouse. - startCopyMode(); - break; - case MotionEvent.BUTTON_SECONDARY: - openContextMenu(pager); - return true; - case MotionEvent.BUTTON_TERTIARY: - // Middle click pastes. - pasteIntoTerminal(); - return true; + MotionEventCompat.getSource(event) == InputDevice.SOURCE_MOUSE) { + int meta = event.getMetaState(); + boolean shiftOn = (event.getMetaState() & KeyEvent.META_SHIFT_ON) != 0; + if (shiftOn && event.getAction() == MotionEvent.ACTION_DOWN){ + switch (event.getButtonState()) { + case MotionEvent.BUTTON_PRIMARY: + // Automatically start copy mode if using a mouse. + startCopyMode(); + break; + case MotionEvent.BUTTON_SECONDARY: + openContextMenu(pager); + return true; + case MotionEvent.BUTTON_TERTIARY: + // Middle click pastes. + pasteIntoTerminal(); + return true; + } + } else if (event.getAction() == MotionEvent.ACTION_DOWN){ + ((vt320) bridge.buffer).mousePressed( + col, row, mouseEventToJavaModifiers(event)); + } else if (event.getAction() == MotionEvent.ACTION_UP){ + ((vt320) bridge.buffer).mouseReleased(col, row); } } // when copying, highlight the area if (copySource != null && copySource.isSelectingForCopy()) { - int row = (int) Math.floor(event.getY() / copySource.charHeight); - int col = (int) Math.floor(event.getX() / copySource.charWidth); - SelectionArea area = copySource.getSelectionArea(); switch (event.getAction()) { @@ -842,6 +851,38 @@ public class ConsoleActivity extends AppCompatActivity implements BridgeDisconne } /** + * + * @param mouseEvent + * @return + */ + @TargetApi(14) + private static int mouseEventToJavaModifiers(MotionEvent mouseEvent) { + if (MotionEventCompat.getSource(mouseEvent) != InputDevice.SOURCE_MOUSE) return 0; + + int mods = 0; + + // See http://docs.oracle.com/javase/7/docs/api/constant-values.html + int buttonState = mouseEvent.getButtonState(); + if ((buttonState & MotionEvent.BUTTON_PRIMARY) != 0) + mods |= 16; + if ((buttonState & MotionEvent.BUTTON_SECONDARY) != 0) + mods |= 8; + if ((buttonState & MotionEvent.BUTTON_TERTIARY) != 0) + mods |= 4; + + // Note: Meta and Ctrl are intentionally swapped here to keep logic in vt320 simple. + int meta = mouseEvent.getMetaState(); + if ((meta & KeyEvent.META_META_ON) != 0) + mods |= 2; + if ((meta & KeyEvent.META_SHIFT_ON) != 0) + mods |= 1; + if ((meta & KeyEvent.META_CTRL_ON) != 0) + mods |= 4; + + return mods; + } + + /** * Ties the {@link TabLayout} to the {@link ViewPager}. * * <p>This method will: |