mirror of https://github.com/jarun/nnn.git
Mouseclicks are no longer delayed (#353)
This patch changes the mouseinterval to 0. And handles detection of doubleclicking events internally. This allows much faster response times for mouse clicks as nnn no longer has to wait for ncurses to confirm what type of click it was. It introduces a new config setting for changing how many milliseconds it may take for a double click to be registered.
This commit is contained in:
parent
49bee69490
commit
2ac22cfc9f
22
src/nnn.c
22
src/nnn.c
|
@ -107,6 +107,7 @@
|
||||||
#define S_BLKSIZE 512 /* S_BLKSIZE is missing on Android NDK (Termux) */
|
#define S_BLKSIZE 512 /* S_BLKSIZE is missing on Android NDK (Termux) */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define _ABSSUB(N, M) (((N) <= (M)) ? ((M) - (N)) : ((N) - (M)))
|
||||||
#define LEN(x) (sizeof(x) / sizeof(*(x)))
|
#define LEN(x) (sizeof(x) / sizeof(*(x)))
|
||||||
#undef MIN
|
#undef MIN
|
||||||
#define MIN(x, y) ((x) < (y) ? (x) : (y))
|
#define MIN(x, y) ((x) < (y) ? (x) : (y))
|
||||||
|
@ -1015,12 +1016,12 @@ static bool initcurses(mmask_t *oldmask)
|
||||||
//intrflush(stdscr, FALSE);
|
//intrflush(stdscr, FALSE);
|
||||||
keypad(stdscr, TRUE);
|
keypad(stdscr, TRUE);
|
||||||
#if NCURSES_MOUSE_VERSION <= 1
|
#if NCURSES_MOUSE_VERSION <= 1
|
||||||
mousemask(BUTTON1_CLICKED | BUTTON1_DOUBLE_CLICKED, oldmask);
|
mousemask(BUTTON1_PRESSED | BUTTON1_DOUBLE_CLICKED, oldmask);
|
||||||
#else
|
#else
|
||||||
mousemask(BUTTON1_CLICKED | BUTTON1_DOUBLE_CLICKED | BUTTON4_PRESSED | BUTTON5_PRESSED,
|
mousemask(BUTTON1_PRESSED | BUTTON4_PRESSED | BUTTON5_PRESSED,
|
||||||
oldmask);
|
oldmask);
|
||||||
#endif
|
#endif
|
||||||
mouseinterval(400);
|
mouseinterval(0);
|
||||||
curs_set(FALSE); /* Hide cursor */
|
curs_set(FALSE); /* Hide cursor */
|
||||||
start_color();
|
start_color();
|
||||||
use_default_colors();
|
use_default_colors();
|
||||||
|
@ -3542,6 +3543,8 @@ static void browse(char *ipath)
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
char *path, *lastdir, *lastname, *dir, *tmp;
|
char *path, *lastdir, *lastname, *dir, *tmp;
|
||||||
MEVENT event;
|
MEVENT event;
|
||||||
|
struct timespec mousetimings[2] = {{.tv_sec = 0, .tv_nsec = 0}, {.tv_sec = 0, .tv_nsec = 0}};
|
||||||
|
bool currentmouse = 1;
|
||||||
|
|
||||||
atexit(dentfree);
|
atexit(dentfree);
|
||||||
|
|
||||||
|
@ -3663,7 +3666,7 @@ nochange:
|
||||||
goto nochange; // fallthrough
|
goto nochange; // fallthrough
|
||||||
case SEL_BACK:
|
case SEL_BACK:
|
||||||
/* Handle clicking on a context at the top */
|
/* Handle clicking on a context at the top */
|
||||||
if (sel == SEL_CLICK && event.bstate == BUTTON1_CLICKED && event.y == 0) {
|
if (sel == SEL_CLICK && event.bstate == BUTTON1_PRESSED && event.y == 0) {
|
||||||
/* Get context from: "[1 2 3 4]..." */
|
/* Get context from: "[1 2 3 4]..." */
|
||||||
r = event.x >> 1;
|
r = event.x >> 1;
|
||||||
|
|
||||||
|
@ -3715,7 +3718,7 @@ nochange:
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Toggle filter mode on left click on last 2 lines */
|
/* Toggle filter mode on left click on last 2 lines */
|
||||||
if (event.y >= xlines - 2) {
|
if (event.y >= xlines - 2 && event.bstate == BUTTON1_PRESSED) {
|
||||||
cfg.filtermode ^= 1;
|
cfg.filtermode ^= 1;
|
||||||
if (cfg.filtermode) {
|
if (cfg.filtermode) {
|
||||||
presel = FILTER;
|
presel = FILTER;
|
||||||
|
@ -3731,13 +3734,18 @@ nochange:
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Handle clicking on a file */
|
/* Handle clicking on a file */
|
||||||
if (2 <= event.y && event.y <= ndents + 1) {
|
if (2 <= event.y && event.y <= ndents + 1 && event.bstate == BUTTON1_PRESSED) {
|
||||||
r = curscroll + (event.y - 2);
|
r = curscroll + (event.y - 2);
|
||||||
move_cursor(r, 1);
|
move_cursor(r, 1);
|
||||||
|
currentmouse ^= 1;
|
||||||
|
clock_gettime(CLOCK_MONOTONIC_RAW, &mousetimings[currentmouse]);
|
||||||
|
|
||||||
/*Single click just selects, double click also opens */
|
/*Single click just selects, double click also opens */
|
||||||
if (event.bstate != BUTTON1_DOUBLE_CLICKED)
|
if (((_ABSSUB(mousetimings[0].tv_sec, mousetimings[1].tv_sec) << 30)
|
||||||
|
+ (mousetimings[0].tv_nsec - mousetimings[1].tv_nsec))
|
||||||
|
> 400000000)
|
||||||
break;
|
break;
|
||||||
|
mousetimings[currentmouse].tv_sec = 0;
|
||||||
} else {
|
} else {
|
||||||
if (cfg.filtermode)
|
if (cfg.filtermode)
|
||||||
presel = FILTER;
|
presel = FILTER;
|
||||||
|
|
Loading…
Reference in New Issue