[gnome-panel] libpanel-applet: restore custom background



commit 3115f77b536a7c79c7d43ded0591e2b8f45219c4
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Wed Mar 9 17:37:51 2016 +0200

    libpanel-applet: restore custom background

 data/theme/Adwaita/gnome-panel-dark.css |    3 +-
 data/theme/Adwaita/gnome-panel.css      |    3 +-
 data/theme/HighContrast/gnome-panel.css |    3 +-
 libpanel-applet/Makefile.am             |    4 +-
 libpanel-applet/panel-applet.c          |   48 +++++----------
 libpanel-applet/panel-plug-private.h    |   32 ++++++++++
 libpanel-applet/panel-plug.c            |   98 +++++++++++++++++++++++++++++++
 7 files changed, 154 insertions(+), 37 deletions(-)
---
diff --git a/data/theme/Adwaita/gnome-panel-dark.css b/data/theme/Adwaita/gnome-panel-dark.css
index ec872eb..4bc7219 100644
--- a/data/theme/Adwaita/gnome-panel-dark.css
+++ b/data/theme/Adwaita/gnome-panel-dark.css
@@ -1,4 +1,5 @@
-panel-toplevel {
+panel-toplevel,
+panel-plug {
   background-color: #393f3f;
 }
 
diff --git a/data/theme/Adwaita/gnome-panel.css b/data/theme/Adwaita/gnome-panel.css
index 2afd342..d403497 100644
--- a/data/theme/Adwaita/gnome-panel.css
+++ b/data/theme/Adwaita/gnome-panel.css
@@ -1,4 +1,5 @@
-panel-toplevel {
+panel-toplevel,
+panel-plug {
   background-color: #e8e8e7;
 }
 
diff --git a/data/theme/HighContrast/gnome-panel.css b/data/theme/HighContrast/gnome-panel.css
index e99b568..5cf1ec0 100644
--- a/data/theme/HighContrast/gnome-panel.css
+++ b/data/theme/HighContrast/gnome-panel.css
@@ -1,4 +1,5 @@
-panel-toplevel {
+panel-toplevel,
+panel-plug {
   background-color: #ffffff;
 }
 
diff --git a/libpanel-applet/Makefile.am b/libpanel-applet/Makefile.am
index eff24dc..33fbe4a 100644
--- a/libpanel-applet/Makefile.am
+++ b/libpanel-applet/Makefile.am
@@ -24,7 +24,9 @@ libpanel_applet_la_SOURCES =          \
        panel-applet-factory.c          \
        panel-applet-bindings.h         \
        panel-applet-bindings.c         \
-       panel-applet-private.h
+       panel-applet-private.h          \
+       panel-plug.c                    \
+       panel-plug-private.h
 
 libpanel_applet_la_LIBADD  = \
        $(LIBPANEL_APPLET_LIBS) \
diff --git a/libpanel-applet/panel-applet.c b/libpanel-applet/panel-applet.c
index 1665dc6..fe350c4 100644
--- a/libpanel-applet/panel-applet.c
+++ b/libpanel-applet/panel-applet.c
@@ -45,6 +45,7 @@
 #include "panel-applet-factory.h"
 #include "panel-applet-marshal.h"
 #include "panel-applet-enums.h"
+#include "panel-plug-private.h"
 
 /**
  * SECTION:applet
@@ -94,7 +95,6 @@ struct _PanelAppletPrivate {
        PanelAppletFlags   flags;
        PanelAppletOrient  orient;
        char              *background;
-       GtkWidget         *background_widget;
 
        int                previous_width;
        int                previous_height;
@@ -1495,37 +1495,27 @@ panel_applet_style_updated (GtkWidget *widget)
 }
 
 static void
-panel_applet_update_background_for_widget (GtkWidget       *widget,
-                                          cairo_pattern_t *pattern)
+panel_applet_handle_background (PanelApplet *applet)
 {
        GdkWindow *window;
+       cairo_pattern_t *pattern;
 
-       window = gtk_widget_get_window (widget);
-
-       if (!window)
+       if (applet->priv->plug == NULL)
                return;
 
-       gdk_window_set_background_pattern (window,
-                                          pattern);
-}
+       window = gtk_widget_get_window (applet->priv->plug);
 
-static void
-panel_applet_handle_background (PanelApplet *applet)
-{
-        cairo_pattern_t *pattern;
+       if (window == NULL)
+         return;
 
        pattern = panel_applet_get_background (applet);
 
-       if (applet->priv->background_widget)
-               panel_applet_update_background_for_widget (applet->priv->background_widget,
-                                                          pattern);
-       else
-               panel_applet_update_background_for_widget (GTK_WIDGET (applet), pattern);
+       gdk_window_set_background_pattern (window, pattern);
+       gtk_widget_queue_draw (applet->priv->plug);
+
+       g_signal_emit (applet, panel_applet_signals [CHANGE_BACKGROUND], 0, pattern);
 
-        g_signal_emit (G_OBJECT (applet),
-                        panel_applet_signals [CHANGE_BACKGROUND],
-                        0, pattern);
-        if (pattern)
+       if (pattern)
                cairo_pattern_destroy (pattern);
 }
 
@@ -1771,7 +1761,7 @@ panel_applet_constructor (GType                  type,
        if (!applet->priv->out_of_process)
                return object;
 
-       applet->priv->plug = gtk_plug_new (0);
+       applet->priv->plug = panel_plug_new ();
 
        g_signal_connect_swapped (G_OBJECT (applet->priv->plug), "embedded",
                                      G_CALLBACK (panel_applet_setup),
@@ -2352,21 +2342,13 @@ panel_applet_factory_setup_in_process (const gchar               *factory_id,
  * Configure #PanelApplet to automatically draw the background of the applet on
  * @widget. It is generally enough to call this function with @applet as
  * @widget.
+ *
+ * Deprecated: 3.20: Do not use this API. Since 3.20 this function does nothing.
  **/
 void
 panel_applet_set_background_widget (PanelApplet *applet,
                                    GtkWidget   *widget)
 {
-       applet->priv->background_widget = widget;
-
-       if (widget && gtk_widget_get_realized (widget)) {
-               cairo_pattern_t *pattern;
-
-               pattern = panel_applet_get_background (applet);
-               panel_applet_update_background_for_widget (widget, pattern);
-               if (pattern)
-                       cairo_pattern_destroy (pattern);
-       }
 }
 
 guint32
diff --git a/libpanel-applet/panel-plug-private.h b/libpanel-applet/panel-plug-private.h
new file mode 100644
index 0000000..5c7f12a
--- /dev/null
+++ b/libpanel-applet/panel-plug-private.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2016 Alberts Muktupāvels
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef PANEL_PLUG_PRIVATE_H
+#define PANEL_PLUG_PRIVATE_H
+
+#include <gtk/gtkx.h>
+
+G_BEGIN_DECLS
+
+#define PANEL_TYPE_PLUG panel_plug_get_type ()
+G_DECLARE_FINAL_TYPE (PanelPlug, panel_plug, PANEL, PLUG, GtkPlug)
+
+GtkWidget *panel_plug_new (void);
+
+G_END_DECLS
+
+#endif
diff --git a/libpanel-applet/panel-plug.c b/libpanel-applet/panel-plug.c
new file mode 100644
index 0000000..bca2761
--- /dev/null
+++ b/libpanel-applet/panel-plug.c
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2016 Alberts Muktupāvels
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include "panel-plug-private.h"
+
+struct _PanelPlug
+{
+  GtkPlug parent;
+};
+
+G_DEFINE_TYPE (PanelPlug, panel_plug, GTK_TYPE_PLUG)
+
+static gboolean
+panel_plug_draw (GtkWidget *widget,
+                 cairo_t   *cr)
+{
+  GdkWindow *window;
+  cairo_pattern_t *pattern;
+
+  if (!gtk_widget_get_realized (widget))
+    return GTK_WIDGET_CLASS (panel_plug_parent_class)->draw (widget, cr);
+
+  window = gtk_widget_get_window (widget);
+  pattern = gdk_window_get_background_pattern (window);
+
+  if (!pattern)
+    {
+      GtkStyleContext *context;
+      gint width;
+      gint height;
+
+      context = gtk_widget_get_style_context (widget);
+      width = gtk_widget_get_allocated_width (widget);
+      height = gtk_widget_get_allocated_height (widget);
+
+      gtk_render_background (context, cr, 0, 0, width, height);
+    }
+
+  return GTK_WIDGET_CLASS (panel_plug_parent_class)->draw (widget, cr);
+}
+
+static void
+panel_plug_realize (GtkWidget *widget)
+{
+  GdkScreen *screen;
+  GdkVisual *visual;
+
+  screen = gdk_screen_get_default ();
+  visual = gdk_screen_get_rgba_visual (screen);
+
+  if (!visual)
+    visual = gdk_screen_get_system_visual (screen);
+
+  gtk_widget_set_visual (widget, visual);
+
+  GTK_WIDGET_CLASS (panel_plug_parent_class)->realize (widget);
+}
+
+static void
+panel_plug_class_init (PanelPlugClass *plug_class)
+{
+  GtkWidgetClass *widget_class;
+
+  widget_class = GTK_WIDGET_CLASS (plug_class);
+
+  widget_class->draw = panel_plug_draw;
+  widget_class->realize = panel_plug_realize;
+
+  gtk_widget_class_set_css_name (widget_class, "panel-plug");
+}
+
+static void
+panel_plug_init (PanelPlug *plug)
+{
+  gtk_widget_set_app_paintable (GTK_WIDGET (plug), TRUE);
+}
+
+GtkWidget *
+panel_plug_new (void)
+{
+  return g_object_new (PANEL_TYPE_PLUG, NULL);
+}


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