void GGI_PumpEvents(_THIS)
{
	struct timeval *tvp, tv = { 0, 0 };
	ggi_event ev;

	tvp = &tv;
	
	
	while (ggiEventPoll(VIS, emAll, tvp))
	{
		int queueevent_mouse = 0, queueevent_kbd = 0;
		static int buttons = 0;
		static int mouse_x = 0, mouse_y = 0, mouse_z = 0;
		int x = 0, y = 0, z = 0, rx = 0, ry = 0, rz = 0;
		int pressed_mouse, pressed_kbd;
		SDL_keysym keysym;
		
		posted = 0;


		ggiEventRead(VIS, &ev, emAll);
		
		switch (ev.any.type)
		{
			case evPtrRelative:
			x = ev.pmove.x;
			y = ev.pmove.y;
			z = ev.pmove.wheel;
			posted += SDL_PrivateMouseMotion(0, 1, x, y);
			break;
			case evPtrAbsolute:
			if (mouse_x != ev.pmove.x || mouse_y != ev.pmove.y || mouse_z != ev.pmove.wheel)
			{
				x = ev.pmove.x - mouse_x;
				y = ev.pmove.y - mouse_y;
				z = ev.pmove.wheel - mouse_z;
				mouse_x = ev.pmove.x;
				mouse_y = ev.pmove.y;
				mouse_z = ev.pmove.wheel;
				posted += SDL_PrivateMouseMotion(0, 1, x, y);
			} 
			break;
			case evPtrButtonPress:
			posted += SDL_PrivateMouseButton(SDL_PRESSED, ev.pbutton.button, 0, 0);
			break;
			case evPtrButtonRelease:
			posted += SDL_PrivateMouseButton(SDL_RELEASED, ev.pbutton.button, 0, 0);
			break;
			case evKeyPress:
			case evKeyRepeat:
			posted += SDL_PrivateKeyboard(SDL_PRESSED, GGI_TranslateKey(&ev, &keysym));
			break;
			case evKeyRelease:
			posted += SDL_PrivateKeyboard(SDL_RELEASED, GGI_TranslateKey(&ev, &keysym));
			break;
			case evCommand:
			fprintf(stderr, "Command event %x recieved\n", ev.cmd.code);
			break;
 			default:
			fprintf(stderr, "Unhandled event type %d\n", ev.any.type);
			break;
		}
	}

}
void GGI_PumpEvents(_THIS)
{
	struct timeval *tvp, tv = { 0, 0 };
	ggi_event ev;

	tvp = &tv;
	
/*	ggiFlush(VIS); */
	
	while (ggiEventPoll(VIS, emAll, tvp))
/*	while (ggiEventPoll(VIS, (emKeyboard | emPointer | emCommand), tvp)) */
	{
		int queueevent_mouse = 0, queueevent_kbd = 0;
		static int buttons = 0;
		static int mouse_x = 0, mouse_y = 0, mouse_z = 0;
		int x = 0, y = 0, z = 0, rx = 0, ry = 0, rz = 0;
		int pressed_mouse, pressed_kbd;
		SDL_keysym keysym;
		
		posted = 0;

		/* FIXME: We do not actually want all events, only
		 * mouse and keyboard events.  Having to handle all
                 * events will slow things down.  */

		ggiEventRead(VIS, &ev, emAll);
/*		ggiEventRead(VIS, &ev, (emKeyboard | emPointer | emCommand)); */
		
		switch (ev.any.type)
		{
			case evPtrRelative:
			x = ev.pmove.x;
			y = ev.pmove.y;
			z = ev.pmove.wheel;
			posted += SDL_PrivateMouseMotion(0, 1, x, y);
			break;
			case evPtrAbsolute:
			if (mouse_x != ev.pmove.x || mouse_y != ev.pmove.y || mouse_z != ev.pmove.wheel)
			{
				x = ev.pmove.x - mouse_x;
				y = ev.pmove.y - mouse_y;
				z = ev.pmove.wheel - mouse_z;
				mouse_x = ev.pmove.x;
				mouse_y = ev.pmove.y;
				mouse_z = ev.pmove.wheel;
				posted += SDL_PrivateMouseMotion(0, 1, x, y);
			} 
			break;
			case evPtrButtonPress:
			posted += SDL_PrivateMouseButton(SDL_PRESSED, ev.pbutton.button, 0, 0);
			break;
			case evPtrButtonRelease:
			posted += SDL_PrivateMouseButton(SDL_RELEASED, ev.pbutton.button, 0, 0);
			break;
			case evKeyPress:
			case evKeyRepeat:
			posted += SDL_PrivateKeyboard(SDL_PRESSED, GGI_TranslateKey(&ev, &keysym));
			break;
			case evKeyRelease:
			posted += SDL_PrivateKeyboard(SDL_RELEASED, GGI_TranslateKey(&ev, &keysym));
			break;
			case evCommand:
			fprintf(stderr, "Command event %x recieved\n", ev.cmd.code);
			break;
 			default:
			fprintf(stderr, "Unhandled event type %d\n", ev.any.type);
			break;
		}
	}

}