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

New WSL session loses focus on startup #998

Open
bobf32 opened this issue Mar 5, 2023 · 18 comments
Open

New WSL session loses focus on startup #998

bobf32 opened this issue Mar 5, 2023 · 18 comments
Labels
bug Something isn't working fixinbound

Comments

@bobf32
Copy link

bobf32 commented Mar 5, 2023

Windows build number:

19045.2604

Your Distribution version:

22.04

Your WSL versions:

WSL version: 1.1.3.0
Kernel version: 5.15.90.1
WSLg version: 1.0.49
MSRDC version: 1.2.3770
Direct3D version: 1.608.2-61064218
DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows version: 10.0.19045.2604

Steps to reproduce:

See mintty/wsltty#329

WSL logs:

No response

WSL dumps:

No response

Expected behavior:

No response

Actual behavior:

On starting a new WSL session, the focus should be set to the window containing that session. This is not the case.

@bobf32 bobf32 added the bug Something isn't working label Mar 5, 2023
@hideyukn88
Copy link
Member

@bobf32, thanks for reporting the issue, I do not observe the issue reported, After launching the mintty, the new "Ubuntu-20.04" window open, then the focus is moved to that window from the window launched mintty, So if I type something from keyboard, the input goes to newly opened "Ubuntu-20.04" window, as below shows as I typed "hello". Is this the expected behavior? thanks!

image

@bobf32
Copy link
Author

bobf32 commented Mar 9, 2023

That's pretty much it, but I can simplify. To reproduce:

  1. Ensure .wslconfig file does not contain line guiApplications=false
  2. From a command prompt: wsl --shutdown
  3. wsl

The window housing the command prompt and now bash session somehow loses focus at this point, and I have to alt-tab or click in it to type into the terminal. Mintty was a red herring, not required to reproduce this.

Further invocations of wsl occasionally but not always exhibit the same issue, but the numbered steps above are reproducible, i.e. after a shutdown. If I include guiApplications=false in .wslconfig all is fine.

@hideyukn88
Copy link
Member

@Bob32, I still don't observe the focus lost with wsl.exe, but starting up WSL with guiApplications enabled involves launching msrdc.exe in background, so it possible that the focus is changed by that, although it might vary by other factors such as host Window's version. Would you please share log files from /mnt/wslg? I would like to double check if there are some unexpected errors, thanks!

@bobf32
Copy link
Author

bobf32 commented Mar 9, 2023

Sure, please see attached.

wslg.zip

@hideyukn88
Copy link
Member

hideyukn88 commented Mar 9, 2023

@bobf32, thanks for sharing the log, and I do see some clue there, below line in your log indicates there is some UI being created in Linux side, and this is most likely the reason of focus change, and for me, I don't see this until I actually run some GUI apps, like firefox, do you have some custom script to run at startup? thanks!

[22:23:12.933] rdp_rail_wake_handler is called on peer_ctx:0x5559cbf733a0

@bobf32
Copy link
Author

bobf32 commented Mar 10, 2023

I have a .bashrc but nothing else that I am aware of. And this does not start any gui stuff I don't think. I don't tend to use gui apps with wsl.

@hideyukn88
Copy link
Member

@bobf32, is it possible you can install fresh distro and see if same issue still occurs? and if you have any customization made by c:\Users\[your user name]\.wslconfig or /etc/wsl.conf, please share with us, thanks!

@bobf32
Copy link
Author

bobf32 commented Mar 10, 2023

I have just installed a fresh copy of Ubuntu 22.04.2 LTS and the problem still occurs.

Problem occurs now in two distros, and in both cases whether .wslconfig exists or not.

In neither case do I have /etc/wsl.conf.

@hideyukn88
Copy link
Member

@bobf32, thanks for trying out. I think, at this point, I will need to have some additional instrumentation to understand this further, and at same time, I will be checking if any repro internally, I will post here if any updates, thanks!

@hideyukn88
Copy link
Member

@bobf32, update: I'm able to reproduce the issue on Windows 10 (while I cannot on Windows 11), and it looks you are on Windows 10 as well, and in this case, the window focus is moved to a window created by msrdc.exe (msrdc.exe is indirectly launched by wsl.exe in background). Do you happen to have separate environment on Windows 11? if so, please check if this does not occur on Windows 11, thanks!

image

@bobf32
Copy link
Author

bobf32 commented Mar 28, 2023

Thank you for the update @hideyukn88. I am indeed on Windows 10 but have not got a Windows 11 environment right now. I'll try and spin up a VM when I get some time.

@hideyukn88
Copy link
Member

The fix for this focus lost issue went into msrdc.exe code, thanks!

@bobf32
Copy link
Author

bobf32 commented Apr 5, 2023

@hideyukn88 Great, is it available yet? What do I need to do to get the fix?

@decriptor
Copy link

I'm having this problem. It doesn't seem like this fix has been released yet? Is there an ETA?

@jacktose
Copy link

jacktose commented Oct 24, 2023

@hideyukn88 That's great news! How does msrdc.exe get updated? Can I do anything to get it now (maybe wsl --update --pre-release)? Thanks!

@HeyItsJono
Copy link

I'm having this exact issue on Windows 11 10.0.22631 N/A Build 22631, but it's happening with mstsc.exe rather than msrdc.exe. Could this fix be implemented there too please?

@orzcode
Copy link

orzcode commented Jan 12, 2025

I'm currently still having this issue on Windows 11, WSL2 Ubuntu, and :

[wsl2]
guiApplications=false

doesn't fix it

@patricknelson
Copy link

I have this issue too and it's extremely easy to reproduce when simply switching between distros.

C:\Users\patnelson\Desktop>wsl --distribution Debian
patnelson@compy386:/mnt/c/Users/patnelson/Desktop$ exit
logout

C:\Users\patnelson\Desktop>wsl --distribution Ubuntu
###  focus is lost here ###
patnelson@compy386:/mnt/c/Users/patnelson/Desktop$ exit
logout

For reference, I'm on a fresh Windows 11 install (fresh from employer, that is) version 10.0.22631.4602 and Terminal version 1.12.10983.0. As explained above, it's also lost if you're starting from scratch as well, but you can very easily repro via switching between distros. In my case, I was just moving away from the default Ubuntu and installing Debian instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixinbound
Projects
None yet
Development

No branches or pull requests

7 participants