GdkSeatDefault: Add functions to add/remove tools

This may be used by any backend using GdkSeatDefault as its seat
implementation.
This commit is contained in:
Carlos Garnacho 2016-01-29 13:07:13 +01:00
parent 6824dd7b8a
commit 5a25c5a9f2
2 changed files with 75 additions and 0 deletions

View File

@ -29,6 +29,8 @@ struct _GdkSeatDefaultPrivate
GList *slave_pointers;
GList *slave_keyboards;
GdkSeatCapabilities capabilities;
GPtrArray *tools;
};
#define KEYBOARD_EVENTS (GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | \
@ -76,6 +78,12 @@ gdk_seat_dispose (GObject *object)
g_object_unref (l->data);
}
if (priv->tools)
{
g_ptr_array_unref (priv->tools);
priv->tools = NULL;
}
g_list_free (priv->slave_pointers);
g_list_free (priv->slave_keyboards);
priv->slave_pointers = NULL;
@ -248,6 +256,30 @@ gdk_seat_default_get_slaves (GdkSeat *seat,
return devices;
}
static GdkDeviceTool *
gdk_seat_default_get_tool (GdkSeat *seat,
guint64 serial)
{
GdkSeatDefaultPrivate *priv;
GdkDeviceTool *tool;
guint i;
priv = gdk_seat_default_get_instance_private (GDK_SEAT_DEFAULT (seat));
if (!priv->tools)
return NULL;
for (i = 0; i < priv->tools->len; i++)
{
tool = g_ptr_array_index (priv->tools, i);
if (tool->serial == serial)
return tool;
}
return NULL;
}
static void
gdk_seat_default_class_init (GdkSeatDefaultClass *klass)
{
@ -263,6 +295,8 @@ gdk_seat_default_class_init (GdkSeatDefaultClass *klass)
seat_class->get_master = gdk_seat_default_get_master;
seat_class->get_slaves = gdk_seat_default_get_slaves;
seat_class->get_tool = gdk_seat_default_get_tool;
}
static void
@ -355,3 +389,40 @@ gdk_seat_default_remove_slave (GdkSeatDefault *seat,
gdk_seat_device_removed (GDK_SEAT (seat), device);
}
}
void
gdk_seat_default_add_tool (GdkSeatDefault *seat,
GdkDeviceTool *tool)
{
GdkSeatDefaultPrivate *priv;
g_return_if_fail (GDK_IS_SEAT_DEFAULT (seat));
g_return_if_fail (tool != NULL);
priv = gdk_seat_default_get_instance_private (seat);
if (!priv->tools)
priv->tools = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
g_ptr_array_add (priv->tools, g_object_ref (tool));
g_signal_emit_by_name (seat, "tool-added", tool);
}
void
gdk_seat_default_remove_tool (GdkSeatDefault *seat,
GdkDeviceTool *tool)
{
GdkSeatDefaultPrivate *priv;
g_return_if_fail (GDK_IS_SEAT_DEFAULT (seat));
g_return_if_fail (tool != NULL);
priv = gdk_seat_default_get_instance_private (seat);
if (tool != gdk_seat_get_tool (GDK_SEAT (seat),
gdk_device_tool_get_serial (tool)))
return;
g_signal_emit_by_name (seat, "tool-removed", tool);
g_ptr_array_remove (priv->tools, tool);
}

View File

@ -52,5 +52,9 @@ void gdk_seat_default_add_slave (GdkSeatDefault *seat,
GdkDevice *device);
void gdk_seat_default_remove_slave (GdkSeatDefault *seat,
GdkDevice *device);
void gdk_seat_default_add_tool (GdkSeatDefault *seat,
GdkDeviceTool *tool);
void gdk_seat_default_remove_tool (GdkSeatDefault *seat,
GdkDeviceTool *tool);
#endif /* __GDK_SEAT_DEFAULT_PRIVATE_H__ */