-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mouse: bind right-click as jump-to-"#"-mark #390
Conversation
Added a third commit which switches the windows mouse code from the legacy x11 method to the more modern SGR (!006) method, so that mouse clicks on windows will now be reported on button-up. Alternatively, and possibly even simpler and better, handle the buttons state at |
So, for reference, that's the legacy mouse handler patch to add support for specific buttons, which is currently in this PR, and it triggers on button-down - which is OK, but suboptimal: static int x11mouse_action(int skip)
{
int b = getcc() - X11MOUSE_OFFSET;
int x = getcc() - X11MOUSE_OFFSET-1;
int y = getcc() - X11MOUSE_OFFSET-1;
if (skip)
return (A_NOACTION);
switch (b) {
default:
return (A_NOACTION);
case X11MOUSE_WHEEL_DOWN:
return mouse_wheel_down();
case X11MOUSE_WHEEL_UP:
return mouse_wheel_up();
- case X11MOUSE_BUTTON_REL:
- return mouse_button_rel(x, y);
+ case X11MOUSE_BUTTON1:
+ return mouse_button_left(x, y);
+ /* is BUTTON2 the rightmost button with 2-buttons mouse? */
+ case X11MOUSE_BUTTON2:
+ case X11MOUSE_BUTTON3:
+ return mouse_button_right(x, y);
}
} And that's an alternative patch which adds specific-buttons support, but triggers on button-up - which is nicer (and would make the windows switch to SGR reporting redundant): static int x11mouse_action(int skip)
{
+ static int prev_b = X11MOUSE_BUTTON_REL;
int b = getcc() - X11MOUSE_OFFSET;
int x = getcc() - X11MOUSE_OFFSET-1;
int y = getcc() - X11MOUSE_OFFSET-1;
if (skip)
return (A_NOACTION);
switch (b) {
default:
+ prev_b = b;
return (A_NOACTION);
case X11MOUSE_WHEEL_DOWN:
return mouse_wheel_down();
case X11MOUSE_WHEEL_UP:
return mouse_wheel_up();
case X11MOUSE_BUTTON_REL:
- return mouse_button_rel(x, y);
+ /* to trigger on button-up, we check the last button-down */
+ switch (prev_b) {
+ case X11MOUSE_BUTTON1:
+ return mouse_button_left(x, y);
+ /* is BUTTON2 the rightmost button with 2-buttons mouse? */
+ case X11MOUSE_BUTTON2:
+ case X11MOUSE_BUTTON3:
+ return mouse_button_right(x, y);
+ }
+ return (A_NOACTION);
}
} If/when the time comes, let me know which approach you prefer and I'll update the PR accordingly. |
For reference, I'm now in favor of fixing the legacy x11 handler to emit button trigger on button-up. The top two commits here show this https://github.com/avih/less/commits/mouse-mark-jump-alt I'm keeping the PR unmodified as reference, but I'll update it to this alternative solution if requested. |
5c42625
to
1c848d4
Compare
Rebased and chose the "fixing the legacy x11 handler to emit button trigger on button-up." approach. |
Previously, pressing the left mouse button incorrectly reported that X11MOUSE_BUTTON3 (right button) was pressed, and right or middle buttons were incorrectly reported as modifiers (ctrl/shift/etc), as they ended up outside the 2-bits which x11 mouse uses for button id. Now left/middle/right are reported as x11 BUTTON 1/2/3, respectively. This doesn't have any visible impact, because currently there's only mouse-button-up binding, and less doesn't care which button it was. However, the next commit will add right-mouse-button binding, so ensure the windows mouse handling doesn't become broken.
Previously any mouse-button click marked the line with '#'. Now left-click marks with '#', and right-click jumps to this mark. In practice, and to support 2/3 buttons mice, we apply the jump with any mouse button which is not X11MOUSE_BUTTON1 (left). With the legacy x11 mouse report handler, a button-release event doesn't have button ID, so to trigger on a specific button release, a state was introduced which holds the last button-press.
1c848d4
to
46daa0f
Compare
Rebased after windows key handling refactor. |
Thanks. |
Previously any mouse-button click set the "#" mark.
With this PR, left-click sets the "#" mark, and right-click jumps to the "#" mark.
There are two commits: the first fixes mouse-button-down encoding on windows in preparation, and the second adds the right-click binding as jump-to-mark.