Thursday 26 March 2015

iPad as a 2nd monitor - now on Linux

So after I figured out how to use my iPad as a 2nd monitor on the Mac and Windows, I thought I'd write another post on how to achieve this on Linux. I used Ubuntu Linux as my Linux of choice (until of course, the new Mac) and the post details how I got it to work on Ubuntu.

This is quite a bit more complicated than the extremely easy method that works on the Mac and on Windows.

What works

Screen sharing on the iPad
Mouse, keyboard and clipboard sharing across the laptop and the iPad

What doesn’t

Drag and drop windows from one screen to the other - This does not seem possible to do between X displays


Step 1: Install the following on Ubuntu

tightvnc - Runs a VNC server on a new X display
x2x - Lets you share the mouse and keyboard across X displays
ipad_charge - Enables charging the iPad in Ubuntu
gnome-session-fallback - Enables a Gnome session in VNC as Unity doesn’t play nicely
xsel - Enables sharing of the clipboard (Credit: nerdopolis @

Run the following commands to complete the installation.
sudo apt-get install -y tightvncserver x2x gnome-session-fallback xsel
sudo apt-get install -y build-essential libusb-1.0-0 libusb-1.0-0-dev git
git clone
cd ./ipad_charge
sudo make install

Step 2: Setup a VNC Password

This provides at least basic security to your main machine, but you should be ok on a home network. You could set up an ssh connection for more security, but this make the rendering of the screen very slow

Enter a password for the VNC server twice and “no” for a read only password

Step 3: Create the xstartup file

Create a file called xstartup in the $HOME/.vnc folder with the following contents
xrdb $HOME/.Xresources
xsetroot -solid grey
#Open a terminal window in the new X display. Comment the following line if unnecessary
x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
x-window-manager &
# Fix to make GNOME work

Step 4: Create a .xsession file

Create a file called .xsession in the $HOME directory with the following contents. This will enable a gnome desktop as Unity does not work over VNC
gnome-session --session=gnome-fallback

Step 5: Install and configure a VNC client on the iPad

Any VNC client will do, but I like this one. It’s free for the basic features which are enough for what we need.
Mocha VNC Lite
Use the following details in the Mocha VNC Lite configuration. The settings may be named different depending on the client you choose. The settings will also be saved, hence from the
VNC server address: As shown when you run the script
VNC server port: 5901
VNC password: The one you set using the vncpasswd command
Local mouse: Off

Step 6: Additional tips to be more productive

  1. Evince: Default PDF reader that works better than Acrobat reader
  2. Browsers seem to like opening on only one of the displays at a time. I ended up using Chrome on my laptop and Firefox on the VNC display
  3. Synapse: A keystroke search tool to replace Unity Dash
  4. Autohide the top panel to increase available screen real estate
  5. Add an Window Selector to the bottom panel to easily switch windows and increase the bottom size panel to 48 to make touch selection easier
  6. Add a new Gnome panel to the left with Synapse and any other frequently used applications to replace Unity Dash


Step 1: Create the 2nd screen with keyboard and mouse sharing

Download the file. Change it to include your network card device (Mine is wlan0 but yours may look like eth0 or eth1) and run it. Enter L (Left) or R (Right) in the command options depending on the side you have placed the iPad. The script needs to be running to enable the monitor.
./ R

Step 2: Share the clipboard

Download the file. Start a new terminal window & run it with the following command. The script needs to be running to enable clipboard sharing.
Note: autocutsel can also achieve clipboard sharing, but it only worked from server to client for me, and not both ways. The script enables bidirectional clipboard sharing which is a lot more useful. To use autocutsel, add the command autocutsel -s PRIMARY -fork to the ~/.vnc/xstartup file

Step 3: Connect to the laptop using the VNC client

Connect to the server you saved in step 5 above. Click the “Lock” icon in the status bar a the bottom of the screen and then the upside down triangle at the bottom right of the screen to hide the status bar.

Step 4: Enjoy your ultra portable 2nd screen

That’s all. You can now interact on the iPad screen using the keyboard and mouse.

Steps summary

The below steps are for the iPad placed to the right of the laptop.
Ctrl + Alt + T
<path>/ R
Ctrl + Shift + T
Connect from iPad using Mocha VNC. Lock the screen and minimise the status bar.



if [ "$1" == "L" ]; then
elif [ "$1" == "R" ]; then
echo "Incorrect position selected. Defaulting to \"Right\""
chmod +x ~/.vnc/xstartup #Just in case
vncserver -alwaysshared :1 #Start the VNC server
ipad_charge #Allow iPad charging on Linux

#Friendly print of the ip address for the iPad to connect to
INPUT=`ifconfig wlan0 | grep "inet addr"`
SUBSTRING=`echo $INPUT| cut -d' ' -f 2`
echo ""
echo "Ipad Monitor enabled to the $pos of the primary screen. Start VNC client on the iPad and connect to IP $SUBSTRING, port 5901"
echo "Press CTRL+C to disable the iPad monitor"
echo "Run the script in a new terminal window to enable clipboard sharing"
x2x -$dir -to :1 #Share the mouse and keyboard

#Cleanup before exit
function finish {
vncserver -kill :1 #Disable the VNC server
ipad_charge --off #Disable USB charging
echo "Ipad Monitor disabled." #Display the status

trap finish EXIT (Credit: nerdopolis @

#! /bin/bash
firstxserver=":0" #1st display is default X display 0
secondxserver=":1" #2nd display has been configured to be at X display 1 while starting the VNC server

#set the variables to the default
echo . | xsel --display $firstxserver -b -i
echo . | xsel --display $secondxserver -b -i

while [ 1 ]
#get the values of the clipboard
firstdislpayclipboard=$(xsel --display $firstxserver -b -o)
seconddislpayclipboard=$(xsel --display $secondxserver -b -o)

#if the first x servers clipboad chages
if [ "$firstdislpayclipboard" != "$clipboard" ]

#if it doesnt change to be blank
if [ $(echo $firstdislpayclipboard | grep ^$ -c) -ne 1 ]
#set the appropriate variables to be the contents of the first comand
xsel --display $firstxserver -b -o | xsel --display $secondxserver -b -i
#if it is blank set it to be .in case if its because the x server went  down
echo . | xsel --display $firstxserver -b -i


#if the second x servers clipboad chages
if [ "$seconddislpayclipboard" != "$clipboard" ]

#if it doesnt change to be blank
if [ $(echo $seconddislpayclipboard | grep ^$ -c) -ne 1 ]
#set the appropriate variables to be the contents of the first comand
xsel --display $secondxserver -b -o | xsel --display $firstxserver -b -i
#if it is blank set it to be .in case if its because the x server went  down
echo . | xsel --display $secondxserver -b -i


sleep 1



Enable dragging of windows from the laptop to the iPad screen. This does not seem to do between X displays. It's highly unlikely that I bother figuring this out because the Mac has become my daily usage computer, but you can try out the solutions below.


xpra comes close to achieving sharing of windows. The only challenge is that each program that you want to run needs to be run using the commands. Also, it seems only one client can connect at a time, so it doesn’t seem possible to run multiple programs on 1 X display (100 in the example below) and keep a few windows on the laptop screen and a few on the iPad screen

To share firefox, run on the laptop
xpra start :100 --start-child=firefox

To view the firefox window, run on the laptop or the iPad
xpra attach :100

xdmx is also another program that could help

teleport is yet another program that seems to do this but I can’t understand how to use it


Post a Comment