Sharing a screen over IP

Published: ,

So last week, there was a Raspberry Pi lying around. Not knowing what to do with it, I setup pulseaudio to use it as the main audio output over the network. But then it hit me, I might be able to use the connected screen as a desktop extension over my LAN. It's hard to find anything on the web for what I'm trying to do. Most of the hits are for sharing mouse/keyboard over LAN, or about having a program running remotely with the GUI locally (X forwarding).

What I was planning on doing was having a screen advertised on my LAN, to which another computer might connect, thus extending this computer's screen real estate. The solution I now use, is not at all good enough for watching a movie of any sort, it's just usable as a (slowish) terminal/IDE. This was probably to be expected, since I'm doing this all over WiFi, and VNC is having to pump massive amounts of data over the air.

VNC is new to me (I normally only dabble in tmux sessions) And it's OK for my day to day usage, but I'm still looking into having a different solution (e.g. XdmX).

The LAN Screen

Currently, the Pi is running Arch Linux with an autostarted Xsession and login. This X session only starts one thing: a listening vncviewer. (Apparently you can do that, yeah)
There's one slight hiccup: the mouse isn't displayed on the Pi, though the vncviewer's is, and this one changes mode depending on where the mouse actually is.

/usr/bin/startx -- /usr/bin/vncviewer -listen 5500 -ViewOnly -Shared

The Extended screen

As my laptop is running Fedora 28, I have got access to an X session and Wayland, and the X guys have thought of creating x11vnc. This is a vncserver which can VNC any part of your screen or virtual screen. Using XRandR, we can actually fake a screen on any orientation. However, I don't yet know how to create an actual fake screen for X, which would make the script probably a bit nicer.

#!/bin/bash

# Share a part of an unseen screen to a vncviewer at host
#
# On HOST, please use:
# startx -- /usr/bin/vncviewer -listen 5500 -ViewOnly -Shared

OUTPUT="VGA-1"
HOST="192.168.6.103"
ORIENTATION=" --left-of LVDS-1"

# Screen Properties
YEXT=1920
YOFF="+0"
XEXT=1200
XOFF="+600"
REFRESH=60.00


# Generate a valid modeline
modeline=$(cvt $YEXT $XEXT $REFRESH | grep "Modeline")

MODENAME=$(echo $modeline | sed -e "s#Modeline ##" | awk '{print $1}' | sed -e 's#"##g')
MODELINE=$(echo $modeline | cut -d ' ' -f3- )

##################################################################
# All of the Voodoo
##################################################################
# Add modeline 
xrandr --newmode $MODENAME $MODELINE

# Add modeline to unused output
xrandr --addmode $OUTPUT $MODENAME

# set mode and orientation for output
xrandr --output $OUTPUT --mode $MODENAME $ORIENTATION

# Start vncserver, push to host
x11vnc -cursor -clip ${MODENAME}${XOFF}${YOFF} -connect_or_exit $HOST

# Disable output
xrandr --output $OUTPUT --auto
# remove  from output
xrandr --delmode $OUTPUT $MODENAME
# remove from server
xrandr --rmmode $MODENAME

echo "Everything is Back to Normal"
<cool> </cool>