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: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3542>
This commit is contained in:
Peter Hutterer 2024-01-24 15:54:25 +10:00 committed by Marge Bot
parent b8914da0c8
commit ff38cf366d

View File

@ -877,18 +877,30 @@ update_tool (MetaSeatX11 *seat_x11,
ClutterInputDeviceTool *tool = NULL; ClutterInputDeviceTool *tool = NULL;
ClutterInputDeviceToolType type; ClutterInputDeviceToolType type;
MetaInputSettings *input_settings; MetaInputSettings *input_settings;
int lookup_serial;
if (serial_id != 0) 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, tool = g_hash_table_lookup (seat_x11->tools_by_serial,
GUINT_TO_POINTER (serial_id)); GUINT_TO_POINTER (lookup_serial));
if (!tool) 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); tool = meta_input_device_tool_x11_new (serial_id, type);
g_hash_table_insert (seat_x11->tools_by_serial, g_hash_table_insert (seat_x11->tools_by_serial,
GUINT_TO_POINTER (serial_id), GUINT_TO_POINTER (lookup_serial),
tool); tool);
} }
} }