diff --git a/src/evdev-frame.h b/src/evdev-frame.h index e544aaa4..341446cf 100644 --- a/src/evdev-frame.h +++ b/src/evdev-frame.h @@ -550,10 +550,12 @@ evdev_frame_append(struct evdev_frame *frame, size_t nevents) { assert(nevents > 0); + int syn_report_value = 0; for (size_t i = 0; i < nevents; i++) { if (evdev_usage_eq(events[i].usage, EVDEV_SYN_REPORT)) { nevents = i; + syn_report_value = events[i].value; break; } } @@ -568,14 +570,24 @@ evdev_frame_append(struct evdev_frame *frame, frame->count += nevents; } + frame->events[frame->count - 1] = (struct evdev_event){ + .usage = evdev_usage_from_uint32_t(EVDEV_SYN_REPORT), + .value = syn_report_value, + }; + return 0; } static inline int evdev_frame_append_one(struct evdev_frame *frame, evdev_usage_t usage, int32_t value) { - if (evdev_usage_eq(usage, EVDEV_SYN_REPORT)) + if (evdev_usage_eq(usage, EVDEV_SYN_REPORT)) { + frame->events[frame->count - 1] = (struct evdev_event){ + .usage = evdev_usage_from_uint32_t(EVDEV_SYN_REPORT), + .value = value, + }; return 0; + } if (frame->count >= frame->max_size) return -ENOMEM; diff --git a/test/test-utils.c b/test/test-utils.c index e572f3da..9032b377 100644 --- a/test/test-utils.c +++ b/test/test-utils.c @@ -3168,6 +3168,49 @@ START_TEST(evdev_frames) ARRAY_LENGTH(events)); litest_assert_int_eq(frame->max_size, ARRAY_LENGTH(events)); } + { + struct evdev_event events[] = { + { + .usage = U(EVDEV_ABS_X), + .value = 1, + }, + { + .usage = U(EVDEV_ABS_Y), + .value = 2, + }, + { + .usage = U(EVDEV_SYN_REPORT), + .value = 1, + }, + }; + + _unref_(evdev_frame) *frame = evdev_frame_new(3); + int rc = evdev_frame_append(frame, events, 3); + litest_assert_neg_errno_success(rc); + + litest_assert_int_eq(evdev_frame_get_count(frame), + ARRAY_LENGTH(events)); + litest_assert_int_eq(frame->max_size, ARRAY_LENGTH(events)); + + size_t nevents; + rc = memcmp(evdev_frame_get_events(frame, &nevents), + events, + sizeof(events)); + litest_assert_int_eq(rc, 0); + litest_assert_int_eq(nevents, ARRAY_LENGTH(events)); + + for (int v = 0; v < 2; v++) { + /* Appending SYN_REPORT changes the value to zero */ + rc = evdev_frame_append_one(frame, U(EVDEV_SYN_REPORT), v); + litest_assert_neg_errno_success(rc); + litest_assert_int_eq(evdev_frame_get_count(frame), + ARRAY_LENGTH(events)); + struct evdev_event *evs = + evdev_frame_get_events(frame, &nevents); + litest_assert(evdev_usage_eq(evs[2].usage, EVDEV_SYN_REPORT)); + litest_assert_int_eq(evs[2].value, v); + } + } } END_TEST