From 54aa01a267fef06ff5ea7799d8638970747f3fbe Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 15 Jan 2024 17:33:43 +1000 Subject: tablet: move tool creation into a helper function --- src/evdev-tablet.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 1a4f5df8..4f4746dd 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -1126,6 +1126,27 @@ out: quirks_unref(q); } +static struct libinput_tablet_tool * +tablet_new_tool(struct tablet_dispatch *tablet, + enum libinput_tablet_tool_type type, + uint32_t tool_id, + uint32_t serial) +{ + struct libinput_tablet_tool *tool = zalloc(sizeof *tool); + + *tool = (struct libinput_tablet_tool) { + .type = type, + .serial = serial, + .tool_id = tool_id, + .refcount = 1, + }; + + tool_set_pressure_thresholds(tablet, tool); + tool_set_bits(tablet, tool); + + return tool; +} + static struct libinput_tablet_tool * tablet_get_tool(struct tablet_dispatch *tablet, enum libinput_tablet_tool_type type, @@ -1176,18 +1197,7 @@ tablet_get_tool(struct tablet_dispatch *tablet, /* If we didn't already have the new_tool in our list of tools, * add it */ if (!tool) { - tool = zalloc(sizeof *tool); - - *tool = (struct libinput_tablet_tool) { - .type = type, - .serial = serial, - .tool_id = tool_id, - .refcount = 1, - }; - - tool_set_pressure_thresholds(tablet, tool); - tool_set_bits(tablet, tool); - + tool = tablet_new_tool(tablet, type, tool_id, serial); list_insert(tool_list, &tool->link); } -- cgit v1.2.3