diff options
author | Matthias Clasen <mclasen@redhat.com> | 2020-05-06 20:25:42 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2020-05-06 20:27:04 -0400 |
commit | 236fc57329f74573da10f4dfd97e99c9e2b8ec0d (patch) | |
tree | c6dca23375686f63ab16bba44e9fdc0833ef8ea2 | |
parent | 7686b13a1ee45ace6e4e4fa3cf4c99a4c34452a4 (diff) | |
download | gtk+-236fc57329f74573da10f4dfd97e99c9e2b8ec0d.tar.gz |
modelbutton: Unify activation code paths
Opening submenus by Enter or Space wasn't working,
because we had different code paths for activation
via keynav and via click. Unify them.
-rw-r--r-- | gtk/gtkmodelbutton.c | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/gtk/gtkmodelbutton.c b/gtk/gtkmodelbutton.c index 1579c1335f..e8fe1bebaf 100644 --- a/gtk/gtkmodelbutton.c +++ b/gtk/gtkmodelbutton.c @@ -183,7 +183,14 @@ struct _GtkModelButton guint iconic : 1; }; -typedef GtkWidgetClass GtkModelButtonClass; +typedef struct _GtkModelButtonClass GtkModelButtonClass; + +struct _GtkModelButtonClass +{ + GtkWidgetClass parent_class; + + void (* clicked) (GtkModelButton *button); +}; static void gtk_model_button_actionable_iface_init (GtkActionableInterface *iface); G_DEFINE_TYPE_WITH_CODE (GtkModelButton, gtk_model_button, GTK_TYPE_WIDGET, @@ -968,11 +975,7 @@ close_menu (GtkModelButton *self) } static void -gtk_model_button_clicked (GtkGestureClick *gesture, - guint n_press, - double x, - double y, - GtkModelButton *self) +gtk_model_button_clicked (GtkModelButton *self) { if (self->menu_name != NULL) { @@ -994,8 +997,6 @@ gtk_model_button_clicked (GtkGestureClick *gesture, close_menu (self); } - g_signal_emit (self, signals[SIGNAL_CLICKED], 0); - if (self->action_helper) gtk_action_helper_activate (self->action_helper); } @@ -1094,6 +1095,8 @@ gtk_model_button_class_init (GtkModelButtonClass *class) widget_class->focus = gtk_model_button_focus; widget_class->get_accessible = gtk_model_button_get_accessible; + class->clicked = gtk_model_button_clicked; + /** * GtkModelButton:role: * @@ -1221,7 +1224,7 @@ gtk_model_button_class_init (GtkModelButtonClass *class) signals[SIGNAL_CLICKED] = g_signal_new (I_("clicked"), G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, - 0, + G_STRUCT_OFFSET (GtkModelButtonClass, clicked), NULL, NULL, NULL, G_TYPE_NONE, 0); @@ -1366,6 +1369,12 @@ focus_in_cb (GtkEventController *controller, } static void +emit_clicked (GtkModelButton *button) +{ + g_signal_emit (button, signals[SIGNAL_CLICKED], 0); +} + +static void gtk_model_button_init (GtkModelButton *self) { GtkEventController *controller; @@ -1398,7 +1407,7 @@ gtk_model_button_init (GtkModelButton *self) gtk_gesture_single_set_touch_only (GTK_GESTURE_SINGLE (gesture), FALSE); gtk_gesture_single_set_exclusive (GTK_GESTURE_SINGLE (gesture), TRUE); gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (gesture), GDK_BUTTON_PRIMARY); - g_signal_connect (gesture, "released", G_CALLBACK (gtk_model_button_clicked), self); + g_signal_connect_swapped (gesture, "released", G_CALLBACK (emit_clicked), self); gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (gesture), GTK_PHASE_CAPTURE); gtk_widget_add_controller (GTK_WIDGET (self), GTK_EVENT_CONTROLLER (gesture)); } |