[Xfce4-commits] [xfce/xfce4-panel] 01/01: Added an xfce_panel_plugin_get_icon_size function to unify icon sizes across plugins
noreply at xfce.org
noreply at xfce.org
Sat Mar 18 00:27:50 CET 2017
This is an automated email from the git hooks/post-receive script.
andrzejr pushed a commit to branch master
in repository xfce/xfce4-panel.
commit 79555402644ba0299b08048f929d81131c02b83c
Author: Andrzej <ndrwrdck at gmail.com>
Date: Fri Mar 17 23:27:38 2017 +0000
Added an xfce_panel_plugin_get_icon_size function to unify icon sizes across plugins
---
libxfce4panel/libxfce4panel.symbols | 1 +
libxfce4panel/xfce-panel-plugin.c | 51 +++++++++++++++++++++++++++++++++++++
libxfce4panel/xfce-panel-plugin.h | 3 +++
3 files changed, 55 insertions(+)
diff --git a/libxfce4panel/libxfce4panel.symbols b/libxfce4panel/libxfce4panel.symbols
index 0e45685..0daac6b 100644
--- a/libxfce4panel/libxfce4panel.symbols
+++ b/libxfce4panel/libxfce4panel.symbols
@@ -99,6 +99,7 @@ xfce_panel_plugin_get_property_base G_GNUC_PURE
xfce_panel_plugin_get_arguments G_GNUC_PURE
xfce_panel_plugin_get_size G_GNUC_PURE
xfce_panel_plugin_get_small G_GNUC_PURE
+xfce_panel_plugin_get_icon_size G_GNUC_PURE
xfce_panel_plugin_get_expand G_GNUC_PURE
xfce_panel_plugin_set_expand
xfce_panel_plugin_get_shrink G_GNUC_PURE
diff --git a/libxfce4panel/xfce-panel-plugin.c b/libxfce4panel/xfce-panel-plugin.c
index e569e4a..d4762fa 100644
--- a/libxfce4panel/xfce-panel-plugin.c
+++ b/libxfce4panel/xfce-panel-plugin.c
@@ -1956,6 +1956,57 @@ xfce_panel_plugin_set_small (XfcePanelPlugin *plugin,
/**
+ * xfce_panel_plugin_get_icon_size:
+ * @plugin : an #XfcePanelPlugin,
+ * @button : a #GtkWidget.
+ *
+ * Returns preferred icon size inside a button.
+ *
+ * Since: 4.14
+ **/
+gint
+xfce_panel_plugin_get_icon_size (XfcePanelPlugin *plugin,
+ GtkWidget *button)
+{
+ gint width;
+#if GTK_CHECK_VERSION (3, 0, 0)
+ GtkStyleContext *context;
+ GtkBorder padding, border;
+ gint xthickness;
+ gint ythickness;
+
+ g_return_val_if_fail (XFCE_IS_PANEL_PLUGIN (plugin), 24);
+ g_return_val_if_fail (XFCE_PANEL_PLUGIN_CONSTRUCTED (plugin), 24);
+ g_return_val_if_fail (GTK_IS_WIDGET (button), 24);
+
+ /* Calculate the size of the widget because the theme can override it */
+ context = gtk_widget_get_style_context (button);
+ gtk_style_context_get_padding (context, gtk_widget_get_state_flags (button), &padding);
+ gtk_style_context_get_border (context, gtk_widget_get_state_flags (button), &border);
+ xthickness = padding.left + padding.right + border.left + border.right;
+ ythickness = padding.top + padding.bottom + border.top + border.bottom;
+
+ /* Calculate the size of the space left for the icon */
+ width = xfce_panel_plugin_get_size (plugin) / xfce_panel_plugin_get_nrows (plugin) - 2 * MAX (xthickness, ythickness);
+#else
+ /* simple fallback for gtk2 */
+ width = xfce_panel_plugin_get_size (plugin) / xfce_panel_plugin_get_nrows (plugin) - 2;
+#endif
+
+ /* Since symbolic icons are usually only provided in 16px we
+ * try to be clever and use size steps */
+ if (width <= 21)
+ return 16;
+ else if (width >=22 && width <= 29)
+ return 24;
+ else if (width >= 30 && width <= 40)
+ return 32;
+ else
+ return width;
+}
+
+
+/**
* xfce_panel_plugin_get_orientation:
* @plugin : an #XfcePanelPlugin.
*
diff --git a/libxfce4panel/xfce-panel-plugin.h b/libxfce4panel/xfce-panel-plugin.h
index 37c3a63..f7f2bf2 100644
--- a/libxfce4panel/xfce-panel-plugin.h
+++ b/libxfce4panel/xfce-panel-plugin.h
@@ -187,6 +187,9 @@ gboolean xfce_panel_plugin_get_small (XfcePanelPlugin *
void xfce_panel_plugin_set_small (XfcePanelPlugin *plugin,
gboolean small);
+gint xfce_panel_plugin_get_icon_size (XfcePanelPlugin *plugin,
+ GtkWidget *button) G_GNUC_PURE;
+
GtkOrientation xfce_panel_plugin_get_orientation (XfcePanelPlugin *plugin) G_GNUC_PURE;
XfcePanelPluginMode xfce_panel_plugin_get_mode (XfcePanelPlugin *plugin) G_GNUC_PURE;
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list