Use your phone as External Monitor

Suson Thapa
5 min readJun 21, 2020

--

Photo by Tarn Nguyen on Unsplash

In linux they say everything is possible and indeed it is. In this story I am going to share how to use your android phone as external monitor. I am not talking about just cloning your desktop to your phone, but to use your phone as real external monitor. This way you can just drag windows from your desktop to phone and vice versa. Let’s get started.

For those who are in hurry, here is the git repository for the script. Just read the instructions and you are good to go. For others who want to know how it works read on.

Step 1

First generate new mode with GTF command gtf 960 540 60 . Here 960 is the width, 540 is the height and 60 is the frame per second. I recommend using a lower resolution to improve latency and bandwidth.

gtf 960 540 60
# Output from above command
# 960x540 @ 60.00 Hz (GTF) hsync: 33.54 kHz; pclk: 40.78 MHz
Modeline "960x540_60.00" 40.78 960 992 1088 1216 540 541 544 559 -HSync +Vsync

Step 2

Now we need to add a new mode to the system using xrandr . I named it mobile-right then pass the output from the above command.

xrandr --newmode "mobile-right" 40.78  960 992 1088 1216  540 541 544 559  -HSync +Vsync

Step 3

Now get the list of display port that your computer has. I use xrandr to get all the displays ports.

xrandr# output from above command
Screen 0: minimum 320 x 200, current 1920 x 1080, maximum 16384 x 16384
eDP-1 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 344mm x 194mm
1920x1080 60.10*+ 60.01 59.97 59.96 59.93
1680x1050 59.95 59.88
1400x1050 59.98
1600x900 59.99 59.94 59.95 59.82
1280x1024 60.02
1400x900 59.96 59.88
1280x960 60.00
1440x810 60.00 59.97
1368x768 59.88 59.85
1280x800 59.99 59.97 59.81 59.91
1280x720 60.00 59.99 59.86 59.74
1024x768 60.04 60.00
960x720 60.00
928x696 60.05
896x672 60.01
1024x576 59.95 59.96 59.90 59.82
960x600 59.93 60.00
960x540 59.96 59.99 59.63 59.82
800x600 60.00 60.32 56.25
840x525 60.01 59.88
864x486 59.92 59.57
700x525 59.98
800x450 59.95 59.82
640x512 60.02
700x450 59.96 59.88
640x480 60.00 59.94
720x405 59.51 58.99
684x384 59.88 59.85
640x400 59.88 59.98
640x360 59.86 59.83 59.84 59.32
512x384 60.00
512x288 60.00 59.92
480x270 59.63 59.82
400x300 60.32 56.34
432x243 59.92 59.57
320x240 60.05
360x202 59.51 59.13
320x180 59.84 59.32
DP-1 disconnected (normal left inverted right x axis y axis)
HDMI-1 disconnected (normal left inverted right x axis y axis)
HDMI-2 disconnected (normal left inverted right x axis y axis)

From the above command we can see that I have DP-1, HDMI-1 and HDMI-2. I will be using HDMI-1. Now we need to add the mode mobile-right that we just created to the HDMI-1 port. Also note your primary display i.e. eDP-1 in my case.

xrandr --addmode HDMI-1 mobile-right

Step 4

Now we need to extend the HDMI-1 to the right side of the embedded Display Port (eDP-1).

xrandr --output HDMI-1 --mode mobile-right --right-of eDP-1

Step 5

Now we have setup the virtual display, the next step is to stream that display to the phone. We will be using VNC server so go ahead and install x11vnc. Then use it to clip the content of the screen that we have setup in above command.

x11vnc -clip 960x540+1920+0

The parameter to the command is 960x540+1920+0 , the first part 960x540 is the resolution to clip, and the next part 1920 is the horizontal offset from the top left of your actual display. Since we are extending the monitor to the right, we need to clip the display from the right end (offset 1920), and the last 0 is the height offset. Now, if you have any firewall make sure to unblock the port 5900 (default vnc port).

Step 6

The next part is to get a VNC client for your android phone. I suggest using VNC Viewer. One of the problem I faced with this client is the issue with the cursor. But this can be solved by passing -nocursorshape to the x11vnc.

The next part is to get the IP of your computer which can be done with command like ip a . After you get your IP(mine is 192.168.16.103) address, open the android app. Then click the add button.

Now enter your IP address with port number and give any name to the computer like “Work Station” or whatever and tap create.

After that tap the connect button. Make sure the x11vnc is running before connecting the android client.

Skip the warning sign that says the connection is insecure, you can setup password later. You might need to use the phone in landscape mode. Now If you try to drag the window toward the right side of your desktop, you will now see that the window will slide from the left side of your phone.

You can look in x11vnc documentation about the options that it supports. Keep in mind not all VNC Clients support all options. So depending on your client your mileage may vary.

Here is the video of what I meant. I use scrcpy to mirror my phone to my laptop and then use my phone as an external monitor (sounds complicated right).

For those who want to get serious, you can use adb to reverse the port on your phone to your laptop. Download adb and install in your laptop.

Now you can use adb command to reverse the port on your phone. First connect your phone to the laptop and enable developer options and usb debugging. Then enter the below command.

adb reverse tcp:5900 tcp:5900

Now you can use localhost to connect to your x11vnc server.

Using adb is quite fast and you can even watch videos if you use low resolution. Typing this many command every time is not so easy, so you can use the scripts that I have provided in my repository to automate the process.

That’s it for this story, let me know in the comments below if you have any issues or suggestions.

--

--

Suson Thapa
Suson Thapa

Written by Suson Thapa

Android | iOS | Flutter | ReactNative — Passionate Software Engineer

Responses (1)