From 40b3ad7287f26de65f5c918467a04011f6c42ec0 Mon Sep 17 00:00:00 2001 From: Andrea Villa Date: Mon, 7 May 2012 13:03:57 +0200 Subject: Use newer tooltip API (bug #8730). This updates the plugin to use the newer tooltip API (requires >=GTK-2.12) and fixes tooltips not showing for update intervals smaller then 500ms. --- panel-plugin/main.c | 31 ++++++++++++++++++++++--------- 1 files changed, 22 insertions(+), 9 deletions(-) diff --git a/panel-plugin/main.c b/panel-plugin/main.c index 43f5450..b3ac143 100644 --- a/panel-plugin/main.c +++ b/panel-plugin/main.c @@ -137,6 +137,8 @@ typedef struct diskperf_t { struct conf_t oConf; struct monitor_t oMonitor; + GtkWidget *tooltip_text; + } diskperf_t; /**************************************************************/ @@ -168,8 +170,6 @@ static int DisplayPerf (struct diskperf_t *p_poPlugin) /* Get the last disk perfomance data, compute the statistics and update the panel-docked monitor bars */ { - static GtkTooltips *s_poToolTips = 0; - struct devperf_t oPerf; struct param_t *poConf = &(p_poPlugin->oConf.oParam); struct monitor_t *poMonitor = &(p_poPlugin->oMonitor); @@ -184,9 +184,6 @@ static int DisplayPerf (struct diskperf_t *p_poPlugin) char acToolTips[256]; int status, i; - if (!s_poToolTips) - s_poToolTips = gtk_tooltips_new (); - rbytes = wbytes = iRBusy_ns = iWBusy_ns = -1; memset (&oPerf, 0, sizeof (oPerf)); oPerf.qlen = -1; @@ -201,8 +198,8 @@ static int DisplayPerf (struct diskperf_t *p_poPlugin) snprintf (acToolTips, sizeof(acToolTips), _("%s: Device statistics unavailable."), poConf->acTitle); UpdateProgressBars(p_poPlugin, 0, 0, 0); - gtk_tooltips_set_tip (s_poToolTips, GTK_WIDGET (poMonitor->wEventBox), - acToolTips, 0); + gtk_label_set_text(GTK_LABEL(p_poPlugin->tooltip_text), acToolTips); + return (-1); } if (poMonitor->oPrevPerf.timestamp_ns) { @@ -262,8 +259,7 @@ static int DisplayPerf (struct diskperf_t *p_poPlugin) (int) round(arBusy[W_DATA]) : -1, #endif (oPerf.qlen >= 0) ? (int) round(arBusy[RW_DATA]) : -1); - gtk_tooltips_set_tip (s_poToolTips, GTK_WIDGET (poMonitor->wEventBox), - acToolTips, 0); + gtk_label_set_text(GTK_LABEL(p_poPlugin->tooltip_text), acToolTips); switch (poConf->eStatistics) { case BUSY_TIME: @@ -481,11 +477,23 @@ static diskperf_t *diskperf_create_control (XfcePanelPlugin *plugin) /**************************************************************/ + +/* ---------------------------------------------------------------------------------------------- */ +static gboolean tooltip_cb(GtkWidget *widget, gint x, gint y, gboolean keyboard, GtkTooltip *tooltip, struct diskperf_t *poPlugin) +{ + gtk_tooltip_set_custom(tooltip, poPlugin->tooltip_text); + return TRUE; +} /* tooltip_cb() */ + + /**************************************************************/ + + static void diskperf_free (XfcePanelPlugin *plugin, diskperf_t *poPlugin) /* Plugin API */ { if (poPlugin->iTimerId) g_source_remove (poPlugin->iTimerId); + gtk_widget_destroy(poPlugin->tooltip_text); g_free (poPlugin); } /* diskperf_free() */ @@ -1183,6 +1191,11 @@ static void diskperf_construct (XfcePanelPlugin *plugin) gtk_container_add (GTK_CONTAINER (plugin), diskperf->oMonitor.wEventBox); + gtk_widget_set_has_tooltip(diskperf->oMonitor.wEventBox, TRUE); + g_signal_connect(diskperf->oMonitor.wEventBox, "query-tooltip", G_CALLBACK(tooltip_cb), diskperf); + diskperf->tooltip_text = gtk_label_new(NULL); + g_object_ref(diskperf->tooltip_text); + CreateMonitorBars (diskperf, xfce_panel_plugin_get_orientation (plugin)); diskperf_read_config (plugin, diskperf); -- 1.7.8.6