Commit 885d4a22 authored by Alberts Muktupāvels's avatar Alberts Muktupāvels

replace PanelBackground with GpTheme

parent 29c331f7
......@@ -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">
......
......@@ -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" \
......
......@@ -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>
......
/*
* 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);
}
/*
* 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
......@@ -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,
......
This diff is collapsed.
/*
* panel-background.h: panel background rendering
*
* Copyright (C) 2002, 2003 Sun Microsystems, Inc.
*
* 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/>.
*
* Authors:
* Mark McLoughlin <mark@skynet.ie>
*/
#ifndef __PANEL_BACKGROUND_H__
#define __PANEL_BACKGROUND_H__
#include <glib.h>
#include <gtk/gtk.h>
#include "panel-enums.h"
#include "panel-types.h"
typedef struct _PanelBackground PanelBackground;
struct _PanelBackground {
GSettings *settings;
PanelBackgroundType type;
GdkRGBA color;
char *image;
GdkPixbuf *loaded_image;
GtkOrientation orientation;
GdkRectangle region;
GdkPixbuf *transformed_image;
cairo_pattern_t *composited_pattern;
GdkWindow *window;
cairo_pattern_t *default_pattern;
GdkRGBA default_color;
PanelBackgroundImageStyle style_image;
guint rotate_image : 1;
guint has_alpha : 1;
guint loaded : 1;
guint transformed : 1;
guint composited : 1;
};
void panel_background_init (PanelBackground *background);
void panel_background_settings_init (PanelBackground *background,
GSettings *settings);
void panel_background_free (PanelBackground *background);
void panel_background_set_default_style (PanelBackground *background,
GdkRGBA *color,
cairo_pattern_t *pattern);
void panel_background_realized (PanelBackground *background,
GdkWindow *window);
void panel_background_unrealized (PanelBackground *background);
void panel_background_change_region (PanelBackground *background,
GtkOrientation orientation,
int x,
int y,
int width,
int height);
PanelBackgroundType panel_background_get_type (PanelBackground *background);
#endif /* __PANEL_BACKGROUND_H__ */
......@@ -46,12 +46,6 @@ typedef enum {
PANEL_ANIMATION_FAST = 2
} 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,
......
......@@ -24,7 +24,6 @@
#include <config.h>
#include "panel-background.h"
#include "panel-typebuiltins.h"
#include "panel-menu-bar-object.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"
......
......@@ -22,7 +22,6 @@
#include <config.h>
#include "panel-background.h"
#include "panel-layout.h"
#include "panel-separator.h"
......
......@@ -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;
......@@ -2409,38 +2412,6 @@ panel_toplevel_initially_hide (PanelToplevel *toplevel)
gtk_widget_queue_resize (GTK_WIDGET (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)
{
......@@ -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);
}
......@@ -2604,37 +2573,6 @@ panel_toplevel_get_preferred_height(GtkWidget *widget, gint *minimal_height, gin
*minimal_height = *natural_height = requisition.height;
}
static void
set_background_region (PanelToplevel *toplevel)
{
GtkWidget *widget;
GdkWindow *window;
gint origin_x;
gint origin_y;
GtkAllocation allocation;