commit d71651b1fdb55c385499d34c4afc77071c0b9496 (HEAD -> cirrus)
Author: Felix Zhang <fezhang@suse.com>
Date:   Fri Jan 19 20:39:38 2018 +0800

    common: Disable Wayland on Cirrus chipset
    
    https://bugzilla.gnome.org/show_bug.cgi?id=789081

diff --git a/common/Makefile.am b/common/Makefile.am
index 2e97090b..8566ccb0 100644
--- a/common/Makefile.am
+++ b/common/Makefile.am
@@ -20,6 +20,8 @@ AM_CPPFLAGS = \
 	-DGDM_DEFAULTS_CONF=\"$(GDM_DEFAULTS_CONF)\"	\
 	-DGDM_CUSTOM_CONF=\"$(GDM_CUSTOM_CONF)\"	\
 	-DGDM_OLD_CONF=\"$(GDM_OLD_CONF)\"		\
+	-DGDM_RUN_DIR=\"$(GDM_RUN_DIR)\"	\
+	-DGDM_RUNTIME_CONF=\"$(GDM_RUNTIME_CONF)\"	\
 	-DGDM_SESSION_DEFAULT_PATH=\"$(GDM_SESSION_DEFAULT_PATH)\" \
 	$(COMMON_CFLAGS)				\
 	$(NULL)
diff --git a/common/gdm-settings-desktop-backend.c b/common/gdm-settings-desktop-backend.c
index a469f30e..049e139d 100644
--- a/common/gdm-settings-desktop-backend.c
+++ b/common/gdm-settings-desktop-backend.c
@@ -46,12 +46,90 @@ struct GdmSettingsDesktopBackendPrivate
         guint       save_id;
 };
 
+enum {
+        PROP_0,
+        PROP_FILENAME,
+};
+
 static void     gdm_settings_desktop_backend_class_init (GdmSettingsDesktopBackendClass *klass);
 static void     gdm_settings_desktop_backend_init       (GdmSettingsDesktopBackend      *settings_desktop_backend);
 static void     gdm_settings_desktop_backend_finalize   (GObject                        *object);
 
 G_DEFINE_TYPE (GdmSettingsDesktopBackend, gdm_settings_desktop_backend, GDM_TYPE_SETTINGS_BACKEND)
 
+static void
+_gdm_settings_desktop_backend_set_file_name (GdmSettingsDesktopBackend *backend,
+                                             const char                *filename)
+{
+        gboolean res;
+        GError  *error;
+        char *contents;
+
+        backend->priv = GDM_SETTINGS_DESKTOP_BACKEND_GET_PRIVATE (backend);
+
+        g_free (backend->priv->filename);
+        backend->priv->filename = g_strdup (filename);
+
+        backend->priv->key_file = g_key_file_new ();
+
+        error = NULL;
+        res = g_key_file_load_from_file (backend->priv->key_file,
+                                         backend->priv->filename,
+                                         G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS,
+                                         &error);
+        if (! res) {
+                g_warning ("Unable to load file '%s': %s", backend->priv->filename, error->message);
+        }
+
+        contents = g_key_file_to_data (backend->priv->key_file, NULL, NULL);
+
+        if (contents != NULL) {
+                g_debug ("GdmSettings: %s is:\n%s\n", backend->priv->filename, contents);
+                g_free (contents);
+        }
+
+}
+
+static void
+gdm_settings_desktop_backend_set_property (GObject      *object,
+                                           guint         prop_id,
+                                           const GValue *value,
+                                           GParamSpec   *pspec)
+{
+        GdmSettingsDesktopBackend *self;
+
+        self = GDM_SETTINGS_DESKTOP_BACKEND (object);
+
+        switch (prop_id) {
+                case PROP_FILENAME:
+                        _gdm_settings_desktop_backend_set_file_name (self, g_value_get_string (value));
+                        break;
+                default:
+                        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+                        break;
+        }
+}
+
+static void
+gdm_settings_desktop_backend_get_property (GObject      *object,
+                                           guint         prop_id,
+                                           GValue       *value,
+                                           GParamSpec   *pspec)
+{
+        GdmSettingsDesktopBackend *self;
+
+        self = GDM_SETTINGS_DESKTOP_BACKEND (object);
+
+        switch (prop_id) {
+                case PROP_FILENAME:
+                        g_value_set_string (value, self->priv->filename);
+                        break;
+                default:
+                        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+                        break;
+        }
+}
+
 static gboolean
 parse_key_string (const char *keystring,
                   char      **group,
@@ -308,41 +386,27 @@ gdm_settings_desktop_backend_class_init (GdmSettingsDesktopBackendClass *klass)
         GObjectClass            *object_class = G_OBJECT_CLASS (klass);
         GdmSettingsBackendClass *backend_class = GDM_SETTINGS_BACKEND_CLASS (klass);
 
+        object_class->get_property = gdm_settings_desktop_backend_get_property;
+        object_class->set_property = gdm_settings_desktop_backend_set_property;
         object_class->finalize = gdm_settings_desktop_backend_finalize;
 
         backend_class->get_value = gdm_settings_desktop_backend_get_value;
         backend_class->set_value = gdm_settings_desktop_backend_set_value;
 
         g_type_class_add_private (klass, sizeof (GdmSettingsDesktopBackendPrivate));
+
+        g_object_class_install_property (object_class,
+                                         PROP_FILENAME,
+                                         g_param_spec_string ("filename",
+                                                              "File Name",
+                                                              "The name of the configuration file",
+                                                              NULL,
+                                                              G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
 }
 
 static void
 gdm_settings_desktop_backend_init (GdmSettingsDesktopBackend *backend)
 {
-        gboolean res;
-        GError  *error;
-        char *contents;
-
-        backend->priv = GDM_SETTINGS_DESKTOP_BACKEND_GET_PRIVATE (backend);
-
-        backend->priv->key_file = g_key_file_new ();
-        backend->priv->filename = g_strdup (GDM_CUSTOM_CONF);
-
-        error = NULL;
-        res = g_key_file_load_from_file (backend->priv->key_file,
-                                         backend->priv->filename,
-                                         G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS,
-                                         &error);
-        if (! res) {
-                g_warning ("Unable to load file '%s': %s", backend->priv->filename, error->message);
-        }
-
-        contents = g_key_file_to_data (backend->priv->key_file, NULL, NULL);
-
-        if (contents != NULL) {
-                g_debug ("GdmSettings: %s is:\n%s\n", backend->priv->filename, contents);
-                g_free (contents);
-        }
 }
 
 static void
@@ -365,11 +429,15 @@ gdm_settings_desktop_backend_finalize (GObject *object)
 }
 
 GdmSettingsBackend *
-gdm_settings_desktop_backend_new (void)
+gdm_settings_desktop_backend_new (const char* filename)
 {
         GObject *object;
 
-        object = g_object_new (GDM_TYPE_SETTINGS_DESKTOP_BACKEND, NULL);
+        if (!g_file_test (GDM_RUNTIME_CONF, G_FILE_TEST_IS_REGULAR))
+                return NULL;
 
+        object = g_object_new (GDM_TYPE_SETTINGS_DESKTOP_BACKEND,
+                               "filename", filename,
+                               NULL);
         return GDM_SETTINGS_BACKEND (object);
 }
diff --git a/common/gdm-settings-desktop-backend.h b/common/gdm-settings-desktop-backend.h
index 6a48c20f..9fb094b4 100644
--- a/common/gdm-settings-desktop-backend.h
+++ b/common/gdm-settings-desktop-backend.h
@@ -49,7 +49,7 @@ typedef struct
 
 GType                      gdm_settings_desktop_backend_get_type        (void);
 
-GdmSettingsBackend        *gdm_settings_desktop_backend_new             (void);
+GdmSettingsBackend        *gdm_settings_desktop_backend_new             (const char* filename);
 
 G_END_DECLS
 
diff --git a/common/gdm-settings.c b/common/gdm-settings.c
index 88b079bf..cebbef25 100644
--- a/common/gdm-settings.c
+++ b/common/gdm-settings.c
@@ -43,7 +43,7 @@
 
 struct GdmSettingsPrivate
 {
-        GdmSettingsBackend *backend;
+        GList *backends;
 };
 
 enum {
@@ -80,15 +80,28 @@ gdm_settings_get_value (GdmSettings *settings,
 {
         GError  *local_error;
         gboolean res;
+        GList   *l;
 
         g_return_val_if_fail (GDM_IS_SETTINGS (settings), FALSE);
         g_return_val_if_fail (key != NULL, FALSE);
 
         local_error = NULL;
-        res = gdm_settings_backend_get_value (settings->priv->backend,
-                                              key,
-                                              value,
-                                              &local_error);
+
+        for (l = settings->priv->backends; l; l = g_list_next (l)) {
+                GdmSettingsBackend *backend = l->data;
+
+                if (local_error) {
+                        g_error_free (local_error);
+                        local_error = NULL;
+                }
+
+                res = gdm_settings_backend_get_value (backend,
+                                                      key,
+                                                      value,
+                                                      &local_error);
+                if (res)
+                        break;
+        }
         if (! res) {
                 g_propagate_error (error, local_error);
         }
@@ -104,6 +117,7 @@ gdm_settings_set_value (GdmSettings *settings,
 {
         GError  *local_error;
         gboolean res;
+        GList   *l;
 
         g_return_val_if_fail (GDM_IS_SETTINGS (settings), FALSE);
         g_return_val_if_fail (key != NULL, FALSE);
@@ -111,10 +125,23 @@ gdm_settings_set_value (GdmSettings *settings,
         g_debug ("Setting value %s", key);
 
         local_error = NULL;
-        res = gdm_settings_backend_set_value (settings->priv->backend,
-                                              key,
-                                              value,
-                                              &local_error);
+
+        for (l = settings->priv->backends; l; l = g_list_next (l)) {
+                GdmSettingsBackend *backend = l->data;
+
+                if (local_error) {
+                        g_error_free (local_error);
+                        local_error = NULL;
+                }
+
+                res = gdm_settings_backend_set_value (backend,
+                                                      key,
+                                                      value,
+                                                      &local_error);
+                if (res)
+                        break;
+        }
+
         if (! res) {
                 g_propagate_error (error, local_error);
         }
@@ -162,13 +189,27 @@ backend_value_changed (GdmSettingsBackend *backend,
 static void
 gdm_settings_init (GdmSettings *settings)
 {
+        GList *l;
+        GdmSettingsBackend *backend;
+
         settings->priv = GDM_SETTINGS_GET_PRIVATE (settings);
 
-        settings->priv->backend = gdm_settings_desktop_backend_new ();
-        g_signal_connect (settings->priv->backend,
-                          "value-changed",
-                          G_CALLBACK (backend_value_changed),
-                          settings);
+        backend = gdm_settings_desktop_backend_new (GDM_CUSTOM_CONF);
+        if (backend)
+                settings->priv->backends = g_list_prepend (NULL, backend);
+
+        backend = gdm_settings_desktop_backend_new (GDM_RUNTIME_CONF);
+        if (backend)
+                settings->priv->backends = g_list_prepend (settings->priv->backends, backend);
+
+        for (l = settings->priv->backends; l; l = g_list_next (l)) {
+                backend = l->data;
+
+                g_signal_connect (backend,
+                                  "value-changed",
+                                  G_CALLBACK (backend_value_changed),
+                                  settings);
+        }
 }
 
 static void
@@ -183,9 +224,9 @@ gdm_settings_finalize (GObject *object)
 
         g_return_if_fail (settings->priv != NULL);
 
-        if (settings->priv->backend != NULL) {
-                g_object_unref (settings->priv->backend);
-        }
+        g_list_foreach (settings->priv->backends, (GFunc) g_object_unref, NULL);
+        g_list_free (settings->priv->backends);
+        settings->priv->backends = NULL;
 
         settings_object = NULL;
 
diff --git a/configure.ac b/configure.ac
index 6b2ef7f3..89d173ef 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1424,6 +1424,24 @@ fi
 AC_SUBST(GDM_SCREENSHOT_DIR)
 
 dnl ---------------------------------------------------------------------------
+dnl - runtime conf
+dnl ---------------------------------------------------------------------------
+
+withval=""
+AC_ARG_WITH(runtime_conf,
+            AS_HELP_STRING([--with-runtime-conf=<FILENAME>],
+                           [FILENAME to give to runtime configuration file @<:@default=GDM_RUN_DIR/runtime.conf@:>@]))
+
+if test x$withval != x; then
+	GDM_RUNTIME_CONF="$withval"
+else
+	GDM_RUNTIME_CONF="$GDM_RUN_DIR/runtime.conf"
+fi
+
+AC_SUBST(GDM_RUNTIME_CONF)
+
+
+dnl ---------------------------------------------------------------------------
 dnl - Finish
 dnl ---------------------------------------------------------------------------
 
diff --git a/data/61-gdm.rules b/data/61-gdm.rules
new file mode 100644
index 00000000..b4f75840
--- /dev/null
+++ b/data/61-gdm.rules
@@ -0,0 +1,4 @@
+# disable Wayland on Cirrus chipsets
+ATTR{vendor}=="0x1013", ATTR{device}=="0x00b8", ATTR{subsystem_vendor}=="0x1af4", ATTR{subsystem_device}=="0x1100", RUN+="/bin/sh -c '/bin/mkdir /run/gdm'"
+ATTR{vendor}=="0x1013", ATTR{device}=="0x00b8", ATTR{subsystem_vendor}=="0x1af4", ATTR{subsystem_device}=="0x1100", RUN+="/bin/sh -c '/bin/echo [daemon] >> /run/gdm/runtime.conf'"
+ATTR{vendor}=="0x1013", ATTR{device}=="0x00b8", ATTR{subsystem_vendor}=="0x1af4", ATTR{subsystem_device}=="0x1100", RUN+="/bin/sh -c '/bin/echo WaylandEnable=false >> /run/gdm/runtime.conf'"
diff --git a/data/Makefile.am b/data/Makefile.am
index c10c9151..93c03865 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -161,12 +161,16 @@ if ENABLE_ARCH_PAM_CONFIG
 pam_files = $(pam_arch_files)
 endif
 
+udevrulesdir = $(prefix)/lib/udev/rules.d
+udevrules_DATA = 61-gdm.rules
+
 EXTRA_DIST +=			\
 	$(dconf_db_files)	\
 	$(schemas_in_files)	\
 	$(schemas_DATA)		\
 	$(dbusconf_in_files)	\
 	$(localealias_DATA)	\
+	$(udevrules_DATA)	\
 	gdm.schemas.in.in	\
 	gdm.conf-custom.in 	\
 	Xsession.in 		\
