Skip to content
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

Merged
merged 2 commits into from
Sep 25, 2023
Merged

Conversation

avih
Copy link
Contributor

@avih avih commented Jun 20, 2023

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.

@avih
Copy link
Contributor Author

avih commented Jun 20, 2023

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 x11mouse_action so that click is reported on button-up on any system which uses the legacy method (and the windows switch to SGR mode is no longer required),

@avih
Copy link
Contributor Author

avih commented Jun 20, 2023

Alternatively, and possibly even simpler and better, handle the buttons state at x11mouse_action so that click is reported on button-up on any system which uses the legacy method

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.

@avih
Copy link
Contributor Author

avih commented Jun 21, 2023

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
(first commit is unmodified from this PR, second commit replaces the second comit here, and the 3rd commit in this PR is dropped).

I'm keeping the PR unmodified as reference, but I'll update it to this alternative solution if requested.

@avih
Copy link
Contributor Author

avih commented Sep 19, 2023

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.
@avih
Copy link
Contributor Author

avih commented Sep 25, 2023

Rebased after windows key handling refactor.

@gwsw gwsw merged commit 0ffa65b into gwsw:master Sep 25, 2023
@avih avih deleted the mouse-mark-jump branch September 25, 2023 21:09
@avih
Copy link
Contributor Author

avih commented Sep 25, 2023

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants