#!/bin/zsh -- # raise a window using wmctrl. If given just a string, it will use # that as a substring for the window-title; it will preferably raise # a match in the current workspace, barring that, on the curring desktop, # or any match otherwise. # # if a desk-index is given with --desk, that desk will be used as preferred # desk over the current one. # # if --exact is given, exact matching (incl. case) will be done rather # than case-insensitive sub-string. # # if passed other parameters, the whole thing will be passed through to # wmctrl without further ado; see there for possible parameters. # # will work correctly on beryl's/compiz' funny cube. # 2007/04/28 Azundris init (yes, this should really be perl) # 2007/05/07 Azundris return meaningful exit-code # 2007/05/07 Azundris parameters for raise_or_start, bug fixes # 2007/05/07 Azundris bug fixes # preferred desk, not given, -1, or - default to current DESK_CUR="" if [[ "x$1" = "x--desk" ]] then shift if [[ "x$1" != "x-1" && "x$1" != "x-" ]] then DESK_CUR=$1 fi shift fi # strict matching? if [[ "x$1" = "x--exact" ]] then EXACT="-F" shift else EXACT="" fi # any other args? call wmctrl with them! Z=`echo $1|cut -c1` if [ "x$Z" = "x-" ] then exec wmctrl $@ fi # do the thang APP="$1" if [ "x$EXACT" = "x" ] then HITS=`wmctrl -l -G|sed -e's/0x[0-9a-f]* *[0-9-]* *[0-9-]* *[0-9-]* *[0-9-]* *[0-9-]* [ ]*[^ ]* *//'|grep -i "$APP"|wc -l` else HITS=`wmctrl -l -G|sed -e's/0x[0-9a-f]* *[0-9-]* *[0-9-]* *[0-9-]* *[0-9-]* *[0-9-]* [ ]*[^ ]* *//'|egrep "^$APP\$"|wc -l` fi # if we have multiple candidates for this application name, pick the one # on the current viewport, if any. otherwise, choose the first match. if [ "$HITS" -gt 1 ] then if [ "x$DESK_CUR" = "x" ] then DESK_CUR=`wmctrl -d|grep "*"|cut -d' ' -f1` fi WA_CUR=`wmctrl -d|grep '*'|sed -e's/.* WA: *\([0-9-]*\),\([0-9-]*\) *\([0-9]*\)x\([0-9]*\) .*/\1 \2 \3 \4/'` WA_X=`echo $WA_CUR|cut -d' ' -f1` WA_Y=`echo $WA_CUR|cut -d' ' -f2` WA_W=`echo $WA_CUR|cut -d' ' -f3` WA_H=`echo $WA_CUR|cut -d' ' -f4` let X2="$WA_X+$WA_W" let Y2="$WA_Y+$WA_H" wmctrl -l -G|grep -i "$APP"|while read L do DESK=`echo "$L"|sed -e's/0x[0-9a-f]* *\([0-9-]*\) .*/\1/'` if [ "x$EXACT" != "x" ] then IS_MATCH=`echo $L|sed -e's/0x[0-9a-f]* *[0-9-]* *[0-9-]* *[0-9-]* *[0-9-]* *[0-9-]* [ ]*[^ ]* *//'|egrep "^$APP\$"|wc -l` else IS_MATCH=`echo $L|sed -e's/0x[0-9a-f]* *[0-9-]* *[0-9-]* *[0-9-]* *[0-9-]* *[0-9-]* [ ]*[^ ]* *//'|grep -i "$APP"|wc -l` fi if [ $IS_MATCH -eq 0 ] then DESK="-2" fi if [ "x$DESK" = "x$DESK_CUR" ] then DESK_APP=`echo $L|sed -e's/0x[0-9a-f]* *[0-9-]* *[0-9-]* *[0-9-]* *[0-9-]* *[0-9-]* [ ]*[^ ]* *//'` # echo "$DESK_APP is on correct desk ($DESK) ..." APP_X=`echo $L|sed -e's/0x[0-9a-f]* *[0-9-]* *\([0-9-]*\) *.*/\1/'` APP_Y=`echo $L|sed -e's/0x[0-9a-f]* *[0-9-]* [0-9-]* *\([0-9-]*\) *.*/\1/'` if [[ $APP_X -ge $WA_X && $APP_X -le $X2 && $APP_Y -ge $WA_Y && $APP_Y -le $Y2 ]] then WA_APP=$DESK_APP # echo "$DESK_APP ($WA_X <= $APP_X <= $X2; $WA_Y <= $APP_Y <= $Y2) qualifies ..." fi fi done fi if [ "x$DESK_APP" != "x" ] then APP=$DESK_APP fi if [ "x$WA_APP" != "x" ] then APP=$WA_APP fi echo "trying to show '$APP' ..." if [ "x$EXACT" = "x" ] then wmctrl -a "$APP" else wmctrl -a "$APP" fi exit $?