WSL+Xapps: add a Windows feeling

Nunix
5 min readAug 24, 2018

--

Introduction

Ever wanted to launch your X application from Windows and do not have to launch a console prior, run your program in the background so it doesn’t end at the same time you close the console?

Even better! Do you want to launch your X application like any other Windows application by clicking on the Windows button and start typing the name of your app and it just appears?

Epic level: launch your X application with a simple key shortcut!

Wait no more, the WSLCorsair has found this treasure and will now share it with you.

Before doing Epic …

I must warn you: (as usual) this is clearly not supported by Microsoft. X applications are not the focus nor the priority of the WSLinux Team

And remember, while supportive of these crazy ideas, if we go overboard there will (@richturn_ms) Dragons!!

Pre-requisites

Here are the three main components needed:

  1. Have at least one WSLinux distro up and running
    https://docs.microsoft.com/en-us/windows/wsl/install-win10
  2. Have a X server installed on Windows, and while there’s various options, I personally choose VcXsrv
    https://sourceforge.net/projects/vcxsrv/
  3. Have the package dbus-x11 installed (thanks to Stefan Stranger):
    $ sudo apt install dbus-x11

Start the X server

Once you installed VcXsrv, you will be able to launch it with the XLaunch.exe application that should appear in your Start menu or, if you prefer having more control, you can run this command from Powershell.exe:

PS> & ‘C:\Program Files\VcXsrv\vcxsrv.exe' -wgl -dpi auto -ac -multiwindow

If -dpi auto and -multiwidow might be self-explanatory, the rest of the options will do the following:
-ac: disable access control restrictions
-wgl: Enable the GLX extension to use the native Windows WGL interface for hardware-accelerated OpenGL

For the full list of options, please refer to https://gist.github.com/stowler/9921780

And you should now have a X server up and running, waiting for a connection.

WSLinux configuration

In order to connect to the X server, we need to configure the DISPLAY environment variable: $ export DISPLAY=:0

Also, for certain applications, we need start the dbus process. While there is different ways of doing it, the one that seemed the more stable is to start it with the init script: $ sudo /etc/init.d/dbus start

Finally, as described by @unixterminal in his excellent repository:

The LIBGL command offloads hardware graphics acceleration from Linux to Windows 10 for faster graphical rendering.

In order to apply this performance tweak, we need to export another environment variable: $ export LIBGL_ALWAYS_INDIRECT=1

Note: in order to not have to go through the whole process once more, remember to add the environment variables into your $HOME/.bashrc or any other shell rc file (i.e. $HOME/.zshrc)

Voilà, our environment is now ready to accept X applications!

Integrating with Windows

Alright, now comes the fun part: as I stated in the Introduction, what about adding your X application into your Windows start menu.

For this example, I have installed Terminator which I find is quite pretty and simple to setup.
As it’s never perfect, it will allow me to show you a limitation of the X applications.

Without further due here are the steps:

  • Install your X application on your WSLinux distro
    $ sudo apt install terminator -y
Install Terminator
  • [Optional] Create a new directory to store the links to your X applications PS> mkdir c:\wslapps; cd wslapps
Create directory and move inside
  • Now open explorer and move to the directory you want to store your X applications links.
    If your in Powershell still, you can easily do so by running PS> explorer .
  • Now create a new Shortcut
Right click > New > Shortcut
  • We will pick powershell.exe as the link target and click Next
Type powershell.exe in the textbox
  • Type the name of the X application (i.e. Terminator)
Type the name of the X application
  • The shortcut is created and right click on the shortcut to edit it
Right click > Properties
  • On the Shortcut tab, click on the Target textbox to edit it as follow:
    c:\Windows\System32\WindowsPowershell\v1.0\powershell.exe -WindowStyle Hidden -Command "wsl.exe run 'export DISPLAY=:0;terminator'" and click Apply
My current WSLinux distro is WLinux
  • Back to explorer, double click on your link and should see the Windows console flash and disappear just before your X application starts
Launching an X application from a Windows shortcut
  • Finally, copy the link into c:\ProgramData\Microsoft\Windows\Start Menu\Programs
  • Click on the Start button and here we have your new X application directly available from Windows
The X application integrated in the Windows Start menu

Epic Level: yes, I’m a Ninja C(trl)A(lt)T

One really nice touch that we can add is a direct Keyboard shortcut that will lauch our X application (of course, avoid the common key bindings).

And this is really not complicated. Right click on the link and click on Properties. The click on the Shortcut Key textbox and type on the keys you want to bind.
You guessed it, for my example I used the CTRL + ALT + T keys

Starting an X application with Windows keybindings

Conclusion

I really hope that you will like this small tweak and let me know on Twitter ( @nunixtech) which application did you “bring” to the Windows side.

--

--

Nunix

WSL Corsair + Winsider + Docker fanboy and Cornerstone Client Advocate.