From c4fe54d004ae16b7b1933f4cce9165389641c46b Mon Sep 17 00:00:00 2001 From: Robert Bragg Date: Mon, 13 Oct 2008 12:23:47 +0100 Subject: [PATCH] Passes through the plugin manager and default plugin trying to rename terse variable names, simplify the plugin interface or consider tweaks for maintainability. * Renames plg -> plugin * Renames mgr ->plugin_mgr (since in a combined window and composite manager I think "mgr" will end up being ambiguous in places) * Renames PluginWorkspaceRectangle -> MetaRectangle (We are no longer concerned about mbwm2 portability) * Renames a few one letter variable names e.g. a -> window, r ->rect * Renames some vars to indicate what they represent not their data type, e.g. group1, group2 ->workspace0, workspace1 * Renames the variable mcw -> mc_window to make it more immediately obvious what it represents. * Removes the verbose META_COMPOSITOR_CLUTTER_PLUGIN_SWITCH_WORKSPACE macro, and just uses metacity_plugin instead. * Instead of hanging data of the plugins global descriptor, we just use a standalone static global variable. * Make do_init a function pointer inside the plugin descriptors instead of special casing it and using another g_module_symbol call. This also removes the need for the META_COMPOSITOR_CLUTTER_PLUGIN_INIT_FUNC macro. * A bunch of anal 80char fixes * Removes the screen_width,height variables from the plugin descriptor struct and add a plugin API instead. --- .../clutter/clutter-plugins/default.c | 412 +++++++--------- .../compositor-clutter-plugin-manager.c | 440 ++++++++++-------- src/include/compositor-clutter-plugin.h | 158 +++---- 3 files changed, 498 insertions(+), 512 deletions(-) diff --git a/src/compositor/clutter/clutter-plugins/default.c b/src/compositor/clutter/clutter-plugins/default.c index 92243d00a..d342d71d3 100644 --- a/src/compositor/clutter/clutter-plugins/default.c +++ b/src/compositor/clutter/clutter-plugins/default.c @@ -42,9 +42,7 @@ #define ACTOR_DATA_KEY "MCCP-Default-actor-data" static GQuark actor_data_quark = 0; -typedef struct PluginPrivate PluginPrivate; -typedef struct ActorPrivate ActorPrivate; - +static gboolean do_init (const char *params); static void minimize (MetaCompWindow *actor); static void map (MetaCompWindow *actor); static void destroy (MetaCompWindow *actor); @@ -58,14 +56,15 @@ static void switch_workspace (const GList **actors, gint from, gint to, static void kill_effect (MetaCompWindow *actor, gulong event); -static gboolean reload (void); +static gboolean reload (const char *params); + /* * First we create the header struct and initialize its static members. * Any dynamically allocated data should be initialized in the * init () function below. */ -MetaCompositorClutterPlugin META_COMPOSITOR_CLUTTER_PLUGIN_STRUCT = +G_MODULE_EXPORT MetaCompositorClutterPlugin metacity_plugin = { /* * These are predefined values; do not modify. @@ -78,6 +77,9 @@ MetaCompositorClutterPlugin META_COMPOSITOR_CLUTTER_PLUGIN_STRUCT = /* Human readable name (for use in UI) */ .name = "Default Effects", + /* Plugin load time initialiser */ + .do_init = do_init, + /* Which types of events this plugin supports */ .features = META_COMPOSITOR_CLUTTER_PLUGIN_MINIMIZE | META_COMPOSITOR_CLUTTER_PLUGIN_DESTROY | @@ -104,7 +106,7 @@ MetaCompositorClutterPlugin META_COMPOSITOR_CLUTTER_PLUGIN_STRUCT = /* * Plugin private data that we store in the .plugin_private member. */ -struct PluginPrivate +typedef struct _DefaultPluginState { ClutterEffectTemplate *destroy_effect; ClutterEffectTemplate *minimize_effect; @@ -120,12 +122,12 @@ struct PluginPrivate ClutterActor *desktop2; gboolean debug_mode : 1; -}; +} DefaultPluginState; /* * Per actor private data we attach to each actor. */ -struct ActorPrivate +typedef struct _ActorPrivate { ClutterActor *orig_parent; @@ -136,7 +138,9 @@ struct ActorPrivate gboolean is_minimized : 1; gboolean is_maximized : 1; -}; +} ActorPrivate; + +static DefaultPluginState *plugin_state; /* * Actor private data accessor @@ -168,26 +172,18 @@ get_actor_private (MetaCompWindow *actor) return priv; } -static inline -MetaCompositorClutterPlugin * -get_plugin () -{ - return &META_COMPOSITOR_CLUTTER_PLUGIN_STRUCT; -} - static void on_switch_workspace_effect_complete (ClutterActor *group, gpointer data) { - MetaCompositorClutterPlugin *plugin = get_plugin (); - PluginPrivate *ppriv = plugin->plugin_private; - GList *l = *((GList**)data); - MetaCompWindow *actor_for_cb = l->data; + DefaultPluginState *state = plugin_state; + GList *l = *((GList**)data); + MetaCompWindow *actor_for_cb = l->data; while (l) { ClutterActor *a = l->data; - MetaCompWindow *mcw = META_COMP_WINDOW (a); - ActorPrivate *priv = get_actor_private (mcw); + MetaCompWindow *mc_window = META_COMP_WINDOW (a); + ActorPrivate *priv = get_actor_private (mc_window); if (priv->orig_parent) { @@ -198,16 +194,16 @@ on_switch_workspace_effect_complete (ClutterActor *group, gpointer data) l = l->next; } - clutter_actor_destroy (ppriv->desktop1); - clutter_actor_destroy (ppriv->desktop2); + clutter_actor_destroy (state->desktop1); + clutter_actor_destroy (state->desktop2); - ppriv->actors = NULL; - ppriv->tml_switch_workspace1 = NULL; - ppriv->tml_switch_workspace2 = NULL; - ppriv->desktop1 = NULL; - ppriv->desktop2 = NULL; + state->actors = NULL; + state->tml_switch_workspace1 = NULL; + state->tml_switch_workspace2 = NULL; + state->desktop1 = NULL; + state->desktop2 = NULL; - meta_comp_clutter_plugin_effect_completed (plugin, actor_for_cb, + meta_comp_clutter_plugin_effect_completed (&metacity_plugin, actor_for_cb, META_COMPOSITOR_CLUTTER_PLUGIN_SWITCH_WORKSPACE); } @@ -215,33 +211,35 @@ static void switch_workspace (const GList **actors, gint from, gint to, MetaMotionDirection direction) { - MetaCompositorClutterPlugin *plugin = get_plugin (); - PluginPrivate *ppriv = plugin->plugin_private; + MetaCompositorClutterPlugin *plugin = &metacity_plugin; + DefaultPluginState *state = plugin_state; GList *l; gint n_workspaces; - ClutterActor *group1 = clutter_group_new (); - ClutterActor *group2 = clutter_group_new (); + ClutterActor *workspace0 = clutter_group_new (); + ClutterActor *workspace1 = clutter_group_new (); ClutterActor *stage; + int screen_width, screen_height; stage = meta_comp_clutter_plugin_get_stage (plugin); -#if 1 - clutter_actor_set_anchor_point (group2, - plugin->screen_width, - plugin->screen_height); - clutter_actor_set_position (group2, - plugin->screen_width, - plugin->screen_height); -#endif + meta_comp_clutter_plugin_query_screen_size (plugin, + &screen_width, + &screen_height); + clutter_actor_set_anchor_point (workspace1, + screen_width, + screen_height); + clutter_actor_set_position (workspace1, + screen_width, + screen_height); - clutter_actor_set_scale (group2, 0.0, 0.0); + clutter_actor_set_scale (workspace1, 0.0, 0.0); - clutter_container_add_actor (CLUTTER_CONTAINER (stage), group2); - clutter_container_add_actor (CLUTTER_CONTAINER (stage), group1); + clutter_container_add_actor (CLUTTER_CONTAINER (stage), workspace1); + clutter_container_add_actor (CLUTTER_CONTAINER (stage), workspace0); if (from == to) { - meta_comp_clutter_plugin_effect_completed (plugin, NULL, + meta_comp_clutter_plugin_effect_completed (&metacity_plugin, NULL, META_COMPOSITOR_CLUTTER_PLUGIN_SWITCH_WORKSPACE); return; } @@ -252,28 +250,29 @@ switch_workspace (const GList **actors, gint from, gint to, while (l) { - MetaCompWindow *mcw = l->data; - ActorPrivate *priv = get_actor_private (mcw); - ClutterActor *a = CLUTTER_ACTOR (mcw); - gint workspace; + MetaCompWindow *mc_window = l->data; + ActorPrivate *priv = get_actor_private (mc_window); + ClutterActor *window = CLUTTER_ACTOR (mc_window); + gint win_workspace; - workspace = meta_comp_window_get_workspace (mcw); + win_workspace = meta_comp_window_get_workspace (mc_window); - if (workspace == to || workspace == from) + if (win_workspace == to || win_workspace == from) { gint x, y; guint w, h; - clutter_actor_get_position (a, &x, &y); - clutter_actor_get_size (a, &w, &h); + clutter_actor_get_position (window, &x, &y); + clutter_actor_get_size (window, &w, &h); - priv->orig_parent = clutter_actor_get_parent (a); + priv->orig_parent = clutter_actor_get_parent (window); - clutter_actor_reparent (a, workspace == to ? group2 : group1); - clutter_actor_show_all (a); - clutter_actor_raise_top (a); + clutter_actor_reparent (window, + win_workspace == to ? workspace1 : workspace0); + clutter_actor_show_all (window); + clutter_actor_raise_top (window); } - else if (workspace < 0) + else if (win_workspace < 0) { /* Sticky window */ priv->orig_parent = NULL; @@ -281,27 +280,27 @@ switch_workspace (const GList **actors, gint from, gint to, else { /* Window on some other desktop */ - clutter_actor_hide (a); + clutter_actor_hide (window); priv->orig_parent = NULL; } l = l->prev; } - ppriv->actors = (GList **)actors; - ppriv->desktop1 = group1; - ppriv->desktop2 = group2; + state->actors = (GList **)actors; + state->desktop1 = workspace0; + state->desktop2 = workspace1; - ppriv->tml_switch_workspace2 = clutter_effect_scale ( - ppriv->switch_workspace_effect, - group2, 1.0, 1.0, - on_switch_workspace_effect_complete, - (gpointer)actors); + state->tml_switch_workspace2 = + clutter_effect_scale (state->switch_workspace_effect, + workspace1, 1.0, 1.0, + on_switch_workspace_effect_complete, + (gpointer)actors); - ppriv->tml_switch_workspace1 = clutter_effect_scale ( - ppriv->switch_workspace_effect, - group1, 0.0, 0.0, - NULL, NULL); + state->tml_switch_workspace1 = + clutter_effect_scale (state->switch_workspace_effect, + workspace0, 0.0, 0.0, + NULL, NULL); } @@ -316,24 +315,24 @@ on_minimize_effect_complete (ClutterActor *actor, gpointer data) * Must reverse the effect of the effect; must hide it first to ensure * that the restoration will not be visible. */ - MetaCompositorClutterPlugin *plugin = get_plugin (); ActorPrivate *apriv; - MetaCompWindow *mcw = META_COMP_WINDOW (actor); + MetaCompWindow *mc_window = META_COMP_WINDOW (actor); apriv = get_actor_private (META_COMP_WINDOW (actor)); apriv->tml_minimize = NULL; clutter_actor_hide (actor); + /* FIXME - we shouldn't assume the original scale, it should be saved + * at the start of the effect */ clutter_actor_set_scale (actor, 1.0, 1.0); clutter_actor_move_anchor_point_from_gravity (actor, CLUTTER_GRAVITY_NORTH_WEST); /* Decrease the running effect counter */ - plugin->running--; - + metacity_plugin.running--; /* Now notify the manager that we are done with this effect */ - meta_comp_clutter_plugin_effect_completed (plugin, mcw, + meta_comp_clutter_plugin_effect_completed (&metacity_plugin, mc_window, META_COMPOSITOR_CLUTTER_PLUGIN_MINIMIZE); } @@ -342,28 +341,26 @@ on_minimize_effect_complete (ClutterActor *actor, gpointer data) * completion). */ static void -minimize (MetaCompWindow *mcw) - +minimize (MetaCompWindow *mc_window) { - MetaCompositorClutterPlugin *plugin = get_plugin (); - PluginPrivate *priv = plugin->plugin_private; - MetaCompWindowType type; - ClutterActor *actor = CLUTTER_ACTOR (mcw); + DefaultPluginState *state = plugin_state; + MetaCompWindowType type; + ClutterActor *actor = CLUTTER_ACTOR (mc_window); - type = meta_comp_window_get_window_type (mcw); + type = meta_comp_window_get_window_type (mc_window); if (type == META_COMP_WINDOW_NORMAL) { - ActorPrivate *apriv = get_actor_private (mcw); + ActorPrivate *apriv = get_actor_private (mc_window); apriv->is_minimized = TRUE; clutter_actor_move_anchor_point_from_gravity (actor, CLUTTER_GRAVITY_CENTER); - META_COMPOSITOR_CLUTTER_PLUGIN_STRUCT.running++; + metacity_plugin.running++; - apriv->tml_minimize = clutter_effect_scale (priv->minimize_effect, + apriv->tml_minimize = clutter_effect_scale (state->minimize_effect, actor, 0.0, 0.0, @@ -372,7 +369,7 @@ minimize (MetaCompWindow *mcw) NULL); } else - meta_comp_clutter_plugin_effect_completed (plugin, mcw, + meta_comp_clutter_plugin_effect_completed (&metacity_plugin, mc_window, META_COMPOSITOR_CLUTTER_PLUGIN_MINIMIZE); } @@ -386,21 +383,21 @@ on_maximize_effect_complete (ClutterActor *actor, gpointer data) /* * Must reverse the effect of the effect. */ - MetaCompositorClutterPlugin *plugin = get_plugin (); - MetaCompWindow *mcw = META_COMP_WINDOW (actor); - ActorPrivate *apriv = get_actor_private (mcw); + MetaCompWindow *mc_window = META_COMP_WINDOW (actor); + ActorPrivate *apriv = get_actor_private (mc_window); apriv->tml_maximize = NULL; + /* FIXME - don't assume the original scale was 1.0 */ clutter_actor_set_scale (actor, 1.0, 1.0); clutter_actor_move_anchor_point_from_gravity (actor, CLUTTER_GRAVITY_NORTH_WEST); /* Decrease the running effect counter */ - plugin->running--; + metacity_plugin.running--; /* Now notify the manager that we are done with this effect */ - meta_comp_clutter_plugin_effect_completed (plugin, mcw, + meta_comp_clutter_plugin_effect_completed (&metacity_plugin, mc_window, META_COMPOSITOR_CLUTTER_PLUGIN_MAXIMIZE); } @@ -413,24 +410,22 @@ on_maximize_effect_complete (ClutterActor *actor, gpointer data) * (Something like a sound would be more appropriate.) */ static void -maximize (MetaCompWindow *mcw, +maximize (MetaCompWindow *mc_window, gint end_x, gint end_y, gint end_width, gint end_height) { - MetaCompositorClutterPlugin *plugin = get_plugin (); - PluginPrivate *priv = plugin->plugin_private; - MetaCompWindowType type; - ClutterActor *actor = CLUTTER_ACTOR (mcw); + MetaCompWindowType type; + ClutterActor *actor = CLUTTER_ACTOR (mc_window); gdouble scale_x = 1.0; gdouble scale_y = 1.0; gint anchor_x = 0; gint anchor_y = 0; - type = meta_comp_window_get_window_type (mcw); + type = meta_comp_window_get_window_type (mc_window); if (type == META_COMP_WINDOW_NORMAL) { - ActorPrivate *apriv = get_actor_private (mcw); + ActorPrivate *apriv = get_actor_private (mc_window); guint width, height; gint x, y; @@ -453,18 +448,19 @@ maximize (MetaCompWindow *mcw, clutter_actor_move_anchor_point (actor, anchor_x, anchor_y); - apriv->tml_maximize = clutter_effect_scale (priv->maximize_effect, - actor, - scale_x, - scale_y, - (ClutterEffectCompleteFunc) - on_maximize_effect_complete, - NULL); + apriv->tml_maximize = + clutter_effect_scale (plugin_state->maximize_effect, + actor, + scale_x, + scale_y, + (ClutterEffectCompleteFunc) + on_maximize_effect_complete, + NULL); return; } - meta_comp_clutter_plugin_effect_completed (plugin, mcw, + meta_comp_clutter_plugin_effect_completed (&metacity_plugin, mc_window, META_COMPOSITOR_CLUTTER_PLUGIN_MAXIMIZE); } @@ -474,23 +470,20 @@ maximize (MetaCompWindow *mcw, * (Just a skeleton code.) */ static void -unmaximize (MetaCompWindow *mcw, +unmaximize (MetaCompWindow *mc_window, gint end_x, gint end_y, gint end_width, gint end_height) { - MetaCompositorClutterPlugin *plugin = get_plugin (); - MetaCompWindowType type; - - type = meta_comp_window_get_window_type (mcw); + MetaCompWindowType type = meta_comp_window_get_window_type (mc_window); if (type == META_COMP_WINDOW_NORMAL) { - ActorPrivate *apriv = get_actor_private (mcw); + ActorPrivate *apriv = get_actor_private (mc_window); apriv->is_maximized = FALSE; } /* Do this conditionally, if the effect requires completion callback. */ - meta_comp_clutter_plugin_effect_completed (plugin, mcw, + meta_comp_clutter_plugin_effect_completed (&metacity_plugin, mc_window, META_COMPOSITOR_CLUTTER_PLUGIN_UNMAXIMIZE); } @@ -500,9 +493,8 @@ on_map_effect_complete (ClutterActor *actor, gpointer data) /* * Must reverse the effect of the effect. */ - MetaCompositorClutterPlugin *plugin = get_plugin (); - MetaCompWindow *mcw = META_COMP_WINDOW (actor); - ActorPrivate *apriv = get_actor_private (mcw); + MetaCompWindow *mc_window = META_COMP_WINDOW (actor); + ActorPrivate *apriv = get_actor_private (mc_window); apriv->tml_map = NULL; @@ -510,10 +502,10 @@ on_map_effect_complete (ClutterActor *actor, gpointer data) CLUTTER_GRAVITY_NORTH_WEST); /* Decrease the running effect counter */ - plugin->running--; + metacity_plugin.running--; /* Now notify the manager that we are done with this effect */ - meta_comp_clutter_plugin_effect_completed (plugin, mcw, + meta_comp_clutter_plugin_effect_completed (&metacity_plugin, mc_window, META_COMPOSITOR_CLUTTER_PLUGIN_MAP); } @@ -522,28 +514,26 @@ on_map_effect_complete (ClutterActor *actor, gpointer data) * completion). */ static void -map (MetaCompWindow *mcw) +map (MetaCompWindow *mc_window) { - MetaCompositorClutterPlugin *plugin = get_plugin (); - PluginPrivate *priv = plugin->plugin_private; MetaCompWindowType type; - ClutterActor *actor = CLUTTER_ACTOR (mcw); + ClutterActor *actor = CLUTTER_ACTOR (mc_window); - type = meta_comp_window_get_window_type (mcw); + type = meta_comp_window_get_window_type (mc_window); if (type == META_COMP_WINDOW_NORMAL) { - ActorPrivate *apriv = get_actor_private (mcw); + ActorPrivate *apriv = get_actor_private (mc_window); clutter_actor_move_anchor_point_from_gravity (actor, CLUTTER_GRAVITY_CENTER); - META_COMPOSITOR_CLUTTER_PLUGIN_STRUCT.running++; + metacity_plugin.running++; clutter_actor_set_scale (actor, 0.0, 0.0); clutter_actor_show (actor); - apriv->tml_map = clutter_effect_scale (priv->map_effect, + apriv->tml_map = clutter_effect_scale (plugin_state->map_effect, actor, 1.0, 1.0, @@ -555,7 +545,7 @@ map (MetaCompWindow *mcw) } else - meta_comp_clutter_plugin_effect_completed (plugin, mcw, + meta_comp_clutter_plugin_effect_completed (&metacity_plugin, mc_window, META_COMPOSITOR_CLUTTER_PLUGIN_MAP); } @@ -567,15 +557,15 @@ map (MetaCompWindow *mcw) static void on_destroy_effect_complete (ClutterActor *actor, gpointer data) { - MetaCompositorClutterPlugin *plugin = get_plugin (); - MetaCompWindow *mcw = META_COMP_WINDOW (actor); - ActorPrivate *apriv = get_actor_private (mcw); + MetaCompositorClutterPlugin *plugin = &metacity_plugin; + MetaCompWindow *mc_window = META_COMP_WINDOW (actor); + ActorPrivate *apriv = get_actor_private (mc_window); apriv->tml_destroy = NULL; - plugin->running--; + metacity_plugin.running--; - meta_comp_clutter_plugin_effect_completed (plugin, mcw, + meta_comp_clutter_plugin_effect_completed (plugin, mc_window, META_COMPOSITOR_CLUTTER_PLUGIN_DESTROY); } @@ -583,25 +573,23 @@ on_destroy_effect_complete (ClutterActor *actor, gpointer data) * Simple TV-out like effect. */ static void -destroy (MetaCompWindow *mcw) +destroy (MetaCompWindow *mc_window) { - MetaCompositorClutterPlugin *plugin = get_plugin (); - PluginPrivate *priv = plugin->plugin_private; - MetaCompWindowType type; - ClutterActor *actor = CLUTTER_ACTOR (mcw); + MetaCompWindowType type; + ClutterActor *actor = CLUTTER_ACTOR (mc_window); - type = meta_comp_window_get_window_type (mcw); + type = meta_comp_window_get_window_type (mc_window); if (type == META_COMP_WINDOW_NORMAL) { - ActorPrivate *apriv = get_actor_private (mcw); + ActorPrivate *apriv = get_actor_private (mc_window); clutter_actor_move_anchor_point_from_gravity (actor, CLUTTER_GRAVITY_CENTER); - plugin->running++; + metacity_plugin.running++; - apriv->tml_destroy = clutter_effect_scale (priv->destroy_effect, + apriv->tml_destroy = clutter_effect_scale (plugin_state->destroy_effect, actor, 1.0, 0.0, @@ -610,16 +598,16 @@ destroy (MetaCompWindow *mcw) NULL); } else - meta_comp_clutter_plugin_effect_completed (plugin, mcw, + meta_comp_clutter_plugin_effect_completed (&metacity_plugin, mc_window, META_COMPOSITOR_CLUTTER_PLUGIN_DESTROY); } static void -kill_effect (MetaCompWindow *mcw, gulong event) +kill_effect (MetaCompWindow *mc_window, gulong event) { - MetaCompositorClutterPlugin *plugin = get_plugin (); + MetaCompositorClutterPlugin *plugin = &metacity_plugin; ActorPrivate *apriv; - ClutterActor *actor = CLUTTER_ACTOR (mcw); + ClutterActor *actor = CLUTTER_ACTOR (mc_window); if (!(plugin->features & event)) { @@ -629,13 +617,13 @@ kill_effect (MetaCompWindow *mcw, gulong event) if (event & META_COMPOSITOR_CLUTTER_PLUGIN_SWITCH_WORKSPACE) { - PluginPrivate *ppriv = plugin->plugin_private; + DefaultPluginState *state = plugin_state; - if (ppriv->tml_switch_workspace1) + if (state->tml_switch_workspace1) { - clutter_timeline_stop (ppriv->tml_switch_workspace1); - clutter_timeline_stop (ppriv->tml_switch_workspace2); - on_switch_workspace_effect_complete (ppriv->desktop1, ppriv->actors); + clutter_timeline_stop (state->tml_switch_workspace1); + clutter_timeline_stop (state->tml_switch_workspace2); + on_switch_workspace_effect_complete (state->desktop1, state->actors); } if (!(event & ~META_COMPOSITOR_CLUTTER_PLUGIN_SWITCH_WORKSPACE)) @@ -645,7 +633,7 @@ kill_effect (MetaCompWindow *mcw, gulong event) } } - apriv = get_actor_private (mcw); + apriv = get_actor_private (mc_window); if ((event & META_COMPOSITOR_CLUTTER_PLUGIN_MINIMIZE) && apriv->tml_minimize) { @@ -694,36 +682,23 @@ g_module_check_init (GModule *module) * by the reload() function. Returns TRUE on success. */ static gboolean -do_init () +do_init (const char *params) { - MetaCompositorClutterPlugin *plugin = get_plugin (); + guint destroy_timeout = DESTROY_TIMEOUT; + guint minimize_timeout = MINIMIZE_TIMEOUT; + guint maximize_timeout = MAXIMIZE_TIMEOUT; + guint map_timeout = MAP_TIMEOUT; + guint switch_timeout = SWITCH_TIMEOUT; - PluginPrivate *priv = g_new0 (PluginPrivate, 1); - const gchar *params; - guint destroy_timeout = DESTROY_TIMEOUT; - guint minimize_timeout = MINIMIZE_TIMEOUT; - guint maximize_timeout = MAXIMIZE_TIMEOUT; - guint map_timeout = MAP_TIMEOUT; - guint switch_timeout = SWITCH_TIMEOUT; - const gchar *name; - - plugin->plugin_private = priv; - - name = plugin->name; - plugin->name = _(name); - - params = plugin->params; + plugin_state = g_new0 (DefaultPluginState, 1); if (params) { - gchar *p; - if (strstr (params, "debug")) { - g_debug ("%s: Entering debug mode.", - META_COMPOSITOR_CLUTTER_PLUGIN_STRUCT.name); + g_debug ("%s: Entering debug mode.", metacity_plugin.name); - priv->debug_mode = TRUE; + plugin_state->debug_mode = TRUE; /* * Double the effect duration to make them easier to observe. @@ -734,60 +709,30 @@ do_init () map_timeout *= 2; switch_timeout *= 2; } - - if ((p = strstr (params, "disable:"))) - { - gchar *d = g_strdup (p+8); - - p = strchr (d, ';'); - - if (p) - *p = 0; - - if (strstr (d, "minimize")) - plugin->features &= ~ META_COMPOSITOR_CLUTTER_PLUGIN_MINIMIZE; - - if (strstr (d, "maximize")) - plugin->features &= ~ META_COMPOSITOR_CLUTTER_PLUGIN_MAXIMIZE; - - if (strstr (d, "unmaximize")) - plugin->features &= ~ META_COMPOSITOR_CLUTTER_PLUGIN_UNMAXIMIZE; - - if (strstr (d, "map")) - plugin->features &= ~ META_COMPOSITOR_CLUTTER_PLUGIN_MAP; - - if (strstr (d, "destroy")) - plugin->features &= ~ META_COMPOSITOR_CLUTTER_PLUGIN_DESTROY; - - if (strstr (d, "switch-workspace")) - plugin->features &= ~META_COMPOSITOR_CLUTTER_PLUGIN_SWITCH_WORKSPACE; - - g_free (d); - } } - priv->destroy_effect + plugin_state->destroy_effect = clutter_effect_template_new (clutter_timeline_new_for_duration ( destroy_timeout), CLUTTER_ALPHA_SINE_INC); - priv->minimize_effect + plugin_state->minimize_effect = clutter_effect_template_new (clutter_timeline_new_for_duration ( minimize_timeout), CLUTTER_ALPHA_SINE_INC); - priv->maximize_effect + plugin_state->maximize_effect = clutter_effect_template_new (clutter_timeline_new_for_duration ( maximize_timeout), CLUTTER_ALPHA_SINE_INC); - priv->map_effect + plugin_state->map_effect = clutter_effect_template_new (clutter_timeline_new_for_duration ( map_timeout), CLUTTER_ALPHA_SINE_INC); - priv->switch_workspace_effect + plugin_state->switch_workspace_effect = clutter_effect_template_new (clutter_timeline_new_for_duration ( switch_timeout), CLUTTER_ALPHA_SINE_INC); @@ -795,22 +740,15 @@ do_init () return TRUE; } -META_COMPOSITOR_CLUTTER_PLUGIN_INIT_FUNC -{ - return do_init (); -} - static void -free_plugin_private (PluginPrivate *priv) +free_plugin_private (DefaultPluginState *state) { - g_object_unref (priv->destroy_effect); - g_object_unref (priv->minimize_effect); - g_object_unref (priv->maximize_effect); - g_object_unref (priv->switch_workspace_effect); + g_object_unref (state->destroy_effect); + g_object_unref (state->minimize_effect); + g_object_unref (state->maximize_effect); + g_object_unref (state->switch_workspace_effect); - g_free (priv); - - META_COMPOSITOR_CLUTTER_PLUGIN_STRUCT.plugin_private = NULL; + g_free (state); } /* @@ -818,22 +756,22 @@ free_plugin_private (PluginPrivate *priv) * changed. */ static gboolean -reload () +reload (const char *params) { - PluginPrivate *priv; + DefaultPluginState *state; - priv = META_COMPOSITOR_CLUTTER_PLUGIN_STRUCT.plugin_private; + state = plugin_state; - if (do_init ()) + if (do_init (params)) { - /* Success; free the old private struct */ - free_plugin_private (priv); + /* Success; free the old state */ + free_plugin_private (plugin_state); return TRUE; } else { - /* Fail -- fall back to the old private. */ - META_COMPOSITOR_CLUTTER_PLUGIN_STRUCT.plugin_private = priv; + /* Fail -- fall back to the old state. */ + plugin_state = state; } return FALSE; @@ -842,12 +780,10 @@ reload () /* * GModule unload function -- do any cleanup required. */ -void g_module_unload (GModule *module); -void g_module_unload (GModule *module) +G_MODULE_EXPORT void g_module_unload (GModule *module); +G_MODULE_EXPORT void +g_module_unload (GModule *module) { - PluginPrivate *priv; - - priv = META_COMPOSITOR_CLUTTER_PLUGIN_STRUCT.plugin_private; - - free_plugin_private (priv); + free_plugin_private (plugin_state); } + diff --git a/src/compositor/clutter/compositor-clutter-plugin-manager.c b/src/compositor/clutter/compositor-clutter-plugin-manager.c index b9c7b740d..616797f2f 100644 --- a/src/compositor/clutter/compositor-clutter-plugin-manager.c +++ b/src/compositor/clutter/compositor-clutter-plugin-manager.c @@ -30,7 +30,8 @@ #include #include -static gboolean meta_compositor_clutter_plugin_manager_reload (MetaCompositorClutterPluginManager *mgr); +static gboolean meta_compositor_clutter_plugin_manager_reload ( + MetaCompositorClutterPluginManager *plugin_mgr); struct MetaCompositorClutterPluginManager { @@ -42,23 +43,23 @@ struct MetaCompositorClutterPluginManager guint idle_unload_id; }; -typedef struct MetaCompositorClutterPluginPrivate MetaCompositorClutterPluginPrivate; - -struct MetaCompositorClutterPluginPrivate +typedef struct MetaCompositorClutterPluginPrivate { + char *name; MetaCompositorClutterPluginManager *self; GModule *module; + gulong features; gboolean disabled : 1; -}; +} MetaCompositorClutterPluginPrivate; static void -free_plugin_workspaces (MetaCompositorClutterPlugin *plg) +free_plugin_workspaces (MetaCompositorClutterPlugin *plugin) { GList *l; - l = plg->work_areas; + l = plugin->work_areas; while (l) { @@ -66,21 +67,21 @@ free_plugin_workspaces (MetaCompositorClutterPlugin *plg) l = l->next; } - if (plg->work_areas) - g_list_free (plg->work_areas); + if (plugin->work_areas) + g_list_free (plugin->work_areas); - plg->work_areas = NULL; + plugin->work_areas = NULL; } /* * Gets work area geometry and stores it in list in the plugin. * - * If the plg list is already populated, we simply replace it (we are dealing - * with a small number of items in the list and unfrequent changes). + * If the plugin list is already populated, we simply replace it (we are + * dealing with a small number of items in the list and unfrequent changes). */ static void update_plugin_workspaces (MetaScreen *screen, - MetaCompositorClutterPlugin *plg) + MetaCompositorClutterPlugin *plugin) { GList *l, *l2 = NULL; @@ -89,9 +90,9 @@ update_plugin_workspaces (MetaScreen *screen, while (l) { MetaWorkspace *w = l->data; - PluginWorkspaceRectangle *r; + MetaRectangle *r; - r = g_new0 (PluginWorkspaceRectangle, 1); + r = g_new0 (MetaRectangle, 1); meta_workspace_get_work_area_all_xineramas (w, (MetaRectangle*)r); @@ -100,9 +101,57 @@ update_plugin_workspaces (MetaScreen *screen, l = l->next; } - free_plugin_workspaces (plg); + free_plugin_workspaces (plugin); - plg->work_areas = l2; + plugin->work_areas = l2; +} + +/** + * parse_disable_params: + * @params: as read from gconf, a ':' seperated list of plugin options + * @features: The mask of features the plugin advertises + * + * This function returns a new mask of features removing anything that + * the user has disabled. + */ +static gulong +parse_disable_params (const char *params, gulong features) +{ + char *p; + + if (!params) + return features; + + if ((p = strstr (params, "disable:"))) + { + gchar *d = g_strdup (p+8); + + p = strchr (d, ';'); + + if (p) + *p = 0; + + if (strstr (d, "minimize")) + features &= ~ META_COMPOSITOR_CLUTTER_PLUGIN_MINIMIZE; + + if (strstr (d, "maximize")) + features &= ~ META_COMPOSITOR_CLUTTER_PLUGIN_MAXIMIZE; + + if (strstr (d, "unmaximize")) + features &= ~ META_COMPOSITOR_CLUTTER_PLUGIN_UNMAXIMIZE; + + if (strstr (d, "map")) + features &= ~ META_COMPOSITOR_CLUTTER_PLUGIN_MAP; + + if (strstr (d, "destroy")) + features &= ~ META_COMPOSITOR_CLUTTER_PLUGIN_DESTROY; + + if (strstr (d, "switch-workspace")) + features &= ~META_COMPOSITOR_CLUTTER_PLUGIN_SWITCH_WORKSPACE; + + g_free (d); + } + return features; } /* @@ -110,51 +159,48 @@ update_plugin_workspaces (MetaScreen *screen, * struct. */ static MetaCompositorClutterPlugin * -meta_compositor_clutter_plugin_load (MetaCompositorClutterPluginManager *mgr, - GModule *module, - const gchar *params) +meta_compositor_clutter_plugin_load ( + MetaCompositorClutterPluginManager *plugin_mgr, + GModule *module, + const gchar *params) { - MetaCompositorClutterPlugin *plg; + MetaCompositorClutterPlugin *plugin; - if (g_module_symbol (module, - META_COMPOSITOR_CLUTTER_PLUGIN_STRUCT_NAME, - (gpointer *)&plg)) + if (g_module_symbol (module, "metacity_plugin", (gpointer *)&plugin)) { - if (plg->version_api == METACITY_CLUTTER_PLUGIN_API_VERSION) + if (plugin->version_api == METACITY_CLUTTER_PLUGIN_API_VERSION) { MetaCompositorClutterPluginPrivate *priv; - gboolean (*init_func) (void); - priv = g_new0 (MetaCompositorClutterPluginPrivate, 1); - plg->params = g_strdup (params); - plg->manager_private = priv; - priv->module = module; - priv->self = mgr; + priv = g_new0 (MetaCompositorClutterPluginPrivate, 1); + priv->name = _(plugin->name); + priv->module = module; + priv->self = plugin_mgr; - meta_screen_get_size (mgr->screen, - &plg->screen_width, &plg->screen_height); + /* FIXME: instead of hanging private data of the plugin descriptor + * we could make the descriptor const if we were to hang it off + * a plugin manager structure */ + plugin->manager_private = priv; - update_plugin_workspaces (mgr->screen, plg); + update_plugin_workspaces (plugin_mgr->screen, plugin); + + priv->features = parse_disable_params (params, plugin->features); /* * Check for and run the plugin init function. */ - if (g_module_symbol (module, - META_COMPOSITOR_CLUTTER_PLUGIN_INIT_FUNC_NAME, - (gpointer *)&init_func) && - !init_func()) + if (!plugin->do_init || !(plugin->do_init (params))) { - g_free (plg->params); g_free (priv); - free_plugin_workspaces (plg); + free_plugin_workspaces (plugin); return NULL; } - meta_verbose ("Loaded plugin [%s]\n", plg->name); + meta_verbose ("Loaded plugin [%s]\n", priv->name); - return plg; + return plugin; } } @@ -167,25 +213,22 @@ meta_compositor_clutter_plugin_load (MetaCompositorClutterPluginManager *mgr, * removal later. */ static gboolean -meta_compositor_clutter_plugin_unload (MetaCompositorClutterPlugin *plg) +meta_compositor_clutter_plugin_unload (MetaCompositorClutterPlugin *plugin) { MetaCompositorClutterPluginPrivate *priv; GModule *module; - priv = plg->manager_private; + priv = plugin->manager_private; module = priv->module; - if (plg->running) + if (plugin->running) { priv->disabled = TRUE; return FALSE; } - g_free (plg->params); - plg->params = NULL; - g_free (priv); - plg->manager_private = NULL; + plugin->manager_private = NULL; g_module_close (module); @@ -197,23 +240,24 @@ meta_compositor_clutter_plugin_unload (MetaCompositorClutterPlugin *plg) * pending for removal. */ static gboolean -meta_compositor_clutter_plugin_manager_idle_unload (MetaCompositorClutterPluginManager *mgr) +meta_compositor_clutter_plugin_manager_idle_unload ( + MetaCompositorClutterPluginManager *plugin_mgr) { - GList *l = mgr->unload; + GList *l = plugin_mgr->unload; gboolean dont_remove = TRUE; while (l) { - MetaCompositorClutterPlugin *plg = l->data; + MetaCompositorClutterPlugin *plugin = l->data; - if (meta_compositor_clutter_plugin_unload (plg)) + if (meta_compositor_clutter_plugin_unload (plugin)) { /* Remove from list */ GList *p = l->prev; GList *n = l->next; if (!p) - mgr->unload = n; + plugin_mgr->unload = n; else p->next = n; @@ -228,11 +272,11 @@ meta_compositor_clutter_plugin_manager_idle_unload (MetaCompositorClutterPluginM l = l->next; } - if (!mgr->unload) + if (!plugin_mgr->unload) { /* If no more unloads are pending, remove the handler as well */ dont_remove = FALSE; - mgr->idle_unload_id = 0; + plugin_mgr->idle_unload_id = 0; } return dont_remove; @@ -242,47 +286,48 @@ meta_compositor_clutter_plugin_manager_idle_unload (MetaCompositorClutterPluginM * Unloads all plugins */ static void -meta_compositor_clutter_plugin_manager_unload (MetaCompositorClutterPluginManager *mgr) +meta_compositor_clutter_plugin_manager_unload ( + MetaCompositorClutterPluginManager *plugin_mgr) { - GList *plugins = mgr->plugins; + GList *plugins = plugin_mgr->plugins; while (plugins) { - MetaCompositorClutterPlugin *plg = plugins->data; + MetaCompositorClutterPlugin *plugin = plugins->data; /* If the plugin could not be removed, move it to the unload list */ - if (!meta_compositor_clutter_plugin_unload (plg)) + if (!meta_compositor_clutter_plugin_unload (plugin)) { - mgr->unload = g_list_prepend (mgr->unload, plg); + plugin_mgr->unload = g_list_prepend (plugin_mgr->unload, plugin); - if (!mgr->idle_unload_id) + if (!plugin_mgr->idle_unload_id) { - mgr->idle_unload_id = g_idle_add ((GSourceFunc) + plugin_mgr->idle_unload_id = g_idle_add ((GSourceFunc) meta_compositor_clutter_plugin_manager_idle_unload, - mgr); + plugin_mgr); } } plugins = plugins->next; } - g_list_free (mgr->plugins); - mgr->plugins = NULL; + g_list_free (plugin_mgr->plugins); + plugin_mgr->plugins = NULL; } static void prefs_changed_callback (MetaPreference pref, void *data) { - MetaCompositorClutterPluginManager *mgr = data; + MetaCompositorClutterPluginManager *plugin_mgr = data; if (pref == META_PREF_CLUTTER_PLUGINS) { - meta_compositor_clutter_plugin_manager_reload (mgr); + meta_compositor_clutter_plugin_manager_reload (plugin_mgr); } else if (pref == META_PREF_NUM_WORKSPACES) { - meta_compositor_clutter_plugin_manager_update_workspaces (mgr); + meta_compositor_clutter_plugin_manager_update_workspaces (plugin_mgr); } } @@ -290,7 +335,8 @@ prefs_changed_callback (MetaPreference pref, * Loads all plugins listed in gconf registry. */ static gboolean -meta_compositor_clutter_plugin_manager_load (MetaCompositorClutterPluginManager *mgr) +meta_compositor_clutter_plugin_manager_load ( + MetaCompositorClutterPluginManager *plugin_mgr) { const gchar *dpath = METACITY_PKGLIBDIR "/plugins/clutter/"; GSList *plugins, *fallback = NULL; @@ -308,17 +354,17 @@ meta_compositor_clutter_plugin_manager_load (MetaCompositorClutterPluginManager while (plugins) { - gchar *plg_string; + gchar *plugin_string; gchar *params; - plg_string = g_strdup (plugins->data); + plugin_string = g_strdup (plugins->data); - if (plg_string) + if (plugin_string) { - GModule *plg; + GModule *plugin; gchar *path; - params = strchr (plg_string, ':'); + params = strchr (plugin_string, ':'); if (params) { @@ -326,26 +372,26 @@ meta_compositor_clutter_plugin_manager_load (MetaCompositorClutterPluginManager ++params; } - path = g_strconcat (dpath, plg_string, ".so", NULL); + path = g_strconcat (dpath, plugin_string, ".so", NULL); - if ((plg = g_module_open (path, 0))) + if ((plugin = g_module_open (path, 0))) { MetaCompositorClutterPlugin *p; - if ((p = meta_compositor_clutter_plugin_load (mgr, - plg, params))) - mgr->plugins = g_list_prepend (mgr->plugins, p); + if ((p = meta_compositor_clutter_plugin_load (plugin_mgr, + plugin, params))) + plugin_mgr->plugins = g_list_prepend (plugin_mgr->plugins, p); else { g_message ("Plugin load for [%s] failed\n", path); - g_module_close (plg); + g_module_close (plugin); } } else g_message ("Unable to load plugin [%s]\n", path); g_free (path); - g_free (plg_string); + g_free (plugin_string); } plugins = plugins->next; @@ -355,9 +401,9 @@ meta_compositor_clutter_plugin_manager_load (MetaCompositorClutterPluginManager if (fallback) g_slist_free (fallback); - if (mgr->plugins != NULL) + if (plugin_mgr->plugins != NULL) { - meta_prefs_add_listener (prefs_changed_callback, mgr); + meta_prefs_add_listener (prefs_changed_callback, plugin_mgr); return TRUE; } @@ -368,44 +414,47 @@ meta_compositor_clutter_plugin_manager_load (MetaCompositorClutterPluginManager * Reloads all plugins */ static gboolean -meta_compositor_clutter_plugin_manager_reload (MetaCompositorClutterPluginManager *mgr) +meta_compositor_clutter_plugin_manager_reload ( + MetaCompositorClutterPluginManager *plugin_mgr) { /* TODO -- brute force; should we build a list of plugins to load and list of * plugins to unload? We are probably not going to have large numbers of * plugins loaded at the same time, so it might not be worth it. */ - meta_compositor_clutter_plugin_manager_unload (mgr); - return meta_compositor_clutter_plugin_manager_load (mgr); + meta_compositor_clutter_plugin_manager_unload (plugin_mgr); + return meta_compositor_clutter_plugin_manager_load (plugin_mgr); } static gboolean -meta_compositor_clutter_plugin_manager_init (MetaCompositorClutterPluginManager *mgr) +meta_compositor_clutter_plugin_manager_init ( + MetaCompositorClutterPluginManager *plugin_mgr) { - return meta_compositor_clutter_plugin_manager_load (mgr); + return meta_compositor_clutter_plugin_manager_load (plugin_mgr); } void -meta_compositor_clutter_plugin_manager_update_workspace (MetaCompositorClutterPluginManager *mgr, MetaWorkspace *w) +meta_compositor_clutter_plugin_manager_update_workspace ( + MetaCompositorClutterPluginManager *plugin_mgr, MetaWorkspace *workspace) { GList *l; - gint n; + gint index; - n = meta_workspace_index (w); - l = mgr->plugins; + index = meta_workspace_index (workspace); + l = plugin_mgr->plugins; while (l) { - MetaCompositorClutterPlugin *plg = l->data; - PluginWorkspaceRectangle *r = g_list_nth_data (plg->work_areas, n); + MetaCompositorClutterPlugin *plugin = l->data; + MetaRectangle *rect = g_list_nth_data (plugin->work_areas, index); - if (r) + if (rect) { - meta_workspace_get_work_area_all_xineramas (w, (MetaRectangle*)r); + meta_workspace_get_work_area_all_xineramas (workspace, rect); } else { /* Something not entirely right; redo the whole thing */ - update_plugin_workspaces (mgr->screen, plg); + update_plugin_workspaces (plugin_mgr->screen, plugin); return; } @@ -414,16 +463,17 @@ meta_compositor_clutter_plugin_manager_update_workspace (MetaCompositorClutterPl } void -meta_compositor_clutter_plugin_manager_update_workspaces (MetaCompositorClutterPluginManager *mgr) +meta_compositor_clutter_plugin_manager_update_workspaces ( + MetaCompositorClutterPluginManager *plugin_mgr) { GList *l; - l = mgr->plugins; + l = plugin_mgr->plugins; while (l) { - MetaCompositorClutterPlugin *plg = l->data; + MetaCompositorClutterPlugin *plugin = l->data; - update_plugin_workspaces (mgr->screen, plg); + update_plugin_workspaces (plugin_mgr->screen, plugin); l = l->next; } @@ -432,35 +482,38 @@ meta_compositor_clutter_plugin_manager_update_workspaces (MetaCompositorClutterP MetaCompositorClutterPluginManager * meta_compositor_clutter_plugin_manager_new (MetaScreen *screen) { - MetaCompositorClutterPluginManager *mgr; + MetaCompositorClutterPluginManager *plugin_mgr; - mgr = g_new0 (MetaCompositorClutterPluginManager, 1); + plugin_mgr = g_new0 (MetaCompositorClutterPluginManager, 1); - mgr->screen = screen; + plugin_mgr->screen = screen; - if (!meta_compositor_clutter_plugin_manager_init (mgr)) + if (!meta_compositor_clutter_plugin_manager_init (plugin_mgr)) { - g_free (mgr); - mgr = NULL; + g_free (plugin_mgr); + plugin_mgr = NULL; } - return mgr; + return plugin_mgr; } static void -meta_compositor_clutter_plugin_manager_kill_effect (MetaCompositorClutterPluginManager *mgr, - MetaCompWindow *actor, - unsigned long events) +meta_compositor_clutter_plugin_manager_kill_effect ( + MetaCompositorClutterPluginManager *plugin_mgr, + MetaCompWindow *actor, + unsigned long events) { - GList *l = mgr->plugins; + GList *l = plugin_mgr->plugins; while (l) { - MetaCompositorClutterPlugin *plg = l->data; - MetaCompositorClutterPluginPrivate *priv = plg->manager_private; + MetaCompositorClutterPlugin *plugin = l->data; + MetaCompositorClutterPluginPrivate *priv = plugin->manager_private; - if (!priv->disabled && (plg->features & events) && plg->kill_effect) - plg->kill_effect (actor, events); + if (!priv->disabled + && (plugin->features & events) + && plugin->kill_effect) + plugin->kill_effect (actor, events); l = l->next; } @@ -479,46 +532,51 @@ meta_compositor_clutter_plugin_manager_kill_effect (MetaCompositorClutterPluginM * appropriate post-effect cleanup is carried out. */ gboolean -meta_compositor_clutter_plugin_manager_event_simple (MetaCompositorClutterPluginManager *mgr, - MetaCompWindow *actor, - unsigned long event) +meta_compositor_clutter_plugin_manager_event_simple ( + MetaCompositorClutterPluginManager *plugin_mgr, + MetaCompWindow *actor, + unsigned long event) { - GList *l = mgr->plugins; + GList *l = plugin_mgr->plugins; gboolean retval = FALSE; while (l) { - MetaCompositorClutterPlugin *plg = l->data; - MetaCompositorClutterPluginPrivate *priv = plg->manager_private; + MetaCompositorClutterPlugin *plugin = l->data; + MetaCompositorClutterPluginPrivate *priv = plugin->manager_private; - if (!priv->disabled && (plg->features & event)) + if (!priv->disabled && (plugin->features & event)) { retval = TRUE; switch (event) { case META_COMPOSITOR_CLUTTER_PLUGIN_MINIMIZE: - if (plg->minimize) + if (plugin->minimize) { - meta_compositor_clutter_plugin_manager_kill_effect (mgr, - actor, - ALL_BUT_SWITCH); - plg->minimize (actor); + meta_compositor_clutter_plugin_manager_kill_effect ( + plugin_mgr, + actor, + ALL_BUT_SWITCH); + + plugin->minimize (actor); } break; case META_COMPOSITOR_CLUTTER_PLUGIN_MAP: - if (plg->map) + if (plugin->map) { - meta_compositor_clutter_plugin_manager_kill_effect (mgr, - actor, - ALL_BUT_SWITCH); - plg->map (actor); + meta_compositor_clutter_plugin_manager_kill_effect ( + plugin_mgr, + actor, + ALL_BUT_SWITCH); + + plugin->map (actor); } break; case META_COMPOSITOR_CLUTTER_PLUGIN_DESTROY: - if (plg->destroy) + if (plugin->destroy) { - plg->destroy (actor); + plugin->destroy (actor); } break; default: @@ -542,46 +600,50 @@ meta_compositor_clutter_plugin_manager_event_simple (MetaCompositorClutterPlugin * appropriate post-effect cleanup is carried out. */ gboolean -meta_compositor_clutter_plugin_manager_event_maximize (MetaCompositorClutterPluginManager *mgr, - MetaCompWindow *actor, - unsigned long event, - gint target_x, - gint target_y, - gint target_width, - gint target_height) +meta_compositor_clutter_plugin_manager_event_maximize ( + MetaCompositorClutterPluginManager *plugin_mgr, + MetaCompWindow *actor, + unsigned long event, + gint target_x, + gint target_y, + gint target_width, + gint target_height) { - GList *l = mgr->plugins; + GList *l = plugin_mgr->plugins; gboolean retval = FALSE; while (l) { - MetaCompositorClutterPlugin *plg = l->data; - MetaCompositorClutterPluginPrivate *priv = plg->manager_private; + MetaCompositorClutterPlugin *plugin = l->data; + MetaCompositorClutterPluginPrivate *priv = plugin->manager_private; - if (!priv->disabled && (plg->features & event)) + if (!priv->disabled && (plugin->features & event)) { retval = TRUE; switch (event) { case META_COMPOSITOR_CLUTTER_PLUGIN_MAXIMIZE: - if (plg->maximize) + if (plugin->maximize) { - meta_compositor_clutter_plugin_manager_kill_effect (mgr, - actor, - ALL_BUT_SWITCH); - plg->maximize (actor, + meta_compositor_clutter_plugin_manager_kill_effect ( + plugin_mgr, + actor, + ALL_BUT_SWITCH); + + plugin->maximize (actor, target_x, target_y, target_width, target_height); } break; case META_COMPOSITOR_CLUTTER_PLUGIN_UNMAXIMIZE: - if (plg->unmaximize) + if (plugin->unmaximize) { - meta_compositor_clutter_plugin_manager_kill_effect (mgr, - actor, - ALL_BUT_SWITCH); - plg->unmaximize (actor, + meta_compositor_clutter_plugin_manager_kill_effect ( + plugin_mgr, + actor, + ALL_BUT_SWITCH); + plugin->unmaximize (actor, target_x, target_y, target_width, target_height); } @@ -606,31 +668,34 @@ meta_compositor_clutter_plugin_manager_event_maximize (MetaCompositorClutterPlug * appropriate post-effect cleanup is carried out. */ gboolean -meta_compositor_clutter_plugin_manager_switch_workspace (MetaCompositorClutterPluginManager *mgr, - const GList **actors, - gint from, - gint to, - MetaMotionDirection direction) +meta_compositor_clutter_plugin_manager_switch_workspace ( + MetaCompositorClutterPluginManager *plugin_mgr, + const GList **actors, + gint from, + gint to, + MetaMotionDirection direction) { - GList *l = mgr->plugins; + GList *l = plugin_mgr->plugins; gboolean retval = FALSE; while (l) { - MetaCompositorClutterPlugin *plg = l->data; - MetaCompositorClutterPluginPrivate *priv = plg->manager_private; + MetaCompositorClutterPlugin *plugin = l->data; + MetaCompositorClutterPluginPrivate *priv = plugin->manager_private; if (!priv->disabled && - (plg->features & META_COMPOSITOR_CLUTTER_PLUGIN_SWITCH_WORKSPACE) && + (plugin->features & META_COMPOSITOR_CLUTTER_PLUGIN_SWITCH_WORKSPACE) && (actors && *actors)) { - if (plg->switch_workspace) + if (plugin->switch_workspace) { retval = TRUE; - meta_compositor_clutter_plugin_manager_kill_effect (mgr, - META_COMP_WINDOW ((*actors)->data), - META_COMPOSITOR_CLUTTER_PLUGIN_SWITCH_WORKSPACE); - plg->switch_workspace (actors, from, to, direction); + meta_compositor_clutter_plugin_manager_kill_effect ( + plugin_mgr, + META_COMP_WINDOW ((*actors)->data), + META_COMPOSITOR_CLUTTER_PLUGIN_SWITCH_WORKSPACE); + + plugin->switch_workspace (actors, from, to, direction); } } @@ -649,23 +714,23 @@ meta_compositor_clutter_plugin_manager_switch_workspace (MetaCompositorClutterPl * appropriate post-effect cleanup is carried out. */ gboolean -meta_compositor_clutter_plugin_manager_xevent_filter - (MetaCompositorClutterPluginManager *mgr, XEvent *xev) +meta_compositor_clutter_plugin_manager_xevent_filter ( + MetaCompositorClutterPluginManager *plugin_mgr, XEvent *xev) { GList *l; - if (!mgr) + if (!plugin_mgr) return FALSE; - l = mgr->plugins; + l = plugin_mgr->plugins; while (l) { - MetaCompositorClutterPlugin *plg = l->data; + MetaCompositorClutterPlugin *plugin = l->data; - if (plg->xevent_filter) + if (plugin->xevent_filter) { - if (plg->xevent_filter (xev) == TRUE) + if (plugin->xevent_filter (xev) == TRUE) return TRUE; } @@ -682,18 +747,18 @@ ClutterActor * meta_comp_clutter_plugin_get_overlay_group (MetaCompositorClutterPlugin *plugin) { MetaCompositorClutterPluginPrivate *priv = plugin->manager_private; - MetaCompositorClutterPluginManager *mgr = priv->self; + MetaCompositorClutterPluginManager *plugin_mgr = priv->self; - return meta_compositor_clutter_get_overlay_group_for_screen (mgr->screen); + return meta_compositor_clutter_get_overlay_group_for_screen (plugin_mgr->screen); } ClutterActor * meta_comp_clutter_plugin_get_stage (MetaCompositorClutterPlugin *plugin) { MetaCompositorClutterPluginPrivate *priv = plugin->manager_private; - MetaCompositorClutterPluginManager *mgr = priv->self; + MetaCompositorClutterPluginManager *plugin_mgr = priv->self; - return meta_compositor_clutter_get_stage_for_screen (mgr->screen); + return meta_compositor_clutter_get_stage_for_screen (plugin_mgr->screen); } void @@ -710,3 +775,14 @@ meta_comp_clutter_plugin_effect_completed (MetaCompositorClutterPlugin *plugin, meta_compositor_clutter_window_effect_completed (actor, event); } +void +meta_comp_clutter_plugin_query_screen_size (MetaCompositorClutterPlugin *plugin, + int *width, + int *height) +{ + MetaCompositorClutterPluginPrivate *priv = plugin->manager_private; + MetaCompositorClutterPluginManager *plugin_mgr = priv->self; + + meta_screen_get_size (plugin_mgr->screen, width, height); +} + diff --git a/src/include/compositor-clutter-plugin.h b/src/include/compositor-clutter-plugin.h index 504d08294..8abcb5c15 100644 --- a/src/include/compositor-clutter-plugin.h +++ b/src/include/compositor-clutter-plugin.h @@ -34,65 +34,27 @@ /* * This file defines the plugin API. * - * Effects plugin is shared library loaded via dlopen(); it is recommended - * that the GModule API is used (otherwise you are on your own to do proper - * plugin clean up when the module is unloaded). + * Effects plugin is shared library loaded via g_module_open(); it is + * recommended that the GModule API is used (otherwise you are on your own to + * do proper plugin clean up when the module is unloaded). * * The plugin interface is exported via the MetaCompositorClutterPlugin struct. */ -/* - * Alias MetaRectangle to PluginWorkspaceRectangle in anticipation of - * making this file metacity-independent (we want the plugins to be portable - * between different WMs. - */ -typedef MetaRectangle PluginWorkspaceRectangle; - -/* - * The name of the header struct; use as: - * - * MetaCompositorClutterPlugin META_COMPOSITOR_CLUTTER_PLUGIN_STRUCT = - * { - * ... - * }; - * - * See clutter-plugins/simple.c for example code. - */ -#define META_COMPOSITOR_CLUTTER_PLUGIN_STRUCT MCCPS__ - -/* - * Definition for the plugin init function; use as: - * - * META_COMPOSITOR_CLUTTER_PLUGIN_INIT_FUNC - * { - * init code ... - * } - * - * See clutter-plugins/simple.c for example code. - */ -#define META_COMPOSITOR_CLUTTER_PLUGIN_INIT_FUNC \ - gboolean mccp_init__(void); \ - gboolean mccp_init__() - - -/* Private; must match the above */ -#define META_COMPOSITOR_CLUTTER_PLUGIN_STRUCT_NAME "MCCPS__" -#define META_COMPOSITOR_CLUTTER_PLUGIN_INIT_FUNC_NAME "mccp_init__" - typedef struct MetaCompositorClutterPlugin MetaCompositorClutterPlugin; /* * Feature flags: identify events that the plugin can handle; a plugin can * handle one or more events. */ -#define META_COMPOSITOR_CLUTTER_PLUGIN_MINIMIZE 0x00000001UL -#define META_COMPOSITOR_CLUTTER_PLUGIN_MAXIMIZE 0x00000002UL -#define META_COMPOSITOR_CLUTTER_PLUGIN_UNMAXIMIZE 0x00000004UL -#define META_COMPOSITOR_CLUTTER_PLUGIN_MAP 0x00000008UL -#define META_COMPOSITOR_CLUTTER_PLUGIN_DESTROY 0x00000010UL -#define META_COMPOSITOR_CLUTTER_PLUGIN_SWITCH_WORKSPACE 0x00000020UL +#define META_COMPOSITOR_CLUTTER_PLUGIN_MINIMIZE (1<<0) +#define META_COMPOSITOR_CLUTTER_PLUGIN_MAXIMIZE (1<<1) +#define META_COMPOSITOR_CLUTTER_PLUGIN_UNMAXIMIZE (1<<2) +#define META_COMPOSITOR_CLUTTER_PLUGIN_MAP (1<<3) +#define META_COMPOSITOR_CLUTTER_PLUGIN_DESTROY (1<<4) +#define META_COMPOSITOR_CLUTTER_PLUGIN_SWITCH_WORKSPACE (1<<5) -#define META_COMPOSITOR_CLUTTER_PLUGIN_ALL_EFFECTS 0xffffffffUL +#define META_COMPOSITOR_CLUTTER_PLUGIN_ALL_EFFECTS (~0) struct MetaCompositorClutterPlugin { @@ -117,6 +79,47 @@ struct MetaCompositorClutterPlugin #endif gchar *name; /* Human-readable name for UI */ gulong features; /* or-ed feature flags */ + + /* + * This function is called once the plugin has been loaded. + * + * @params is a string containing additional parameters for the plugin and is + * specified after the plugin name in the gconf database, separated by a + * colon. + * + * The following parameter tokens need to be handled by all + * plugins: + * + * 'debug' + * Indicates running in debug mode; the plugin + * might want to print useful debug info, or + * extend effect duration, etc. + * + * 'disable: ...;' + * + * The disable token indicates that the effects + * listed after the colon should be disabled. + * + * The list is comma-separated, terminated by a + * semicolon and consisting of the following + * tokens: + * + * minimize + * maximize + * unmaximize + * map + * destroy + * switch-workspace + * + * FIXME: ^^^ Instead of configuring in terms of what should be + * disabled, and needing a mechanism for coping with the user + * mistakenly not disabling the right things, it might be neater + * if plugins were enabled on a per effect basis in the first + * place. I.e. in gconf we could have effect:plugin key value + * pairs. + */ + + gboolean (*do_init) (const char *params); /* * Event handlers @@ -153,6 +156,7 @@ struct MetaCompositorClutterPlugin * Each actor in the list has a workspace number attached to it using * g_object_set_data() with key META_COMPOSITOR_CLUTTER_PLUGIN_WORKSPACE_KEY; * workspace < 0 indicates the window is sticky (i.e., on all desktops). + * TODO: Add accessor for sticky bit in new MetaCompWindow structure */ void (*switch_workspace) (const GList **actors, gint from, @@ -168,58 +172,22 @@ struct MetaCompositorClutterPlugin void (*kill_effect) (MetaCompWindow *actor, gulong events); - /* * The plugin manager will call this function when module should be reloaded. * This happens, for example, when the parameters for the plugin changed. */ - gboolean (*reload) (void); + gboolean (*reload) (const char *params); /* General XEvent filter. This is fired *before* metacity itself handles * an event. Return TRUE to block any further processing. - */ + */ gboolean (*xevent_filter) (XEvent *event); - -#ifdef META_COMPOSITOR_CLUTTER_BUILDING_PLUGIN - const -#endif - gchar *params; /* String containing additional parameters for the plugin; - * this is specified after the pluing name in the gconf - * database, separated by a colon. - * - * The following parameter tokens need to be handled by all - * plugins: - * - * 'debug' - * Indicates running in debug mode; the plugin - * might want to print useful debug info, or - * extend effect duration, etc. - * - * 'disable: ...;' - * - * The disable token indicates that the effects - * listed after the colon should be disabled. - * - * The list is comma-separated, terminated by a - * semicolon and consisting of the following - * tokens: - * - * minimize - * maximize - * unmaximize - * map - * destroy - * switch-workspace - */ - - gint screen_width; - gint screen_height; - - GList *work_areas; /* List of PluginWorkspaceRectangles defining the - * geometry of individual workspaces. - */ - + /* List of PluginWorkspaceRectangles defining the geometry of individual + * workspaces. */ + GList *work_areas; + + /* FIXME: It should be possible to hide this from plugins */ gint running; /* Plugin must increase this counter for each effect it starts * decrease it again once the effect finishes. */ @@ -243,4 +211,10 @@ meta_comp_clutter_plugin_get_overlay_group (MetaCompositorClutterPlugin *plugin) ClutterActor * meta_comp_clutter_plugin_get_stage (MetaCompositorClutterPlugin *plugin); -#endif + +void +meta_comp_clutter_plugin_query_screen_size (MetaCompositorClutterPlugin *plugin, + int *width, + int *height); + +#endif /* META_COMPOSITOR_CLUTTER_PLUGIN_H_ */