Пример #1
0
void event_poll(Uint32 mask)
{
	SDL_Event event;
#if TO_EVENT_POLL
	time_t t0 = SDL_GetTicks ();
	time_t _t = t0;
#endif

/*
	if (!mask)
		mask = SDL_ALLEVENTS;
	else
		mask |= SDL_ACTIVEEVENTMASK | SDL_QUITMASK | SDL_SYSWMEVENTMASK;
	while (PollEvent(&event, mask)) {
*/
	while (SDL_PollEvent (&event)) {
#if TO_EVENT_POLL
		if (!gameOpts->legacy.bInput)
			_t = SDL_GetTicks ();
#endif
		switch(event.type) {
			case SDL_KEYDOWN:
				key_handler((SDL_KeyboardEvent *)&event);
				break;
			case SDL_KEYUP:
				key_handler((SDL_KeyboardEvent *)&event);
				break;
			case SDL_MOUSEBUTTONDOWN:
			case SDL_MOUSEBUTTONUP:
				mouse_button_handler((SDL_MouseButtonEvent *)&event);
				break;
			case SDL_MOUSEMOTION:
				mouse_motion_handler((SDL_MouseMotionEvent *)&event);
				break;
#ifndef USE_LINUX_JOY       // stpohle - so we can choose at compile time..
			case SDL_JOYBUTTONDOWN:
			case SDL_JOYBUTTONUP:
				joy_button_handler((SDL_JoyButtonEvent *)&event);
				break;
			case SDL_JOYAXISMOTION:
				joy_axis_handler((SDL_JoyAxisEvent *)&event);
				break;
			case SDL_JOYHATMOTION:
				joy_hat_handler((SDL_JoyHatEvent *)&event);
				break;
			case SDL_JOYBALLMOTION:
				break;
#endif
			case SDL_QUIT: {
				quit_request();
			} break;
		}
#if TO_EVENT_POLL
	if (!gameOpts->legacy.bInput && (_t - t0 >= TO_EVENT_POLL))
		break;
#endif
	}
}
Пример #2
0
void handle_updown(void) {
  int key = scan_keyboard();
  if (updown_state == DOWN_CHECK_START) {
    if (key >= 0) {
      pressed_key = key;
      updown_state = DOWN_CHECK_END;
      updown_ocr = TICKS_TILL_SURE;
    } else {
      updown_state = IDLE;
      return ;
    }
  } else if (updown_state == DOWN_CHECK_END) {
    if (key >= 0 && key == pressed_key) {
      key_handler(pressed_key);
      if (repeat_key & 1 << pressed_key) {
        repeater_state = REPEAT_CHECK_START;
        repeater_counter = 0;
        repeater_ocr = TICKS_TILL_REPEAT;
      }
      updown_state = UP_CHECK_START;
      updown_ocr = TICKS_PER_UP_CHECK;
    } else {
      updown_state = IDLE;
    }
  } else if (updown_state == UP_CHECK_START) {
    if (key == -1) {
      updown_state = UP_CHECK_END;
      updown_ocr = TICKS_TILL_SURE;
    } else {
      updown_state = UP_CHECK_START;
      updown_ocr = TICKS_PER_UP_CHECK;
    }
  } else if(updown_state == UP_CHECK_END) {
    if (key == -1) {
      key_handler(KEYBOARD_KEYUP);
      pressed_key = -1;
      repeater_state = IDLE;
      updown_state = LONG_PAUSE_CHECK;
      updown_ocr = TICKS_TILL_LONG_PAUSE;
    } else {
      updown_state = UP_CHECK_START;
      updown_ocr = TICKS_PER_UP_CHECK;
    }
  } else if(updown_state == LONG_PAUSE_CHECK) {
    key_handler(KEYBOARD_KEYLONGPAUSE);
    updown_state = IDLE;
    set_sleep_mode(SLEEP_MODE_STANDBY);
  }
};
Пример #3
0
int main(int argc, char const *argv[]) {
    double moveback[4][4];
    double distance;
    for (int i=1; i<argc; i++) {
        FILE* f = fopen(argv[i], "r");
        read_object3d_from_file(f, &objs[i-1]);

        obj = &objs[i-1];
        //move the object backwards so that it doesn't intersect with the view
        distance = max(obj->zs, obj->n)+10;
        printf("initial distance is %f\n", distance);
        D3d_make_identity(moveback);
        D3d_translate(moveback, useless, 0, 0, -distance);
        //scale the object to fit the view
        double max_dim = 10;
        double m = max(obj->xs, obj->n);
        if (m > max_dim) max_dim = m;
        m = max(obj->ys, obj->n);
        if (m > max_dim) max_dim = m;
        printf("max dimension is %f\n", max_dim);
        //D3d_scale(moveback, useless, .1, .1, .1);
        transform_object3d(obj, moveback);
    }
    num_objs = argc-1;
    setup_matrices();


    fov = M_PI/8.0;
    G_init_graphics(600, 600);

    key_handler();
    return 0;
}
Пример #4
0
void KISR(void) {
  byte ptp = PTP, ptt = PTT, pts = PTS & 0x80;
  byte row;
  
  CLRMSK(PTS, 0x80);
  
  // Ensure we don't update the seven-segment display.
  PTT = 0;

  /* Ensure that the ports are primed to receive keypresses. */
  SETMSK(DDRP, 0x0F); /* Set row polling bits (PTP0..3) as outputs. */
  CLRMSK(DDRH, 0xF0); /* Set column bits (PTH4..7) as inputs. */
  SPI1CR1 = 0;        /* Disable the serial interface. */
  
  /* Probe all of the rows. */
  for (row = 0; row < ROWS; row++) {
    byte col, col_mask;

	SETMSK(PTM, 0x08); /* Pass through the latch to the keypad. */
    PTP = 0x01 << row; /* Query the current keypad row. */
    CLRMSK(PTM, 0x08); /* Re-enable latching on keypad. */

    col_mask = PTH;    /* Copy the polling result. */

    /* Test all of the columns in the row. */
    for (col = 0; col < COLS; col++) {
      byte table_index = row * ROWS + col;
      boolean is_pressed = col_mask & (0x10 << col);

      /* Check if the given column is _newly_ set. */
      if (is_pressed) {
        keypad_handler_t key_handler = keypad_handlers[table_index];

        /* Additional requirement: Display the character entered. */
        putchar(keypad_characters[table_index]);
		
        /* Execute the key handler, if one is present. */
        if (key_handler != NULL) key_handler();
      }
    }
  }
  
  SETMSK(PTM, 0x08);
  PTP = 0x0F;  // Restore scan row(s)
  CLRMSK(PTM, 0x08);
  
  PTP = ptp;   // Restore the value on Port P.  
  PTT = ptt;
  PIFH = PIFH;
  
  SETMSK(PTS, pts);
}
Пример #5
0
void renderLoop( projectM_t *pm, short pcm_data[2][512] ) {

    int i;
    int x, y;
    int index;

    /** Handle any keys... */
    projectMEvent evt;
    projectMKeycode key;
    projectMModifier mod;

    /** Process SDL events */
    SDL_Event event;
    while ( SDL_PollEvent( &event ) ) {
        /** Translate into projectM codes and process */
        evt = sdl2pmEvent( event );
        key = sdl2pmKeycode( event.key.keysym.sym );
        mod = sdl2pmModifier( event.key.keysym.mod );
        if ( evt == PROJECTM_KEYDOWN ) {
            key_handler( evt, key, mod );
          }
      }

    /** Add the waveform data */
    addPCM16( pcm_data );

    /** Render the new frame */
    renderFrame( pm );

    if ( dumpFrame ) {
        char fname[1024];
        FILE *f;
        sprintf( fname, "projectM_%08d.ppm", frameNumber++ );
        f = fopen( fname, "wb" );
        fprintf( f, "P3\n#\n%d %d\n255\n", pm->wvw, pm->wvh );
        glReadPixels( 0, 0, pm->wvw, pm->wvh, GL_RGB, GL_UNSIGNED_BYTE, fbuffer );
        index = 0;
        for ( y = 0 ; y < pm->wvh ; y++ ) {
            for ( x = 0 ; x < pm->wvw ; x++ ) {
                fprintf( f, "%d %d %d ", fbuffer[index++], fbuffer[index++], fbuffer[index++] );
              }
            fprintf( f, "\n" );
          }
        fclose( f );
      }

    SDL_GL_SwapBuffers();
	
  }
Пример #6
0
int
main(int argc, char **argv)
{

// load in the mesh

	MT_Vector3 mesh_min,mesh_max;

	LOD_Decimation_InfoPtr LOD_info = NewVertsFromFile("beethoven.ply",mesh_min,mesh_max);

	// load the mesh data 

	int load_result = LOD_LoadMesh(LOD_info);
	int preprocess_result = LOD_PreprocessMesh(LOD_info);

	if (!(load_result && preprocess_result)) {
		cout << " could not load mesh! \n";
		return 0;
	}

	// make and install a mouse handler

	MEM_SmartPtr<MyGlutMouseHandler> mouse_handler(MyGlutMouseHandler::New());
	GlutMouseManager::Instance()->InstallHandler(mouse_handler);

	// instantiate the drawing class	

	MEM_SmartPtr<GlutMeshDrawer> drawer(GlutMeshDrawer::New());
	GlutDrawManager::Instance()->InstallDrawer(drawer);
	drawer->SetLODInfo(LOD_info);	
	drawer->SetMouseHandler(mouse_handler);

	// make and install a keyhandler

	MEM_SmartPtr<MyGlutKeyHandler> key_handler(MyGlutKeyHandler::New(LOD_info));
	GlutKeyboardManager::Instance()->InstallHandler(key_handler);


	LOD_GhostTestApp LOD_app;

	LOD_app.InitApp();
	init(mesh_min,mesh_max);

	LOD_app.Run();


	return 0;             /* ANSI C requires main to return int. */
}
Пример #7
0
void Game::event_handler(const SDL_Event& event)
{
    switch (event.type)
    {
        case SDL_QUIT:
        {
            Program::stop();
            break;
        }
        case SDL_KEYDOWN:
            key_handler(event.key);
            break;
        case SDL_MOUSEBUTTONUP:
            if (m_window.stats_button_clicked(event.button))
                show_stats();
            break;
    }
}
Пример #8
0
void handle_repeater(void) {
  int key = scan_keyboard();
  if (key == pressed_key) {
    // key pressed
    if (repeater_state == REPEAT_CHECK_START) {
      // wait till sure
      repeater_state = REPEAT_CHECK_END;
      repeater_ocr = TICKS_TILL_SURE;
    } else {
      key_handler(pressed_key);
      //PORTA ^= 1 << PA2;
      repeater_state = REPEAT_CHECK_START;
      repeater_ocr = TICKS_TILL_REPEAT;
    }
  } else {
    // bad key pressed, abort repeating
    repeater_state = IDLE;
  }
};
Пример #9
0
void EXTI9_5_IRQHandler(void)
{
    uint32_t key_flag = 0;

    if(EXTI_GetITStatus(EXTI_Line5) == SET)
    {
        EXTI_ClearITPendingBit(EXTI_Line5);
    }

    if(EXTI_GetITStatus(EXTI_Line6) == SET)
    {
        extern void ra8875_nwait_isr(void);

        EXTI_ClearITPendingBit(EXTI_Line6);
        ra8875_nwait_isr();
    }

    if(EXTI_GetITStatus(EXTI_Line7) == SET)
    {
        EXTI_ClearITPendingBit(EXTI_Line7);
        key_flag = 1;
    }

    if(EXTI_GetITStatus(EXTI_Line8) == SET)
    {
        EXTI_ClearITPendingBit(EXTI_Line8);
        key_flag = 1;
    }

    if(EXTI_GetITStatus(EXTI_Line9) == SET)
    {
        EXTI_ClearITPendingBit(EXTI_Line9);
        key_flag = 1;
    }

    if(key_flag)
    {
        key_handler();
    }
}
Пример #10
0
int
main(int argc, char **argv)
{


	const int seg_num = 5;
	const MT_Scalar seg_length = 15;

	const float seg_startA[3] = {0,0,0};
	const float seg_startB[3] = {0,-20,0};

	// create some segments to solve with

	// First chain
	//////////////


	IK_Segment_ExternPtr const segmentsA = new IK_Segment_Extern[seg_num]; 	
	IK_Segment_ExternPtr const segmentsB = new IK_Segment_Extern[seg_num]; 	

	IK_Segment_ExternPtr seg_it = segmentsA; 	
	IK_Segment_ExternPtr seg_itB = segmentsB; 	

	
	{

//		MT_Quaternion qmat(MT_Vector3(0,0,1),-3.141/2);
		MT_Quaternion qmat(MT_Vector3(0,0,1),0);
		MT_Matrix3x3 mat(qmat);

		seg_it->seg_start[0] = seg_startA[0];
		seg_it->seg_start[1] = seg_startA[1];
		seg_it->seg_start[2] = seg_startA[2];

		float temp[12];
		mat.getValue(temp);
 
		seg_it->basis[0] = temp[0];
		seg_it->basis[1] = temp[1];
		seg_it->basis[2] = temp[2];

		seg_it->basis[3] = temp[4];
		seg_it->basis[4] = temp[5];
		seg_it->basis[5] = temp[6];

		seg_it->basis[6] = temp[8];
		seg_it->basis[7] = temp[9];
		seg_it->basis[8] = temp[10];
 
		seg_it->length = seg_length;

		MT_Quaternion q;
		q.setEuler(0,0,0);

			
		MT_Matrix3x3 qrot(q);

		seg_it->basis_change[0] = 1;
		seg_it->basis_change[1] = 0;
		seg_it->basis_change[2] = 0;
		seg_it->basis_change[3] = 0;
		seg_it->basis_change[4] = 1;
		seg_it->basis_change[5] = 0;
		seg_it->basis_change[6] = 0;
		seg_it->basis_change[7] = 0;
		seg_it->basis_change[8] = 1;


		seg_it ++;			

		seg_itB->seg_start[0] = seg_startA[0];
		seg_itB->seg_start[1] = seg_startA[1];
		seg_itB->seg_start[2] = seg_startA[2];
 
		seg_itB->basis[0] = temp[0];
		seg_itB->basis[1] = temp[1];
		seg_itB->basis[2] = temp[2];

		seg_itB->basis[3] = temp[4];
		seg_itB->basis[4] = temp[5];
		seg_itB->basis[5] = temp[6];

		seg_itB->basis[6] = temp[8];
		seg_itB->basis[7] = temp[9];
		seg_itB->basis[8] = temp[10];
 
		seg_itB->length = seg_length;

		seg_itB->basis_change[0] = 1;
		seg_itB->basis_change[1] = 0;
		seg_itB->basis_change[2] = 0;
		seg_itB->basis_change[3] = 0;
		seg_itB->basis_change[4] = 1;
		seg_itB->basis_change[5] = 0;
		seg_itB->basis_change[6] = 0;
		seg_itB->basis_change[7] = 0;
		seg_itB->basis_change[8] = 1;


		seg_itB ++;			


	}


	int i;
	for (i=1; i < seg_num; ++i, ++seg_it,++seg_itB) {

		MT_Quaternion qmat(MT_Vector3(0,0,1),0.3);
		MT_Matrix3x3 mat(qmat);

		seg_it->seg_start[0] = 0;
		seg_it->seg_start[1] = 0;
		seg_it->seg_start[2] = 0;

		float temp[12];
		mat.getValue(temp);
 
		seg_it->basis[0] = temp[0];
		seg_it->basis[1] = temp[1];
		seg_it->basis[2] = temp[2];

		seg_it->basis[3] = temp[4];
		seg_it->basis[4] = temp[5];
		seg_it->basis[5] = temp[6];

		seg_it->basis[6] = temp[8];
		seg_it->basis[7] = temp[9];
		seg_it->basis[8] = temp[10];
 
		seg_it->length = seg_length;

		MT_Quaternion q;
		q.setEuler(0,0,0);

			
		MT_Matrix3x3 qrot(q);

		seg_it->basis_change[0] = 1;
		seg_it->basis_change[1] = 0;
		seg_it->basis_change[2] = 0;
		seg_it->basis_change[3] = 0;
		seg_it->basis_change[4] = 1;
		seg_it->basis_change[5] = 0;
		seg_it->basis_change[6] = 0;
		seg_it->basis_change[7] = 0;
		seg_it->basis_change[8] = 1;


		///////////////////////////////

		seg_itB->seg_start[0] = 0;
		seg_itB->seg_start[1] = 0;
		seg_itB->seg_start[2] = 0;
 
		seg_itB->basis[0] = temp[0];
		seg_itB->basis[1] = temp[1];
		seg_itB->basis[2] = temp[2];

		seg_itB->basis[3] = temp[4];
		seg_itB->basis[4] = temp[5];
		seg_itB->basis[5] = temp[6];

		seg_itB->basis[6] = temp[8];
		seg_itB->basis[7] = temp[9];
		seg_itB->basis[8] = temp[10];
 
		seg_itB->length = seg_length;

		seg_itB->basis_change[0] = 1;
		seg_itB->basis_change[1] = 0;
		seg_itB->basis_change[2] = 0;
		seg_itB->basis_change[3] = 0;
		seg_itB->basis_change[4] = 1;
		seg_itB->basis_change[5] = 0;
		seg_itB->basis_change[6] = 0;
		seg_itB->basis_change[7] = 0;
		seg_itB->basis_change[8] = 1;



	}

	// create the chains

	const int num_chains = 2;

	IK_Chain_ExternPtr chains[num_chains];

	chains[0] = IK_CreateChain();
	chains[1] = IK_CreateChain();

	// load segments into chain

	IK_LoadChain(chains[0],segmentsA,seg_num);
	IK_LoadChain(chains[1],segmentsB,seg_num);

	// make and install a mouse handler

	MEM_SmartPtr<MyGlutMouseHandler> mouse_handler (MyGlutMouseHandler::New());
	GlutMouseManager::Instance()->InstallHandler(mouse_handler);

	mouse_handler->SetChain(chains,num_chains);

	// make and install a keyhandler
	MEM_SmartPtr<MyGlutKeyHandler> key_handler (MyGlutKeyHandler::New());
	GlutKeyboardManager::Instance()->InstallHandler(key_handler);

	// instantiate the drawing class	

	MEM_SmartPtr<ChainDrawer> drawer (ChainDrawer::New());
	GlutDrawManager::Instance()->InstallDrawer(drawer);

	drawer->SetMouseHandler(mouse_handler);
	drawer->SetChain(chains,num_chains);
	drawer->SetKeyHandler(key_handler);

	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
	glutCreateWindow("ik");
	glutDisplayFunc(GlutDrawManager::Draw);
	glutMouseFunc(GlutMouseManager::Mouse);
	glutMotionFunc(GlutMouseManager::Motion);
	glutKeyboardFunc(GlutKeyboardManager::HandleKeyboard);

	init(MT_Vector3(-50,-50,-50),MT_Vector3(50,50,50));
	glutMainLoop();
	return 0;             /* ANSI C requires main to return int. */
}
Пример #11
0
void KISR(void) {
  byte ptp, ptt, pts;
  byte row;
  
  ptp = PTP;
  ptt = PTT;
  pts = PTS & 0x80;
  
  CLRMSK(PTS, 0x80);
  
  // Ensure we don't update the seven-segment display.
  PTT = 0;

  /* Ensure that the ports are primed to receive keypresses. */
  SETMSK(DDRP, 0x0F); /* Set row polling bits (PTP0..3) as outputs. */
  CLRMSK(DDRH, 0xF0); /* Set column bits (PTH4..7) as inputs. */
  SPI1CR1 = 0;        /* Disable the serial interface. */
  
  /* Probe all of the rows. */
  for (row = 0; row < ROWS; row++) {
    byte col, col_mask;

	SETMSK(PTM, 0x08); /* Pass through the latch to the keypad. */
    PTP = 0x01 << row; /* Query the current keypad row. */
    CLRMSK(PTM, 0x08); /* Re-enable latching on keypad. */

    col_mask = PTH;    /* Copy the polling result. */

    /* Test all of the columns in the row. */
    for (col = 0; col < COLS; col++) {
      byte table_index = row * ROWS + col;
      boolean is_pressed = col_mask & (0x10 << col);

      /* Check if the given column is _newly_ set. */
      if (is_pressed) {
	    char character = keypad_characters[table_index];
		void (*key_handler)(char) = state_handlers[state].key_pressed;

        /* Return to the main view if 'E' is pressed. */
        if (character == 'E') {
		  state = VIEW_CLOCK; // Return to the main view.
		  continue;           // Don't allow this to fall through into key handlers.
		} else if (character == 'F') { // Global alarm disable.
		  disable_all_alarms();
		  continue;
		}
		  
        /* Execute the key handler, if one is present. */
        if (key_handler != NULL) key_handler(character);
      }
    }
  }
  
  SETMSK(PTM, 0x08);
  PTP = 0x0F;  // Restore scan row(s)
  CLRMSK(PTM, 0x08);
  
  PTP = ptp;   // Restore the value on Port P.  
  PTT = ptt;
  PIFH = PIFH;
  
  SETMSK(PTS, pts);
}
Пример #12
0
/*
MAIN
Envoyer et recevoir des donnes
Gere les fenetres du GUI
*/
int main (int argc, char* argv[]) {

	if ( argc < 2 ) {
		printf ("Usage: %s PORT\n", argv[0]);
		exit (EXIT_FAILURE);
	}

	initscr();	// Start curses mode
	cbreak();	// Line buffering disabled, Pass on everty thing to me

	//my_win = create_newwin(height, width, starty, startx);
	f_haut	= definirFenetre( f_haut_hauteur, COLS, 0, 0 );
	f_bas	= definirFenetre( f_bas_hauteur, COLS, (LINES - f_bas_hauteur - marge_bas), 0 );
	f_info	= definirFenetre( f_info_hauteur, COLS, (LINES - donnerHauteur(f_bas) - f_info_hauteur - marge_bas), 0 );
	f_cmd 	= definirFenetre( f_cmd_hauteur, COLS, (LINES - donnerHauteur(f_bas) - donnerHauteur(f_info) - marge_bas - f_cmd_hauteur), 0);
	f_chat	= definirFenetre( (LINES - donnerHauteur(f_haut) - donnerHauteur(f_cmd) - donnerHauteur(f_info) - donnerHauteur(f_bas) - marge_bas), COLS, donnerHauteur(f_haut), 0 );

	refresh();
	w_haut	= create_newwin_with_border( f_haut );
	w_bas	= create_newwin_no_border( f_bas );
	w_info	= create_newwin_with_border( f_info );
	w_cmd	= create_newwin_with_border( f_cmd );
	w_chat	= create_newwin_no_border( f_chat );

	scrollok( w_chat, 1 );
	wsetscrreg( w_chat, donnerStarty(f_chat), donnerHauteur(f_chat) );
	wtimeout(w_bas, 500);

	mvwprintw(w_haut, 1, 1, "CHAT CLIENT");
	mvwprintw(w_cmd, 1, 1, "");
	mvwprintw(w_info, 1, 1, "/nom usager\t/mp usager msg\t/creer   groupe type\t/info  groupe\t\t/accept  usager groupe");
	mvwprintw(w_info, 2, 1, "\t\t/mg groupe msg\t/joindre groupe\t\t/liste usagers\t\t/refuser usager groupe");
	mvwprintw(w_info, 3, 1, "/quitter\t\t\t/byebye  groupe\t\t/liste groupes\t\t/stats   groupe");
	wmove( w_bas, 0, 0 );
	wrefresh(w_haut);
	wrefresh(w_info);
	wrefresh(w_bas);
	wrefresh(w_cmd);

	
	struct sockaddr_in	serveur;
	struct hostent*		hp;

	socket_d = socket (AF_INET, SOCK_STREAM, 0);
	if (socket_d < 0) {
		endwin();
		printf("Erreur lors de la création de la socket !\n");
		return 1;
	}
	setnonblocking (socket_d);

	hp = gethostbyname("localhost");
	if (hp==0) {
		endwin();
		close (socket_d);
		printf("Hôte inconnu!\n");
		return 2;
	}

	serveur.sin_family = AF_INET;
	serveur.sin_port = htons(atoi(argv[1]));
	bcopy((char *)hp->h_addr, (char *)&serveur.sin_addr, hp->h_length);

	if ( connect(socket_d,(struct sockaddr *)&serveur,sizeof(struct sockaddr_in)) < 0 ) {
		endwin();
		close (socket_d);
		printf("Erreur lors de la création d'une nouvelle connexion !\n");
		return 3;
	}


	nom_usager_defini = 0;

	input = chaineCreerVide( COLS );
	while ( 1 ) {
		key_handler();

		if ( ! recv_handler() )
			break;
	}	

	endwin ();
	close (socket_d);
	return 0;
}
Пример #13
0
void event_poll()
{
    SDL_Event event;
    int clean_uniframe=1;
    window *wind = window_get_front();
    int idle = 1;

    // If the front window changes, exit this loop, otherwise unintended behavior can occur
    // like pressing 'Return' really fast at 'Difficulty Level' causing multiple games to be started
    while ((wind == window_get_front()) && SDL_PollEvent(&event))
    {
        switch(event.type) {
        case SDL_KEYDOWN:
        case SDL_KEYUP:
            if (clean_uniframe)
                memset(unicode_frame_buffer,'\0',sizeof(unsigned char)*KEY_BUFFER_SIZE);
            clean_uniframe=0;
            key_handler((SDL_KeyboardEvent *)&event);
            idle = 0;
            break;
        case SDL_MOUSEBUTTONDOWN:
        case SDL_MOUSEBUTTONUP:
            mouse_button_handler((SDL_MouseButtonEvent *)&event);
            idle = 0;
            break;
        case SDL_MOUSEMOTION:
            mouse_motion_handler((SDL_MouseMotionEvent *)&event);
            idle = 0;
            break;
        case SDL_JOYBUTTONDOWN:
        case SDL_JOYBUTTONUP:
            joy_button_handler((SDL_JoyButtonEvent *)&event);
            idle = 0;
            break;
        case SDL_JOYAXISMOTION:
            if (joy_axis_handler((SDL_JoyAxisEvent *)&event))
                idle = 0;
            break;
        case SDL_JOYHATMOTION:
            joy_hat_handler((SDL_JoyHatEvent *)&event);
            idle = 0;
            break;
        case SDL_JOYBALLMOTION:
            break;
        case SDL_QUIT: {
            d_event qevent = { EVENT_QUIT };
            call_default_handler(&qevent);
            idle = 0;
        }
        break;
        }
    }

    // Send the idle event if there were no other events
    if (idle)
    {
        d_event ievent;

        ievent.type = EVENT_IDLE;
        event_send(&ievent);
    }
    else
        event_reset_idle_seconds();

    mouse_cursor_autohide();
}