-
Notifications
You must be signed in to change notification settings - Fork 8.1k
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
Windows Terminal Window Does Not Send EVENT_OBJECT_DESTROY
On Close
#17298
Comments
Until now the orphan window/container reaper has always run on every WinEvent. Unfortunately Windows Terminal does not sent a WinEvent when it is closed. This is a problem for the new border_manager module which draws and destroys borders based on notifications sent to it after WinEvents and SocketMessages have been processed. Since Windows Terminal is not sending a WinEvent on close, this means that user interaction is required to remove the ghost border that gets left behind. This commit starts a separate thread for the reaper where it runs once every second in a loop. This is quite wasteful and definitely not something I wanted to implement, but a temporary solution is needed given the popularity of the buggy application in question. An issue on the Windows Terminal tracker has been opened here: microsoft/terminal#17298
Until now the orphan window/container reaper has always run on every WinEvent. Unfortunately Windows Terminal does not sent a WinEvent when it is closed. This is a problem for the new border_manager module which draws and destroys borders based on notifications sent to it after WinEvents and SocketMessages have been processed. Since Windows Terminal is not sending a WinEvent on close, this means that user interaction is required to remove the ghost border that gets left behind. This commit starts a separate thread for the reaper where it runs once every second in a loop. This is quite wasteful and definitely not something I wanted to implement, but a temporary solution is needed given the popularity of the buggy application in question. An issue on the Windows Terminal tracker has been opened here: microsoft/terminal#17298
I'm somewhat surprised that the OS doesn't do that for us. We use While I can see how we should try to emit these events on exit, I'm not sure whether that would help your project at all. A lot of applications, and not just Windows Terminal, use |
Updates have already been made on our side to protect against any other applications which might exhibit this kind of non-standard
I can confirm this is not the case; applications killed from the Task Manager send
If and when there are more examples from other applications I will be happy to share them, but for now, if 99% of other applications windows are doing the right thing (sending the appropriate |
I've hacked this C++ snippet together as a test case for this issue: https://gist.github.com/lhecker/82b029643e9f9ccf15304a623093880b However, I'm doing something wrong in that code, because the same thing happens for VS Code and other applications: AW5Sm4xuRzrM4pUi.mp4Since it happens with pretty much all applications, I must be doing something wrong but I can't figure out what. @LGUG2Z I don't mean to bother you unnecessarily, but if you can spot any flaws with what I described above, or any flaws in my code, please let me know. 🙂 |
Just after writing that comment, I finally figured out the first mistake I made! Apparently, when a I've now changed the code to instead search through all windows and that gets VS Code down to just 0 to 1 HWND leaks per launch. But that's the same amount as for Windows Terminal. Weird. Am I checking some of the callback parameters incorrectly? 🤔 |
Unfortunately I'm not well versed enough with CPP to offer much meaningful insight, but I created something similar using
I'm tracking the state in a hashmap keyed by the exe path, incrementing by 1 whenever a create event comes through, decrementing by 1 whenever a destroy event comes through, and removing from the map when we drop to 0. For when OpenProcess calls might fail, there is another hashmap keyed with the HWND to look up the exe path if the API call fails. With this I can see that there are a few lingering create events between opening and closing instances of WT that don't have corresponding destroy events, and I'm betting these are for the visible window that interaction happens with 🤔 |
Thoughts:
we honestly don't know! We should find someone who does |
Windows Terminal version
1.19.11213.0
Windows build number
10.0.22631.0
Other Software
No response
Steps to reproduce
Open a single instance of Windows terminal on the desktop. Close that instance of Windows Terminal.
EVENT_OBJECT_DESTROY
is not emitted.Expected Behavior
EVENT_OBJECT_DESTROY
should be emitted when the Windows Terminal window is closed by the window handle that the user has just interacted with.Actual Behavior
EVENT_OBJECT_DESTROY
is not emitted for the Windows Terminal window that was closed.When opening Windows Terminal,
EVENT_SYSTEM_FOREGROUND
is emitted, and the window handle of the actual window that I as the user interact with is the log example below is658858
:When I close the window, sometimes an
EVENT_OBJECT_HIDE
is emitted, but it is emitted for a completely separate window handle (920252
):The text was updated successfully, but these errors were encountered: