-
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
Sometimes the Terminal launches behind all other windows / without foreground / isn't activated #15479
Comments
@DHowett had a pretty simple repro with: |
edit 20.6. |
Uhg guys I can't get this to repro. Certainly not consistently. I had it happen like, once by
I reckon that this regressed in the #5000 changes. Especially somewhere around the way that a new window gets summoned in the existing process. I just can't for the life of me get a consistent repro. It probably depends on
|
Something blind we could try: diff --git a/src/cascadia/WindowsTerminal/AppHost.cpp b/src/cascadia/WindowsTerminal/AppHost.cpp
index 81218dbf4..af5d8d7ff 100644
--- a/src/cascadia/WindowsTerminal/AppHost.cpp
+++ b/src/cascadia/WindowsTerminal/AppHost.cpp
@@ -1406,6 +1406,8 @@ winrt::fire_and_forget AppHost::_WindowInitializedHandler(const winrt::Windows::
nCmdShow == SW_FORCEMINIMIZE;
if (!noForeground)
{
+ LOG_IF_WIN32_BOOL_FALSE(BringWindowToTop(_window->GetHandle()));
+
SetForegroundWindow(_window->GetHandle());
_peasantNotifyActivateWindow();
} around: terminal/src/cascadia/WindowsTerminal/AppHost.cpp Lines 1396 to 1412 in 059f770
That's what I'd bet the culprit is, if there is one. |
Not sure it's actually related to this issue but anyways, regarding a non-focused window on startup, you can also take a look at this thread from Directory Opus user. I can confirm the same behaviour: invoking default "Open in Terminal" context menu entry in DOpus is misbehaving (it's not happening with Explorer or when launching the Terminal from Start Menu, though). |
Welp. I can't repro that with Directory Opus myself. Just launches straight to the foreground, from both a cold launch and a warm launch. Are you doing anything weird with |
Indeed, I had UAC disabled as well, but after re-enabling it, Terminal no longer launches as admin, but still launches behind DOpus window. Also note that the problem is only with 'Open in Terminal' entry, if for example I launch PowerShell or Cmd directly - everything works fine, they're opened in Terminal which is correctly brought to foreground. Update1: It happens for me regardless of LaunchMode mentioned in this issue (I've tried 'Default', 'Maximized', 'Fullscreen', 'Focus', 'Maximized Focus' and they all appear behind DOpus). Update2: If I now set the default profile to launch elevated, the system correctly shows me UAC prompt and then brings the window to foreground. Update3: If I launch DOpus itself elevated, then there is no 'Open in Terminal' entry anymore and when I try to launch PowerShell/Cmd directly they no longer spawn inside WT, but instead in their own consoles. |
I can repro my previous steps like 99% all the time. Doesn't matter if it is fresh boot with nothing running, or launching over 30 apps. Next thing is if I click drop arrow in terminal, and Shift + Click on any profile, new window is shown behind Terminal window from which I executed new profile, not in foreground. But now, not always, steps to reproduce:
But this is not 100% always. If I do it continuously, it spawns new windows randomly in foreground/background. |
Relatedly to this issue, WT sometimes opens in the background, behind all other applications. I can fairly readily reproduce that by holding shift while clicking it in the start menu. Holding shift should simply make the launched application unfocused and this works correctly for e.g. conhost, but WT doesn't even launch in the foreground. |
Now, with v1.19, WT is launched in background 100% times, behind all apps. Looks like new instance is put on the last place of Z-order. |
You wanna know something crazy? I can 100% repro that, UNLESS I have a debugger attached. With either VS or WinDBG attached, the window always opens in the front, with foreground. That's just amazingly annoying for the sake of attempting to debug. Interestingly enough, I get the same behavior with Notepad that I'm seeing here. Curious. |
This seems to happen to me when I enable open a quake window / run in headless It stops happening once I kill all wt processes and there's no quake mode enabled For me, 100% reproducibility |
This is incredibly annoying on windows 11 since there is no way to ungroup taskbar items (or at least there wasn't, I haven't researched lately)... I feel like recently something has changed with how this works. I'll hit windows key, type term and hit enter to open a new terminal fast. It's in my muscle memory. Now I have to go searching for the new window every time! |
I have the same issue. Just started after a fresh install of windows and all apps. |
I went to settings, changed the launch parameters and tested a few options and saved. Changed them back to defaults and now it's not happening. We'll see if it re-occurs. |
It didn't fix it for long. |
@AshleyScirra thank you for your replication steps. they also replicate for me. -- @jakenybo do the steps provided in #15479 (comment) replicate your issue reliably (and compared to beginning with no terminal windows open and minimized)? many people here report being frustrated with this problem, so i would assume these people do not have a fix. i suspect we simply have to use workarounds |
@lucasreddinger, yes those steps replicate the same behavior on my machine. i'm learning that i think the issue has more to do with whether or not you already have an instance of Windows Terminal running. if no prior Windows Terminal instance is running, the "Open in Terminal" option in a folder will open the Windows Terminal window on top of Windows Explorer (as it should). if you already have another instance of Windows Terminal running (even minimized to system tray, as is the case with me), then all subsequent "Open in Terminal" options will open the Windows Terminal window behind the WIndows Explorer window (which is erroneous behavior given its default behavior). i don't know why anyone would ever want it to open in the background if you just selected "Open in Terminal". that should always result in Window Terminal opening on top of all other windows a fix for this would be great! |
Also having the problem here! I came to the same conclusion as @jakenybo. Versions
|
in my case, the win+r + wt combination openes a terminal in foreground if i have another terminal opened which was moved on the screen using winkey+alt |
I experience this behavior consistently when:
This behavior does not occur when:
In my case, the behavior described above is consistent across profiles, launching directories, and seems independent of running instances and in-app settings. Build 22631.3296 PD: Here's the icon in case anyone is trying to make new shortcuts: |
New observation. I'm getting 100% no-focus when launching Terminal with WSL2 default profile for the first time. Doesn't matter how/from where. As for fist time it took like 2-3 seconds to start WSL2. Probably it is launhch Hyper-V services or whatever else, I don't know. During startup it has focus, WSL2 distro shows shell and Terminal loses focus. Funny thing is that while it is starting, it affect VMware Player window, because it flashes. Often ctrl + click from dropdown menu opens new Terminal without focus, or even behind current Terminal window. Terminal Version: 1.20.10572.0 I think it never happened with WSL1 as it starts instantly. |
@marbaa That sounds like the WSL issue here: microsoft/wslg#1212. This also means that specific issue is not related to WT, and could be repro on other terminals (Eg. VS, VSCode) |
I have been facing the same issue consistently when opening the WT through the Windows 11 start menu or PowerToys Run.
I could see this being resolved by forcibly ordering the new window on top of the Window stack with the |
For the version (1.19.11213.0, released on May 4th, 2024), the problem seemed solved. New window can be created on the top of the old window. But that is not the case if new windows are created on a different desktop: If I open one window at one virtual desktop, switch to another virtual desktop, open a new window and close it. From now on, the new created window will lose the focus, thought the cursor blinking. I find this from about one year ago and use the preview one downloaded here, instead of that installed in the Microsoft store. |
I tried the new prelease. Problem still happens to me. Any subsequent launches after the first have their windows go behind everything else, regardless whether the launch was from context menu or app shortcut in the taskbar search Edit: just realized my comment sounds a bit snarky. That was not intended. I read the above comment wrong thinking it was solved in the new version, and wanted to make it clear it still happens for me |
I can confirm that the behavior does persist with ne new version on my system as well. I hope hope this can be resolved, I am happy with the terminal application regardless. It would just add convenience if the opened terminal was visible and had keyboard focus. If I can find the time I will try to help in finding a workaround. |
You know what, if you just ensure that any window of the terminal is focused when the new window is starting up, the new window always starts in the foreground. And same goes for when no window of the terminal has focus, the new window starts behind all other windows on the screen😕 It doesn't work as a workaround though, because only the foreground window (or its process) can request to change the foreground window to a different one. |
I have some different behaviours depending on launch method, but for me, it seems to only be failing with the Quake console active.
|
Started to open on background always. Only |
Same issue. Also happens when run through "Send To" shortcut or when started through Flow Launcher. |
Sometimes subsequent WT windows open in the background behind other applications. This PR tries to fix it. Refs #15895 Refs #15479 Mysterious bug (and annoying). There are even some discussions about happening to the first startup, not just subsequent ones. Sometimes the window may show up without animation too. So I don't think this is the final solution, but it did get solved on my computer, for now. ## Validation Steps Performed 0. Quit all WT windows if some. 1. Open File Explorer, click "Open in Terminal" in context menu. 2. Move the newly opened window and minimize it. 3. Back to step 1 and repeat several times. 4. All the windows should open in the foreground correctly (yet possibly without animation). --------- Co-authored-by: Mike Griese <migrie@microsoft.com>
Sometimes subsequent WT windows open in the background behind other applications. This PR tries to fix it. Refs #15895 Refs #15479 Mysterious bug (and annoying). There are even some discussions about happening to the first startup, not just subsequent ones. Sometimes the window may show up without animation too. So I don't think this is the final solution, but it did get solved on my computer, for now. ## Validation Steps Performed 0. Quit all WT windows if some. 1. Open File Explorer, click "Open in Terminal" in context menu. 2. Move the newly opened window and minimize it. 3. Back to step 1 and repeat several times. 4. All the windows should open in the foreground correctly (yet possibly without animation). --------- Co-authored-by: Mike Griese <migrie@microsoft.com> (cherry picked from commit c52ba7d) Service-Card-Id: 92715122 Service-Version: 1.21
Sometimes subsequent WT windows open in the background behind other applications. This PR tries to fix it. Refs #15895 Refs #15479 Mysterious bug (and annoying). There are even some discussions about happening to the first startup, not just subsequent ones. Sometimes the window may show up without animation too. So I don't think this is the final solution, but it did get solved on my computer, for now. ## Validation Steps Performed 0. Quit all WT windows if some. 1. Open File Explorer, click "Open in Terminal" in context menu. 2. Move the newly opened window and minimize it. 3. Back to step 1 and repeat several times. 4. All the windows should open in the foreground correctly (yet possibly without animation). --------- Co-authored-by: Mike Griese <migrie@microsoft.com> (cherry picked from commit c52ba7d) Service-Card-Id: 92715121 Service-Version: 1.20
This may have been fixed by #17368 in 1.22 Preview - can anyone confirm/? |
The steps I described in this comment no longer reproduce for me with Windows Terminal v1.20.11781.0 on Windows 11 23H2 (build 22631.4037). Glad it's working as this had been bugging me for ages! |
@zadjii-msft Can confirm that this is working for me! Thanks so much Windows information: |
This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. |
Windows Terminal version
1.18.1421.0
Windows build number
10.0.22621.1702
Other Software
No response
Steps to reproduce
Just leave the default value in Settings -> Launch parameters -> Launch Mode -> Default.
Terminal window is launched but has no focus. Doesn't matter which profile is set to default, if Powershell, or WSL, or whatever else. Often happens that if I'm in other application and I run Terminal, from pinned taskbar icon for example, it is not visible at all. Doesn't matter if I run it with keyboard shortcut Win + 1-9 or with middle mouse button. It starts behind the current application which I'm in.
Expected Behavior
Terminal window in foreground with focus.
Actual Behavior
Terminal window in foreground without focus, and sometimes even hidden behind other application.
The text was updated successfully, but these errors were encountered: