[metacity] main: use enumeration type to find value



commit b9ca97f9fe9b55a1ba312e17e242d5a1345c4b86
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Sun Sep 13 11:31:58 2020 +0300

    main: use enumeration type to find value

 src/Makefile.am |  1 +
 src/core/main.c | 21 ++++++++++++---------
 2 files changed, 13 insertions(+), 9 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 4f703eb3..f86af600 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -200,6 +200,7 @@ testasyncgetprop_CFLAGS = \
 
 ENUM_TYPES = \
        $(srcdir)/core/window-private.h \
+       $(srcdir)/include/meta-compositor.h \
        $(NULL)
 
 core/meta-enum-types.c: core/meta-enum-types.c.in $(ENUM_TYPES) Makefile.am
diff --git a/src/core/main.c b/src/core/main.c
index 5b62b461..038398ed 100644
--- a/src/core/main.c
+++ b/src/core/main.c
@@ -47,6 +47,7 @@
 #include "util.h"
 #include "display-private.h"
 #include "errors.h"
+#include "meta-enum-types.h"
 #include "ui.h"
 #include "session.h"
 #include "prefs.h"
@@ -224,19 +225,18 @@ option_compositior_cb (const char  *option_name,
                        GError     **error)
 {
   MetaArguments *args;
+  GEnumClass *enum_class;
+  GEnumValue *enum_value;
 
   args = data;
 
-  if (g_strcmp0 (value, "none") == 0)
-    {
-      args->compositor = META_COMPOSITOR_TYPE_NONE;
-    }
-  else if (g_strcmp0 (value, "xrender") == 0)
-    {
-      args->compositor = META_COMPOSITOR_TYPE_XRENDER;
-    }
-  else
+  enum_class = g_type_class_ref (META_TYPE_COMPOSITOR_TYPE);
+  enum_value = g_enum_get_value_by_nick (enum_class, value);
+
+  if (enum_value == NULL)
     {
+      g_type_class_unref (enum_class);
+
       g_set_error (error,
                    G_OPTION_ERROR,
                    G_OPTION_ERROR_FAILED,
@@ -246,8 +246,11 @@ option_compositior_cb (const char  *option_name,
       return FALSE;
     }
 
+  args->compositor = enum_value->value;
   args->compositor_set = TRUE;
 
+  g_type_class_unref (enum_class);
+
   return TRUE;
 }
 


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