seat: improve api to take into account the tool type

Otherwise if we have several tools with the same serial
and hardware id we might match the wrong tool.
This commit is contained in:
Ignacio Casal Quinteiro 2021-01-07 12:27:26 +01:00
parent 0d99ef7cee
commit 45ec3fc389
4 changed files with 16 additions and 13 deletions

View File

@ -436,9 +436,10 @@ gdk_seat_tool_removed (GdkSeat *seat,
}
GdkDeviceTool *
gdk_seat_get_tool (GdkSeat *seat,
guint64 serial,
guint64 hw_id)
gdk_seat_get_tool (GdkSeat *seat,
guint64 serial,
guint64 hw_id,
GdkDeviceToolType type)
{
GdkDeviceTool *match = NULL;
GList *tools, *l;
@ -449,7 +450,7 @@ gdk_seat_get_tool (GdkSeat *seat,
{
GdkDeviceTool *tool = l->data;
if (tool->serial == serial && tool->hw_id == hw_id)
if (tool->serial == serial && tool->hw_id == hw_id && tool->type == type)
{
match = tool;
break;

View File

@ -442,7 +442,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), tool->serial, tool->hw_id))
if (tool != gdk_seat_get_tool (GDK_SEAT (seat), tool->serial, tool->hw_id, tool->type))
return;
g_signal_emit_by_name (seat, "tool-removed", tool);

View File

@ -75,9 +75,10 @@ void gdk_seat_tool_removed (GdkSeat *seat,
GdkDeviceTool *tool);
GdkDeviceTool *
gdk_seat_get_tool (GdkSeat *seat,
guint64 serial,
guint64 hw_id);
gdk_seat_get_tool (GdkSeat *seat,
guint64 serial,
guint64 hw_id,
GdkDeviceToolType type);
GdkGrabStatus gdk_seat_grab (GdkSeat *seat,
GdkSurface *surface,

View File

@ -1097,15 +1097,16 @@ handle_property_change (GdkX11DeviceManagerXI2 *device_manager,
if (ev->what != XIPropertyDeleted &&
device_get_tool_serial_and_id (device, &serial_id, &tool_id))
{
GdkDeviceToolType tool_type;
seat = gdk_device_get_seat (device);
tool = gdk_seat_get_tool (seat, serial_id, tool_id);
tool_type = device_get_tool_type (device);
if (!tool && serial_id > 0)
if (tool_type != GDK_DEVICE_TOOL_TYPE_UNKNOWN)
{
GdkDeviceToolType tool_type;
tool = gdk_seat_get_tool (seat, serial_id, tool_id, tool_type);
tool_type = device_get_tool_type (device);
if (tool_type != GDK_DEVICE_TOOL_TYPE_UNKNOWN)
if (!tool && serial_id > 0)
{
tool = gdk_device_tool_new (serial_id, tool_id, tool_type, 0);
gdk_seat_default_add_tool (GDK_SEAT_DEFAULT (seat), tool);