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

BringWindowToTop doesn't set active tab #18429

Open
zacuke opened this issue Jan 15, 2025 · 0 comments
Open

BringWindowToTop doesn't set active tab #18429

zacuke opened this issue Jan 15, 2025 · 0 comments
Labels
Area-Windowing Window frame, quake mode, tearout Issue-Feature Complex enough to require an in depth planning process and actual budgeted, scheduled work. Product-Conpty For console issues specifically related to conpty
Milestone

Comments

@zacuke
Copy link

zacuke commented Jan 15, 2025

Description of the new feature

Currently, BringWindowToTop only brings the terminal window to the foreground; however, it does not activate the correct tab. In certain scenarios, the user's focus is not restored to the intended location if the active tab isn't the one that initiated the BringWindowToTop call.

Using the information from this StackOverflow post, I created a functional example. The example demonstrates BringWindowToTop being used to ensure the user focus returns to the correct command line.

A current workaround for this limitation is to avoid using tabs altogether and stick with individual console windows instead.

As a side note, it would be nice if the built-in windows start command also had a /refocus option, so the functional example I created wouldn't be necessary. We could alias start /wait /refocus myapp $* to achieve this workflow behavior.

Proposed technical implementation details

If BringWindowToTop() can't be hooked to automatically switch to the active tab, is there an alternative approach to programmatically identify the correct tab using some sort of ID or identifier, and then invoke a function to set that tab as active?

I see a possible way of doing it on line 940 in src/cascadia/TerminalControl/HwndTerminal.cpp
void __stdcall TerminalSetFocus(void* terminal) but it doesn't seem to me that is exposed as a public API.

Which leads me to this

    /// This class is only left public since xaml cannot work with internal classes.
    /// </remarks>
    public class TerminalContainer : HwndHost
    { 
...
private IntPtr TerminalContainer_MessageHook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            if (hwnd == this.hwnd)
            {
                switch ((NativeMethods.WindowMessage)msg)
                {
                    case NativeMethods.WindowMessage.WM_SETFOCUS:
                        NativeMethods.TerminalSetFocus(this.terminal);

I can imagine trying to send the terminal host process some kind of IPC message which would trigger the TerminalSetFocus allowing us to call BringWindowToTop as well as this additional trick to bring the correct tab up too. But ideally, the host process detects BringWindowToTop() and also brings the tab to top.

@zacuke zacuke added the Issue-Feature Complex enough to require an in depth planning process and actual budgeted, scheduled work. label Jan 15, 2025
@microsoft-github-policy-service microsoft-github-policy-service bot added Needs-Tag-Fix Doesn't match tag requirements Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting labels Jan 15, 2025
@carlos-zamora carlos-zamora added Product-Conpty For console issues specifically related to conpty Area-Windowing Window frame, quake mode, tearout and removed Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Needs-Tag-Fix Doesn't match tag requirements labels Jan 15, 2025
@carlos-zamora carlos-zamora added this to the Backlog milestone Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Windowing Window frame, quake mode, tearout Issue-Feature Complex enough to require an in depth planning process and actual budgeted, scheduled work. Product-Conpty For console issues specifically related to conpty
Projects
None yet
Development

No branches or pull requests

2 participants