Giter Site home page Giter Site logo

linux-extend-screen's Introduction

Tutorial

Do you have any old Android tablet at home? Then you have a new second screen for your laptop! With this tutorial you will be able to use any Android device to extend your screen on Linux. For this purpose we are going to use a wireless connection, but it can also be done through a USB cable. The tutorial seems very long but it is because I will explain each step in detail so that anyone can follow it.

I guess this tutorial can also be done with an iPad or other laptop instead of an Android tablet, but I haven't checked it.

Test environment

  • Laptop with Ubuntu 18.04
  • Nvidia Geforce GTX 1660Ti
  • Intel Core i7-9750H (Intel UHD Graphics 630)

Necessary software

  • In the computer:
    • a VNC server (as for example x11vnc)
     sudo apt install x11vnc
    
  • In the tablet:
    • a VNC client app: I recommend you bVNC Free because it has more security options than other apps.

Workaround

1. Get some information

Firt we need to know available displays and output ports.

xrandr

The output should be something like this (I removed some entries because the output was very long):

Screen 0: minimum 8 x 8, current 1920 x 1080, maximum 32767 x 32767
HDMI-0 disconnected primary (normal left inverted right x axis y axis)
eDP-1-1 connected 1920x1080+0+0 (normal left inverted right x axis y axis) 344mm x 194mm
   1920x1080    144.00*+  60.01    59.97    59.96    59.93  
   1680x1050     84.94    74.89    69.88    59.95    59.88  
   1600x1024     60.17  
   1400x1050     85.00    74.76    70.00    59.98  
   1600x900      59.99    59.94    59.95    59.82  
   1280x1024     85.02    75.02    60.02  
   1440x900      59.89  
   [...]
   480x270       59.63    59.82  
   400x300       85.27    72.19    75.12    60.32    56.34  
   432x243       59.92    59.57  
   320x240       85.18    72.81    75.00    60.05  
   360x202       59.51    59.13  
   360x200       85.04  
   320x200       85.27  
   320x180       59.84    59.32  
   320x175       85.27  
DP-1-1 disconnected (normal left inverted right x axis y axis)
HDMI-1-1 disconnected (normal left inverted right x axis y axis)

As you can see, my current display is eDP-1-1 with the resolution 1920x1080 144.00Hz. The unused output ports are HDMI-0, DP-1-1 and HDMI-1-1. You may have a different output ports and resolutions depending on your graphic card.

2. Create a new virtual monitor

We need to know the tablet's resolution. In my case is 1280x800.

If you don't know your tablet's resolution, visit this site from your tablet's web browser and it will show you your screen resolution. If it is different from mine you will have to replace it in all the commands.

Generate modeline for the resolution of the VPN screen. Run in terminal:

gtf 1280 800 60

60 is the screen refresh rate for the tablet

The modeline generated by this command is:

# 1280x800 @ 60.00 Hz (GTF) hsync: 49.68 kHz; pclk: 83.46 MHz
  Modeline "1280x800_60.00"  83.46  1280 1344 1480 1680  800 801 804 828  -HSync +Vsync

Copy everything after the word Modeline (exclude it) into the next command. Now let's add a new mode for our Android device:

xrandr --newmode "1280x800_60.00"  83.46  1280 1344 1480 1680  800 801 804 828  -HSync +Vsync

Note: xrandr means X Resize and Rotate (just a curiosity)

Add this new mode to an unused output port. HDMI-1-1 in this case.

You may have a different output ports so you need to try the output ports that work for you. Find the available ports with the command xrandr like in the first section

xrandr --addmode HDMI-1-1 1280x800_60.00

Now let’s enable HDMI-1-1 and move it to the left of the default display (eDP-1-1). After this mouse cursor can be moved to the left side more than your default display allows. It is because we are adding 1280×800 to the left side of eDP-1-1.

xrandr --output HDMI-1-1 --mode 1280x800_60.00 --left-of eDP-1-1

If you want to put the second screen in the right side of the default display just change the option --left-of by --right-of.

The final step is to start the VNC server:

x11vnc -clip 1280x800+0+0

Now you need to connect your Android device using a VNC client. To do so you need an IP and port. To find your computer's IP run:

ip a

In my case it is 192.168.1.67. The default port in VNC is 5900 unless you changed it.

alt text Screenshot of the bVNC Free app

3. Disable the second screen

After stopping the VNC server you need to disable the second screen HDMI-1-1:

xrandr --output HDMI-1-1 --off

Summary

Every time you reboot the computer you will have to add the modeline again. Then I will make a summary of all the commands used in this tutorial:

# Create the virtual monitor (every time after rebooting the computer)
xrandr --newmode "1280x800_60.00"  83.46  1280 1344 1480 1680  800 801 804 828  -HSync +Vsync
xrandr --addmode HDMI-1-1 1280x800_60.00

# Enable the second display
xrandr --output HDMI-1-1 --mode 1280x800_60.00 --left-of eDP-1-1
x11vnc -clip 1280x800+0+0

# Disable
xrandr --output HDMI-1-1 --off

Clean modes

To remove the mode:

xrandr --output HDMI-1-1 --off
xrandr --delmode HDMI-1-1 "1280x800_60.00"
xrandr --rmmode "1280x800_60.00"

Check displays and modes

xrandr -q

ADB Support

You can connect an Android device to the computer with an USB cable to have access to the VNC server. It is done through the ADB platform. According to this link, adb reverse was introduced in Android 5.0 onwards, so, to use this feature, your android tablet can not be 'that old'.

First, you need to install the proper tools:

sudo apt install adb android-tools-adb android-tools-fastboot

And now follow this steps:

  • connect your device to the PC with an USB cable
  • turn on USB debugging on your device (inside developer options, which is enabled by tapping the Build Number option 7 times)
  • run the reverse command on PC adb reverse tcp:5900 tcp:5900
  • enable the second display with the commands of the tutorial
  • in the app bVNC Free set 127.0.0.1 as server address and connect to the server

After stopping the VNC server stop the ADB daemon:

adb kill-server

Notices

  • Data is unencrypted! (Relevant for public network connections)
  • Any network you are connected that can reach port 5900 can connect to your monitor! (Not a problem if using a USB connection)

Due to this you should use some security options when using x11vnc.

Add more security to the connection

Change the port of the connection

By default x11vnc use the port 5900. We can change it by running the following command:

x11vnc -rfbport <port_number>

If something else is using that port x11vnc will exit immediately.

Establish a password for the connection

You can use one of the following commands:

x11vnc -storepasswd password /path/to/passfile
x11vnc -storepasswd /path/to/passfile
x11vnc -storepasswd
# The last one will save the password in ~/.vnc/passwd

And then start x11vnc via:

x11vnc -rfbauth /path/to/passfile

Or run

x11vnc -usepw

It automatically use your ~/.vnc/passwd or ~/.vnc/passwdfile password files. Under -usepw, x11vnc will exit if it cannot find a password to use.

WARNING: Even with a password, the subsequent VNC traffic is sent in the clear. Solution => SSL connection.

Use a SSL connection or Tunneling

Consider tunnelling via ssh: http://www.karlrunge.com/x11vnc/#tunnelling

Or using the x11vnc SSL options: -ssl and -stunnel

The -ssl mode requires an SSL certificate and key (i.e. .pem file). These are usually created via the openssl program. In fact when you run the -ssl option (same as "-ssl SAVE") it will run openssl for you automatically. It will prompt you if you want to protect it with a passphrase. In general, the PEM file contains both the Certificate (i.e. public key) and the Private Key, so it should be protected from being read by untrusted users. The best way to do this is to encrypt the key with a passphrase (note however this requires supplying the passphrase each time x11vnc is started up).

Example:

x11vnc -ssl SAVE ...

This way it will be saved in the default directory ~/.vnc/certs/ as server.crt (the certificate only) and server.pem (both certificate and private key.) This opens up the possibility of copying the server.crt to machines where the VNC Viewer will be run to enable authenticating the x11vnc SSL VNC server to the clients.

If you are using the bVNC Free app in the Android device, go to the Connection Type menu and select the Secure VNC over SSL Tunnel option.

Limit which machines can connect to the VNC server

With the -allow option we can limit connections by hostname or IP address. Example:

x11vnc -allow 192.168.0.1,192.168.0.2

Or use -localhost, that achieves the same thing as -allow 127.0.0.1

More information about security

Known issues

  • Often having a Firewall/Router sitting between the vncviewer and x11vnc will make it impossible for the viewer to connect to x11vnc. Try to use a USB connection to solve this problem. (+info)

Resources I used to create this tutorial

X11vnc is a really powerful tool. I strongly recommend you to take a look at the documentation

linux-extend-screen's People

Contributors

hudsantos avatar santiagofdezg 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

linux-extend-screen's Issues

Use `--clip xinerama` instead of manually calculating clip offsets

Use '-clip xinerama0' to clip to the first xinerama
sub-screen (if xinerama is active).  xinerama1 for the
2nd sub-screen, etc.  This way you don't need to figure
out the WxH+X+Y of the desired xinerama sub-screen.
screens are sorted in increasing distance from the
(0,0) origin (I.e. not the Xserver's order).

Ought to be xinerama1 for the common use case of no other screen being connected (and easily adjusted for other setups), which makes the whole script a lot more more robust.

Connection speed & possiblity to mirror/flip?

Thank you very much for providing the expertise shared here!

I find the connection via ADB rather slow. If I use screen mirroring via the tigervnc-scraping-server running x0vncserver, the connection is fast. Any spontaneous ideas in terms of how to improve the speed in your setup would be welcome.

What I am really interested in is to use a tablet as secondary display on a teleprompter in a video conference (setup like this: https://www.youtube.com/watch?v=ScnXGRLugVk). The problem is to mirror flip the display. Of course, this is possible with an HDMI camera field monitor, but that is much less travel friendly and versatile compared to an android tablet.

One can use VNC via ADB but it seems next to impossible to mirror flip the image. xrandr -x does turn the display, but only locally, not via VNC. Android VNC clients able to mirror flip on the client side do not seem to be available. A VNC forum discussion forum did not provide an answer (https://groups.google.com/g/tigervnc-users/c/vy-lLJ3p8lY).

Do your think that your setup could incorporate an xrandr -x, so that the VNC target does see the screen mirror flipped? For that purpose a separate display (to the left or right ...) would not be necessary. A reflection of the main display would be just as good.

Regards,

Michael Schefczyk

Connection is always mirrored

For some reason my second display is always mirroring the 1st, and my display manager doesn't show a second monitor existing.
I'm setting xrandr to put the second display left of or right of, and there's a bit more desktop available on the second monitor since it's a wider resolution, but it's basically mirrored rather than an extended desktop.
Any ideas for something I can try to fix this? I'm out of ideas :/

cannot find output

when i use the "xrandr" command, i get the following output:

Screen 0: minimum 16 x 16, current 1366 x 768, maximum 32767 x 32767
XWAYLAND0 connected 1360x768+0+0 (normal left inverted right x axis y axis) 340mm x 190mm
1360x768 59.80*+
1024x768 59.92
800x600 59.86
640x480 59.38
320x240 59.52
720x480 59.71
640x400 59.95
320x200 58.96
1280x720 59.86
1024x576 59.90
864x486 59.92
720x400 59.55
640x350 59.77

and when i use
"xrandr --addmode HDMI-1-1 1280x800_60.00"

i get the following output
"xrandr: cannot find output "HDMI-1-1"

help out and let me understand where i went wrong
Thank you :)

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.