Beispiel #1
0
/* Enter SIZE bytes from the buffer BUF into the virtual console
   VCONS.  */
error_t
cons_vcons_input (vcons_t vcons, char *buf, size_t size)
{
  pthread_mutex_lock (&vcons->lock);

  _cons_vcons_console_event (vcons, CONS_EVT_KEYPRESS);
  
  if (vcons->scrolling && _cons_jump_down_on_input)
    _cons_vcons_scrollback (vcons, CONS_SCROLL_ABSOLUTE_LINE, 0);

  _cons_vcons_input (vcons, buf, size);

  pthread_mutex_unlock (&vcons->lock);
  return 0;
}
error_t
cons_vcons_move_mouse (vcons_t vcons, mouse_event_t ev)
{
  char event[CONS_MOUSE_EVENT_LENGTH];
  uint32_t report_events;
  
  mutex_lock (&vcons->lock);
  report_events = vcons->display->flags & CONS_FLAGS_TRACK_MOUSE;
  
  switch (ev->mouse_movement)
    {
    case CONS_VCONS_MOUSE_MOVE_REL:
      mousepos_x += ((float) ev->x / _cons_mouse_sens);
      mousepos_y += ((float) ev->y / _cons_mouse_sens);
      break;

    case CONS_VCONS_MOUSE_MOVE_ABS_PERCENT:
      mousepos_x = vcons->state.screen.width * ev->x / 100;
      mousepos_y = vcons->state.screen.height * ev->y / 100;
      
    case CONS_VCONS_MOUSE_MOVE_ABS:
      mousepos_x = ev->x;
      mousepos_y = ev->y;
      break;
    }

  /* Keep the mouse cursor in range of the VC.  */
  if (mousepos_x < 0)
    mousepos_x = 0;
  if (mousepos_y < 0)
    mousepos_y = 0;
  if (mousepos_x >= (float) vcons->state.screen.width)
    mousepos_x = vcons->state.screen.width - 1;
  if (mousepos_y >= (float) vcons->state.screen.height)
    mousepos_y = vcons->state.screen.height - 1;
  
  cons_vcons_set_mousecursor_pos (vcons, (float) mousepos_x, (float) mousepos_y);
  
  /* Report a mouse movement event.  */
  if (ev->x || ev->y)
    _cons_vcons_console_event (vcons, CONS_EVT_MOUSE_MOVE);
  
  /* Report a mouse button event.  */
  if (ev->mouse_button != CONS_VCONS_MOUSE_BUTTON_NO_OP)
    _cons_vcons_console_event (vcons, CONS_EVT_MOUSE_BUTTON);
  
  if (report_events)
    {
      switch (ev->mouse_button)
	{
	case CONS_VCONS_MOUSE_BUTTON_NO_OP:
	  break;

	case CONS_VCONS_MOUSE_BUTTON_PRESSED:
	  /* Make an xterm like event string.  */
	  CONS_MOUSE_EVENT (event, ev->button, (int) mousepos_x + 1, (int) mousepos_y + 1);

	  _cons_vcons_input (vcons, event, CONS_MOUSE_EVENT_LENGTH);
	  /* And send it to the server.  */
	  break;

	case CONS_VCONS_MOUSE_BUTTON_RELEASED:
	  /* Make an xterm like event string.  */
	  CONS_MOUSE_EVENT (event, CONS_MOUSE_RELEASE, (int) mousepos_x + 1, (int) mousepos_y + 1);

	  /* And send it to the server.  */
	  _cons_vcons_input (vcons,  event, CONS_MOUSE_EVENT_LENGTH);
	  break;
	}
    }
  
  mutex_unlock (&vcons->lock);
  return 0;
}