Repository navigation
Resolve the TSF InputSite HWND within the owning Terminal window - #20913
김대현 (96-kdh) wants to merge 3 commits into
Conversation
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
|
@microsoft-github-policy-service agree |
|
The spelling check failed during dependency installation due to a DNS resolution error for azure.archive.ubuntu.com, before spelling validation ran. Could a maintainer please rerun the failed job? Failed job: https://github.com/microsoft/terminal/actions/runs/43042027734/job/130596059108 |
There was a problem hiding this comment.
Thank you for making this PR. But it's incomplete:
- It states that
FindWindowOfActiveTSFis wrong and yet it still exists - It also states that it may not be cached but not why it should not be cached.
_tsfDataProvideris per pane and the only bug I see is that we don't reset_tsfDataProvider._hwndwhen the tab gets dragged.
All windows share one UI thread and ITfThreadMgr, and EnumDocumentMgrs returns document managers in creation order, so the first one may belong to a different window. Look up the InputSite window only underneath our own window instead, and cache it per control. A TermControl never moves between windows (tab moves create a new control), so the cached HWND cannot go stale. Failed lookups are not cached.
|
Thanks for the review. My earlier explanation was too broad: the issue is which window's HWND gets cached, rather than caching itself. I've revised the change to address both points:
The underlying problem is that all Terminal windows share one UI thread and For validation, I used automated UI tests (AutoHotkey) with eight windows open simultaneously, checking whether the Hangul/English toggle took effect:
These results are limited to the tested environment and automated input sequence. |
|
김대현 (@96-kdh) We do not permit LLM-authored comments in our repository, and I'll not read what you wrote out of principle. We're basically down to ~1 maintainer for this project and have little time to read large amounts of text, as typically produced by LLMs. You may use LLMs for translating your comments, however. |
| const auto hwnd = FindInputSiteWindow(owner); | ||
| // Only cache a successful lookup. A TermControl never changes windows | ||
| // (moving a tab creates a new one), so the result never goes stale. | ||
| if (hwnd != owner) |
There was a problem hiding this comment.
Seems like you may want to return nullptr instead. The comparison against owner is not obvious without reading FindInputSiteWindow's implementation.
| _hwnd = GetTSFHandle().FindWindowOfActiveTSF(); | ||
| if (!_hwnd) | ||
| // All windows share the same UI thread and ITfThreadMgr, so we must look for the one underneath | ||
| // our own window. Asking TSF instead (e.g. via EnumDocumentMgrs) yields an arbitrary window's. |
There was a problem hiding this comment.
Ah I see now, your theory is that EnumDocumentMgrs may return any windows' input site.
My assumption was that focusing a window enables the current windows' input site first and only then raises the XAML focus event, and only then we enter this function after all - by this time, FindWindowOfActiveTSF would thus return the input site HWND.
There was a problem hiding this comment.
FindWindowOfActiveTSF takes only the first entry from EnumDocumentMgrs via Next(1, …), without checking whether it belongs to the focused window. Even with the focus sequence you described, that first entry is not necessarily associated with the current window.
If the first lookup selects another window's InputSite, that HWND remains cached for subsequent calls.
In the tests, failures clustered on the same tabs across clicks, window activation, and tab switches, though those tabs sometimes succeeded.
Summary of the Pull Request
Resolve the TSF InputSite HWND within the control's owning window instead of caching a HWND obtained from the thread's document-manager enumeration. With multiple Terminal windows sharing a UI thread, the cached handle can belong to another window, leaving Korean input toggles ineffective after window reactivation.
References and Relevant Issues
Closes #20912.
Draft for discussion of the proposed approach. The issue has been filed; maintainer agreement on the approach has not yet been obtained.
Detailed Description of the Pull Request / Additional comments
Search for the InputSite descendant under
OwningHwnd(). If it does not exist yet, return the owner and search again on the next call. A null owner returns null. Remove the HWND cache so owner changes and InputSite recreation do not retain stale handles or borrow another window's TSF context.Five tests use real hidden Win32 windows to cover separate owners, null owners, delayed creation, nested descendants/reparenting, and destruction/recreation. These exercise the helper rather than the complete TSF event sequence.
The cross-window cache mismatch was directly observed in official 1.24.12741.0. The exact initialization ordering that first selects the incorrect handle is not isolated; the visible failure is intermittent. See #20912 for evidence and reproduction details.
AI assistance was used for investigation, implementation, tests and drafting. The submitting contributor personally observed the automated reproduction, checked the results, and read and understood the complete code change.
Validation Steps Performed
Control.Unit.Tests.dll /name:*InputSiteWindowTests*: 5 passed, 0 failed.Control.Unit.Tests.dll: 34 passed, 0 failed, 0 blocked/skipped/not run.5f7dc283013152f89bfb76950515c33f45157ad7: original implementation failed in 7/20 tabs; proposed implementation failed in 0/20. All 40 cases had complete received-text records and owned focus at every observation. Each variant retained windows in one process, so these counts are not population failure-rate estimates.Microsoft.Terminal.Control.dlldiffered. Actual loaded DLL paths were independently recorded. Both layouts successfully launched PowerShell child processes.PR Checklist