Skip to content

listbase: Allow scroll_to() to grab focus on inactive windows

António Fernandes requested to merge wip/antoniof/fix-focus-within-check into main

gtk_[grid,column]_view_scroll_to() does 2 things when asked to focus:

  1. it sets the focus item tracker to point to the requested position.
  2. then it grabs focus on the item widget if focus is within the view.

However, the way it checks whether focus is within the view is faulty. The FOCUS_WITHIN flag is set only if the global input focus is within. But what we want to know here is whether the GtkRoot:focus widget is within, regardless of the window being active or not, otherwise we are not holding to our documented promise:

This function works no matter if the listview is shown or focused. If it isn’t, then the changes will take effect once that happens.

If the containing window doesn't is inactive, setting the focus item tracker without grabbing focus is useless, because, once a the window becomes active, it resets the focus states all the way up from the GtkRoot:focus widget. But GtkRoot:focus was not changed because we didn't grab focus, so, if it is another item widget than the one requested, then even the focus item tracker resets to the original focus, as a side effect of .set_focus_child()

Therefore, even if the window is inactive, we should grab focus if the GtkRoot:focus is within the view.

Fixes #6266

Merge request reports