Merge branch 'wip/syn-report-value' into 'main'

evdev: store the SYN_REPORT value in the frame

Closes #1261

See merge request libinput/libinput!1449
This commit is contained in:
Peter Hutterer 2026-03-19 10:24:53 +10:00
commit b0e062df2a
2 changed files with 56 additions and 1 deletions

View file

@ -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;

View file

@ -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