Simplify plugins background setting - they should never use any own background.
authorAndriy Grytsenko <andrej@rep.kiev.ua>
Sun, 30 Nov 2014 23:28:22 +0000 (01:28 +0200)
committerAndriy Grytsenko <andrej@rep.kiev.ua>
Sun, 30 Nov 2014 23:28:22 +0000 (01:28 +0200)
Widgets should either use one from panel or from theme (depending on the panel
configuration). This should improve performance.

ChangeLog
src/panel.c
src/plugin.c
src/private.h

index 1738214..f610510 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
     user attention (patch from Andy Balaam).
 * Moved bit of code that is used out from src/bg.c and discarded src/bg.c
     from code used.
+* Dropped setting members of Panel structure: workarea, wa_len, bg.
+* Replaced GtkComboBoxEntry in netstatus plugin window with GtkComboBox.
+* Simplified plugins background setting - they should never use any own
+    background but either use one from panel or from theme (depending on
+    panel configuration). This should improve performance.
 
 0.7.2
 -------------------------------------------------------------------------
index 25542c9..b95f577 100644 (file)
@@ -674,37 +674,23 @@ static void paint_root_pixmap(LXPanel *panel, cairo_t *cr)
 #endif
 }
 
-void panel_determine_background_pixmap(Panel * panel, GtkWidget * widget, GdkWindow * window)
-{
-    _panel_determine_background_pixmap(panel->topgwin, widget);
-}
-
-void _panel_determine_background_pixmap(LXPanel * panel, GtkWidget * widget)
+void _panel_determine_background_pixmap(LXPanel * panel)
 {
 #if GTK_CHECK_VERSION(3, 0, 0)
-    cairo_surface_t *surface;
     cairo_pattern_t *pattern;
 #else
     GdkPixmap * pixmap = NULL;
 #endif
+    GtkWidget * widget = GTK_WIDGET(panel);
     GdkWindow * window = gtk_widget_get_window(widget);
     Panel * p = panel->priv;
     cairo_t *cr;
-    GtkAllocation alloc;
     gint x = 0, y = 0;
 
     if (!p->background && !p->transparent)
         goto not_paintable;
     else if (p->aw <= 1 || p->ah <= 1)
         goto not_paintable;
-#if GTK_CHECK_VERSION(3, 0, 0)
-    else if (GTK_WIDGET(panel) != widget)
-    {
-        /* reset background for the child, using background of panel */
-        gdk_window_set_background_pattern(window, NULL);
-        return;
-    }
-#endif
     else if (p->surface == NULL)
     {
         GdkPixbuf *pixbuf = NULL;
@@ -749,25 +735,16 @@ void _panel_determine_background_pixmap(LXPanel * panel, GtkWidget * widget)
     if (p->surface != NULL)
     {
         gtk_widget_set_app_paintable(widget, TRUE);
-        gtk_widget_get_allocation(widget, &alloc);
 #if GTK_CHECK_VERSION(3, 0, 0)
-        surface = gdk_window_create_similar_surface(window, CAIRO_CONTENT_COLOR_ALPHA,
-                                                    alloc.width, alloc.height);
-        cr = cairo_create(surface);
+        pattern = cairo_pattern_create_for_surface(p->surface);
+        gdk_window_set_background_pattern(window, pattern);
+        cairo_pattern_destroy(pattern);
 #else
-        pixmap = gdk_pixmap_new(window, alloc.width, alloc.height, -1);
+        pixmap = gdk_pixmap_new(window, p->aw, p->ah, -1);
         cr = gdk_cairo_create(pixmap);
-#endif
-        gtk_widget_translate_coordinates(widget, GTK_WIDGET(panel), 0, 0, &x, &y);
-        cairo_set_source_surface(cr, p->surface, 0.0 - x, 0.0 - y);
+        cairo_set_source_surface(cr, p->surface, 0, 0);
         cairo_paint(cr);
         cairo_destroy(cr);
-#if GTK_CHECK_VERSION(3, 0, 0)
-        pattern = cairo_pattern_create_for_surface(surface);
-        gdk_window_set_background_pattern(window, pattern);
-        cairo_pattern_destroy(pattern);
-        cairo_surface_destroy(surface);
-#else
         gdk_window_set_back_pixmap(window, pixmap, FALSE);
         g_object_unref(pixmap);
 #endif
@@ -779,6 +756,23 @@ not_paintable:
     }
 }
 
+void panel_determine_background_pixmap(Panel * panel, GtkWidget * widget, GdkWindow * window)
+{
+    if (GTK_WIDGET(panel->topgwin) != widget)
+    {
+        /* Backward compatibility:
+           reset background for the child, using background of panel */
+        gtk_widget_set_app_paintable(widget, (panel->background || panel->transparent));
+#if GTK_CHECK_VERSION(3, 0, 0)
+        gdk_window_set_background_pattern(window, NULL);
+#else
+        gdk_window_set_back_pixmap(window, NULL, TRUE);
+#endif
+    }
+    else
+        _panel_determine_background_pixmap(panel->topgwin);
+}
+
 /* Update the background of the entire panel.
  * This function should only be called after the panel has been realized. */
 void panel_update_background(Panel * p)
@@ -799,7 +793,7 @@ static void _panel_update_background(LXPanel * p)
     }
 
     /* Redraw the top level widget. */
-    _panel_determine_background_pixmap(p, w);
+    _panel_determine_background_pixmap(p);
     gdk_window_clear(gtk_widget_get_window(w));
     gtk_widget_queue_draw(w);
 
index d38a5d9..035259e 100644 (file)
@@ -183,32 +183,26 @@ void plugin_widget_set_background(GtkWidget * w, LXPanel * panel)
 {
     if (w != NULL)
     {
-        Panel *p = panel->priv;
         if (gtk_widget_get_has_window(w))
         {
-            if ((p->background) || (p->transparent))
-            {
-                if (gtk_widget_get_realized(w))
-                {
-                    _panel_determine_background_pixmap(panel, w);
-                    gdk_window_invalidate_rect(gtk_widget_get_window(w), NULL, TRUE);
-                }
-            }
-            else
+            Panel *p = panel->priv;
+
+            gtk_widget_set_app_paintable(w, ((p->background) || (p->transparent)));
+            if (gtk_widget_get_realized(w))
             {
-                /* Set background according to the current GTK style. */
-                gtk_widget_set_app_paintable(w, FALSE);
-                if (gtk_widget_get_realized(w))
-                {
+                GdkWindow *window = gtk_widget_get_window(w);
 #if GTK_CHECK_VERSION(3, 0, 0)
-                    gdk_window_set_background_pattern(gtk_widget_get_window(w), NULL);
+                gdk_window_set_background_pattern(window, NULL);
 #else
-                    gdk_window_set_back_pixmap(gtk_widget_get_window(w), NULL, TRUE);
+                gdk_window_set_back_pixmap(window, NULL, TRUE);
 #endif
-                    gtk_style_set_background(gtk_widget_get_style(w),
-                                             gtk_widget_get_window(w),
+                if ((p->background) || (p->transparent))
+                    /* Reset background for the child, using background of panel */
+                    gdk_window_invalidate_rect(window, NULL, TRUE);
+                else
+                    /* Set background according to the current GTK style. */
+                    gtk_style_set_background(gtk_widget_get_style(w), window,
                                              GTK_STATE_NORMAL);
-                }
             }
         }
 
index 00cd474..56debdf 100644 (file)
@@ -227,7 +227,6 @@ void _panel_show_config_dialog(LXPanel *panel, GtkWidget *p, GtkWidget *dlg);
 
 void _calculate_position(LXPanel *panel, GdkRectangle *rect);
 
-void _panel_determine_background_pixmap(LXPanel * p, GtkWidget * widget);
 void _panel_establish_autohide(LXPanel *p);
 void _panel_set_wm_strut(LXPanel *p);
 void _panel_set_panel_configuration_changed(LXPanel *p);