#!/bin/sh ############################################################# # sh-tool for some fluxbox-kungfoo ############################################################# # Copyright (c) 2004 Mathias Gumz ############################################################# # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, modify, merge, publish, # distribute, sublicense, and/or sell copies of the Software, and to # permit persons to whom the Software is furnished to do so, subject to # the following conditions: # # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ############################################################# check_in_path() { if ! which "$1" 2>&1 > /dev/null then echo "${0##*/}error, [$1] not in PATH, exit." >&2 exit 1 fi } display_usage() { cat << EOF ABOUT $0 provides some help functions to get more info about the running fluxbox. USAGE $0 [action [options...]] ACTIONS wsname - current workspace name wsno - current workspace number pid - current pid of fluxbox logout - show logout dialog help - display help EOF exit $1 } display_wm_pid() { xprop -root | awk '/^_BLACKBOX_PID/ { print $3; }' } display_ws_number() { xprop -root | awk '{ /^_WIN_WORKSPACE\(CARDINAL\)/ { print $3; }' } display_ws_name() { case $1 in --help | help ) cat << EOF HELP for "$0 ws_name" $0 ws_name - displays current workspace name" EXAMPLE bind a key to in $HOME/.fluxbox/keys to Mod4 Left :MacroCommand {PrevWorkspace} {ExecCommand fbtoolsh wsname | osd_cat} EOF ;; esac xprop -root | awk ' /^_WIN_WORKSPACE\(CARDINAL\)/ { current = $3; } /^_WIN_WORKSPACE_NAMES/ { FS=","; for (i = 3; i <= NF; i ++) { gsub("\"", "", $i); gsub(",", "", $i); ws_names[i] = $i; } } END { print ws_names[current+3]; } ' } func_logout() { mode="$1" if [ -n "$2" ]; then question="$2" else question="really logout?" fi case "$1" in help ) cat << EOF HELP for "$0 logout" $0 logout mode logoutmessage MODES xmessage zenity gdialog kdialog EXAMPLE \$> $0 logout gdialog pops up a logout dialog with a gnomeinterface EOF ;; gdialog ) check_in_path gdialog && gdialog --yesno "$question" ;; zenity ) check_in_path zenity && zenity --question --text="$question" ;; xmessage | gxmessage ) check_in_path $mode && $mode -nearmouse -buttons no:1,yes:0 "$question" ;; kdialog ) check_in_path kdialog && kdialog --yesno "$question" ;; * ) echo "error, not a supported *dialog, exit." exit 1 ;; esac # kill the process :/ if ! $?; then pid=`display_wm_pid` kill -TERM $pid fi } [ $# -lt 1 ] && display_usage 0 case $1 in help | -h | --help ) display_usage 0;; wsno | wsnumber ) display_ws_number;; wsname) shift 1; display_ws_name $@;; wmpid | pid ) display_wm_pid;; logout ) shift 1; func_logout $@;; * ) display_usage 1; esac ############################################################# # vim:ts=2:sw=2:fdm=marker:fdc=4:tw=82: #############################################################