widget: Insist that widgets are rooted to be focusable

This check was in the vfunc before, but it's a general rule, so apply it
before.
This commit is contained in:
Benjamin Otte 2019-10-15 16:11:03 +02:00
parent 14c34a7014
commit 9c1b1eb894

View File

@ -5425,7 +5425,8 @@ gtk_widget_grab_focus (GtkWidget *widget)
{
g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
if (!gtk_widget_is_sensitive (widget))
if (!gtk_widget_is_sensitive (widget) ||
widget->priv->root == NULL)
return FALSE;
return GTK_WIDGET_GET_CLASS (widget)->grab_focus (widget);
@ -5436,9 +5437,6 @@ gtk_widget_real_grab_focus (GtkWidget *focus_widget)
{
GtkWidgetPrivate *priv = gtk_widget_get_instance_private (focus_widget);
if (!priv->root)
return FALSE;
gtk_root_set_focus (priv->root, focus_widget);
return TRUE;
}