combobox: Redo key event forwarding hack

Instead of manualling invoking bindings, we now reorder event
controllers inside the treemenu, so that shortcuts run before the event
forwarding.
This commit is contained in:
Benjamin Otte 2018-08-12 21:15:37 +02:00 committed by Matthias Clasen
parent 56595e7529
commit 3ef6be0d25

View File

@ -19,12 +19,12 @@
#include "gtkcomboboxprivate.h"
#include "gtkbindings.h"
#include "gtkbox.h"
#include "gtkcellareabox.h"
#include "gtkcelllayout.h"
#include "gtkcellrenderertext.h"
#include "gtkcellview.h"
#include "gtkeventcontrollerkey.h"
#include "gtkeventcontrollerscroll.h"
#include "gtkframe.h"
#include "gtkbuiltiniconprivate.h"
@ -33,10 +33,11 @@
#include "gtkmain.h"
#include "gtkmarshalers.h"
#include "gtkprivate.h"
#include "gtkshortcutcontroller.h"
#include "gtktogglebutton.h"
#include "gtktreepopoverprivate.h"
#include "gtktypebuiltins.h"
#include "gtkeventcontrollerkey.h"
#include "gtkwidgetprivate.h"
#include "a11y/gtkcomboboxaccessible.h"
@ -845,6 +846,7 @@ gtk_combo_box_init (GtkComboBox *combo_box)
{
GtkComboBoxPrivate *priv = gtk_combo_box_get_instance_private (combo_box);
GtkEventController *controller;
GList *controllers, *list;
priv->active = -1;
priv->active_row = NULL;
@ -879,6 +881,19 @@ gtk_combo_box_init (GtkComboBox *combo_box)
G_CALLBACK (gtk_combo_box_scroll_controller_scroll),
combo_box);
gtk_widget_add_controller (GTK_WIDGET (combo_box), controller);
controllers = gtk_widget_list_controllers (priv->popup_widget, GTK_PHASE_BUBBLE);
for (list = controllers; list; list = list->next)
{
if (GTK_IS_SHORTCUT_CONTROLLER (list->data))
{
g_object_ref (list->data);
gtk_widget_remove_controller (priv->popup_widget, list->data);
gtk_widget_add_controller (priv->popup_widget, list->data);
break;
}
}
g_list_free (controllers);
}
static void
@ -1808,18 +1823,7 @@ gtk_combo_box_menu_key (GtkEventControllerKey *key,
GdkModifierType modifiers,
GtkComboBox *combo_box)
{
GtkWidget *widget;
GdkEvent *event;
widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (key));
event = gtk_get_current_event ();
if (!gtk_bindings_activate_event (G_OBJECT (widget), event))
{
gtk_event_controller_key_forward (key, GTK_WIDGET (combo_box));
}
gdk_event_unref (event);
gtk_event_controller_key_forward (key, GTK_WIDGET (combo_box));
return TRUE;
}