ComboBox no longer gives initial focus to the currently active/selected item in the popover
moving from Discourse
In GTK3, GtkComboBox
(and GtkMenu
, et al.) would open the popup and have the item/button therein pre-focused, for the current index. For instance, in a country selector, if USA was selected and shown on the button, when clicking to open the popup, it’d get focus in the menu.
This no longer happens in GTK4. Instead, the first/top item gets initial focus every time, regardless of it not being the active option. That’s jarring and inconvenient, as well as a regression from GTK3 - and when compared to other toolkits, where I think GTK3’s behaviour is the norm.
[edit] To clarify, if the DropDown uses a SelectionModel, then then selected item is visibly selected, in that the button is pressed-in - but it does not get initial focus, so keyboard input starts from the 1st/top item. For Combobox neither work.
[edit 2]: I have just run across a case where this does work, i.e. the selected item does get visible/functional keyboard focus... so it seems this sometimes works. I have not yet been able to narrow down what makes it work, or not work.
Was this intentionally omitted? If not (and I really hope not!) - would a patch to fix be reviewed? First I'd welcome some sense-checks / input of my evaluation of the situation, as now follows...
In my own popup widget I just do Popover::show -> ::idle -> activeButton.grab_focus()
, and it seems to work OK.
However, I'm not sure it's easy to do something equivalent for these specific widgets, because:
-
With list models/views, as in
DropDown
, it gets more complex.ListView
et al. do not provide any way to get the widget that’s currently showing a given model item, and are clear it's because said widget could be recycled for another model item. So I think to give proper initial focus, we need support from the view, right? I don't think only aSelectionModel
suffices; AFAICS, that only lets us get the selected model object, but not the widget that will show it on popup... andDropDown
et al. don't seem to have any more internal insight than anyone else. -
ComboBox
doesn't use models/views, instead the oldTreeModel
- but the code has changed quite a bit. While in GTK3ComboBox
has aMenu
(let’s not dare mentionappears-as-list
mode), in GTK4Menu
is gone, so it uses aPopover
, which Inspector shows is aGtkTreePopover
... and the code that would have ‘pre-selected’ (in this case, moved to the cursor) the active item has been disabled with a big#if 0
. -
Also, a bug with wrong prelighting in Popovers is likely to increase the Fun Quotient
🙃
I won't insist we poke ComboBox
any further, given that it's deprecated, but IMHO it seems important to fix this for DropDown
, and I'd like to help, once I understand the current/future intent and limitations a bit better.
One last note: Emmanuele said that:
focus of
GtkListView
rows is being addressed by the sections merge request
...but as far as I can tell, that was merged and closed with handling of focus still being an open checklist item.