Example #1
0
File: GE.c Project: NoPublic/GIMX
/*
 * \brief Start a timer to make GE_PumpEvents return periodically.
 * 
 * \param period  the period of the timer (microseconds).
 */
void GE_TimerStart(int usec)
{
#ifndef WIN32
  int tfd = timer_start(usec);

  if(tfd >= 0)
  {
    ev_register_source(tfd, 0, &timer_read, NULL, &timer_close);
  }
#else
  timer_start(usec);
#endif
}
Example #2
0
int xinput_init()
{
  int ret = 0;
  int event, error;
  int m_num = 0;
  int k_num = 0;

  memset(devices, 0x00, sizeof(devices));
  nb_devices = 0;

  unsigned int i;
  for(i=0; i<sizeof(device_index)/sizeof(*device_index); ++i)
  {
    device_index[i] = -1;
  }

  dpy = XOpenDisplay(NULL);

  if (!dpy)
  {
    fprintf(stderr, "Failed to open display.\n");
    return -1;
  }

  if (!XQueryExtension(dpy, "XInputExtension", &xi_opcode, &event, &error))
  {
    fprintf(stderr, "X Input extension not available.\n");
    return -1;
  }

  win = create_win(dpy);

  int nxdevices;
  XIDeviceInfo *xdevices, *xdevice;

  xdevices = XIQueryDevice(dpy, XIAllDevices, &nxdevices);

  for (i = 0; nxdevices > 0 && i < (unsigned int) nxdevices; i++)
  {
      xdevice = &xdevices[i];

      if(xdevice->deviceid >= GE_MAX_DEVICES)
      {
        continue;
      }

      device_index[xdevice->deviceid] = nb_devices;

      switch(xdevice->use) {
         case XISlaveKeyboard:
           devices[nb_devices].type = DEVTYPE_KEYBOARD;
           devices[nb_devices].id = k_num;
           ++k_num;
           break;
         case XISlavePointer:
           devices[nb_devices].type = DEVTYPE_MOUSE;
           devices[nb_devices].id = m_num;
           ++m_num;
           break;
      }

      if(devices[nb_devices].type)
      {
        devices[nb_devices].name = strdup(xdevice->name);
        ++nb_devices;
      }
  }

  XIFreeDeviceInfo(xdevices);

  ev_register_source(ConnectionNumber(dpy), i, &xinput_process_events, NULL, &xinput_close);

  XEvent xevent;

  /* get info about current pointer position */
  XQueryPointer(dpy, DefaultRootWindow(dpy),
  &xevent.xbutton.root, &xevent.xbutton.window,
  &xevent.xbutton.x_root, &xevent.xbutton.y_root,
  &xevent.xbutton.x, &xevent.xbutton.y,
  &xevent.xbutton.state);

  mouse_coordinates.x = xevent.xbutton.x;
  mouse_coordinates.y = xevent.xbutton.y;

  return ret;
}
Example #3
0
File: GE.c Project: NoPublic/GIMX
/*
 * Add an event source.
 */
void GE_AddSource(int fd, int id, int (*fp_read)(int), int (*fp_write)(int), int (*fp_cleanup)(int))
{
  ev_register_source(fd, id, fp_read, fp_write, fp_cleanup);
}
Example #4
0
File: js.c Project: cqllzp/GIMX
int js_init()
{
  int ret = 0;
  int i;
  int fd;
  char joystick[sizeof("/dev/input/js255")];
  char name[1024] = {0};

  j_num = 0;
  max_joystick_id = -1;
  memset(joystick_name, 0x00, sizeof(joystick_name));
  memset(joystick_button_nb, 0x00, sizeof(joystick_button_nb));
  memset(joystick_hat_value, 0x00, sizeof(joystick_hat_value));
  memset(joystick_ax_map, 0x00, sizeof(joystick_ax_map));

  for(i=0; i<GE_MAX_DEVICES; ++i)
  {
    joystick_fd[i] = -1;
    joystick_id[i] = -1;
  }

  struct dirent **namelist;
  int n;

  n = scandir(DEV_INPUT, &namelist, is_event_device, alphasort);
  if (n >= 0)
  {
    for(i=0; i<n && !ret; ++i)
    {
      snprintf(joystick, sizeof(joystick), "%s/%s", DEV_INPUT, namelist[i]->d_name);

      fd = open (joystick, O_RDONLY | O_NONBLOCK);
      if(fd != -1)
      {
        if (ioctl(fd, JSIOCGNAME(sizeof(name) - 1), name) < 0) {
          fprintf(stderr, "ioctl EVIOCGNAME failed: %s\n", strerror(errno));
          close(fd);
          continue;
        }
        //printf("%s\n", name);
        unsigned char buttons;
        if (ioctl (fd, JSIOCGBUTTONS, &buttons) >= 0 && ioctl (fd, JSIOCGAXMAP, &joystick_ax_map[i]) >= 0)
        {
          joystick_name[i] = strdup(name);
          joystick_fd[i] = fd;
          joystick_button_nb[i] = buttons;
          max_joystick_id = i;
          joystick_id[i] = j_num;
          j_num++;
          ev_register_source(joystick_fd[i], i, &js_process_events, &js_close);
        }
        else
        {
          close(fd);
        }
      }
      else if(errno == EACCES)
      {
        fprintf(stderr, "can't open %s: %s\n", joystick, strerror(errno));
        ret = -1;
      }

      free(namelist[i]);
    }
    free(namelist);
  }
  else
  {
    fprintf(stderr, "can't scan directory %s: %s\n", DEV_INPUT, strerror(errno));
    ret = -1;
  }

  return ret;
}