Skip to content

Instantly share code, notes, and snippets.

@rkmax
Created November 18, 2014 23:50
Show Gist options
  • Save rkmax/6262e14d64ea58f8bb1c to your computer and use it in GitHub Desktop.
Save rkmax/6262e14d64ea58f8bb1c to your computer and use it in GitHub Desktop.
Setup a virtual screen for connect from VNC viewer (example VNC VIwer Android)
#!/bin/bash
WIDTH=1280
HEIGHT=800
x11_cmd=x11vnc
if [[ ! -z $(pgrep ${x11_cmd}) ]]; then
pkill ${x11_cmd}
fi
MODE=$(gtf ${WIDTH} ${HEIGHT} 60| egrep -v '#' | awk '{first = $1; $1 = ""; print $0, first; }')
MODE_NAME=$(echo ${MODE} | awk '{ print $1}')
OFFSET=$(xrandr | grep primary | awk '{ print $4}' | sed 's/\([0-9]*\)\(.*\)/\1/')
PRIMARY=$(xrandr | grep primary | awk '{print $1}')
VIRTUAL=VIRTUAL1
xrandr --newmode ${MODE} 2> /dev/null
xrandr --addmode ${VIRTUAL} ${MODE_NAME} 2> /dev/null
xrandr --output ${VIRTUAL} --right-of ${PRIMARY}
LOG=/var/log/x11vnc.log
if [[ ! -f "${LOG}" ]]; then
sudo touch ${LOG}
sudo chown ${USER}. ${LOG}
fi
x11vnc -usepw -noxdamage -bg -forever -display $DISPLAY -clip "${WIDTH}x${HEIGHT}+${OFFSET}+0" -o ${LOG}
xset r
@joeesteves
Copy link

Thanks, works great!

@Sergi030
Copy link

How I can create the Virtual1 Display?

@sillyslux
Copy link

@Sergi030 i had the same issue, got it back after creating
/usr/share/X11/xorg.conf.d/20-intel.conf
Section "Device" Driver "Intel" Identifier "Intel" EndSection

@uxdiin
Copy link

uxdiin commented Sep 3, 2022

I just found out you don't need vnc server, You can just use software like deskscreen and share ur virtual monitor lol

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment