From cf836c87a5f422bd572405ecc2e5ccfcaf09e620 Mon Sep 17 00:00:00 2001 From: Simon Steinbeiss <simon.steinbeiss@elfenbeinturm.at> Date: Thu, 5 Mar 2015 08:48:14 +0100 Subject: [PATCH] Correctly calculate the icon's size based on the widget's padding and border instead of an relying on an arbitrary value. --- panel-plugin/pulseaudio-button.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/panel-plugin/pulseaudio-button.c b/panel-plugin/pulseaudio-button.c index 7fea918..759dc60 100644 --- a/panel-plugin/pulseaudio-button.c +++ b/panel-plugin/pulseaudio-button.c @@ -266,10 +266,9 @@ pulseaudio_button_menu_deactivate (PulseaudioButton *button, static void pulseaudio_button_update_icons (PulseaudioButton *button) { - guint i; - GtkIconInfo *info; - GtkStyleContext *context; - gboolean is_symbolic; + guint i; + GtkIconInfo *info; + GtkStyleContext *context; g_return_if_fail (IS_PULSEAUDIO_BUTTON (button)); @@ -332,10 +331,23 @@ void pulseaudio_button_set_size (PulseaudioButton *button, gint size) { + GtkStyleContext *context; + GtkBorder padding; + GtkBorder border; + gint xthickness; + gint ythickness; + g_return_if_fail (IS_PULSEAUDIO_BUTTON (button)); g_return_if_fail (size > 0); - button->icon_size = size - 4; + /* Get widget's padding and border to correctly calculate the button's icon size */ + context = gtk_widget_get_style_context (GTK_WIDGET (button)); + gtk_style_context_get_padding (context, gtk_widget_get_state_flags (GTK_WIDGET (button)), &padding); + gtk_style_context_get_border (context, gtk_widget_get_state_flags (GTK_WIDGET (button)), &border); + xthickness = padding.left+padding.right+border.left+border.right; + ythickness = padding.top+padding.bottom+border.top+border.bottom; + + button->icon_size = size - 2* MAX (xthickness, ythickness); gtk_widget_set_size_request (GTK_WIDGET (button), size, size); pulseaudio_button_update_icons (button); } -- GitLab