From 7b33369bfb8d3480d0803e7aa9ddea435ef394b4 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Fri, 14 Dec 2018 15:28:29 +1000 Subject: [PATCH] x11: make the tool lookup dependent on the hw id as well Tools on the same physical item have the same serial number, so the eraser and the pen part of a single pen share that serial number. With the current lookup code, we'll always return whichever tool comes first into proximity. Change the code to use the hw id in addition to the serial number, this way we can differ between two tools. --- gdk/gdkseat.c | 5 +++-- gdk/gdkseatdefault.c | 8 ++++---- gdk/gdkseatprivate.h | 6 ++++-- gdk/x11/gdkdevicemanager-xi2.c | 2 +- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/gdk/gdkseat.c b/gdk/gdkseat.c index a507d451bd..aed44a4d93 100644 --- a/gdk/gdkseat.c +++ b/gdk/gdkseat.c @@ -449,12 +449,13 @@ gdk_seat_tool_removed (GdkSeat *seat, GdkDeviceTool * gdk_seat_get_tool (GdkSeat *seat, - guint64 serial) + guint64 serial, + guint64 hw_id) { GdkSeatClass *seat_class; g_return_val_if_fail (GDK_IS_SEAT (seat), NULL); seat_class = GDK_SEAT_GET_CLASS (seat); - return seat_class->get_tool (seat, serial); + return seat_class->get_tool (seat, serial, hw_id); } diff --git a/gdk/gdkseatdefault.c b/gdk/gdkseatdefault.c index ce4bdc82d2..a83901a692 100644 --- a/gdk/gdkseatdefault.c +++ b/gdk/gdkseatdefault.c @@ -275,7 +275,8 @@ gdk_seat_default_get_slaves (GdkSeat *seat, static GdkDeviceTool * gdk_seat_default_get_tool (GdkSeat *seat, - guint64 serial) + guint64 serial, + guint64 hw_id) { GdkSeatDefaultPrivate *priv; GdkDeviceTool *tool; @@ -290,7 +291,7 @@ gdk_seat_default_get_tool (GdkSeat *seat, { tool = g_ptr_array_index (priv->tools, i); - if (tool->serial == serial) + if (tool->serial == serial && tool->hw_id == hw_id) return tool; } @@ -436,8 +437,7 @@ gdk_seat_default_remove_tool (GdkSeatDefault *seat, priv = gdk_seat_default_get_instance_private (seat); - if (tool != gdk_seat_get_tool (GDK_SEAT (seat), - gdk_device_tool_get_serial (tool))) + if (tool != gdk_seat_get_tool (GDK_SEAT (seat), tool->serial, tool->hw_id)) return; g_signal_emit_by_name (seat, "tool-removed", tool); diff --git a/gdk/gdkseatprivate.h b/gdk/gdkseatprivate.h index bd66f68bf5..e031294aca 100644 --- a/gdk/gdkseatprivate.h +++ b/gdk/gdkseatprivate.h @@ -57,7 +57,8 @@ struct _GdkSeatClass GdkSeatCapabilities capabilities); GdkDeviceTool * (* get_tool) (GdkSeat *seat, - guint64 serial); + guint64 serial, + guint64 tool_id); }; void gdk_seat_device_added (GdkSeat *seat, @@ -72,6 +73,7 @@ void gdk_seat_tool_removed (GdkSeat *seat, GdkDeviceTool * gdk_seat_get_tool (GdkSeat *seat, - guint64 serial); + guint64 serial, + guint64 hw_id); #endif /* __GDK_SEAT_PRIVATE_H__ */ diff --git a/gdk/x11/gdkdevicemanager-xi2.c b/gdk/x11/gdkdevicemanager-xi2.c index 5c7a5a1614..135a0512aa 100644 --- a/gdk/x11/gdkdevicemanager-xi2.c +++ b/gdk/x11/gdkdevicemanager-xi2.c @@ -1115,7 +1115,7 @@ handle_property_change (GdkX11DeviceManagerXI2 *device_manager, device_get_tool_serial_and_id (device, &serial_id, &tool_id)) { seat = gdk_device_get_seat (device); - tool = gdk_seat_get_tool (seat, serial_id); + tool = gdk_seat_get_tool (seat, serial_id, tool_id); if (!tool && serial_id > 0) {