twscons/twsmouse.c

121 lines
2.4 KiB
C
Raw Normal View History

2024-11-07 15:21:46 +01:00
/* wsmouse events dump */
#include <sys/ioctl.h>
2024-11-07 15:21:46 +01:00
#include <sys/time.h>
#include <dev/wscons/wsconsio.h>
#include <err.h>
2024-11-07 15:21:46 +01:00
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
void
usage(void)
{
errx(2, "usage: twsmouse [-v version]");
}
2024-11-07 15:21:46 +01:00
int
main(int argc, char *argv[])
{
int ch, fd, n, version = 0;
int type, value;
2024-11-07 15:21:46 +01:00
char *dev;
struct wscons_event event;
struct wscons_event_ex eventx;
while ((ch = getopt(argc, argv, "v:")) != -1) {
switch (ch) {
case 'v':
version = atoi(optarg);
break;
default:
usage();
}
}
argc -= optind;
argv += optind;
if (argc == 1) {
dev = argv[0];
2024-11-07 15:21:46 +01:00
} else {
dev = "/dev/wsmouse";
}
2024-11-07 15:21:46 +01:00
fd = open(dev, O_RDONLY);
if (fd < 0) {
perror("open");
exit(1);
}
if (version > 0)
if (ioctl(fd, WSKBDIO_SETVERSION, &version) == -1)
err(1, "SETVERSION %d", version);
2024-11-07 15:21:46 +01:00
while (1) {
if (version == 0)
n = read(fd, &event, sizeof(struct wscons_event));
else
n = read(fd, &eventx, sizeof(struct wscons_event_ex));
2024-11-07 15:21:46 +01:00
if (n <= 0) {
perror("read");
}
if (version == 0) {
type = event.type;
value = event.value;
} else {
type = eventx.type;
value = eventx.value;
printf("device: %#x: ", eventx.device);
}
switch (type) {
2024-11-07 15:21:46 +01:00
case WSCONS_EVENT_MOUSE_UP:
printf("MOUSE_UP: 0x%x\n", value);
2024-11-07 15:21:46 +01:00
break;
case WSCONS_EVENT_MOUSE_DOWN:
printf("MOUSE_DOWN: 0x%x\n", value);
2024-11-07 15:21:46 +01:00
break;
case WSCONS_EVENT_MOUSE_DELTA_X:
printf("MOUSE_DELTA_X: %d\n", value);
2024-11-07 15:21:46 +01:00
break;
case WSCONS_EVENT_MOUSE_DELTA_Y:
printf("MOUSE_DELTA_Y: %d\n", value);
2024-11-07 15:21:46 +01:00
break;
#ifdef WSCONS_EVENT_MOUSE_DELTA_Z
case WSCONS_EVENT_MOUSE_DELTA_Z:
printf("MOUSE_DELTA_Z: %d\n", value);
2024-11-07 15:21:46 +01:00
break;
#endif
#ifdef WSCONS_EVENT_MOUSE_ABSOLUTE_Z
case WSCONS_EVENT_MOUSE_ABSOLUTE_Z:
printf("MOUSE_ABSOLUTE_Z: %d\n", value);
2024-11-07 15:21:46 +01:00
break;
#endif
case WSCONS_EVENT_MOUSE_ABSOLUTE_X:
printf("MOUSE_ABSOLUTE_X: %d\n", value);
2024-11-07 15:21:46 +01:00
break;
case WSCONS_EVENT_MOUSE_ABSOLUTE_Y:
printf("MOUSE_ABSOLUTE_Y: %d\n", value);
break;
case WSCONS_EVENT_MOUSE_DELTA_W:
printf("MOUSE_DELTA_W: %d\n", value);
break;
case WSCONS_EVENT_MOUSE_ABSOLUTE_W:
printf("MOUSE_ABSOLUTE_W: %d\n", value);
2024-11-07 15:21:46 +01:00
break;
case WSCONS_EVENT_SYNC:
printf("SYNC\n");
break;
case WSCONS_EVENT_HSCROLL:
printf("HSCROLL: %d\n", value);
break;
case WSCONS_EVENT_VSCROLL:
printf("VSCROLL: %d\n", value);
break;
2024-11-07 15:21:46 +01:00
default:
printf("unknown event type 0x%x, value 0x%x\n",
type, value);
2024-11-07 15:21:46 +01:00
}
}
}