-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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 + Neovim: FocusLost/Gained events don't fire. #11682
Comments
I suspect this is because we don't support XTerm's focus event mode (private mode 1004). I thought there might have been an issue for it already, but I haven't been able find one. Edit: Not a duplicate as such, but I see now it has been discussed before here: #10531 (comment) |
Well cool, I would have suspected there was an issue already for this. Plumbing through conpty shouldn't be too hard, if a bit annoying. |
Oh boy I sure did go overboard on my branch off #12799. We may just have to do this whole thing, so, here it is: (left is before, right is after) note to self:
|
…12799) ## Window shenanigans, part the third: Hooks the Terminal's focus state up to the underlying ConPTY. This is LOAD BEARING for allowing windows created by console applications to bring themselves to the foreground. We're using the [FocusIn/FocusOut](https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-FocusIn_FocusOut) sequences to communicate to ConPTY when a control gains/loses focus. Theoretically, other terminals could do this as well. ## References #11682 tracks _real_ support for this sequence in Console & conpty. When we do that, we should consider even if a client application disables this mode, the Terminal & conpty should always request this from the hosting terminal (and just ignore internally to ConPTY). See also #12515, #12526, which are the other two parts of this effort. This was tested with all three merged together, and they worked beautifully for all our scenarios. They are kept separate for ease of review. ## PR Checklist * [x] This is prototype 3 for #2988 * [x] I work here * [ ] Tests added/passed * [n/a] Requires documentation to be updated ## Detailed Description of the Pull Request / Additional comments This allows windows spawned by console processes to bring themselves to the foreground _when the console is focused_. (Historically, this is also called in the WndProc, when focus changes). Notably, before this, ConPTY was _never_ focused, so windows could never bring themselves to the foreground when run from a ConPTY console. We're not blanket granting the SetForeground right to all console apps when run in ConPTY. It's the responsibility of the hosting terminal emulator to always tell ConPTY when a particular instance is focused. ## Validation Steps Performed (gif below)
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 * [x] closes #11682 * This combined with #12515 will finally close out #2988 as well, but we can do that manually. * [x] I work here * [ ] There aren't tests for this. There probably should be.
🎉This issue was addressed in #12900, which has now been successfully released as Handy links: |
Windows Terminal version (or Windows build number)
1.12.2931.0
Other Software
Neovim 0.5+
Steps to reproduce
Steps to reproduce:
min.vim
file, with the commandnvim -u min.vim --clean
Expected Behavior
See title and steps to reproduce. This works in all Linux/MacOS terminals I've used, including Alacritty, Kitty, and iTerm2, as well as in tmux sessions if focus-events are enabled.
The Vim/Neovim release is not particularly important unless you would also like to test in tmux; in that case, choose a release any time after April 2021 and put
set -g focus-events on
in your.tmux.conf
Actual Behavior
Nothing happens.
The text was updated successfully, but these errors were encountered: