pidgin/pidgin

Fix the infinite resizing freeze
release-2.x.y
23 months ago, Belgin Știrbu
0079467afee4
Parents c5c98b27f755
Children 82f6b5267eac
Fix the infinite resizing freeze

This appears related to libpango somehow, as in Debian
Bullseye, libpango splits URLs with dashes at the end,
but in Debian Bookworm, the URLs are not split with dashes
at the end, and the bug does not appear to be triggered
in Bookworm.

This patch makes the assumption that the gtkimhtml widgets
stored in a PidginConversation normally resize in an
alternating manner. However, when the bug is triggered,
only the "entry" gtkimhtml member of PidginConversation
resizes, so we allow "entry" to resize only up to 3 times
in a row.

Testing Done:
Compiled and tested on several desktop environments on a few
GNU/Linux distros by pasting the link mentioned
here https://issues.imfreedom.org/issue/PIDGIN-17413 moving
the cursor at the beginning of the buffer, and holding
the spacebar pressed.

Bugs closed: PIDGIN-16753, PIDGIN-16999, PIDGIN-17287, PIDGIN-17413, PIDGIN-17430, PIDGIN-17568, PIDGIN-17602

Reviewed at https://reviews.imfreedom.org/r/1342/
--- a/pidgin/gtkconv.c Fri Apr 15 11:15:37 2022 -0500
+++ b/pidgin/gtkconv.c Fri Apr 15 11:29:11 2022 -0500
@@ -118,6 +118,9 @@
static GdkColor *nick_colors = NULL;
static guint nbr_nick_colors;
+/* GTK_IMHTML_MAX_CONSEC_RESIZES is also defined in gtkimhtml.c */
+#define GTK_IMHTML_MAX_CONSEC_RESIZES 6
+
typedef struct {
GtkWidget *window;
@@ -264,8 +267,17 @@
static gboolean
lbox_size_allocate_cb(GtkWidget *w, GtkAllocation *allocation, gpointer data)
{
+ PidginConversation *gtkconv = data;
+
purple_prefs_set_int(PIDGIN_PREFS_ROOT "/conversations/chat/userlist_width", allocation->width == 1 ? 0 : allocation->width);
+ if(gtkconv != NULL) {
+ g_object_set_data(G_OBJECT(gtkconv->entry), "resize-count",
+ GINT_TO_POINTER(0));
+ g_object_set_data(G_OBJECT(gtkconv->imhtml), "resize-count",
+ GINT_TO_POINTER(0));
+ }
+
return FALSE;
}
@@ -2362,6 +2374,9 @@
g_return_if_fail(gtkconv != NULL);
+ g_object_set_data(G_OBJECT(gtkconv->imhtml), "resize-count",
+ GINT_TO_POINTER(0));
+
if (!purple_prefs_get_bool("/purple/conversations/im/send_typing"))
return;
@@ -2379,6 +2394,9 @@
g_return_if_fail(gtkconv != NULL);
+ g_object_set_data(G_OBJECT(gtkconv->imhtml), "resize-count",
+ GINT_TO_POINTER(0));
+
conv = gtkconv->active_conv;
if (!purple_prefs_get_bool("/purple/conversations/im/send_typing"))
@@ -2807,6 +2825,9 @@
PurpleContact *contact = purple_buddy_get_contact(buddy);
purple_blist_node_set_int((PurpleBlistNode*)contact, "pidgin-infopane-iconsize", size);
}
+
+ g_object_set_data(G_OBJECT(gtkconv->imhtml), "resize-count",
+ GINT_TO_POINTER(0));
}
static void
@@ -4348,6 +4369,11 @@
new_topic);
g_free(new_topic);
+
+ g_object_set_data(G_OBJECT(gtkconv->imhtml), "resize-count",
+ GINT_TO_POINTER(0));
+ g_object_set_data(G_OBJECT(gtkconv->entry), "resize-count",
+ GINT_TO_POINTER(0));
}
static gint
@@ -4613,6 +4639,17 @@
gboolean interior_focus;
int focus_width;
+ if(GPOINTER_TO_INT(
+ g_object_get_data(
+ G_OBJECT(gtkconv->entry), "resize-count")) ==
+ GTK_IMHTML_MAX_CONSEC_RESIZES + 1) {
+ g_object_set_data(G_OBJECT(gtkconv->entry), "resize-count",
+ GINT_TO_POINTER(0));
+ g_object_set_data(G_OBJECT(gtkconv->imhtml), "resize-count",
+ GINT_TO_POINTER(0));
+ return;
+ }
+
pad_top = gtk_text_view_get_pixels_above_lines(GTK_TEXT_VIEW(gtkconv->entry));
pad_bottom = gtk_text_view_get_pixels_below_lines(GTK_TEXT_VIEW(gtkconv->entry));
pad_inside = gtk_text_view_get_pixels_inside_wrap(GTK_TEXT_VIEW(gtkconv->entry));
@@ -4647,7 +4684,7 @@
diff = height - gtkconv->entry->allocation.height;
if (ABS(diff) < oneline.height / 2)
- return FALSE;
+ diff = 0;
gtk_widget_set_size_request(gtkconv->lower_hbox, -1,
diff + gtkconv->lower_hbox->allocation.height);
@@ -5073,6 +5110,7 @@
gtk_widget_set_name(gtkconv->entry, "pidgin_conv_entry");
gtk_imhtml_set_protocol_name(GTK_IMHTML(gtkconv->entry),
purple_account_get_protocol_name(conv->account));
+ g_object_set_data(G_OBJECT(gtkconv->entry), "gtkconv", gtkconv);
g_signal_connect(G_OBJECT(gtkconv->entry), "populate-popup",
G_CALLBACK(entry_popup_menu_cb), gtkconv);
@@ -7397,6 +7435,11 @@
gtk_widget_hide(gtkconv->toolbar);
g_idle_add((GSourceFunc)resize_imhtml_cb,gtkconv);
+
+ g_object_set_data(G_OBJECT(gtkconv->imhtml), "resize-count",
+ GINT_TO_POINTER(0));
+ g_object_set_data(G_OBJECT(gtkconv->entry), "resize-count",
+ GINT_TO_POINTER(0));
}
}
@@ -9094,6 +9137,12 @@
PurpleConversation *conv = gtkconv->active_conv;
const char *text = NULL;
+ g_object_set_data(G_OBJECT(gtkconv->imhtml), "resize-count",
+ GINT_TO_POINTER(0));
+
+ g_object_set_data(G_OBJECT(gtkconv->entry), "resize-count",
+ GINT_TO_POINTER(0));
+
if (!GTK_WIDGET_VISIBLE(gtkconv->infopane)) {
/* There's already an entry for alias. Let's not create another one. */
return FALSE;
@@ -9253,6 +9302,21 @@
static gboolean gtk_conv_configure_cb(GtkWidget *w, GdkEventConfigure *event, gpointer data) {
int x, y;
+ GList *gtkconvs;
+ PidginWindow *win = data;
+ PidginConversation *gtkconv;
+
+ if(win != NULL) {
+ for (gtkconvs = win->gtkconvs; gtkconvs != NULL; gtkconvs = gtkconvs->next) {
+ gtkconv = gtkconvs->data;
+ if(gtkconv != NULL) {
+ g_object_set_data(G_OBJECT(gtkconv->imhtml), "resize-count",
+ GINT_TO_POINTER(0));
+ g_object_set_data(G_OBJECT(gtkconv->entry), "resize-count",
+ GINT_TO_POINTER(0));
+ }
+ }
+ }
if (GTK_WIDGET_VISIBLE(w))
gtk_window_get_position(GTK_WINDOW(w), &x, &y);
@@ -9286,6 +9350,9 @@
pidgin_conv_set_position_size(PidginWindow *win, int conv_x, int conv_y,
int conv_width, int conv_height)
{
+ GList *gtkconvs;
+ PidginConversation *gtkconvs_data;
+
/* if the window exists, is hidden, we're saving positions, and the
* position is sane... */
if (win && win->window &&
@@ -9308,6 +9375,18 @@
#endif
gtk_window_resize(GTK_WINDOW(win->window), conv_width, conv_height);
}
+
+ if(win != NULL) {
+ for (gtkconvs = win->gtkconvs; gtkconvs != NULL; gtkconvs = gtkconvs->next) {
+ gtkconvs_data = gtkconvs->data;
+ if(gtkconvs_data != NULL) {
+ g_object_set_data(G_OBJECT(gtkconvs_data->imhtml), "resize-count",
+ GINT_TO_POINTER(0));
+ g_object_set_data(G_OBJECT(gtkconvs_data->entry), "resize-count",
+ GINT_TO_POINTER(0));
+ }
+ }
+ }
}
static void
@@ -9515,6 +9594,8 @@
GtkWidget *tab_cont = gtkconv->tab_cont;
PurpleConversationType conv_type;
const gchar *tmp_lab;
+ GList *gtkconvs;
+ PidginConversation *gtkconvs_data;
conv_type = purple_conversation_get_type(conv);
@@ -9583,6 +9664,21 @@
if (pidgin_conv_window_get_gtkconv_count(win) == 1)
update_send_to_selection(win);
+
+ for (gtkconvs = win->gtkconvs; gtkconvs != NULL; gtkconvs = gtkconvs->next) {
+ gtkconvs_data = gtkconvs->data;
+ if(gtkconvs_data != NULL) {
+ g_object_set_data(G_OBJECT(gtkconvs_data->imhtml), "resize-count",
+ GINT_TO_POINTER(0));
+ g_object_set_data(G_OBJECT(gtkconvs_data->entry), "resize-count",
+ GINT_TO_POINTER(0));
+ }
+ }
+
+ g_object_set_data(G_OBJECT(gtkconv->imhtml), "resize-count",
+ GINT_TO_POINTER(0));
+ g_object_set_data(G_OBJECT(gtkconv->entry), "resize-count",
+ GINT_TO_POINTER(0));
}
static void
@@ -9592,6 +9688,11 @@
gint angle = 0;
GtkWidget *first, *third, *ebox;
+ g_object_set_data(G_OBJECT(gtkconv->imhtml), "resize-count",
+ GINT_TO_POINTER(0));
+ g_object_set_data(G_OBJECT(gtkconv->entry), "resize-count",
+ GINT_TO_POINTER(0));
+
if (purple_prefs_get_int(PIDGIN_PREFS_ROOT "/conversations/tab_side") == GTK_POS_LEFT ||
purple_prefs_get_int(PIDGIN_PREFS_ROOT "/conversations/tab_side") == GTK_POS_RIGHT)
tabs_side = TRUE;
@@ -9687,6 +9788,8 @@
pidgin_conv_window_remove_gtkconv(PidginWindow *win, PidginConversation *gtkconv)
{
unsigned int index;
+ GList *gtkconvs;
+ PidginConversation *gtkconvs_data;
index = gtk_notebook_page_num(GTK_NOTEBOOK(win->notebook), gtkconv->tab_cont);
@@ -9705,6 +9808,14 @@
if (!win->gtkconvs && win != hidden_convwin)
pidgin_conv_window_destroy(win);
+
+ for (gtkconvs = win->gtkconvs; gtkconvs != NULL; gtkconvs = gtkconvs->next) {
+ gtkconvs_data = gtkconvs->data;
+ if(gtkconvs_data != NULL) {
+ g_object_set_data(G_OBJECT(gtkconvs_data->imhtml), "resize-count",
+ GINT_TO_POINTER(0));
+ }
+ }
}
PidginConversation *
@@ -9878,7 +9989,7 @@
win = pidgin_conv_window_new();
g_signal_connect(G_OBJECT(win->window), "configure_event",
- G_CALLBACK(gtk_conv_configure_cb), NULL);
+ G_CALLBACK(gtk_conv_configure_cb), win);
pidgin_conv_window_add_gtkconv(win, conv);
pidgin_conv_window_show(win);
@@ -9896,6 +10007,11 @@
PurpleConversationType type = purple_conversation_get_type(conv->active_conv);
GList *all;
+ g_object_set_data(G_OBJECT(conv->imhtml), "resize-count",
+ GINT_TO_POINTER(0));
+ g_object_set_data(G_OBJECT(conv->entry), "resize-count",
+ GINT_TO_POINTER(0));
+
if (GTK_WIDGET_VISIBLE(w))
gtk_window_get_position(GTK_WINDOW(w), &x, &y);
else
@@ -9978,7 +10094,7 @@
win = pidgin_conv_window_new();
g_signal_connect(G_OBJECT(win->window), "configure_event",
- G_CALLBACK(gtk_conv_configure_cb), NULL);
+ G_CALLBACK(gtk_conv_configure_cb), win);
pidgin_conv_window_add_gtkconv(win, conv);
--- a/pidgin/gtkimhtml.c Fri Apr 15 11:15:37 2022 -0500
+++ b/pidgin/gtkimhtml.c Fri Apr 15 11:29:11 2022 -0500
@@ -67,6 +67,9 @@
#define TOOLTIP_TIMEOUT 500
+/* GTK_IMHTML_MAX_CONSEC_RESIZES is also defined in gtkconv.c */
+#define GTK_IMHTML_MAX_CONSEC_RESIZES 6
+
static GtkTextViewClass *parent_class = NULL;
struct scalable_data {
@@ -395,6 +398,59 @@
int height = 0, y = 0;
GtkTextIter iter;
gboolean scroll = TRUE;
+ PidginConversation *gtkconv;
+ GtkIMHtml *entry, *messages;
+ int resize_count;
+ int entry_rc;
+ int messages_rc;
+
+ gtkconv = g_object_get_data(G_OBJECT(imhtml), "gtkconv");
+
+ if(gtkconv != NULL) {
+ entry = GTK_IMHTML(gtkconv->entry);
+ messages = GTK_IMHTML(gtkconv->imhtml);
+
+ entry_rc = GPOINTER_TO_INT(
+ g_object_get_data(
+ G_OBJECT(entry), "resize-count"));
+
+ messages_rc = GPOINTER_TO_INT(
+ g_object_get_data(
+ G_OBJECT(messages), "resize-count"));
+
+ resize_count = GPOINTER_TO_INT(
+ g_object_get_data(
+ G_OBJECT(imhtml), "resize-count"));
+
+ if(imhtml == entry) {
+ if(entry_rc >= GTK_IMHTML_MAX_CONSEC_RESIZES ||
+ messages_rc >= GTK_IMHTML_MAX_CONSEC_RESIZES) {
+ return;
+ }
+ } else if(imhtml == messages) {
+ if(resize_count >= GTK_IMHTML_MAX_CONSEC_RESIZES) {
+ g_object_set_data(
+ G_OBJECT(entry), "resize-count",
+ GINT_TO_POINTER(
+ GTK_IMHTML_MAX_CONSEC_RESIZES + 1));
+
+ return;
+ }
+
+ if(entry_rc == GTK_IMHTML_MAX_CONSEC_RESIZES + 1) {
+ g_object_set_data(G_OBJECT(messages), "resize-count",
+ GINT_TO_POINTER(0));
+ return;
+ }
+
+ g_object_set_data(G_OBJECT(entry), "resize-count",
+ GINT_TO_POINTER(0));
+ }
+
+ resize_count++;
+ g_object_set_data(G_OBJECT(imhtml), "resize-count",
+ GINT_TO_POINTER(resize_count));
+ }
gtk_text_buffer_get_end_iter(imhtml->text_buffer, &iter);
@@ -1167,6 +1223,8 @@
if (!imhtml->wbfo && !plaintext)
gtk_imhtml_close_tags(imhtml, &iter);
+ g_object_set_data(G_OBJECT(imhtml), "resize-count",
+ GINT_TO_POINTER(0));
}
static void paste_plaintext_received_cb (GtkClipboard *clipboard, const gchar *text, gpointer data)
@@ -1186,6 +1244,9 @@
char *text;
GtkIMHtml *imhtml = data;
+ g_object_set_data(G_OBJECT(imhtml), "resize-count",
+ GINT_TO_POINTER(0));
+
if (!gtk_text_view_get_editable(GTK_TEXT_VIEW(imhtml)))
return;
@@ -1282,6 +1343,9 @@
/* ok, then we need to insert the image buffer text before the anchor */
gtk_text_buffer_insert(imhtml->text_buffer, &iter, text, -1);
+
+ g_object_set_data(G_OBJECT(imhtml), "resize-count",
+ GINT_TO_POINTER(0));
}
static void paste_clipboard_cb(GtkIMHtml *imhtml, gpointer blah)
@@ -1307,6 +1371,8 @@
gtk_text_buffer_remove_selection_clipboard(GTK_IMHTML(imhtml)->text_buffer,
gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_PRIMARY));
+ g_object_set_data(G_OBJECT(imhtml), "resize-count",
+ GINT_TO_POINTER(0));
}
static void imhtml_destroy_add_primary(GtkIMHtml *imhtml, gpointer unused)
@@ -1387,6 +1453,9 @@
g_signal_emit_by_name(imhtml, "paste_clipboard");
else if (purple_strequal(str, "text"))
paste_unformatted_cb(NULL, imhtml);
+
+ g_object_set_data(G_OBJECT(imhtml), "resize-count",
+ GINT_TO_POINTER(0));
}
static void imhtml_toggle_format(GtkIMHtml *imhtml, GtkIMHtmlButtons buttons)
@@ -4355,6 +4424,7 @@
static void insert_cb(GtkTextBuffer *buffer, GtkTextIter *end, gchar *text, gint len, GtkIMHtml *imhtml)
{
+ PidginConversation *gtkconv;
GtkTextIter start;
if (!len)
@@ -4364,10 +4434,19 @@
gtk_text_iter_set_offset(&start, imhtml->insert_offset);
gtk_imhtml_apply_tags_on_insert(imhtml, &start, end);
+
+ gtkconv = g_object_get_data(G_OBJECT(imhtml), "gtkconv");
+ if(gtkconv != NULL) {
+ g_object_set_data(G_OBJECT(gtkconv->entry), "resize-count",
+ GINT_TO_POINTER(0));
+ g_object_set_data(G_OBJECT(gtkconv->imhtml), "resize-count",
+ GINT_TO_POINTER(0));
+ }
}
static void delete_cb(GtkTextBuffer *buffer, GtkTextIter *start, GtkTextIter *end, GtkIMHtml *imhtml)
{
+ PidginConversation *gtkconv;
GList *l;
GSList *tags, *sl;
GtkTextIter i;
@@ -4422,6 +4501,14 @@
}
sl = next;
}
+
+ gtkconv = g_object_get_data(G_OBJECT(imhtml), "gtkconv");
+ if(gtkconv != NULL) {
+ g_object_set_data(G_OBJECT(gtkconv->entry), "resize-count",
+ GINT_TO_POINTER(0));
+ g_object_set_data(G_OBJECT(gtkconv->imhtml), "resize-count",
+ GINT_TO_POINTER(0));
+ }
}
static void gtk_imhtml_apply_tags_on_insert(GtkIMHtml *imhtml, GtkTextIter *start, GtkTextIter *end)