aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar lvgx <l@vgx.fr>2020-03-01 08:10:35 +0100
committerGravatar GitHub <noreply@github.com>2020-03-01 12:40:35 +0530
commitb2f2b78990acb2bc6b02808433d05cfd7ec50fca (patch)
tree8e9b6572af4ee2149c22f181020873322e5d1796
parent2b11601f8905d9dfd1f9ae575497596e24832615 (diff)
downloadnnn-b2f2b78990acb2bc6b02808433d05cfd7ec50fca.tar.gz
Add right click file selection (#482)
-rw-r--r--src/nnn.c26
1 files changed, 22 insertions, 4 deletions
diff --git a/src/nnn.c b/src/nnn.c
index 0d9ad8a..b44ed61 100644
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -1458,9 +1458,11 @@ static bool initcurses(void *oldmask)
keypad(stdscr, TRUE);
#ifndef NOMOUSE
#if NCURSES_MOUSE_VERSION <= 1
- mousemask(BUTTON1_PRESSED | BUTTON1_DOUBLE_CLICKED, (mmask_t *)oldmask);
+ mousemask(BUTTON1_PRESSED | BUTTON1_DOUBLE_CLICKED | BUTTON3_PRESSED,
+ (mmask_t *)oldmask);
#else
- mousemask(BUTTON1_PRESSED | BUTTON4_PRESSED | BUTTON5_PRESSED, (mmask_t *)oldmask);
+ mousemask(BUTTON1_PRESSED | BUTTON3_PRESSED | BUTTON4_PRESSED | BUTTON5_PRESSED,
+ (mmask_t *)oldmask);
#endif
mouseinterval(0);
#endif
@@ -4949,6 +4951,7 @@ static bool browse(char *ipath, const char *session)
MEVENT event;
struct timespec mousetimings[2] = {{.tv_sec = 0, .tv_nsec = 0}, {.tv_sec = 0, .tv_nsec = 0} };
bool currentmouse = 1;
+ bool rightclicksel = 0;
#endif
#ifndef DIR_LIMITED_SELECTION
@@ -5162,9 +5165,18 @@ nochange:
}
/* Handle clicking on a file */
- if (event.y >= 2 && event.y <= ndents + 1 && event.bstate == BUTTON1_PRESSED) {
+ if (event.y >= 2 && event.y <= ndents + 1 &&
+ (event.bstate == BUTTON1_PRESSED ||
+ event.bstate == BUTTON3_PRESSED)) {
r = curscroll + (event.y - 2);
move_cursor(r, 1);
+
+ /* Handle right click selection */
+ if (event.bstate == BUTTON3_PRESSED) {
+ rightclicksel = 1;
+ goto selection;
+ }
+
currentmouse ^= 1;
clock_gettime(
#if defined(CLOCK_MONOTONIC_RAW)
@@ -5600,6 +5612,7 @@ nochange:
/* Repopulate as directory content may have changed */
goto begin;
}
+selection:
case SEL_SEL:
if (!ndents)
goto nochange;
@@ -5629,7 +5642,12 @@ nochange:
if (!nselected)
unlink(g_selpath);
-
+#ifndef NOMOUSE
+ if (rightclicksel) {
+ rightclicksel = 0;
+ break;
+ }
+#endif
/* move cursor to the next entry if this is not the last entry */
if (!cfg.picker && cur != ndents - 1)
move_cursor((cur + 1) % ndents, 0);