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

WSL VM boot up steals focus from the foreground app #1212

Open
1 of 2 tasks
tusharsnx opened this issue Mar 13, 2024 · 7 comments
Open
1 of 2 tasks

WSL VM boot up steals focus from the foreground app #1212

tusharsnx opened this issue Mar 13, 2024 · 7 comments

Comments

@tusharsnx
Copy link

tusharsnx commented Mar 13, 2024

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

  1. To ensure wsl isn't running in the background, run wsl --shutdown.
  2. Start wsl: wsl
  3. 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

Copy link

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:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

@tusharsnx
Copy link
Author

As wsl is a background service, it shouldn't steal focus when starting up.

@OneBlue
Copy link
Collaborator

OneBlue commented Mar 13, 2024

This is most likely caused by wslg, transferring.

@hideyukn88
Copy link
Member

@tusharsnx, would you please collect log and share with us? thanks!

  1. download foregroundTracing.txt and save as foregroundTracing.wprp at local disk.
  2. run wpr -start foregroundTracing.wprp from Windows's command prompt
  3. launch wsl and observe window focus issue.
  4. run wpr -stop foregroundTracing.etl
  5. share foregroundTracing.etl with us.

@bersbersbers
Copy link

@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.

image

Now, I cannot reproduce this behavior on either system. Will update this issue with traces if it occurs again.

@tusharsnx
Copy link
Author

@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?

@tusharsnx
Copy link
Author

tusharsnx commented Apr 30, 2024

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:

  1. 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;
}
  1. Start a debugging session by clicking on "Local Windows Debugger".
  2. A terminal window would open with the output of "hello world".
  3. Create a new terminal tab within the same window.
  4. run wsl --shutdown && wsl.
  5. In a moment, the terminal window would lose focus.

Trace:

I repeated the step (5) 3 times.

image

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 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants