From 97a9726845d38071ef32c0e93948117e2da819de Mon Sep 17 00:00:00 2001 From: "Owen W. Taylor" Date: Mon, 12 Apr 2010 17:34:49 -0400 Subject: [PATCH] Add an explicit start() method for plugins Rather than using the plugin objects constructed() method for doing setup that requires the MetaScreen, add an explicit start() method that is called after the screen is set. The reason for this is that this allows plugin objects to be created early before the bulk of Metacity setup, which then allows plugins to affect how the setup happens. (For example, to change the way that preferences are loaded.) This is an incompatible change, since 'screen' is now not set in the constructed method, so the plugin API version is bumped. https://bugzilla.gnome.org/show_bug.cgi?id=615586 --- configure.in | 2 +- src/compositor/mutter-plugin-manager.c | 51 +++++++++----------------- src/compositor/mutter-plugin.c | 3 +- src/compositor/plugins/default.c | 8 ++-- src/include/mutter-plugin.h | 2 + 5 files changed, 25 insertions(+), 41 deletions(-) diff --git a/configure.in b/configure.in index bf2428843..50c3d719b 100644 --- a/configure.in +++ b/configure.in @@ -7,7 +7,7 @@ m4_define([mutter_micro_version], [1]) m4_define([mutter_version], [mutter_major_version.mutter_minor_version.mutter_micro_version]) -m4_define([mutter_plugin_api_version], [2]) +m4_define([mutter_plugin_api_version], [3]) AC_INIT([mutter], [mutter_version], [http://bugzilla.gnome.org/enter_bug.cgi?product=mutter]) diff --git a/src/compositor/mutter-plugin-manager.c b/src/compositor/mutter-plugin-manager.c index 26e6697da..712c701ac 100644 --- a/src/compositor/mutter-plugin-manager.c +++ b/src/compositor/mutter-plugin-manager.c @@ -45,20 +45,12 @@ struct MutterPluginManager { MetaScreen *screen; - GList /* MutterPluginPending */ *pending_plugin_modules; /* Plugins not yet fully loaded */ GList /* MutterPlugin */ *plugins; /* TODO -- maybe use hash table */ GList *unload; /* Plugins that are disabled and pending unload */ guint idle_unload_id; }; -typedef struct MutterPluginPending -{ - MutterModule *module; - char *path; - char *params; -} MutterPluginPending; - /* * Checks that the plugin is compatible with the WM and sets up the plugin * struct. @@ -78,7 +70,6 @@ mutter_plugin_load (MutterPluginManager *mgr, } plugin = g_object_new (plugin_type, - "screen", mgr->screen, "params", params, NULL); @@ -270,12 +261,14 @@ mutter_plugin_manager_load (MutterPluginManager *plugin_mgr) if (use_succeeded) { - MutterPluginPending *pending = g_new0 (MutterPluginPending, 1); - pending->module = module; - pending->path = g_strdup (path); - pending->params = g_strdup (params); - plugin_mgr->pending_plugin_modules = - g_list_prepend (plugin_mgr->pending_plugin_modules, pending); + MutterPlugin *plugin = mutter_plugin_load (plugin_mgr, module, params); + + if (plugin) + plugin_mgr->plugins = g_list_prepend (plugin_mgr->plugins, plugin); + else + g_warning ("Plugin load for [%s] failed", path); + + g_type_module_unuse (G_TYPE_MODULE (module)); } } else @@ -293,7 +286,7 @@ mutter_plugin_manager_load (MutterPluginManager *plugin_mgr) if (fallback) g_slist_free (fallback); - if (plugin_mgr->pending_plugin_modules != NULL) + if (plugin_mgr->plugins != NULL) { meta_prefs_add_listener (prefs_changed_callback, plugin_mgr); return TRUE; @@ -307,27 +300,19 @@ mutter_plugin_manager_initialize (MutterPluginManager *plugin_mgr) { GList *iter; - for (iter = plugin_mgr->pending_plugin_modules; iter; iter = iter->next) + for (iter = plugin_mgr->plugins; iter; iter = iter->next) { - MutterPluginPending *pending = (MutterPluginPending*) iter->data; - MutterPlugin *p; + MutterPlugin *plugin = (MutterPlugin*) iter->data; + MutterPluginClass *klass = MUTTER_PLUGIN_GET_CLASS (plugin); - if ((p = mutter_plugin_load (plugin_mgr, pending->module, pending->params))) - { - plugin_mgr->plugins = g_list_prepend (plugin_mgr->plugins, p); - } - else - { - g_warning ("Plugin load for [%s] failed", pending->path); - } + g_object_set (plugin, + "screen", plugin_mgr->screen, + NULL); - g_type_module_unuse (G_TYPE_MODULE (pending->module)); - g_free (pending->path); - g_free (pending->params); - g_free (pending); + if (klass->start) + klass->start (plugin); } - g_list_free (plugin_mgr->pending_plugin_modules); - plugin_mgr->pending_plugin_modules = NULL; + return TRUE; } diff --git a/src/compositor/mutter-plugin.c b/src/compositor/mutter-plugin.c index d60afffcd..4c6d4154b 100644 --- a/src/compositor/mutter-plugin.c +++ b/src/compositor/mutter-plugin.c @@ -238,8 +238,7 @@ mutter_plugin_class_init (MutterPluginClass *klass) "MetaScreen", "MetaScreen", META_TYPE_SCREEN, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY)); + G_PARAM_READWRITE)); g_object_class_install_property (gobject_class, PROP_PARAMS, diff --git a/src/compositor/plugins/default.c b/src/compositor/plugins/default.c index e4a5f2929..95deecf99 100644 --- a/src/compositor/plugins/default.c +++ b/src/compositor/plugins/default.c @@ -175,10 +175,9 @@ mutter_default_plugin_get_property (GObject *object, } static void -mutter_default_plugin_constructed (GObject *object) +start (MutterPlugin *plugin) { - MutterPlugin *plugin = MUTTER_PLUGIN (object); - MutterDefaultPluginPrivate *priv = MUTTER_DEFAULT_PLUGIN (object)->priv; + MutterDefaultPluginPrivate *priv = MUTTER_DEFAULT_PLUGIN (plugin)->priv; guint destroy_timeout = DESTROY_TIMEOUT; guint minimize_timeout = MINIMIZE_TIMEOUT; @@ -201,7 +200,6 @@ mutter_default_plugin_constructed (GObject *object) map_timeout *= 2; switch_timeout *= 2; } - } static void @@ -212,10 +210,10 @@ mutter_default_plugin_class_init (MutterDefaultPluginClass *klass) gobject_class->finalize = mutter_default_plugin_finalize; gobject_class->dispose = mutter_default_plugin_dispose; - gobject_class->constructed = mutter_default_plugin_constructed; gobject_class->set_property = mutter_default_plugin_set_property; gobject_class->get_property = mutter_default_plugin_get_property; + plugin_class->start = start; plugin_class->map = map; plugin_class->minimize = minimize; plugin_class->maximize = maximize; diff --git a/src/include/mutter-plugin.h b/src/include/mutter-plugin.h index 282b27221..4892c18f1 100644 --- a/src/include/mutter-plugin.h +++ b/src/include/mutter-plugin.h @@ -69,6 +69,8 @@ struct _MutterPluginClass { GObjectClass parent_class; + void (*start) (MutterPlugin *plugin); + void (*minimize) (MutterPlugin *plugin, MutterWindow *actor);