Using Android/PC as a Second Monitor in Linux
Using second monitor is a cool thing that eliminates the burden of changing windows. Windows 10 have already this feature builtin and it is wireless. There are also bunch of apps available to do these things. But with Linux it seems little hard if you don’t know how to do. So here is the few commands that makes it possible to use any Android devices or Windows or Linux PC as a wireless secondary monitor. However Android can be also connected using a data cable.
And the result will look like above. Image Source
Before starting make sure you have VNC server (x11vnc) installed. To check you can try simply running x11vnc.
You can install
tightvnc if VNC server is not already installed.
First of all you need to find the resolution of the device you want to use as secondary display. For example let’s use an Android device of 1280×720 resolution and the PC has 1366×768 resolution.
Then we need to know available displays and outputs ports.
The output was;
Screen 0: minimum 320 x 200, current 1366 x 768, maximum 8192 x 8192 eDP-1 connected primary 1366x768+0+0 (normal left inverted right x axis y axis) 344mm x 193mm 1366x768 60.00*+ 48.01 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 HDMI-1 disconnected (normal left inverted right x axis y axis)
Here my current display is eDP-1 and unused output port is HDMI-1.
First of all we need to create a new mode for the secondary monitor. For this we need some extra information which can be found using;
gtf 1280 720 60
Which gives VESA GTF mode lines for 1280×720 @ 60 fps. This results;
# 1280x720 @ 60.00 Hz (GTF) hsync: 44.76 kHz; pclk: 74.48 MHz Modeline "1280x720_60.00" 74.48 1280 1336 1472 1664 720 721 724 746 -HSync +Vsync
Now let’s add a new mode for our Android device.
xrandr --newmode "1280x720_60.00" 74.48 1280 1336 1472 1664 720 721 724 746 -HSync +Vsync
Now let’s add this new mode to the unused display. HDMI-1 for this case.
xrandr --addmode HDMI-1 1280x720_60.00
Now let’s enable HDMI-1 and move it to the right of the default display (eDP-1). After this mouse cursor can be moved to right side more than your default display allows. It is because we are adding 1280×720 to the right side of eDP-1.
xrandr --output HDMI-1 --mode 1280x720_60.00 --right-of eDP-1
The final step is to start VNC server and only allow to show the right portion of the screen which can’t be seen in default display.
x11vnc -clip 1280x720+1366+0
It clips the 1366 pixels (width) of your total screen (1366+1280) and shows the only remaining (which we can not see now) screen of the right side.
Now you need to connect your Android or PC using VNC viewer. To do so you need an IP and port. To find IP run;
In my case it is 192.168.1.67. The default port in VNC is 5900 unless you changed it.