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

Disable win32 input mode on exit #16408

Merged
merged 4 commits into from
Dec 5, 2023
Merged

Conversation

lhecker
Copy link
Member

@lhecker lhecker commented Dec 1, 2023

When ConPTY exits it should attempt to restore the state as it was
before it started. This is particularly important for the win32
input mode sequences, as Linux shells don't know what to do with it.

Related to #16343

Validation Steps Performed

  • Replace conhost with this
  • Launch a Win32 application inside WSL
  • Exit that application
  • Shell prompt doesn't get filled with win32 input mode sequences ✅

@lhecker lhecker added Product-Conpty For console issues specifically related to conpty Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-0 Bugs that we consider release-blocking/recall-class (P0) zInbox-Bug Ignore me! labels Dec 1, 2023
// It's important that any additional modes set here are also mirrored in
// the AdaptDispatch::HardReset method, since that needs to re-enable them
// in the connected terminal after passing through an RIS sequence.
RETURN_IF_FAILED(_RequestWin32Input());
RETURN_IF_FAILED(_RequestFocusEventMode());
RETURN_IF_FAILED(_Write("\033[?9001;1004h"));
Copy link
Member

Choose a reason for hiding this comment

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

lol, straight up yeet them in. I love it actually.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's the same sequence as in AdaptDispatch::HardReset, which I felt like makes it easier to find.

@j4james
Copy link
Collaborator

j4james commented Dec 3, 2023

I was thinking along the same lines as this, but my concern was that it might not work if the parent shell did actually want win32-input mode, i.e. you start off with win32-input mode enabled, you initiate a conpty session which enables it again, but when the conpty session ends we're now disabling it, which is not your initial state. Or is that not a possible scenario?

@lhecker
Copy link
Member Author

lhecker commented Dec 4, 2023

I believe that's possible. For instance, if you run ConPTY inside ConPTY right? I was unsure how to solve that issue, but felt like that doing nothing is worse, as it breaks shell input in WSL instantly.

But I just realized that if we encounter a \033[?9001l sequence to disable win32-input-mode inside ConPTY, we should simply not bubble it up, but only disable it locally (i.e., for the output of this particular ConPTY instance only). That would make it work correctly, right?

@DHowett
Copy link
Member

DHowett commented Dec 4, 2023

you start off with win32-input mode enabled, you initiate a conpty session which enables it again, but when the conpty session ends we're now disabling it

I think this is pretty similar to "I need DECKPAM but I need to spawn an application that might reset it." Applications that host other applications and need specific input modes are, unfortunately, at the mercy of the applications they host. :/ (Which you of course already know! Sorry!)

Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

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

Yea, I think I'm cool with this. I'd assume it's well understood that if you're a client app that needs specific modes and you call child processes, you need to set the modes back to what you need.

and if that isn't well known, well, (how did I not know that) and (yikes)

@j4james
Copy link
Collaborator

j4james commented Dec 5, 2023

I was unsure how to solve that issue, but felt like that doing nothing is worse, as it breaks shell input in WSL instantly.

Absolutely. Even if that is all that it fixes, I'd be happy with this PR. It would be great if we could also restore the win32-input when it was actually wanted, but it wouldn't be the end of the world if we can't.

But I just realized that if we encounter a \033[?9001l sequence to disable win32-input-mode inside ConPTY, we should simply not bubble it up, but only disable it locally (i.e., for the output of this particular ConPTY instance only). That would make it work correctly, right?

I honestly don't have a great understanding of what's going on when we're nesting conpty instances like this, but that sounds right to me.

@DHowett
Copy link
Member

DHowett commented Dec 5, 2023

@j4james I tried to draw up a diagram, as I was having trouble understanding it myself. Here's what terror I came up with.

image


All this aside, this collection of PRs (mainly #16407) doesn't fix the deadlock when run under Terminal Stable. Here's my proposal...

image

What if we move this down here? It should only serve to improve the DSR-CPR startup exchange.

@DHowett DHowett merged commit 70e51ae into main Dec 5, 2023
15 of 17 checks passed
@DHowett DHowett deleted the dev/lhecker/win32-mode-disable branch December 5, 2023 01:53
DHowett pushed a commit that referenced this pull request Dec 5, 2023
When ConPTY exits it should attempt to restore the state as it was
before it started. This is particularly important for the win32
input mode sequences, as Linux shells don't know what to do with it.

Related to #16343

## Validation Steps Performed
* Replace conhost with this
* Launch a Win32 application inside WSL
* Exit that application
* Shell prompt doesn't get filled with win32 input mode sequences ✅

(cherry picked from commit 70e51ae)
Service-Card-Id: 91246943
Service-Version: 1.19
@j4james
Copy link
Collaborator

j4james commented Dec 5, 2023

All this aside, this collection of PRs (mainly #16407) doesn't fix the deadlock when run under Terminal Stable. Here's my proposal...

@DHowett For this to be of any benefit, your proposed fix would assumedly have to make its way into the inbox conhost before Terminal Stable gets the #16407 fix. Am I understanding that correctly?

If that's a likely scenario, then it probably is worth doing. The only downside I can see is if the CPR response is slow, it might be possible that some keypresses arrive in VT format before win32-input mode kicks in. But that doesn't seem like a massive issue, assuming it's even possible at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-0 Bugs that we consider release-blocking/recall-class (P0) Product-Conpty For console issues specifically related to conpty zInbox-Bug Ignore me!
Projects
Development

Successfully merging this pull request may close these issues.

4 participants