[mutter/wip/display-no-wayland: 14/33] default plugin: add a random color background on each monitor



commit 169780346b686441283193df11dfbd0a9d8336a0
Author: Giovanni Campagna <gcampagn redhat com>
Date:   Tue Jul 23 11:53:04 2013 +0200

    default plugin: add a random color background on each monitor
    
    Instead of a full white background, make one with a random color.
    This way the different "monitors" are visible and it's easier
    to debug the DBus API.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=705670

 src/compositor/plugins/default.c |   53 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 53 insertions(+), 0 deletions(-)
---
diff --git a/src/compositor/plugins/default.c b/src/compositor/plugins/default.c
index 228fb19..067b128 100644
--- a/src/compositor/plugins/default.c
+++ b/src/compositor/plugins/default.c
@@ -24,6 +24,8 @@
 #include <meta/meta-plugin.h>
 #include <meta/window.h>
 #include <meta/util.h>
+#include <meta/meta-background-group.h>
+#include <meta/meta-background-actor.h>
 
 #include <libintl.h>
 #define _(x) dgettext (GETTEXT_PACKAGE, x)
@@ -113,6 +115,8 @@ struct _MetaDefaultPluginPrivate
   ClutterActor          *desktop1;
   ClutterActor          *desktop2;
 
+  ClutterActor          *background_group;
+
   MetaPluginInfo         info;
 };
 
@@ -300,8 +304,57 @@ show_stage (MetaPlugin *plugin)
 }
 
 static void
+on_monitors_changed (MetaScreen *screen,
+                     MetaPlugin *plugin)
+{
+  MetaDefaultPlugin *self = META_DEFAULT_PLUGIN (plugin);
+  int i, n;
+
+  clutter_actor_destroy_all_children (self->priv->background_group);
+
+  n = meta_screen_get_n_monitors (screen);
+  for (i = 0; i < n; i++)
+    {
+      MetaRectangle rect;
+      ClutterActor *background;
+      ClutterColor color;
+
+      meta_screen_get_monitor_geometry (screen, i, &rect);
+
+      background = meta_background_actor_new ();
+
+      clutter_actor_set_position (background, rect.x, rect.y);
+      clutter_actor_set_size (background, rect.width, rect.height);
+
+      /* Don't use rand() here, mesa calls srand() internally when
+         parsing the driconf XML, but it's nice if the colors are
+         reproducible.
+      */
+      clutter_color_init (&color,
+                          g_random_int () % 255,
+                          g_random_int () % 255,
+                          g_random_int () % 255,
+                          255);
+      clutter_actor_set_background_color (background, &color);
+
+      clutter_actor_add_child (self->priv->background_group, background);
+    }
+}
+
+static void
 start (MetaPlugin *plugin)
 {
+  MetaDefaultPlugin *self = META_DEFAULT_PLUGIN (plugin);
+  MetaScreen *screen = meta_plugin_get_screen (plugin);
+
+  self->priv->background_group = meta_background_group_new ();
+  clutter_actor_insert_child_below (meta_get_window_group_for_screen (screen),
+                                    self->priv->background_group, NULL);
+
+  g_signal_connect (screen, "monitors-changed",
+                    G_CALLBACK (on_monitors_changed), plugin);
+  on_monitors_changed (screen, plugin);
+
   meta_later_add (META_LATER_BEFORE_REDRAW,
                   (GSourceFunc) show_stage,
                   plugin,


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