mirror of
https://github.com/jarun/nnn.git
synced 2025-01-09 17:39:38 +00:00
Added mouse support
This commit is contained in:
parent
ece7654221
commit
0eec240260
41
src/nnn.c
41
src/nnn.c
|
@ -871,6 +871,7 @@ static bool initcurses(void)
|
||||||
nonl();
|
nonl();
|
||||||
//intrflush(stdscr, FALSE);
|
//intrflush(stdscr, FALSE);
|
||||||
keypad(stdscr, TRUE);
|
keypad(stdscr, TRUE);
|
||||||
|
mousemask(BUTTON1_CLICKED | BUTTON1_DOUBLE_CLICKED, NULL);
|
||||||
curs_set(FALSE); /* Hide cursor */
|
curs_set(FALSE); /* Hide cursor */
|
||||||
start_color();
|
start_color();
|
||||||
use_default_colors();
|
use_default_colors();
|
||||||
|
@ -3034,6 +3035,7 @@ static void browse(char *ipath)
|
||||||
bool dir_changed = FALSE;
|
bool dir_changed = FALSE;
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
char *path, *lastdir, *lastname, *dir, *tmp;
|
char *path, *lastdir, *lastname, *dir, *tmp;
|
||||||
|
MEVENT event;
|
||||||
|
|
||||||
atexit(dentfree);
|
atexit(dentfree);
|
||||||
|
|
||||||
|
@ -3131,6 +3133,45 @@ nochange:
|
||||||
|
|
||||||
setdirwatch();
|
setdirwatch();
|
||||||
goto begin;
|
goto begin;
|
||||||
|
case SEL_CLICK:
|
||||||
|
if (getmouse(&event) != OK)
|
||||||
|
break;
|
||||||
|
// Handle clicking on a context at the top:
|
||||||
|
if (event.y == 0) {
|
||||||
|
// Get context from: "[1 2 3 4]..."
|
||||||
|
r = event.x/2;
|
||||||
|
if (event.x != 1 + 2*r)
|
||||||
|
break; // The character after the context number
|
||||||
|
if (0 <= r && r < CTX_MAX && r != cfg.curctx) {
|
||||||
|
savecurctx(&cfg, path, dents[cur].name, r);
|
||||||
|
|
||||||
|
/* Reset the pointers */
|
||||||
|
path = g_ctx[r].c_path;
|
||||||
|
lastdir = g_ctx[r].c_last;
|
||||||
|
lastname = g_ctx[r].c_name;
|
||||||
|
|
||||||
|
setdirwatch();
|
||||||
|
goto begin;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// Handle clicking on a file:
|
||||||
|
if (2 <= event.y && event.y < LINES - 2) {
|
||||||
|
r = 0;
|
||||||
|
if (cur-(LINES-4)/2 > 0)
|
||||||
|
r = cur-(LINES-4)/2;
|
||||||
|
if (ndents >= LINES-4 && ndents - (LINES-4) < r)
|
||||||
|
r = ndents - (LINES-4);
|
||||||
|
r += event.y - 2;
|
||||||
|
if (r >= ndents)
|
||||||
|
break;
|
||||||
|
cur = r;
|
||||||
|
// Single click just selects, double click also opens
|
||||||
|
if (event.bstate != BUTTON1_DOUBLE_CLICKED)
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
case SEL_NAV_IN: // fallthrough
|
case SEL_NAV_IN: // fallthrough
|
||||||
case SEL_GOIN:
|
case SEL_GOIN:
|
||||||
/* Cannot descend in empty directories */
|
/* Cannot descend in empty directories */
|
||||||
|
|
|
@ -102,6 +102,7 @@ enum action {
|
||||||
SEL_QUITCTX,
|
SEL_QUITCTX,
|
||||||
SEL_QUITCD,
|
SEL_QUITCD,
|
||||||
SEL_QUIT,
|
SEL_QUIT,
|
||||||
|
SEL_CLICK,
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Associate a pressed key to an action */
|
/* Associate a pressed key to an action */
|
||||||
|
@ -256,4 +257,5 @@ static struct key bindings[] = {
|
||||||
/* Quit */
|
/* Quit */
|
||||||
{ 'Q', SEL_QUIT },
|
{ 'Q', SEL_QUIT },
|
||||||
{ CONTROL('Q'), SEL_QUIT },
|
{ CONTROL('Q'), SEL_QUIT },
|
||||||
|
{ KEY_MOUSE, SEL_CLICK },
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue