#!/bin/sh # gox: script to start X with different resolutions and bpp. ############################################################################ # Paths to various config files: # XF86CONFIG=/etc/X11/XF86Config FVWMCONFIG=/usr/X11R6/lib/X11/fvwm2/system.fvwmrc TWMCONFIG=/etc/X11/twm/system.twmrc # default command (e.g. wm) to run: # #cmd="exec fvwm -f $FVWMCONFIG" cmd="exec twm -f $TWMCONFIG" # default bpp and x-resolution: bpp=16 res=800 ############################################################################ Usage=" gox: start a simple X session (e.g. twm + xterm) with variable color depth (bpp) and screen resolution. Useful for running games that need lower resolution and/or number of colors. Usage: gox [-c ] [-d ] Defaults: width: $res bpp: $bpp cmd: $cmd Notes: The root password will be required (to run: xinit -- -xf86config via su(1)) A free DISPLAY is searched for from :0 to :9 unless -d is used. The above in -c is usually the window manager command to run, but it could simply just be the game (if it can run with no wm). The template xf86config file: \"$XF86CONFIG\" must have a \"Screen\" section with all of the desired resolutions on a \"Modes\" line. All of those resolutions must, of course, have corresponding \"ModeLine\" lines in the config file that work. If there are uncommon resolutions, it will be best if the used \"Screen\" section is the last one in the file since the resolutions are extracted from it. Additional options: -u run the X session as -C run in background before starting the wm (i.e. the -c cmd). E.g. start the game, but also have a window manager." program=`basename $0` # process cmd line options: while [ "$1" != "" ] do case $1 in "-c") cmd="$2"; shift ;; "-C") append_cmd="$2"; shift ;; "-d") display="$2"; shift ;; "-u") USER="$2"; export USER; shift ;; "-h"*) echo "$Usage"; exit 0 ;; "-"*) echo; echo "$program: $1 not an option"; echo "$Usage"; exit 1 ;; *) break ;; esac shift done # process cmd line operands: if [ "$1" != "" -a "$2" != "" ]; then res=$1 bpp=$2 elif [ "$1" != "" ]; then res=$1 fi # check bpp: case $bpp in 8|16|24|32) echo "bpp=$bpp" ;; *) echo "bad bpp: $bpp (use: 8|16|24|32)"; exit 1 ;; esac # check res: case $res in 1280|1024|800|640|480|400|320) echo "res=$res" ;; *) echo "bad res: $res (use: 1280|1024|800|640|480|400|320)"; exit 1 ;; esac if [ "$display" != "" ]; then DISPLAY="$display"; export DISPLAY else # try to find an open DISPLAY (in case another X server is running) for i in 0 1 2 3 4 5 6 7 8 9 do if netstat -ant | grep LISTEN | grep ":600$i" > /dev/null; then echo "display in use: 600$i" else DISPLAY=":$i"; export DISPLAY echo "set DISPLAY to: $DISPLAY" break fi done fi # create tmpdir and filenames: tmpdir="/tmp/gox.$USER.$$" if [ -d "$tmpdir" ]; then echo "tmpdir already exists: $tmpdir" exit 1 fi mkdir -m 0755 $tmpdir || exit 1 chmod 755 $tmpdir || exit 1 xconfig="$tmpdir/xconfig" xinitrc="$tmpdir/xinitrc" xclient="$tmpdir/xclient" # get the XY resolution for the "Virtual": XY=`grep '^[ ]*Modes[ ]' $XF86CONFIG \ | grep "${res}x" \ | sed -e 's/Modes/ /g' -e 's/[ ][ ]*/ /g' -e 's/"//g' \ | tr ' ' '\n' \ | grep "^${res}x" \ | sed -e 's/x/ /g' \ | tail -1` if [ "$XY" = "" ]; then # error case, try these as backup.. case $res in 1280) XY="1280 1024" ;; 1024) XY="1024 768" ;; 800) XY="800 600" ;; 640) XY="640 480" ;; 480) XY="480 320" ;; 400) XY="400 300" ;; 320) XY="320 240" ;; *) XY="800 600"; echo "warning set XY to $XY" ;; esac fi echo "XY: $XY" # modify the template XF86Config file to desired settings: cat $XF86CONFIG | sed -e "s/^[ ]*Depth.*$/ Depth $bpp/g" \ -e "s/^[ ]*Virtual.*$/ Virtual $XY/" > $xconfig # create the xintirc to use: if echo "$cmd" | grep -i wm >/dev/null; then # if cmd has string "wm" pop up an xterm to work in. xterm_cmd="export TERM=xterm; sleep 1; xterm -geometry 80x25+1+1 &" else xterm_cmd="" fi if [ "$append_cmd" != "" ]; then append_cmd="sleep 1; $append_cmd &" if [ "$xterm_cmd" != "" ]; then xterm_cmd=`echo "$xterm_cmd" | sed -e 's/xterm /xterm -iconic /'` fi fi cat > $xinitrc << END #!/bin/sh $xterm_cmd $append_cmd # start window manager or supplied cmd: $cmd END # create the "client" cmd script for xinit arg: cat > $xclient << END #!/bin/sh # the following xhosts could be needed in some situations to allow # windows from processes owned by the ordinary user: # #xhost +localhost #xhost +`hostname` su $USER -c $xinitrc END # make them both executable: chmod 755 $xinitrc $xclient # run xinit as root: su root -c "xinit $xclient -- $DISPLAY -xf86config $xconfig" # when it finishes, remove our junk: rm -rf $tmpdir exit 0