gtkwidget: better handle when trying to focus a widget with no GtkRoot
Issue #5676 found a case where GTK tried to focus a widget with
a NULL GtkRoot. That specific case was a GtkButton which was a
GtkExpander's child, and until the GtkExpander is expanded (and
thus the GtkButton becomes visible) the button has no GtkRoot,
yet GTK tried to focus on it when GtkExpander's code called
gtk_widget_focus_child()
on it.
We could change GtkExpander code to check if widget has no GtkRoot
and in that case avoid calling gtk_widget_focus_child()
, but
it seems generally better to handle this at GtkWidget level so
it may cover other widgets that could misbehave in a similar way
as GtkExpander.
So in this patch:
- We turn a critical message (failed assertion) into a proper warning which informs the user about the non-allowed action.
- We also make sure
gtk_widget_focus_child()
properly returns FALSE when called on an unrooted widget.
Fixes #5676