GNOME Bugzilla – Bug 53130
Incorrect changed events for GtkEntry, GtkSpinButton
Last modified: 2011-02-04 16:09:21 UTC
GtkEntry triggers "changed" events for clicking in a blank entry or before the first character and pressing the backspace button. Of course the text (or lack thereof) hasn't actually changed. In this case, backspace is like the back arrow key and should not emit this particular event. This problem also occurs for GtkSpinButtons, of course. GtkSpinButtons trigger "changed" events for pressing the space bar, which can't by definition change the value. I think GtkSpinButton was improved recently to disallow anything but -?[0-9]*\.?[0-9]*, but typing other characters still triggers "changed" events even though the value didn't change.
In general, "changed" signals should be thought of as "something might have changed" rather than as "something changed". However, I can see where this might be annoying behavior while maintaining, e.g., the sensitivity of a "Apply" button in a dialog, so fixing it up to the extent possible is probably a good idea. I don't see it as very feasible to fix up GtkSpinButton, but fixing up GtkEntry should be more or less easy. (Emit CHANGED out of real_insert_text(), real_delete_text(), instead of out of insert_text, delete_text)
Created attachment 6789 [details] [review] patch (untested - is there a good way to test signal emission ?)
Connect to the example in testgtk and print stuff to stderr? Bug 64998 is a closely related bug, though considerably harder to fix. (That one, you'd probably have to set a "in multiple change" flag and suppress ::change signals until it is cleared; might be best fixed along with 69616?) Actually, the in-change flag could solve this one as well... insert_/delete_text() would do: start_change() [ push the stuff inside ] end_change() real_insert/delete_text would set a "stuff actually changed" flag. Then end_change would emit ::changed() if the "stuff actually changed" flag was set.
"print to stderr" rang the bell; I just refactored my testcase for 54444 to print out entry::changed. This uncovered that my patch doesn't completely fix the described problems with entry::changed. It still gets emitted when backspace is pressed at position 0. The next patch fixes this and works ok as far as cursory testing can prove.
Created attachment 6801 [details] [review] fixed fix
Regarding the spinbutton problems, connecting to spinbutton::value_changed or adjustment::value_changed instead of spinbutton::changed might be a solution, although that has the slight problem that if the value is typed in the entry of the spinbutton, ::value_changed will apparently not be emitted until the spinbutton looses focus.
Sat Feb 23 16:52:38 2002 Owen Taylor <otaylor@redhat.com> * gtk/gtkentry.c: Patch from Matthias Clasen to remove some excessive ::changed signals for GtkEntry. (#53130)