curses mouse right-click

Right button is button3 rather than button2.  Accept either and treat
both as "not left" to pass CLICK_2 back to the core.

Treat <Ctrl>+left-click as "not left" too, to simplify usage with Mac
one-button mouse (where <Ctrl>+left-click can be configured to send
"secondary click" but might not be set do so) or one-button laptop
trackpad (where having two fingers on the scrolling portion of the pad
while clicking the button is necessary to send "secondary click").
This commit is contained in:
PatR
2019-06-27 15:02:49 -07:00
parent aada9e2706
commit 56387dccb6
2 changed files with 19 additions and 10 deletions

View File

@@ -838,8 +838,10 @@ curses_init_options()
#ifdef NCURSES_MOUSE_VERSION
if (iflags.wc_mouse_support) {
mousemask(BUTTON1_CLICKED, NULL);
curses_mouse_support(iflags.wc_mouse_support);
}
#else
iflags.wc_mouse_support = 0;
#endif
}

View File

@@ -870,6 +870,13 @@ curses_convert_keys(int key)
return ret;
}
/* we treat buttons 2 and 3 as equivalent so that it doesn't matter which
one is for right-click and which for middle-click; the core uses CLICK_2
for right-click ("not left" click) even though 2 might be middle button;
we also support Ctrl+left-click as another way to get "not left" click
since Mac is traditionally saddled with a one button mouse or trackpad */
#define MOUSEBUTTONS ((BUTTON1_CLICKED | BUTTON2_CLICKED | BUTTON3_CLICKED) \
| BUTTON_CTRL)
/* Process mouse events. Mouse movement is processed until no further
mouse movement events are available. Returns 0 for a mouse click
@@ -884,8 +891,8 @@ curses_get_mouse(int *mousex, int *mousey, int *mod)
#ifdef NCURSES_MOUSE_VERSION
MEVENT event;
if (getmouse(&event) == OK) { /* When the user clicks left mouse button */
if (event.bstate & (BUTTON1_CLICKED | BUTTON2_CLICKED)) {
if (getmouse(&event) == OK) { /* True if user has clicked */
if ((event.bstate & MOUSEBUTTONS) != 0) {
/*
* The ncurses man page documents wmouse_trafo() incorrectly.
* It says that last argument 'TRUE' translates from screen
@@ -903,17 +910,16 @@ curses_get_mouse(int *mousex, int *mousey, int *mod)
* or the ncurses documentation, so keep the 'bad' argument for
* it until we find out. [Mouse can be used successfully with
* 'bad' coordinate translation via align_message:bottom (and
* avoiding align_status:left) so that the subset of the screen
* corresponding to the map needs no translation. Adding instead
* of subtracting or vice versa makes no difference when amount
* involved is 0.]
* avoiding align_status:top or left) so that the subset of the
* screen corresponding to the map needs no translation. Adding
* instead of subtracting makes no difference when amount is 0.]
*/
TRUE
#else
FALSE
#endif
)) {
key = 0; /* Flag mouse click */
key = '\0'; /* core uses this to detect a mouse click */
*mousex = event.x + 1; /* +1: screen 0..78 is map 1..79 */
*mousey = event.y;
@@ -922,7 +928,8 @@ curses_get_mouse(int *mousex, int *mousey, int *mod)
(*mousey)--;
}
*mod = (event.bstate & BUTTON1_CLICKED) ? CLICK_1 : CLICK_2;
*mod = ((event.bstate & (BUTTON1_CLICKED | BUTTON_CTRL))
== BUTTON1_CLICKED) ? CLICK_1 : CLICK_2;
}
}
}
@@ -941,7 +948,7 @@ int mode; /* 0: off, 1: on, 2: alternate on */
if (!mode)
newmask = 0;
else
newmask = BUTTON1_CLICKED | BUTTON2_CLICKED;
newmask = MOUSEBUTTONS; /* buttons 1, 2, and 3 */
result = mousemask(newmask, &oldmask);
nhUse(result);