Adding graphics to the Windows System for Linux
The days of Microsoft's rejection of open source are long gone. Not only does it, as the stickers say, '❤Linux', but you'll now find several Linux distributions in the Windows Store. The launch of the Windows System for Linux (WSL) showed that the two operating systems could coexist, running Linux binaries in the Windows command-line terminal.
WSL was conceived as a way of bringing Linux-based development tooling to Windows 10. Much of the devops tooling that's in use, tools like Jenkins and web servers like NGINX, are designed to run on Linux, using Linux scripting environments to manage and control them. It's a typically pragmatic approach from Microsoft, bringing its tools and developers together. Running Ubuntu in WSL gives you access to all the its command-line applications, installing new applications from Ubuntu's built-in package manager.
There's one thing missing, though. WSL is designed to be a command-line environment, running in a terminal window. Most of us who have built and run UNIX systems are familiar with this approach, using the Linux desktop as a launcher for terminal window after terminal window. But there are plenty of tools that need more than a line or two of text, and Linux desktop environments give you access to tools that help make that command-line experience more effective.
So how do you add a richer desktop experience to your WSL install?
WSL and X
Underneath the command line, WSL is a set of tools and services that translate Linux OS calls to Windows. The intent is to be as faithful as possible, and that means supporting the features that Linux uses to work with its existing desktop management tools. Building on its UNIX heritage, much of Linux's GUI is handled by the X Window System. It takes a relatively simple approach to desktop composition, handling mouse and keyboard, and managing windows. Everything else is handled by applications, including desktop managers, which apply the look and feel. Applications are clients, with the underlying X server handling the graphics. Even the desktop manager is a client.
With WSL supporting all the networking features needed by client applications, all that's needed to support X applications is an X Server running under Windows. Running outside the WSL environment, it can host UIs for WSL applications, using X's protocols to communicate between WSL-hosted apps and the Windows environment.
Windows-based X servers are nothing new. They've been around almost as long as Windows itself; I first used one with Windows 3.11 back in the early 1990s, adding a PC as a second terminal on a SunOS workstation. So it didn't take long for users to hook X desktop environments up to WSL. But getting X configured for Windows can be complicated. It requires complex configuration files, documenting device graphics capabilities so they can be shared with X client apps.
Recently an X server appeared in the Windows Store. X410 is a modified version of one of the common X server implementations, X.Org, focused on supporting WSL. That's allowed it to remove dependencies on other open-source UNIX tooling, delivering an X Server that's designed for modern Windows desktops and which lets you either run apps on a hosted X desktop or in their own windows on the Windows desktop.
Getting started with X410 is easy enough. You'll need to configure the bash environment for your WSL Linux distribution first, setting the DISPLAY variable to local host and saving it in your .bashrc file. You may also need to configure the D-Bus inter-process communication service (which may not be installed by default). You'll also need to install the Xfce desktop manager, which will give you a Linux desktop on your Windows 10 system. This can take a while, as it's a hefty piece of software with a lot of dependencies. However Ubuntu's apt package manager will handle all the work for you. Some of xfce's features, like screensavers and screenlockers aren't essential on Windows, which has its own tools to handle this, so you'll probably want to remove those packages from your Xfce install.
Running Linux apps in X410
To simplify launching an X desktop on my PCs, I've created a simple batch file to start X410 in desktop mode, and then launch WSL's Ubuntu with xfce. It's a quick way of getting everything you need in place to start running X, opening a resizable desktop space on your PC. I then placed a shortcut to the batch file in my Start menu, giving me one-click access to my Linux environment.
It's a good idea to tune the default Xfce desktop - you can choose fonts and icons, as well as colours. On install, Xfce has terminals, file managers, and a handful of other tools. You'll need to use the Ubuntu tools to download any additional apps you want, and either add them to the Xfce applications menu or launch them from a terminal. I've been able to install and run various graphical apps that couldn't run in the WSL terminal, including Firefox. Tools like screenFetch show that Xfce terminals report that they're running on X, making it easy to launch and run X Windows apps.
One thing to note: X410 can be GPU intensive. I've been running it on a Surface Book 2 with a Nvidia GPU, and with a handful of windows open it's taking anything up to 75 percent of my system's GPU resources when running OpenGL code. Things are a lot less hardware intensive with a handful of terminal windows - a much more common use case. As the project is moving quite fast, with regular updates, I'd expect this resource management issue to be fixed soon enough.
Microsoft has been doing excellent work in adding more and more Linux compatibility to WSL, and tools like X410 are a good example of how well that work is going. You may not need or want to run an X Server on your PC, but it's good to know that you can. There's more to Linux than console apps, and X410 makes it a lot easier to bring that world to Windows.