wslg icon indicating copy to clipboard operation
wslg copied to clipboard

Dynamically change WSLg display size according to Windows host screen size

Open GhostScript0r opened this issue 1 year ago • 2 comments

Is your feature request related to a problem:

When the resolution of main display changed, WSLg won't recognize the screen size change. As a result, maximized WSLg windows would be the size of the screen when WSL last started.

This issue is prominent when I access my Windows PC remotely. On my guest PC I have a horizontal and a vertical monitor. If I start WSL when the RDP window is on the horizontal monitor and move the RDP window to the vertical monitor. The WSLg windows will still be the size of the horizontal monitor when maximized:

image

Describe the solution you'd like:

WSLg shall be able to recognize the current screen resolution real-time and not require a WSL restart to change the shape of the maximized window.

Describe alternatives you've considered:

Using Xvnc or Xrdp instead of WSLg. But those solutions will be cumbersome.

Additional context:

No response

GhostScript0r avatar Aug 26 '24 08:08 GhostScript0r

Is there any update on this?

I constantly need to remotely access a Windows PC where WSL is running, using Remote Desktop. Just like @GhostScript0r, I see that the size of maximized WSLg windows on the remote PC doesn't get updated when the size of the (maximized) RDP window changes due to a screen resolution update on the local PC.

The size of maximized WSLg windows running locally do get updated correctly, so it seems that this issue is somehow related to RDP.

This doesn't occur for any other maximized windows on the remote PC, so it's definitely an issue with WSLg. It's also a major annoyance - the only workaround that I have found so far is to close all WSLg windows, kill the msrdc.exe process, let the process (immediately) restart itself, and then launch the WSLg applications again. Hence, even though this issue is currently marked as an enhancement, I would rather classify it as a bug.

tdebaets avatar Jul 31 '25 12:07 tdebaets

I've taken a closer look at this issue and found out that maximized WSLg windows running locally do not get updated after all, so this isn't just limited to Remote Desktop. During my previous tests of WSLg running locally, I was always combining the screen resolution change with a DPI change as well (switching between 100% and 150%) and apparently, changing the DPI does trigger WSLg to update its window sizes. However, changing only the screen resolution shows exactly the same issue when running WSLg locally as when accessing WSLg on a remote PC using Remote Desktop.

Fortunately, I have also found out what exactly triggers WSLg to update the window sizes: a WM_SETTINGCHANGE notification message with a wParam of SPI_SETWORKAREA, which is sent to the invisible top-level window with class TsWindow_GeneralWindowClass of the msrdc.exe process. And I can indeed verify that when I manually send this message after a screen resolution change, the size of all maximized WSLg windows are updated to account for the new screen resolution. This single line of code does the trick:

SendMessage(HWND_BROADCAST, WM_SETTINGCHANGE, SPI_SETWORKAREA, 0)

(Note that the message must be sent for this to have effect, i.e. PostMessage doesn't work.)

This still leaves the question why Windows doesn't send a WM_SETTINGCHANGE notification out of itself when changing the screen resolution. Or perhaps it does, but maybe WSLg ignores the notification for some reason? To be further investigated...

tdebaets avatar Aug 13 '25 19:08 tdebaets