Describe the bug
If Windows Terminal set as default terminal app, after a click on 'Open in Terminal' context menu option the terminal window opens behind the Files UWP window, and the Files UWP window remains in focus.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
A newly opened terminal window should be focused like it is for CMD terminal application.
Screenshot

Desktop (please complete the following information):
for me any file opens behind the app
@XPoppyX Same for me. I think it's a bug.
When opening the app we need to set it to be focused, I haven't looked into it but I would assume it's a simple parameter.
for me only for the first or second time, launching the terminal, the terminal is in the background. After the third time it always opens in the foreground
I have not been able to reproduce this issue, @XPoppyX @Jaiganeshkumaran @lampenlampen what version of Windows are you running? Perhaps the behavior changed with 2004 and that is why I cannot reproduce this.
@yaichenbaum I am using Windows 10 Insider Preview Fast Ring.
in the microsoft store version it does happen, but with the last changes to the master branch I can no longer reproduce this issue
If you're using Windows 10 Insider Preview, the issue of apps opening in the background has been fixed with Build 20150.
If you're using Windows 10 Insider Preview, the issue of apps opening in the background has been fixed with Build 20150.
Can it be fixed in "regular" Windows 10 (I use 19.09)?
I don鈥檛 really know. Since it鈥檚 a system wide bug that affects all applications occasionally and not a Files UWP, I recommend you to give report this issue to Microsoft via Feedback Hub.
I noticed Command Prompt doesn't have this issue. Can anyone else verify if this bug is with the Windows Terminal app only?
only with the terminal app for me

We could always bring the Window to the foreground with Win32 APIs shortly after launching it.
@gave92 This sounds right up your ally. 馃榾
@duke7553 I'm not finding a good way of bringing the window to the front :/
Issue is finding what was launched:
Launcher.LaunchFileAsync won't return the process/window that was openedProcess.Start(file_path) often returns null if the launched app was UWPI have this same issue and also when opening a PDF file. Acrobat Pro opens in the background. I would add more details to this response to the email I received however, I have no idea where to look. I just really love this file manager!
EDIT
JP Johnston ME CSWP
Rogue Exploration Technologies
@gave92 So, you're saying Process.MainWindowHandle would return null, so we cannot use it in BringWindowToTop() ?
@duke7553 The issue of launched app appearing on the background does not seem limited to the Window Terminal (#1270).
So I was hoping to find something that works in the general case (e.g. opening a file).
Process.MainWindowHandle and bring the window to the top (this should work for windows terminal)Edit: but perhaps we can start by fixing Window Terminal and think on the rest later :)
Edit 2: opened a PR with some test code that may solve this: @XPoppyX could you test this and see if it solves the issue? thanks!
Edit 3
The above PR #985 succeeded in consistently bringing the window to the front but I was not able to activate it (user had to click on it)
@duke7553 can this ticket be refactored to be more general?
@gave92 @yaichenbaum I'm not sure if this one is an issue anymore.
In my testing, multiple apps like Terminal, Notepad, and Edge all launch in front of the app window, as expected. Maybe if it is still an issue, we can do something like this when launching another process(?):
public static void DemoteTopmostWindow()
{
var topHwnd = PInvoke.User32.GetTopWindow(IntPtr.Zero);
if (topHwnd != IntPtr.Zero)
{
var nextHwnd = PInvoke.User32.GetWindow(
topHwnd,
PInvoke.User32.GetWindowCommands.GW_HWNDNEXT);
PInvoke.User32.SetForegroundWindow(nextHwnd);
}
}
@duke7553 I'm not sure if this is still an issue, as I was never able to reproduce this consistently.
A couple of possible issues with the code above (that I remember from my previous testing):
@duke7553 I can still reproduce it.
@duke7553 I'm not sure if this is still an issue, as I was never able to reproduce this consistently.
A couple of possible issues with the code above (that I remember from my previous testing):
- the opened window is not always the "next" one, sometimes is the one at the very bottom
- SetForegroundWindow was not working for me, possibly because of calling it from a process which is not on the foreground
Just read the docs on this. You're right, it has to be called from the foreground process, so that function won't work.
@duke7553 there should be a way around this since Autohotkey and the like manage it, I tried looking at their source and they're doing some magic with AttachThreadInput function but could not get it to work
@duke7553 Here's an idea. Create a fake blank foreground and make it transparent
Most helpful comment
for me any file opens behind the app