microsoft / wslg

Enabling the Windows Subsystem for Linux to include support for Wayland and X server related scenarios
MIT License
10.15k stars 303 forks source link

msrdc.exe randomly stealing focus #894

Open mha42 opened 1 year ago

mha42 commented 1 year ago

Version

10.0.22621.0

WSL Version

Kernel Version

5.15.74.2

Distro Version

Ubuntu 22.04

Other Software

Irrelevant, and happens as soon as the WSL instance is started.

Repro Steps

  1. Start any WSL instance. In my case I have a WSL v1 started without any WSLg support.
  2. Wait
  3. Focus is randomly stolen from your application.

I found an app somewhere at some point simply printing what process is currently getting focus. When focus is stolen I see the following line printed;

4300:C:\Program Files\WindowsApps\MicrosoftCorporationII.WindowsSubsystemForLinux_1.0.0.0_x64__8wekyb3d8bbwe\msrdc.exe | Thu 17 November 12:26:04

Often I am having an outlook window open at the time in which I am composing a mail and suddenly I cannot write in it anymore.

Expected Behavior

WSL should not steal focus.

Actual Behavior

Focus is randomly stolen

Diagnostic Logs

N/A

jacktose commented 8 months ago

image

TobberH This is what I did. Looks like \\wsl.localhost\ is the base path that any WSL instances would be installed at.

@Spongeloaf Do you mean that you added \\wsl.localhost\ to Folders and unchecked “Attempt to monitor changes”?

Spongeloaf commented 8 months ago

@jacktose Yes, that's what I meant. I will edit the screenshot to add emphasis to that.

TheRealAlexV commented 8 months ago

Following for updates. I'm also experiencing this issue and traced it back to msrdc. I'm just keeping xcalc or xclock open in the background and that seems to do the trick for me.

hideyukn88 commented 8 months ago

@TheRealAlexV, does that happen while you are actively using other application, then suddenly the focus is moved to xcalc unexpectedly, or while you are away from machine (so the machine may enter sleep, hibernate, etc.), then after coming back, xcalc has focus even the other app had the focus before? thanks!

RemyMachado commented 8 months ago

EDIT:

I succeeded in making .wslconfig work on Windows 10, but I had to create the file from my WSL (ubuntu) terminal with touch & echo commands. I believe creating a text file with Windows (event without .txt extension) wouldn't work. Maybe CRLFs had something to do with it.


Creating .wslconfig doesn't seem to work on Windows 10, maybe it's only a Windows 11 solution?

Is there a different manipulation to make it work for Windows 10?

BrBill commented 7 months ago

Can we please get this fixed? It's a problem in Win 11 too.

ghost commented 7 months ago

Was dealing with this through windows terminal where ubuntu.exe was stealing focus. I changed my profile to load C:\WINDOWS\system32\wsl.exe -d Ubuntu instead of the default profile that runs ubuntu.exe, preventing it from stealing focus at all.

31088:C:\Program Files\WindowsApps\CanonicalGroupLimited.Ubuntu_2204.3.49.0_x64__79rhkp1fndgsc\ubuntu.exe | Fri 08 March 11:16:37

HASJ commented 5 months ago

I use the tool SearchEverything, and it was scanning WSL folders periodically. I turned off the functionality to automatically scan, and the ghost stealing focused finally stopped. It was kicking off a background WSL instance, performing an index, and then closing WSL instance :/

image

This fixed it!

goldfishrock commented 4 months ago

anthonylowther21

This was the problem for me. Now all fixed! Thank you so much

AJolly commented 4 months ago

I use the tool SearchEverything, and it was scanning WSL folders periodically. I turned off the functionality to automatically scan, and the ghost stealing focused finally stopped. It was kicking off a background WSL instance, performing an index, and then closing WSL instance :/ Thanks so much! This was exactly my problem, once I told everything to stop monitoring changes on that WSL directory everything fixed itself.

ijprest-haptx commented 2 months ago

New data point:

I was getting this today. WSL was not running (i.e., wsl --shutdown), but msrdc was stealing focus every 10 seconds or so, then closing (or crashing) shortly thereafter.

I was going to try some of the workarounds mentioned above, but the behavior mysteriously stopped when I started up my WSL distro. Roughly concurrently with that, I noticed that I had a stray VSCode window pointing at WSL, and it had a 'lost WSL connection; reconnecting in 30 seconds' dialog up. I closed VSCode.

So, I don't know whether it was the act of launching WSL, or closing the disconnected VSCode, but the problem resolved itself. (Msrdc.exe is running, but it's no longer crashing & relaunching every few seconds.)