[Xfce4-commits] [panel-plugins/xfce4-whiskermenu-plugin] 02/02: Fix regression of non-square panel image support. (bug #14506)

noreply at xfce.org noreply at xfce.org
Mon Jul 2 18:32:14 CEST 2018


This is an automated email from the git hooks/post-receive script.

g   o   t   t   c   o   d   e       p   u   s   h   e   d       a       c   o   m   m   i   t       t   o       b   r   a   n   c   h       m   a   s   t   e   r   
   in repository panel-plugins/xfce4-whiskermenu-plugin.

commit fb2992260f5f08879a3630a8262c8aa511326b22
Author: Graeme Gott <graeme at gottcode.org>
Date:   Sun Jul 1 13:41:09 2018 -0400

    Fix regression of non-square panel image support. (bug #14506)
---
 panel-plugin/plugin.cpp | 37 +++++++++++++++++++++++++++++++------
 panel-plugin/plugin.h   |  1 +
 2 files changed, 32 insertions(+), 6 deletions(-)

diff --git a/panel-plugin/plugin.cpp b/panel-plugin/plugin.cpp
index 49cb665..5cf28a0 100644
--- a/panel-plugin/plugin.cpp
+++ b/panel-plugin/plugin.cpp
@@ -90,7 +90,8 @@ static void widget_add_css(GtkWidget* widget, const gchar* css)
 Plugin::Plugin(XfcePanelPlugin* plugin) :
 	m_plugin(plugin),
 	m_window(NULL),
-	m_opacity(100)
+	m_opacity(100),
+	m_file_icon(false)
 {
 	// Load settings
 	wm_settings = new Settings;
@@ -332,14 +333,12 @@ void Plugin::icon_changed(const gchar* icon)
 	if (!g_path_is_absolute(icon))
 	{
 		gtk_image_set_from_icon_name(m_button_icon, icon, GTK_ICON_SIZE_BUTTON);
+		m_file_icon = false;
 	}
 	else
 	{
-		GFile* file = g_file_new_for_path(icon);
-		GIcon* gicon = g_file_icon_new(file);
-		gtk_image_set_from_gicon(m_button_icon, gicon, GTK_ICON_SIZE_BUTTON);
-		g_object_unref(gicon);
-		g_object_unref(file);
+		gtk_image_clear(m_button_icon);
+		m_file_icon = true;
 	}
 }
 
@@ -443,6 +442,32 @@ gboolean Plugin::size_changed(XfcePanelPlugin*, gint size)
 #endif
 	gtk_image_set_pixel_size(m_button_icon, icon_size);
 
+	// Load icon from absolute path
+	if (m_file_icon)
+	{
+		const gint scale = gtk_widget_get_scale_factor(m_button);
+		gint max_width = icon_size * scale;
+		gint max_height = icon_size * scale;
+		if (mode == XFCE_PANEL_PLUGIN_MODE_HORIZONTAL)
+		{
+			max_width *= 6;
+		}
+		else
+		{
+			max_height *= 6;
+		}
+
+		GdkPixbuf* pixbuf = gdk_pixbuf_new_from_file_at_size(wm_settings->button_icon_name.c_str(), max_width, max_height, NULL);
+		if (pixbuf)
+		{
+			// Handle high dpi
+			cairo_surface_t* surface = gdk_cairo_surface_create_from_pixbuf(pixbuf, scale, NULL);
+			gtk_image_set_from_surface(m_button_icon, surface);
+			cairo_surface_destroy(surface);
+			g_object_unref(pixbuf);
+		}
+	}
+
 	if (wm_settings->button_title_visible)
 	{
 		gtk_widget_set_size_request(m_button, -1, -1);
diff --git a/panel-plugin/plugin.h b/panel-plugin/plugin.h
index d551ce6..561cb50 100644
--- a/panel-plugin/plugin.h
+++ b/panel-plugin/plugin.h
@@ -83,6 +83,7 @@ private:
 	GtkImage* m_button_icon;
 
 	int m_opacity;
+	bool m_file_icon;
 };
 
 }

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list