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

Added: Advanced Mouse Mode setting #4083

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 @@ -60,6 +60,9 @@ public void putBoolean(String key, boolean value) {
case "soft_keyboard_enabled_only_if_no_hardware":
mPreferences.setSoftKeyboardEnabledOnlyIfNoHardware(value);
break;
case "advanced_mouse":
mPreferences.setAdvancedMouse(value);
break;
default:
break;
}
Expand All @@ -74,6 +77,8 @@ public boolean getBoolean(String key, boolean defValue) {
return mPreferences.isSoftKeyboardEnabled();
case "soft_keyboard_enabled_only_if_no_hardware":
return mPreferences.isSoftKeyboardEnabledOnlyIfNoHardware();
case "advanced_mouse":
return mPreferences.isAdvancedMouse();
default:
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ public void onStart() {
boolean isTerminalViewKeyLoggingEnabled = mActivity.getPreferences().isTerminalViewKeyLoggingEnabled();
mActivity.getTerminalView().setIsTerminalViewKeyLoggingEnabled(isTerminalViewKeyLoggingEnabled);

// Set {@link TerminalView#ADVANCED_MOUSE} value
// Also required if user changed the preference from {@link TermuxSettings} activity and returns
boolean isAdvancedMouse = mActivity.getPreferences().isAdvancedMouse();
mActivity.getTerminalView().setAdvancedMouse(isAdvancedMouse);

// Piggyback on the terminal view key logging toggle for now, should add a separate toggle in future
mActivity.getTermuxActivityRootView().setIsRootViewLoggingEnabled(isTerminalViewKeyLoggingEnabled);
ViewUtils.setIsViewUtilsLoggingEnabled(isTerminalViewKeyLoggingEnabled);
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,15 @@
no hardware keyboard is connected.</string>


<!-- Mouse Category -->
<string name="termux_mouse_header">Mouse</string>

<!-- Touch Dragging -->
<string name="termux_advanced_mouse_title">Advanced Mouse Mode</string>
<string name="termux_advanced_mouse_off">Dragging the touch screen sends scroll wheel up/down events. (Default)</string>
<string name="termux_advanced_mouse_on">Dragging the touch screen sends mouse move events.</string>


<!-- Terminal View Preferences -->
<string name="termux_terminal_view_preferences_title">Terminal View</string>
<string name="termux_terminal_view_preferences_summary">Preferences for terminal view</string>
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/res/xml/termux_terminal_io_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,15 @@

</PreferenceCategory>

<PreferenceCategory
app:key="mouse"
app:title="@string/termux_mouse_header">

<SwitchPreferenceCompat
app:key="advanced_mouse"
app:summaryOff="@string/termux_advanced_mouse_off"
app:summaryOn="@string/termux_advanced_mouse_on"
app:title="@string/termux_advanced_mouse_title" />

</PreferenceCategory>
</PreferenceScreen>
15 changes: 14 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 @@ -47,6 +47,9 @@ public final class TerminalView extends View {
/** Log terminal view key and IME events. */
private static boolean TERMINAL_VIEW_KEY_LOGGING_ENABLED = false;

/** Send full mouse events for dragging the touch screen, rather than scroll-wheep up/down */
private static boolean ADVANCED_MOUSE = false;

/** The currently displayed terminal session, whose emulator is {@link #mEmulator}. */
public TerminalSession mTermSession;
/** Our terminal emulator whose session is {@link #mTermSession}. */
Expand Down Expand Up @@ -131,7 +134,8 @@ public boolean onSingleTapUp(MotionEvent event) {
@Override
public boolean onScroll(MotionEvent e, float distanceX, float distanceY) {
if (mEmulator == null) return true;
if (mEmulator.isMouseTrackingActive() && e.isFromSource(InputDevice.SOURCE_MOUSE)) {
if (ADVANCED_MOUSE || (mEmulator.isMouseTrackingActive() && e.isFromSource(InputDevice.SOURCE_MOUSE))) {
// Unless using advanced mouse mode:
// If moving with mouse pointer while pressing button, report that instead of scroll.
// This means that we never report moving with button press-events for touch input,
// since we cannot just start sending these events without a starting press event,
Expand Down Expand Up @@ -242,6 +246,15 @@ public void setIsTerminalViewKeyLoggingEnabled(boolean value) {
TERMINAL_VIEW_KEY_LOGGING_ENABLED = value;
}

/**
* Sets whether dragging the touch screen sends mouse move events, or up/down scroll wheel
*
* @param value True to send mouse swipe events, false for scroll wheel
*/
public void setAdvancedMouse(boolean value) {
ADVANCED_MOUSE = value;
}



/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ public void setSoftKeyboardEnabledOnlyIfNoHardware(boolean value) {
SharedPreferenceUtils.setBoolean(mSharedPreferences, TERMUX_APP.KEY_SOFT_KEYBOARD_ENABLED_ONLY_IF_NO_HARDWARE, value, false);
}

public boolean isAdvancedMouse() {
return SharedPreferenceUtils.getBoolean(mSharedPreferences, TERMUX_APP.KEY_ADVANCED_MOUSE, TERMUX_APP.DEFAULT_VALUE_KEY_ADVANCED_MOUSE);
}

public void setAdvancedMouse(boolean value) {
SharedPreferenceUtils.setBoolean(mSharedPreferences, TERMUX_APP.KEY_ADVANCED_MOUSE, value, false);
}



public boolean shouldKeepScreenOn() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.termux.shared.termux.settings.preferences;

/*
* Version: v0.16.0
* Version: v0.17.0
*
* Changelog
*
Expand Down Expand Up @@ -69,6 +69,10 @@
* - 0.16.0 (2022-06-11)
* - Added following to `TERMUX_APP`:
* `KEY_APP_SHELL_NUMBER_SINCE_BOOT` and `KEY_TERMINAL_SESSION_NUMBER_SINCE_BOOT`.
*
* - 0.17.0 (2024-08-07)
* - Added following to `TERMUX_APP`:
* `KEY_ADVANCED_MOUSE` and `DEFAULT_VALUE_KEY_ADVANCED_MOUSE`
*/

import com.termux.shared.shell.command.ExecutionCommand;
Expand Down Expand Up @@ -118,6 +122,12 @@ public static final class TERMUX_APP {
public static final boolean DEFAULT_VALUE_KEY_SOFT_KEYBOARD_ENABLED_ONLY_IF_NO_HARDWARE = false;


/**
* Defines the key for whether dragging the touch screen sends full mouse events instead of scroll wheel up/down
*/
public static final String KEY_ADVANCED_MOUSE = "advanced_mouse";
public static final boolean DEFAULT_VALUE_KEY_ADVANCED_MOUSE = false;

/**
* Defines the key for whether to always keep screen on.
*/
Expand Down