gtkmenu: Stop using ::key-press-event

Use GtkEventControllerKey for the task
This commit is contained in:
Carlos Garnacho 2018-03-11 13:56:32 +01:00
parent d5e826a660
commit d724506abe
2 changed files with 8 additions and 19 deletions

View File

@ -115,6 +115,7 @@
#include "gtkwidgetprivate.h"
#include "gtkwindowgroup.h"
#include "gtkwindowprivate.h"
#include "gtkeventcontrollerkey.h"
#include "a11y/gtkmenuaccessible.h"
@ -224,8 +225,6 @@ static void gtk_menu_size_allocate (GtkWidget *widget,
static void gtk_menu_show (GtkWidget *widget);
static void gtk_menu_snapshot (GtkWidget *widget,
GtkSnapshot *snapshot);
static gboolean gtk_menu_key_press (GtkWidget *widget,
GdkEventKey *event);
static void gtk_menu_motion (GtkEventController *controller,
double x,
double y,
@ -505,7 +504,6 @@ gtk_menu_class_init (GtkMenuClass *class)
widget_class->size_allocate = gtk_menu_size_allocate;
widget_class->show = gtk_menu_show;
widget_class->snapshot = gtk_menu_snapshot;
widget_class->key_press_event = gtk_menu_key_press;
widget_class->focus = gtk_menu_focus;
widget_class->can_activate_accel = gtk_menu_real_can_activate_accel;
widget_class->grab_notify = gtk_menu_grab_notify;
@ -1144,6 +1142,11 @@ gtk_menu_init (GtkMenu *menu)
g_signal_connect (priv->motion_controller, "enter", G_CALLBACK (gtk_menu_enter), menu);
g_signal_connect (priv->motion_controller, "motion", G_CALLBACK (gtk_menu_motion), menu);
g_signal_connect (priv->motion_controller, "leave", G_CALLBACK (gtk_menu_leave), menu);
priv->key_controller =
gtk_event_controller_key_new (GTK_WIDGET (menu));
g_signal_connect_swapped (priv->key_controller, "key-pressed",
G_CALLBACK (gtk_menu_stop_navigating_submenu), menu);
}
static void
@ -1218,6 +1221,7 @@ gtk_menu_finalize (GObject *object)
g_clear_object (&priv->click_gesture);
g_clear_object (&priv->scroll_controller);
g_clear_object (&priv->motion_controller);
g_clear_object (&priv->key_controller);
G_OBJECT_CLASS (gtk_menu_parent_class)->finalize (object);
}
@ -3037,22 +3041,6 @@ gtk_menu_released_cb (GtkGestureMultiPress *gesture,
}
}
static gboolean
gtk_menu_key_press (GtkWidget *widget,
GdkEventKey *event)
{
GtkMenu *menu;
g_return_val_if_fail (GTK_IS_MENU (widget), FALSE);
g_return_val_if_fail (event != NULL, FALSE);
menu = GTK_MENU (widget);
gtk_menu_stop_navigating_submenu (menu);
return GTK_WIDGET_CLASS (gtk_menu_parent_class)->key_press_event (widget, event);
}
static gboolean
check_threshold (GtkWidget *widget,
gint start_x,

View File

@ -78,6 +78,7 @@ struct _GtkMenuPrivate
GtkGesture *click_gesture;
GtkEventController *scroll_controller;
GtkEventController *motion_controller;
GtkEventController *key_controller;
gint scroll_offset;
gint saved_scroll_offset;