--- trunk/webthumb 2008/02/06 23:34:35 63 +++ trunk/webthumb 2008/02/06 23:59:09 65 @@ -29,13 +29,18 @@ # It will create snapshot of following size W=1024 H=768 +D=24 # and then resize it to (comment out to disable) #RESIZE=200x -# turn locally visible Xnest server to watch progress +# turn locally visible server to watch progress DEBUG=0 -test ! -z "$3" && DEBUG=1 +if [ ! -z "$3" ] ; then + echo "DEBUG turned on" + DEBUG=1 + D=8 +fi # wait for $WAIT seconds for page to load WAIT=30 @@ -81,20 +86,30 @@ exit 1 fi -echo "starting X server $XSERVER" +DISPLAY_PORT=6042 + +while netstat -ln | grep ":$DISPLAY_PORT " >/dev/null ; do + DISPLAY_PORT=`expr $DISPLAY_PORT + 1` +done -export DISPLAY=:42 +DISPLAY=:`expr $DISPLAY_PORT - 6000` +echo "using DISPLAY=$DISPLAY" if [ "$DEBUG" == 1 ] ; then echo "using locally visible debug server on $LOCAL_DISPLAY" - Xnest -display $LOCAL_DISPLAY -ac -geometry ${W}x${H} -depth 24 $DISPLAY 2>/dev/null & + DISPLAY=$LOCAL_DISPLAY Xephyr -ac -screen ${W}x${H}x${D} $DISPLAY 2>/dev/null & else echo "starting $XSERVER" - $XSERVER -ac -screen 0 ${W}x${H}x24 $DISPLAY 2>/dev/null & + $XSERVER -ac -screen 0 ${W}x${H}x${D} $DISPLAY 2>/dev/null & fi +if [ -z "$!" ] ; then + echo "ABORT: can't start X server!" + exit +fi XSERVER_PID=$! + echo "X server pid $XSERVER_PID" function kill_x_server() { @@ -160,15 +175,6 @@ ping_browser -$BROWSER -remote "openURL($FRAMESET)" 2>/dev/null - -echo "waiting for on_load event from browser $BROWSER_PID for ${WAIT}s" - -# there is hard-coded limit here: -# we will wait $WAIT sec for page to load and render - -echo -e "HTTP/1.0 304 Not modified\r\n\r\n" | nc -l -w $WAIT -p $PORT >/dev/null || echo "Timeout after $WAIT sec!" - # get Mozilla Firefox window id (for resize) WINDOW_ID=`xwininfo -display $DISPLAY -root -tree | grep gecko | cut -d\" -f1 | sort -n | head -1` @@ -186,6 +192,15 @@ ping_browser +$BROWSER -remote "openURL($FRAMESET)" 2>/dev/null + +echo "waiting for on_load event from browser $BROWSER_PID for ${WAIT}s" + +# there is hard-coded limit here: +# we will wait $WAIT sec for page to load and render + +echo -e "HTTP/1.0 304 Not modified\r\n\r\n" | nc -l -w $WAIT -p $PORT >/dev/null || echo "Timeout after $WAIT sec!" + # try to deduce inside area of window DUMP_ID=`xwininfo -display $DISPLAY -id $WINDOW_ID -tree | grep 0x | grep -v ${W}x${H} | grep ${W}x | head -1 | sed 's/^ *//' | cut -d' ' -f1`