GNOME Bugzilla – Bug 782636
GtkEntry continues to emit changed signal once max_length is hit
Last modified: 2017-05-16 21:06:48 UTC
If you create a GtkEntry and set the maximum length using gtk_entry_set_max_length() it will emit a GtkEntry::changed signal for each key press even once the maximum length has been reached. It is proposed this signal should not be emitted if the input is truncated like this.
Test case: Typing into the entry generates events even though it can contain only one character. // gcc -g -Wall test.c -o test `pkg-config --cflags --libs gtk+-3.0` #include <gtk/gtk.h> static void changed_cb () { g_printerr ("!\n"); } int main (int argc, char **argv) { gtk_init (&argc, &argv); GtkWidget *w = gtk_window_new (GTK_WINDOW_TOPLEVEL); GtkWidget *e = gtk_entry_new (); gtk_entry_set_max_length (GTK_ENTRY (e), 1); g_signal_connect (e, "changed", G_CALLBACK (changed_cb), NULL); gtk_container_add (GTK_CONTAINER (w), e); gtk_widget_show_all (w); gtk_main (); return 0; }
This was found when using a GtkSearchEntry. This entry was connected to a server based query and due to some input error (a cat on the keyboard?) it sent an enormous number of queries to the server. We proposed limiting the length of the search entry, but due to the described bug it would continue to generate queries even once it hits the limit.
Created attachment 351845 [details] [review] EntryBuffer: Don't generate changed events when input is truncated There seems to be two places where this could be done: a) gtk_entry_buffer_insert_text() - ignore user input if it ends up with length zero (i.e. this patch) b) gtk_entry_buffer_normal_insert_text() - after the text is processed and possibly overridable? (can't think of a use case).
Review of attachment 351845 [details] [review]: Looks fine to me
Fixed in master and gnome-3-22
that should say gtk-3-22