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
This commit is contained in:
Owen W. Taylor 2010-04-12 17:34:49 -04:00
parent 020aea033c
commit 97a9726845
5 changed files with 25 additions and 41 deletions

View File

@ -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])

View File

@ -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;
}

View File

@ -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,

View File

@ -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;

View File

@ -69,6 +69,8 @@ struct _MutterPluginClass
{
GObjectClass parent_class;
void (*start) (MutterPlugin *plugin);
void (*minimize) (MutterPlugin *plugin,
MutterWindow *actor);