[Xfce4-commits] <xfce4-indicator-plugin:master> Icons can now be scaled up to the row size (or panel size in 4.8).
Andrzej
noreply at xfce.org
Fri Mar 23 15:40:02 CET 2012
Updating branch refs/heads/master
to ac510b4d7851c2b7fece06b17f048d15831c2770 (commit)
from 733903a016ee6fea8f51c0f600de97aeb67fb8b2 (commit)
commit ac510b4d7851c2b7fece06b17f048d15831c2770
Author: Andrzej <ndrwrdck at gmail.com>
Date: Wed Mar 21 01:49:04 2012 +0900
Icons can now be scaled up to the row size (or panel size in 4.8).
Because there is no cap on the maximum icon size, this patch changes
the behavior of the plugin in panel 4.8. We probably need a configuration
variable like "Max icon size" or "Min number of rows" to make the icons
smaller again and perhaps allow multi-row layout in 4.8.
panel-plugin/indicator-button.c | 98 +++++++++++++++++++++++++++------------
panel-plugin/indicator-button.h | 2 +-
2 files changed, 69 insertions(+), 31 deletions(-)
diff --git a/panel-plugin/indicator-button.c b/panel-plugin/indicator-button.c
index 34ccfcb..27adffe 100644
--- a/panel-plugin/indicator-button.c
+++ b/panel-plugin/indicator-button.c
@@ -60,7 +60,7 @@ xfce_indicator_button_init (XfceIndicatorButton *button)
button->size = 0;
button->panel_size = 0;
- button->orig_icon_size = 0;
+ button->icon_size = 24;
button->panel_orientation = GTK_ORIENTATION_HORIZONTAL;
button->orientation = GTK_ORIENTATION_HORIZONTAL;
@@ -122,18 +122,11 @@ static void
xfce_indicator_button_update_layout (XfceIndicatorButton *button)
{
GtkRequisition label_size;
- gint border_thickness;
- GtkStyle *style;
- gint icon_size;
g_return_if_fail (XFCE_IS_INDICATOR_BUTTON (button));
if (button->icon != NULL && button->size != 0)
{
- style = gtk_widget_get_style (GTK_WIDGET (button));
- border_thickness = 2 * MAX (style->xthickness, style->ythickness) + 2;
- icon_size = MIN (button->size - border_thickness, button->orig_icon_size);
-
if (button->label != NULL &&
button->panel_orientation == GTK_ORIENTATION_VERTICAL &&
button->orientation == GTK_ORIENTATION_HORIZONTAL)
@@ -143,18 +136,66 @@ xfce_indicator_button_update_layout (XfceIndicatorButton *button)
/* put icon above the label if number of rows > 1 (they look better)
or if they don't fit when arranged horizontally */
if (button->panel_size != button->size ||
- label_size.width > button->panel_size - icon_size - border_thickness)
+ label_size.width > button->panel_size - button->size)
gtk_orientable_set_orientation (GTK_ORIENTABLE (button->box), GTK_ORIENTATION_VERTICAL);
else
gtk_orientable_set_orientation (GTK_ORIENTABLE (button->box), GTK_ORIENTATION_HORIZONTAL);
}
- xfce_panel_image_set_size (XFCE_PANEL_IMAGE (button->icon), icon_size);
+ xfce_panel_image_set_size (XFCE_PANEL_IMAGE (button->icon), button->icon_size);
}
}
+static void
+xfce_indicator_button_update_icon (XfceIndicatorButton *button)
+{
+ GdkPixbuf *pixbuf_s, *pixbuf_d;
+ gdouble aspect;
+ gint size;
+
+ g_return_if_fail (GTK_IS_IMAGE (button->orig_icon));
+ g_return_if_fail (XFCE_IS_PANEL_IMAGE (button->icon));
+
+ size = button->icon_size;
+
+ /* Copied from xfce_panel_image.c, try to snap to icon sizes, which minimize smoothing */
+#if 0
+ if (size > 16 && size < 22)
+ size = 16;
+ else if (size > 22 && size < 24)
+ size = 22;
+ else if (size > 24 && size < 32)
+ size = 24;
+#endif
+
+ pixbuf_s = gtk_image_get_pixbuf (GTK_IMAGE (button->orig_icon));
+
+ if (pixbuf_s != NULL)
+ {
+ aspect = (gdouble) gdk_pixbuf_get_width (pixbuf_s) /
+ (gdouble) gdk_pixbuf_get_height (pixbuf_s);
+ if (aspect > 1.0)
+ pixbuf_d = gdk_pixbuf_scale_simple
+ (pixbuf_s, size, (gint) (size / aspect),
+ GDK_INTERP_BILINEAR);
+ else
+ pixbuf_d = gdk_pixbuf_scale_simple
+ (pixbuf_s, (gint) (size * aspect), size,
+ GDK_INTERP_BILINEAR);
+ xfce_panel_image_set_from_pixbuf (XFCE_PANEL_IMAGE (button->icon), pixbuf_d);
+ }
+ else
+ {
+ xfce_panel_image_set_from_source (XFCE_PANEL_IMAGE (button->icon), "image-missing");
+ }
+
+ xfce_panel_image_set_size (XFCE_PANEL_IMAGE (button->icon), button->icon_size);
+}
+
+
+
void
xfce_indicator_button_set_label (XfceIndicatorButton *button,
GtkLabel *label)
@@ -189,13 +230,7 @@ on_pixbuf_changed (GtkImage *image, GParamSpec *pspec, XfceIndicatorButton *butt
g_return_if_fail (GTK_IS_IMAGE (image));
g_return_if_fail (XFCE_IS_PANEL_IMAGE (button->icon));
- pixbuf = gtk_image_get_pixbuf (image);
-
- if (pixbuf != NULL)
- {
- button->orig_icon_size = gdk_pixbuf_get_width (pixbuf);
- xfce_panel_image_set_from_pixbuf (button->icon, pixbuf);
- }
+ xfce_indicator_button_update_icon (button);
}
@@ -209,6 +244,8 @@ xfce_indicator_button_set_image (XfceIndicatorButton *button,
g_return_if_fail (XFCE_IS_INDICATOR_BUTTON (button));
g_return_if_fail (GTK_IS_IMAGE (image));
+ g_debug ("indicator-button set image, image=%x\n", (uint) image);
+
if (button->orig_icon != GTK_WIDGET (image))
{
if (button->orig_icon != NULL)
@@ -229,19 +266,10 @@ xfce_indicator_button_set_image (XfceIndicatorButton *button,
button->orig_icon_handler = g_signal_connect
(G_OBJECT (image), "notify::pixbuf", G_CALLBACK (on_pixbuf_changed), button);
- pixbuf = gtk_image_get_pixbuf (image);
- if (pixbuf)
- {
- button->orig_icon_size = gdk_pixbuf_get_width (pixbuf);
- button->icon = xfce_panel_image_new_from_pixbuf (pixbuf);
- }
- else
- {
- button->icon = xfce_panel_image_new_from_source ("image-missing");
- /* hard-coded size to mimic the limitation of pixbuf scaling */
- button->orig_icon_size = 24;
- }
+
+ button->icon = xfce_panel_image_new ();
+ xfce_indicator_button_update_icon (button);
gtk_box_pack_start (GTK_BOX (button->box), button->icon, TRUE, FALSE, 1);
gtk_widget_show (button->icon);
@@ -360,6 +388,9 @@ xfce_indicator_button_set_size (XfceIndicatorButton *button,
gint size)
{
gboolean needs_update = FALSE;
+ gint border_thickness;
+ GtkStyle *style;
+ gdouble aspect;
g_return_if_fail (XFCE_IS_INDICATOR_BUTTON (button));
@@ -376,7 +407,14 @@ xfce_indicator_button_set_size (XfceIndicatorButton *button,
}
if (needs_update)
- xfce_indicator_button_update_layout (button);
+ {
+ style = gtk_widget_get_style (GTK_WIDGET (button));
+ border_thickness = 2 * MAX (style->xthickness, style->ythickness) + 2;
+ button->icon_size = button->size - border_thickness;
+
+ xfce_indicator_button_update_icon (button);
+ xfce_indicator_button_update_layout (button);
+ }
}
diff --git a/panel-plugin/indicator-button.h b/panel-plugin/indicator-button.h
index b2a1926..80e93fb 100644
--- a/panel-plugin/indicator-button.h
+++ b/panel-plugin/indicator-button.h
@@ -48,7 +48,7 @@ struct _XfceIndicatorButton
gint panel_size;
gint size;
- gint orig_icon_size;
+ gint icon_size;
GtkOrientation panel_orientation;
GtkOrientation orientation;
More information about the Xfce4-commits
mailing list