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

terminal: support mouse input #13711

Merged
merged 8 commits into from
Apr 17, 2024
Merged

Conversation

na-na-hi
Copy link
Contributor

This adds mouse input parsing and enables mouse support for terminal VOs (vo_tct, vo_sixel, vo_kitty), making it possible to use mouse key bindings and OSC with these VOs.

Copy link

github-actions bot commented Mar 16, 2024

Download the artifacts for this pull request:

Windows
macOS

@kasper93
Copy link
Contributor

Are you interested also in implementing it for win32? There are dragons hiding there, but it should be possible to add support for it.

@na-na-hi
Copy link
Contributor Author

Are you interested also in implementing it for win32?

I will look into it later. The console API terminal-win uses already provides the necessary facilities so it should be doable.

@na-na-hi na-na-hi changed the title terminal-unix: support mouse input terminal: support mouse input Mar 31, 2024
@na-na-hi
Copy link
Contributor Author

na-na-hi commented Mar 31, 2024

@kasper93
Added mouse support for win32 terminal. (QuickEdit mode must be turned off for mouse input to work)

@na-na-hi na-na-hi force-pushed the terminal-mouse branch 3 times, most recently from 0a78ed3 to 74b8395 Compare April 7, 2024 20:35
@kasper93 kasper93 added this to the Release v0.39.0 milestone Apr 9, 2024
Copy link
Contributor

@kasper93 kasper93 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few minor comments.

osdep/terminal-unix.c Outdated Show resolved Hide resolved
osdep/terminal-win.c Outdated Show resolved Hide resolved
osdep/terminal-win.c Outdated Show resolved Hide resolved
osdep/terminal-win.c Outdated Show resolved Hide resolved
These 6-byte codes have the format of \e [ M <button> <xpos> <ypos>.
Support the first 3 mouse bottons + scroll up/down for now as
button numbers > 5 are pretty non-portable across terminals.
Pixel-based mouse position values are calculated and sent to the
input system.
21d434d attempted to ignore unknown
CSI sequences with a specific termination rule. This however does not
apply to mouse CSI sequences which can have characters out of that
range. Fix this by throwing away the whole sequence when an unhandled
mouse sequence is detected.
This function is used to enable/disable mouse input for win32 and unix.
The size of the console font can be acquired with GetCurrentConsoleFont,
and the terminal size can be calculated from the rols, cols, and font
size.
The mouse input information is available from the INPUT_RECORD
with MOUSE_EVENT event type.
@na-na-hi
Copy link
Contributor Author

Applied all suggested changes.

Copy link
Contributor

@kasper93 kasper93 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Frankly not sure about usefulness of this, but why not.

@kasper93 kasper93 merged commit 7cfd369 into mpv-player:master Apr 17, 2024
14 checks passed
Comment on lines +135 to +142
int w = 0, h = 0, fw = 0, fh = 0;
terminal_get_size(&w, &h);
if (get_font_size(&fw, &fh)) {
*px_width = fw * w;
*px_height = fh * h;
*rows = w;
*cols = h;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@na-na-hi

This doesn't work well for recently added sixel support in conhost.

They use 10x20 sized cells (see microsoft/terminal#17504).

Do you want to play around with it and improve it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked into it and the problem is with the current terminal input architecture. mpv never used control sequences for querying, and all terminal inputs are processed in a dedicated thread. That means with the current architecture, querying character pixel size would be an asynchronous operation since there might be some inputs waiting to be processed before the query responses arrive.

Not sure what's the best way to proceed from here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what's the best way to proceed from here.

Same. Would be nice to have it supported, but don't see easy path forward with this one.

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.

3 participants