Skip to content

Commit 5a55b72

Browse files
committed
Added: Advanced Mouse Mode setting
Adds a setting so users can choose whether dragging the touch screen sends mouse move events, or scroll wheel up/down. Defaults to scroll wheel (the old behavior). Closes termux#1384
1 parent 57e4ef4 commit 5a55b72

File tree

7 files changed

+63
-2
lines changed

7 files changed

+63
-2
lines changed

app/src/main/java/com/termux/app/fragments/settings/termux/TerminalIOPreferencesFragment.java

+5
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ public void putBoolean(String key, boolean value) {
6060
case "soft_keyboard_enabled_only_if_no_hardware":
6161
mPreferences.setSoftKeyboardEnabledOnlyIfNoHardware(value);
6262
break;
63+
case "advanced_mouse":
64+
mPreferences.setAdvancedMouse(value);
65+
break;
6366
default:
6467
break;
6568
}
@@ -74,6 +77,8 @@ public boolean getBoolean(String key, boolean defValue) {
7477
return mPreferences.isSoftKeyboardEnabled();
7578
case "soft_keyboard_enabled_only_if_no_hardware":
7679
return mPreferences.isSoftKeyboardEnabledOnlyIfNoHardware();
80+
case "advanced_mouse":
81+
return mPreferences.isAdvancedMouse();
7782
default:
7883
return false;
7984
}

app/src/main/java/com/termux/app/terminal/TermuxTerminalViewClient.java

+5
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ public void onStart() {
101101
boolean isTerminalViewKeyLoggingEnabled = mActivity.getPreferences().isTerminalViewKeyLoggingEnabled();
102102
mActivity.getTerminalView().setIsTerminalViewKeyLoggingEnabled(isTerminalViewKeyLoggingEnabled);
103103

104+
// Set {@link TerminalView#ADVANCED_MOUSE} value
105+
// Also required if user changed the preference from {@link TermuxSettings} activity and returns
106+
boolean isAdvancedMouse = mActivity.getPreferences().isAdvancedMouse();
107+
mActivity.getTerminalView().setAdvancedMouse(isAdvancedMouse);
108+
104109
// Piggyback on the terminal view key logging toggle for now, should add a separate toggle in future
105110
mActivity.getTermuxActivityRootView().setIsRootViewLoggingEnabled(isTerminalViewKeyLoggingEnabled);
106111
ViewUtils.setIsViewUtilsLoggingEnabled(isTerminalViewKeyLoggingEnabled);

app/src/main/res/values/strings.xml

+9
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,15 @@
188188
no hardware keyboard is connected.</string>
189189

190190

191+
<!-- Mouse Category -->
192+
<string name="termux_mouse_header">Mouse</string>
193+
194+
<!-- Touch Dragging -->
195+
<string name="termux_advanced_mouse_title">Advanced Mouse Mode</string>
196+
<string name="termux_advanced_mouse_off">Dragging the touch screen sends scroll wheel up/down events. (Default)</string>
197+
<string name="termux_advanced_mouse_on">Dragging the touch screen sends mouse move events.</string>
198+
199+
191200
<!-- Terminal View Preferences -->
192201
<string name="termux_terminal_view_preferences_title">Terminal View</string>
193202
<string name="termux_terminal_view_preferences_summary">Preferences for terminal view</string>

app/src/main/res/xml/termux_terminal_io_preferences.xml

+11
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,15 @@
1818

1919
</PreferenceCategory>
2020

21+
<PreferenceCategory
22+
app:key="mouse"
23+
app:title="@string/termux_mouse_header">
24+
25+
<SwitchPreferenceCompat
26+
app:key="advanced_mouse"
27+
app:summaryOff="@string/termux_advanced_mouse_off"
28+
app:summaryOn="@string/termux_advanced_mouse_on"
29+
app:title="@string/termux_advanced_mouse_title" />
30+
31+
</PreferenceCategory>
2132
</PreferenceScreen>

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

+14-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ public final class TerminalView extends View {
4747
/** Log terminal view key and IME events. */
4848
private static boolean TERMINAL_VIEW_KEY_LOGGING_ENABLED = false;
4949

50+
/** Send full mouse events for dragging the touch screen, rather than scroll-wheep up/down */
51+
private static boolean ADVANCED_MOUSE = false;
52+
5053
/** The currently displayed terminal session, whose emulator is {@link #mEmulator}. */
5154
public TerminalSession mTermSession;
5255
/** Our terminal emulator whose session is {@link #mTermSession}. */
@@ -131,7 +134,8 @@ public boolean onSingleTapUp(MotionEvent event) {
131134
@Override
132135
public boolean onScroll(MotionEvent e, float distanceX, float distanceY) {
133136
if (mEmulator == null) return true;
134-
if (mEmulator.isMouseTrackingActive() && e.isFromSource(InputDevice.SOURCE_MOUSE)) {
137+
if (ADVANCED_MOUSE || (mEmulator.isMouseTrackingActive() && e.isFromSource(InputDevice.SOURCE_MOUSE))) {
138+
// Unless using advanced mouse mode:
135139
// If moving with mouse pointer while pressing button, report that instead of scroll.
136140
// This means that we never report moving with button press-events for touch input,
137141
// since we cannot just start sending these events without a starting press event,
@@ -242,6 +246,15 @@ public void setIsTerminalViewKeyLoggingEnabled(boolean value) {
242246
TERMINAL_VIEW_KEY_LOGGING_ENABLED = value;
243247
}
244248

249+
/**
250+
* Sets whether dragging the touch screen sends mouse move events, or up/down scroll wheel
251+
*
252+
* @param value True to send mouse swipe events, false for scroll wheel
253+
*/
254+
public void setAdvancedMouse(boolean value) {
255+
ADVANCED_MOUSE = value;
256+
}
257+
245258

246259

247260
/**

termux-shared/src/main/java/com/termux/shared/termux/settings/preferences/TermuxAppSharedPreferences.java

+8
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,14 @@ public void setSoftKeyboardEnabledOnlyIfNoHardware(boolean value) {
110110
SharedPreferenceUtils.setBoolean(mSharedPreferences, TERMUX_APP.KEY_SOFT_KEYBOARD_ENABLED_ONLY_IF_NO_HARDWARE, value, false);
111111
}
112112

113+
public boolean isAdvancedMouse() {
114+
return SharedPreferenceUtils.getBoolean(mSharedPreferences, TERMUX_APP.KEY_ADVANCED_MOUSE, TERMUX_APP.DEFAULT_VALUE_KEY_ADVANCED_MOUSE);
115+
}
116+
117+
public void setAdvancedMouse(boolean value) {
118+
SharedPreferenceUtils.setBoolean(mSharedPreferences, TERMUX_APP.KEY_ADVANCED_MOUSE, value, false);
119+
}
120+
113121

114122

115123
public boolean shouldKeepScreenOn() {

termux-shared/src/main/java/com/termux/shared/termux/settings/preferences/TermuxPreferenceConstants.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.termux.shared.termux.settings.preferences;
22

33
/*
4-
* Version: v0.16.0
4+
* Version: v0.17.0
55
*
66
* Changelog
77
*
@@ -69,6 +69,10 @@
6969
* - 0.16.0 (2022-06-11)
7070
* - Added following to `TERMUX_APP`:
7171
* `KEY_APP_SHELL_NUMBER_SINCE_BOOT` and `KEY_TERMINAL_SESSION_NUMBER_SINCE_BOOT`.
72+
*
73+
* - 0.17.0 (2024-08-07)
74+
* - Added following to `TERMUX_APP`:
75+
* `KEY_ADVANCED_MOUSE` and `DEFAULT_VALUE_KEY_ADVANCED_MOUSE`
7276
*/
7377

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

120124

125+
/**
126+
* Defines the key for whether dragging the touch screen sends full mouse events instead of scroll wheel up/down
127+
*/
128+
public static final String KEY_ADVANCED_MOUSE = "advanced_mouse";
129+
public static final boolean DEFAULT_VALUE_KEY_ADVANCED_MOUSE = false;
130+
121131
/**
122132
* Defines the key for whether to always keep screen on.
123133
*/

0 commit comments

Comments
 (0)