Code Monkey home page Code Monkey logo

runx's Introduction

runx - Run Linux GUI applications on MS Windows

runx allows to easily run Linux GUI applications and desktops on MS Windows in Cygwin, MSYS2 or WSL.

  • This is especially of interest for WSL in Windows 10 that does not support graphical applications on itself.

Background:

  • runx starts an X server, either VcXsrv or XWin, to provide a graphical environment for Linux applications.
  • runx creates an authorization cookie to restrict access to the X server to allowed clients only.
  • runx runs the desired Linux GUI application with the credentials needed to access the X server.

For similar functionality on native Linux systems use x11docker with options --backend=host or --xonly.

Table of contents

Linux environments on MS Windows

runx can run in:

  • WSL: Windows subsystem for Linux.
  • Cygwin: Cygwin is a large collection of Open Source tools which provide functionality similar to a Linux distribution on Windows.
  • MSYS2: MSYS2 is a software distro and building platform for Windows and serves as a base for git for windows and MingW. It is mainly used by developers.

Installation

Installation in general:

  • Install an X server, VcXsrv or XWin.
  • Copy runx into folder /usr/local/bin and make it executeable with chmod +x /usr/local/bin/runx.
  • Install Linux dependency xauth if available.
  • Install Linux dependency telnet.

Installation of X server

runx needs an X server. Install on MS Windows one or both of:

  • VcXsrv to provide X server VcXsrv.
    • Easier to install than XWin.
  • Cygwin with packages xinit and xauth.
    • This provides X server XWin for Cygwin and WSL.
    • XWin has a better --gpu support than VcXsrv.

runx will automatically use XWin if available. You can specify the desired X server with options --xwin or --vcxsrv.

Installation in WSL

  • Run the following commands in WSL/Ubuntu terminal to install runx and its dependencies:
    sudo wget https://raw.githubusercontent.com/mviereck/runx/master/runx -O /usr/local/bin/runx
    sudo chmod +x /usr/local/bin/runx
    sudo apt update
    sudo apt install xauth
    

Installation in Cygwin

  • Run the Cygwin installer and install packages xinit, xauth and wget.
  • In Cygwin terminal run the commands:
    wget https://raw.githubusercontent.com/mviereck/runx/master/runx -O /usr/local/bin/runx
    chmod +x /usr/local/bin/runx
    

Installation in MSYS2

  • In MSYS2 terminal run the commands:
    mkdir /usr/local/bin
    wget https://raw.githubusercontent.com/mviereck/runx/master/runx -O /usr/local/bin/runx
    chmod +x /usr/local/bin/runx
    
  • Constraint in MSYS2: runx only supports X server VcXsrv, but not XWin.

GPU hardware acceleration

runx supports GPU hardware accelerated graphics with option --gpu.

  • GPU access can cause issues with X server VcXsrv, especially with NVIDIA cards. For that reason GPU usage is disabled by default in runx.
  • If you encounter issues with option --gpu, try X server XWin instead of VcXsrv.

Usage examples

  • File manager pcmanfm in WSL:
    • Installation:
      sudo apt update
      sudo apt install pcmanfm
      
    • Run:
      runx -- pcmanfm
      
  • Mate desktop environment in WSL:
    • Installation:
      sudo apt update
      sudo apt install mate-desktop-environment
      
    • Run:
      runx --desktop --gpu -- mate-session
      

Providing X server in background

You can make an entry in the file ~/.bashrc to have an X server always available. Possible entry in ~/.bashrc:

source /usr/local/bin/runx

In future runs of the terminal you can directly run Linux GUI applications, e.g.:

pcmanfm

Use an already running X server

  • If you specify option --display, runx will check if an X server is already running with the specified display number and will only provide the access credentials DISPLAY and XAUTHORITY instead of running an additional X server.
  • The access credentials are also stored in file ~/.Xenv. You can make them available in a new terminal sourcing the file with . ~/.Xenv or source ~/.Xenv.

Output of runx --help

runx - Run Linux GUI applications on MS Windows.
Provides an X server on MS Windows in Cygwin, MSYS2 or WSL.

Syntax:
  runx [OPTIONS]  --  [COMMAND]

Options:
  -h, --help                   Show this help.
  -d, --desktop                Open a parent window for desktop environments.
  -g, --gpu                    Enable GPU hardware acceleration. Can fail 
                               with NVIDIA cards. Works best with XWin.
      --size WIDTHxHEIGHT      Window size for option --desktop, e.g. 800x600.
      --vcxsrv                 Use X server VcXsrv.
      --xwin                   Use X server XWin.
      --clipboard [=yes|no]    Enable clipboard sharing yes/no. Default: yes.
      --display N              Use display number N for new X server.
                               If the display number is already in use, runx will 
                               only provide the likely access credentials.
      --ip ADRESS              IP adress to use. Default: First found 192.168.*
      --no-auth                Disable X cookie authentication. Discouraged.
      --cleanup                Stop all X servers and delete cookies.
  -v, --verbose                Be verbose.

Installation of runx in WSL:
 - Copy runx into /usr/local/bin/
 - Make runx executeable:        sudo chmod +x /usr/local/bin/runx
 - Install xauth:                sudo apt update
                                 sudo apt install xauth
 
Install an X server on Windows:
  runx supports two X servers: VcXsrv and XWin. Install at least one of them.
   - VcXsrv: Download and install from: 
       https://sourceforge.net/projects/vcxsrv/
   - XWin: Download and install Cygwin64 with packages: xinit xauth
       https://www.cygwin.com
VcXsrv is easier to install. XWin provides a better GPU support.

WSL, Cygwin: runx starts XWin if available, otherwise it starts VcXsrv.
MSYS2:       runx supports VcXsrv only.

Usage:

Example to directly run an application with runx:
 - Install file manager pcmanfm: sudo apt update
                                 sudo apt install pcmanfm
 - Run pcmanfm with:             runx -- pcmanfm

Example to run Mate desktop:
 - Install Mate desktop with:    sudo apt install mate-desktop-environment
 - Run Mate desktop with:        runx --desktop -- mate-session
 
Example to get a Wayland environment:
 - Install Wayland compositor:   sudo apt install weston
 - Run Weston with:              XDG_RUNTIME_DIR=/tmp  runx -- weston

Providing an X server in background all the time:
 - Create an entry in ~/.bashrc: source /usr/local/bin/runx
 - In future terminal session you can directly run GUI commands.
   E.g. just type:  'pcmanfm'  instead of 'runx -- pcmanfm'.
 - If you specify a display number with --display, runx will re-use
   a possibly already running X server with same display number
   and only provide the access credentials DISPLAY and XAUTHORITY.
   This allows to use the same X server across several terminals.

runx stores the access credentials DISPLAY and XAUTHORITY in ~/.Xenv
This allows sourcing the file for custom access setups.

runx version 0.4.20
Please report issues and get help at:   https://github.com/mviereck/runx

Screenshot

runx running Mate desktop on MS Windows: Mate Desktop on MS Windows

runx's People

Contributors

mviereck avatar rolandrosier avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

runx's Issues

reuse $DISPLAY variable

Hello Martin!

Could you enhance your script to get IP / display number from DISPLAY variable ?

How do I want to use it:
I need only one X-Server on my machine (I think it is most popular option)
set $DISPLAY=127.0.0.1:bla-bla always on startup in bashrc
start X-Server manually, when I need it
run clients from several terminals

Options are parsed after check_host called - so the "verbose" option is not detected in time to be used in check_host

The options are parsed in the parse_options function, but this function is called after the check_host function is called.

The check_host function looks to see if the "verbose" option has been passed and, if so, outputs debug information.

Because the parse_options function is currently only called after the check_host function has run, the "verbose" option is not detected until after the check_host function is run and this additional debug information is not output even when the "verbose" option is passed.

Hence, it would be logical to call parse_options before calling check_host so that passing the "verbose" option can cause check_host to output this additional debug information.

When sourced, runx -h outputs help and then a load of error messages

Context, my system is an Ubuntu WSL2 system.

When I source runx and pass the "-h" option, after the help output, I get the following errors:

Command 'main' not found, did you mean:
  command 'maim' from deb maim (5.6.3-1)
  command 'rain' from deb bsdgames (2.17-29)
  command 'man' from deb man-db (2.10.2-1)
  command 'mail' from deb mailutils (1:3.14-1)
Try: apt install <deb name>
finish: command not found

This is because in parse_options, when the "-h" or "--help" option is detected, the finish function is called, which uses "$Sourced" to detect that the script has been sourced and then unsets all the variables and functions defined in the script.
After returning from parse_options, the script tries to call the main and then finish functions, but these have already been unset, so the shell tries to find them as standard commands, which it can't.
As such, it then tries to suggest packages to install which could provide these functions as standard commands.

Furthermore, if a fix to issue #13 is implemented, moving the parse_options function to before the check_host function, this breaks the "$Sourced" logic because the detection of whether the script is "$Sourced" is performed in the check_host function, so when "-h" is then detected and finish is called, the finish function no longer knows that the script has been "$Sourced".

So:

  1. The detection of "$Sourced" should be moved into the parse_options function, because sourcing the function is a 'kind-of' option - and that detection should be done as early as possible, before there is any chance that the script will need to know that it has been "$Sourced".
  2. The finish function should not be called on detection of "-h" or "--help" by parse_options. Instead, the parse_options function should return as normal, but setting "$Exitcode" to a value (0 is suggested, because outputting help is a 'kind-of' success) and then testing "$Exitcode" to ensure that it is still unset before calling any of the subsequent functionality.
  3. The finish function is then called as the last function call in the script, and it can happily unset everything without there being any resulting errors.

Cygwin install instructions are invalid

Great script! I've noted that your install instructions for cygwin point to the wrong url for getting the runx script.

You have:

wget https://github.com/mviereck/runx/blob/master/runx -O /usr/local/bin/runx
chmod +x /usr/local/bin/runx

When it should be:

wget https://raw.githubusercontent.com/mviereck/runx/master/runx -O /usr/local/bin/runx
chmod +x /usr/local/bin/runx

without using https://raw.githubusercontent.com/mviereck/runx/master/runx the runx scripts is just a bunch of HTML ;)

Copyright notice

The copyright notice in the license file does not include the name of the copyright holder. This might lead to some confusion about attribution or the legal validity of the license statement in some jurisdictions if this script is distributed with, or incorporated in other software packages.

runx does not detect WSL2

I get this error after I followed your instructions on the README. I'm running runx in a WSL2 in Windows Terminal. Running other GUI programs: startlxde or emacs work without using runx.

$ runx
runx ERROR: runx is designed to run on MS Windows in WSL, Cygwin or MSYS2.
  Did not detect WSL, Cygwin or MSYS2.

Windows systeminfo

Host Name:                 VREXTON
OS Name:                   Microsoft Windows 10 Pro
OS Version:                10.0.19035 N/A Build 19035
OS Manufacturer:           Microsoft Corporation
OS Configuration:          Standalone Workstation
OS Build Type:             Multiprocessor Free
Registered Owner:          Windows User
Registered Organization:
Product ID:                00330-80000-00000-AA894
Original Install Date:     1/5/2020, 3:30:21 PM
System Boot Time:          1/5/2020, 6:22:15 PM
System Manufacturer:       System manufacturer
System Model:              System Product Name
System Type:               x64-based PC
Processor(s):              1 Processor(s) Installed.
                           [01]: Intel64 Family 6 Model 94 Stepping 3 GenuineIntel ~3504 Mhz
BIOS Version:              American Megatrends Inc. 3007, 11/29/2016
Windows Directory:         C:\WINDOWS
System Directory:          C:\WINDOWS\system32
Boot Device:               \Device\HarddiskVolume3
System Locale:             en-us;English (United States)
Input Locale:              en-us;English (United States)
Time Zone:                 (UTC-05:00) Eastern Time (US & Canada)
Total Physical Memory:     32,707 MB
Available Physical Memory: 19,122 MB
Virtual Memory: Max Size:  57,283 MB
Virtual Memory: Available: 40,712 MB
Virtual Memory: In Use:    16,571 MB
Page File Location(s):     C:\pagefile.sys
Domain:                    WORKGROUP
Logon Server:              \\VREXTON
Hotfix(s):                 N/A
Network Card(s): (...)
Hyper-V Requirements:      A hypervisor has been detected. Features required for Hyper-V will not be displayed.

Subsystem

Distributor ID: Ubuntu
Description:    Ubuntu 18.04.3 LTS
Release:        18.04
Codename:       bionic

VcXsrv

VcXsrv X Server
Version "1.20.5.1" (27 Jul 2019)

XWin

$ startxwin

Welcome to the XWin X Server
Vendor: The Cygwin/X Project
Release: 1.20.5.0
OS: CYGWIN_NT-10.0-19035 vrexton 3.1.2-340.x86_64 2019-12-21 15:25 UTC x86_64
OS: Windows 10  [Windows NT 10.0 build 19035] (Win64)
Package: version 1.20.5-3 built 2019-09-06

XWin was started with the following command line:

/usr/bin/XWin :0 -multiwindow -auth /home/Jonas/.serverauth.1386

(II) xorg.conf is not supported
(II) See http://x.cygwin.com/docs/faq/cygwin-x-faq.html for more information
LoadPreferences: /home/Jonas/.XWinrc not found
LoadPreferences: Loading /etc/X11/system.XWinrc
LoadPreferences: Done parsing the configuration file...
winDetectSupportedEngines - RemoteSession: no
winDetectSupportedEngines - DirectDraw4 installed, allowing ShadowDDNL
winDetectSupportedEngines - Returning, supported engines 00000005
winSetEngine - Multi Window or Rootless => ShadowGDI
winScreenInit - Using Windows display depth of 32 bits per pixel
winAllocateFBShadowGDI - Creating DIB with width: 3000 height: 1920 depth: 32
winFinishScreenInitFB - Masks: 00ff0000 0000ff00 000000ff
winInitVisualsShadowGDI - Masks 00ff0000 0000ff00 000000ff BPRGB 8 d 24 bpp 32
MIT-SHM extension disabled due to lack of kernel support
XFree86-Bigfont extension local-client optimization disabled due to lack of shared memory support in the kernel
glWinSelectGLimplementation: Loaded 'cygnativeGLthunk.dll'
(II) AIGLX: Testing pixelFormatIndex 5
GL_VERSION:     4.6.0 NVIDIA 436.48
GL_VENDOR:      NVIDIA Corporation
GL_RENDERER:    GeForce GTX 1070/PCIe/SSE2
(II) GLX: enabled GLX_SGI_make_current_read
(II) GLX: enabled GLX_SGI_swap_control
(II) GLX: enabled GLX_MESA_swap_control
(II) GLX: enabled GLX_SGIX_pbuffer
(II) GLX: enabled GLX_ARB_multisample
(II) GLX: enabled GLX_SGIS_multisample
(II) GLX: enabled GLX_ARB_fbconfig_float
(II) GLX: enabled GLX_EXT_fbconfig_packed_float
(II) GLX: enabled GLX_ARB_create_context
(II) GLX: enabled GLX_ARB_create_context_profile
(II) GLX: enabled GLX_ARB_create_context_robustness
(II) GLX: enabled GLX_EXT_create_context_es2_profile
(II) AIGLX: enabled GLX_MESA_copy_sub_buffer
(II) 670 pixel formats reported by wglGetPixelFormatAttribivARB
(II) 634 fbConfigs
(II) ignored pixel formats: 0 not OpenGL, 0 unknown pixel type, 36 unaccelerated
(II) GLX: Initialized Win32 native WGL GL provider for screen 0
winPointerWarpCursor - Discarding first warp: 1500 960
(--) 16 mouse buttons found
(--) Setting autorepeat to delay=500, rate=31
(--) Windows keyboard layout: "00000409" (00000409) "US", type 4
(--) Found matching XKB configuration "English (USA)"
(--) Model = "pc105" Layout = "us" Variant = "none" Options = "none"
Rules = "base" Model = "pc105" Layout = "us" Variant = "none" Options = "none"
winInitMultiWindowWM - DISPLAY=:0.0
winMultiWindowXMsgProc - DISPLAY=:0.0
winInitMultiWindowWM - xcb_connect () returned and successfully opened the display.
winClipboardThreadProc - DISPLAY=:0.0
winProcEstablishConnection - winInitClipboard returned.
winMultiWindowXMsgProc - xcb_connect() returned and successfully opened the display.
winClipboardProc - xcb_connect () returned and successfully opened the display.
Using Composite redirection

Drop xauth dependency / custom cookie creation

Hello @eine ,

are you still using x11docker and runx?
Once we had the issue that MSYS2 does not provide package xauth so x11docker and runx could only run with option --no-auth.
These days I managed to create a cookie file without the need of xauth.
I'd like to implement this in runx and want to ask you if you could test it if it works.

Prefer WSL2 internal IP to external IP

In WSL2, there is an internal network created between Windows and WSL2, with the range 172.16.0.0/12.

Whilst X-Windows servers such as VcSrv are likely to listen on the generic IP 0.0.0.0, port 6XXX, a security-minded PC setup should block all incoming connections from the externally-facing interfaces (e.g. Ethernet, WiFi) and only allow connections from the internal network.

Therefore, when looking for the Host IP of the X-Server running on Windows, WSL2 should connect to the internal IP.

There are multiple ways that this internal IP can be dynamically determined. One way is:
ip route list default | awk '{print $3}'

Every time that WSL2 is restarted (including when the PC is rebooted), the address assigned to the WSL2 instance and to the Windows host can potentially change, so the determination of the Host IP address should use one of the mechanisms for determining the changing IP.

(Note: This security mechanism of using the firewall to block incoming connections from externally-facing interfaces can be used to enhance the xauth mechanism - providing greater defense-in-depth for the system).

Doesn't detect VcXsrv installed into C:\Program Files (x86)\VcXsrv

Hi! First of all, really cool script! I was trying it out on my machine and noticed that I got an error:

runx ERROR: No X server found.
Please either install X server VcXsrv:
  https://sourceforge.net/projects/vcxsrv
or install Cygwin with packages xinit and xauth to provide XWin:
  https://www.cygwin.com/ 

I looked into what the script was doing and realized my VcXsrv installation was in C:\Program Files (x86). It's a pretty easy fix but wanted to put up an issue for this in case anyone bumps into a similar issue. I can submit a quick patch to check that directory in a sec, but wondering if there's a better way to go about checking for the executable in Windows?

Runx doesn't set correct Hostip in case of multiple Virtual Switches on Windows

Environment: Win10, WSL2.

runx bash script goes through ipconfig.exe output and sets Hostip var (needed for the DISPLAY envvar) to the value from the first found "IPv4"-containing string.
But when there are multiple Virtual Switches the first found value may be not correct (my case) so runx doesn't work because DISPLAY is not set correctly.
Disabling additional Virtual Switches solves the problem but it took about an hour for me (not mentioning reading through code) to find the reason of the problem.

Please take this situation into account.
Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.