From 4ddc94b293504b56c0106b0177c36c8efd2d3a57 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Fri, 9 Mar 2018 06:14:59 +0100 Subject: [PATCH] multipressgesture: Port to new API model --- demos/gtk-demo/clipboard.c | 8 ++++---- demos/gtk-demo/dnd.c | 3 ++- examples/drawing.c | 4 ++-- gtk/gtkappchooserwidget.c | 10 +++++----- gtk/gtkbutton.c | 17 ++--------------- gtk/gtkcalendar.c | 10 +++++----- gtk/gtkcolorswatch.c | 11 ++++++----- gtk/gtkentry.c | 12 ++++++------ gtk/gtkexpander.c | 16 +++++++--------- gtk/gtkflowbox.c | 20 ++++++++++---------- gtk/gtkfontchooserwidget.c | 5 ++--- gtk/gtkgesturemultipress.c | 6 +----- gtk/gtkgesturemultipress.h | 2 +- gtk/gtkiconview.c | 10 ++++++---- gtk/gtkiconviewprivate.h | 1 - gtk/gtkimcontextwayland.c | 10 +++++++--- gtk/gtklabel.c | 6 +++--- gtk/gtklinkbutton.c | 17 ++++++++--------- gtk/gtklistbox.c | 21 ++++++++++----------- gtk/gtkmenu.c | 15 ++++++++------- gtk/gtkmenuprivate.h | 1 - gtk/gtkmountoperation.c | 13 +++++-------- gtk/gtknotebook.c | 14 +++++++------- gtk/gtkrange.c | 6 +++--- gtk/gtkspinbutton.c | 38 ++++++++++++++++++-------------------- gtk/gtkswitch.c | 5 ++--- gtk/gtktextview.c | 16 ++++++++-------- gtk/gtktoolbar.c | 16 +++++++--------- gtk/gtktreeview.c | 19 +++++++++---------- gtk/gtkwindow.c | 6 ++---- tests/testentryicons.c | 3 ++- tests/testgtk.c | 4 ++-- tests/testtreeedit.c | 4 ++-- testsuite/gtk/gestures.c | 3 ++- 34 files changed, 164 insertions(+), 188 deletions(-) diff --git a/demos/gtk-demo/clipboard.c b/demos/gtk-demo/clipboard.c index 73a8d4ed6f..08ad05e788 100644 --- a/demos/gtk-demo/clipboard.c +++ b/demos/gtk-demo/clipboard.c @@ -321,10 +321,10 @@ do_clipboard (GtkWidget *do_widget) G_CALLBACK (drag_data_received), image); /* context menu on image */ - gesture = gtk_gesture_multi_press_new (image); + gesture = gtk_gesture_multi_press_new (); gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (gesture), GDK_BUTTON_SECONDARY); - g_object_set_data_full (G_OBJECT (image), "gesture", gesture, g_object_unref); g_signal_connect (gesture, "pressed", G_CALLBACK (pressed_cb), image); + gtk_widget_add_controller (image, GTK_EVENT_CONTROLLER (gesture)); /* Create the second image */ image = gtk_image_new_from_icon_name ("process-stop"); @@ -346,10 +346,10 @@ do_clipboard (GtkWidget *do_widget) G_CALLBACK (drag_data_received), image); /* context menu on image */ - gesture = gtk_gesture_multi_press_new (image); + gesture = gtk_gesture_multi_press_new (); gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (gesture), GDK_BUTTON_SECONDARY); - g_object_set_data_full (G_OBJECT (image), "gesture", gesture, g_object_unref); g_signal_connect (gesture, "pressed", G_CALLBACK (pressed_cb), image); + gtk_widget_add_controller (image, GTK_EVENT_CONTROLLER (gesture)); } if (!gtk_widget_get_visible (window)) diff --git a/demos/gtk-demo/dnd.c b/demos/gtk-demo/dnd.c index e31c392cee..e13cc6be95 100644 --- a/demos/gtk-demo/dnd.c +++ b/demos/gtk-demo/dnd.c @@ -356,10 +356,11 @@ do_dnd (GtkWidget *do_widget) gtk_widget_set_hexpand (fixed, TRUE); gtk_widget_set_vexpand (fixed, TRUE); - multipress = gtk_gesture_multi_press_new (fixed); + multipress = gtk_gesture_multi_press_new (); gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (multipress), 0); g_signal_connect (multipress, "pressed", G_CALLBACK (pressed_cb), NULL); g_signal_connect (multipress, "released", G_CALLBACK (released_cb), NULL); + gtk_widget_add_controller (fixed, GTK_EVENT_CONTROLLER (multipress)); provider = gtk_css_provider_new (); gtk_css_provider_load_from_resource (provider, "/dnd/dnd.css"); diff --git a/examples/drawing.c b/examples/drawing.c index 7bf1bb688e..0713b81611 100644 --- a/examples/drawing.c +++ b/examples/drawing.c @@ -165,9 +165,9 @@ activate (GtkApplication *app, g_signal_connect (drag, "drag-update", G_CALLBACK (drag_update), drawing_area); g_signal_connect (drag, "drag-end", G_CALLBACK (drag_end), drawing_area); - press = gtk_gesture_multi_press_new (drawing_area); + press = gtk_gesture_multi_press_new (); gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (press), GDK_BUTTON_SECONDARY); - g_object_set_data_full (G_OBJECT (drawing_area), "press", press, g_object_unref); + gtk_widget_add_controller (drawing_area, GTK_EVENT_CONTROLLER (press)); g_signal_connect (press, "pressed", G_CALLBACK (pressed), drawing_area); diff --git a/gtk/gtkappchooserwidget.c b/gtk/gtkappchooserwidget.c index 19c0969047..bf5acc36f9 100644 --- a/gtk/gtkappchooserwidget.c +++ b/gtk/gtkappchooserwidget.c @@ -97,7 +97,6 @@ struct _GtkAppChooserWidgetPrivate { GAppInfoMonitor *monitor; GtkWidget *popup_menu; - GtkGesture *multipress_gesture; }; enum { @@ -886,7 +885,6 @@ gtk_app_chooser_widget_finalize (GObject *object) g_free (self->priv->default_text); g_signal_handlers_disconnect_by_func (self->priv->monitor, app_info_changed, self); g_object_unref (self->priv->monitor); - g_object_unref (self->priv->multipress_gesture); G_OBJECT_CLASS (gtk_app_chooser_widget_parent_class)->finalize (object); } @@ -1139,6 +1137,7 @@ gtk_app_chooser_widget_init (GtkAppChooserWidget *self) { GtkTreeSelection *selection; GtkTreeModel *sort; + GtkGesture *gesture; self->priv = gtk_app_chooser_widget_get_instance_private (self); @@ -1176,10 +1175,11 @@ gtk_app_chooser_widget_init (GtkAppChooserWidget *self) g_signal_connect (self->priv->monitor, "changed", G_CALLBACK (app_info_changed), self); - self->priv->multipress_gesture = gtk_gesture_multi_press_new (self->priv->program_list); - gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (self->priv->multipress_gesture), GDK_BUTTON_SECONDARY); - g_signal_connect (self->priv->multipress_gesture, "pressed", + gesture = gtk_gesture_multi_press_new (); + gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (gesture), GDK_BUTTON_SECONDARY); + g_signal_connect (gesture, "pressed", G_CALLBACK (gtk_app_chooser_row_pressed_cb), self); + gtk_widget_add_controller (self->priv->program_list, GTK_EVENT_CONTROLLER (gesture)); } static GAppInfo * diff --git a/gtk/gtkbutton.c b/gtk/gtkbutton.c index 6f6599479a..7d9395b9c5 100644 --- a/gtk/gtkbutton.c +++ b/gtk/gtkbutton.c @@ -124,7 +124,6 @@ enum { }; -static void gtk_button_finalize (GObject *object); static void gtk_button_dispose (GObject *object); static void gtk_button_set_property (GObject *object, guint prop_id, @@ -215,7 +214,6 @@ gtk_button_class_init (GtkButtonClass *klass) container_class = GTK_CONTAINER_CLASS (klass); gobject_class->dispose = gtk_button_dispose; - gobject_class->finalize = gtk_button_finalize; gobject_class->set_property = gtk_button_set_property; gobject_class->get_property = gtk_button_get_property; @@ -442,7 +440,7 @@ gtk_button_init (GtkButton *button) priv->use_underline = FALSE; priv->child_type = WIDGET_CHILD; - priv->gesture = gtk_gesture_multi_press_new (GTK_WIDGET (button)); + priv->gesture = gtk_gesture_multi_press_new (); gtk_gesture_single_set_touch_only (GTK_GESTURE_SINGLE (priv->gesture), FALSE); gtk_gesture_single_set_exclusive (GTK_GESTURE_SINGLE (priv->gesture), TRUE); gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (priv->gesture), GDK_BUTTON_PRIMARY); @@ -451,18 +449,7 @@ gtk_button_init (GtkButton *button) g_signal_connect (priv->gesture, "update", G_CALLBACK (multipress_gesture_update_cb), button); g_signal_connect (priv->gesture, "cancel", G_CALLBACK (multipress_gesture_cancel_cb), button); gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (priv->gesture), GTK_PHASE_CAPTURE); - -} - -static void -gtk_button_finalize (GObject *object) -{ - GtkButton *button = GTK_BUTTON (object); - GtkButtonPrivate *priv = gtk_button_get_instance_private (button); - - g_clear_object (&priv->gesture); - - G_OBJECT_CLASS (gtk_button_parent_class)->finalize (object); + gtk_widget_add_controller (GTK_WIDGET (button), GTK_EVENT_CONTROLLER (priv->gesture)); } static void diff --git a/gtk/gtkcalendar.c b/gtk/gtkcalendar.c index 219be68481..704ce1808d 100644 --- a/gtk/gtkcalendar.c +++ b/gtk/gtkcalendar.c @@ -249,7 +249,6 @@ struct _GtkCalendarPrivate gint detail_width_chars; gint detail_overflow[6]; - GtkGesture *press_gesture; GtkGesture *drag_gesture; GtkEventController *scroll_controller; GtkEventController *key_controller; @@ -643,6 +642,7 @@ static void gtk_calendar_init (GtkCalendar *calendar) { GtkWidget *widget = GTK_WIDGET (calendar); + GtkGesture *gesture; time_t secs; struct tm *tm; gint i; @@ -672,9 +672,10 @@ gtk_calendar_init (GtkCalendar *calendar) gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (calendar)), GTK_STYLE_CLASS_VIEW); - priv->press_gesture = gtk_gesture_multi_press_new (GTK_WIDGET (calendar)); - g_signal_connect (priv->press_gesture, "pressed", G_CALLBACK (gtk_calendar_button_press), calendar); - g_signal_connect (priv->press_gesture, "released", G_CALLBACK (gtk_calendar_button_release), calendar); + gesture = gtk_gesture_multi_press_new (); + g_signal_connect (gesture, "pressed", G_CALLBACK (gtk_calendar_button_press), calendar); + g_signal_connect (gesture, "released", G_CALLBACK (gtk_calendar_button_release), calendar); + gtk_widget_add_controller (GTK_WIDGET (calendar), GTK_EVENT_CONTROLLER (gesture)); priv->drag_gesture = gtk_gesture_drag_new (GTK_WIDGET (calendar)); g_signal_connect (priv->drag_gesture, "drag-begin", G_CALLBACK (gtk_calendar_drag_begin), calendar); @@ -1332,7 +1333,6 @@ gtk_calendar_finalize (GObject *object) { GtkCalendarPrivate *priv = GTK_CALENDAR (object)->priv; - g_object_unref (priv->press_gesture); g_object_unref (priv->drag_gesture); g_object_unref (priv->scroll_controller); g_object_unref (priv->key_controller); diff --git a/gtk/gtkcolorswatch.c b/gtk/gtkcolorswatch.c index 7ce4eff673..7b2765b76e 100644 --- a/gtk/gtkcolorswatch.c +++ b/gtk/gtkcolorswatch.c @@ -66,7 +66,6 @@ struct _GtkColorSwatchPrivate guint has_menu : 1; GtkGesture *long_press_gesture; - GtkGesture *multipress_gesture; GtkEventController *key_controller; GtkWidget *overlay_widget; @@ -505,7 +504,6 @@ swatch_dispose (GObject *object) } g_clear_object (&swatch->priv->long_press_gesture); - g_clear_object (&swatch->priv->multipress_gesture); g_clear_object (&swatch->priv->key_controller); G_OBJECT_CLASS (gtk_color_swatch_parent_class)->dispose (object); @@ -562,6 +560,8 @@ gtk_color_swatch_class_init (GtkColorSwatchClass *class) static void gtk_color_swatch_init (GtkColorSwatch *swatch) { + GtkGesture *gesture; + swatch->priv = gtk_color_swatch_get_instance_private (swatch); swatch->priv->use_alpha = TRUE; swatch->priv->selectable = TRUE; @@ -576,10 +576,11 @@ gtk_color_swatch_init (GtkColorSwatch *swatch) g_signal_connect (swatch->priv->long_press_gesture, "pressed", G_CALLBACK (hold_action), swatch); - swatch->priv->multipress_gesture = gtk_gesture_multi_press_new (GTK_WIDGET (swatch)); - gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (swatch->priv->multipress_gesture), 0); - g_signal_connect (swatch->priv->multipress_gesture, "pressed", + gesture = gtk_gesture_multi_press_new (); + gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (gesture), 0); + g_signal_connect (gesture, "pressed", G_CALLBACK (tap_action), swatch); + gtk_widget_add_controller (GTK_WIDGET (swatch), GTK_EVENT_CONTROLLER (gesture)); swatch->priv->key_controller = gtk_event_controller_key_new (GTK_WIDGET (swatch)); g_signal_connect (swatch->priv->key_controller, "key-pressed", diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c index 1419cca037..804cf13b57 100644 --- a/gtk/gtkentry.c +++ b/gtk/gtkentry.c @@ -213,7 +213,6 @@ struct _GtkEntryPrivate GtkWidget *magnifier; GtkGesture *drag_gesture; - GtkGesture *multipress_gesture; GtkEventController *motion_controller; GtkEventController *key_controller; @@ -2517,6 +2516,7 @@ gtk_entry_init (GtkEntry *entry) { GtkEntryPrivate *priv = gtk_entry_get_instance_private (entry); GtkCssNode *widget_node; + GtkGesture *gesture; gint i; gtk_widget_set_can_focus (GTK_WIDGET (entry), TRUE); @@ -2565,11 +2565,12 @@ gtk_entry_init (GtkEntry *entry) gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (priv->drag_gesture), 0); gtk_gesture_single_set_exclusive (GTK_GESTURE_SINGLE (priv->drag_gesture), TRUE); - priv->multipress_gesture = gtk_gesture_multi_press_new (GTK_WIDGET (entry)); - g_signal_connect (priv->multipress_gesture, "pressed", + gesture = gtk_gesture_multi_press_new (); + g_signal_connect (gesture, "pressed", G_CALLBACK (gtk_entry_multipress_gesture_pressed), entry); - gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (priv->multipress_gesture), 0); - gtk_gesture_single_set_exclusive (GTK_GESTURE_SINGLE (priv->multipress_gesture), TRUE); + gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (gesture), 0); + gtk_gesture_single_set_exclusive (GTK_GESTURE_SINGLE (gesture), TRUE); + gtk_widget_add_controller (GTK_WIDGET (entry), GTK_EVENT_CONTROLLER (gesture)); priv->motion_controller = gtk_event_controller_motion_new (GTK_WIDGET (entry)); g_signal_connect (priv->motion_controller, "motion", @@ -2796,7 +2797,6 @@ gtk_entry_finalize (GObject *object) g_free (priv->im_module); g_clear_object (&priv->drag_gesture); - g_clear_object (&priv->multipress_gesture); g_clear_object (&priv->motion_controller); if (priv->tabs) diff --git a/gtk/gtkexpander.c b/gtk/gtkexpander.c index 0777fc39a6..91aba25726 100644 --- a/gtk/gtkexpander.c +++ b/gtk/gtkexpander.c @@ -155,8 +155,6 @@ struct _GtkExpanderPrivate GtkWidget *arrow_widget; GtkWidget *child; - GtkGesture *multipress_gesture; - guint expand_timer; guint expanded : 1; @@ -338,6 +336,7 @@ static void gtk_expander_init (GtkExpander *expander) { GtkExpanderPrivate *priv = gtk_expander_get_instance_private (expander); + GtkGesture *gesture; gtk_widget_set_can_focus (GTK_WIDGET (expander), TRUE); gtk_widget_set_has_surface (GTK_WIDGET (expander), FALSE); @@ -367,15 +366,16 @@ gtk_expander_init (GtkExpander *expander) gtk_drag_dest_set (GTK_WIDGET (expander), 0, NULL, 0); gtk_drag_dest_set_track_motion (GTK_WIDGET (expander), TRUE); - priv->multipress_gesture = gtk_gesture_multi_press_new (priv->title_widget); - gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (priv->multipress_gesture), + gesture = gtk_gesture_multi_press_new (); + gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (gesture), GDK_BUTTON_PRIMARY); - gtk_gesture_single_set_touch_only (GTK_GESTURE_SINGLE (priv->multipress_gesture), + gtk_gesture_single_set_touch_only (GTK_GESTURE_SINGLE (gesture), FALSE); - g_signal_connect (priv->multipress_gesture, "released", + g_signal_connect (gesture, "released", G_CALLBACK (gesture_multipress_released_cb), expander); - gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (priv->multipress_gesture), + gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (gesture), GTK_PHASE_BUBBLE); + gtk_widget_add_controller (GTK_WIDGET (priv->title_widget), GTK_EVENT_CONTROLLER (gesture)); } static GtkBuildableIface *parent_buildable_iface; @@ -491,8 +491,6 @@ gtk_expander_destroy (GtkWidget *widget) priv->arrow_widget = NULL; } - g_clear_object (&priv->multipress_gesture); - GTK_WIDGET_CLASS (gtk_expander_parent_class)->destroy (widget); } diff --git a/gtk/gtkflowbox.c b/gtk/gtkflowbox.c index a37159d32f..1c4ed8db98 100644 --- a/gtk/gtkflowbox.c +++ b/gtk/gtkflowbox.c @@ -665,7 +665,6 @@ struct _GtkFlowBoxPrivate { gpointer sort_data; GDestroyNotify sort_destroy; - GtkGesture *multipress_gesture; GtkGesture *drag_gesture; GtkEventController *key_controller; @@ -3379,7 +3378,6 @@ gtk_flow_box_finalize (GObject *obj) g_clear_object (&priv->vadjustment); g_object_unref (priv->drag_gesture); - g_object_unref (priv->multipress_gesture); g_object_unref (priv->key_controller); if (priv->bound_model) @@ -3727,6 +3725,7 @@ static void gtk_flow_box_init (GtkFlowBox *box) { GtkFlowBoxPrivate *priv = BOX_PRIV (box); + GtkGesture *gesture; gtk_widget_set_has_surface (GTK_WIDGET (box), FALSE); @@ -3741,21 +3740,22 @@ gtk_flow_box_init (GtkFlowBox *box) priv->children = g_sequence_new (NULL); - priv->multipress_gesture = gtk_gesture_multi_press_new (GTK_WIDGET (box)); - gtk_gesture_single_set_touch_only (GTK_GESTURE_SINGLE (priv->multipress_gesture), + gesture = gtk_gesture_multi_press_new (); + gtk_gesture_single_set_touch_only (GTK_GESTURE_SINGLE (gesture), FALSE); - gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (priv->multipress_gesture), + gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (gesture), GDK_BUTTON_PRIMARY); - gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (priv->multipress_gesture), + gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (gesture), GTK_PHASE_BUBBLE); - g_signal_connect (priv->multipress_gesture, "pressed", + g_signal_connect (gesture, "pressed", G_CALLBACK (gtk_flow_box_multipress_gesture_pressed), box); - g_signal_connect (priv->multipress_gesture, "released", + g_signal_connect (gesture, "released", G_CALLBACK (gtk_flow_box_multipress_gesture_released), box); - g_signal_connect (priv->multipress_gesture, "stopped", + g_signal_connect (gesture, "stopped", G_CALLBACK (gtk_flow_box_multipress_gesture_stopped), box); - g_signal_connect (priv->multipress_gesture, "unpaired-release", + g_signal_connect (gesture, "unpaired-release", G_CALLBACK (gtk_flow_box_multipress_unpaired_release), box); + gtk_widget_add_controller (GTK_WIDGET (box), GTK_EVENT_CONTROLLER (gesture)); priv->drag_gesture = gtk_gesture_drag_new (GTK_WIDGET (box)); gtk_gesture_single_set_touch_only (GTK_GESTURE_SINGLE (priv->drag_gesture), diff --git a/gtk/gtkfontchooserwidget.c b/gtk/gtkfontchooserwidget.c index d5bdc4fbad..bd823e055d 100644 --- a/gtk/gtkfontchooserwidget.c +++ b/gtk/gtkfontchooserwidget.c @@ -2026,11 +2026,10 @@ add_check_group (GtkFontChooserWidget *fontchooser, g_signal_connect_swapped (feat, "notify::inconsistent", G_CALLBACK (update_font_features), fontchooser); g_signal_connect (feat, "clicked", G_CALLBACK (feat_clicked), NULL); - gesture = gtk_gesture_multi_press_new (feat); - g_object_set_data_full (G_OBJECT (feat), "press", gesture, g_object_unref); - + gesture = gtk_gesture_multi_press_new (); gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (gesture), GDK_BUTTON_SECONDARY); g_signal_connect (gesture, "pressed", G_CALLBACK (feat_pressed), feat); + gtk_widget_add_controller (feat, GTK_EVENT_CONTROLLER (gesture)); example = gtk_label_new (""); gtk_label_set_selectable (GTK_LABEL (example), TRUE); diff --git a/gtk/gtkgesturemultipress.c b/gtk/gtkgesturemultipress.c index 5f0122787f..db654036e5 100644 --- a/gtk/gtkgesturemultipress.c +++ b/gtk/gtkgesturemultipress.c @@ -432,7 +432,6 @@ gtk_gesture_multi_press_init (GtkGestureMultiPress *gesture) /** * gtk_gesture_multi_press_new: - * @widget: a #GtkWidget * * Returns a newly created #GtkGesture that recognizes single and multiple * presses. @@ -440,12 +439,9 @@ gtk_gesture_multi_press_init (GtkGestureMultiPress *gesture) * Returns: a newly created #GtkGestureMultiPress **/ GtkGesture * -gtk_gesture_multi_press_new (GtkWidget *widget) +gtk_gesture_multi_press_new (void) { - g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL); - return g_object_new (GTK_TYPE_GESTURE_MULTI_PRESS, - "widget", widget, NULL); } diff --git a/gtk/gtkgesturemultipress.h b/gtk/gtkgesturemultipress.h index 06d46234e8..16c50ff102 100644 --- a/gtk/gtkgesturemultipress.h +++ b/gtk/gtkgesturemultipress.h @@ -42,7 +42,7 @@ GDK_AVAILABLE_IN_ALL GType gtk_gesture_multi_press_get_type (void) G_GNUC_CONST; GDK_AVAILABLE_IN_ALL -GtkGesture * gtk_gesture_multi_press_new (GtkWidget *widget); +GtkGesture * gtk_gesture_multi_press_new (void); GDK_AVAILABLE_IN_ALL void gtk_gesture_multi_press_set_area (GtkGestureMultiPress *gesture, diff --git a/gtk/gtkiconview.c b/gtk/gtkiconview.c index a1718c1790..45e4088d14 100644 --- a/gtk/gtkiconview.c +++ b/gtk/gtkiconview.c @@ -918,6 +918,8 @@ gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface) static void gtk_icon_view_init (GtkIconView *icon_view) { + GtkGesture *gesture; + icon_view->priv = gtk_icon_view_get_instance_private (icon_view); icon_view->priv->width = 0; @@ -957,11 +959,12 @@ gtk_icon_view_init (GtkIconView *icon_view) gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (icon_view)), GTK_STYLE_CLASS_VIEW); - icon_view->priv->press_gesture = gtk_gesture_multi_press_new (GTK_WIDGET (icon_view)); - g_signal_connect (icon_view->priv->press_gesture, "pressed", G_CALLBACK (gtk_icon_view_button_press), + gesture = gtk_gesture_multi_press_new (); + g_signal_connect (gesture, "pressed", G_CALLBACK (gtk_icon_view_button_press), icon_view); - g_signal_connect (icon_view->priv->press_gesture, "released", G_CALLBACK (gtk_icon_view_button_release), + g_signal_connect (gesture, "released", G_CALLBACK (gtk_icon_view_button_release), icon_view); + gtk_widget_add_controller (GTK_WIDGET (icon_view), GTK_EVENT_CONTROLLER (gesture)); icon_view->priv->motion_controller = gtk_event_controller_motion_new (GTK_WIDGET (icon_view)); g_signal_connect (icon_view->priv->motion_controller, "leave", G_CALLBACK (gtk_icon_view_leave), @@ -1020,7 +1023,6 @@ gtk_icon_view_dispose (GObject *object) priv->cell_area = NULL; } - g_clear_object (&priv->press_gesture); g_clear_object (&priv->motion_controller); g_clear_object (&priv->key_controller); diff --git a/gtk/gtkiconviewprivate.h b/gtk/gtkiconviewprivate.h index e335d161d0..737c23bf1d 100644 --- a/gtk/gtkiconviewprivate.h +++ b/gtk/gtkiconviewprivate.h @@ -60,7 +60,6 @@ struct _GtkIconViewPrivate GList *items; - GtkGesture *press_gesture; GtkEventController *motion_controller; GtkEventController *key_controller; diff --git a/gtk/gtkimcontextwayland.c b/gtk/gtkimcontextwayland.c index db2a6a6053..e9cc6a6eb2 100644 --- a/gtk/gtkimcontextwayland.c +++ b/gtk/gtkimcontextwayland.c @@ -436,8 +436,11 @@ gtk_im_context_wayland_set_client_widget (GtkIMContext *context, if (widget == context_wayland->widget) return; - if (context_wayland->widget && context_wayland->widget != widget) - g_clear_object (&context_wayland->gesture); + if (context_wayland->widget) + { + gtk_widget_remove_controller (context_wayland->widget, GTK_EVENT_CONTROLLER (context_wayland->gesture)); + context_wayland->gesture = NULL; + } g_set_object (&context_wayland->widget, widget); @@ -445,13 +448,14 @@ gtk_im_context_wayland_set_client_widget (GtkIMContext *context, { GtkGesture *gesture; - gesture = gtk_gesture_multi_press_new (widget); + gesture = gtk_gesture_multi_press_new (); gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (gesture), GTK_PHASE_CAPTURE); g_signal_connect (gesture, "pressed", G_CALLBACK (pressed_cb), context); g_signal_connect (gesture, "released", G_CALLBACK (released_cb), context); + gtk_widget_add_controller (widget, GTK_EVENT_CONTROLLER (gesture)); context_wayland->gesture = gesture; } } diff --git a/gtk/gtklabel.c b/gtk/gtklabel.c index 570d1ed3cd..c15cd69459 100644 --- a/gtk/gtklabel.c +++ b/gtk/gtklabel.c @@ -3178,7 +3178,6 @@ gtk_label_finalize (GObject *object) if (priv->select_info) { g_object_unref (priv->select_info->drag_gesture); - g_object_unref (priv->select_info->multipress_gesture); g_object_unref (priv->select_info->motion_controller); g_object_unref (priv->select_info->provider); } @@ -5024,13 +5023,14 @@ gtk_label_ensure_select_info (GtkLabel *label) G_CALLBACK (gtk_label_drag_gesture_update), label); gtk_gesture_single_set_exclusive (GTK_GESTURE_SINGLE (priv->select_info->drag_gesture), TRUE); - priv->select_info->multipress_gesture = gtk_gesture_multi_press_new (GTK_WIDGET (label)); + priv->select_info->multipress_gesture = gtk_gesture_multi_press_new (); g_signal_connect (priv->select_info->multipress_gesture, "pressed", G_CALLBACK (gtk_label_multipress_gesture_pressed), label); g_signal_connect (priv->select_info->multipress_gesture, "released", G_CALLBACK (gtk_label_multipress_gesture_released), label); gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (priv->select_info->multipress_gesture), 0); gtk_gesture_single_set_exclusive (GTK_GESTURE_SINGLE (priv->select_info->multipress_gesture), TRUE); + gtk_widget_add_controller (GTK_WIDGET (label), GTK_EVENT_CONTROLLER (priv->select_info->multipress_gesture)); priv->select_info->motion_controller = gtk_event_controller_motion_new (GTK_WIDGET (label)); g_signal_connect (priv->select_info->motion_controller, "motion", @@ -5054,7 +5054,7 @@ gtk_label_clear_select_info (GtkLabel *label) if (!priv->select_info->selectable && !priv->select_info->links) { g_object_unref (priv->select_info->drag_gesture); - g_object_unref (priv->select_info->multipress_gesture); + gtk_widget_remove_controller (GTK_WIDGET (label), GTK_EVENT_CONTROLLER (priv->select_info->multipress_gesture)); g_object_unref (priv->select_info->motion_controller); GTK_LABEL_CONTENT (priv->select_info->provider)->label = NULL; g_object_unref (priv->select_info->provider); diff --git a/gtk/gtklinkbutton.c b/gtk/gtklinkbutton.c index aae687fb2b..42fa0a238b 100644 --- a/gtk/gtklinkbutton.c +++ b/gtk/gtklinkbutton.c @@ -79,7 +79,6 @@ struct _GtkLinkButtonPrivate gboolean visited; GtkWidget *popup_menu; - GtkGesture *click_gesture; }; enum @@ -209,9 +208,9 @@ gtk_link_button_class_init (GtkLinkButtonClass *klass) static void gtk_link_button_init (GtkLinkButton *link_button) { - GtkLinkButtonPrivate *priv = gtk_link_button_get_instance_private (link_button); GtkStyleContext *context; GdkContentFormats *targets; + GtkGesture *gesture; gtk_button_set_relief (GTK_BUTTON (link_button), GTK_RELIEF_NONE); gtk_widget_set_state_flags (GTK_WIDGET (link_button), GTK_STATE_FLAG_LINK, FALSE); @@ -232,12 +231,13 @@ gtk_link_button_init (GtkLinkButton *link_button) gdk_content_formats_unref (targets); gtk_drag_source_set_icon_name (GTK_WIDGET (link_button), "text-x-generic"); - priv->click_gesture = gtk_gesture_multi_press_new (GTK_WIDGET (link_button)); - gtk_gesture_single_set_touch_only (GTK_GESTURE_SINGLE (priv->click_gesture), FALSE); - gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (priv->click_gesture), 0); - gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (priv->click_gesture), GTK_PHASE_BUBBLE); - g_signal_connect (priv->click_gesture, "pressed", G_CALLBACK (gtk_link_button_pressed_cb), + gesture = gtk_gesture_multi_press_new (); + gtk_gesture_single_set_touch_only (GTK_GESTURE_SINGLE (gesture), FALSE); + gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (gesture), 0); + gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (gesture), GTK_PHASE_BUBBLE); + g_signal_connect (gesture, "pressed", G_CALLBACK (gtk_link_button_pressed_cb), link_button); + gtk_widget_add_controller (GTK_WIDGET (link_button), GTK_EVENT_CONTROLLER (gesture)); context = gtk_widget_get_style_context (GTK_WIDGET (link_button)); gtk_style_context_add_class (context, "link"); @@ -252,8 +252,7 @@ gtk_link_button_finalize (GObject *object) GtkLinkButtonPrivate *priv = gtk_link_button_get_instance_private (link_button); g_free (priv->uri); - g_object_unref (priv->click_gesture); - + G_OBJECT_CLASS (gtk_link_button_parent_class)->finalize (object); } diff --git a/gtk/gtklistbox.c b/gtk/gtklistbox.c index c258836185..2c4e4a2304 100644 --- a/gtk/gtklistbox.c +++ b/gtk/gtklistbox.c @@ -114,8 +114,6 @@ typedef struct gboolean activate_single_click; gboolean accept_unpaired_release; - GtkGesture *multipress_gesture; - /* DnD */ GtkListBoxRow *drag_highlighted_row; @@ -379,7 +377,6 @@ gtk_list_box_finalize (GObject *obj) g_clear_object (&priv->adjustment); g_clear_object (&priv->drag_highlighted_row); - g_clear_object (&priv->multipress_gesture); g_sequence_free (priv->children); g_hash_table_unref (priv->header_hash); @@ -612,6 +609,7 @@ gtk_list_box_init (GtkListBox *box) { GtkListBoxPrivate *priv = BOX_PRIV (box); GtkWidget *widget = GTK_WIDGET (box); + GtkGesture *gesture; gtk_widget_set_has_surface (widget, FALSE); priv->selection_mode = GTK_SELECTION_SINGLE; @@ -620,21 +618,22 @@ gtk_list_box_init (GtkListBox *box) priv->children = g_sequence_new (NULL); priv->header_hash = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, NULL); - priv->multipress_gesture = gtk_gesture_multi_press_new (widget); - gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (priv->multipress_gesture), + gesture = gtk_gesture_multi_press_new (); + gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (gesture), GTK_PHASE_BUBBLE); - gtk_gesture_single_set_touch_only (GTK_GESTURE_SINGLE (priv->multipress_gesture), + gtk_gesture_single_set_touch_only (GTK_GESTURE_SINGLE (gesture), FALSE); - gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (priv->multipress_gesture), + gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (gesture), GDK_BUTTON_PRIMARY); - g_signal_connect (priv->multipress_gesture, "pressed", + g_signal_connect (gesture, "pressed", G_CALLBACK (gtk_list_box_multipress_gesture_pressed), box); - g_signal_connect (priv->multipress_gesture, "released", + g_signal_connect (gesture, "released", G_CALLBACK (gtk_list_box_multipress_gesture_released), box); - g_signal_connect (priv->multipress_gesture, "stopped", + g_signal_connect (gesture, "stopped", G_CALLBACK (gtk_list_box_multipress_gesture_stopped), box); - g_signal_connect (priv->multipress_gesture, "unpaired-release", + g_signal_connect (gesture, "unpaired-release", G_CALLBACK (gtk_list_box_multipress_unpaired_release), box); + gtk_widget_add_controller (widget, GTK_EVENT_CONTROLLER (gesture)); g_signal_connect (box, "notify::parent", G_CALLBACK (gtk_list_box_parent_cb), NULL); } diff --git a/gtk/gtkmenu.c b/gtk/gtkmenu.c index c87c8f9df5..3cb683aa36 100644 --- a/gtk/gtkmenu.c +++ b/gtk/gtkmenu.c @@ -1085,6 +1085,7 @@ static void gtk_menu_init (GtkMenu *menu) { GtkMenuPrivate *priv; + GtkGesture *gesture; priv = gtk_menu_get_instance_private (menu); @@ -1129,12 +1130,13 @@ gtk_menu_init (GtkMenu *menu) gtk_widget_set_parent (priv->bottom_arrow_widget, GTK_WIDGET (menu)); gtk_widget_hide (priv->bottom_arrow_widget); - priv->click_gesture = gtk_gesture_multi_press_new (GTK_WIDGET (menu)); - gtk_gesture_single_set_touch_only (GTK_GESTURE_SINGLE (priv->click_gesture), FALSE); - gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (priv->click_gesture), 0); - gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (priv->click_gesture), GTK_PHASE_BUBBLE); - g_signal_connect (priv->click_gesture, "pressed", G_CALLBACK (gtk_menu_pressed_cb), menu); - g_signal_connect (priv->click_gesture, "released", G_CALLBACK (gtk_menu_released_cb), menu); + gesture = gtk_gesture_multi_press_new (); + gtk_gesture_single_set_touch_only (GTK_GESTURE_SINGLE (gesture), FALSE); + gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (gesture), 0); + gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (gesture), GTK_PHASE_BUBBLE); + g_signal_connect (gesture, "pressed", G_CALLBACK (gtk_menu_pressed_cb), menu); + g_signal_connect (gesture, "released", G_CALLBACK (gtk_menu_released_cb), menu); + gtk_widget_add_controller (GTK_WIDGET (menu), GTK_EVENT_CONTROLLER (gesture)); priv->scroll_controller = gtk_event_controller_scroll_new (GTK_WIDGET (menu), @@ -1223,7 +1225,6 @@ gtk_menu_finalize (GObject *object) gtk_widget_unparent (priv->top_arrow_widget); gtk_widget_unparent (priv->bottom_arrow_widget); - g_clear_object (&priv->click_gesture); g_clear_object (&priv->scroll_controller); g_clear_object (&priv->motion_controller); g_clear_object (&priv->key_controller); diff --git a/gtk/gtkmenuprivate.h b/gtk/gtkmenuprivate.h index 3ef3525a88..70e6fc159d 100644 --- a/gtk/gtkmenuprivate.h +++ b/gtk/gtkmenuprivate.h @@ -75,7 +75,6 @@ struct _GtkMenuPrivate GtkWidget *top_arrow_widget; GtkWidget *bottom_arrow_widget; - GtkGesture *click_gesture; GtkEventController *scroll_controller; GtkEventController *motion_controller; GtkEventController *key_controller; diff --git a/gtk/gtkmountoperation.c b/gtk/gtkmountoperation.c index 889c7fc956..e03c565f24 100644 --- a/gtk/gtkmountoperation.c +++ b/gtk/gtkmountoperation.c @@ -132,8 +132,6 @@ struct _GtkMountOperationPrivate { /* for the show-processes dialog */ GtkWidget *process_tree_view; GtkListStore *process_list_store; - - GtkGesture *multipress_gesture; }; enum { @@ -231,9 +229,6 @@ gtk_mount_operation_finalize (GObject *object) if (priv->handler) g_object_unref (priv->handler); - if (priv->multipress_gesture) - g_object_unref (priv->multipress_gesture); - G_OBJECT_CLASS (gtk_mount_operation_parent_class)->finalize (object); } @@ -1384,6 +1379,7 @@ create_show_processes_dialog (GtkMountOperation *op, GtkListStore *list_store; gchar *s; gboolean use_header; + GtkGesture *gesture; priv = op->priv; @@ -1474,10 +1470,11 @@ create_show_processes_dialog (GtkMountOperation *op, G_CALLBACK (on_popup_menu_for_process_tree_view), op); - priv->multipress_gesture = gtk_gesture_multi_press_new (tree_view); - gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (priv->multipress_gesture), GDK_BUTTON_SECONDARY); - g_signal_connect (priv->multipress_gesture, "pressed", + gesture = gtk_gesture_multi_press_new (); + gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (gesture), GDK_BUTTON_SECONDARY); + g_signal_connect (gesture, "pressed", G_CALLBACK (multi_press_cb), op); + gtk_widget_add_controller (tree_view, GTK_EVENT_CONTROLLER (gesture)); list_store = gtk_list_store_new (3, GDK_TYPE_TEXTURE, diff --git a/gtk/gtknotebook.c b/gtk/gtknotebook.c index 80abd55d56..3ad8d16961 100644 --- a/gtk/gtknotebook.c +++ b/gtk/gtknotebook.c @@ -207,7 +207,6 @@ struct _GtkNotebookPrivate guint switch_tab_timer; GList *switch_tab; - GtkGesture *press_gesture; GtkEventController *motion_controller; guint32 timer; @@ -1042,6 +1041,7 @@ gtk_notebook_init (GtkNotebook *notebook) { GtkNotebookPrivate *priv; GdkContentFormats *targets; + GtkGesture *gesture; gtk_widget_set_can_focus (GTK_WIDGET (notebook), TRUE); gtk_widget_set_has_surface (GTK_WIDGET (notebook), FALSE); @@ -1111,11 +1111,12 @@ gtk_notebook_init (GtkNotebook *notebook) gtk_widget_set_vexpand (priv->stack_widget, TRUE); gtk_container_add (GTK_CONTAINER (priv->box), priv->stack_widget); - priv->press_gesture = gtk_gesture_multi_press_new (GTK_WIDGET (notebook)); - gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (priv->press_gesture), 0); - gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (priv->press_gesture), GTK_PHASE_CAPTURE); - g_signal_connect (priv->press_gesture, "pressed", G_CALLBACK (gtk_notebook_gesture_pressed), notebook); - g_signal_connect (priv->press_gesture, "released", G_CALLBACK (gtk_notebook_gesture_released), notebook); + gesture = gtk_gesture_multi_press_new (); + gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (gesture), 0); + gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (gesture), GTK_PHASE_CAPTURE); + g_signal_connect (gesture, "pressed", G_CALLBACK (gtk_notebook_gesture_pressed), notebook); + g_signal_connect (gesture, "released", G_CALLBACK (gtk_notebook_gesture_released), notebook); + gtk_widget_add_controller (GTK_WIDGET (notebook), GTK_EVENT_CONTROLLER (gesture)); priv->motion_controller = gtk_event_controller_motion_new (GTK_WIDGET (notebook)); g_signal_connect (priv->motion_controller, "motion", G_CALLBACK (gtk_notebook_motion), notebook); @@ -1608,7 +1609,6 @@ gtk_notebook_finalize (GObject *object) GtkNotebook *notebook = GTK_NOTEBOOK (object); GtkNotebookPrivate *priv = notebook->priv; - g_clear_object (&priv->press_gesture); g_clear_object (&priv->motion_controller); gtk_widget_unparent (priv->box); diff --git a/gtk/gtkrange.c b/gtk/gtkrange.c index b1d0278d78..f1a6acc179 100644 --- a/gtk/gtkrange.c +++ b/gtk/gtkrange.c @@ -574,13 +574,14 @@ gtk_range_init (GtkRange *range) g_signal_connect (priv->drag_gesture, "drag-update", G_CALLBACK (gtk_range_drag_gesture_update), range); - priv->multipress_gesture = gtk_gesture_multi_press_new (GTK_WIDGET (range)); + priv->multipress_gesture = gtk_gesture_multi_press_new (); gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (priv->multipress_gesture), 0); - gtk_gesture_group (priv->drag_gesture, priv->multipress_gesture); g_signal_connect (priv->multipress_gesture, "pressed", G_CALLBACK (gtk_range_multipress_gesture_pressed), range); g_signal_connect (priv->multipress_gesture, "released", G_CALLBACK (gtk_range_multipress_gesture_released), range); + gtk_widget_add_controller (GTK_WIDGET (range), GTK_EVENT_CONTROLLER (priv->multipress_gesture)); + gtk_gesture_group (priv->drag_gesture, priv->multipress_gesture); priv->long_press_gesture = gtk_gesture_long_press_new (GTK_WIDGET (range)); g_object_set (priv->long_press_gesture, "delay-factor", 2.0, NULL); @@ -1292,7 +1293,6 @@ gtk_range_finalize (GObject *object) GtkRangePrivate *priv = gtk_range_get_instance_private (range); g_clear_object (&priv->drag_gesture); - g_clear_object (&priv->multipress_gesture); g_clear_object (&priv->long_press_gesture); g_clear_object (&priv->scroll_controller); g_clear_object (&priv->key_controller); diff --git a/gtk/gtkspinbutton.c b/gtk/gtkspinbutton.c index 9d1b9bd7ff..4bbffdff2c 100644 --- a/gtk/gtkspinbutton.c +++ b/gtk/gtkspinbutton.c @@ -187,9 +187,7 @@ struct _GtkSpinButtonPrivate GtkWidget *entry; GtkWidget *up_button; - GtkGesture *up_click_gesture; GtkWidget *down_button; - GtkGesture *down_click_gesture; GtkWidget *click_child; @@ -774,8 +772,7 @@ button_pressed_cb (GtkGestureMultiPress *gesture, { GtkSpinButton *spin_button = user_data; GtkSpinButtonPrivate *priv = gtk_spin_button_get_instance_private (spin_button); - GtkWidget *pressed_button = GTK_GESTURE (gesture) == priv->up_click_gesture ? - priv->up_button : priv->down_button; + GtkWidget *pressed_button = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture)); gtk_widget_grab_focus (GTK_WIDGET (spin_button)); @@ -810,14 +807,15 @@ button_released_cb (GtkGestureMultiPress *gesture, if (button == GDK_BUTTON_SECONDARY) { + GtkWidget *button = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture)); double diff; - if (GTK_GESTURE (gesture) == priv->down_click_gesture) + if (button == priv->down_button) { diff = gtk_adjustment_get_value (priv->adjustment) - gtk_adjustment_get_lower (priv->adjustment); if (diff > EPSILON) gtk_spin_button_real_spin (spin_button, -diff); } - else if (GTK_GESTURE (gesture) == priv->up_click_gesture) + else if (button == priv->up_button) { diff = gtk_adjustment_get_upper (priv->adjustment) - gtk_adjustment_get_value (priv->adjustment); if (diff > EPSILON) @@ -867,26 +865,28 @@ gtk_spin_button_init (GtkSpinButton *spin_button) gtk_style_context_add_class (gtk_widget_get_style_context (priv->down_button), "down"); gtk_container_add (GTK_CONTAINER (priv->box), priv->down_button); - priv->down_click_gesture = gtk_gesture_multi_press_new (GTK_WIDGET (priv->down_button)); - gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (priv->down_click_gesture), 0); - gtk_gesture_single_set_touch_only (GTK_GESTURE_SINGLE (priv->down_click_gesture), FALSE); - gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (priv->down_click_gesture), + gesture = gtk_gesture_multi_press_new (); + gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (gesture), 0); + gtk_gesture_single_set_touch_only (GTK_GESTURE_SINGLE (gesture), FALSE); + gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (gesture), GTK_PHASE_CAPTURE); - g_signal_connect (priv->down_click_gesture, "pressed", G_CALLBACK (button_pressed_cb), spin_button); - g_signal_connect (priv->down_click_gesture, "released", G_CALLBACK (button_released_cb), spin_button); + g_signal_connect (gesture, "pressed", G_CALLBACK (button_pressed_cb), spin_button); + g_signal_connect (gesture, "released", G_CALLBACK (button_released_cb), spin_button); + gtk_widget_add_controller (GTK_WIDGET (priv->down_button), GTK_EVENT_CONTROLLER (gesture)); priv->up_button = gtk_button_new_from_icon_name ("list-add-symbolic"); gtk_widget_set_can_focus (priv->up_button, FALSE); gtk_style_context_add_class (gtk_widget_get_style_context (priv->up_button), "up"); gtk_container_add (GTK_CONTAINER (priv->box), priv->up_button); - priv->up_click_gesture = gtk_gesture_multi_press_new (GTK_WIDGET (priv->up_button)); - gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (priv->up_click_gesture), 0); - gtk_gesture_single_set_touch_only (GTK_GESTURE_SINGLE (priv->up_click_gesture), FALSE); - gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (priv->up_click_gesture), + gesture = gtk_gesture_multi_press_new (); + gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (gesture), 0); + gtk_gesture_single_set_touch_only (GTK_GESTURE_SINGLE (gesture), FALSE); + gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (gesture), GTK_PHASE_CAPTURE); - g_signal_connect (priv->up_click_gesture, "pressed", G_CALLBACK (button_pressed_cb), spin_button); - g_signal_connect (priv->up_click_gesture, "released", G_CALLBACK (button_released_cb), spin_button); + g_signal_connect (gesture, "pressed", G_CALLBACK (button_pressed_cb), spin_button); + g_signal_connect (gesture, "released", G_CALLBACK (button_released_cb), spin_button); + gtk_widget_add_controller (GTK_WIDGET (priv->up_button), GTK_EVENT_CONTROLLER (gesture)); gtk_spin_button_set_adjustment (spin_button, NULL); @@ -917,8 +917,6 @@ gtk_spin_button_finalize (GObject *object) gtk_spin_button_unset_adjustment (spin_button); g_object_unref (priv->scroll_controller); - g_object_unref (priv->up_click_gesture); - g_object_unref (priv->down_click_gesture); gtk_widget_unparent (priv->box); diff --git a/gtk/gtkswitch.c b/gtk/gtkswitch.c index e5fa5a1726..b02c7fdd04 100644 --- a/gtk/gtkswitch.c +++ b/gtk/gtkswitch.c @@ -475,8 +475,6 @@ gtk_switch_dispose (GObject *object) g_clear_object (&priv->action_helper); - g_clear_object (&priv->multipress_gesture); - G_OBJECT_CLASS (gtk_switch_parent_class)->dispose (object); } @@ -619,7 +617,7 @@ gtk_switch_init (GtkSwitch *self) gtk_widget_set_has_surface (GTK_WIDGET (self), FALSE); gtk_widget_set_can_focus (GTK_WIDGET (self), TRUE); - gesture = gtk_gesture_multi_press_new (GTK_WIDGET (self)); + gesture = gtk_gesture_multi_press_new (); gtk_gesture_single_set_touch_only (GTK_GESTURE_SINGLE (gesture), FALSE); gtk_gesture_single_set_exclusive (GTK_GESTURE_SINGLE (gesture), TRUE); g_signal_connect (gesture, "pressed", @@ -628,6 +626,7 @@ gtk_switch_init (GtkSwitch *self) G_CALLBACK (gtk_switch_multipress_gesture_released), self); gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (gesture), GTK_PHASE_BUBBLE); + gtk_widget_add_controller (GTK_WIDGET (self), GTK_EVENT_CONTROLLER (gesture)); priv->multipress_gesture = gesture; gesture = gtk_gesture_pan_new (GTK_ORIENTATION_HORIZONTAL); diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c index 193c9a9794..c50fe411f7 100644 --- a/gtk/gtktextview.c +++ b/gtk/gtktextview.c @@ -224,7 +224,6 @@ struct _GtkTextViewPrivate GtkTextPendingScroll *pending_scroll; - GtkGesture *multipress_gesture; GtkGesture *drag_gesture; GtkEventController *motion_controller; GtkEventController *key_controller; @@ -1617,6 +1616,7 @@ gtk_text_view_init (GtkTextView *text_view) GdkContentFormats *target_list; GtkTextViewPrivate *priv; GtkStyleContext *context; + GtkGesture *gesture; text_view->priv = gtk_text_view_get_instance_private (text_view); priv = text_view->priv; @@ -1671,11 +1671,12 @@ gtk_text_view_init (GtkTextView *text_view) priv->text_window = text_window_new (GTK_TEXT_WINDOW_TEXT, widget); - priv->multipress_gesture = gtk_gesture_multi_press_new (widget); - gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (priv->multipress_gesture), 0); - g_signal_connect (priv->multipress_gesture, "pressed", + gesture = gtk_gesture_multi_press_new (); + gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (gesture), 0); + g_signal_connect (gesture, "pressed", G_CALLBACK (gtk_text_view_multipress_gesture_pressed), widget); + gtk_widget_add_controller (widget, GTK_EVENT_CONTROLLER (gesture)); priv->drag_gesture = gtk_gesture_drag_new (widget); g_signal_connect (priv->drag_gesture, "drag-update", @@ -3599,7 +3600,6 @@ gtk_text_view_finalize (GObject *object) cancel_pending_scroll (text_view); - g_object_unref (priv->multipress_gesture); g_object_unref (priv->drag_gesture); g_object_unref (priv->motion_controller); g_object_unref (priv->key_controller); @@ -5121,7 +5121,7 @@ gtk_text_view_multipress_gesture_pressed (GtkGestureMultiPress *gesture, with the middle button */ priv->scroll_after_paste = FALSE; - get_iter_from_gesture (text_view, priv->multipress_gesture, + get_iter_from_gesture (text_view, GTK_GESTURE (gesture), &iter, NULL, NULL); gtk_text_buffer_paste_clipboard (get_buffer (text_view), gtk_widget_get_primary_clipboard (GTK_WIDGET (text_view)), @@ -5153,7 +5153,7 @@ gtk_text_view_multipress_gesture_pressed (GtkGestureMultiPress *gesture, if (is_touchscreen) handle_mode = GTK_TEXT_HANDLE_MODE_CURSOR; - get_iter_from_gesture (text_view, priv->multipress_gesture, + get_iter_from_gesture (text_view, GTK_GESTURE (gesture), &iter, NULL, NULL); if (gtk_text_buffer_get_selection_bounds (get_buffer (text_view), @@ -5208,7 +5208,7 @@ gtk_text_view_multipress_gesture_pressed (GtkGestureMultiPress *gesture, } gtk_text_view_end_selection_drag (text_view); - get_iter_from_gesture (text_view, priv->multipress_gesture, + get_iter_from_gesture (text_view, GTK_GESTURE (gesture), &iter, NULL, NULL); gtk_text_view_start_selection_drag (text_view, &iter, n_press == 2 ? SELECT_WORDS : SELECT_LINES, diff --git a/gtk/gtktoolbar.c b/gtk/gtktoolbar.c index b75a1c9e6b..ccb6f405d1 100644 --- a/gtk/gtktoolbar.c +++ b/gtk/gtktoolbar.c @@ -130,8 +130,6 @@ struct _GtkToolbarPrivate GTimer *timer; - GtkGesture *click_gesture; - gulong settings_connection; gint idle_id; @@ -559,6 +557,7 @@ gtk_toolbar_init (GtkToolbar *toolbar) { GtkToolbarPrivate *priv; GtkWidget *widget; + GtkGesture *gesture; widget = GTK_WIDGET (toolbar); toolbar->priv = gtk_toolbar_get_instance_private (toolbar); @@ -596,11 +595,12 @@ gtk_toolbar_init (GtkToolbar *toolbar) priv->timer = g_timer_new (); - priv->click_gesture = gtk_gesture_multi_press_new (GTK_WIDGET (toolbar)); - gtk_gesture_single_set_touch_only (GTK_GESTURE_SINGLE (priv->click_gesture), FALSE); - gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (priv->click_gesture), 0); - gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (priv->click_gesture), GTK_PHASE_BUBBLE); - g_signal_connect (priv->click_gesture, "pressed", G_CALLBACK (gtk_toolbar_pressed_cb), toolbar); + gesture = gtk_gesture_multi_press_new (); + gtk_gesture_single_set_touch_only (GTK_GESTURE_SINGLE (gesture), FALSE); + gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (gesture), 0); + gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (gesture), GTK_PHASE_BUBBLE); + g_signal_connect (gesture, "pressed", G_CALLBACK (gtk_toolbar_pressed_cb), toolbar); + gtk_widget_add_controller (GTK_WIDGET (toolbar), GTK_EVENT_CONTROLLER (gesture)); } static void @@ -2669,8 +2669,6 @@ gtk_toolbar_finalize (GObject *object) if (priv->idle_id) g_source_remove (priv->idle_id); - g_clear_object (&priv->click_gesture); - G_OBJECT_CLASS (gtk_toolbar_parent_class)->finalize (object); } diff --git a/gtk/gtktreeview.c b/gtk/gtktreeview.c index 3b0795b1cd..6e928d2a79 100644 --- a/gtk/gtktreeview.c +++ b/gtk/gtktreeview.c @@ -459,7 +459,6 @@ struct _GtkTreeViewPrivate /* Gestures */ GtkGesture *multipress_gesture; - GtkGesture *column_multipress_gesture; GtkGesture *drag_gesture; /* Rubberbanding, row DnD */ GtkGesture *column_drag_gesture; /* Column reordering, resizing */ GtkEventController *motion_controller; @@ -1648,6 +1647,7 @@ gtk_tree_view_init (GtkTreeView *tree_view) { GtkTreeViewPrivate *priv; GtkCssNode *widget_node; + GtkGesture *gesture; priv = tree_view->priv = gtk_tree_view_get_instance_private (tree_view); @@ -1715,18 +1715,20 @@ gtk_tree_view_init (GtkTreeView *tree_view) gtk_css_node_set_state (priv->header_node, gtk_css_node_get_state (widget_node)); g_object_unref (priv->header_node); - priv->multipress_gesture = gtk_gesture_multi_press_new (GTK_WIDGET (tree_view)); + priv->multipress_gesture = gtk_gesture_multi_press_new (); gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (priv->multipress_gesture), 0); g_signal_connect (priv->multipress_gesture, "pressed", G_CALLBACK (gtk_tree_view_multipress_gesture_pressed), tree_view); g_signal_connect (priv->multipress_gesture, "released", G_CALLBACK (gtk_tree_view_multipress_gesture_released), tree_view); + gtk_widget_add_controller (GTK_WIDGET (tree_view), GTK_EVENT_CONTROLLER (priv->multipress_gesture)); - priv->column_multipress_gesture = gtk_gesture_multi_press_new (GTK_WIDGET (tree_view)); - g_signal_connect (priv->column_multipress_gesture, "pressed", + gesture = gtk_gesture_multi_press_new (); + g_signal_connect (gesture, "pressed", G_CALLBACK (gtk_tree_view_column_multipress_gesture_pressed), tree_view); - gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (priv->column_multipress_gesture), + gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (gesture), GTK_PHASE_CAPTURE); + gtk_widget_add_controller (GTK_WIDGET (tree_view), GTK_EVENT_CONTROLLER (gesture)); priv->drag_gesture = gtk_gesture_drag_new (GTK_WIDGET (tree_view)); g_signal_connect (priv->drag_gesture, "drag-begin", @@ -2136,9 +2138,7 @@ gtk_tree_view_destroy (GtkWidget *widget) tree_view->priv->vadjustment = NULL; } - g_clear_object (&tree_view->priv->multipress_gesture); g_clear_object (&tree_view->priv->drag_gesture); - g_clear_object (&tree_view->priv->column_multipress_gesture); g_clear_object (&tree_view->priv->column_drag_gesture); g_clear_object (&tree_view->priv->motion_controller); @@ -10518,11 +10518,10 @@ gtk_tree_view_ensure_interactive_directory (GtkTreeView *tree_view) g_signal_connect (tree_view->priv->search_window, "key-press-event", G_CALLBACK (gtk_tree_view_search_key_press_event), tree_view); - gesture = gtk_gesture_multi_press_new (tree_view->priv->search_window); - g_object_set_data_full (G_OBJECT (tree_view->priv->search_window), "gesture", - gesture, g_object_unref); + gesture = gtk_gesture_multi_press_new (); g_signal_connect (gesture, "pressed", G_CALLBACK (gtk_tree_view_search_pressed_cb), tree_view); + gtk_widget_add_controller (tree_view->priv->search_window, GTK_EVENT_CONTROLLER (gesture)); controller = gtk_event_controller_scroll_new (tree_view->priv->search_window, GTK_EVENT_CONTROLLER_SCROLL_VERTICAL); diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c index 0b090e323c..2e39cb0e2b 100644 --- a/gtk/gtkwindow.c +++ b/gtk/gtkwindow.c @@ -1963,12 +1963,13 @@ gtk_window_constructed (GObject *object) if (priv->type == GTK_WINDOW_TOPLEVEL) { - priv->multipress_gesture = gtk_gesture_multi_press_new (GTK_WIDGET (object)); + priv->multipress_gesture = gtk_gesture_multi_press_new (); gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (priv->multipress_gesture), 0); gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (priv->multipress_gesture), GTK_PHASE_NONE); g_signal_connect (priv->multipress_gesture, "pressed", G_CALLBACK (multipress_gesture_pressed_cb), object); + gtk_widget_add_controller (GTK_WIDGET (object), GTK_EVENT_CONTROLLER (priv->multipress_gesture)); priv->drag_gesture = gtk_gesture_drag_new (GTK_WIDGET (object)); gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (priv->drag_gesture), @@ -5952,9 +5953,6 @@ gtk_window_finalize (GObject *object) priv->mnemonics_display_timeout_id = 0; } - if (priv->multipress_gesture) - g_object_unref (priv->multipress_gesture); - if (priv->drag_gesture) g_object_unref (priv->drag_gesture); diff --git a/tests/testentryicons.c b/tests/testentryicons.c index 48e6df2c5c..3ef25e7e92 100644 --- a/tests/testentryicons.c +++ b/tests/testentryicons.c @@ -321,8 +321,9 @@ main (int argc, char **argv) gtk_widget_set_tooltip_text (image, "Click me"); GtkGesture *gesture; - gesture = gtk_gesture_multi_press_new (image); + gesture = gtk_gesture_multi_press_new (); g_signal_connect (gesture, "pressed", G_CALLBACK (icon_pressed_cb), NULL); + gtk_widget_add_controller (image, GTK_EVENT_CONTROLLER (gesture)); gtk_container_add (GTK_CONTAINER (box), image); image = gtk_image_new_from_icon_name ("document-save-symbolic"); g_object_set (image, "margin", 6, NULL); diff --git a/tests/testgtk.c b/tests/testgtk.c index 7e5d683746..37e58a2483 100644 --- a/tests/testgtk.c +++ b/tests/testgtk.c @@ -3796,10 +3796,10 @@ create_cursors (GtkWidget *widget) gtk_drawing_area_set_content_height (GTK_DRAWING_AREA (darea), 80); gtk_drawing_area_set_draw_func (GTK_DRAWING_AREA (darea), cursor_draw, NULL, NULL); gtk_container_add (GTK_CONTAINER (frame), darea); - gesture = gtk_gesture_multi_press_new (darea); + gesture = gtk_gesture_multi_press_new (); gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (gesture), 0); g_signal_connect (gesture, "pressed", G_CALLBACK (cursor_pressed_cb), entry); - g_object_set_data_full (G_OBJECT (darea), "gesture", gesture, g_object_unref); + gtk_widget_add_controller (darea, GTK_EVENT_CONTROLLER (gesture)); gtk_widget_show (darea); g_signal_connect (entry, "changed", diff --git a/tests/testtreeedit.c b/tests/testtreeedit.c index ad41714019..784ee41a1a 100644 --- a/tests/testtreeedit.c +++ b/tests/testtreeedit.c @@ -249,9 +249,9 @@ main (gint argc, gchar **argv) tree_model = create_model (); tree_view = gtk_tree_view_new_with_model (tree_model); - gesture = gtk_gesture_multi_press_new (tree_view); + gesture = gtk_gesture_multi_press_new (); g_signal_connect (gesture, "pressed", G_CALLBACK (pressed_cb), tree_view); - g_object_set_data_full (G_OBJECT (tree_view), "gesture", gesture, g_object_unref); + gtk_widget_add_controller (tree_view, GTK_EVENT_CONTROLLER (gesture)); gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (tree_view), TRUE); column = gtk_tree_view_column_new (); diff --git a/testsuite/gtk/gestures.c b/testsuite/gtk/gestures.c index afe7cd3679..3f0f806636 100644 --- a/testsuite/gtk/gestures.c +++ b/testsuite/gtk/gestures.c @@ -331,10 +331,11 @@ add_gesture (GtkWidget *w, const gchar *name, GtkPropagationPhase phase, GString data->str = str; data->state = state; - g = gtk_gesture_multi_press_new (w); + g = gtk_gesture_multi_press_new (); gtk_gesture_single_set_touch_only (GTK_GESTURE_SINGLE (g), FALSE); gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (g), 1); gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (g), phase); + gtk_widget_add_controller (w, GTK_EVENT_CONTROLLER (g)); g_object_set_data (G_OBJECT (g), "name", (gpointer)name);