DWORD unix_process(DWORD lparam)
{
	SDL_Event event;

	while( SDL_PollEvent(&event) ) {
		switch(event.type) {
			case SDL_ACTIVEEVENT:
				if( (event.active.state & SDL_APPACTIVE) || (event.active.state & SDL_APPINPUTFOCUS) ) {
					if (fAppActive != event.active.gain) {
						if(!Cmdline_no_unfocus_pause)
						{
							if (fAppActive)
								game_pause();
							else
								game_unpause();
						}
					}
					fAppActive = event.active.gain;
					gr_activate(fAppActive);
				}
				break;

			case SDL_KEYDOWN:
				/*if( (event.key.keysym.mod & KMOD_ALT) && (event.key.keysym.sym == SDLK_RETURN) ) {
					Gr_screen_mode_switch = 1;
					gr_activate(1);
					break;
				}*/

				if( SDLtoFS2[event.key.keysym.sym] ) {
					key_mark( SDLtoFS2[event.key.keysym.sym], 1, 0 );
				}
				break;

			case SDL_KEYUP:
				/*if( (event.key.keysym.mod & KMOD_ALT) && (event.key.keysym.sym == SDLK_RETURN) ) {
					Gr_screen_mode_switch = 0;
					break;
				}*/

				if (SDLtoFS2[event.key.keysym.sym]) {
					key_mark( SDLtoFS2[event.key.keysym.sym], 0, 0 );
				}
				break;

			case SDL_MOUSEBUTTONDOWN:
			case SDL_MOUSEBUTTONUP:
				if (event.button.button == SDL_BUTTON_LEFT)
					mouse_mark_button( MOUSE_LEFT_BUTTON, event.button.state );
				else if (event.button.button == SDL_BUTTON_MIDDLE)
					mouse_mark_button( MOUSE_MIDDLE_BUTTON, event.button.state );
				else if (event.button.button == SDL_BUTTON_RIGHT)
					mouse_mark_button( MOUSE_RIGHT_BUTTON, event.button.state );

				break;

			case SDL_JOYHATMOTION:
				joy_set_hat_state( event.jhat.value );
				break;

			case SDL_JOYBUTTONDOWN:
			case SDL_JOYBUTTONUP:
				if (event.jbutton.button < JOY_NUM_BUTTONS) {
					joy_set_button_state( event.jbutton.button, event.jbutton.state );
				}
				break;
		}
	}

	return 0;
}
DWORD unix_process2(DWORD lparam)
{
	SDL_Event event;
	while(SDL_PollEvent(&event)) {
		switch(event.type) {
		case SDL_ACTIVEEVENT:
			if (event.active.state & (SDL_APPACTIVE | SDL_APPINPUTFOCUS)) {
				mprintf(("SDL_ACTIVEEVENT (%02x, %02x) happened\n",
							event.active.state, event.active.gain));
				fAppActive = event.active.gain;
			}
			break;

		case SDL_KEYDOWN: {
      case SDL_KEYUP:
			if (event.key.keysym.scancode <= 8) {
				Assert(event.key.keysym.scancode == 0);
				break;
			}
			
			// the keycode returned by SDL seems to be 8 higher than Win32...
			byte keydata = event.key.keysym.scancode - 8;
			int latency = 0; // don't think we can get this from SDL

			int mark;
			if (event.type == SDL_KEYDOWN) {
				mprintf(("Key press detected: Scancode: %02X, keycode: %02X\n", 
							keydata, event.key.keysym.sym));
				mark = 1;
			} else {
				mprintf(("Key release detected: Scancode: %02X, keycode: %02X\n", 
							keydata, event.key.keysym.sym));
				mark = 0;
			}

			byte trans_key = sdl_key_translation[keydata];
			if (trans_key) {
				// SDL scancodes are different than Win32 in some cases...
				mprintf(("  Translating to %02x\n", trans_key));
				keydata = trans_key;
			}

			key_mark( keydata, mark, latency );
			break;
		}

		case SDL_MOUSEBUTTONDOWN:
		case SDL_MOUSEBUTTONUP:
		{
			int state = (event.button.state == SDL_PRESSED);
			uint button;
			switch (event.button.button) {
			case SDL_BUTTON_LEFT:
				mouse_mark_button(MOUSE_LEFT_BUTTON, state);
				break;
			case SDL_BUTTON_MIDDLE:
				mouse_mark_button(MOUSE_MIDDLE_BUTTON, state);
				break;
			case SDL_BUTTON_RIGHT:
				mouse_mark_button(MOUSE_RIGHT_BUTTON, state);
				break;
			}
		}
		}
	}


	  // mharris TODO
//  	  XEvent event_return;
//  	  while (true) {
//  			 XNextEvent(display, &event_return);
//  			 if (event_return.type = DestroyNotify)
//  					break;
//  	  }
	return 0;
}