From 892e5d35c712cc08328666964ec32f2551288ba9 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 3 Jul 2025 09:58:14 +1000 Subject: [PATCH] plugin: use evdev_frame_append_one() for simpler code Instead of creating a struct and passing it in as array let's use the helper function. Part-of: --- src/libinput-plugin-button-debounce.c | 9 ++---- src/libinput-plugin-mouse-wheel.c | 36 ++++++++---------------- src/libinput-plugin-tablet-forced-tool.c | 10 ++----- 3 files changed, 18 insertions(+), 37 deletions(-) diff --git a/src/libinput-plugin-button-debounce.c b/src/libinput-plugin-button-debounce.c index a417b7c8..1062a34c 100644 --- a/src/libinput-plugin-button-debounce.c +++ b/src/libinput-plugin-button-debounce.c @@ -250,18 +250,15 @@ debounce_notify_button(struct plugin_device *device, struct evdev_frame *frame, enum libinput_button_state state) { - const struct evdev_event button = { - .usage = device->button_usage, - .value = state == LIBINPUT_BUTTON_STATE_PRESSED ? 1 : 0, - }; - _unref_(evdev_frame) *button_frame = NULL; if (frame == NULL) { button_frame = evdev_frame_new(2); frame = button_frame; } - evdev_frame_append(frame, &button, 1); + evdev_frame_append_one(frame, + device->button_usage, + state == LIBINPUT_BUTTON_STATE_PRESSED ? 1 : 0); evdev_frame_set_time(frame, device->button_time); libinput_plugin_prepend_evdev_frame(device->parent->plugin, diff --git a/src/libinput-plugin-mouse-wheel.c b/src/libinput-plugin-mouse-wheel.c index 584b00fa..1e42af89 100644 --- a/src/libinput-plugin-mouse-wheel.c +++ b/src/libinput-plugin-mouse-wheel.c @@ -250,42 +250,30 @@ static void wheel_queue_scroll_events(struct plugin_device *pd, struct evdev_frame *frame) { if (pd->hi_res.y != 0) { - struct evdev_event e = { - .usage = evdev_usage_from(EVDEV_REL_WHEEL_HI_RES), - .value = pd->hi_res.y, - }; - - evdev_frame_append(frame, &e, 1); + evdev_frame_append_one(frame, + evdev_usage_from(EVDEV_REL_WHEEL_HI_RES), + pd->hi_res.y); pd->hi_res.y = 0; } if (pd->lo_res.y != 0) { - struct evdev_event e = { - .usage = evdev_usage_from(EVDEV_REL_WHEEL), - .value = pd->lo_res.y, - }; - - evdev_frame_append(frame, &e, 1); + evdev_frame_append_one(frame, + evdev_usage_from(EVDEV_REL_WHEEL), + pd->lo_res.y); pd->lo_res.y = 0; } if (pd->hi_res.x != 0) { - struct evdev_event e = { - .usage = evdev_usage_from(EVDEV_REL_HWHEEL_HI_RES), - .value = pd->hi_res.x, - }; - - evdev_frame_append(frame, &e, 1); + evdev_frame_append_one(frame, + evdev_usage_from(EVDEV_REL_HWHEEL_HI_RES), + pd->hi_res.x); pd->hi_res.x = 0; } if (pd->lo_res.x != 0) { - struct evdev_event e = { - .usage = evdev_usage_from(EVDEV_REL_HWHEEL), - .value = pd->lo_res.x, - }; - - evdev_frame_append(frame, &e, 1); + evdev_frame_append_one(frame, + evdev_usage_from(EVDEV_REL_HWHEEL), + pd->lo_res.x); pd->lo_res.x = 0; } } diff --git a/src/libinput-plugin-tablet-forced-tool.c b/src/libinput-plugin-tablet-forced-tool.c index 1b4e34ad..aa19bd59 100644 --- a/src/libinput-plugin-tablet-forced-tool.c +++ b/src/libinput-plugin-tablet-forced-tool.c @@ -152,13 +152,9 @@ forced_tool_plugin_device_handle_frame(struct libinput_plugin *libinput_plugin, * stylus is def. in proximity). We don't do this for pure * button events because we discard those. */ - const struct evdev_event prox = { - .usage = evdev_usage_from(EVDEV_BTN_TOOL_PEN), - .value = 1, - }; - evdev_frame_append(frame, - &prox, - 1); /* libinput's event frame will have space */ + evdev_frame_append_one(frame, + evdev_usage_from(EVDEV_BTN_TOOL_PEN), + 1); /* libinput's event frame will have space */ } static void