[gnome-panel] replace PanelBackground with GpTheme



commit 885d4a223697d8f69efc2c37e76fff1c402188c0
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Sat Oct 8 14:49:01 2016 +0300

    replace PanelBackground with GpTheme

 ...rg.gnome.gnome-panel.toplevel.gschema.xml.in.in |   28 -
 gnome-panel/Makefile.am                            |    6 +-
 gnome-panel/gp-properties-dialog.ui                |    1 -
 gnome-panel/gp-theme.c                             |  371 +++++++++
 gnome-panel/gp-theme.h                             |   40 +
 gnome-panel/panel-applet-frame.c                   |    6 +-
 gnome-panel/panel-background.c                     |  844 --------------------
 gnome-panel/panel-background.h                     |   83 --
 gnome-panel/panel-enums-gsettings.h                |    6 -
 gnome-panel/panel-menu-bar-object.c                |    1 -
 gnome-panel/panel-schemas.h                        |    8 -
 gnome-panel/panel-separator.c                      |    1 -
 gnome-panel/panel-toplevel.c                       |  155 +---
 gnome-panel/panel-toplevel.h                       |    3 -
 gnome-panel/panel.c                                |   45 +-
 15 files changed, 478 insertions(+), 1120 deletions(-)
---
diff --git a/data/org.gnome.gnome-panel.toplevel.gschema.xml.in.in 
b/data/org.gnome.gnome-panel.toplevel.gschema.xml.in.in
index 20e24d8..5549429 100644
--- a/data/org.gnome.gnome-panel.toplevel.gschema.xml.in.in
+++ b/data/org.gnome.gnome-panel.toplevel.gschema.xml.in.in
@@ -93,36 +93,8 @@
       <_summary>Animation speed</_summary>
       <_description>The speed in which panel animations should occur. Possible values are "slow", "medium" 
and "fast". This key is only relevant if the enable_animations key is true.</_description>
     </key>
-    <child name="background" schema="org.gnome.gnome-panel.toplevel.background"/>
     <child name="theme" schema="org.gnome.gnome-panel.toplevel.theme"/>
   </schema>
-  <schema id="org.gnome.gnome-panel.toplevel.background">
-    <key name="type" enum="org.gnome.gnome-panel.PanelBackgroundType">
-      <default>'none'</default>
-      <_summary>Background type</_summary>
-      <_description>Which type of background should be used for this panel. Possible values are "none" - the 
default GTK+ widget background will be used, "color" - the color key will be used as background color or 
"image" - the image specified by the image key will be used as background.</_description>
-    </key>
-    <key name="color" type="s">
-      <default>'rgba(255,255,255,.2)'</default>
-      <_summary>Background color</_summary>
-      <_description>Specifies the background color for the panel in #RGB format.</_description>
-    </key>
-    <key name="image-uri" type="s">
-      <default>''</default>
-      <_summary>Background image</_summary>
-      <_description>Specifies the file to be used for the background image. If the image contains an alpha 
channel it will be composited onto the desktop background image.</_description>
-    </key>
-    <key name="image-rotate" type="b">
-      <default>false</default>
-      <_summary>Rotate image on vertical panels</_summary>
-      <_description>If true, the background image will be rotated when the panel is oriented 
vertically.</_description>
-    </key>
-    <key name="image-style" enum="org.gnome.gnome-panel.PanelBackgroundImageStyle">
-      <default>'none'</default>
-      <_summary>Image options</_summary>
-      <_description>Determines how the image set by image-uri is rendered. Possible values are "none", 
"stretch", "fit". With "stretch", the image will be scaled to the panel dimensions and the aspect ratio of 
the image will not be maintained. With "fit", the image will be scaled (retaining the aspect ratio of the 
image) to the panel height (if horizontal).</_description>
-    </key>
-  </schema>
 
   <schema id="org.gnome.gnome-panel.toplevel.theme">
 
diff --git a/gnome-panel/Makefile.am b/gnome-panel/Makefile.am
index cb86f61..a9ac2e5 100644
--- a/gnome-panel/Makefile.am
+++ b/gnome-panel/Makefile.am
@@ -17,6 +17,8 @@ panel_sources =                       \
        gp-arrow-button.h \
        gp-properties-dialog.c \
        gp-properties-dialog.h \
+       gp-theme.c \
+       gp-theme.h \
        main.c                  \
        panel-widget.c          \
        button-widget.c         \
@@ -33,7 +35,6 @@ panel_sources =                       \
        launcher.c              \
        panel-applet-frame.c    \
        panel-applets-manager.c \
-       panel-background.c      \
        panel-stock-icons.c     \
        panel-action-button.c   \
        panel-image-menu-item.c \
@@ -78,7 +79,6 @@ panel_headers =                       \
        launcher.h              \
        panel-applet-frame.h    \
        panel-applets-manager.h \
-       panel-background.h      \
        panel-stock-icons.h     \
        panel-action-button.h   \
        panel-image-menu-item.h \
@@ -214,7 +214,6 @@ panel-marshal.c: panel-marshal.list $(GLIB_GENMARSHAL)
 
 panel-typebuiltins.c: $(panel_enum_headers)
        $(AM_V_GEN)glib-mkenums \
-                       --fhead "#include <glib-object.h>\n" \
                        --fhead "#include \"panel-typebuiltins.h\"\n\n" \
                        --fprod "\n/* enumerations from \"@filename@\" */" \
                        --fprod "\n#include \"@filename@\"\n" \
@@ -232,6 +231,7 @@ panel-typebuiltins.h: $(panel_enum_headers)
        $(AM_V_GEN)glib-mkenums \
                        --fhead "#ifndef __PANEL_TYPEBUILTINS_H__\n" \
                        --fhead "#define __PANEL_TYPEBUILTINS_H__ 1\n\n" \
+                       --fhead "#include <glib-object.h>\n\n" \
                        --fhead "G_BEGIN_DECLS\n\n" \
                        --ftail "G_END_DECLS\n\n" \
                        --ftail "#endif /* __PANEL_TYPEBUILTINS_H__ */\n" \
diff --git a/gnome-panel/gp-properties-dialog.ui b/gnome-panel/gp-properties-dialog.ui
index 6644812..e387787 100644
--- a/gnome-panel/gp-properties-dialog.ui
+++ b/gnome-panel/gp-properties-dialog.ui
@@ -507,7 +507,6 @@
                     <child>
                       <object class="GtkCheckButton" id="rotate">
                         <property name="label" translatable="yes">Rotate image on vertical panel</property>
-                        <property name="visible">True</property>
                         <property name="can_focus">True</property>
                         <property name="receives_default">False</property>
                         <property name="use_underline">True</property>
diff --git a/gnome-panel/gp-theme.c b/gnome-panel/gp-theme.c
new file mode 100644
index 0000000..3307f18
--- /dev/null
+++ b/gnome-panel/gp-theme.c
@@ -0,0 +1,371 @@
+/*
+ * 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 <gio/gio.h>
+
+#include "gp-theme.h"
+#include "panel-enums-gsettings.h"
+
+struct _GpTheme
+{
+  GObject         parent;
+
+  gchar          *toplevel_id;
+  GSettings      *settings;
+
+  GtkCssProvider *css;
+
+  gboolean        composited;
+  GtkOrientation  orientation;
+};
+
+enum
+{
+  PROP_0,
+
+  PROP_TOPLEVEL_ID,
+  PROP_COMPOSITED,
+  PROP_ORIENTATION,
+
+  LAST_PROP
+};
+
+static GParamSpec *properties[LAST_PROP] = { NULL };
+
+G_DEFINE_TYPE (GpTheme, gp_theme, G_TYPE_OBJECT)
+
+static gchar *
+get_color (GpTheme     *theme,
+           const gchar *key)
+{
+  gchar *color;
+  GdkRGBA rgba;
+
+  color = g_settings_get_string (theme->settings, key);
+  if (!gdk_rgba_parse (&rgba, color))
+    {
+      g_free (color);
+      return NULL;
+    }
+
+  if (theme->composited)
+    return color;
+
+  rgba.alpha = 1;
+
+  g_free (color);
+  color = gdk_rgba_to_string (&rgba);
+
+  return color;
+}
+
+static void
+append_custom_bg (GpTheme *theme,
+                  GString *string)
+{
+  gboolean custom_bg_color;
+  gboolean custom_bg_image;
+  gchar *bg_color;
+  gchar *bg_image;
+
+  custom_bg_color = g_settings_get_boolean (theme->settings, "custom-bg-color");
+  custom_bg_image = g_settings_get_boolean (theme->settings, "custom-bg-image");
+
+  if (!custom_bg_color && !custom_bg_image)
+    return;
+
+  bg_color = get_color (theme, "bg-color");
+  bg_image = g_settings_get_string (theme->settings, "bg-image");
+
+  g_string_append_printf (string, "#%s.background {\n", theme->toplevel_id);
+
+  if (custom_bg_color && bg_color != NULL &&
+      custom_bg_image && *bg_image != '\0')
+    {
+      g_string_append_printf (string, "\tbackground-color: %s;\n", bg_color);
+      g_string_append_printf (string, "\tbackground-image: url('%s');\n", bg_image);
+    }
+  else if (custom_bg_color && bg_color != NULL)
+    {
+      g_string_append_printf (string, "\tbackground-color: %s;\n", bg_color);
+    }
+  else if (custom_bg_image && *bg_image != '\0')
+    {
+      if (theme->composited)
+        g_string_append (string, "\tbackground-color: transparent;\n");
+
+      g_string_append_printf (string, "\tbackground-image: url('%s');\n", bg_image);
+    }
+
+  if (custom_bg_image && *bg_image != '\0')
+    {
+      PanelBackgroundImageStyle style;
+
+      style = g_settings_get_enum (theme->settings, "bg-image-style");
+
+      switch (style)
+        {
+          case PANEL_BACKGROUND_IMAGE_STYLE_STRETCH:
+            g_string_append (string, "\tbackground-repeat: no-repeat;\n");
+            g_string_append (string, "\tbackground-size: 100% 100%;\n");
+            break;
+
+          case PANEL_BACKGROUND_IMAGE_STYLE_FIT:
+            if (theme->orientation == GTK_ORIENTATION_HORIZONTAL)
+              {
+                g_string_append (string, "\tbackground-repeat: repeat-x;\n");
+                g_string_append (string, "\tbackground-size: auto 100%;\n");
+              }
+            else
+              {
+                g_string_append (string, "\tbackground-repeat: repeat-y;\n");
+                g_string_append (string, "\tbackground-size: 100% auto;\n");
+              }
+            break;
+
+          case PANEL_BACKGROUND_IMAGE_STYLE_NONE:
+          default:
+            g_string_append (string, "\tbackground-repeat: repeat;\n");
+            break;
+        }
+
+      if (g_settings_get_boolean (theme->settings, "bg-image-rotate"))
+        {
+        }
+    }
+
+  g_string_append (string, "}\n");
+
+  g_free (bg_image);
+  g_free (bg_color);
+}
+
+static void
+append_custom_fg (GpTheme *theme,
+                  GString *string)
+{
+  gchar *fg_color;
+
+  if (!g_settings_get_boolean (theme->settings, "custom-fg-color"))
+    return;
+
+  fg_color = get_color (theme, "fg-color");
+  if (fg_color == NULL)
+    return;
+
+  g_string_append_printf (string, "#%s .gp-text-color {\n", theme->toplevel_id);
+  g_string_append_printf (string, "\tcolor: %s;\n", fg_color);
+  g_string_append (string, "}\n");
+
+  g_free (fg_color);
+}
+
+static void
+changed_cb (GSettings   *settings,
+            const gchar *key,
+            GpTheme     *theme)
+{
+  GString *string;
+  gchar *css;
+
+  string = g_string_new (NULL);
+
+  append_custom_bg (theme, string);
+  append_custom_fg (theme, string);
+
+  css = g_string_free (string, FALSE);
+  gtk_css_provider_load_from_data (theme->css, css, -1, NULL);
+  g_free (css);
+}
+
+static void
+gp_theme_constructed (GObject *object)
+{
+  GpTheme *theme;
+  const gchar *schema;
+  gchar *path;
+
+  G_OBJECT_CLASS (gp_theme_parent_class)->constructed (object);
+
+  theme = GP_THEME (object);
+  schema = "org.gnome.gnome-panel.toplevel.theme";
+  path = g_strdup_printf ("/org/gnome/gnome-panel/layout/toplevels/%s/theme/",
+                          theme->toplevel_id);
+
+  theme->settings = g_settings_new_with_path (schema, path);
+  g_free (path);
+
+  g_signal_connect (theme->settings, "changed", G_CALLBACK (changed_cb), theme);
+  changed_cb (theme->settings, NULL, theme);
+}
+
+static void
+gp_theme_dispose (GObject *object)
+{
+  GpTheme *theme;
+
+  theme = GP_THEME (object);
+
+  if (theme->css != NULL)
+    {
+      GdkScreen *screen;
+      GtkStyleProvider *provider;
+
+      screen = gdk_screen_get_default ();
+      provider = GTK_STYLE_PROVIDER (theme->css);
+
+      gtk_style_context_remove_provider_for_screen (screen, provider);
+    }
+
+  g_clear_object (&theme->settings);
+  g_clear_object (&theme->css);
+
+  G_OBJECT_CLASS (gp_theme_parent_class)->dispose (object);
+}
+
+static void
+gp_theme_finalize (GObject *object)
+{
+  GpTheme *theme;
+
+  theme = GP_THEME (object);
+
+  g_free (theme->toplevel_id);
+
+  G_OBJECT_CLASS (gp_theme_parent_class)->finalize (object);
+}
+
+static void
+gp_theme_set_property (GObject      *object,
+                       guint         property_id,
+                       const GValue *value,
+                       GParamSpec   *pspec)
+{
+  GpTheme *theme;
+
+  theme = GP_THEME (object);
+
+  switch (property_id)
+    {
+      case PROP_TOPLEVEL_ID:
+        theme->toplevel_id = g_value_dup_string (value);
+        break;
+
+      case PROP_COMPOSITED:
+        theme->composited = g_value_get_boolean (value);
+        break;
+
+      case PROP_ORIENTATION:
+        theme->orientation = g_value_get_enum (value);
+        break;
+
+      default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+        break;
+    }
+}
+
+static void
+install_properties (GObjectClass *object_class)
+{
+  properties[PROP_TOPLEVEL_ID] =
+    g_param_spec_string ("toplevel-id", "toplevel-id", "toplevel-id",
+                         NULL, G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE |
+                         G_PARAM_STATIC_STRINGS);
+
+  properties[PROP_COMPOSITED] =
+    g_param_spec_boolean ("composited", "composited", "composited",
+                          TRUE, G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE |
+                          G_PARAM_STATIC_STRINGS);
+
+  properties[PROP_ORIENTATION] =
+    g_param_spec_enum ("orientation", "orientation", "orientation",
+                       GTK_TYPE_ORIENTATION, GTK_ORIENTATION_HORIZONTAL,
+                       G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE |
+                       G_PARAM_STATIC_STRINGS);
+
+  g_object_class_install_properties (object_class, LAST_PROP, properties);
+}
+
+static void
+gp_theme_class_init (GpThemeClass *theme_class)
+{
+  GObjectClass *object_class;
+
+  object_class = G_OBJECT_CLASS (theme_class);
+
+  object_class->constructed = gp_theme_constructed;
+  object_class->dispose = gp_theme_dispose;
+  object_class->finalize = gp_theme_finalize;
+  object_class->set_property = gp_theme_set_property;
+
+  install_properties (object_class);
+}
+
+static void
+gp_theme_init (GpTheme *theme)
+{
+  GdkScreen *screen;
+  GtkStyleProvider *provider;
+  guint priority;
+
+  screen = gdk_screen_get_default ();
+
+  theme->css = gtk_css_provider_new ();
+  provider = GTK_STYLE_PROVIDER (theme->css);
+  priority = GTK_STYLE_PROVIDER_PRIORITY_USER + 100;
+
+  gtk_style_context_add_provider_for_screen (screen, provider, priority);
+}
+
+GpTheme *
+gp_theme_new (const gchar    *toplevel_id,
+              gboolean        composited,
+              GtkOrientation  orientation)
+{
+  return g_object_new (GP_TYPE_THEME,
+                       "toplevel-id", toplevel_id,
+                       "composited", composited,
+                       "orientation", orientation,
+                       NULL);
+}
+
+void
+gp_theme_set_composited (GpTheme  *theme,
+                         gboolean  composited)
+{
+  if (theme->composited == composited)
+    return;
+
+  theme->composited = composited;
+
+  changed_cb (theme->settings, NULL, theme);
+}
+
+void
+gp_theme_set_orientation (GpTheme        *theme,
+                          GtkOrientation  orientation)
+{
+  if (theme->orientation == orientation)
+    return;
+
+  theme->orientation = orientation;
+
+  changed_cb (theme->settings, NULL, theme);
+}
diff --git a/gnome-panel/gp-theme.h b/gnome-panel/gp-theme.h
new file mode 100644
index 0000000..e45dc55
--- /dev/null
+++ b/gnome-panel/gp-theme.h
@@ -0,0 +1,40 @@
+/*
+ * 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 GP_THEME_H
+#define GP_THEME_H
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define GP_TYPE_THEME gp_theme_get_type ()
+G_DECLARE_FINAL_TYPE (GpTheme, gp_theme, GP, THEME, GObject)
+
+GpTheme *gp_theme_new             (const gchar    *toplevel_id,
+                                   gboolean        composited,
+                                   GtkOrientation  orientation);
+
+void     gp_theme_set_composited  (GpTheme        *theme,
+                                   gboolean        composited);
+
+void     gp_theme_set_orientation (GpTheme        *theme,
+                                   GtkOrientation  orientation);
+
+G_END_DECLS
+
+#endif
diff --git a/gnome-panel/panel-applet-frame.c b/gnome-panel/panel-applet-frame.c
index 66f086e..ca054ef 100644
--- a/gnome-panel/panel-applet-frame.c
+++ b/gnome-panel/panel-applet-frame.c
@@ -35,7 +35,6 @@
 #include "panel.h"
 #include "applet.h"
 #include "panel-marshal.h"
-#include "panel-background.h"
 #include "panel-layout.h"
 #include "panel-lockdown.h"
 #include "panel-object-loader.h"
@@ -97,7 +96,6 @@ panel_applet_frame_draw (GtkWidget *widget,
        GtkStyleContext *context;
        GtkStateFlags     state;
        cairo_pattern_t  *bg_pattern;
-       PanelBackground  *background;
 
         if (GTK_WIDGET_CLASS (panel_applet_frame_parent_class)->draw)
                 GTK_WIDGET_CLASS (panel_applet_frame_parent_class)->draw (widget, cr);
@@ -117,10 +115,8 @@ panel_applet_frame_draw (GtkWidget *widget,
        gtk_style_context_get (context, state,
                               "background-image", &bg_pattern,
                               NULL);
-       background = &frame->priv->panel->toplevel->background;
 
-       if (bg_pattern && (background->type == PANEL_BACK_IMAGE ||
-           (background->type == PANEL_BACK_COLOR && background->has_alpha))) {
+       if (bg_pattern) {
                cairo_matrix_t ptm;
 
                cairo_matrix_init_translate (&ptm,
diff --git a/gnome-panel/panel-enums-gsettings.h b/gnome-panel/panel-enums-gsettings.h
index 0c9f3c3..546eb9f 100644
--- a/gnome-panel/panel-enums-gsettings.h
+++ b/gnome-panel/panel-enums-gsettings.h
@@ -47,12 +47,6 @@ typedef enum {
 } PanelAnimationSpeed;
 
 typedef enum {
-       PANEL_BACK_NONE  = 0,
-       PANEL_BACK_COLOR = 1,
-       PANEL_BACK_IMAGE = 2
-} PanelBackgroundType;
-
-typedef enum {
        PANEL_BACKGROUND_IMAGE_STYLE_NONE    = 0,
        PANEL_BACKGROUND_IMAGE_STYLE_STRETCH = 1,
        PANEL_BACKGROUND_IMAGE_STYLE_FIT     = 2
diff --git a/gnome-panel/panel-menu-bar-object.c b/gnome-panel/panel-menu-bar-object.c
index 600ccf9..e9e2785 100644
--- a/gnome-panel/panel-menu-bar-object.c
+++ b/gnome-panel/panel-menu-bar-object.c
@@ -24,7 +24,6 @@
 
 #include <config.h>
 
-#include "panel-background.h"
 #include "panel-typebuiltins.h"
 
 #include "panel-menu-bar-object.h"
diff --git a/gnome-panel/panel-schemas.h b/gnome-panel/panel-schemas.h
index 0a3d495..47762a1 100644
--- a/gnome-panel/panel-schemas.h
+++ b/gnome-panel/panel-schemas.h
@@ -53,14 +53,6 @@
 #define PANEL_TOPLEVEL_AUTO_HIDE_SIZE_KEY   "auto-hide-size"
 #define PANEL_TOPLEVEL_ANIMATION_SPEED_KEY  "animation-speed"
 
-#define PANEL_BACKGROUND_SCHEMA_CHILD     "background"
-#define PANEL_BACKGROUND_TYPE_KEY         "type"
-#define PANEL_BACKGROUND_COLOR_KEY        "color"
-#define PANEL_BACKGROUND_IMAGE_URI_KEY    "image-uri"
-#define PANEL_BACKGROUND_IMAGE_STYLE_KEY  "image-style"
-#define PANEL_BACKGROUND_IMAGE_ROTATE_KEY "image-rotate"
-#define PANEL_BACKGROUND_COLOR_DEFAULT    "rgba(255,255,255,.2)"
-
 #define PANEL_OBJECT_SCHEMA             "org.gnome.gnome-panel.object"
 #define PANEL_OBJECT_IID_KEY            "object-iid"
 #define PANEL_OBJECT_TOPLEVEL_ID_KEY    "toplevel-id"
diff --git a/gnome-panel/panel-separator.c b/gnome-panel/panel-separator.c
index a809c0b..9142612 100644
--- a/gnome-panel/panel-separator.c
+++ b/gnome-panel/panel-separator.c
@@ -22,7 +22,6 @@
 
 #include <config.h>
 
-#include "panel-background.h"
 #include "panel-layout.h"
 
 #include "panel-separator.h"
diff --git a/gnome-panel/panel-toplevel.c b/gnome-panel/panel-toplevel.c
index 8d47e33..58df8e0 100644
--- a/gnome-panel/panel-toplevel.c
+++ b/gnome-panel/panel-toplevel.c
@@ -36,6 +36,7 @@
 #include <libpanel-util/panel-glib.h>
 
 #include "gp-arrow-button.h"
+#include "gp-theme.h"
 #include "panel-xutils.h"
 #include "panel-multiscreen.h"
 #include "panel-a11y.h"
@@ -79,6 +80,8 @@ struct _PanelToplevelPrivate {
        GSettings              *delayed_settings;
        guint                   apply_delayed_id;
 
+       GpTheme                *theme;
+
        gboolean                expand;
        PanelOrientation        orientation;
        int                     size;
@@ -2410,38 +2413,6 @@ panel_toplevel_initially_hide (PanelToplevel *toplevel)
 }
 
 static void
-set_background_default_style (GtkWidget *widget)
-{
-       PanelToplevel *toplevel;
-       GtkStyleContext *context;
-       GtkStateFlags state;
-       GdkRGBA *bg_color;
-       cairo_pattern_t *bg_image;
-
-       if (!gtk_widget_get_realized (widget))
-               return;
-
-       toplevel = PANEL_TOPLEVEL (widget);
-
-       context = gtk_widget_get_style_context (widget);
-       state = gtk_style_context_get_state (context);
-
-       gtk_style_context_get (context, state,
-                              "background-color", &bg_color,
-                              "background-image", &bg_image,
-                              NULL);
-
-       panel_background_set_default_style (&toplevel->background,
-                                           bg_color, bg_image);
-
-       if (bg_color)
-               gdk_rgba_free (bg_color);
-
-       if (bg_image)
-               cairo_pattern_destroy (bg_image);
-}
-
-static void
 panel_toplevel_realize (GtkWidget *widget)
 {
        PanelToplevel *toplevel;
@@ -2465,9 +2436,6 @@ panel_toplevel_realize (GtkWidget *widget)
 
        window = gtk_widget_get_window (widget);
 
-       set_background_default_style (widget);
-       panel_background_realized (&toplevel->background, window);
-
        panel_struts_set_window_hint (toplevel);
 
        gdk_window_set_group (window, window);
@@ -2502,7 +2470,6 @@ panel_toplevel_unrealize (GtkWidget *widget)
        toplevel = PANEL_TOPLEVEL (widget);
 
        panel_toplevel_disconnect_timeouts (toplevel);
-       panel_background_unrealized (&toplevel->background);
 
        GTK_WIDGET_CLASS (panel_toplevel_parent_class)->unrealize (widget);
 }
@@ -2514,6 +2481,8 @@ panel_toplevel_dispose (GObject *widget)
        
        panel_toplevel_disconnect_timeouts (toplevel);
 
+       g_clear_object (&toplevel->priv->theme);
+
         G_OBJECT_CLASS (panel_toplevel_parent_class)->dispose (widget);
 }
 
@@ -2605,37 +2574,6 @@ panel_toplevel_get_preferred_height(GtkWidget *widget, gint *minimal_height, gin
 }
 
 static void
-set_background_region (PanelToplevel *toplevel)
-{
-       GtkWidget *widget;
-       GdkWindow *window;
-       gint origin_x;
-       gint origin_y;
-       GtkAllocation allocation;
-       GtkOrientation orientation;
-
-       widget = GTK_WIDGET (toplevel);
-
-       if (!gtk_widget_get_realized (widget))
-               return;
-
-       window = gtk_widget_get_window (widget);
-       origin_x = -1;
-       origin_y = -1;
-
-       gdk_window_get_origin (window, &origin_x, &origin_y);
-       gtk_widget_get_allocation (widget, &allocation);
-
-       orientation = GTK_ORIENTATION_HORIZONTAL;
-       if (toplevel->priv->orientation & PANEL_VERTICAL_MASK)
-               orientation = GTK_ORIENTATION_VERTICAL;
-
-       panel_background_change_region (&toplevel->background, orientation,
-                                       origin_x, origin_y,
-                                       allocation.width, allocation.height);
-}
-
-static void
 panel_toplevel_size_allocate (GtkWidget     *widget,
                              GtkAllocation *allocation)
 {
@@ -2683,8 +2621,6 @@ panel_toplevel_size_allocate (GtkWidget     *widget,
 
        if (child && gtk_widget_get_visible (child))
                gtk_widget_size_allocate (child, &challoc);
-
-       set_background_region (toplevel);
 }
 
 static gboolean
@@ -2818,19 +2754,6 @@ panel_toplevel_button_release_event (GtkWidget      *widget,
 }
 
 static gboolean
-panel_toplevel_configure_event (GtkWidget        *widget,
-                               GdkEventConfigure *event)
-{
-       PanelToplevel *toplevel;
-
-       toplevel = PANEL_TOPLEVEL (widget);
-
-       set_background_region (toplevel);
-
-       return GDK_EVENT_PROPAGATE;
-}
-
-static gboolean
 panel_toplevel_key_press_event (GtkWidget   *widget,
                                GdkEventKey *event)
 {
@@ -3307,16 +3230,6 @@ panel_toplevel_focus_out_event (GtkWidget     *widget,
 }
 
 static void
-panel_toplevel_state_flags_changed (GtkWidget     *widget,
-                                    GtkStateFlags  previous_state)
-{
-       GTK_WIDGET_CLASS (panel_toplevel_parent_class)->state_flags_changed (widget,
-                                                                            previous_state);
-
-       set_background_default_style (widget);
-}
-
-static void
 panel_toplevel_style_updated (GtkWidget *widget)
 {
        PanelToplevel *toplevel = PANEL_TOPLEVEL (widget);
@@ -3326,12 +3239,24 @@ panel_toplevel_style_updated (GtkWidget *widget)
        if (GTK_WIDGET_CLASS (panel_toplevel_parent_class)->style_updated)
                GTK_WIDGET_CLASS (panel_toplevel_parent_class)->style_updated (widget);
 
-       set_background_default_style (widget);
-
        panel_widget_set_size (toplevel->priv->panel_widget, toplevel->priv->size);
 }
 
 static void
+panel_toplevel_composited_changed (GtkWidget *widget)
+{
+       PanelToplevel *toplevel;
+       GdkScreen *screen;
+       gboolean composited;
+
+       toplevel = PANEL_TOPLEVEL (widget);
+       screen = gdk_screen_get_default ();
+       composited = gdk_screen_is_composited (screen);
+
+       gp_theme_set_composited (toplevel->priv->theme, composited);
+}
+
+static void
 panel_toplevel_drag_threshold_changed (PanelToplevel *toplevel)
 {
        int threshold;
@@ -3406,6 +3331,29 @@ panel_toplevel_screen_changed (GtkWidget *widget,
        gtk_widget_queue_resize (widget);
 }
 
+static void
+panel_toplevel_constructed (GObject *object)
+{
+       PanelToplevel *toplevel;
+       GdkScreen *screen;
+       gboolean composited;
+       GtkOrientation orientation;
+
+       toplevel = PANEL_TOPLEVEL (object);
+       screen = gdk_screen_get_default ();
+
+       G_OBJECT_CLASS (panel_toplevel_parent_class)->constructed (object);
+
+       composited = gdk_screen_is_composited (screen);
+       orientation = GTK_ORIENTATION_HORIZONTAL;
+
+       if (toplevel->priv->orientation & PANEL_VERTICAL_MASK)
+               orientation = GTK_ORIENTATION_VERTICAL;
+
+       toplevel->priv->theme = gp_theme_new (toplevel->priv->toplevel_id,
+                                             composited, orientation);
+}
+
 static GObject *
 panel_toplevel_constructor (GType                  type,
                            guint                  n_construct_properties,
@@ -3615,8 +3563,6 @@ panel_toplevel_finalize (GObject *object)
        panel_toplevel_disconnect_gtk_settings (toplevel);
        toplevel->priv->gtk_settings = NULL;
 
-       panel_background_free (&toplevel->background);
-
        if (toplevel->priv->description)
                g_free (toplevel->priv->description);
        toplevel->priv->description = NULL;
@@ -3660,6 +3606,7 @@ panel_toplevel_class_init (PanelToplevelClass *klass)
 
         binding_set = gtk_binding_set_by_class (klass);
 
+       gobject_class->constructed  = panel_toplevel_constructed;
        gobject_class->constructor  = panel_toplevel_constructor;
        gobject_class->set_property = panel_toplevel_set_property;
         gobject_class->get_property = panel_toplevel_get_property;
@@ -3674,7 +3621,6 @@ panel_toplevel_class_init (PanelToplevelClass *klass)
        widget_class->draw                 = panel_toplevel_draw;
        widget_class->button_press_event   = panel_toplevel_button_press_event;
        widget_class->button_release_event = panel_toplevel_button_release_event;
-       widget_class->configure_event      = panel_toplevel_configure_event;
        widget_class->key_press_event      = panel_toplevel_key_press_event;
        widget_class->motion_notify_event  = panel_toplevel_motion_notify_event;
        widget_class->enter_notify_event   = panel_toplevel_enter_notify_event;
@@ -3682,8 +3628,8 @@ panel_toplevel_class_init (PanelToplevelClass *klass)
        widget_class->screen_changed       = panel_toplevel_screen_changed;
        widget_class->focus_in_event       = panel_toplevel_focus_in_event;
        widget_class->focus_out_event      = panel_toplevel_focus_out_event;
-       widget_class->state_flags_changed  = panel_toplevel_state_flags_changed;
        widget_class->style_updated        = panel_toplevel_style_updated;
+       widget_class->composited_changed   = panel_toplevel_composited_changed;
 
        container_class->check_resize = panel_toplevel_check_resize;
 
@@ -4158,8 +4104,6 @@ panel_toplevel_init (PanelToplevel *toplevel)
                               GDK_ENTER_NOTIFY_MASK |
                               GDK_LEAVE_NOTIFY_MASK);
 
-       gtk_widget_set_app_paintable (widget, TRUE);
-
        panel_toplevel_setup_widgets (toplevel);
        panel_toplevel_update_description (toplevel);
        panel_toplevel_update_gtk_settings (toplevel);
@@ -4176,8 +4120,6 @@ panel_toplevel_init (PanelToplevel *toplevel)
 
        context = gtk_widget_get_style_context (GTK_WIDGET (toplevel));
        gtk_style_context_add_class (context, GTK_STYLE_CLASS_HORIZONTAL);
-
-       panel_background_init (&toplevel->background);
 }
 
 PanelWidget *
@@ -4376,6 +4318,7 @@ panel_toplevel_set_toplevel_id (PanelToplevel *toplevel,
        g_assert (toplevel->priv->toplevel_id == NULL);
 
        toplevel->priv->toplevel_id = g_strdup (toplevel_id);
+       gtk_widget_set_name (GTK_WIDGET (toplevel), toplevel_id);
 }
 
 const char *
@@ -4390,8 +4333,6 @@ static void
 panel_toplevel_set_settings_path (PanelToplevel *toplevel,
                                  const char    *settings_path)
 {
-       GSettings *settings_background;
-
        g_assert (toplevel->priv->settings_path == NULL);
        g_assert (toplevel->priv->settings == NULL);
        g_assert (toplevel->priv->delayed_settings == NULL);
@@ -4402,12 +4343,6 @@ panel_toplevel_set_settings_path (PanelToplevel *toplevel,
        toplevel->priv->delayed_settings = g_settings_new_with_path (PANEL_TOPLEVEL_SCHEMA,
                                                                     settings_path);
        g_settings_delay (toplevel->priv->delayed_settings);
-
-       settings_background = g_settings_get_child (toplevel->priv->settings,
-                                                   PANEL_BACKGROUND_SCHEMA_CHILD);
-
-       panel_background_settings_init (&toplevel->background, settings_background);
-       g_object_unref (settings_background);
 }
 
 static void
diff --git a/gnome-panel/panel-toplevel.h b/gnome-panel/panel-toplevel.h
index 528c9c7..f1f9c67 100644
--- a/gnome-panel/panel-toplevel.h
+++ b/gnome-panel/panel-toplevel.h
@@ -25,7 +25,6 @@
 
 #include <gtk/gtk.h>
 
-#include "panel-background.h"
 #include "panel-enums.h"
 
 G_BEGIN_DECLS
@@ -51,8 +50,6 @@ typedef struct _PanelToplevelPrivate PanelToplevelPrivate;
 struct _PanelToplevel {
        GtkWindow              window_instance;
 
-       PanelBackground        background;
-
        PanelToplevelPrivate  *priv;
 };
 
diff --git a/gnome-panel/panel.c b/gnome-panel/panel.c
index 985874b..ec436b4 100644
--- a/gnome-panel/panel.c
+++ b/gnome-panel/panel.c
@@ -320,22 +320,21 @@ panel_key_press_event (PanelToplevel *toplevel,
 }
 
 static GSettings *
-get_settings_background_for_toplevel (PanelToplevel *toplevel)
+get_theme_settings_for_toplevel (PanelToplevel *toplevel)
 {
        char      *toplevel_settings_path;
        GSettings *settings;
-       GSettings *settings_background;
+       GSettings *theme;
 
        g_object_get (toplevel, "settings-path", &toplevel_settings_path, NULL);
        settings = g_settings_new_with_path (PANEL_TOPLEVEL_SCHEMA,
                                             toplevel_settings_path);
-       settings_background = g_settings_get_child (settings,
-                                                   PANEL_BACKGROUND_SCHEMA_CHILD);
+       theme = g_settings_get_child (settings, "theme");
 
        g_object_unref (settings);
        g_free (toplevel_settings_path);
 
-       return settings_background;
+       return theme;
 }
 
 static gboolean
@@ -352,21 +351,18 @@ set_background_image_from_uri (PanelToplevel *toplevel,
        }
        g_object_unref (file);
 
-       settings = get_settings_background_for_toplevel (toplevel);
+       settings = get_theme_settings_for_toplevel (toplevel);
 
-       if (!g_settings_is_writable (settings,
-                                    PANEL_BACKGROUND_TYPE_KEY) ||
-           !g_settings_is_writable (settings,
-                                    PANEL_BACKGROUND_IMAGE_URI_KEY)) {
+       if (!g_settings_is_writable (settings, "custom-bg-image") ||
+           !g_settings_is_writable (settings, "bg-image")) {
                g_object_unref (settings);
                return FALSE;
        }
 
-       g_settings_set_string (settings, PANEL_BACKGROUND_IMAGE_URI_KEY, uri);
-       g_settings_set_enum (settings, PANEL_BACKGROUND_TYPE_KEY, PANEL_BACK_IMAGE);
+       g_settings_set_enum (settings, "custom-bg-image", TRUE);
+       g_settings_set_string (settings, "bg-image", uri);
 
        g_object_unref (settings);
-
        return FALSE;
 }
 
@@ -381,12 +377,10 @@ set_background_color (PanelToplevel *toplevel,
        if (!dropped)
                return FALSE;
 
-       settings = get_settings_background_for_toplevel (toplevel);
+       settings = get_theme_settings_for_toplevel (toplevel);
 
-       if (!g_settings_is_writable (settings,
-                                    PANEL_BACKGROUND_TYPE_KEY) ||
-           !g_settings_is_writable (settings,
-                                    PANEL_BACKGROUND_COLOR_KEY)) {
+       if (!g_settings_is_writable (settings, "custom-bg-color") ||
+           !g_settings_is_writable (settings, "bg-color")) {
                g_object_unref (settings);
                return FALSE;
        }
@@ -398,12 +392,11 @@ set_background_color (PanelToplevel *toplevel,
 
        color_str = gdk_rgba_to_string (&color);
 
-       g_settings_set_string (settings, PANEL_BACKGROUND_COLOR_KEY, color_str);
-       g_settings_set_enum (settings, PANEL_BACKGROUND_TYPE_KEY, PANEL_BACK_COLOR);
-
+       g_settings_set_boolean (settings, "custom-bg-color", TRUE);
+       g_settings_set_string (settings, "bg-color", color_str);
        g_free (color_str);
-       g_object_unref (settings);
 
+       g_object_unref (settings);
        return TRUE;
 }
 
@@ -412,16 +405,14 @@ reset_background (PanelToplevel *toplevel)
 {
        GSettings *settings;
 
-       settings = get_settings_background_for_toplevel (toplevel);
+       settings = get_theme_settings_for_toplevel (toplevel);
 
-       if (!g_settings_is_writable (settings,
-                                    PANEL_BACKGROUND_TYPE_KEY)) {
+       if (!g_settings_is_writable (settings, "custom-bg-image")) {
                g_object_unref (settings);
                return FALSE;
        }
 
-       g_settings_set_enum (settings, PANEL_BACKGROUND_TYPE_KEY, PANEL_BACK_NONE);
-
+       g_settings_set_boolean (settings, "custom-bg-image", FALSE);
        g_object_unref (settings);
 
        return TRUE;


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