[gnome-panel] simplify background handling



commit 692f233cba984b054895c598cfc2b9f355bd0699
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Thu Nov 20 21:46:02 2014 +0200

    simplify background handling
    
    All this code is not needed and has not worked like it should.
    
    GTK+ 3.16 will deprecate some functions used by this code. Setting
    background-image with gtk_style_properties_set was not implemented.
    See bug: https://bugzilla.gnome.org/show_bug.cgi?id=710184
    
    This restores ability to have transparent panels. Tested with both
    in process and out of process applets, with compositing manager and
    without it.
    
    If some applets are not transparent that most likely is theme
    problem.

 gnome-panel/panel-applet-frame.c    |   70 -------------------
 gnome-panel/panel-applet-frame.h    |    3 -
 gnome-panel/panel-background.c      |  126 -----------------------------------
 gnome-panel/panel-background.h      |    3 -
 gnome-panel/panel-menu-bar-object.c |   46 -------------
 gnome-panel/panel-menu-bar-object.h |    2 -
 gnome-panel/panel-separator.c       |   33 ---------
 gnome-panel/panel-separator.h       |    1 -
 gnome-panel/panel.c                 |   12 ++--
 libpanel-applet/panel-applet.c      |   74 +--------------------
 10 files changed, 9 insertions(+), 361 deletions(-)
---
diff --git a/gnome-panel/panel-applet-frame.c b/gnome-panel/panel-applet-frame.c
index 3abeac9..cc76e8a 100644
--- a/gnome-panel/panel-applet-frame.c
+++ b/gnome-panel/panel-applet-frame.c
@@ -143,28 +143,6 @@ panel_applet_frame_draw (GtkWidget *widget,
 }
 
 static void
-panel_applet_frame_update_background_size (PanelAppletFrame *frame,
-                                          GtkAllocation    *old_allocation,
-                                          GtkAllocation    *new_allocation)
-{
-       PanelBackground *background;
-
-       if (old_allocation->x      == new_allocation->x &&
-           old_allocation->y      == new_allocation->y &&
-           old_allocation->width  == new_allocation->width &&
-           old_allocation->height == new_allocation->height)
-               return;
-
-       background = &frame->priv->panel->background;
-
-       if (background->type == PANEL_BACK_NONE ||
-          (background->type == PANEL_BACK_COLOR && !background->has_alpha))
-               return;
-
-       panel_applet_frame_change_background (frame, background->type);
-}
-
-static void
 panel_applet_frame_get_preferred_width(GtkWidget *widget, gint *minimal_width, gint *natural_width)
 {
        PanelAppletFrame *frame;
@@ -251,7 +229,6 @@ panel_applet_frame_size_allocate (GtkWidget     *widget,
        GtkWidget        *child;
        GdkWindow        *window;
        GtkAllocation     new_allocation;
-       GtkAllocation     old_allocation;
        GtkAllocation     widget_allocation;
 
        frame = PANEL_APPLET_FRAME (widget);
@@ -259,17 +236,9 @@ panel_applet_frame_size_allocate (GtkWidget     *widget,
 
        gtk_widget_get_allocation (widget, &widget_allocation);
 
-       old_allocation.x      = widget_allocation.x;
-       old_allocation.y      = widget_allocation.y;
-       old_allocation.width  = widget_allocation.width;
-       old_allocation.height = widget_allocation.height;
-
        if (!frame->priv->has_handle) {
                GTK_WIDGET_CLASS (panel_applet_frame_parent_class)->size_allocate (widget,
                                                                                   allocation);
-               panel_applet_frame_update_background_size (frame,
-                                                          &old_allocation,
-                                                          allocation);
                return;
        }
 
@@ -343,10 +312,6 @@ panel_applet_frame_size_allocate (GtkWidget     *widget,
                gtk_widget_size_allocate (child, &new_allocation);
   
        frame->priv->child_allocation = new_allocation;
-
-       panel_applet_frame_update_background_size (frame,
-                                                  &old_allocation,
-                                                  allocation);
 }
 
 static inline gboolean
@@ -522,29 +487,6 @@ panel_applet_frame_change_orientation (PanelAppletFrame *frame,
 }
 
 void
-panel_applet_frame_change_background (PanelAppletFrame    *frame,
-                                     PanelBackgroundType  type)
-{
-       GtkWidget *parent;
-
-       g_return_if_fail (PANEL_IS_APPLET_FRAME (frame));
-
-       parent = gtk_widget_get_parent (GTK_WIDGET (frame));
-
-       g_return_if_fail (PANEL_IS_WIDGET (parent));
-
-       if (frame->priv->has_handle) {
-               PanelBackground *background;
-
-               background = &PANEL_WIDGET (parent)->background;
-               panel_background_change_background_on_widget (background,
-                                                             GTK_WIDGET (frame));
-       }
-
-       PANEL_APPLET_FRAME_GET_CLASS (frame)->change_background (frame, type);
-}
-
-void
 panel_applet_frame_set_panel (PanelAppletFrame *frame,
                              PanelWidget      *panel)
 {
@@ -618,22 +560,10 @@ _panel_applet_frame_update_flags (PanelAppletFrame *frame,
                                  gboolean          minor,
                                  gboolean          has_handle)
 {
-       gboolean old_has_handle;
-
        panel_widget_set_applet_expandable (
                frame->priv->panel, GTK_WIDGET (frame), major, minor);
 
-       old_has_handle = frame->priv->has_handle;
        frame->priv->has_handle = has_handle;
-
-       if (!old_has_handle && frame->priv->has_handle) {
-               /* we've added an handle, so we need to get the background for
-                * it */
-               PanelBackground *background;
-
-               background = &frame->priv->panel->background;
-               panel_applet_frame_change_background (frame, background->type);
-       }
 }
 
 void
diff --git a/gnome-panel/panel-applet-frame.h b/gnome-panel/panel-applet-frame.h
index 2d234cf..1a786aa 100644
--- a/gnome-panel/panel-applet-frame.h
+++ b/gnome-panel/panel-applet-frame.h
@@ -86,9 +86,6 @@ void  panel_applet_frame_load               (PanelWidget         *panel_widget,
 void  panel_applet_frame_change_orientation (PanelAppletFrame    *frame,
                                             PanelOrientation     orientation);
 
-void  panel_applet_frame_change_background  (PanelAppletFrame    *frame,
-                                            PanelBackgroundType  type);
-
 void  panel_applet_frame_set_panel          (PanelAppletFrame    *frame,
                                             PanelWidget         *panel);
 
diff --git a/gnome-panel/panel-background.c b/gnome-panel/panel-background.c
index 27b12cd..65e79eb 100644
--- a/gnome-panel/panel-background.c
+++ b/gnome-panel/panel-background.c
@@ -996,129 +996,3 @@ panel_background_effective_type (PanelBackground *background)
 
        return retval;
 }
-
-static cairo_pattern_t *
-panel_background_get_pattern_for_widget (PanelBackground *background,
-                                         GtkWidget       *widget)
-{
-       GtkAllocation    allocation;
-       cairo_t         *cr;
-        cairo_surface_t *surface;
-        cairo_surface_t *bg_surface;
-       cairo_pattern_t *pattern;
-        cairo_matrix_t   matrix;
-
-        if (!background->composited_pattern)
-                return NULL;
-
-        if (cairo_pattern_get_surface (background->composited_pattern, &bg_surface) != CAIRO_STATUS_SUCCESS)
-                return NULL;
-
-       gtk_widget_get_allocation (widget, &allocation);
-        surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24,
-                                              allocation.width, allocation.height);
-
-       cr = cairo_create (surface);
-        cairo_set_source_surface (cr, bg_surface, -allocation.x, -allocation.y);
-        cairo_rectangle (cr, 0, 0, allocation.width, allocation.height);
-        cairo_fill (cr);
-        cairo_destroy (cr);
-
-        pattern = cairo_pattern_create_for_surface (surface);
-        cairo_matrix_init_translate (&matrix, 0, 0);
-        cairo_matrix_scale (&matrix, allocation.width, allocation.height);
-        cairo_pattern_set_matrix (pattern, &matrix);
-        cairo_pattern_set_extend (pattern, CAIRO_EXTEND_PAD);
-
-        cairo_surface_destroy (surface);
-
-        return pattern;
-}
-
-static GtkStyleProperties *
-_panel_background_get_widget_style_properties (GtkWidget *widget,
-                                               gboolean   create_if_needed)
-{
-        GtkStyleProperties *properties;
-
-        properties = g_object_get_data (G_OBJECT (widget),
-                                        "panel-object-style-props");
-
-        if (!properties && create_if_needed) {
-                properties = gtk_style_properties_new ();
-                g_object_set_data_full (G_OBJECT (widget),
-                                        "panel-object-style-props",
-                                        properties,
-                                        (GDestroyNotify) g_object_unref);
-        }
-
-        return properties;
-}
-
-static void
-_panel_background_reset_widget_style_properties (GtkWidget *widget)
-{
-        GtkStyleProperties *properties;
-
-        properties = _panel_background_get_widget_style_properties (widget, FALSE);
-
-        if (properties)
-                gtk_style_context_remove_provider (gtk_widget_get_style_context (widget),
-                                                   GTK_STYLE_PROVIDER (properties));
-
-
-        g_object_set_data (G_OBJECT (widget), "panel-object-style-props", NULL);
-}
-
-void
-panel_background_change_background_on_widget (PanelBackground *background,
-                                             GtkWidget       *widget)
-{
-        GtkStyleProperties *properties;
-
-        gtk_widget_reset_style (widget);
-
-       switch (panel_background_get_type (background)) {
-       case PANEL_BACK_NONE:
-                _panel_background_reset_widget_style_properties (widget);
-                return;
-       case PANEL_BACK_COLOR:
-                if (!background->has_alpha) {
-                        properties = _panel_background_get_widget_style_properties (widget, TRUE);
-                        gtk_style_properties_set (properties, GTK_STATE_FLAG_NORMAL,
-                                                  "background-color", &background->color,
-                                                  "background-image", NULL,
-                                                  NULL);
-                        break;
-                }
-                // Color with alpha, fallback to image
-       case PANEL_BACK_IMAGE: {
-                cairo_pattern_t *pattern;
-
-                properties = _panel_background_get_widget_style_properties (widget, TRUE);
-                pattern = panel_background_get_pattern_for_widget (background, widget);
-                if (pattern) {
-                        gtk_style_properties_set (properties, GTK_STATE_FLAG_NORMAL,
-                                                  /* background-color can't be
-                                                   * NULL, but is ignored
-                                                   * anyway */
-                                                  "background-image", pattern,
-                                                  NULL);
-                        cairo_pattern_destroy (pattern);
-                } else {
-                        _panel_background_reset_widget_style_properties (widget);
-                        return;
-                }
-        }
-               break;
-       default:
-               g_assert_not_reached ();
-               break;
-       }
-
-       /* Note: this actually replaces the old properties, since it's the same
-        * pointer */
-        gtk_style_context_add_provider (gtk_widget_get_style_context (widget),
-                                        GTK_STYLE_PROVIDER (properties),
-                                        GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
-}
diff --git a/gnome-panel/panel-background.h b/gnome-panel/panel-background.h
index 027d7d6..286d526 100644
--- a/gnome-panel/panel-background.h
+++ b/gnome-panel/panel-background.h
@@ -101,7 +101,4 @@ const GdkRGBA       *panel_background_get_color  (PanelBackground *background);
 PanelBackgroundType
       panel_background_effective_type    (PanelBackground     *background);
 
-void panel_background_change_background_on_widget (PanelBackground *background,
-                                                  GtkWidget       *widget);
-
 #endif /* __PANEL_BACKGROUND_H__ */
diff --git a/gnome-panel/panel-menu-bar-object.c b/gnome-panel/panel-menu-bar-object.c
index 86c4597..4e2998a 100644
--- a/gnome-panel/panel-menu-bar-object.c
+++ b/gnome-panel/panel-menu-bar-object.c
@@ -141,48 +141,13 @@ panel_menu_bar_object_set_property (GObject         *object,
 }
 
 static void
-panel_menu_bar_object_size_allocate (GtkWidget     *widget,
-                                    GtkAllocation *allocation)
-{
-       GtkAllocation    old_allocation;
-       GtkAllocation    widget_allocation;
-       PanelBackground *background;
-
-       gtk_widget_get_allocation (widget, &widget_allocation);
-
-       old_allocation.x      = widget_allocation.x;
-       old_allocation.y      = widget_allocation.y;
-       old_allocation.width  = widget_allocation.width;
-       old_allocation.height = widget_allocation.height;
-
-       GTK_WIDGET_CLASS (panel_menu_bar_object_parent_class)->size_allocate (widget, allocation);
-
-       if (old_allocation.x      == allocation->x &&
-           old_allocation.y      == allocation->y &&
-           old_allocation.width  == allocation->width &&
-           old_allocation.height == allocation->height)
-               return;
-
-       background = &PANEL_MENU_BAR_OBJECT (widget)->priv->panel->background;
-
-       if (background->type == PANEL_BACK_NONE ||
-          (background->type == PANEL_BACK_COLOR && !background->has_alpha))
-               return;
-
-       panel_menu_bar_object_change_background (PANEL_MENU_BAR_OBJECT (widget));
-}
-
-static void
 panel_menu_bar_object_class_init (PanelMenuBarObjectClass *klass)
 {
        GObjectClass   *gobject_class = (GObjectClass   *) klass;
-       GtkWidgetClass *widget_class  = (GtkWidgetClass *) klass;
 
        gobject_class->get_property = panel_menu_bar_object_get_property;
         gobject_class->set_property = panel_menu_bar_object_set_property;
 
-       widget_class->size_allocate = panel_menu_bar_object_size_allocate;
-
        g_type_class_add_private (klass, sizeof (PanelMenuBarObjectPrivate));
 
        g_object_class_install_property (
@@ -231,7 +196,6 @@ panel_menu_bar_object_object_load_finish (PanelMenuBarObject *menubar,
        menubar->priv->panel = panel;
 
        /* we didn't do this on "applet-added" since we didn't have the panel yet */
-       panel_menu_bar_object_change_background (menubar);
         panel_menu_bar_object_update_orientation (menubar);
        panel_menu_bar_object_update_text_gravity (menubar);
 
@@ -250,16 +214,6 @@ panel_menu_bar_object_object_load_finish (PanelMenuBarObject *menubar,
        panel_widget_set_applet_expandable (panel, GTK_WIDGET (menubar), FALSE, TRUE);
 }
 
-void
-panel_menu_bar_object_change_background (PanelMenuBarObject *menubar)
-{
-       if (!menubar->priv->panel)
-               return;
-
-       panel_background_change_background_on_widget (&menubar->priv->panel->background,
-                                                     GTK_WIDGET (menubar));
-}
-
 static void
 set_item_text_gravity (GtkWidget *item)
 {
diff --git a/gnome-panel/panel-menu-bar-object.h b/gnome-panel/panel-menu-bar-object.h
index d57a269..9421ea5 100644
--- a/gnome-panel/panel-menu-bar-object.h
+++ b/gnome-panel/panel-menu-bar-object.h
@@ -55,8 +55,6 @@ GType      panel_menu_bar_object_get_type  (void) G_GNUC_CONST;
 void panel_menu_bar_object_object_load_finish (PanelMenuBarObject *menubar,
                                               PanelWidget        *panel);
 
-void       panel_menu_bar_object_change_background (PanelMenuBarObject *menubar);
-
 void             panel_menu_bar_object_set_orientation (PanelMenuBarObject     *menubar,
                                                        PanelOrientation        orientation);
 PanelOrientation panel_menu_bar_object_get_orientation (PanelMenuBarObject     *menubar);
diff --git a/gnome-panel/panel-separator.c b/gnome-panel/panel-separator.c
index d5c3622..a809c0b 100644
--- a/gnome-panel/panel-separator.c
+++ b/gnome-panel/panel-separator.c
@@ -35,8 +35,6 @@ struct _PanelSeparatorPrivate {
 
        GtkOrientation  orientation;
        GtkWidget      *separator;
-
-       unsigned char   force_background_redraw: 1;
 };
 
 G_DEFINE_TYPE (PanelSeparator, panel_separator, GTK_TYPE_EVENT_BOX)
@@ -132,17 +130,12 @@ static void
 panel_separator_size_allocate (GtkWidget     *widget,
                               GtkAllocation *allocation)
 {
-       PanelSeparator  *separator = PANEL_SEPARATOR (widget);
-       GtkAllocation    old_allocation;
        GtkStyleContext *context;
        GtkStateFlags    state;
        GtkBorder        padding;
        GtkBorder        border;
        GtkAllocation    new_allocation;
        GtkWidget       *child;
-       PanelBackground *background;
-
-       gtk_widget_get_allocation (widget, &old_allocation);
 
        GTK_WIDGET_CLASS (panel_separator_parent_class)->size_allocate (widget, allocation);
 
@@ -172,23 +165,6 @@ panel_separator_size_allocate (GtkWidget     *widget,
        child = gtk_bin_get_child (GTK_BIN (widget));
        if (child && gtk_widget_get_visible (child))
                gtk_widget_size_allocate (child, &new_allocation);
-
-       if (!separator->priv->force_background_redraw &&
-           (old_allocation.x      == allocation->x &&
-            old_allocation.y      == allocation->y &&
-            old_allocation.width  == allocation->width &&
-            old_allocation.height == allocation->height))
-               return;
-
-       separator->priv->force_background_redraw = FALSE;
-
-       background = &separator->priv->panel->background;
-
-       if (background->type == PANEL_BACK_NONE ||
-          (background->type == PANEL_BACK_COLOR && !background->has_alpha))
-               return;
-
-       panel_separator_change_background (separator);
 }
 
 static void
@@ -230,7 +206,6 @@ panel_separator_init (PanelSeparator *separator)
        separator->priv->panel = NULL;
        separator->priv->orientation = GTK_ORIENTATION_HORIZONTAL;
        separator->priv->separator = gtk_separator_new (GTK_ORIENTATION_VERTICAL);
-       separator->priv->force_background_redraw = FALSE;
 
        gtk_container_add (GTK_CONTAINER (separator),
                           separator->priv->separator);
@@ -280,7 +255,6 @@ panel_separator_set_orientation (PanelSeparator   *separator,
        gtk_orientable_set_orientation (GTK_ORIENTABLE (separator->priv->separator),
                                        orient_separator);
 
-       separator->priv->force_background_redraw = TRUE;
        gtk_widget_queue_resize (GTK_WIDGET (separator));
 }
 
@@ -320,10 +294,3 @@ panel_separator_create (PanelToplevel       *toplevel,
                                    panel_toplevel_get_id (toplevel),
                                    pack_type, pack_index);
 }
-
-void
-panel_separator_change_background (PanelSeparator *separator)
-{
-       panel_background_change_background_on_widget (&separator->priv->panel->background,
-                                                     GTK_WIDGET (separator));
-}
diff --git a/gnome-panel/panel-separator.h b/gnome-panel/panel-separator.h
index a65bbf1..9a84ef9 100644
--- a/gnome-panel/panel-separator.h
+++ b/gnome-panel/panel-separator.h
@@ -58,7 +58,6 @@ void   panel_separator_load              (PanelWidget      *panel_widget,
                                          GSettings        *settings);
 void   panel_separator_set_orientation   (PanelSeparator   *separator,
                                          PanelOrientation  orientation);
-void   panel_separator_change_background (PanelSeparator   *separator);
 
 G_END_DECLS
 
diff --git a/gnome-panel/panel.c b/gnome-panel/panel.c
index f04abdb..c952f68 100644
--- a/gnome-panel/panel.c
+++ b/gnome-panel/panel.c
@@ -112,17 +112,19 @@ void
 back_change (AppletInfo  *info,
             PanelWidget *panel)
 {
+       PanelAppletFrame    *frame;
+       PanelBackgroundType  type;
+
        switch (info->type) {
        case PANEL_OBJECT_APPLET:
-               panel_applet_frame_change_background (
-                       PANEL_APPLET_FRAME (info->widget), panel->background.type);
+               frame = PANEL_APPLET_FRAME (info->widget);
+               type = panel->background.type;
+
+               PANEL_APPLET_FRAME_GET_CLASS (frame)->change_background (frame, type);
                break;
        case PANEL_OBJECT_MENU_BAR:
        case PANEL_OBJECT_USER_MENU:
-               panel_menu_bar_object_change_background (PANEL_MENU_BAR_OBJECT (info->widget));
-               break;
        case PANEL_OBJECT_SEPARATOR:
-               panel_separator_change_background (PANEL_SEPARATOR (info->widget));
                break;
        default:
                break;
diff --git a/libpanel-applet/panel-applet.c b/libpanel-applet/panel-applet.c
index c6d2f4e..a3ab23c 100644
--- a/libpanel-applet/panel-applet.c
+++ b/libpanel-applet/panel-applet.c
@@ -1520,82 +1520,12 @@ panel_applet_set_background_string (PanelApplet *applet,
        g_object_notify (G_OBJECT (applet), "background");
 }
 
-static GtkStyleProperties *
-_panel_applet_get_widget_style_properties (GtkWidget *widget,
-                                           gboolean   create_if_needed)
-{
-        GtkStyleProperties *properties;
-
-        properties = g_object_get_data (G_OBJECT (widget),
-                                        "panel-applet-style-props");
-
-        if (!properties && create_if_needed) {
-                properties = gtk_style_properties_new ();
-                g_object_set_data_full (G_OBJECT (widget),
-                                        "panel-applet-style-props",
-                                        properties,
-                                        (GDestroyNotify) g_object_unref);
-        }
-
-        return properties;
-}
-
-static void
-_panel_applet_reset_widget_style_properties (GtkWidget *widget)
-{
-        GtkStyleProperties *properties;
-
-        properties = _panel_applet_get_widget_style_properties (widget, FALSE);
-
-        if (properties)
-                gtk_style_context_remove_provider (gtk_widget_get_style_context (widget),
-                                                   GTK_STYLE_PROVIDER (properties));
-
-        g_object_set_data (G_OBJECT (widget), "panel-applet-style-props", NULL);
-}
-
 static void
 panel_applet_update_background_for_widget (GtkWidget       *widget,
                                           cairo_pattern_t *pattern)
 {
-        GtkStyleProperties *properties;
-
-        gtk_widget_reset_style (widget);
-
-        if (!pattern) {
-                _panel_applet_reset_widget_style_properties (widget);
-                return;
-        }
-
-        properties = _panel_applet_get_widget_style_properties (widget, TRUE);
-
-        switch (cairo_pattern_get_type (pattern)) {
-        case CAIRO_PATTERN_TYPE_SOLID: {
-                GdkRGBA color;
-
-                cairo_pattern_get_rgba (pattern, &color.red, &color.green, &color.blue, &color.alpha);
-                gtk_style_properties_set (properties, GTK_STATE_FLAG_NORMAL,
-                                          "background-color", &color,
-                                          "background-image", NULL,
-                                          NULL);
-        }
-                break;
-        case CAIRO_PATTERN_TYPE_SURFACE:
-                gtk_style_properties_set (properties, GTK_STATE_FLAG_NORMAL,
-                                         /* background-color can't be NULL,
-                                          * but is ignored anyway */
-                                          "background-image", pattern,
-                                          NULL);
-                break;
-        default:
-                break;
-        }
-
-       /* Note: this actually replaces the old properties, since it's the same
-        * pointer */
-        gtk_style_context_add_provider (gtk_widget_get_style_context (widget),
-                                        GTK_STYLE_PROVIDER (properties),
-                                        GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+       gdk_window_set_background_pattern (gtk_widget_get_window (widget),
+                                          pattern);
 }
 
 static void


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