@@ -53,6 +53,8 @@ public final class TerminalView extends View {
5353 /** Our terminal emulator whose session is {@link #mTermSession}. */
5454 public TerminalEmulator mEmulator ;
5555
56+ private boolean mIsMouseCursorMovementEnabled = false ;
57+
5658 public TerminalRenderer mRenderer ;
5759
5860 public TerminalViewClient mClient ;
@@ -295,6 +297,9 @@ public boolean attachSession(TerminalSession session) {
295297 mEmulator = null ;
296298 mCombiningAccent = 0 ;
297299
300+ android .content .SharedPreferences prefs = androidx .preference .PreferenceManager .getDefaultSharedPreferences (getContext ());
301+ mIsMouseCursorMovementEnabled = prefs .getBoolean ("mouse_cursor_movement_enabled" , false );
302+
298303 updateSize ();
299304
300305 // Wait with enabling the scrollbar until we have a terminal to get scroll position from.
@@ -611,11 +616,11 @@ public boolean onTouchEvent(MotionEvent event) {
611616 updateFloatingToolbarVisibility (event );
612617 mGestureRecognizer .onTouchEvent (event );
613618 return true ;
614- } else if (event .isFromSource (InputDevice .SOURCE_MOUSE )) {
615- if (event .isButtonPressed (MotionEvent .BUTTON_SECONDARY )) {
619+ } else if (event .isFromSource (InputDevice .SOURCE_MOUSE ) || event . isFromSource ( InputDevice . SOURCE_TOUCHSCREEN ) ) {
620+ if (event .isFromSource ( InputDevice . SOURCE_MOUSE ) && event . isButtonPressed (MotionEvent .BUTTON_SECONDARY )) {
616621 if (action == MotionEvent .ACTION_DOWN ) showContextMenu ();
617622 return true ;
618- } else if (event .isButtonPressed (MotionEvent .BUTTON_TERTIARY )) {
623+ } else if (event .isFromSource ( InputDevice . SOURCE_MOUSE ) && event . isButtonPressed (MotionEvent .BUTTON_TERTIARY )) {
619624 ClipboardManager clipboardManager = (ClipboardManager ) getContext ().getSystemService (Context .CLIPBOARD_SERVICE );
620625 ClipData clipData = clipboardManager .getPrimaryClip ();
621626 if (clipData != null ) {
@@ -636,6 +641,47 @@ public boolean onTouchEvent(MotionEvent event) {
636641 break ;
637642 }
638643 }
644+ else { // Mouse tracking is OFF, handle for the shell
645+ if (mIsMouseCursorMovementEnabled && event .getAction () == MotionEvent .ACTION_DOWN ) {
646+ // Get target row and column from the click
647+ int [] targetCoords = getColumnAndRow (event , false );
648+ int targetColumn = targetCoords [0 ];
649+ int targetRow = targetCoords [1 ];
650+ // Boundary Check
651+ try {
652+ String clickedChar = mEmulator .getScreen ().getSelectedText (targetColumn , targetRow , targetColumn + 1 , targetRow ).toString ();
653+ if (clickedChar == null || clickedChar .trim ().isEmpty ()) {
654+ return true ;
655+ }
656+ } catch (Exception e ) {
657+ return true ;
658+ }
659+
660+ // Get cursor's current visual position
661+ int currentRow = mEmulator .getCursorRow ();
662+ int currentColumn = mEmulator .getCursorCol ();
663+
664+ // Get the width of the terminal in characters
665+ int terminalWidth = mEmulator .mColumns ;
666+
667+ // Calculate the 1D index for both the click position and the cursor position.
668+ int targetIndex = (targetRow * terminalWidth ) + targetColumn ;
669+ int currentIndex = (currentRow * terminalWidth ) + currentColumn ;
670+
671+ int diff = targetIndex - currentIndex ;
672+
673+ // Send Left or Right commands
674+ if (diff > 0 ) { // Need to move right
675+ for (int i = 0 ; i < diff ; i ++) {
676+ handleKeyCode (android .view .KeyEvent .KEYCODE_DPAD_RIGHT , 0 );
677+ }
678+ } else if (diff < 0 ) { // Need to move left
679+ for (int i = 0 ; i < -diff ; i ++) {
680+ handleKeyCode (android .view .KeyEvent .KEYCODE_DPAD_LEFT , 0 );
681+ }
682+ }
683+ }
684+ }
639685 }
640686
641687 mGestureRecognizer .onTouchEvent (event );
@@ -1495,4 +1541,9 @@ public void updateFloatingToolbarVisibility(MotionEvent event) {
14951541 }
14961542 }
14971543
1544+ public void reloadPreferences () {
1545+ android .content .SharedPreferences prefs = androidx .preference .PreferenceManager .getDefaultSharedPreferences (getContext ());
1546+ mIsMouseCursorMovementEnabled = prefs .getBoolean ("mouse_cursor_movement_enabled" , false );
1547+ }
1548+
14981549}
0 commit comments