[Xfce4-commits] <xfce4-xkb-plugin:master> Improve tooltip drawing.
Jérôme Guelfucci
noreply at xfce.org
Fri May 6 10:14:04 CEST 2011
Updating branch refs/heads/master
to 396d2710bdfaaf7e8d24277d91100f995b92d852 (commit)
from 58bd6e7a1ed7f02180135c49593fc498c0cc2fb7 (commit)
commit 396d2710bdfaaf7e8d24277d91100f995b92d852
Author: Jérôme Guelfucci <jeromeg at xfce.org>
Date: Fri May 6 09:11:06 2011 +0200
Improve tooltip drawing.
There is no need to use a custom widget with a expose handler which does
not work. Instead use gtk_tooltip_set_icon. The bonus effects are that we
do not leak the custom widget anymore and that tooltip drawing actually
works.
panel-plugin/xkb-callbacks.c | 74 +++++++++++++++---------------------------
1 files changed, 26 insertions(+), 48 deletions(-)
diff --git a/panel-plugin/xkb-callbacks.c b/panel-plugin/xkb-callbacks.c
index c2ae9d6..9ab4716 100644
--- a/panel-plugin/xkb-callbacks.c
+++ b/panel-plugin/xkb-callbacks.c
@@ -186,33 +186,6 @@ xkb_plugin_popup_menu (GtkButton *btn,
gtk_get_current_event_time ());
}
-static gboolean
-xkb_plugin_tooltip_image_exposed (GtkWidget *widget,
- GdkEventExpose *event,
- t_xkb *xkb)
-{
- const gchar *group_name;
- cairo_t *cr;
- /*GtkStyle *style;*/
- /*GdkColor fgcolor;*/
-
- cr = gdk_cairo_create ((GTK_WIDGET (widget))->window);
-
- group_name = xkb_config_get_group_name (-1);
-
- /* xkb_cairo_draw_flag (cr, group_name,
- xfce_panel_plugin_get_size (xkb->plugin),
- 20, 15,
- 20, 15,
- xkb_config_variant_index_for_group (-1)
- ); */
-
- cairo_destroy (cr);
-
- return FALSE;
-
-}
-
gboolean
xkb_plugin_set_tooltip (GtkWidget *widget,
gint x,
@@ -221,28 +194,33 @@ xkb_plugin_set_tooltip (GtkWidget *widget,
GtkTooltip *tooltip,
t_xkb *xkb)
{
- GtkWidget *image, *label, *hbox;
- gchar *text;
-
- hbox = gtk_hbox_new (FALSE, 2);
- gtk_widget_show (hbox);
-
- image = gtk_image_new ();
- gtk_container_add (GTK_CONTAINER (hbox), image);
- g_signal_connect (G_OBJECT (image), "expose-event",
- G_CALLBACK (xkb_plugin_tooltip_image_exposed), xkb);
- gtk_widget_show (image);
-
- text = xkb_util_get_layout_string (
- xkb_config_get_group_name (-1),
- xkb_config_get_variant (-1)
- );
- label = gtk_label_new (text);
- g_free (text);
- gtk_container_add (GTK_CONTAINER (hbox), label);
- gtk_widget_show (label);
+ RsvgHandle *handle;
+ GdkPixbuf *pixbuf, *tmp;
+ gchar *imgfilename;
+ gchar *text;
+
+ imgfilename = xkb_util_get_flag_filename (xkb_config_get_group_name (-1));
+ handle = rsvg_handle_new_from_file (imgfilename, NULL);
+ g_free (imgfilename);
+
+ if (handle)
+ {
+ tmp = rsvg_handle_get_pixbuf (handle);
+ pixbuf = gdk_pixbuf_scale_simple (tmp, 24, 24, GDK_INTERP_BILINEAR);
+ gtk_tooltip_set_icon (tooltip, pixbuf);
+
+ g_object_unref (pixbuf);
+ g_object_unref (tmp);
+ g_object_unref (handle);
+ }
+ else
+ gtk_tooltip_set_icon (tooltip, NULL);
+
+ text = xkb_util_get_layout_string (xkb_config_get_group_name (-1),
+ xkb_config_get_variant (-1));
- gtk_tooltip_set_custom (tooltip, GTK_WIDGET (hbox));
+ gtk_tooltip_set_text (tooltip, text);
+ g_free (text);
return TRUE;
}
More information about the Xfce4-commits
mailing list