mintty / wsltty

Mintty as a terminal for Bash on Ubuntu on Windows / WSL
Other
3.11k stars 104 forks source link

New session loses focus on startup (WSL issue) #329

Open bobf32 opened 1 year ago

bobf32 commented 1 year ago

Windows 10 Pro 22H2 Build 19045.2604 wsltty 3.6.1.2

Every so often, but not all the time, when I start a new session the newly opened window does not have focus.

The problem doesn't occur every time I start a wsltty session, but these steps seem to be repeatable:

  1. Open new Windows command prompt / powershell
  2. wsl --shutdown
  3. %LOCALAPPDATA%\wsltty\bin\mintty.exe --WSL="Ubuntu" --configdir="%APPDATA%\wsltty" -~ -

Actual result: A new wsltty window appears, but the window does not have focus.

Expected result: the new window has focus on opening.

mintty commented 1 year ago

Does it also happen if you start wsltty the "regular" way? (e.g. via desktop shortcut, or from the Start Menu) Is it the window from which you start it that regains the focus? Maybe it "steals" the focus for some reason?

mintty commented 1 year ago

Sounds as if being related to https://github.com/mintty/mintty/issues/1113 but more analysis is needed, as that issue was assumedly fixed. Do you type anything quickly after starting wsltty?

Biswa96 commented 1 year ago

There were some 'focus' related issue in GUI part of WSL2 also, see https://github.com/microsoft/WSLg/issues?q=is%3Aissue+is%3Aopen+focus. Make sure if the issue can be reproduced after disabling GUI feature with WSL2.

bobf32 commented 1 year ago

Does it also happen if you start wsltty the "regular" way? (e.g. via desktop shortcut, or from the Start Menu) Is it the window from which you start it that regains the focus? Maybe it "steals" the focus for some reason?

I am starting wsltty from shortcut. The path I posted originally is that of the shortcut. Wherever focus goes, it is not back to the window that had focus immediately before.

bobf32 commented 1 year ago

Sounds as if being related to mintty/mintty#1113 but more analysis is needed, as that issue was assumedly fixed. Do you type anything quickly after starting wsltty?

I don't really understand the question. I start a terminal session because I want to start typing, but I can't because I have to manually set focus first. I don't recall ever having to do this before.

bobf32 commented 1 year ago

There were some 'focus' related issue in GUI part of WSL2 also, see https://github.com/microsoft/WSLg/issues?q=is%3Aissue+is%3Aopen+focus. Make sure if the issue can be reproduced after disabling GUI feature with WSL2.

How would I do that?

Biswa96 commented 1 year ago

How would I do that?

Add the following lines in %USERPROFILE%\.wslconfig file.

[wsl2]
guiApplications=false

More info https://learn.microsoft.com/en-us/windows/wsl/wsl-config#wslconfig

bobf32 commented 1 year ago

How would I do that?

Add the following lines in %USERPROFILE%\.wslconfig file.

[wsl2]
guiApplications=false

More info https://learn.microsoft.com/en-us/windows/wsl/wsl-config#wslconfig

Thanks. That does indeed fix the issue. And as I am still able to run gitk I wonder if, as I am running Windows 10, there is a downside.

Biswa96 commented 1 year ago

Can you see the issue with wsl.exe when those lines are not present in .wslconfig file?

bobf32 commented 1 year ago

Can you see the issue with wsl.exe when those lines are not present in .wslconfig file?

Yes. Without guiApplications=false, wsl --shutdown followed by wsl.exe at a powershell prompt causes focus from the PS console window to be lost.

Biswa96 commented 1 year ago

So, this does not look like mintty/wsltty issue, right? You can see those issues in wslg repository.

bobf32 commented 1 year ago

So, this does not look like mintty/wsltty issue, right? You can see those issues in wslg repository.

Seems fair.