How do you use an android tablet as a second display?

Here's how to use Android as a second monitor, share the mouse, drag windows between tablet and computer screens.

The original source for the tutorial can be found here.

A. Tutorial

Step 1. Create a new virtual monitor

My tablet's resolution is 1280x1024. (You may change 1280 and 1024 everywhere in the commands if your tablet is in different resolution. You may also need to change LVDS1 if the default monitor's name is different).

Run in terminal:

  1. $ gtf 1280 1024 60.

    There is a line in the output similar to Modeline "1280x1024_60.00" 108.88 1280 1360 1496 1712 1024 1025 1028 1060 -HSync +Vsync. Copy everything after the word Modeline (exclude it) into the next command.

  2. xrandr --newmode "1280x1024_60.00" 108.88 1280 1360 1496 1712 1024 1025 1028 1060 -HSync +Vsync

    (Note, in the next step, you may also need to change VIRTUAL1 with what you find in xrandr output as an output with new mode)

  3. xrandr --addmode VIRTUAL1 1280x1024_60.00

  4. xrandr --output VIRTUAL1 --mode 1280x1024_60.00 --left-of LVDS1

Step 2. Enable remote desktop for the virtual monitor

Start VNC:

  1. x11vnc -clip 1280x1024+0+0

Step 3. Connect to the remote desktop

  1. Get the tablet on the same local network as the computer. Either by connecting to the same Wi-Fi or by creating a hotspot with one device and then connecting with another to it (USB Tethering).

  2. Find your computer's IP using ifconfig (when connecting from LAN).

  3. Download a VNC app to the tablet and then connect to the computer using computer's IP (and selecting port 5900) in the app.

Notices

  • Credits: kjans, contents edited.
  • WARNING: Data is unencrypted! (Relevant for Wi-Fi and not-LAN usage)
  • WARNING: Devices from all the networks you are connected might reach port 5900 and therefore connect to your monitor! Being behind a router usually would limit it to be accessible only within your local network (If you're using USB connection, you could block local network altogether with -listen <IP_ADDR> option to x11vnc (where <IP_ADDR> is the USB network interface)).
  • Running any of the 1 - 4 steps twice may output errors.
  • After successful use, 5. step must be repeated for another connection.

B. Script

The tutorial implemented as a script (Change the IP for use with the USB cable OR delete it and uncomment the line to use with Wi-Fi).

#!/bin/bash
W=1280
H=800
O=VIRTUAL1
if [ "$1" == "create" ]; then
  gtf $W $H 60 | sed '3q;d' | sed 's/Modeline//g' | xargs xrandr --newmode
  # sed: get third line, delete 'Modeline', get first word, remove first and last characters
  gtf $W $H 60 | sed '3q;d' | sed 's/Modeline//g' | awk '{print $1;}' | sed 's/^.\(.*\).$/\1/' | xargs xrandr --addmode $O
  gtf $W $H 60 | sed '3q;d' | sed 's/Modeline//g' | awk '{print $1;}' | sed 's/^.\(.*\).$/\1/' | xargs xrandr --output $O --left-of LVDS1 --mode
elif [ "$1" == "on" ]; then
  x11vnc -listen 192.168.42.149 -clip ${W}x${H}+0+0
  # For use in Wi-Fi LAN.
  #x11vnc -clip ${W}x${H}+0+0 #**WARNING** Unencrypted stream. VNC accessible without password through port 5900 in all internet interfaces.
else
  echo "missing argument: [create | on]"
fi

Get a VNC client for Android, start up a new VNC server session on your computer (don't just share the current display - use vnc4server not x11vnc), connect to it from the Android VNC client, and (the clever bit) share the PC keyboard and mouse between the two sessions using synergy.

All necessary software to do this is available in the standard repos for the Ubuntu side, and there's a few free VNC clients available for Android in the market.

You won't be able to drag windows across the displays using this method. For that I think you would need to use Xdmx to bond the two sessions. This is a lot harder and would probably cause you to lose 3D acceleration.

Also be aware that synergy and vnc don't use encryption by default so you need to tunnel the connections if you are not on a trusted network.


tl; dr: xrandr --fb and x11vnc --clip together make a killer combo.

The thread linked by recognitium has a really interesting idea, not sure whether he meant this one because I couldn't find the author he indicated and also because I followed up on the forum post there, I will post this separately and not as an edit:

  1. First, let's assume the primary machine does have a screen resolution of 1280x800 and the secondary machine that you want to extend your desktop to over VNC has screen resolution of 1280x1024 and you want the extended screen to be right of your primary screen. The virtual screen needs to be 1280x800 + 1280x1024 = 2560x1024. (extend it horizontally and make the vertical resolution the bigger of the two) So run xrandr --fb 2560x1024.

  2. Now, that the screen is bigger than your primary monitor, you have to make sure there is no panning or any other unwanted "feature" activated and also that the coordinates of your primary monitor's top left corner are 0x0.

  3. x11vnc -clip 1280x1024+1281+0 plus add any other x11vnc options to taste :)

This should be it.