mirror of
git://git.sv.gnu.org/nano.git
synced 2024-11-22 04:41:21 +03:00
various mouse support-related simplifications, improvements, and fixes
git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@4107 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
This commit is contained in:
parent
7f8bfca081
commit
3a5eaeb401
11
ChangeLog
11
ChangeLog
@ -1,3 +1,14 @@
|
||||
2007-05-20 David Lawrence Ramsey <pooka109@gmail.com>
|
||||
|
||||
* nano.c (do_mouse), prompt.c (do_statusbar_mouse,
|
||||
do_yesno_prompt), winio.c (do_mouseinput): Fix processing of
|
||||
mouse events so that those we don't handle are ignored instead
|
||||
of being erroneously passed through.
|
||||
* winio.c (do_mouseinput): Simplify handling of mouse events
|
||||
involving the first mouse button.
|
||||
* winio.c (do_mouseinput): Improve mouse wheel support to only
|
||||
move the cursor if we're in the edit window or on the statusbar.
|
||||
|
||||
2007-05-15 David Lawrence Ramsey <pooka109@gmail.com>
|
||||
|
||||
* winio.c (do_mouseinput): Add mouse wheel support, per Helmut
|
||||
|
@ -131,7 +131,7 @@ char *do_browser(char *path, DIR *dir)
|
||||
{
|
||||
int mouse_x, mouse_y;
|
||||
|
||||
if (!get_mouseinput(&mouse_x, &mouse_y, TRUE)) {
|
||||
if (get_mouseinput(&mouse_x, &mouse_y, TRUE) == 0) {
|
||||
/* We can click in the edit window to select a
|
||||
* filename. */
|
||||
if (wenclose(edit, mouse_y, mouse_x)) {
|
||||
|
@ -1333,7 +1333,7 @@ int do_input(bool *meta_key, bool *func_key, bool *s_or_t, bool
|
||||
/* If we got a mouse click and it was on a shortcut, read in the
|
||||
* shortcut character. */
|
||||
if (*func_key && input == KEY_MOUSE) {
|
||||
if (do_mouse())
|
||||
if (do_mouse() == 1)
|
||||
input = get_kbinput(edit, meta_key, func_key);
|
||||
else {
|
||||
*meta_key = FALSE;
|
||||
@ -1491,12 +1491,12 @@ int do_input(bool *meta_key, bool *func_key, bool *s_or_t, bool
|
||||
|
||||
#ifndef DISABLE_MOUSE
|
||||
/* Handle a mouse click on the edit window or the shortcut list. */
|
||||
bool do_mouse(void)
|
||||
int do_mouse(void)
|
||||
{
|
||||
int mouse_x, mouse_y;
|
||||
bool retval = get_mouseinput(&mouse_x, &mouse_y, TRUE);
|
||||
int retval = get_mouseinput(&mouse_x, &mouse_y, TRUE);
|
||||
|
||||
if (!retval) {
|
||||
if (retval == 0) {
|
||||
/* We can click in the edit window to move the cursor. */
|
||||
if (wenclose(edit, mouse_y, mouse_x)) {
|
||||
bool sameline;
|
||||
|
13
src/prompt.c
13
src/prompt.c
@ -76,7 +76,7 @@ int do_statusbar_input(bool *meta_key, bool *func_key, bool *s_or_t,
|
||||
/* If we got a mouse click and it was on a shortcut, read in the
|
||||
* shortcut character. */
|
||||
if (*func_key && input == KEY_MOUSE) {
|
||||
if (do_statusbar_mouse())
|
||||
if (do_statusbar_mouse() == 1)
|
||||
input = get_kbinput(bottomwin, meta_key, func_key);
|
||||
else {
|
||||
*meta_key = FALSE;
|
||||
@ -273,12 +273,12 @@ int do_statusbar_input(bool *meta_key, bool *func_key, bool *s_or_t,
|
||||
|
||||
#ifndef DISABLE_MOUSE
|
||||
/* Handle a mouse click on the statusbar prompt or the shortcut list. */
|
||||
bool do_statusbar_mouse(void)
|
||||
int do_statusbar_mouse(void)
|
||||
{
|
||||
int mouse_x, mouse_y;
|
||||
bool retval = get_mouseinput(&mouse_x, &mouse_y, TRUE);
|
||||
int retval = get_mouseinput(&mouse_x, &mouse_y, TRUE);
|
||||
|
||||
if (!retval) {
|
||||
if (retval == 0) {
|
||||
/* We can click in the statusbar window text to move the
|
||||
* cursor. */
|
||||
if (wenclose(bottomwin, mouse_y, mouse_x)) {
|
||||
@ -1337,9 +1337,8 @@ int do_yesno_prompt(bool all, const char *msg)
|
||||
break;
|
||||
#ifndef DISABLE_MOUSE
|
||||
case KEY_MOUSE:
|
||||
get_mouseinput(&mouse_x, &mouse_y, FALSE);
|
||||
|
||||
if (wenclose(bottomwin, mouse_y, mouse_x) &&
|
||||
if (get_mouseinput(&mouse_x, &mouse_y, FALSE) == 0 &&
|
||||
wenclose(bottomwin, mouse_y, mouse_x) &&
|
||||
!ISSET(NO_HELP) && mouse_x < (width * 2) &&
|
||||
mouse_y - (2 - no_more_space()) -
|
||||
editwinrows - 1 >= 0) {
|
||||
|
@ -485,7 +485,7 @@ void terminal_init(void);
|
||||
int do_input(bool *meta_key, bool *func_key, bool *s_or_t, bool
|
||||
*ran_func, bool *finished, bool allow_funcs);
|
||||
#ifndef DISABLE_MOUSE
|
||||
bool do_mouse(void);
|
||||
int do_mouse(void);
|
||||
#endif
|
||||
void do_output(char *output, size_t output_len, bool allow_cntrls);
|
||||
|
||||
@ -494,7 +494,7 @@ int do_statusbar_input(bool *meta_key, bool *func_key, bool *s_or_t,
|
||||
bool *ran_func, bool *finished, bool allow_funcs, void
|
||||
(*refresh_func)(void));
|
||||
#ifndef DISABLE_MOUSE
|
||||
bool do_statusbar_mouse(void);
|
||||
int do_statusbar_mouse(void);
|
||||
#endif
|
||||
void do_statusbar_output(char *output, size_t output_len, bool
|
||||
*got_enter, bool allow_cntrls);
|
||||
@ -749,7 +749,7 @@ void unparse_kbinput(char *output, size_t output_len);
|
||||
int *get_verbatim_kbinput(WINDOW *win, size_t *kbinput_len);
|
||||
int *parse_verbatim_kbinput(WINDOW *win, size_t *kbinput_len);
|
||||
#ifndef DISABLE_MOUSE
|
||||
bool get_mouseinput(int *mouse_x, int *mouse_y, bool allow_shortcuts);
|
||||
int get_mouseinput(int *mouse_x, int *mouse_y, bool allow_shortcuts);
|
||||
#endif
|
||||
const shortcut *get_shortcut(const shortcut *s_list, int *kbinput, bool
|
||||
*meta_key, bool *func_key);
|
||||
|
116
src/winio.c
116
src/winio.c
@ -1625,17 +1625,18 @@ int *parse_verbatim_kbinput(WINDOW *win, size_t *kbinput_len)
|
||||
|
||||
#ifndef DISABLE_MOUSE
|
||||
/* Handle any mouse events that may have occurred. We currently handle
|
||||
* releases or clicks of the first mouse button. If allow_shortcuts is
|
||||
* TRUE, releasing or clicking on a visible shortcut will put back the
|
||||
* keystroke associated with that shortcut. If NCURSES_MOUSE_VERSION is
|
||||
* at least 2, we also currently handle presses of the fourth mouse
|
||||
* button (upward rolls of the mouse wheel) by putting back the
|
||||
* keystrokes to move up, and presses of the fifth mouse button
|
||||
* (downward rolls of the mouse wheel) by putting back the keystrokes to
|
||||
* move down. Return FALSE if we don't put back any keystrokes in the
|
||||
* course of handling mouse events, or TRUE if we do. Assume that
|
||||
* KEY_MOUSE has already been read in. */
|
||||
bool get_mouseinput(int *mouse_x, int *mouse_y, bool allow_shortcuts)
|
||||
* releases of the first mouse button. If allow_shortcuts is TRUE,
|
||||
* releasing on a visible shortcut will put back the keystroke
|
||||
* associated with that shortcut. If NCURSES_MOUSE_VERSION is at least
|
||||
* 2, we also currently handle presses of the fourth mouse button
|
||||
* (upward rolls of the mouse wheel) by putting back the keystrokes to
|
||||
* move up, and presses of the fifth mouse button (downward rolls of the
|
||||
* mouse wheel) by putting back the keystrokes to move down. Return -1
|
||||
* on error, 0 if the mouse event needs to be handled, 1 if it's been
|
||||
* handled by putting back keystrokes that need to be handled. or 2 if
|
||||
* the mouse event is ignored. Assume that KEY_MOUSE has already been
|
||||
* read in. */
|
||||
int get_mouseinput(int *mouse_x, int *mouse_y, bool allow_shortcuts)
|
||||
{
|
||||
MEVENT mevent;
|
||||
|
||||
@ -1644,20 +1645,19 @@ bool get_mouseinput(int *mouse_x, int *mouse_y, bool allow_shortcuts)
|
||||
|
||||
/* First, get the actual mouse event. */
|
||||
if (getmouse(&mevent) == ERR)
|
||||
return FALSE;
|
||||
return -1;
|
||||
|
||||
/* Handle releases or clicks of the first mouse button. */
|
||||
if (mevent.bstate & (BUTTON1_RELEASED | BUTTON1_CLICKED)) {
|
||||
/* Save the screen coordinates where the mouse event took
|
||||
* place. */
|
||||
*mouse_x = mevent.x;
|
||||
*mouse_y = mevent.y;
|
||||
/* Save the screen coordinates where the mouse event took place. */
|
||||
*mouse_x = mevent.x;
|
||||
*mouse_y = mevent.y;
|
||||
|
||||
/* Handle releases of the first mouse button. */
|
||||
if (mevent.bstate & BUTTON1_RELEASED) {
|
||||
/* If we're allowing shortcuts, the current shortcut list is
|
||||
* being displayed on the last two lines of the screen, and the
|
||||
* mouse event took place inside it, we need to figure out which
|
||||
* shortcut was clicked and put back the equivalent keystroke(s)
|
||||
* for it. */
|
||||
* first mouse button was pressed inside it, we need to figure
|
||||
* out which shortcut was clicked and put back the equivalent
|
||||
* keystroke(s) for it. */
|
||||
if (allow_shortcuts && !ISSET(NO_HELP) && wenclose(bottomwin,
|
||||
*mouse_y, *mouse_x)) {
|
||||
int i, j;
|
||||
@ -1665,7 +1665,7 @@ bool get_mouseinput(int *mouse_x, int *mouse_y, bool allow_shortcuts)
|
||||
/* The number of shortcuts in the current shortcut
|
||||
* list. */
|
||||
const shortcut *s = currshortcut;
|
||||
/* The actual shortcut we clicked on, starting at the
|
||||
/* The actual shortcut we released on, starting at the
|
||||
* first one in the current shortcut list. */
|
||||
|
||||
/* Get the shortcut lists' length. */
|
||||
@ -1694,26 +1694,28 @@ bool get_mouseinput(int *mouse_x, int *mouse_y, bool allow_shortcuts)
|
||||
* out, and set j to it. */
|
||||
j = *mouse_y - (2 - no_more_space()) - editwinrows - 1;
|
||||
|
||||
/* If we're on the statusbar, don't do anything. */
|
||||
/* Ignore releases of the first mouse button on the
|
||||
* statusbar. */
|
||||
if (j < 0)
|
||||
return FALSE;
|
||||
return 2;
|
||||
|
||||
/* Calculate the x-coordinate relative to the beginning of
|
||||
* the shortcut list in bottomwin, and add it to j. j
|
||||
* should now be the index in the shortcut list of the
|
||||
* shortcut we clicked. */
|
||||
* shortcut we released on. */
|
||||
j = (*mouse_x / i) * 2 + j;
|
||||
|
||||
/* Adjust j if we clicked in the last two shortcuts. */
|
||||
/* Adjust j if we released on the last two shortcuts. */
|
||||
if ((j >= currslen) && (*mouse_x % i < COLS % i))
|
||||
j -= 2;
|
||||
|
||||
/* If we're beyond the last shortcut, don't do anything. */
|
||||
/* Ignore releases of the first mouse button beyond the last
|
||||
* shortcut. */
|
||||
if (j >= currslen)
|
||||
return FALSE;
|
||||
return 2;
|
||||
|
||||
/* Go through the shortcut list to determine which shortcut
|
||||
* was clicked. */
|
||||
* we released on. */
|
||||
for (; j > 0; j--)
|
||||
s = s->next;
|
||||
|
||||
@ -1722,41 +1724,53 @@ bool get_mouseinput(int *mouse_x, int *mouse_y, bool allow_shortcuts)
|
||||
* key, an equivalent primary meta key sequence, or both. */
|
||||
if (s->ctrlval != NANO_NO_KEY) {
|
||||
unget_kbinput(s->ctrlval, FALSE, FALSE);
|
||||
return TRUE;
|
||||
return 1;
|
||||
} else if (s->metaval != NANO_NO_KEY) {
|
||||
unget_kbinput(s->metaval, TRUE, FALSE);
|
||||
return TRUE;
|
||||
return 1;
|
||||
}
|
||||
} else
|
||||
return FALSE;
|
||||
/* Handle releases of the first mouse button that aren't on
|
||||
* the current shortcut list elsewhere. */
|
||||
return 0;
|
||||
}
|
||||
#if NCURSES_MOUSE_VERSION >= 2
|
||||
/* Handle presses of the fourth mouse button (upward rolls of the
|
||||
* mouse wheel). */
|
||||
else if (mevent.bstate & BUTTON4_PRESSED) {
|
||||
int i = 0;
|
||||
* mouse wheel) and presses of the fifth mouse button (downward
|
||||
* rolls of the mouse wheel) . */
|
||||
else if (mevent.bstate & (BUTTON4_PRESSED | BUTTON5_PRESSED)) {
|
||||
if (wenclose(edit, *mouse_y, *mouse_x) || wenclose(bottomwin,
|
||||
*mouse_y, *mouse_x)) {
|
||||
/* Calculate the y-coordinate relative to the beginning of
|
||||
* the shortcut list in bottomwin, i.e. with the sizes of
|
||||
* topwin, edit, and the first line of bottomwin subtracted
|
||||
* out, and set i to it. */
|
||||
int i = *mouse_y - (2 - no_more_space()) - editwinrows - 1;
|
||||
|
||||
/* One upward roll of the mouse wheel is equivalent to moving up
|
||||
* three lines. */
|
||||
for (; i < 3; i++)
|
||||
unget_kbinput(NANO_PREVLINE_KEY, FALSE, FALSE);
|
||||
/* Ignore presses of the fourth mouse button and presses of
|
||||
* the fifth mouse button below the statusbar. */
|
||||
if (i >= 0)
|
||||
return 2;
|
||||
|
||||
return TRUE;
|
||||
/* Handle presses of the fifth mouse button (downward rolls of the
|
||||
* mouse wheel). */
|
||||
} else if (mevent.bstate & BUTTON5_PRESSED) {
|
||||
int i = 0;
|
||||
/* One upward roll of the mouse wheel is equivalent to
|
||||
* moving up three lines, and one downward roll of the mouse
|
||||
* wheel is equivalent to moving down three lines. */
|
||||
for (i = 0; i < 3; i++)
|
||||
unget_kbinput((mevent.bstate & BUTTON4_PRESSED) ?
|
||||
NANO_PREVLINE_KEY : NANO_NEXTLINE_KEY, FALSE,
|
||||
FALSE);
|
||||
|
||||
/* One downward roll of the mouse wheel is equivalent to moving
|
||||
* down three lines. */
|
||||
for (; i < 3; i++)
|
||||
unget_kbinput(NANO_NEXTLINE_KEY, FALSE, FALSE);
|
||||
|
||||
return TRUE;
|
||||
return 1;
|
||||
} else
|
||||
/* Ignore presses of the fourth mouse button and presses of
|
||||
* the fifth mouse buttons that aren't on the edit window or
|
||||
* the statusbar. */
|
||||
return 2;
|
||||
}
|
||||
#endif
|
||||
else
|
||||
return FALSE;
|
||||
/* Ignore all other mouse events. */
|
||||
return 2;
|
||||
}
|
||||
#endif /* !DISABLE_MOUSE */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user