[mutter/wip/tablet-protocol-v2: 55/65] wayland: Add getters for the current feedback strings in MetaWaylandTabletPad



commit 5ead55bd1767266e284f4e3ba26db8fbfa875c05
Author: Carlos Garnacho <carlosg gnome org>
Date:   Wed Jun 22 19:00:15 2016 +0200

    wayland: Add getters for the current feedback strings in MetaWaylandTabletPad
    
    Each of the buttons/rings/strips may have one such feedback string, this API
    makes is meant to make lookups consistent.

 src/wayland/meta-wayland-tablet-pad.c |   69 +++++++++++++++++++++++++++++++++
 src/wayland/meta-wayland-tablet-pad.h |    4 ++
 2 files changed, 73 insertions(+), 0 deletions(-)
---
diff --git a/src/wayland/meta-wayland-tablet-pad.c b/src/wayland/meta-wayland-tablet-pad.c
index 11b5dcd..1f47745 100644
--- a/src/wayland/meta-wayland-tablet-pad.c
+++ b/src/wayland/meta-wayland-tablet-pad.c
@@ -26,6 +26,7 @@
 #include "config.h"
 
 #include <glib.h>
+#include <glib/gi18n-lib.h>
 
 #include <wayland-server.h>
 #include "tablet-unstable-v2-server-protocol.h"
@@ -437,3 +438,71 @@ meta_wayland_tablet_pad_update (MetaWaylandTabletPad *pad,
       break;
     }
 }
+
+static gchar *
+meta_wayland_tablet_pad_label_mode_switch_button (MetaWaylandTabletPad *pad,
+                                                  guint                 button)
+{
+  MetaWaylandTabletPadGroup *group;
+  GList *l;
+
+  for (l = pad->groups; l; l = l->next)
+    {
+      group = l->data;
+
+      if (meta_wayland_tablet_pad_group_is_mode_switch_button (group, button))
+        return g_strdup_printf (_("Mode Switch: Mode %d"), group->current_mode + 1);
+    }
+
+  return NULL;
+}
+
+gchar *
+meta_wayland_tablet_pad_get_label (MetaWaylandTabletPad *pad,
+                                  MetaPadActionType     type,
+                                  guint                 action)
+{
+  const gchar *label = NULL;
+  gchar *mode_label;
+
+  switch (type)
+    {
+    case META_PAD_ACTION_BUTTON:
+      mode_label = meta_wayland_tablet_pad_label_mode_switch_button (pad, action);
+      if (mode_label)
+        return mode_label;
+
+      label = g_hash_table_lookup (pad->feedback, GUINT_TO_POINTER (action));
+      break;
+    case META_PAD_ACTION_RING:
+      {
+        MetaWaylandTabletPadGroup *group;
+        MetaWaylandTabletPadRing *ring;
+
+        /* FIXME: Assuming each group gets 1 */
+        group = g_list_nth_data (pad->groups, action);
+        if (!group)
+          break;
+        ring = g_list_nth_data (group->rings, 0);
+        if (ring)
+          label = ring->feedback;
+        break;
+      }
+    case META_PAD_ACTION_STRIP:
+      {
+        MetaWaylandTabletPadGroup *group;
+        MetaWaylandTabletPadStrip *strip;
+
+        /* FIXME: Assuming each group gets 1 */
+        group = g_list_nth_data (pad->groups, action);
+        if (!group)
+          break;
+        strip = g_list_nth_data (group->strips, 0);
+        if (strip)
+          label = strip->feedback;
+        break;
+      }
+    }
+
+  return g_strdup (label);
+}
diff --git a/src/wayland/meta-wayland-tablet-pad.h b/src/wayland/meta-wayland-tablet-pad.h
index a627226..72a66ec 100644
--- a/src/wayland/meta-wayland-tablet-pad.h
+++ b/src/wayland/meta-wayland-tablet-pad.h
@@ -73,4 +73,8 @@ gboolean     meta_wayland_tablet_pad_handle_event        (MetaWaylandTabletPad *
 void         meta_wayland_tablet_pad_set_focus           (MetaWaylandTabletPad *pad,
                                                           MetaWaylandSurface   *surface);
 
+gchar *      meta_wayland_tablet_pad_get_label           (MetaWaylandTabletPad *pad,
+                                                         MetaPadActionType     type,
+                                                         guint                 action);
+
 #endif /* META_WAYLAND_TABLET_PAD_H */


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