[Xfce4-commits] <xfce4-panel:master> Move composited child function to plugin.

Nick Schermer noreply at xfce.org
Tue Dec 28 20:50:08 CET 2010


Updating branch refs/heads/master
         to c8bdf2b20efc0447ca7074e969ea1bc11582e72e (commit)
       from bdc17ee8fc838690a408054c2a48a4cb9e1d67eb (commit)

commit c8bdf2b20efc0447ca7074e969ea1bc11582e72e
Author: Nick Schermer <nick at xfce.org>
Date:   Sat Dec 25 12:13:06 2010 +0100

    Move composited child function to plugin.
    
    This makes it more obvious this is something special
    we need to do after Gtk's expose event to draw composited
    icons.

 plugins/systray/systray-box.c |   47 ------------------------------------
 plugins/systray/systray.c     |   53 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 53 insertions(+), 47 deletions(-)

diff --git a/plugins/systray/systray-box.c b/plugins/systray/systray-box.c
index 3814f6c..3c12770 100644
--- a/plugins/systray/systray-box.c
+++ b/plugins/systray/systray-box.c
@@ -53,8 +53,6 @@ static void     systray_box_size_request          (GtkWidget       *widget,
                                                    GtkRequisition  *requisition);
 static void     systray_box_size_allocate         (GtkWidget       *widget,
                                                    GtkAllocation   *allocation);
-static gboolean systray_box_expose_event          (GtkWidget       *widget,
-                                                   GdkEventExpose  *event);
 static void     systray_box_add                   (GtkContainer    *container,
                                                    GtkWidget       *child);
 static void     systray_box_remove                (GtkContainer    *container,
@@ -124,7 +122,6 @@ systray_box_class_init (SystrayBoxClass *klass)
   gtkwidget_class = GTK_WIDGET_CLASS (klass);
   gtkwidget_class->size_request = systray_box_size_request;
   gtkwidget_class->size_allocate = systray_box_size_allocate;
-  gtkwidget_class->expose_event = systray_box_expose_event;
 
   gtkcontainer_class = GTK_CONTAINER_CLASS (klass);
   gtkcontainer_class->add = systray_box_add;
@@ -417,50 +414,6 @@ systray_box_size_allocate (GtkWidget     *widget,
 
 
 
-static gboolean
-systray_box_expose_event (GtkWidget      *widget,
-                          GdkEventExpose *event)
-{
-  SystrayBox    *box = XFCE_SYSTRAY_BOX (widget);
-  cairo_t       *cr;
-  GtkWidget     *child;
-  GSList        *li;
-  gboolean       result;
-  GtkAllocation *child_alloc;
-
-  result = GTK_WIDGET_CLASS (systray_box_parent_class)->expose_event (widget, event);
-
-  if (gtk_widget_is_composited (widget))
-    {
-      cr = gdk_cairo_create (widget->window);
-      gdk_cairo_region (cr, event->region);
-      cairo_clip (cr);
-
-      for (li = box->childeren; li != NULL; li = li->next)
-        {
-          child = GTK_WIDGET (li->data);
-          child_alloc = &child->allocation;
-
-          /* skip invisible (offscreen) or not composited children */
-          if (child_alloc->x < 0
-              || child_alloc->y < 0
-              || !systray_socket_is_composited (XFCE_SYSTRAY_SOCKET (child)))
-            continue;
-
-          /* paint the child */
-          gdk_cairo_set_source_pixmap (cr, gtk_widget_get_window (child),
-                                       child_alloc->x, child_alloc->y);
-          cairo_paint (cr);
-        }
-
-      cairo_destroy (cr);
-    }
-
-  return result;
-}
-
-
-
 static void
 systray_box_add (GtkContainer *container,
                  GtkWidget    *child)
diff --git a/plugins/systray/systray.c b/plugins/systray/systray.c
index 16f2018..7629f47 100644
--- a/plugins/systray/systray.c
+++ b/plugins/systray/systray.c
@@ -54,6 +54,8 @@ static void     systray_plugin_orientation_changed          (XfcePanelPlugin
 static gboolean systray_plugin_size_changed                 (XfcePanelPlugin       *panel_plugin,
                                                              gint                   size);
 static void     systray_plugin_configure_plugin             (XfcePanelPlugin       *panel_plugin);
+static void     systray_plugin_box_expose_event             (GtkWidget             *box,
+                                                             GdkEventExpose        *event);
 static void     systray_plugin_button_toggled               (GtkWidget             *button,
                                                              SystrayPlugin         *plugin);
 static void     systray_plugin_button_set_arrow             (SystrayPlugin         *plugin);
@@ -217,6 +219,8 @@ systray_plugin_init (SystrayPlugin *plugin)
 
   plugin->box = systray_box_new ();
   gtk_box_pack_start (GTK_BOX (plugin->hvbox), plugin->box, TRUE, TRUE, 0);
+  g_signal_connect (G_OBJECT (plugin->box), "expose-event",
+      G_CALLBACK (systray_plugin_box_expose_event), NULL);
   gtk_widget_show (plugin->box);
 
   plugin->button = xfce_arrow_button_new (GTK_ARROW_RIGHT);
@@ -546,6 +550,55 @@ systray_plugin_configure_plugin (XfcePanelPlugin *panel_plugin)
 
 
 static void
+systray_plugin_box_expose_event_icon (GtkWidget *child,
+                                      gpointer   user_data)
+{
+  cairo_t       *cr = user_data;
+  GtkAllocation *alloc;
+
+  if (systray_socket_is_composited (XFCE_SYSTRAY_SOCKET (child)))
+    {
+      alloc = &child->allocation;
+
+      /* skip hidden (see offscreen in box widget) icons */
+      if (alloc->x > 0 && alloc->y > 0)
+        {
+          gdk_cairo_set_source_pixmap (cr, gtk_widget_get_window (child),
+                                       alloc->x, alloc->y);
+          cairo_paint (cr);
+        }
+    }
+}
+
+
+
+static void
+systray_plugin_box_expose_event (GtkWidget      *box,
+                                 GdkEventExpose *event)
+{
+  cairo_t *cr;
+
+  if (!gtk_widget_is_composited (box))
+    return;
+
+  cr = gdk_cairo_create (gtk_widget_get_window (box));
+  if (G_LIKELY (cr != NULL))
+    {
+      gdk_cairo_rectangle (cr, &event->area);
+      cairo_clip (cr);
+
+      /* separately draw all the composed tray icons after gtk
+       * handled the expose event */
+      gtk_container_foreach (GTK_CONTAINER (box),
+          systray_plugin_box_expose_event_icon, cr);
+
+      cairo_destroy (cr);
+    }
+}
+
+
+
+static void
 systray_plugin_button_toggled (GtkWidget     *button,
                                SystrayPlugin *plugin)
 {



More information about the Xfce4-commits mailing list