summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2024-01-15 17:33:43 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2024-01-30 14:29:25 +1000
commit54aa01a267fef06ff5ea7799d8638970747f3fbe (patch)
tree0c1d2ea5da58e002f58d1ba6c721af3d56899621
parent7cffd28e8f2de17ffe5f0bfbd9e85fc5cbc05fe0 (diff)
tablet: move tool creation into a helper function
-rw-r--r--src/evdev-tablet.c34
1 files 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
@@ -1127,6 +1127,27 @@ out:
}
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,
uint32_t tool_id,
@@ -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);
}