#!/bin/zsh -- # start a program on a given desktop (defaulting to current), with # a given location and/or size (given as wmctrl or X geometry), # defaulting to whatever the application tries for. # xstartup |- [-t ] [-F] # # 0..n for work-area, -1 or - for current # 0..1 transparency. requires transset. # # [],|-1,|-1,|-1,|-1 # |-1x|-1[+|-1+|-1] # # Example: # xstartup -1 320,192,992,888 -F "Beryl Settings Manager" beryl-settings # # start beryl settings manager on current cube-face (-1), # at 320,192, size 992x888 (default gravity omitted in front), # as beryl-settings (with no parameters), # expect window-title to be (exactly, -F) "Beryl Settings Manager" # this was tested with beryl's cube, should work with compiz too # (and POSSIBLY other window-managers; the work-area calculations # may or may not be wonky for that), should work with non-cube # (read "wall") workspace layouts. for applications going to a # "background" cube-face, we will spin the cube first, for effect. # for maximum effect, use in a sequence, opening your favourite # programs during startup from ~/.xinitrc -- and yes, this has minor # race conditions if someone manages to spin the cube while this # script runs (app may end up on wrong cube-face, though script tries # to avoid that), or if several instances of the same app exist on the # same cube-face (wrong app may have geometry applied). it's a bit QND # that way, but it Works For Me(TM). # "Yes, this should really be perl." # 2007/05/05 Azundris init # 2007/05/07 Azundris basic DISPLAY magic # 2007/05/11 Azundris basic transparency support. requires transset. if [[ $# -eq 0 ]] then echo "$0 |- [-t ] [-F] " echo echo " 0..n for work-area, -1 or - for current" echo "" echo " 0..1 for transparency (float!)" echo " [],|-1,|-1,|-1,|-1" echo " |-1x|-1[+|-1+|-1]" fi if [[ "x$DISPLAY" = "x" ]] then if [ -f ~/.display ] then . ~/.display else export DISPLAY=":0" fi echo "warning: DISPLAY not set, defaulting to $DISPLAY ..." fi WA=$1 shift GEO=$1 X=`echo "x$GEO"|sed -e's/x[0-9]*,[0-9-]*,[0-9-]*,[0-9-]*,[0-9-]*//'` if [[ "x$X" = "x" ]] then echo "full wmctrl geo ($GEO)" else X=`echo "x$GEO"|sed -e's/x[0-9-]*,[0-9-]*,[0-9-]*,[0-9-]*//'` if [[ "x$X" = "x" ]] then GEO="0,$GEO" echo "partial wmctrl geo ($GEO)" else X=`echo "x$GEO"|sed -e's/x[0-9-]*x-*[0-9]*[-+]*[0-9][0-9]*[-+][0-9-]*//'` if [[ "x$X" = "x" ]] then W=`echo "x$GEO"|sed -e's/x\(-*[0-9][0-9]*\)x.*/\1/'` H=`echo "x$GEO"|sed -e's/x[0-9-]*x\(-*[0-9][0-9]*\)[+-].*/\1/'` R=`echo "x$GEO"|sed -e's/x[0-9-]*x-*[0-9][0-9]*\(.*\)/\1/'` X=`echo "x$R"|sed -e's/x\([-+]*[0-9][0-9]*\).*/\1/'` Y=`echo "x$R"|sed -e"s/x$X\(.*\)/\1/"|sed -e's/+//'` X=`echo "x$X"|sed -e's/x+//'` GEO="0,$X,$Y,$W,$H" echo "full X geo ($GEO)" else X=`echo "x$GEO"|sed -e's/x[0-9-]*x[0-9-]*//'` if [[ "x$X" = "x" ]] then W=`echo "x$GEO"|sed -e's/x\([0-9-]*\)x.*/\1/'` H=`echo "x$GEO"|sed -e's/x[0-9-]*x\([0-9-]*\)/\1/'` GEO="0,-1,-1,$W,$H" echo "partial X geo ($GEO)" else if [[ "x$GEO" != "x-" ]] then echo "unknown geometry ($GEO)" exit 1 fi fi fi fi fi shift TRANS="" if [[ "x$1" = "x-t" ]] then shift TRANS="$1" shift fi EXACT="" if [[ "x$1" = "x-F" ]] then EXACT="-F" shift else if [[ "x$1" = "x-" ]] then shift fi fi MASK=$1 shift ARGS="$*" # echo "|$WA|$GEO|$EXACT|$MASK|$ARGS|" if [[ "x$WA" = "x-1" || "x$WA" = "x-" ]] then echo "current work-area" WA="" else DESKS=`wmctrl -d|wc -l` let DESKS="$DESKS-1" X=`echo $WA|sed -e's/[^0-9]*//g'` if [[ "x$WA" != "x$X" || $X -gt $DESKS ]] then echo "work-area must be numeric, '-1' ... '$DESKS', or '-' -- '$WA' does no qualify!" exit 1 fi CURWA=`wmctrl -d|grep " \* "|cut -d' ' -f1` X=0 wmctrl -d|while read L do CURWA=`echo "$L"|cut -d' ' -f1` W=`echo "$L"|sed -e's/.* WA: [0-9-]*,[0-9-]* \([0-9-]*\)x[0-9-]* .*/\1/g'` if [[ "$CURWA" -lt "$WA" ]] then let X="$X+W" fi done echo "go to work-area $WA @ $X" wmctrl -o $X,0 while [[ "$X" != "" ]] do sleep 1 CURX=`wmctrl -d|head -1|sed -e's/.* VP: \([0-9-]*\),[0-9-]* .*/\1/g'` if [[ "$CURX" = "$X" ]] then X="" fi done fi $* & PID=$! # wait for window to open X=$MASK while [[ "x$X" != "x" ]] do sleep 1 wmctrl -l -G|grep -i "$MASK"|while read L do APP=`echo $L|sed -e's/0x[0-9a-f]* *[0-9-]* *[0-9-]* *[0-9-]* *[0-9-]* *[0-9-]* [ ]*[^ ]* *//'` MSK=`echo "$MASK"|sed -e's#/#\/#g'` TGT=`echo $APP|sed -e"s#$MSK##gi"` if [[ "x$TGT" != "x$APP" ]] then X="" echo "$APP-window is open ..." WINID=`echo $L|sed -e's/\(0x[0-9a-f]*\) .*/\1/'` if [[ "x$TRANS" != "x" ]] then which transset >/dev/null 2>&1 if [ $? -eq 0 ] then echo "setting transparency to $TRANS ..." transset --id $WINID $TRANS else echo "transset not found; transparency argument ignored ..." fi fi if [[ "x$GEO" != "x" && "x$GEO" != "x-" ]] then echo "enforce geometry $GEO ..." if [[ "x$EXACT" != "x" ]] then wmctrl $EXACT -r $MASK -e $GEO else wmctrl -r $MASK -e $GEO fi fi fi done done echo "WINID: $WINID" exit 0