Skip to content
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
1 change: 1 addition & 0 deletions .github/workflows/debug_build.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Build

on:
workflow_dispatch:
push:
branches:
- master
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ public void putBoolean(String key, boolean value) {
case "terminal_margin_adjustment":
mPreferences.setTerminalMarginAdjustment(value);
break;
case "swap_mouse_right_click":
mPreferences.setSwapMouseRightClick(value);
break;
default:
break;
}
Expand All @@ -69,6 +72,8 @@ public boolean getBoolean(String key, boolean defValue) {
switch (key) {
case "terminal_margin_adjustment":
return mPreferences.isTerminalMarginAdjustmentEnabled();
case "swap_mouse_right_click":
return mPreferences.shouldSwapMouseRightClick();
default:
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -799,4 +799,8 @@ public void doPaste() {
session.getEmulator().paste(text);
}

@Override
public boolean shouldSwapMouseRightClick() {
return mActivity.getPreferences().shouldSwapMouseRightClick();
}
}
5 changes: 5 additions & 0 deletions app/src/main/res/xml/termux_terminal_view_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
app:summaryOn="@string/termux_terminal_view_terminal_margin_adjustment_on"
app:title="@string/termux_terminal_view_terminal_margin_adjustment_title" />

<SwitchPreferenceCompat
app:key="swap_mouse_right_click"
app:title="Swap mouse right click"
app:summary="Right click shows copy/paste, long press shows the menu" />

</PreferenceCategory>

</PreferenceScreen>
22 changes: 21 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 @@ -248,6 +248,12 @@ public boolean onDoubleTap(MotionEvent event) {

@Override
public void onLongPress(MotionEvent event) {
if (mClient.shouldSwapMouseRightClick()
&& event.isFromSource(InputDevice.SOURCE_MOUSE)
&& isEmptyAreaAt(event)) {
showContextMenu();
return;
}
if (mGestureRecognizer.isInProgress()) return;
if (mClient.onLongPress(event)) return;
if (!isSelectingText()) {
Expand Down Expand Up @@ -614,7 +620,10 @@ public boolean onTouchEvent(MotionEvent event) {
return true;
} else if (event.isFromSource(InputDevice.SOURCE_MOUSE)) {
if (event.isButtonPressed(MotionEvent.BUTTON_SECONDARY)) {
if (action == MotionEvent.ACTION_DOWN) showContextMenu();
if (action == MotionEvent.ACTION_DOWN) {
if (mClient.shouldSwapMouseRightClick() && isEmptyAreaAt(event)) startTextSelectionMode(event);
else showContextMenu();
}
return true;
} else if (event.isButtonPressed(MotionEvent.BUTTON_TERTIARY)) {
ClipboardManager clipboardManager = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
Expand Down Expand Up @@ -1517,4 +1526,15 @@ public void updateFloatingToolbarVisibility(MotionEvent event) {
}
}

private boolean isEmptyAreaAt(MotionEvent event) {
if (mEmulator == null) return true;
try {
int[] cr = getColumnAndRow(event, true);
String t = mEmulator.getScreen().getSelectedText(cr[0], cr[1], cr[0], cr[1]);
return t == null || t.trim().isEmpty();
} catch (Exception e) {
return false; // on any problem, behave normally (no swap)
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,5 @@ public interface TerminalViewClient {

void logStackTrace(String tag, Exception e);

boolean shouldSwapMouseRightClick();
}
Original file line number Diff line number Diff line change
Expand Up @@ -258,4 +258,14 @@ public void setCrashReportNotificationsEnabled(boolean value) {
SharedPreferenceUtils.setBoolean(mSharedPreferences, TERMUX_APP.KEY_CRASH_REPORT_NOTIFICATIONS_ENABLED, value, false);
}

public boolean shouldSwapMouseRightClick() {
return SharedPreferenceUtils.getBoolean(mSharedPreferences,
TERMUX_APP.KEY_SWAP_MOUSE_RIGHT_CLICK,
TERMUX_APP.DEFAULT_VALUE_SWAP_MOUSE_RIGHT_CLICK);
}

public void setSwapMouseRightClick(boolean value) {
SharedPreferenceUtils.setBoolean(mSharedPreferences,
TERMUX_APP.KEY_SWAP_MOUSE_RIGHT_CLICK, value, true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@ public static final class TERMUX_APP {
public static final String KEY_CRASH_REPORT_NOTIFICATIONS_ENABLED = "crash_report_notifications_enabled";
public static final boolean DEFAULT_VALUE_CRASH_REPORT_NOTIFICATIONS_ENABLED = true;

/**
* Defines the key for whether swap action between right mouse click and left mouse hold or not.
*/
public static final String KEY_SWAP_MOUSE_RIGHT_CLICK = "swap_mouse_right_click";
public static final boolean DEFAULT_VALUE_SWAP_MOUSE_RIGHT_CLICK = false;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public boolean shouldUseCtrlSpaceWorkaround() {
return false;
}

public boolean shouldSwapMouseRightClick() {
return false;
}

@Override
public boolean isTerminalViewSelected() {
return true;
Expand Down