From f7334100c91e6b9d654b12863c71cc6acd0d43e5 Mon Sep 17 00:00:00 2001 From: Fabian Keil Date: Sat, 9 Apr 2011 23:19:59 +0200 Subject: [PATCH] Truncate the tooltip text after 150 characters. Works around crashes in gdk with long space-less headers in the summaryview. --- src/summaryview.c | 19 ++++++++++++++++++- 1 files changed, 18 insertions(+), 1 deletions(-) diff --git a/src/summaryview.c b/src/summaryview.c index 79fb17d..94a8ffd 100644 --- a/src/summaryview.c +++ b/src/summaryview.c @@ -6180,6 +6180,7 @@ static gboolean tooltip_cb (GtkWidget *widget, MsgInfo *info = NULL; GdkRectangle rect; gboolean vert = (prefs_common.layout_mode == VERTICAL_LAYOUT); + static const int max_characters_in_tooltip_text = 150; if (!prefs_common.show_tooltips) return FALSE; @@ -6215,7 +6216,23 @@ static gboolean tooltip_cb (GtkWidget *widget, if (!text || !*text) return FALSE; - formatted = g_strdup(text); + /* + * Really long words in tooltip texts cause gdk to abort(). + * Workaround this by limiting the text to max_characters_in_tooltip_text characters. + */ + if (g_utf8_strlen(text, max_characters_in_tooltip_text+1) < max_characters_in_tooltip_text) + formatted = g_strdup(text); + else + { + gchar *tmp; + static const gchar truncation_signs[] = " [...]"; + formatted = g_strndup(text, max_characters_in_tooltip_text); + if (!formatted) + return FALSE; + tmp = g_utf8_find_prev_char(formatted, formatted+max_characters_in_tooltip_text-sizeof(truncation_signs)); + g_utf8_strncpy(tmp, truncation_signs, sizeof(truncation_signs)); + debug_print("Truncated tooltip text to %s\n", formatted); + } g_strstrip(formatted); if (!vert) -- 1.7.4.1