#!/bin/bash

# This script uses Xnest to provide remote GUI access to the Raspberry Pi
# It will create a single window on the remote machine, and populate that
# window with the contents of the user's Raspberry Pi desktop.
# The remote window /is/ the Rpi desktop.

# Usage: Xdesk.sh [display]
# where display is the colon address of the new display (defaults to :1)

WHERE=${1:-:1}

Xnest -name "$USER @ $HOSTNAME - display $WHERE" -geometry 1024x768+0+1080 $WHERE &
# Xnest opens a window on the remote system, and allows Rpi X clients
# to access it as if they were talking to the local X server
# Note: the -geometry parameter above sets the window size and location
#	on the remote system. The values above make the window (and thus
#	the Rpi desktop) 1024 pixels wide by 768 pixels high, and place
#	the window's upper left hand corner on the remote desktop at a point
#	0 pixels to the right of the left edge of the remote desktop, and
#	1080 pixels below the top edge of the remote desktop.
#	Adjust these size and position values as you need.
# Also: Xnest takes an explicit desktop identifier in it's commandline
#	so we pass in the address here. We don't initialize DISPLAY
#	and use it here (either explicitly /or/ implicitly) because
#	this somehow fscks Xnest and/or lxsession. So, we use WHERE
#	instead, and set DISPLAY after Xnest is started

export DISPLAY=$WHERE

exec lxsession
# Note:	lxsession expects the DISPLAY environment variable to name
#	the target display.
# Also: we "exec" because this is the end of the script, and we don't
#	need the shell to stick around. Doing this leaves Xnest and
#	lxsession running, but disposes of the bash process.
