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

Emulating 2-dimensional scrolling with arrow keys #2819

Closed
ducis opened this issue Jun 30, 2020 · 8 comments
Closed

Emulating 2-dimensional scrolling with arrow keys #2819

ducis opened this issue Jun 30, 2020 · 8 comments

Comments

@ducis
Copy link

ducis commented Jun 30, 2020

Can I get the terminal emulator to send the four arrow keys to the enclosed program
when receiving vertical and horizontal scroll events?
Better yet only do so when user-specified programs are detected, as this may break in some situations?

In vim, for example, I could then use a mouse/trackball/joystick to move the (terminal) cursor around without
moving the actual mouse cursor, the inability of which is probably why navigating with keyboards
still feels better than that with the continuous devices.
If I would like to implement it, where shall I start?

A related issue is high-precision scrolling.
I configured a trackball to act as a (high-precision) wheel when a button is pressed,
and I feel that the minimal amount of movement to trigger any scrolling is larger in kitty than in, say, Firefox.
To ensure that the cursor can reach every row I have to use wheel_scroll_multiplier 1.0.
So I would like the terminal to move by one row more when an as-small-as-possible movement is detected.
How does kitty process high-precision scrolling events?

@kovidgoyal
Copy link
Owner

Not something I am interested in, but look in mouse.c IIRC kitty already
sends key events for scroll events when the terminal program does not
ask for mouse events.

@trygveaa
Copy link
Sponsor Contributor

IIRC kitty already sends key events for scroll events when the terminal program does not ask for mouse events.

Only for vertical scrolling, kitty doesn't currently support horizontal scrolling.

In vim, for example, I could then use a mouse/trackball/joystick to move the (terminal) cursor around without moving the actual mouse cursor, the inability of which is probably why navigating with keyboards still feels better than that with the continuous devices.

For vertical scrolling in vim you can do that by enabling mouse mode and mapping scroll up/down:

:set mouse=a
:map <ScrollWheelUp> k
:map <ScrollWheelDown> j

If you want horizontal scrolling you have to implement support for that in mouse.c. Though, I'm not sure if vim supports horizontal scrolling either (it doesn't work out of the box in xterm at least). If not, you can disable mouse mode in vim so kitty sends arrow keys like @kovidgoyal said. For horizontal scrolling, this also has to be implemented in mouse.c though.

@ducis
Copy link
Author

ducis commented Jul 1, 2020

Not something I am interested in, but look in mouse.c IIRC kitty already
sends key events for scroll events when the terminal program does not
ask for mouse events.

Thank you for the info.

I just realized another issue with scrolling. As I use a trackball for scrolling, which is the same as scrolling with mouse movement when a button is down, I am able to send scroll events at a much higher frequency than with a typical wheel, like scrolling for more than 60 steps a second.
When doing so, kitty seems to not catch up with the actual movement but instead queue the events, continuing to scroll after the input has stopped, no matter what console application is inside.

In konsole, terminology and gnome-terminal the scrolling always stops when the input device stops.

I saw that there are something about momentum scrolling in mouse.c. Does this lag have anything to do with momentum scrolling, or is kitty just taking the time to process the scroll events ( and presumably redraw after scrolling each step) ?

@Luflosi
Copy link
Contributor

Luflosi commented Jul 1, 2020

There are two different code paths, one for high resolution scrolling like track pads and I think for normal mice on macOS as well and one code path for low resolution scrolling, like with normal mice. This information is supplied by the OS. Look at is_high_resolution in mouse.c. Add a printf("%s\n", is_high_resolution ? "yes":"no"); to find out the value of that variable when scrolling with your trackball. The momentum scrolling stuff is only used on macOS.
Are you using Linux? And are you running Wayland or X11?

@Luflosi
Copy link
Contributor

Luflosi commented Jul 1, 2020

I was wrong, normal mice on macOS are not counted as high-resolution, it's just that because of scrolling acceleration, mice can generate very small scrolling deltas.
Can you try running my fork too? I made some modifications to the scroll code a long time ago and I'm curious if it will change anything for you.

@tmccombs
Copy link

I'm not sure if vim supports horizontal scrolling either

Vim supports <ScrollWheelLeft> and <ScrollWheelRight> events. I'm not sure exactly what escape code vim is expecting for that, but kitty doesn't seem to be sending it.

@tmccombs
Copy link

Thank you @kovidgoyal !

@alex-hunt-materialize
Copy link

alex-hunt-materialize commented Apr 12, 2023

Not something I am interested in, but look in mouse.c IIRC kitty already
sends key events for scroll events when the terminal program does not
ask for mouse events.

Is there a way to disable this behavior and just have kitty not send anything? Sending <Up> and <Down> events when scrolling is very unintuitive and makes disabling all neovim mouse support impossible while retaining working arrow keys.

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

No branches or pull requests

6 participants