-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Conversation
Download the artifacts for this pull request: |
Are you interested also in implementing it for win32? There are dragons hiding there, but it should be possible to add support for it. |
I will look into it later. The console API terminal-win uses already provides the necessary facilities so it should be doable. |
db2bcc2
to
4b69572
Compare
@kasper93 |
0a78ed3
to
74b8395
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few minor comments.
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.
74b8395
to
96a805a
Compare
Applied all suggested changes. |
There was a problem hiding this 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.
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; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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.