twsmouse: add event version handling

While there, decode some more possible event types.
This commit is contained in:
Matthieu Herrb 2024-11-07 16:42:31 +01:00
parent 5d7f9487c1
commit 570d394d26

View file

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