-
Notifications
You must be signed in to change notification settings - Fork 8.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
OpenConsole.exe
can steal focus from the terminal
#17168
Comments
Hi I'm an AI powered bot that finds similar issues based off the issue title. Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you! Open similar issues:
|
TraceI repeated step (3) 4 times to get better data, and indeed three instances of openconsole.exe, and all of them stole focus from the terminal just after starting up. The 3rd time it didn't steal the focus, proving that it might not always happen. I was investigating microsoft/wslg#1212 which also deals with the same area of focus lost issue. They shared a trace profile |
I'm guessing what you've done here is basically investigate #13388. That bug has been my white whale for... really some long time now. I've spent months trying to trace or get consistent enough repros to find something out. I'm 99% sure the code that creates that window is in
WS_POPUP , WS_EX_TOOLWINDOW | WS_EX_TRANSPARENT | WS_EX_LAYERED | WS_EX_NOACTIVATE window still gets foreground - because it doesn't make any sense.
Maybe you'll have better luck? If you've got a consistent repro, then maybe there's more traces we could have you collect? I'll reach out to him and see. |
#16014 also had some windowing changes that I wanted to experiment with, but I also didn't have a consistent repro, so they were all guesses. If you've got a consistent repro, maybe you might be able to get a better signal out of that PR? (though, admittedly, that PR was mostly there to address the tiny boxes that sometimes show up in the top-right corner of the monitor, ala #15219) |
re: #16014 (comment) |
I think part of the problem (and this is me trying to remember what Evan was explaining a year back) was that it can receive a I forget why we didn't ever merge that PR in the past, but we should totally just do that as soon as 1.21 forks |
(Oh, it may be worth mentioning for other readers of this issue that I responded over in the mentioned PR, where I felt like it's more appropriate. Here: #16014 (comment)) |
Based on #16014, I tried all window (extended/non-extended) styles in islolation, and nothing seems to stop the child window from stealing parent focus. What am I missing here? Code#include <windows.h>
#include "string"
static constexpr auto parentWindowClass = L"ParentWindow";
static constexpr auto childWindowClass = L"ChildWindow";
LRESULT static _stdcall WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
if (message == WM_DESTROY)
{
PostQuitMessage(0);
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
ATOM MyRegisterClass(const std::wstring& szWindowClass)
{
WNDCLASSEXW wcex{ 0 };
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.lpfnWndProc = WndProc;
wcex.cbWndExtra = 0;
wcex.lpszClassName = &szWindowClass[0];
return RegisterClassExW(&wcex);
}
int _stdcall wWinMain(HINSTANCE hInstance,
HINSTANCE /*hPrevInstance*/,
LPWSTR /*lpCmdLine*/,
int nCmdShow)
{
const auto parentClassName = reinterpret_cast<LPCWSTR>(MyRegisterClass(parentWindowClass));
const auto childClassName = reinterpret_cast<LPCWSTR>(MyRegisterClass(childWindowClass));
// Parent window
HWND hWnd = CreateWindowW(parentClassName,
nullptr,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
nullptr,
nullptr,
nullptr,
nullptr);
if (!hWnd)
{
return FALSE;
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
// Child window
// using WS_POPUP makes the window invisible, but doesn't stop the focus shifting.
const auto styles = WS_OVERLAPPED | (WS_MINIMIZEBOX | WS_SYSMENU);
// - using WS_EX_LAYERED makes the window invisible, but doesn't stop the focus shifting.
// - WS_EX_NOACTIVATE doesn't stop the focus shifting too.
const auto exStyles = WS_EX_TRANSPARENT | WS_EX_NOACTIVATE;
HWND childHWnd = CreateWindowExW(exStyles,
childClassName,
nullptr,
styles,
0,
0,
0,
0,
hWnd,
nullptr,
nullptr,
nullptr);
ShowWindow(childHWnd, nCmdShow);
UpdateWindow(childHWnd);
// SetForegroundWindow(hWnd);
// This SETS parent (not ownership) even when WS_CHILD isn't used???
//
// SetParent also seems to put the focus to the child hwnd. Another opportunity for focus shifting.
// SetParent(childHWnd, hWnd);
// Message loop
MSG msg;
while (GetMessage(&msg, nullptr, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int) msg.wParam;
} |
I believe the problem is that you need to pass terminal/src/host/outputStream.cpp Line 223 in a0d1329
|
wait @tusharsnx did the 👍 you gave on #17168 (comment) actually mean "that worked"? I feel like we've been at a loss for so long on this, that I'm just desperate for any progress at all |
You can try ANSI escape code void Clear() |
@tusharsnx just to double check - is this fixed in the latest canary for you/? |
@zadjii-msft Yes, I can't repro this in the latest canary (1.23.2481.0) 😃 |
Windows Terminal version
Windows Terminal Dev
Windows build number
10.0.22631.0
Other Software
No response
Steps to reproduce
Expected Behavior
WT starts with focus.
Actual Behavior
WT starts without focus.
The text was updated successfully, but these errors were encountered: