-
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
GUI apps still don't open in the foreground, from a default terminal launch #13211
Comments
This is not actionable without knowing the version of Windows Terminal the TCC user has installed -- we made some significant windowing changes in Preview 1.14. |
His setup is the same as mine. I have no such problem. v:> ver |
The user in question is using WindowsTerminalPreview 1.14.2205.25002. I am using WindowsTerminalPreview 1.14.2205.23002. Is that newer build available on GitHub? |
Here's a link to the original report. I suspect with CreateProcessW. WinDbg isn't being very cooperative: 0:001> bp shell32!ShellExecuteW It does not break on ShellEXecute[Ex] when I issue "notepad". |
I tried again. WinDbg does break at CreateProcessW when I issue "notepad". |
Mike, if you're following, you'll be interested in #18. The user reports that whatever shell is in WT's FIRST tab will exhibit this problem. In a nutshell ... it's not only TCC. |
And, if I read his comments accurately, he has a setup in which WT is the default handler for console apps (as opposed to conhost). Musy be (?) he has some sort of insider status. |
I was the originator of this bug report, over on the JPSoft forums. I mistakenly thought the problem was limited to TCC, but that is not the case. I am not an “Insider”, this is a public build of Windows Terminal Preview, and a public build of Windows. Microsoft Windows Windows Terminal Preview I obtained Windows Terminal Preview from the Microsoft Store. It offered to make itself the default handler for shells, and I accepted the offer. I have shortcuts on the desktop for cmd.exe and tcc.exe (Jpsoft). If I click on either of those shortcuts, they start in a new Windows Terminal Preview tabbed window. And from there, if I start an application (notepad, for instance), the focus stays in the Windows Terminal Preview window, it does not shift to the newly launched application. The same behavior for tcc and for cmd. Doesn’t matter if I type in “notepad” or “start notepad”. Also, if I launch Powershell Preview from the Start Menu, it starts up in a Windows Terminal tabbed window, and exhibits the same behavior. Now once I have a window up for Windows Terminal Preview, if I start another tab, the problem does not exist in the secondary tab. And it doesn’t matter what’s running in the secondary tab, cmd, tcc, pwsh, all behave normally. Launch an application, that new application gets the focus. And if I kill the primary tab, so the secondary tab becomes the primary tab, there is now no problem in the new primary tab. I also have Windows Terminal Version: 1.12.10983.0 That launches tcc under the older version of WT, and the problem does not then exist. |
Thanks for all the background guys. I had a feeling this was related to defterm, and everything here confirms that suspicion. I bet the focus/foreground handler isn't triggered for defterm connections. I'll take a look. |
Mike, can defterm be configured manually on Windows 10? I have onle unzipped installations of WT? Once installed, by any means, is it easy to switch it on/off? Thanks! |
Nope.
Yep, it's a dropdown in the Settings UI, in the Settings app, and in the Console properties sheet. |
I'm betting that the owner is never set for that pane. If it were set, then deactivating and reactivating that pane would re-mark the pane as focused, fixing the issue. I bet the conpty here never knows the owner, so when it checks if the owner is focused - it never is. I can't just stick a DebugBreak() in Where is
We may be able to remedy this by checking if we don't have a Even after fixing that (4de1ef7),
It's cause focus event requesting is tied to w32 input mode, which apparently isn't requested for defterm EVEN AFTER FIXING THAT it still doesn't work. I'm 100% betting that this is due to the I was right
terminal/src/interactivity/base/HostSignalInputThread.cpp Lines 95 to 102 in 1b81c65
I'm gonna have to peek behind the OS curtain, and see where that API goes. I bet they reject the call in that fashion, because the process we're giving FG to is attached to OpenConsole, not conhost, but conhost does the ConsoleControl (or something like that) There's only one place in I totally know why this don't work. OC tells conhost the handle to the process to request FG for, but that handle doesn't exist in conhost. We're literally just passing the HANDLE value.
So we should be able to DuplicateHandle the handle to the original conhost.... but without OS-side changes to conhost, each of those process handles is just gonna get leaked by conhost, each time. Can we close a handle in another process? Other stupid idea: conhost is never gonna close these handles, so just maintain a map of Or maybe more obviously - openconsole can store the conhost side of the handle in the process list we already maintain, and just wait to close the conhost side of the handle until we prune the process entry (when openconsole is done with it. |
See also: #12799, the origin of much of this. This change evolved over multiple phases. ### Part the first When we create a defterm connection in `TerminalPage::_OnNewConnection`, we don't have the hosting HWND yet, so the tab gets created without one. We'll later get called with the owner, in `Initialize`. To remedy this, we need to: * In `Initialize`, make sure to update any existing controls with the new owner. * In `ControlCore`, actually propogate the new owner down to the connection ### Part the second DefTerm launches don't actually request focus mode, so the Terminal never sends them focus events. We need those focus events so that the console can request foreground rights. To remedy this, we need to: * pass `--win32input` to the commandline used to initialize OpenConsole in ConPTY mode. We request focus events at the same time we request win32-input-mode. * I also added `--resizeQuirk`, because _by all accounts that should be there_. Resizing in defterm windows should be _wacky_ without it, and I'm a little surprised we haven't seen any bugs due to this yet. ### Part the third `ConsoleSetForeground` expects a `HANDLE` to the process we want to give foreground rights to. The problem is, the wire format we used _also_ decided that a HANDLE value was a good idea. It's not. If we pass the literal value of the HANDLE to the process from OpenConsole to conhost, so conhost can call that API, the value that conhost uses there will most likely be an invalid handle. The HANDLE's value is its value in _OpenConsole_, not in conhost. To remedy this, we need to: * Just not forward `ConsoleSetForeground`. Turns out, we _can_ just call that in OpenConsole safely. There's no validation. So just instantiate a static version of the Win32 version of ConsoleControl, just to use for SetForeground. (thanks Dustin) * [x] Tested manually - Win+R `powershell`, `notepad` spawns on top. Closes #13211
@zadjii-msft sorry to leave you with this headache but great analysis and I'm glad that process information I left behind was worth it! |
See also: #12799, the origin of much of this. This change evolved over multiple phases. When we create a defterm connection in `TerminalPage::_OnNewConnection`, we don't have the hosting HWND yet, so the tab gets created without one. We'll later get called with the owner, in `Initialize`. To remedy this, we need to: * In `Initialize`, make sure to update any existing controls with the new owner. * In `ControlCore`, actually propogate the new owner down to the connection DefTerm launches don't actually request focus mode, so the Terminal never sends them focus events. We need those focus events so that the console can request foreground rights. To remedy this, we need to: * pass `--win32input` to the commandline used to initialize OpenConsole in ConPTY mode. We request focus events at the same time we request win32-input-mode. * I also added `--resizeQuirk`, because _by all accounts that should be there_. Resizing in defterm windows should be _wacky_ without it, and I'm a little surprised we haven't seen any bugs due to this yet. `ConsoleSetForeground` expects a `HANDLE` to the process we want to give foreground rights to. The problem is, the wire format we used _also_ decided that a HANDLE value was a good idea. It's not. If we pass the literal value of the HANDLE to the process from OpenConsole to conhost, so conhost can call that API, the value that conhost uses there will most likely be an invalid handle. The HANDLE's value is its value in _OpenConsole_, not in conhost. To remedy this, we need to: * Just not forward `ConsoleSetForeground`. Turns out, we _can_ just call that in OpenConsole safely. There's no validation. So just instantiate a static version of the Win32 version of ConsoleControl, just to use for SetForeground. (thanks Dustin) * [x] Tested manually - Win+R `powershell`, `notepad` spawns on top. Closes #13211 (cherry picked from commit 2a7dd8b) Service-Card-Id: 83026847 Service-Version: 1.14
🎉This issue was addressed in #13247, which has now been successfully released as Handy links: |
🎉This issue was addressed in #13247, which has now been successfully released as Handy links: |
A TCC user said that GUI apps started by TCC in WT don't get focus (unlike other shells in WT and unlike TCC in a console). I said I didn't think I could get TCC and/or WT to act that way if I tried. Have I overlooked anything ... any ideas? Thanks!
The text was updated successfully, but these errors were encountered: