After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 782636 - GtkEntry continues to emit changed signal once max_length is hit
GtkEntry continues to emit changed signal once max_length is hit
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Widget: GtkEntry
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2017-05-15 04:59 UTC by Robert Ancell
Modified: 2017-05-16 21:06 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
EntryBuffer: Don't generate changed events when input is truncated (757 bytes, patch)
2017-05-15 05:06 UTC, Robert Ancell
accepted-commit_now Details | Review

Description Robert Ancell 2017-05-15 04:59:55 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.
Comment 1 Robert Ancell 2017-05-15 05:00:37 UTC
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;
}
Comment 2 Robert Ancell 2017-05-15 05:03:05 UTC
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.
Comment 3 Robert Ancell 2017-05-15 05:06:18 UTC
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).
Comment 4 Matthias Clasen 2017-05-16 18:55:25 UTC
Review of attachment 351845 [details] [review]:

Looks fine to me
Comment 5 Robert Ancell 2017-05-16 21:06:29 UTC
Fixed in master and gnome-3-22
Comment 6 Robert Ancell 2017-05-16 21:06:48 UTC
that should say gtk-3-22