[gnome-panel/gtk3] Handle opacity for solid color backgrounds again
- From: Carlos Garcia Campos <carlosgc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-panel/gtk3] Handle opacity for solid color backgrounds again
- Date: Mon, 17 Jan 2011 17:43:40 +0000 (UTC)
commit c78acd1548fae57f9211ae6019ea957a37cd66da
Author: Carlos Garcia Campos <carlosgc gnome org>
Date: Mon Jan 17 18:42:32 2011 +0100
Handle opacity for solid color backgrounds again
gnome-panel/panel-profile.c | 97 +++++++++++++++++----------------
gnome-panel/panel-profile.h | 3 -
gnome-panel/panel-properties-dialog.c | 18 +++----
3 files changed, 58 insertions(+), 60 deletions(-)
---
diff --git a/gnome-panel/panel-profile.c b/gnome-panel/panel-profile.c
index a4f0935..4a4a68e 100644
--- a/gnome-panel/panel-profile.c
+++ b/gnome-panel/panel-profile.c
@@ -418,6 +418,36 @@ panel_profile_get_background_type (PanelToplevel *toplevel)
TOPLEVEL_IS_WRITABLE_FUNC ("background/type", background, type)
+static void
+panel_profile_set_background_opacity (PanelToplevel *toplevel,
+ gdouble opacity)
+{
+ GConfClient *client;
+ const char *key;
+
+ client = panel_gconf_get_client ();
+
+ key = panel_profile_get_toplevel_key (toplevel, "background/opacity");
+ gconf_client_set_int (client, key, (guint16) ((opacity * 65535.) + 0.5), NULL);
+}
+
+static gdouble
+panel_profile_get_background_opacity (PanelToplevel *toplevel)
+{
+ GConfClient *client;
+ const char *key;
+ guint16 opacity;
+
+ client = panel_gconf_get_client ();
+
+ key = panel_profile_get_toplevel_key (toplevel, "background/opacity");
+ opacity = gconf_client_get_int (client, key, NULL);
+
+ return opacity / 65535.;
+}
+
+TOPLEVEL_IS_WRITABLE_FUNC ("background/opacity", background, opacity)
+
void
panel_profile_set_background_color (PanelToplevel *toplevel,
const GdkRGBA *color)
@@ -432,6 +462,8 @@ panel_profile_set_background_color (PanelToplevel *toplevel,
key = panel_profile_get_toplevel_key (toplevel, "background/color");
gconf_client_set_string (client, key, color_str, NULL);
+ panel_profile_set_background_opacity (toplevel, color->alpha);
+
g_free (color_str);
}
@@ -451,8 +483,9 @@ panel_profile_get_background_color (PanelToplevel *toplevel,
color->red = 0.;
color->green = 0.;
color->blue = 0.;
- color->alpha = 0.;
+ color->alpha = 1.;
}
+ color->alpha = panel_profile_get_background_opacity (toplevel);
g_free (color_str);
}
@@ -460,41 +493,6 @@ panel_profile_get_background_color (PanelToplevel *toplevel,
TOPLEVEL_IS_WRITABLE_FUNC ("background/color", background, color)
void
-panel_profile_set_background_opacity (PanelToplevel *toplevel,
- guint16 opacity)
-{
-#if 0
- GConfClient *client;
- const char *key;
-
- client = panel_gconf_get_client ();
-
- key = panel_profile_get_toplevel_key (toplevel, "background/opacity");
- gconf_client_set_int (client, key, opacity, NULL);
-#endif
-}
-
-guint16
-panel_profile_get_background_opacity (PanelToplevel *toplevel)
-{
-#if 0
- GConfClient *client;
- const char *key;
- guint16 opacity;
-
- client = panel_gconf_get_client ();
-
- key = panel_profile_get_toplevel_key (toplevel, "background/opacity");
- opacity = gconf_client_get_int (client, key, NULL);
-
- return opacity;
-#endif
- return 0;
-}
-
-TOPLEVEL_IS_WRITABLE_FUNC ("background/opacity", background, opacity)
-
-void
panel_profile_set_background_image (PanelToplevel *toplevel,
const char *image)
{
@@ -779,6 +777,7 @@ get_background_color (GConfClient *client,
GError *error;
const char *key;
char *color_str;
+ guint16 alpha;
error = NULL;
key = panel_gconf_sprintf ("%s/background/color", toplevel_dir);
@@ -796,17 +795,17 @@ get_background_color (GConfClient *client,
g_free (color_str);
-#if 0
error = NULL;
key = panel_gconf_sprintf ("%s/background/opacity", toplevel_dir);
- color->alpha = gconf_client_get_int (client, key, &error);
+ alpha = gconf_client_get_int (client, key, &error);
if (error) {
g_warning (_("Error reading GConf integer value '%s': %s"),
key, error->message);
g_error_free (error);
- color->alpha = 65535; /* fallback to fully opaque */
- }
-#endif
+ color->alpha = 1.; /* fallback to fully opaque */
+ } else {
+ color->alpha = alpha / 65535.;
+ }
}
static char *
@@ -1234,12 +1233,18 @@ panel_profile_background_change_notify (GConfClient *client,
if (gdk_rgba_parse (&color, str))
panel_background_set_color (background, &color);
}
-#if 0
} else if (!strcmp (key, "opacity")) {
- if (value->type == GCONF_VALUE_INT)
- panel_background_set_opacity (background,
- gconf_value_get_int (value));
-#endif
+ if (value->type == GCONF_VALUE_INT) {
+ guint16 opacity;
+ const GdkRGBA *bg_color;
+ GdkRGBA color;
+
+ opacity = gconf_value_get_int (value);
+ bg_color = panel_background_get_color (background);
+ color = *bg_color;
+ color.alpha = opacity / 65535.;
+ panel_background_set_color (background, &color);
+ }
} else if (!strcmp (key, "image")) {
if (value->type == GCONF_VALUE_STRING)
panel_background_set_image (background,
diff --git a/gnome-panel/panel-profile.h b/gnome-panel/panel-profile.h
index 767eded..7f0ec72 100644
--- a/gnome-panel/panel-profile.h
+++ b/gnome-panel/panel-profile.h
@@ -121,9 +121,6 @@ void panel_profile_get_background_color (PanelToplevel *topl
GdkRGBA *color);
gboolean panel_profile_is_writable_background_color (PanelToplevel *toplevel);
-void panel_profile_set_background_opacity (PanelToplevel *toplevel,
- guint16 opacity);
-guint16 panel_profile_get_background_opacity (PanelToplevel *toplevel);
gboolean panel_profile_is_writable_background_opacity (PanelToplevel *toplevel);
void panel_profile_set_background_image (PanelToplevel *toplevel,
diff --git a/gnome-panel/panel-properties-dialog.c b/gnome-panel/panel-properties-dialog.c
index 7ecc275..7d4ff56 100644
--- a/gnome-panel/panel-properties-dialog.c
+++ b/gnome-panel/panel-properties-dialog.c
@@ -404,7 +404,7 @@ static void
panel_properties_dialog_opacity_changed (PanelPropertiesDialog *dialog)
{
gdouble percentage;
- guint16 opacity;
+ GdkRGBA color;
percentage = gtk_range_get_value (GTK_RANGE (dialog->opacity_scale));
@@ -413,17 +413,16 @@ panel_properties_dialog_opacity_changed (PanelPropertiesDialog *dialog)
else if (percentage <= 2)
percentage = 0;
- opacity = (percentage / 100) * 65535;
-
- panel_profile_set_background_opacity (dialog->toplevel, opacity);
+ gtk_color_button_get_rgba (GTK_COLOR_BUTTON (dialog->color_button), &color);
+ color.alpha = (percentage / 100);
+ panel_profile_set_background_color (dialog->toplevel, &color);
}
static void
panel_properties_dialog_setup_opacity_scale (PanelPropertiesDialog *dialog,
GtkBuilder *gui)
{
- guint16 opacity;
- gdouble percentage;
+ GdkRGBA color;
dialog->opacity_scale = PANEL_GTK_BUILDER_GET (gui, "opacity_scale");
g_return_if_fail (dialog->opacity_scale != NULL);
@@ -432,11 +431,8 @@ panel_properties_dialog_setup_opacity_scale (PanelPropertiesDialog *dialog,
dialog->opacity_legend = PANEL_GTK_BUILDER_GET (gui, "opacity_legend");
g_return_if_fail (dialog->opacity_legend != NULL);
- opacity = panel_profile_get_background_opacity (dialog->toplevel);
-
- percentage = (opacity * 100.0) / 65535;
-
- gtk_range_set_value (GTK_RANGE (dialog->opacity_scale), percentage);
+ panel_profile_get_background_color (dialog->toplevel, &color);
+ gtk_range_set_value (GTK_RANGE (dialog->opacity_scale), color.alpha * 100.0);
g_signal_connect_swapped (dialog->opacity_scale, "value_changed",
G_CALLBACK (panel_properties_dialog_opacity_changed),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]