From: Tim Pope Date: Tue, 31 May 2005 06:55:34 +0000 (+0000) Subject: Major overhaul X-Git-Url: http://git.tpope.net/?p=tpope-extra.git;a=commitdiff_plain;h=6d0e3a9ebfaf12eda1f3d7256c339406a1fc247c Major overhaul --- diff --git a/bin/gamelaunch b/bin/gamelaunch index 7d46589..baa8aa0 100755 --- a/bin/gamelaunch +++ b/bin/gamelaunch @@ -4,56 +4,90 @@ # Launches a game. Works both on $1 (an argument) and $0 (the actual name # of the script, presumably a symlink). Takes care of killing troublemaking -# games, pausing unclutter, remapping the keyboard, and setting an away -# message. +# games, pausing unclutter, remapping the keyboard, setting an away message, +# and anything else that needs to be done. -pkill -INT `basename $0`-bin -pkill -INT ut2003-bin -pkill -INT ut2004-bin -sleep 1 -[ "$DISPLAY" = "127.0.0.1:7.0" ] && DISPLAY=:1.0 - -for suffix in '_demo' '-demo' 'demo' ''; do - [ -x "/usr/games/`basename $0`$suffix" ] && \ - binary="/usr/games/`basename $0`$suffix" - [ -x "/usr/local/bin/`basename $0`$suffix" ] && \ - binary="/usr/local/bin/`basename $0`$suffix" -done +basename="`basename $0`" -if [ "`basename $0`" = gamelaunch ]; then +if [ "$basename" = gamelaunch ]; then + if [ "x$1" = x--name ]; then + shift + name="$1" + shift + fi binary="$1" + basename="`basename $binary`" shift fi -pkill -9 `basename $binary`-bin +pkill -INT "^$basename-bin\$" && sleep 1 +pkill -INT "^ut2004-bin\$" && sleep 1 +pkill -KILL "^$basename-bin\$" sync +[ "$DISPLAY" = "127.0.0.1:7.0" ] && DISPLAY=:1.0 + +game="${name:-$basename}" +if [ -f "$HOME/games/names.txt" ] && grep -i "^$game=" "$HOME/games/names.txt" >/dev/null; then + game="`grep "^$game=" "$HOME/games/names.txt"|sed -e 's/^[^=]*=//g'`" +elif [ -z "$name" ]; then + game="`echo $game|sed -e 's/\(^\|[-_. ]\)\(.\)/ \U\2/g' -e 's/\([a-z]\)\([0-9]\)/\1 \2/' -e 's/ \([EU]\)t\>/ \1T/' -e 's/^ //'`" +fi + +for suffix in '_demo' '-demo' 'demo' ''; do + [ -x "/usr/bin/$basename$suffix" ] && \ + binary="/usr/bin/$basename$suffix" + [ -x "/usr/games/$basename$suffix" ] && \ + binary="/usr/games/$basename$suffix" + [ -x "/usr/local/bin/$basename$suffix" ] && \ + binary="/usr/local/bin/$basename$suffix" +done + +if [ -z "$binary" ]; then + echo "Game not found." >&2 + exit 1 +fi + setxkbmap us -xmodmap "$HOME/.Xmodmap" 2> /dev/null || xmodmap "$HOME/.xmodmap" +xmodmap "$HOME/.Xmodmap" 2>/dev/null || xmodmap "$HOME/.xmodmap" pkill -STOP unclutter -if [ "`basename $binary`" = doom3 ]; then - xset m 2 4 - xmodmap -e "keysym Super_L = KP_5" - xmodmap -e "keysym Hyper_L = KP_Insert" - xmodmap -e "keysym Super_R = F11" -else +case "$basename" in + ut2004|quake3|doom3|et|armyops) xmodmap -e "keysym Super_L = F13" xmodmap -e "keysym Hyper_L = F14" xmodmap -e "keysym Super_R = F15" -fi + ;; +esac tpope activity > "$HOME/.activity.$$.bak" -echo "Playing `basename $binary`"|tpope activity - +if [ -n "$game" ]; then + tpope activity "Playing $game" +fi + +if lspci 2>/dev/null|grep 'VT8233/A/8235/8237' >/dev/null; then + SDL_DSP_NOSELECT=1 + export SDL_DSP_NOSELECT + sh -c "sleep 2; amixer sset IEC958 unmute >/dev/null &" +fi -$binary "$@" 2>&1 | tee "$HOME/.`basename $binary`.log" +if lspci 2>/dev/null|grep 'Savage 3D' >/dev/null; then + s3="`s3switch|grep 'Devices active:'|sed -e 's/Devices active: *//'`" + s3switch TV +fi -pkill -CONT unclutter -setxkbmap us -xmodmap "$HOME/.Xmodmap" || xmodmap "$HOME/.xmodmap" -xset m 3 3 +on_exit() { + [ -z "$sdpid" ] || kill "$sdpid" + pkill -CONT unclutter + setxkbmap us + xmodmap "$HOME/.Xmodmap" 2>/dev/null || xmodmap "$HOME/.xmodmap" + xset m 3 3 + [ -z "$s3" ] || s3switch $s3 + + tpope activity "`cat "$HOME/.activity.$$.bak"`" + rm -f "$HOME/.activity.$$.bak" +} + +trap on_exit EXIT -#rm -f "$HOME/.activity" -#[ -f "$HOME/.activity.$$.bak" ] && mv "$HOME/.activity.$$.bak" "$HOME/.activity" -cat "$HOME/.activity.$$.bak"|tpope activity - -rm -f "$HOME/.activity.$$.bak" +tpope display-manage $binary "$@" # 2>&1