terminal
terminal copied to clipboard
Sometimes the Terminal launches behind all other windows / without foreground / isn't activated
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.
@DHowett had a pretty simple repro with:
wt -w -1
Run that from the Run dialog
~~Found situation when this nofocus issue occurs. It is because of Quake mode.~~
~~Steps to repro:~~
~~1. Lanuch WT by whatever way it is possible (from Start menu, from taskbar, .exe, ...)~~
~~2. Open Quake-mode with WIN + ~~ ~~3. Launch some ssh session there (I have always running ```az network tunnel``` session in Quake-mode window)~~ ~~4. Hide Quake-mode with WIN + ~~
~~5. Launch new WT instance from step 1.~~
~~This way, new lanuched WT doesn't have focus. If you disconnect the sessions in Quake-mode, and hide Quake-mode, then the newly WT instances will have focus correctly.~~
edit 20.6. Above is not true. Next day, it happened without using Quake-mode.
Uhg guys I can't get this to repro. Certainly not consistently. I had it happen like, once by
- shift clicking on the taskbar (with a window already open),
- waiting what seemed like a minute
- activating other windows. Minimizing one.
- then eventually the new window appeared, beneath everything.
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
- If there's a terminal window already running
- How you spawn the new terminal window
- what you do before the new terminal window launches
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: https://github.com/microsoft/terminal/blob/059f7701f241a314a049eb5d2c62cf7f4c3b803f/src/cascadia/WindowsTerminal/AppHost.cpp#L1396-L1412
That's what I'd bet the culprit is, if there is one.
Uhg guys I can't get this to repro. Certainly not consistently. I had it happen like, once by
- shift clicking on the taskbar (with a window already open),
- waiting what seemed like a minute
- activating other windows. Minimizing one.
- then eventually the new window appeared, beneath everything.
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
- If there's a terminal window already running
- How you spawn the new terminal window
- what you do before the new terminal window launches
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 elevate: true in your profiles? From the GIF in the linked thread, that looks like they're running with UAC disabled entirely, but that might be another variable here.
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
elevate: truein your profiles? From the GIF in the linked thread, that looks like they're running with UAC disabled entirely, but that might be another variable here.
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:
- Don't have any Terminal running.
- Start Terminal with whatever way.
- Shift + Click on any new profile in down arrow menu - new Terminal window is shown in background.
- Shift + Click again on any new profile to open another session - new Terminal winndow is now shown in foreground.
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. If no apps are running, WT is launched with no focus.
I can fairly readily reproduce that by holding shift while clicking it in the start menu.
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.
Interestingly enough, I get the same behavior with Notepad that I'm seeing here. Curious.
For me, it sometimes also happens with ShareX, when double-clicking their tray icon. May be not a Terminal, but a Windows issue?
Also, found out that the second & further Terminal windows always open behind any other apps & even behind previous Terminal windows. This happens regardless of how the first window was launched.
This is the latest v1.18, and the following param:
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.
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.
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).
"Open in Terminal" in Explorer does it for me sometimes. I'll try to figure out how to reproduce it reliably.
Infuriating!
2 days ago i noticed that when using the windows 11 context-menu Open in Terminal: Terminal launches BEHIND explorer 100% of the time.
I use that link ~300 times per day and didn't notice it before, but I have an ultrawide, so perhaps it was always like this and I just fluked explorer never being in the same spot when it launches. More realistic estimate might be ~2-3 months ago when Power Rename also started opening behind W11 Explorer 100% of time when using that same context menu.
I now end up with literally dozens of terminal windows in the background when I go to shutdown my PC each day, reminding me of all the times I didn't notice it launching behind focus.
In case it helps, I can reproduce this 100% on Windows 11 with these steps:
- Open File Explorer to a folder
- Right-click in a space in the folder and choose 'Open in Terminal' - it appears on top
- Minimize that Terminal window
- Right-click in a space in the folder and choose 'Open in Terminal' again - it appears underneath
I can't recall exactly but I don't think 'Open in Terminal' is in the explorer context menu by default, I think there's some developer setting to turn that on. Also step 4 requires that the terminal window attempts to open in a position overlapping File Explorer, so you might need to drag windows around to make sure that at step 4 they overlap.
This is really annoying for me as for my job I start the day by opening Terminal, starting a HTTP server, minimizing it, then doing web development all day which occasionally involves opening more terminals, which always appear under File Explorer every time.
I am having the exact same issues. Interestingly enough here's what I have found:
- Running
wtin the run window = window goes to back - Searching in windows search for "terminal" then pressing enter = window goes to back
- Right clicking taskbar icon and selecting terminal = window goes to back
- Opening terminal by doing win + x then selecting terminal = windows goes to front????
So a temporary shortcut for fellow shortcut lovers is to do win + x then i. That's the fastest way I have found to open a new wt without it going to the back.
This is so frustrating 🥲
To follow up on pTinosq, I've been having this problem of it launching in the background for a long time.
I can confirm point 4 indeed did cause it to go to front for me. Huh.
in my configuration, right-clicking inside a folder in windows explorer and selecting "Open in Terminal" launches the Windows Terminal window behind the Windows Explorer window. frustrating because it require me to click down on the taskbar to bring it to the front for use. any suggestions on a fix?
@AshleyScirra thank you for your replication steps. they also replicate for me.
--
@jakenybo do the steps provided in https://github.com/microsoft/terminal/issues/15479#issuecomment-1895644698 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
- Windows Terminal:
1.19.10573.0 - Windows version:
Windows 11 Family - 23H2 - 22631.3155
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:
- Launching from from system-generated start menu shortcut, search result, or 'all apps' list
- Except when launching in admin mode
- Launching from pinned taskbar element (or by left clicking taskbar element > l-click Terminal > Open)
- Except when launching in admin mode
This behavior does not occur when:
- Launching from Win + X menu
- Launching by double clicking executable
- Launching from user-created shortcut
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 WT 1.19.10573.0
PD: Here's the icon in case anyone is trying to make new shortcuts: https://raw.githubusercontent.com/microsoft/terminal/master/res/terminal.ico
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. Mess..
Terminal Version: 1.20.10572.0 Windows 11 22H2 (22621.3155) Dell 7560 + NVIDIA T1200 (driver 551.61)
I think it never happened with WSL1 as it starts instantly.
@marbaa That sounds like the WSL issue here: https://github.com/microsoft/wslg/issues/1212.
This also means that specific issue is not related to WT, and could be repro on other terminals (Eg. VS, VSCode)