[gtk+/wip/wayland-tablet: 535/555] GdkSeatDefault: Add functions to add/remove tools



commit 3082383f6e5c2e32eb42f8d7cfc4b63bf532d52e
Author: Carlos Garnacho <carlosg gnome org>
Date:   Fri Jan 29 13:07:13 2016 +0100

    GdkSeatDefault: Add functions to add/remove tools
    
    This may be used by any backend using GdkSeatDefault as its seat
    implementation.

 gdk/gdkseatdefault.c        |   71 +++++++++++++++++++++++++++++++++++++++++++
 gdk/gdkseatdefaultprivate.h |    4 ++
 2 files changed, 75 insertions(+), 0 deletions(-)
---
diff --git a/gdk/gdkseatdefault.c b/gdk/gdkseatdefault.c
index f82cf5d..41e4410 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) gdk_device_tool_unref);
+
+  g_ptr_array_add (priv->tools, gdk_device_tool_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 727bcc1..b641d4e 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__ */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]