From ff38cf366d6cf53788534ad3537cd825dede0b01 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 24 Jan 2024 15:54:25 +1000 Subject: [PATCH] backends/x11: Store eraser and stylus tools separately Our hashtable stores tools by the serial but our stylus tool and eraser tool share the same serial - they only differ by the tool type. This results in only one tool being created and this tool re-used for the other type tool. Fun side-effects of this are that the stylus ends up using the eraser pressure curve (or vice versa). Hack around this by bit-flipping the serial for the eraser to make it distinct - this is the only place we need to wrorry . Closes #1884 Part-of: --- src/backends/x11/meta-seat-x11.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/backends/x11/meta-seat-x11.c b/src/backends/x11/meta-seat-x11.c index cf1c1afe3..32b21cd53 100644 --- a/src/backends/x11/meta-seat-x11.c +++ b/src/backends/x11/meta-seat-x11.c @@ -877,18 +877,30 @@ update_tool (MetaSeatX11 *seat_x11, ClutterInputDeviceTool *tool = NULL; ClutterInputDeviceToolType type; MetaInputSettings *input_settings; + int lookup_serial; if (serial_id != 0) { + /* stylus and eraser share the same serial, so bitflip the eraser's + * serial to make them distinct in the hashtable */ + if (clutter_input_device_get_device_type (device) == CLUTTER_ERASER_DEVICE) + { + lookup_serial = ~serial_id; + type = CLUTTER_INPUT_DEVICE_TOOL_ERASER; + } + else + { + lookup_serial = serial_id; + type = CLUTTER_INPUT_DEVICE_TOOL_PEN; + } + tool = g_hash_table_lookup (seat_x11->tools_by_serial, - GUINT_TO_POINTER (serial_id)); + GUINT_TO_POINTER (lookup_serial)); if (!tool) { - type = clutter_input_device_get_device_type (device) == CLUTTER_ERASER_DEVICE ? - CLUTTER_INPUT_DEVICE_TOOL_ERASER : CLUTTER_INPUT_DEVICE_TOOL_PEN; tool = meta_input_device_tool_x11_new (serial_id, type); g_hash_table_insert (seat_x11->tools_by_serial, - GUINT_TO_POINTER (serial_id), + GUINT_TO_POINTER (lookup_serial), tool); } }