#!/bin/sh # # xlogout [options] [text] # # Logout button using various different programs which may or maynot # be available on the current machine. When user presses it just quit. # To be used as the last command in a xsession or xinitrc script. # # Options # -wm Size it to match Anthony's WS manager (40 pixels high) # -g {geometry} Where to place the logout button (positions only) # -fg {color} foreground color (for text and bitmap buttons) # -bg {color} background color (for text and bitmap buttons) # # Any 'text' will be used instead of "Logout" if provided. # # For example to create a 'hold command' for a SSH network link for VNC # xlogout "VNC Link" # # Author: Anthony Thyssen # Initially Created: 1 November 1994 # Re-written: 14 August 1997 # # ---- Defaults ----- position='-5-5' # default position (if not given) fg=Gold # bitmap/text colors bg=Navy icondir="$HOME/icons/appl/twm" # Location of AIcons Library bitmap="$icondir/logout32.xbm" # bitmap monocrome image (not used) pixmap="$icondir/logout32.xpm" # pixmap color image (standard size) # Size/Position # to fit a ctwm window manager (40 pixel high screens - 3 pixel border) # wm_size=`xdpyinfo | # sed -n 's/ *dimensions: *\([0-9]*\)x\([0-9]*\) .*/40*\1\/\2-3/pg' | # bc`x38 wm_size=60x40 # Is the command available? type -t cmd_found >/dev/null || cmd_found() { type -t "$1" >/dev/null; } # ----- Option Handling ----- PROGNAME=`basename $0` Usage() { echo >&2 "Usage: $PROGNAME [options] [text]" echo >&2 " Start a logout button, and wait for it to be pressed" exit 10 } while [ $# -gt 0 ]; do case "$1" in -v) verbose=true ;; # verbose -wm) size=$wm_size ;; # specific Window Manager size for button -g) shift; position="$1" ;; # placement geometry -fg) shift; fg="$1" ;; # foreground color -bg) shift; bg="$1" ;; # background color --) shift; break ;; # end options -*) echo "$PROGNAME: Unknown option \"$1\"" 1>&2 Usage ;; *) break ;; esac shift # next option done unset loop (( $# > 1 )) && Usage "Too Many Arguments" class="xlogout" # I have my window manager setup NOT to decorate this class text="${1:-Logout}" # ----------- Show Pixmap Logout Button ----------- # This is very GOOD but can not handle a mouse button press # and it has positioning problems. (keypress handler is hardcoded) # Needs the libXpm-devel package installed # # if cmd_found sxpm; then # [ "$verbose" ] && echo "xlogout using sxpm" # exec sxpm -name "$class" -title "$class" -geometry "$size$position" \ # -xrm '*baseTranslations: #override : exit(0)' \ # "$pixmap" # fi # # ----------- Bricons Logout Button ----------- # Bricons allows for the use of a color pixmap image # # if cmd_found bricons; then # [ "$verbose" ] && echo "xlogout using bricons" # tmp=/tmp/xlogout$$ # cat >$tmp <<-EOF # %pixmap $pixmap # kill $$ # EOF # # # auto remove the above file after we have started! # (sleep 60; rm -f $tmp;) & # # # exec to the actual logout button # # NOTE: You have to exec for the 'kill' in script to work # exec bricons -name "$class" -title "$class" \ # -geometry "$size$position" -fg Black -bg "$bg" \ # -default off -file $tmp $size \ # -xrm "*Thickness: 0" -xrm "*borderWidth: 0" \ # >/dev/null 2>&1 # fi # ------- XLabel Button -------- # Graphical bitmap image -- removed due to old Xaw dependancy # if cmd_found xlabel; then # [ "$verbose" ] && echo "xlogout using xlabel" # exec xlabel -name "$class" -title "$class" \ # -g "$size$position" -bg "slategrey" -fg "black" \ # -xrm "*bitmap: $bitmap" \ # -xrm '*baseTranslations: #override : quit()' # fi # ------ XMessage Logout Text Button --------- if cmd_found xmessage; then [ "$verbose" ] && echo "xlogout using xmessage" exec xmessage -name "$class" -title "$class" \ -geometry $position -fg "$fg" -bg "$bg" \ -buttons "" -xrm '*message.borderWidth: 0' \ -xrm '*message.scrollVertical: false' \ -xrm '*Font: -*-new cent*-bold-r-normal--24-*' \ -xrm 'xlogout*.displayList: ' \ -xrm 'xlogout*baseTranslations: #override : exit(0)' \ "$text" fi # ------- YAD Button -------- if cmd_found yad; then [ "$verbose" ] && echo "xlogout using yad" exec yad --title "$class" --button="$text" --geometry=$position \ --undecorated --skip-taskbar #--image=gnome-logout --image-on-top \ fi # ------- XLogo Button -------- # This is normally a last resort only but xlogo should be present... # Start a xlogo which is pressed anywhere will exit cleanly # This may not work on some very old X window systems. # if cmd_found xlogo; then [ "$verbose" ] && echo "xlogout using xlogo" [ -z "$size" ] && size=32x32 #fall back default size exec xlogo -name "$class" -title "$class" \ -g "$size$position" -fg "$fg" -bg "$bg" \ -xrm 'XLogo*baseTranslations: #override : quit()' fi # ------- Zenity Notification ------ # Places itself in the panel notification area - not nice if cmd_found zenity; then [ "$verbose" ] && echo "xlogout using xenity" exec zenity --info --text "$text"'\n(Fallback)' fi # ------- Emergency logout button ------ echo >&2 "xlogout: I can find anything to use as a logout button!" echo >&2 " Try setup a Emergency Session" # Lets run a terminal if cmd_found xterm; then [ "$verbose" ] && echo "xlogout using xterm" exec xterm -name "$class" -title "$class" -iconic \ -geometry 80x3+5+5 -fg "$fg" -bg "$bg" fi # What not even xterm! Arrgghh.. if cmd_found gnome-calculator; then [ "$verbose" ] && echo "xlogout using gnome-calculator" gnome-terminal & exec gnome-calculator fi # ------- Desperation Time ------ echo >&2 "xlogout: No XTerm! ... Going into sleep loop - kill me!" while :; do sleep 3600; done # -------------------------------------------