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

Set dpi of wsl2 windows independently of screen resolution #590

Open DangerStu opened 2 years ago

DangerStu commented 2 years ago

Is your feature request related to a problem? Please describe. I using a vanilla WSL2 install on windows 11, all my Ubunto apps look like postage stamps compare to regular windows apps

Describe the solution you'd like Details of how to configure the DPI independently of Display Settings so that both windows and Ubunto apps are approximately the same size.

Describe alternatives you've considered I've tried changing the DPI via Display Settings but then my windows apps are too big

Additional context Add any other context or screenshots about the feature request here.

hideyukn88 commented 2 years ago

@DangerStu, this is partially possible by WESTON_RDP_DEBUG_DESKTOP_SCALING_FACTOR with .wslgconfig, please refer https://github.com/microsoft/wslg/wiki/WSLg-Configuration-Options-for-Debugging, please let us know if this does what you need, thanks!

DangerStu commented 2 years ago

Unfortunately this seems to have no effect

hideyukn88 commented 2 years ago

@DangerStu, thanks for trying out, if it's correctly configured, /mnt/wslg/weston.log should include the line with WESTON_RDP_DEBUG_DESKTOP_SCALING_FACTOR with custom scale factor, do you see it? thanks!

DangerStu commented 2 years ago

I'm not seeing the entry in the log file.

I did see this line WESTON_CONFIG_FILE=/home/wslg/.config/weston.ini and I'm not aware where this file exists.

Sorry I'm a complete newb when it comes to linux.

Thanks again for looking into this for me

On Wed, Dec 1, 2021 at 6:49 AM Hideyuki Nagase @.***> wrote:

@DangerSu, thanks for trying out, if it's correctly configured, /mnt/wslg/weston.log should include the line with WESTON_RDP_DEBUG_DESKTOP_SCALING_FACTOR with custom scale factor, do you see it? thanks!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/microsoft/wslg/issues/590#issuecomment-983714863, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABKQK4ZEMPGP2K5X7BT2BJDUOYYXHANCNFSM5I7YESNA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

mangkoran commented 2 years ago

I encountered this issue too. I already put WESTON_RDP_DEBUG_DESKTOP_SCALING_FACTOR=200 and then tried with other value to see whether its working. But it seems it's not working (checked with GUI Emacs, UI scaling is still same).

hideyukn88 commented 2 years ago

@DangerStu, @mangkoran, the contents of file should be like below and placed 2 possible locations depending on how you installed WSL. But for sure, simply place both location at C:\Users\[your username]\.wslgconfig, or C:\ProgramData\Microsoft\WSL\.wslgconfig, and it is working for me. Please let us know how it goes.

[system-distro-env]
WESTON_RDP_DEBUG_DESKTOP_SCALING_FACTOR=200
chreinhardt commented 2 years ago

Making the .wslgconfig file with [system-distro-env] WESTON_RDP_DEBUG_DESKTOP_SCALING_FACTOR=200 in both directories worked in the sense that my gvim window (on ubuntu) is quite big now but the fonts are extremely pixely. Is there something I can do to improve that?

juandarias commented 2 years ago

@DangerStu, @mangkoran, the contents of file should be like below and placed 2 possible locations depending on how you installed WSL. But for sure, simply place both location at C:\Users[your username].wslgconfig, or C:\ProgramData\Microsoft\WSL.wslgconfig, and it is working for me. Please let us know how it goes.

[system-distro-env]
WESTON_RDP_DEBUG_DESKTOP_SCALING_FACTOR=200

@hideyukn88 I've tried your solution, but on Windows 11 there seem to be no effect. The output of grep /mnt/wslg/weston.log -e WESTON is:

[17:40:01.452] RDP backend: WESTON_RDP_DEBUG_LEVEL: 3 [17:40:01.452] RDP backend: WESTON_RDP_MONITOR_REFRESH_RATE: 60000 [17:40:01.452] WESTON_DISABLE_ABSTRACT_FD=1 [17:40:01.452] WESTON_CONFIG_FILE=/home/wslg/.config/weston.ini [17:40:01.511] RDPRAIL-shell: WESTON_RDPRAIL_SHELL_DEBUG_LEVEL: 3. [17:40:01.511] WESTON_RDPRAIL_SHELL_DISABLE_APPEND_DISTRONAME_STARTMEN:1 [17:40:01.515] WESTON_RDPRAIL_SHELL_DISABLE_BLEND_OVERLAY_ICON_TASKBAR:1 [17:40:01.515] WESTON_RDPRAIL_SHELL_DISABLE_BLEND_OVERLAY_ICON_APPLIST:1

PedroMPagani commented 2 years ago

Were you able to get it working juan?

ansorre commented 2 years ago

Windows 11 here and nothing in this page worked for me.

matan7890 commented 2 years ago

@ansorre @PedroMPagani Install newer wsl version from here: https://github.com/microsoft/WSL/releases I'm currently working on 0.67.6 and it works like a charm. Hope it will work for you too guys!

ansorre commented 2 years ago

I can confirm that nothing in this page worked for me even after updating to this version:

WSL version: 0.68.4.0 Kernel version: 5.15.68.1 WSLg version: 1.0.44 MSRDC version: 1.2.3401 Direct3D version: 1.606.4 DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp Windows version: 10.0.22000.1042

Not only. Now if I create the file: c:\ProgramData\Microsoft\WSL.wslgconfig or c:\Users[your user name].wslgconfig or both of them no matter what they contain I cannot run wsl because of this error message being fired when trying to run it:

{Application Error} The application was unable to start correctly (0x%lx). Click OK to close the application. Error code: Wsl/Service/CreateInstance/CreateVm/0x8007023f

Sample content of the files:

[system-distro-env] WESTON_RDP_DEBUG_DESKTOP_SCALING_FACTOR=200

But, again, no matter what the files contain. If I want to run wsl I have to delete both: c:\ProgramData\Microsoft\WSL.wslgconfig and c:\Users[your user name].wslgconfig

rfog commented 1 year ago

Installed version 0.7.0.0 and still not working in W11 22H2. Well, WSL2 works but does not escalate.

chreinhardt commented 1 year ago

The best solution I found so far for my Ubuntu GUI applications was to include the following lines in my .bashrc file:

export GDK_SCALE=2 export GDK_DPI_SCALE=0.75

While it is clearly not the solution to all problems at least my gvim looks good and this approach should be independent of any wsl specifics.

strottie commented 1 year ago

Similarly to @chreinhardt I have something like this in my ~/.bashrc which pulls Windows's DPI and applies it to WSL.

wslg_dpi_scale() {
    local dpi_scale WindowMetricsAppliedDPI
    dpi_scale="${GDK_DPI_SCALE:-${QT_SCALE_FACTOR:-}}"
    if [[ -z "${dpi_scale:-}" ]] ; then
        WindowMetricsAppliedDPI=$("/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe" "(Get-ItemProperty -Path 'HKCU:\\Control Panel\\Desktop\\WindowMetrics').AppliedDPI")
        WindowMetricsAppliedDPI=${WindowMetricsAppliedDPI%$'\r'}
        dpi_scale=$(bc <<<"scale=2; $WindowMetricsAppliedDPI / 96")
    fi

    export GDK_DPI_SCALE=${GDK_DPI_SCALE:-$dpi_scale}
    export GTK_SCALE=${GTK_SCALE:-$dpi_scale}

    # https://doc.qt.io/qt-5/highdpi.html
    # export QT_AUTO_SCREEN_SCALE_FACTOR=${QT_AUTO_SCREEN_SCALE_FACTOR:-1}
    # export QT_ENABLE_HIGHDPI_SCALING=${QT_ENABLE_HIGHDPI_SCALING:-1}
    export QT_SCALE_FACTOR=${QT_SCALE_FACTOR:-$GDK_DPI_SCALE}

    # export MESA_D3D12_DEFAULT_ADAPTER_NAME="Intel(R) UHD Graphics 770"
}

[ -d /mnt/wslg/runtime-dir ] && wslg_dpi_scale

I have not tested all the different variables/frameworks and left some commented for later but I hope it will help others customize the experience to their taste/needs.

matan7890 commented 1 year ago

READ MY EDIT IN THE END BEFORE USAGE

Improving @strottie 's solution, I changed the Powershell's query to search for the maximum DPI of ALL of the available displays. I believe this is the best solution for multi-display setup with different DPI levels right now as GTK/X11 doesn't support (AFAIK) multi-display DPI settings:

wslg_dpi_scale() {
    local dpi_scale WindowMetricsAppliedDPI
    dpi_scale="${GDK_DPI_SCALE:-${QT_SCALE_FACTOR:-}}"
    if [[ -z "${dpi_scale:-}" ]] ; then
        WindowMetricsAppliedDPI=$("/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe" '$dpis = @{}; $dpis.add(-6, 100); $dpis.add(-5, 125); $dpis.add(-4, 150); $dpis.add(-3, 175); $dpis.add(-2, 200); $dpis.add(-1, 225); $dpis.add(0, 250); $dpis.add(1, 300); (((Get-ChildItem -Path '"'"'HKCU:\\Control Panel\\Desktop\\PerMonitorSettings\'"'"') | ForEach-Object {$dpis[($_.GetValue('"'"'DpiValue'"'"'))]} | Measure-Object -Maximum).Maximum)' |  tr -d '\r\n')
        dpi_scale=$(bc <<<"scale=2; $WindowMetricsAppliedDPI / 100")
    fi

    export GDK_DPI_SCALE=${GDK_DPI_SCALE:-$dpi_scale}
    export GTK_SCALE=${GTK_SCALE:-$dpi_scale}

    # https://doc.qt.io/qt-5/highdpi.html
    # export QT_AUTO_SCREEN_SCALE_FACTOR=${QT_AUTO_SCREEN_SCALE_FACTOR:-1}
    # export QT_ENABLE_HIGHDPI_SCALING=${QT_ENABLE_HIGHDPI_SCALING:-1}
    export QT_SCALE_FACTOR=${QT_SCALE_FACTOR:-$GDK_DPI_SCALE}

    # export MESA_D3D12_DEFAULT_ADAPTER_NAME="Intel(R) UHD Graphics 770"
}

[ -d /mnt/wslg/runtime-dir ] && wslg_dpi_scale

EDIT: It seems that the values in HKCU:\\Control Panel\\Desktop\\PerMonitorSettings are display/resolution specific. If anyone knowns how to determine how to map between the values there and the DPI percentage it could be really useful.

songhat commented 1 year ago

@strottie I try your solution, but there is a problem,when i run gazebo, font size is fine,but the window is wrong:

image
mickleby commented 7 months ago

WESTON_RDP_DEBUG_DESKTOP_SCALING_FACTOR=200

For me this worked AFTER I restarted wsl from PowerShell: wsl --shutdown

Curious what is being restarted. Is it Weston?🤔

timmhayes commented 6 months ago

WESTON_RDP_DEBUG_DESKTOP_SCALING_FACTOR=200

For me this worked AFTER I restarted wsl from PowerShell: wsl --shutdown

This worked for me too, but only after I saved the file in C:\ProgramData\Microsoft\WSL.wslgconfig. The location at C:\Users[your username].wslgconfig did not work.

kanch-zl-de commented 5 months ago

C:\Users[your username].wslgconfig

putting to into C:\Users\[your username]\.wslgconfig worked for me on

Edition Windows 10 Enterprise
Version 22H2
Installed on    ‎2023/‎10/‎31
OS build    19045.4291
Experience  Windows Feature Experience Pack 1000.19056.1000.0
A-Ribeiro commented 1 month ago

Hi.

I believe that wslg is not delivering the actual size of the monitor to the internal WSL display driver.

Native applications use this size to calculate the actual DPI value and scale GUI elements appropriately.

I have a few OpenGL projects that I made that query this value and I am getting the same xrandr values.

:~$ xrandr
Screen 0: minimum 16 x 16, current 2560 x 1440, maximum 32767 x 32767
XWAYLAND0 connected 2560x1440+0+0 (normal left inverted right x axis y axis) 0mm x 0mm
   2560x1440     59.96*+
   ...

In a native environment, this value: 0mm x 0mm should reflect the physical size of the monitor.

Note: After searching the internet, I found that these values ​​are set based on the monitor's EDID information (native environment).

The workaround I found is to set the GDK, GTK, QT, etc... scaling factors based on the actual DPI of the device (thanks to previous comments).

I created a script to do that: https://github.com/A-Ribeiro/wsl-hidpi-suggestion .

By running this command:

(wget -qO- https://raw.githubusercontent.com/A-Ribeiro/wsl-hidpi-suggestion/main/run.sh | xargs -0 -o bash -c) && . ~/.wsl-hidpi-suggestion

We get this:

1) [DPI 100%]
2) DPI 125%
3) DPI 150%
4) DPI 175%
5) DPI 200%
6) DPI 225%
7) DPI 250%
Select the zoom you want to apply: 1

# wsl-hidpi-suggestion
# 
# Variable suggestion to use in the following files:
#   ~/.bashrc
#   /etc/profile
# 
# DPI scale info:
#  - Main size
#      (px): 2560x1600
#      (mm): 344x215
#      (DPI-100%): 189.023257 DPI
#  - Scale set to: 1.968992
# 
export GDK_SCALE=1.968992
export GDK_DPI_SCALE=1.968992
export GTK_SCALE=1.968992
export QT_SCALE_FACTOR=1.968992

creating ~/.wsl-hidpi-suggestion

Do you want to add changes to ~./bashrc? (yes/no) y

adding '. ~/.wsl-hidpi-suggestion' to ~/.bashrc
 - adding entry to ~/.bashrc
dzid26 commented 1 month ago

Above didn't work. This works:

C:/users//.wslgconfig:

[system-distro-env]
WESTON_RDP_HI_DPI_SCALING=true
WESTON_RDP_FRACTIONAL_HI_DPI_SCALING=true
WESTON_RDP_DEBUG_DESKTOP_SCALING_FACTOR=100

then wsl --shutdown