User Tools

Site Tools


projects:liflg:startscript_xephyr
Idea

This script should wrap the game-binaries/libs so they use xephyr and not the «real» X-Server.

Code
#!/bin/sh
###############################################################################
#
## LIFLG Startup Script
#
# Copyright (C) 2004-2010  Team LIFLG http://www.liflg.org/
#
#
# This script is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
###############################################################################
#
# The game binary
GAME_BINARY=""

# Subdirectory
SUBDIR="."

# Library directory
LIBDIR=""

# Xephyr binary
XEPHYR="Xephyr"

# Fullscreen or not
XEPHYR_FULLSCREEN="true"

# Resolution to activate to before going fullscreen
XEPHYR_FULLSCREEN_RESOLUTION="1024x768"

# Additional commandline options for mods etc.
CMD_ARGS=""

# Tests, if xrandr is available and safe current mode
XRANDR_AVAILABLE="false"
if [ -n `which \"xrandr\"` ]
then
	XRANDR_AVAILABLE="true"
        XRANDR_ORIGINAL_MODE=`xrandr|grep *+|head -n 1|awk '{print $1}'` #forgett aditional monitors if availabel
fi

# display number
#XSERVER_DISPLAY=":1.0" # not tested if working

###############################################################################
## DO NOT EDIT BELOW THIS LINE
###############################################################################
export LANG="POSIX"

if [ -n "${XSERVER_DISPLAY}" ]
then
	DISPLAY=${XSERVER_DISPLAY}
	export DISPLAY
fi

# readlink replacement for older bash versions
readlink() {
	path=$1
 
	if [ -L "$path" ]
	then
		ls -l "$path" | sed 's/^.*-> //'
	else
		return 1
	fi
}

SCRIPT="$0"
COUNT=0
while [ -L "${SCRIPT}" ]
do
	SCRIPT=$(readlink ${SCRIPT})
	COUNT=$(expr ${COUNT} + 1)
	if [ ${COUNT} -gt 100 ]
	then
		echo "Too many symbolic links"
		exit 1
	fi
done
GAMEDIR=$(dirname "${SCRIPT}")

cd "${GAMEDIR}"

echo "Trying to start Xephyr-Server"
if [ -n "`which \"$XEPHYR\"`" ]
then
	echo "Xephyr binary ($XEPHYR) found, using it"
        if [ -n "$DISPLAY" ]
        then
        	TMPDISPLAY="`echo "M${DISPLAY}"|awk -F: '{print $2}'|awk -F. '{print $1}'`" # forget the hostname part, hope that's not a problem
                TMPDISPLAY=":`expr $TMPSCREEN + 1`"
	else
        	TMPDISPLAY=":1"
       	fi

        echo "Starting new server on ${TMPDISPLAY}"

        if [ "$XEPHYR_FULLSCREEN" = "true" -a "$XRANDR_AVAILABLE" = "true" ]
        then
		echo "Switching from $XRANDR_ORIGINAL_MODE to $XEPHYR_FULLSCREEN_RESOLUTION on host server"
		xrandr -s "$XEPHYR_FULLSCREEN_RESOLUTION"
        	$XEPHYR $TMPDISPLAY  -ac -br -fullscreen -screen $XEPHYR_FULLSCREEN_RESOLUTION -reset -extension Composite &
        else
                $XEPHYR $TMPDISPLAY -ac -br -screen $XEPHYR_FULLSCREEN_RESOLUTION -reset -extension Composite +extension RANDR &
        fi
	XPID=$!
	
	export OLD_DISPLAY=$DISPLAY
        export DISPLAY=$TMPDISPLAY
        sleep 3; #give Xephyr enougth time to start
else
        echo "Xephyr binary not found, falling back to standard server"
fi

	./${GAME_BINARY} ${CMD_ARGS} "$@"
	EXITCODE="$?"

if [ -n "$XPID" ]
then
	kill $XPID
fi

if [ "$XEPHYR_FULLSCREEN" = "true" -a "$XRANDR_AVAILABLE" = "true" ]
then
	echo "Switching back to $XRANDR_ORIGINAL_MODE on host server"
	DISPLAY=$OLD_DISPLAY xrandr -s $XRANDR_ORIGINAL_MODE #switching back to the highest available resolution
fi

exit ${EXITCODE}
projects/liflg/startscript_xephyr.txt · Last modified: 2010/02/18 13:38 by rettichschnidi