WSL VM boot up steals focus from the foreground app
tusharsnx opened this issue · comments
Windows Version
Microsoft Windows [Version 10.0.22631.3235]
WSL Version
2.1.4.0
Are you using WSL 1 or WSL 2?
- WSL 2
- WSL 1
Kernel Version
5.15.146.1-2
Distro Version
No response
Other Software
No response
Repro Steps
- To ensure wsl isn't running in the background, run
wsl --shutdown
. - Start wsl:
wsl
- Focus is lost from the terminal app.
This repros on VScode and Visual Studio integrated terminals, and Windows Terminal also.
Expected Behavior
Focus is still on the foreground (terminal) app.
Actual Behavior
Focus is lost from the foreground app.
Diagnostic Logs
No response
Hi I'm an AI powered bot that finds similar issues based off the issue title.
Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!
Closed similar issues:
- WSL does not get focus when launching from taskbar (#3443), similarity score: 0.71
Note: You can give me feedback by thumbs upping or thumbs downing this comment.
As wsl is a background service, it shouldn't steal focus when starting up.
This is most likely caused by wslg, transferring.
@tusharsnx, would you please collect log and share with us? thanks!
- download foregroundTracing.txt and save as foregroundTracing.wprp at local disk.
- run wpr -start foregroundTracing.wprp from Windows's command prompt
- launch wsl and observe window focus issue.
- run wpr -stop foregroundTracing.etl
- share foregroundTracing.etl with us.
@hideyukn88 I am using Windows 11 23H2 on two systems. Could reproduce that issue on both system this afternoon. On one system, I had the impression that when the focus got lost, the language selector (the ENG
guy below) flickered; but that may have been a consequence of the focus switch itself. Disabling it did not help.
Now, I cannot reproduce this behavior on either system. Will update this issue with traces if it occurs again.
@hideyukn88 TBH, I couldn't reproduce it at the moment, but I do see it sometimes. I think after I created this issue the severity has gone down a little. Previously, I used to see it at every wsl boot, but now seems like it only happens at the first wsl boot up after the system is restarted. I'm also on the latest pre-release version, so maybe something was fixed between this version and the earlier versions.
I'll try to submit the trace if I see it again. For now, since bersbersbers can repro it, I should keep it open?
Okay, I've got a perfect repro. When I'm debugging any application and run wsl --shutdown && wsl
while the debugging session is on, the windows terminal loses focus 100% of the time.
Steps to repro:
- Create a scratch project in VS
#include <iostream>
int main() {
std::cout << "hello world";
// I tried to put a breakpoint to keep the program running,
// but that doesn't repro the issue.
// So, it seems like program must be in running state,
// which we do by blocking on cin.get().
std::cin.get();
return 0;
}
- Start a debugging session by clicking on "Local Windows Debugger".
- A terminal window would open with the output of "hello world".
- Create a new terminal tab within the same window.
- run
wsl --shutdown && wsl
. - In a moment, the terminal window would lose focus.
Trace:
I repeated the step (5) 3 times.
foregroundTracing.zip
wsl-focus-lost-repro-video.zip
On one system, I had the impression that when the focus got lost, the language selector (the ENG guy below) flickered; but that may have been a consequence of the focus switch itself.
@bersbersbers You're right, I just realized that too (I usually have my taskbar autohide so I couldn't notice it earlier) you can see in the repro video 😄