2021-09-11

My computer is Win11 enterprise edition, version number is 21H2. Although WSL2 is already very powerful, it will one day be able to break through the barriers between Win and Linux and achieve true free switching, which will be very easy for us to develop and test. But getting through the two systems may not be easy and requires multiple efforts.

Linux and Windows coexist

Forget MacOS. I don’t like MacOS.

Vm and Dual-system

Linux VIRTUAL machine or dual system when I was in high school, although I worked it out, I didn’t know anything at that time, I just used the Ubuntu graphical interface, I couldn’t use the command line, I couldn’t feel the difference between Win and Linux.

After the university began to contact programming, we know that the best environment is Unix environment or unix-like environment, at that time installed Win10 + Ubuntu18.04 dual system, although said to write code experience is very cool, but the homework experience is very poor. Not to mention listening to music, watching videos and using other software, using a pure Linux environment means you have to forgo high standard office software, general-purpose entertainment software and games, and even desktop software for development, which in my opinion is not worth it. However, the gap between Win and Linux was too deep, so I had to use dual system at that time, and the dual system experience was very bad.

WSL and WSL2

I used to curse Windows for closed source. Developing on Windows is a pain, especially if you have to do compilation work. Then Microsoft came out with WSL. Although it was very good, the concept shocked me. I was probably one of the first WSL users, and immediately removed the dual-system, moved back to Windows, and used WSL instead of Linux, but WSL was crap at the time, with a lot of kernel problems, and it didn’t work. So I thought, let’s use a virtual machine first. It turns out WSL is actually a Hyper-V virtual machine that doesn’t work with VMware or VirtualBox. It’s just plain crazy. So the WSL got a lot of flak, and I did too, but also because there was a real need for it.

Then WSL2 came out, and I was one of the first players to update to WSL2 since I was a beta user and subscribed to the Dev Channel like crazy. The WSL experience is getting better and better because of the docker support for WSL2, plus Microsoft’s own layout of Windows mobile and VSCode’s contribution to WSL. So when WSL2 came out, there was less criticism and Microsoft became what everyone called “big hard”.

Other big software platforms are also supporting Windows 2. After all, this is the trend. No one can refuse Windows, the biggest Linux distribution, haha. Including VMware, Docker Desktop to do WSL2 support, not too cool.

Unfortunately, JetBrain’s compiler doesn’t support WSL2 well enough, updates are slow, and maven doesn’t work at all, which is a major pain point for Java engineers. I thought it would be nice to be able to use desktop applications in Linux. I didn’t know about X11 Forwarding at the time.

WSL2 desktop support

WSL2 updates WSLg to support the use of Linux desktop applications! I tried it right away, So Bad. Because resolution cannot be adjusted, Scaling can only be adjusted to integer multiples. Linux is on my 2K screen, and the words are as small as ants. I can’t use them. So expectations were dashed.

In fact, WSL2’s graphics support is implemented through RDP, similar to X11 Forwarding. The display is certainly better than X11 Forwarding, but the high score screen still doesn’t work…

X11 Graphics forwarding

It is impossible for Linux to interwork with Windows, since the kernel is different, but virtual machines can coexist. So in order for them to communicate, we can think of Linux as a remote server.

X-Windows

Linux, unlike Windows, did not put graphics capabilities into the kernel, and in its early days Linux was based on terminals, not Windows applications. So Linux graphical application support is achieved through the program, even if we use Ubuntu Desktop to see the entire graphical window, but also Linux a program, and Windows that kind of innate graphical interface is completely different.

Linux uses X Window System to implement graphical interfaces. It is called X11 because all new versions of X-Windows are extensions of X11 without any fundamental changes. (X11 was made in 1987.)

X-windows consists of an X Server and an X Client. The X Server receives various EVENTS from THE I/O device, such as mouse click events, screen click times, and keyboard input events, and then displays the output to users. X Client is a graphics program. X Server sends various events received to X Client. After processing, X Client responds to the results to X Server, which then outputs the results.

X-windows defines the framework, but does not define the details of the input and output, which is why Linux’s graphical interfaces flourish today.

Graphics forward

We found that the X Server’s primary role is input, rendering, and communication, and does not participate in the calculation of the application, so the X Server layer can be isolated. The X Server layer shows where the terminal is, and the X Client can act as a remote host and interact with the X Server over the network, so that we can use Linux graphics applications remotely.

This is how many of WSL’s peers started with graphical interfaces. It’s also the way we do remote development. But here’s the problem with this approach:

  1. Data transmission efficiency is low, X11 forwarding consumption is very large, which has been criticized.
  2. X Server does not work well with display devices.

All the updates to THE X Server have been minor, so much so that most people now have X Server on Windows that is 10 years old (yes, Xming). Because of X Server we will put on the Windows side to implement the function of using Linux programs in Windows.

Resolution pit

One uncomfortable problem is that X Servers are usually too old to support high resolution, and Windows X Servers are almost impossible to change resolution. This is the pit I came across. I was screwed. I tried Xming, MobaXterm and VcxSrv and couldn’t change it.

Even if you’re running a new Linux distribution that supports a GNOME or KDE desktop with the best resolution, you won’t be able to solve this problem. Because Linux’s own desktop is rendered by Linux host’s own X Server, and the X Server for our remote graphics forwarding is the X Server of our SSH client, functions on Linux’s OWN X Server cannot be used at all. They are two separate things.

There are a lot of tutorials on the web to change the resolution, but they are useless, because Linux’s own X Server supports the change, and your client’s X Server does not support the change, and there is nothing you can do.

So… Still gotta go back to the virtual machine.

So now it’s a Windows + WSL2 + Linux VM environment, Linux VM is used less, but I just like to drill into the hole, head pain.

WSLg

The problem that WSLg launched by WSL2 has too small font on the high score screen can be set by export GDK_DPI_SCALE=N, where N is the font scaling multiple, but it can only be an integer multiple. Also, the title box can’t zoom, which is killing my ocD.

WSLg does not seem to support fractional scaling · Issue #23 Microsoft/WSLg (github.com)

However, the official reason for banning this feature is that non-integer scaling is too vague, so if you can tolerate it, you can enable it in this way:

Create a file C:\ProgramData\Microsoft\WSL\. Wslgconfig with the following contents:

[system-distro-env]
WESTON_RDP_DISABLE_FRACTIONAL_HI_DPI_SCALING=false
Copy the code