void handle_key(int key) {
  char result = 0;
  do {
    if (editor_state == CHAR_SELECTION)
  	  result = handle_char_selection(key);
    else if (editor_state == IDLE)
  	  result = handle_idle(key); 
  } while (result != 0);

  maybe_refresh = 1;
};
char handle_char_selection(int key) {
  if (key & CHAR_KEYS_MASK) {

  } else handle_idle(key);
};
int new_snake_window(int argc, char **argv)
{
  GR_SCREEN_INFO si;
  
  fin = 0;
  snake_count = 0;
  game_speed = start_speed;

  GrGetScreenInfo(&si); /* Get screen info */
      
  srand(time(0));
  
  game_state = SNAKE_START;

  /* Make the window */
 
  /*swindow = GrNewWindowEx(WM_PROPS, "nxsnake", GR_ROOT_WINDOW_ID, 
		       10, 10, WWIDTH, WHEIGHT, BLACK);*/
  swindow = pz_new_window (0,HEADER_TOPLINE+1,si.cols,si.rows-HEADER_TOPLINE-1,
                         do_draw,nxsnake_handle_event);
  
  GrSelectEvents(swindow, GR_EVENT_MASK_EXPOSURE | 
		 		GR_EVENT_MASK_KEY_DOWN|GR_EVENT_MASK_TIMER);

  nxsnake_timer = GrCreateTimer( swindow, 5 );
  
  offscreen = pz_new_window (0,HEADER_TOPLINE+1,si.cols,si.rows-HEADER_TOPLINE-1,
                    do_draw,nxsnake_handle_event);
                    
  //offscreen = GrNewPixmap(WWIDTH, WHEIGHT, 0);
  
  do_draw();
  GrMapWindow(swindow);
  GrMapWindow(offscreen);

  /* Draw the instructions into the buffer */
  draw_string( (char *) welcome, 1);

  while(fin != 1)
    {
      GR_EVENT event;

      /* We start at 130ms, but it goes down every */
      /* time a nibble is eaten */

      /* If they get this far, then they rock! */
      if (game_speed < 5) game_speed = 5;

      GrGetNextEventTimeout(&event, game_speed);
      
      switch(event.type)
        {
        case GR_EVENT_TYPE_EXPOSURE:
        case GR_EVENT_TYPE_KEY_DOWN:
          nxsnake_handle_event(&event);
          break;

        case GR_EVENT_TYPE_TIMER:
          handle_idle();
          break;
          
        }
    
    }
  return(1);
}