Skip to content

Plumb Focus events through VT Input#12900

Merged
40 commits merged intomainfrom
dev/migrie/f/11682-vt-focus-events
Apr 20, 2022
Merged

Plumb Focus events through VT Input#12900
40 commits merged intomainfrom
dev/migrie/f/11682-vt-focus-events

Conversation

@zadjii-msft
Copy link
Member

@zadjii-msft zadjii-msft commented Apr 13, 2022

Further builds on #12799. #12799 assumes that the connection is prepared to receive FocusIn/FocusOut events as input. For ConPTY we can be relatively sure of that, but that's not technically correct. In the hypothetical world where the connection is not a ConPTY connection, then the other side might not be expecting those sequences.

This remedies the issue by

  • ConPTY will always request focus event mode (from the terminal) when it starts up
  • when a client tries to disable focus events in conpty, conpty is gonna note that internally, but never transmit that to the hosting terminal, to leave the terminal in focus event mode.
  • TerminalDispatch and ControlCore are hooked up now to only send focus events when the Terminal is in focus event mode (which will be always for conpty)
  • At this point, it was like, 4LOC in terminalInput.cpp to add support for focus events to conhost as well.

checklist

@ghost ghost added Area-Input Related to input processing (key presses, mouse, etc.) Area-VT Virtual Terminal sequence support Issue-Task It's a feature request, but it doesn't really need a major design. Product-Conhost For issues in the Console codebase Product-Conpty For console issues specifically related to conpty Product-Terminal The new Windows Terminal. labels Apr 13, 2022
@github-actions

This comment was marked as resolved.

Copy link
Member

@lhecker lhecker left a comment

Choose a reason for hiding this comment

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

I can't review this from a architectural POV unfortunately.

// it's focused or not, as to match the end-terminal's state.
// - Used to call ConsoleControl(ConsoleSetForeground,...).
// - Full support for this sequence is tracked in GH#11682.
// - Full support for this sequence was added in GH#11682.
Copy link
Member

Choose a reason for hiding this comment

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

We can just kill this line. Otherwise we're gonna litter our code with historical artifacts pointing to GitHub issues that we could relegate to git blame :)

// Theoretically, this could be propagated as a focus event as well, to the
// input buffer. That should be considered when implementing GH#11682.

return true;
Copy link
Member

Choose a reason for hiding this comment

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

we should make sure that a VT Input client on the far receiving end doesn't get two events each focus change. I was wondering if it would because:

  1. we might pass one through (original one)
  2. we add a FOCUS_EVENT to the input buffer, which TerminalInput later converts into another focus VT sequence

Copy link
Member Author

Choose a reason for hiding this comment

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

WHOOPS IT DOES THE OPPOSITE.

Terminal doesn't send any focus events to the client. It sets the terminal into focus mode, it sends the focus in, InteractDispatch then enables CONSOLE_FOREGROUND, and then returns and never writes the focus event to the buffer.

Copy link
Member

Choose a reason for hiding this comment

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

oops!

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed it

gh-11682-in-terminal

Base automatically changed from dev/migrie/b/2988-focus-fg-with-owner to main April 19, 2022 21:26
@zadjii-msft zadjii-msft added the AutoMerge Marked for automatic merge by the bot when requirements are met label Apr 19, 2022
@ghost
Copy link

ghost commented Apr 19, 2022

Hello @zadjii-msft!

Because this pull request has the AutoMerge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@DHowett DHowett removed the AutoMerge Marked for automatic merge by the bot when requirements are met label Apr 19, 2022
@DHowett
Copy link
Member

DHowett commented Apr 19, 2022

I did unmark automerge if you wanted to think about HandleFocusEvent; it's optional of course

@DHowett DHowett added the AutoMerge Marked for automatic merge by the bot when requirements are met label Apr 20, 2022
@ghost ghost merged commit 87f5034 into main Apr 20, 2022
@ghost ghost deleted the dev/migrie/f/11682-vt-focus-events branch April 20, 2022 18:22
@ghost
Copy link

ghost commented May 24, 2022

🎉Windows Terminal Preview v1.14.143 has been released which incorporates this pull request.:tada:

Handy links:

ghost pushed a commit that referenced this pull request Jun 10, 2022
As described in #13238. libuv sends a focus event to jiggle the handle. Now that we support focus events as VT input (#12900), we'd translate those focus events to VT input as well. That combination of things caused exiting neovim to emit a `\x1b[O` to the input line of the shell when exited. 

To fix this, we're going to secretly filter out any focus events that came from the API, before translating to VT. We're fortunate here, the `FOCUS_EVENT_RECORD` version of the ctor is only called by the API. 

* [x] Closes #13238
DHowett pushed a commit that referenced this pull request Jun 30, 2022
As described in #13238. libuv sends a focus event to jiggle the handle. Now that we support focus events as VT input (#12900), we'd translate those focus events to VT input as well. That combination of things caused exiting neovim to emit a `\x1b[O` to the input line of the shell when exited.

To fix this, we're going to secretly filter out any focus events that came from the API, before translating to VT. We're fortunate here, the `FOCUS_EVENT_RECORD` version of the ctor is only called by the API.

* [x] Closes #13238

(cherry picked from commit b22684e)
Service-Card-Id: 83027721
Service-Version: 1.14
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-Input Related to input processing (key presses, mouse, etc.) Area-VT Virtual Terminal sequence support AutoMerge Marked for automatic merge by the bot when requirements are met Issue-Task It's a feature request, but it doesn't really need a major design. Product-Conhost For issues in the Console codebase Product-Conpty For console issues specifically related to conpty Product-Terminal The new Windows Terminal.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Terminal + Neovim: FocusLost/Gained events don't fire.

4 participants