[Xfce4-commits] [panel-plugins/xfce4-whiskermenu-plugin] 413/473: Add support for non-square icons. Closes #49
noreply at xfce.org
noreply at xfce.org
Mon Feb 16 23:59:43 CET 2015
This is an automated email from the git hooks/post-receive script.
gottcode pushed a commit to branch master
in repository panel-plugins/xfce4-whiskermenu-plugin.
commit 042b47689e13254c75742be41d85bb1b48161903
Author: Graeme Gott <graeme at gottcode.org>
Date: Sat Dec 6 18:45:25 2014 -0500
Add support for non-square icons. Closes #49
---
panel-plugin/plugin.cpp | 32 +++++++++++++++++++++++++++-----
panel-plugin/plugin.h | 2 +-
2 files changed, 28 insertions(+), 6 deletions(-)
diff --git a/panel-plugin/plugin.cpp b/panel-plugin/plugin.cpp
index 9ef0be4..46cb6a5 100644
--- a/panel-plugin/plugin.cpp
+++ b/panel-plugin/plugin.cpp
@@ -134,7 +134,7 @@ Plugin::Plugin(XfcePanelPlugin* plugin) :
gtk_container_set_border_width(GTK_CONTAINER(m_button_box), 0);
gtk_widget_show(GTK_WIDGET(m_button_box));
- m_button_icon = XFCE_PANEL_IMAGE(xfce_panel_image_new_from_source(wm_settings->button_icon_name.c_str()));
+ m_button_icon = GTK_IMAGE(gtk_image_new());
gtk_box_pack_start(m_button_box, GTK_WIDGET(m_button_icon), true, false, 0);
if (wm_settings->button_icon_visible)
{
@@ -273,7 +273,6 @@ void Plugin::set_button_icon_name(const std::string& icon)
{
wm_settings->button_icon_name = icon;
wm_settings->set_modified();
- xfce_panel_image_set_from_source(m_button_icon, icon.c_str());
size_changed(m_plugin, xfce_panel_plugin_get_size(m_plugin));
}
@@ -420,10 +419,33 @@ gboolean Plugin::size_changed(XfcePanelPlugin*, gint size)
!wm_settings->button_title_visible,
0, GTK_PACK_START);
- // Resize icon
+ // Find icon maximum size
GtkStyle* style = gtk_widget_get_style(m_button);
gint border = (2 * std::max(style->xthickness, style->ythickness)) + 2;
- xfce_panel_image_set_size(m_button_icon, row_size - border);
+ gint icon_width_max = (mode == XFCE_PANEL_PLUGIN_MODE_HORIZONTAL) ?
+ 6 * row_size - border :
+ size - border;
+ gint icon_height_max = row_size - border;
+
+ // Load icon
+ GdkScreen* screen = gtk_widget_get_screen(GTK_WIDGET(m_plugin));
+ GtkIconTheme* icon_theme = NULL;
+ if (G_LIKELY(screen != NULL))
+ {
+ icon_theme = gtk_icon_theme_get_for_screen (screen);
+ }
+ GdkPixbuf* icon = xfce_panel_pixbuf_from_source_at_size(
+ wm_settings->button_icon_name.c_str(),
+ icon_theme,
+ icon_width_max,
+ icon_height_max);
+ gint icon_width = 0;
+ if (G_LIKELY(icon != NULL))
+ {
+ gtk_image_set_from_pixbuf(m_button_icon, icon);
+ icon_width = gdk_pixbuf_get_width(icon);
+ g_object_unref(G_OBJECT(icon));
+ }
#if (LIBXFCE4PANEL_CHECK_VERSION(4,9,0))
if (wm_settings->button_title_visible || !wm_settings->button_single_row)
@@ -436,7 +458,7 @@ gboolean Plugin::size_changed(XfcePanelPlugin*, gint size)
if (mode == XFCE_PANEL_PLUGIN_MODE_DESKBAR &&
wm_settings->button_title_visible &&
wm_settings->button_icon_visible &&
- label_size.width <= (size - row_size))
+ label_size.width <= (size - border - icon_width))
{
orientation = GTK_ORIENTATION_HORIZONTAL;
}
diff --git a/panel-plugin/plugin.h b/panel-plugin/plugin.h
index c710b28..42010a6 100644
--- a/panel-plugin/plugin.h
+++ b/panel-plugin/plugin.h
@@ -79,7 +79,7 @@ private:
GtkWidget* m_button;
GtkBox* m_button_box;
GtkLabel* m_button_label;
- XfcePanelImage* m_button_icon;
+ GtkImage* m_button_icon;
};
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list