X-Git-Url: http://git.tpope.net/?p=tpope-extra.git;a=blobdiff_plain;f=bin%2Fgamelaunch;h=cb0a5c48a1a2bb31d0500c60ceec7374e831f7b8;hp=aaa0c515b81cad48ee7a6ca80a8c83896dd355e3;hb=refs%2Fheads%2Fmaster;hpb=6d3296dbcaf824fed68a80348847949270b1770b diff --git a/bin/gamelaunch b/bin/gamelaunch index aaa0c51..cb0a5c4 100755 --- a/bin/gamelaunch +++ b/bin/gamelaunch @@ -1,49 +1,94 @@ #!/bin/sh -# Author: Tim Pope +# $Id$ +# -*- sh -*- vim: ft=sh sw=4 sts=4 -# Launches a game. Works both on $1 (an argument) and $0 (the actually name +# 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. - -pkill -INT `basename $0`-bin -pkill -INT ut2003-bin -pkill -INT ut2004-bin -sleep 1 -pkill -9 `basename $0`-bin +# games, pausing unclutter, remapping the keyboard, setting an away message, +# and anything else that needs to be done. + +basename="`basename $0`" + +if [ "$basename" = gamelaunch ]; then + if [ "x$1" = x--name ]; then + shift + name="$1" + shift + fi + binary="$1" + basename="`basename $binary`" + shift +fi + +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 -#[ -f "$HOME/.activity" ] && mv "$HOME/.activity" "$HOME/.activity.$$.bak" -tpope activity > "$HOME/.activity.$$.bak" -#echo "Playing `basename $0`" > "$HOME/.activity" -echo "Playing `basename $0`"|tpope activity - +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" || xmodmap "$HOME/.xmodmap" -pkill -STOP unclutter +xmodmap "$HOME/.Xmodmap" 2>/dev/null || xmodmap "$HOME/.xmodmap" +skill -STOP unclutter -xmodmap -e "keysym Super_L = F13" -xmodmap -e "keysym Hyper_L = F14" -xmodmap -e "keysym Super_R = F15" +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" + ;; +esac -for suffix in '_demo' '-demo' 'demo' ''; do - [ -x "/usr/local/bin/`basename $0`$suffix" ] && \ - binary=/usr/local/bin/`basename $0`$suffix -done +activity="`tpope status activity`" +if [ -n "$game" ]; then + tpope status activity "Playing $game" +fi -if [ "`basename $0`" = gamelaunch ]; then - binary="$1" - shift +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 >/dev/null +fi -pkill -CONT unclutter -setxkbmap us -xmodmap "$HOME/.Xmodmap" || xmodmap "$HOME/.xmodmap" +on_exit() { + [ -z "$sdpid" ] || kill "$sdpid" + skill -CONT unclutter + setxkbmap us + xmodmap "$HOME/.Xmodmap" 2>/dev/null || xmodmap "$HOME/.xmodmap" + xset m 3 3 + [ -z "$s3" ] || s3switch $s3 >/dev/null + xvidtune -unlock + FvwmCommand "GoToDeskAndPage 0 0 0" >/dev/null 2>&1 + tpope status activity -c +} + +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" +FvwmCommand "GoToDeskAndPage 0 2 2" >/dev/null 2>&1 +tpope display-manage $binary "$@" # 2>&1