diff --git a/steam-runtime-tools/utils-internal.h b/steam-runtime-tools/utils-internal.h index 396a76acb7679b63099a41758a4e94ea7afed8bc..5b93333fb553749a8d7cdebf1d0ee87550898278 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 d324b5db26576b4c61ce57d29f7e7eafe63484cd..0440ceb709bc53063fb348be7f18ce51adab48ff 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