static void
queryTabletPos(GLUTwindow * window)
{
#if !defined(WIN32)
  XDeviceState *state;
  XInputClass *any;
  XValuatorState *v;
  int i;

  state = XQueryDeviceState(__glutDisplay, __glutTablet);
  any = state->data;
  for (i = 0; i < state->num_classes; i++) {
    switch (any->class) {
    case ValuatorClass:
      v = (XValuatorState *) any;
      if (v->num_valuators < 2)
        goto end;
      if (window->tabletPos[0] == -1)
        window->tabletPos[0] = normalizeTabletPos(0, v->valuators[0]);
      if (window->tabletPos[1] == -1)
        window->tabletPos[1] = normalizeTabletPos(1, v->valuators[1]);
    }
    any = (XInputClass *) ((char *) any + any->length);
  }
end:
  XFreeDeviceState(state);
#endif /* !WIN32 */
}
示例#2
0
static void
queryTabletPos(GLUTwindow * window)
{
  XDeviceState *state;
  XInputClass *any;
  XValuatorState *v;
  int i;

  state = XQueryDeviceState(__glutDisplay, __glutTablet);
  any = state->data;
  for (i = 0; i < state->num_classes; i++) {
#if defined(__cplusplus) || defined(c_plusplus)
    switch (any->c_class) {
#else
    switch (any->class) {
#endif
    case ValuatorClass:
      v = (XValuatorState *) any;
      if (v->num_valuators < 2)
        goto end;
      if (window->tabletPos[0] == -1)
        window->tabletPos[0] = normalizeTabletPos(0, v->valuators[0]);
      if (window->tabletPos[1] == -1)
        window->tabletPos[1] = normalizeTabletPos(1, v->valuators[1]);
    }
    any = (XInputClass *) ((char *) any + any->length);
  }
end:
  XFreeDeviceState(state);
}

static void
tabletPosChange(GLUTwindow * window, int first, int count, int *data)
{
  int i, value, genEvent = 0;

  for (i = first; i < first + count; i++) {
    switch (i) {
    case 0:            /* X axis */
    case 1:            /* Y axis */
      value = normalizeTabletPos(i, data[i - first]);
      if (value != window->tabletPos[i]) {
        window->tabletPos[i] = value;
        genEvent = 1;
      }
      break;
    }
  }
  if (window->tabletPos[0] == -1 || window->tabletPos[1] == -1)
    queryTabletPos(window);
  if (genEvent)
    window->tabletMotion(window->tabletPos[0], window->tabletPos[1]);
}
示例#3
0
文件: state.c 项目: aosm/X11apps
int
query_state(Display	*display,
	    int		argc,
	    char	*argv[],
	    char	*name,
	    char	*desc)
{
    XDeviceInfo		*info;
    XDevice		*device;
    XDeviceState	*state;
    int			loop;
    int			loop2;
    XInputClass		*cls;
    XValuatorState	*val_state;
    XKeyState		*key_state;
    XButtonState	*but_state;

    if (argc != 1) {
	fprintf(stderr, "usage: xinput %s %s\n", name, desc);
	return 1;
    }

    info = find_device_info(display, argv[0], True);

    if (!info) {
	fprintf(stderr, "unable to find device %s\n", argv[0]);
	return 1;
    }

    device = XOpenDevice(display, info->id);

    if (!device) {
	fprintf(stderr, "unable to open device %s\n", argv[0]);
	return 1;
    }

    state = XQueryDeviceState(display, device);

    if (state) {
        cls = state->data;
	printf("%d class%s :\n", state->num_classes,
	       (state->num_classes > 1) ? "es" : "");
	for(loop=0; loop<state->num_classes; loop++) {
	  switch(cls->class) {
	  case ValuatorClass:
	    val_state = (XValuatorState *) cls;
	    printf("ValuatorClass Mode=%s Proximity=%s\n",
		   val_state->mode & 1 ? "Absolute" : "Relative",
		   val_state->mode & 2 ? "Out" : "In");
	    for(loop2=0; loop2<val_state->num_valuators; loop2++) {
	      printf("\tvaluator[%d]=%d\n", loop2, val_state->valuators[loop2]);
	    }
	    break;

	  case ButtonClass:
	    but_state = (XButtonState *) cls;
	    printf("ButtonClass\n");
	    for(loop2=1; loop2<=but_state->num_buttons; loop2++) {
	      printf("\tbutton[%d]=%s\n", loop2,
		     (but_state->buttons[loop2 / 8] & (1 << (loop2 % 8))) ? "down" : "up" );
	    }
	    break;

	  case KeyClass:
	    key_state = (XKeyState *) cls;
	    printf("KeyClass\n");
	    for(loop2=0; loop2<key_state->num_keys; loop2++) {
	      printf("\tkey[%d]=%s\n", loop2,
		     (key_state->keys[loop2 / 8] & (1 << (loop2 % 8))) ? "down" : "up" );
	    }

	    break;

	  }
	  cls = (XInputClass *) ((char *) cls + cls->length);
	}
	XFreeDeviceState(state);
    }
    return EXIT_SUCCESS;
}