diff --git a/gdk/gdkseatdefault.c b/gdk/gdkseatdefault.c index f82cf5d93a..87150642c9 100644 --- a/gdk/gdkseatdefault.c +++ b/gdk/gdkseatdefault.c @@ -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); +} diff --git a/gdk/gdkseatdefaultprivate.h b/gdk/gdkseatdefaultprivate.h index 727bcc1b1e..b641d4e29d 100644 --- a/gdk/gdkseatdefaultprivate.h +++ b/gdk/gdkseatdefaultprivate.h @@ -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__ */