popover: Forward key events to focus widget while visible/modal

This is the expected behavior while the popover keeps the grab, leaving
this up to the toplevel implementation gives place to key handlers
connected there to handle the event otherwise, and maybe redirect key
events somewhere else.
This commit is contained in:
Carlos Garnacho 2014-11-25 13:54:25 +01:00
parent f71831c780
commit dde77704ed

View File

@ -1200,12 +1200,27 @@ static gboolean
gtk_popover_key_press (GtkWidget *widget, gtk_popover_key_press (GtkWidget *widget,
GdkEventKey *event) GdkEventKey *event)
{ {
GtkWidget *toplevel, *focus;
if (event->keyval == GDK_KEY_Escape) if (event->keyval == GDK_KEY_Escape)
{ {
gtk_widget_hide (widget); gtk_widget_hide (widget);
return GDK_EVENT_STOP; return GDK_EVENT_STOP;
} }
if (!GTK_POPOVER (widget)->priv->modal)
return GDK_EVENT_PROPAGATE;
toplevel = gtk_widget_get_toplevel (widget);
if (GTK_IS_WINDOW (toplevel))
{
focus = gtk_window_get_focus (GTK_WINDOW (toplevel));
if (focus && gtk_widget_is_ancestor (focus, widget))
return gtk_window_propagate_key_event (GTK_WINDOW (toplevel), event);
}
return GDK_EVENT_PROPAGATE; return GDK_EVENT_PROPAGATE;
} }