diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2020-01-31 18:03:01 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2020-01-31 10:40:49 +0000 |
commit | 0a2bbdf6e74b7d11e49b8ed69890818406c810d5 (patch) | |
tree | f0532ce7e82b5050d932473b58c4dc8a48af0f58 | |
parent | 2059a015ae099cdd6a0a2f1ca5560fbccc6fa4b0 (diff) |
tools: record: record the EV_ABS deltas along with the absolute value
It's useful to have this in the immediate recording. Example output now:
- evdev:
- [ 2, 300309, 3, 47, 0] # EV_ABS / ABS_MT_SLOT 0
- [ 2, 300309, 3, 54, 3547] # EV_ABS / ABS_MT_POSITION_Y 3547 (+8)
- [ 2, 300309, 3, 58, 70] # EV_ABS / ABS_MT_PRESSURE 70 (-14)
- [ 2, 300309, 3, 47, 1] # EV_ABS / ABS_MT_SLOT 1
- [ 2, 300309, 3, 54, 3112] # EV_ABS / ABS_MT_POSITION_Y 3112 (+4)
- [ 2, 300309, 3, 58, 68] # EV_ABS / ABS_MT_PRESSURE 68 (-4)
- [ 2, 300309, 3, 1, 3547] # EV_ABS / ABS_Y 3547 (+8)
- [ 2, 300309, 3, 24, 70] # EV_ABS / ABS_PRESSURE 70 (-14)
- [ 2, 300309, 0, 0, 0] # ------------ SYN_REPORT (0) ---------- +49ms
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
-rw-r--r-- | tools/libinput-record.c | 95 |
1 files changed, 90 insertions, 5 deletions
diff --git a/tools/libinput-record.c b/tools/libinput-record.c index 04f6ccc1..ed346b24 100644 --- a/tools/libinput-record.c +++ b/tools/libinput-record.c @@ -81,6 +81,8 @@ struct record_device { struct list link; char *devnode; /* device node of the source device */ struct libevdev *evdev; + struct libevdev *evdev_prev; /* previous value, used for EV_ABS + deltas */ struct libinput_device *device; struct event *events; @@ -201,9 +203,11 @@ time_offset(struct record_context *ctx, uint64_t time) } static inline void -print_evdev_event(struct record_context *ctx, struct input_event *ev) +print_evdev_event(struct record_context *ctx, + struct record_device *dev, + struct input_event *ev) { - const char *cname; + const char *tname, *cname; bool was_modified = false; char desc[1024]; uint64_t time = input_event_time(ev) - ctx->offset; @@ -214,6 +218,7 @@ print_evdev_event(struct record_context *ctx, struct input_event *ev) if (!ctx->show_keycodes) was_modified = obfuscate_keycode(ev); + tname = libevdev_event_type_get_name(ev->type); cname = libevdev_event_code_get_name(ev->type, ev->code); if (ev->type == EV_SYN && ev->code == SYN_MT_REPORT) { @@ -236,9 +241,87 @@ print_evdev_event(struct record_context *ctx, struct input_event *ev) cname, ev->value, dt); - } else { - const char *tname = libevdev_event_type_get_name(ev->type); + } else if (ev->type == EV_ABS) { + int oldval = 0; + enum { DELTA, SLOT_DELTA, NO_DELTA } want = DELTA; + int delta = 0; + + /* We want to print deltas for abs axes but there are a few + * that we don't care about for actual deltas because + * they're meaningless. + * + * Also, any slotted axis needs to be printed per slot + */ + switch (ev->code) { + case ABS_MT_SLOT: + libevdev_set_event_value(dev->evdev_prev, + ev->type, + ev->code, + ev->value); + want = NO_DELTA; + break; + case ABS_MT_TRACKING_ID: + case ABS_MT_BLOB_ID: + want = NO_DELTA; + break; + case ABS_MT_TOUCH_MAJOR ... ABS_MT_POSITION_Y: + case ABS_MT_PRESSURE ... ABS_MT_TOOL_Y: + if (libevdev_get_num_slots(dev->evdev_prev) > 0) + want = SLOT_DELTA; + break; + default: + break; + } + + switch (want) { + case DELTA: + oldval = libevdev_get_event_value(dev->evdev_prev, + ev->type, + ev->code); + libevdev_set_event_value(dev->evdev_prev, + ev->type, + ev->code, + ev->value); + break; + case SLOT_DELTA: { + int slot = libevdev_get_current_slot(dev->evdev_prev); + oldval = libevdev_get_slot_value(dev->evdev_prev, + slot, + ev->code); + libevdev_set_slot_value(dev->evdev_prev, + slot, + ev->code, + ev->value); + break; + } + case NO_DELTA: + break; + + } + delta = ev->value - oldval; + + switch (want) { + case DELTA: + case SLOT_DELTA: + snprintf(desc, + sizeof(desc), + "%s / %-20s %6d (%+d)", + tname, + cname, + ev->value, + delta); + break; + case NO_DELTA: + snprintf(desc, + sizeof(desc), + "%s / %-20s %6d", + tname, + cname, + ev->value); + break; + } + } else { snprintf(desc, sizeof(desc), "%s / %-20s %6d%s", @@ -1248,7 +1331,7 @@ print_cached_events(struct record_context *ctx, switch (e->type) { case EVDEV: - print_evdev_event(ctx, &e->u.evdev); + print_evdev_event(ctx, d, &e->u.evdev); break; case LIBINPUT: iprintf(ctx, "- %s\n", e->u.libinput.msg); @@ -2199,6 +2282,8 @@ init_device(struct record_context *ctx, char *path) } rc = libevdev_new_from_fd(fd, &d->evdev); + if (rc == 0) + rc = libevdev_new_from_fd(fd, &d->evdev_prev); if (rc != 0) { fprintf(stderr, "Failed to create context for %s (%s)\n", |