/* call-seq:
 *   window.waitEvent() -> event or nil
 *
 * Wait for an event and return it.
 *
 * This function is blocking: if there's no pending event then it will wait until an event is received. After this 
 * function returns (and no error occured), the event object is always valid and filled properly. This function is 
 * typically used when you have a thread that is dedicated to events handling: you want to make this thread sleep as 
 * long as no new event is received. 
 */
static VALUE Window_WaitEvent( VALUE self )
{
        sf::Event event;
        sf::Window *window = NULL;
        Data_Get_Struct( self, sf::Window, window );
        if( window->WaitEvent( event ) == true )
        {
                VALUE rbObject = rb_funcall( globalEventClass, rb_intern( "new" ), 1, INT2FIX( event.Type ) );
                sf::Event *rubyRawEvent = NULL;
                Data_Get_Struct( rbObject, sf::Event, rubyRawEvent );
                *rubyRawEvent = event;
                return rbObject;
        }
        else
        {
                return Qnil;
        }      
}