From a27e34f0500eb503355cd0810e6d2f5261ebccf6 Mon Sep 17 00:00:00 2001
From: Jeremy Whiting <jeremy.whiting@collabora.com>
Date: Thu, 5 Dec 2019 13:42:38 -0700
Subject: [PATCH] Add srt_enum_value_to_nick to get string for enumeration
 value.

---
 steam-runtime-tools/utils-internal.h |  4 ++++
 steam-runtime-tools/utils.c          | 34 ++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+)

diff --git a/steam-runtime-tools/utils-internal.h b/steam-runtime-tools/utils-internal.h
index 396a76acb..5b93333fb 100644
--- a/steam-runtime-tools/utils-internal.h
+++ b/steam-runtime-tools/utils-internal.h
@@ -48,3 +48,7 @@ G_GNUC_INTERNAL const char *_srt_find_myself (const char **helpers_path_out,
 G_GNUC_INTERNAL gboolean _srt_process_timeout_wait_status (int wait_status,
                                                            int *exit_status,
                                                            int *terminating_signal);
+
+const char *srt_enum_value_to_nick (GType enum_type,
+                                    int value);
+
diff --git a/steam-runtime-tools/utils.c b/steam-runtime-tools/utils.c
index d324b5db2..0440ceb70 100644
--- a/steam-runtime-tools/utils.c
+++ b/steam-runtime-tools/utils.c
@@ -409,6 +409,40 @@ _srt_filter_gameoverlayrenderer (const gchar *input)
   return ret;
 }
 
+/**
+ * srt_enum_value_to_nick
+ * @enum_type: The type of the enumeration.
+ * @value: The enumeration value to stringify.
+ *
+ * Get the #GEnumValue.value-nick of a given enumeration value.
+ * For example, `srt_enum_value_to_nick (SRT_TYPE_WINDOW_SYSTEM, SRT_WINDOW_SYSTEM_EGL_X11)`
+ * returns `"egl-x11"`.
+ *
+ * Returns: (transfer none): A string representation
+ *  of the given enumeration value.
+ */
+const char *
+srt_enum_value_to_nick (GType enum_type,
+                        int value)
+{
+  GEnumClass *class;
+  GEnumValue *enum_value;
+  const char *result;
+
+  g_return_val_if_fail (G_TYPE_IS_ENUM (enum_type), NULL);
+
+  class = g_type_class_ref (enum_type);
+  enum_value = g_enum_get_value (class, value);
+
+  if (enum_value != NULL)
+    result = enum_value->value_nick;
+  else
+    result = NULL;
+
+  g_type_class_unref (class);
+  return result;
+}
+
 #if !GLIB_CHECK_VERSION(2, 36, 0)
 static void _srt_constructor (void) __attribute__((__constructor__));
 static void
-- 
GitLab