GNOME Bugzilla – Bug 308076
GtkEntryCompletion popup does not resize after adding items to the model
Last modified: 2018-02-10 04:32:59 UTC
I've been trying to use a GtkEntryCompletion in gnome-dictionary in the following way : * The user types some characters in a GtkEntry with a GtkEntryCompletion. * Based on these characters, possible completions are fetched on a dict server. * The GtkEntryCompletion model is filled based on the results. When I follow these steps, nothing appears on the screen (no completion popup). Using a custom comparison function shows the completion is actually done, but not displayed. This is because the completion is first done on an empty model, thus the popup at first has no size, and this size is not updated when new completions are added to the model. To make this obvious, I've added two phony completions in the model *before* fetching the real ones on the server. When doing this, the real completions appear in the popup, but the popup still shows only 2 rows (you have to scroll to see the new completions).
Created attachment 47911 [details] testcase.c Here is a testcase adding new elements to the model after a 5-seconds timeout. The completion does not show up (calling gtk_entry_completion_complete does not help). If the function add_items is called directly instead of using the timeout, the completion shows up. Or did I do something stupid somewhere ?
I even tried ref'ing the model just in case, but same thing.
Created attachment 47912 [details] Another testcase This testcase shows how the completions are there, but you can't see them because the popup does not resize. This program adds a first completion right away, then waits 5 seconds before adding the rest. The popup is one line tall, and you have to scroll to see the other completions. Thus if you omit the first completion, nothing shows up.
Created attachment 47914 [details] [review] tiny patch for gtkentrycompletion.c This small patch for gtk+ fixes the issue, but I'm not sure if it's correct - I guess the resizing function was not called there for a reason (some race condition or something)
2005-06-17 Matthias Clasen <mclasen@redhat.com> * gtk/gtkentrycompletion.c (gtk_entry_completion_complete): Resize the popup if necessary. (#308076, Vincent Noel)
Well actually the patch only looked like it fixed the bug, but it didn't :P If you take a longer look at the gtk_entry_completion_complete function, you'll see that _gtk_entry_completion_resize_popup is already called there, but only if the widget is GTK_WIDGET_VISIBLE. So the actual bug is that the widget was not shown in the first place. Thus, with the patch, the popup correctly resized in testcase2.c, but still did not show up in testcase.c. So all that is actually required is a call to show the popup if items are present in the filtered model, and everything will just work (resizing et al). A new (correct) patch is coming up.
Created attachment 48043 [details] [review] Correct patch for gtkentrycompletion.c With this patch the popup correctly shows up in both testcases.
This is a misunderstanding. I just added the call to resize the popup if its visible a few days ago. But gtk_entry_completion_complete() is not meant to pop up the window. At least I did not understand it to, so far. The documentation may be a bit ambiguous.
The problem is the following : if you add items to the model too long after the user typed something in the entry, *and the popup is not visible yet*, then the completions do not appear (because the popup does not get shown anywhere). If the popup is already visible, and you add items, this function does the right thing (ie resizes the popup). So there is two different behaviors here, depending if the popup is already visible or not. Maybe the window popup should be called somewhere else, but I'm pretty sure the resulting behavior is sane. If gtk_entry_completion_complete is not meant to pop up the window, how do one gets the completions to appear in testcase2.c ?
testcase2 looks pretty artificial to me. Why would you clear and then refill the set of possible completions when the user types something ?
Because I'm fetching the possible completions for the word the user just entered on a dict server, and this takes some time (even on a pretty fast connection)... I can't fill the model with every single possible dictionary word. For example, if the user types "dictiona" the following completions appear : dictionaries dictionalrian dictionary If the user then removes the final "a", "Diction" must be added to the list.
Moreover, the clearing of the model is not really the problem here. Maybe I'm not being very clear, so I'll try to summarize the issue better : If you have a GtkEntry with a set of possible completions that do not fit the present word in the entry, nothing appears. So far, so good. If, later on, you add words to the model that fit the word in the entry, and call gtk_entry_completion_complete, then the new completions should appear. If you already had some fitting completions before, they appear. If you don't (which is our case here) they don't. This is because gtk_entry_completion_complete resizes the popup, which is fine if the popup was already visible, but not enough if it isn't. There are two separate behaviors depending on the state of the popup, which doesn't feel right to me.
ok, thats an interesting use case. My current understanding of gtk_entry_completion_complete() is that it is ok to call at any time. That would no longer be the case if we made it pop up the completions, since you don't want the completions popup to appear spontaneously without user action, just because the set of completions changed. Maybe we need new API here.
I'm a little puzzled why would anyone call gtk_entry_completion_complete and still want the popup hidden... As I see it, the only reason to call this function is when you have new completions you want to show the user right now. If there was no user action, you don't need to call the function, as it will be called automatically on the next user action (right ?). However I'm sure there are good reasons why gtk_entry_completion_complete works the way it does now :-)
The right fix here is to export gtk_entry_completion_popup/_popdown, I think.
We're moving to gitlab! As part of this move, we are closing bugs that haven't seen activity in more than 5 years. If this issue is still imporant to you and still relevant with GTK+ 3.22 or master, please consider creating a gitlab issue for it.