diff options
-rw-r--r-- | demos/gtk-demo/gestures.c | 8 | ||||
-rw-r--r-- | docs/reference/gtk/gtk3-sections.txt | 11 | ||||
-rw-r--r-- | gtk/gtkbutton.c | 4 | ||||
-rw-r--r-- | gtk/gtkcolorplane.c | 4 | ||||
-rw-r--r-- | gtk/gtkcolorscale.c | 6 | ||||
-rw-r--r-- | gtk/gtkcolorswatch.c | 12 | ||||
-rw-r--r-- | gtk/gtkdnd.c | 7 | ||||
-rw-r--r-- | gtk/gtkeventcontroller.c | 83 | ||||
-rw-r--r-- | gtk/gtkeventcontroller.h | 8 | ||||
-rw-r--r-- | gtk/gtkgesture.c | 49 | ||||
-rw-r--r-- | gtk/gtkgesture.h | 6 | ||||
-rw-r--r-- | gtk/gtkrange.c | 8 | ||||
-rw-r--r-- | gtk/gtkscrolledwindow.c | 24 | ||||
-rw-r--r-- | gtk/gtkspinbutton.c | 16 | ||||
-rw-r--r-- | gtk/gtktreeview.c | 6 | ||||
-rw-r--r-- | gtk/gtkwidget.c | 88 | ||||
-rw-r--r-- | gtk/gtkwidget.h | 8 | ||||
-rw-r--r-- | gtk/gtkwidgetprivate.h | 6 | ||||
-rw-r--r-- | gtk/gtkwindow.c | 9 |
19 files changed, 119 insertions, 244 deletions
diff --git a/demos/gtk-demo/gestures.c b/demos/gtk-demo/gestures.c index 387e357b6c..dd27cdb4a6 100644 --- a/demos/gtk-demo/gestures.c +++ b/demos/gtk-demo/gestures.c @@ -156,7 +156,7 @@ do_gestures (GtkWidget *do_widget) gesture = gtk_gesture_swipe_new (drawing_area); g_signal_connect (gesture, "swipe", G_CALLBACK (swipe_gesture_swept), drawing_area); - gtk_widget_add_controller (drawing_area, GTK_EVENT_CONTROLLER (gesture)); + gtk_gesture_attach (gesture, GTK_PHASE_BUBBLE); g_object_unref (gesture); /* Long press */ @@ -165,21 +165,21 @@ do_gestures (GtkWidget *do_widget) G_CALLBACK (long_press_gesture_pressed), drawing_area); g_signal_connect (gesture, "end", G_CALLBACK (long_press_gesture_end), drawing_area); - gtk_widget_add_controller (drawing_area, GTK_EVENT_CONTROLLER (gesture)); + gtk_gesture_attach (gesture, GTK_PHASE_BUBBLE); g_object_unref (gesture); /* Rotate */ rotate = gesture = gtk_gesture_rotate_new (drawing_area); g_signal_connect (gesture, "angle-changed", G_CALLBACK (rotation_angle_changed), drawing_area); - gtk_widget_add_controller (drawing_area, GTK_EVENT_CONTROLLER (gesture)); + gtk_gesture_attach (gesture, GTK_PHASE_BUBBLE); g_object_unref (gesture); /* Zoom */ zoom = gesture = gtk_gesture_zoom_new (drawing_area); g_signal_connect (gesture, "scale-changed", G_CALLBACK (zoom_scale_changed), drawing_area); - gtk_widget_add_controller (drawing_area, GTK_EVENT_CONTROLLER (gesture)); + gtk_gesture_attach (gesture, GTK_PHASE_BUBBLE); g_object_unref (gesture); } diff --git a/docs/reference/gtk/gtk3-sections.txt b/docs/reference/gtk/gtk3-sections.txt index fb9a599a3e..51729188d9 100644 --- a/docs/reference/gtk/gtk3-sections.txt +++ b/docs/reference/gtk/gtk3-sections.txt @@ -5583,11 +5583,6 @@ gtk_widget_class_bind_template_callback gtk_widget_class_bind_template_callback_full gtk_widget_class_set_connect_func -<SUBSECTION Gestures> -gtk_widget_add_controller -gtk_widget_remove_controller -gtk_widget_list_controllers - <SUBSECTION Standard> GTK_WIDGET GTK_IS_WIDGET @@ -7902,9 +7897,6 @@ gtk_popover_get_modal <TITLE>GtkEventController</TITLE> GtkEventController gtk_event_controller_handle_event -GtkPropagationPhase -gtk_event_controller_get_propagation_phase -gtk_event_controller_set_propagation_phase gtk_event_controller_get_event_mask gtk_event_controller_set_event_mask gtk_event_controller_get_widget @@ -7939,6 +7931,9 @@ gtk_gesture_set_state gtk_gesture_cancel_sequence gtk_gesture_get_sequences gtk_gesture_handles_sequence +GtkPropagationPhase +gtk_gesture_attach +gtk_gesture_detach <SUBSECTION> gtk_gesture_get_last_updated_sequence diff --git a/gtk/gtkbutton.c b/gtk/gtkbutton.c index 41db02427a..f355372769 100644 --- a/gtk/gtkbutton.c +++ b/gtk/gtkbutton.c @@ -648,7 +648,7 @@ gtk_button_init (GtkButton *button) gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (priv->gesture), GDK_BUTTON_PRIMARY); g_signal_connect (priv->gesture, "begin", G_CALLBACK (gesture_begin_cb), button); g_signal_connect (priv->gesture, "end", G_CALLBACK (gesture_end_cb), button); - gtk_widget_add_controller (GTK_WIDGET (button), GTK_EVENT_CONTROLLER (priv->gesture)); + gtk_gesture_attach (priv->gesture, GTK_PHASE_BUBBLE); } static void @@ -665,7 +665,7 @@ gtk_button_destroy (GtkWidget *widget) if (priv->gesture) { - gtk_widget_remove_controller (widget, GTK_EVENT_CONTROLLER (priv->gesture)); + gtk_gesture_detach (priv->gesture); g_object_unref (priv->gesture); priv->gesture = NULL; } diff --git a/gtk/gtkcolorplane.c b/gtk/gtkcolorplane.c index 9a81af1df0..26467e9b87 100644 --- a/gtk/gtkcolorplane.c +++ b/gtk/gtkcolorplane.c @@ -427,7 +427,7 @@ gtk_color_plane_init (GtkColorPlane *plane) plane->priv->long_press_gesture = gtk_gesture_long_press_new (GTK_WIDGET (plane)); g_signal_connect (plane->priv->long_press_gesture, "pressed", G_CALLBACK (hold_action), plane); - gtk_widget_add_controller (GTK_WIDGET (plane), GTK_EVENT_CONTROLLER (plane->priv->long_press_gesture)); + gtk_gesture_attach (plane->priv->long_press_gesture, GTK_PHASE_BUBBLE); } static void @@ -442,7 +442,7 @@ plane_finalize (GObject *object) g_clear_object (&plane->priv->s_adj); g_clear_object (&plane->priv->v_adj); - gtk_widget_remove_controller (GTK_WIDGET (object), GTK_EVENT_CONTROLLER (plane->priv->long_press_gesture)); + gtk_gesture_detach (plane->priv->long_press_gesture); g_clear_object (&plane->priv->long_press_gesture); G_OBJECT_CLASS (gtk_color_plane_parent_class)->finalize (object); diff --git a/gtk/gtkcolorscale.c b/gtk/gtkcolorscale.c index 7622bd1d28..0331b04318 100644 --- a/gtk/gtkcolorscale.c +++ b/gtk/gtkcolorscale.c @@ -258,8 +258,7 @@ gtk_color_scale_init (GtkColorScale *scale) scale->priv->long_press_gesture = gtk_gesture_long_press_new (GTK_WIDGET (scale)); g_signal_connect (scale->priv->long_press_gesture, "pressed", G_CALLBACK (hold_action), scale); - gtk_widget_add_controller (GTK_WIDGET (scale), - GTK_EVENT_CONTROLLER (scale->priv->long_press_gesture)); + gtk_gesture_attach (scale->priv->long_press_gesture, GTK_PHASE_BUBBLE); } static void @@ -270,8 +269,7 @@ scale_finalize (GObject *object) if (scale->priv->surface) cairo_surface_destroy (scale->priv->surface); - gtk_widget_remove_controller (GTK_WIDGET (object), - GTK_EVENT_CONTROLLER (scale->priv->long_press_gesture)); + gtk_gesture_detach (scale->priv->long_press_gesture); g_clear_object (&scale->priv->long_press_gesture); G_OBJECT_CLASS (gtk_color_scale_parent_class)->finalize (object); diff --git a/gtk/gtkcolorswatch.c b/gtk/gtkcolorswatch.c index ed61f85dfe..23c167c2b1 100644 --- a/gtk/gtkcolorswatch.c +++ b/gtk/gtkcolorswatch.c @@ -90,14 +90,12 @@ gtk_color_swatch_init (GtkColorSwatch *swatch) swatch->priv->long_press_gesture = gtk_gesture_long_press_new (GTK_WIDGET (swatch)); g_signal_connect (swatch->priv->long_press_gesture, "pressed", G_CALLBACK (hold_action), swatch); - gtk_widget_add_controller (GTK_WIDGET (swatch), - GTK_EVENT_CONTROLLER (swatch->priv->long_press_gesture)); + gtk_gesture_attach (swatch->priv->long_press_gesture, GTK_PHASE_BUBBLE); swatch->priv->multipress_gesture = gtk_gesture_multi_press_new (GTK_WIDGET (swatch)); g_signal_connect (swatch->priv->multipress_gesture, "pressed", G_CALLBACK (tap_action), swatch); - gtk_widget_add_controller (GTK_WIDGET (swatch), - GTK_EVENT_CONTROLLER (swatch->priv->multipress_gesture)); + gtk_gesture_attach (swatch->priv->multipress_gesture, GTK_PHASE_BUBBLE); } #define INTENSITY(r, g, b) ((r) * 0.30 + (g) * 0.59 + (b) * 0.11) @@ -721,12 +719,10 @@ swatch_finalize (GObject *object) g_free (swatch->priv->icon); - gtk_widget_remove_controller (GTK_WIDGET (object), - GTK_EVENT_CONTROLLER (swatch->priv->long_press_gesture)); + gtk_gesture_detach (swatch->priv->long_press_gesture); g_object_unref (swatch->priv->long_press_gesture); - gtk_widget_remove_controller (GTK_WIDGET (object), - GTK_EVENT_CONTROLLER (swatch->priv->multipress_gesture)); + gtk_gesture_detach (swatch->priv->multipress_gesture); g_object_unref (swatch->priv->multipress_gesture); G_OBJECT_CLASS (gtk_color_swatch_parent_class)->finalize (object); diff --git a/gtk/gtkdnd.c b/gtk/gtkdnd.c index a375e219f2..f9452eda96 100644 --- a/gtk/gtkdnd.c +++ b/gtk/gtkdnd.c @@ -2801,9 +2801,7 @@ gtk_drag_source_set (GtkWidget *widget, site->drag_gesture = gtk_gesture_drag_new (widget); gtk_gesture_single_set_touch_only (GTK_GESTURE_SINGLE (site->drag_gesture), FALSE); - gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (site->drag_gesture), - GTK_PHASE_NONE); - gtk_widget_add_controller (widget, GTK_EVENT_CONTROLLER (site->drag_gesture)); + gtk_gesture_attach (site->drag_gesture, GTK_PHASE_NONE); g_signal_connect (widget, "button-press-event", G_CALLBACK (gtk_drag_source_event_cb), @@ -2846,8 +2844,7 @@ gtk_drag_source_unset (GtkWidget *widget) g_signal_handlers_disconnect_by_func (widget, gtk_drag_source_event_cb, site); - gtk_widget_remove_controller (widget, - GTK_EVENT_CONTROLLER (site->drag_gesture)); + gtk_gesture_detach (site->drag_gesture); g_object_set_data (G_OBJECT (widget), I_("gtk-site-data"), NULL); } } diff --git a/gtk/gtkeventcontroller.c b/gtk/gtkeventcontroller.c index a3dd64967b..a505512bce 100644 --- a/gtk/gtkeventcontroller.c +++ b/gtk/gtkeventcontroller.c @@ -27,15 +27,6 @@ * #GtkEventController is a base, low-level implementation for event * controllers. Those react to a series of #GdkEvents, and possibly trigger * actions as a consequence of those. - * - * Most usually, event controllers are attached to a widget through - * gtk_widget_add_controller(). This ensures events received by the - * widget are delivered to the controller. On special situations, - * manual delivery may be desired, this can be achieved by setting - * the capture phase to %GTK_PHASE_NONE and feeding events manually - * through gtk_event_controller_handle_event(). See - * gtk_event_controller_set_propagation_phase() and #GtkPropagationPhase - * to know more about how events are delivered to event controllers. */ #include "config.h" @@ -50,8 +41,7 @@ typedef struct _GtkEventControllerPrivate GtkEventControllerPrivate; enum { PROP_WIDGET = 1, - PROP_EVENT_MASK, - PROP_PROPAGATION_PHASE + PROP_EVENT_MASK }; enum { @@ -64,7 +54,6 @@ struct _GtkEventControllerPrivate { GtkWidget *widget; guint evmask; - guint propagation_phase : 2; }; guint signals[N_SIGNALS] = { 0 }; @@ -165,22 +154,6 @@ gtk_event_controller_class_init (GtkEventControllerClass *klass) GDK_TYPE_EVENT_MASK, 0, GTK_PARAM_READWRITE)); /** - * GtkEventController:propagation-phase: - * - * Specifies the stage in event propagation at which events are handled by the - * controller. Note that this requires a controller to be attached through - * gtk_widget_add_controller(). - * - * Since: 3.14 - */ - g_object_class_install_property (object_class, - PROP_PROPAGATION_PHASE, - g_param_spec_enum ("propagation-phase", - P_("Propagation phase"), - P_("Phase in event propagation where this controller handles events"), - GTK_TYPE_PROPAGATION_PHASE, GTK_PHASE_BUBBLE, - GTK_PARAM_READWRITE)); - /** * GtkEventController::handle-event: * @controller: the object which receives the signal * @event: the event to handle @@ -221,10 +194,6 @@ gtk_event_controller_class_init (GtkEventControllerClass *klass) static void gtk_event_controller_init (GtkEventController *controller) { - GtkEventControllerPrivate *priv; - - priv = gtk_event_controller_get_instance_private (controller); - priv->propagation_phase = GTK_PHASE_BUBBLE; } /** @@ -343,53 +312,3 @@ gtk_event_controller_reset (GtkEventController *controller) g_signal_emit (controller, signals[RESET], 0); } - -/** - * gtk_event_controller_get_propagation_phase: - * @controller: a #GtkEventController - * - * Gets the propagation phase at which this @controller is run. - * - * Returns: The propagation phase - * - * Since: 3.14 - **/ -GtkPropagationPhase -gtk_event_controller_get_propagation_phase (GtkEventController *controller) -{ - GtkEventControllerPrivate *priv; - - g_return_val_if_fail (GTK_IS_EVENT_CONTROLLER (controller), GTK_PHASE_NONE); - - priv = gtk_event_controller_get_instance_private (controller); - - return priv->propagation_phase; -} - -/** - * gtk_event_controller_set_propagation_phase: - * @controller: a #GtkEventController - * @phase: the propagation phase - * - * Sets the propagation phase at which this @controller is run. Note that - * event controllers are run before the regular #GtkWidget::event handler. - * - * Since: 3.14 - **/ -void -gtk_event_controller_set_propagation_phase (GtkEventController *controller, - GtkPropagationPhase phase) -{ - GtkEventControllerPrivate *priv; - - g_return_if_fail (GTK_IS_EVENT_CONTROLLER (controller)); - g_return_if_fail (phase >= GTK_PHASE_NONE && phase <= GTK_PHASE_CAPTURE); - - priv = gtk_event_controller_get_instance_private (controller); - - if (priv->propagation_phase == phase) - return; - - priv->propagation_phase = phase; - g_object_notify (G_OBJECT (controller), "propagation-phase"); -} diff --git a/gtk/gtkeventcontroller.h b/gtk/gtkeventcontroller.h index db1fa57ca5..9bf0531911 100644 --- a/gtk/gtkeventcontroller.h +++ b/gtk/gtkeventcontroller.h @@ -59,14 +59,6 @@ gboolean gtk_event_controller_handle_event (GtkEventController *controller GDK_AVAILABLE_IN_3_14 void gtk_event_controller_reset (GtkEventController *controller); -GDK_AVAILABLE_IN_3_14 -GtkPropagationPhase - gtk_event_controller_get_propagation_phase (GtkEventController *controller); - -GDK_AVAILABLE_IN_3_14 -void gtk_event_controller_set_propagation_phase (GtkEventController *controller, - GtkPropagationPhase phase); - G_END_DECLS #endif /* __GTK_EVENT_CONTROLLER_H__ */ diff --git a/gtk/gtkgesture.c b/gtk/gtkgesture.c index fd72f20161..28a07c6206 100644 --- a/gtk/gtkgesture.c +++ b/gtk/gtkgesture.c @@ -88,6 +88,7 @@ #include "config.h" #include "gtkgesture.h" +#include "gtkwidgetprivate.h" #include "gtkgestureprivate.h" #include "gtktypebuiltins.h" #include "gtkprivate.h" @@ -1557,3 +1558,51 @@ _gtk_gesture_get_pointer_emulating_sequence (GtkGesture *gesture, return FALSE; } + +/** + * gtk_gesture_attach: + * @gesture: a #GtkGesture + * @phase: phase at which events are handled + * + * Attaches @gesture to its widget, so @gesture is able to receive + * and manage the events that are emitted on the #GtkWidget. This call + * will also make sure that the gesture state is maintained properly + * whenever input is grabbed elsewhere. + * + * If @phase is %GTK_PHASE_NONE, no automatical event handling will be + * performed, but other additional gesture maintenance will. The events + * can be managed by calling gtk_event_controller_handle_event(). + * + * Since: 3.14 + **/ +void +gtk_gesture_attach (GtkGesture *gesture, + GtkPropagationPhase phase) +{ + GtkWidget *widget; + + g_return_if_fail (GTK_IS_GESTURE (gesture)); + g_return_if_fail (phase >= GTK_PHASE_NONE && phase <= GTK_PHASE_BUBBLE); + + widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture)); + _gtk_widget_add_controller (widget, GTK_EVENT_CONTROLLER (gesture), phase); +} + +/** + * gtk_gesture_detach: + * @gesture: a #GtkGesture + * + * Detaches @gesture from its widget. + * + * Since: 3.14 + **/ +void +gtk_gesture_detach (GtkGesture *gesture) +{ + GtkWidget *widget; + + g_return_if_fail (GTK_IS_GESTURE (gesture)); + + widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture)); + _gtk_widget_remove_controller (widget, GTK_EVENT_CONTROLLER (gesture)); +} diff --git a/gtk/gtkgesture.h b/gtk/gtkgesture.h index a478a45826..c90b8f1f1a 100644 --- a/gtk/gtkgesture.h +++ b/gtk/gtkgesture.h @@ -120,6 +120,12 @@ GDK_AVAILABLE_IN_3_14 gboolean gtk_gesture_is_grouped_with (GtkGesture *gesture, GtkGesture *other); +GDK_AVAILABLE_IN_3_14 +void gtk_gesture_attach (GtkGesture *gesture, + GtkPropagationPhase phase); +GDK_AVAILABLE_IN_3_14 +void gtk_gesture_detach (GtkGesture *gesture); + G_END_DECLS #endif /* __GTK_GESTURE_H__ */ diff --git a/gtk/gtkrange.c b/gtk/gtkrange.c index 5961a39f40..b8ab861d8c 100644 --- a/gtk/gtkrange.c +++ b/gtk/gtkrange.c @@ -1507,7 +1507,7 @@ gtk_range_destroy (GtkWidget *widget) if (priv->long_press_gesture) { - gtk_widget_remove_controller (widget, GTK_EVENT_CONTROLLER (priv->long_press_gesture)); + gtk_gesture_detach (priv->long_press_gesture); g_clear_object (&priv->long_press_gesture); } @@ -2369,8 +2369,7 @@ update_zoom_set (GtkRange *range, { if (zoom_set) { - gtk_widget_remove_controller (GTK_WIDGET (range), - GTK_EVENT_CONTROLLER (range->priv->long_press_gesture)); + gtk_gesture_detach (range->priv->long_press_gesture); g_clear_object (&range->priv->long_press_gesture); } @@ -2712,8 +2711,7 @@ gtk_range_button_press (GtkWidget *widget, gtk_gesture_single_set_touch_only (GTK_GESTURE_SINGLE (priv->long_press_gesture), FALSE); gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (priv->long_press_gesture), 1); - gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (priv->long_press_gesture), - GTK_PHASE_NONE); + gtk_gesture_attach (priv->long_press_gesture, GTK_PHASE_NONE); g_signal_connect (priv->long_press_gesture, "pressed", G_CALLBACK (hold_action), range); diff --git a/gtk/gtkscrolledwindow.c b/gtk/gtkscrolledwindow.c index 01d5f52619..65061d4ffc 100644 --- a/gtk/gtkscrolledwindow.c +++ b/gtk/gtkscrolledwindow.c @@ -745,8 +745,6 @@ gtk_scrolled_window_init (GtkScrolledWindow *scrolled_window) priv->drag_gesture = gtk_gesture_drag_new (widget); gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (priv->drag_gesture), 1); - gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (priv->drag_gesture), - GTK_PHASE_CAPTURE); g_signal_connect_swapped (priv->drag_gesture, "drag-begin", G_CALLBACK (scrolled_window_drag_begin_cb), scrolled_window); @@ -760,16 +758,12 @@ gtk_scrolled_window_init (GtkScrolledWindow *scrolled_window) priv->swipe_gesture = gtk_gesture_swipe_new (widget); gtk_gesture_group (priv->swipe_gesture, priv->drag_gesture); gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (priv->swipe_gesture), 1); - gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (priv->swipe_gesture), - GTK_PHASE_CAPTURE); g_signal_connect_swapped (priv->swipe_gesture, "swipe", G_CALLBACK (scrolled_window_swipe_cb), scrolled_window); priv->long_press_gesture = gtk_gesture_long_press_new (widget); gtk_gesture_group (priv->long_press_gesture, priv->drag_gesture); gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (priv->long_press_gesture), 1); - gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (priv->long_press_gesture), - GTK_PHASE_CAPTURE); g_signal_connect_swapped (priv->long_press_gesture, "pressed", G_CALLBACK (scrolled_window_long_press_cb), scrolled_window); @@ -1253,21 +1247,15 @@ gtk_scrolled_window_set_kinetic_scrolling (GtkScrolledWindow *scrolled_window, if (priv->kinetic_scrolling) { - gtk_widget_add_controller (GTK_WIDGET (scrolled_window), - GTK_EVENT_CONTROLLER (priv->drag_gesture)); - gtk_widget_add_controller (GTK_WIDGET (scrolled_window), - GTK_EVENT_CONTROLLER (priv->swipe_gesture)); - gtk_widget_add_controller (GTK_WIDGET (scrolled_window), - GTK_EVENT_CONTROLLER (priv->long_press_gesture)); + gtk_gesture_attach (priv->drag_gesture, GTK_PHASE_CAPTURE); + gtk_gesture_attach (priv->swipe_gesture, GTK_PHASE_CAPTURE); + gtk_gesture_attach (priv->long_press_gesture, GTK_PHASE_CAPTURE); } else { - gtk_widget_remove_controller (GTK_WIDGET (scrolled_window), - GTK_EVENT_CONTROLLER (priv->drag_gesture)); - gtk_widget_remove_controller (GTK_WIDGET (scrolled_window), - GTK_EVENT_CONTROLLER (priv->swipe_gesture)); - gtk_widget_remove_controller (GTK_WIDGET (scrolled_window), - GTK_EVENT_CONTROLLER (priv->long_press_gesture)); + gtk_gesture_detach (priv->drag_gesture); + gtk_gesture_detach (priv->swipe_gesture); + gtk_gesture_detach (priv->long_press_gesture); gtk_scrolled_window_cancel_deceleration (scrolled_window); } diff --git a/gtk/gtkspinbutton.c b/gtk/gtkspinbutton.c index fb0c40b357..1e3db86436 100644 --- a/gtk/gtkspinbutton.c +++ b/gtk/gtkspinbutton.c @@ -719,20 +719,14 @@ gtk_spin_button_init (GtkSpinButton *spin_button) gtk_widget_add_events (GTK_WIDGET (spin_button), GDK_SCROLL_MASK); priv->long_press_gesture = gtk_gesture_long_press_new (GTK_WIDGET (spin_button)); - gtk_widget_add_controller (GTK_WIDGET (spin_button), - GTK_EVENT_CONTROLLER (priv->long_press_gesture)); - gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (priv->long_press_gesture), - GTK_PHASE_NONE); + gtk_gesture_attach (priv->long_press_gesture, GTK_PHASE_NONE); g_signal_connect (priv->long_press_gesture, "pressed", G_CALLBACK (long_press_action), spin_button); g_signal_connect (priv->long_press_gesture, "cancelled", G_CALLBACK (long_press_cancel_action), spin_button); priv->swipe_gesture = gtk_gesture_swipe_new (GTK_WIDGET (spin_button)); - gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (priv->swipe_gesture), - GTK_PHASE_NONE); - gtk_widget_add_controller (GTK_WIDGET (spin_button), - GTK_EVENT_CONTROLLER (priv->swipe_gesture)); + gtk_gesture_attach (priv->swipe_gesture, GTK_PHASE_NONE); g_signal_connect (priv->swipe_gesture, "update", G_CALLBACK (swipe_gesture_update), spin_button); } @@ -751,12 +745,10 @@ gtk_spin_button_finalize (GObject *object) if (priv->up_panel_context) g_object_unref (priv->up_panel_context); - gtk_widget_remove_controller (GTK_WIDGET (spin_button), - GTK_EVENT_CONTROLLER (priv->long_press_gesture)); + gtk_gesture_detach (priv->long_press_gesture); g_object_unref (priv->long_press_gesture); - gtk_widget_add_controller (GTK_WIDGET (spin_button), - GTK_EVENT_CONTROLLER (priv->swipe_gesture)); + gtk_gesture_detach (priv->swipe_gesture); g_object_unref (priv->swipe_gesture); G_OBJECT_CLASS (gtk_spin_button_parent_class)->finalize (object); diff --git a/gtk/gtktreeview.c b/gtk/gtktreeview.c index 74bedcada0..1d24a5c934 100644 --- a/gtk/gtktreeview.c +++ b/gtk/gtktreeview.c @@ -1841,8 +1841,7 @@ gtk_tree_view_init (GtkTreeView *tree_view) gtk_gesture_single_set_touch_only (GTK_GESTURE_SINGLE (tree_view->priv->multipress_gesture), FALSE); g_signal_connect (tree_view->priv->multipress_gesture, "pressed", G_CALLBACK (_tree_view_multipress_pressed), tree_view); - gtk_widget_add_controller (GTK_WIDGET (tree_view), - GTK_EVENT_CONTROLLER (tree_view->priv->multipress_gesture)); + gtk_gesture_attach (tree_view->priv->multipress_gesture, GTK_PHASE_BUBBLE); } @@ -2209,8 +2208,7 @@ gtk_tree_view_destroy (GtkWidget *widget) if (tree_view->priv->multipress_gesture) { - gtk_widget_remove_controller (GTK_WIDGET (tree_view), - GTK_EVENT_CONTROLLER (tree_view->priv->multipress_gesture)); + gtk_gesture_detach (tree_view->priv->multipress_gesture); g_clear_object (&tree_view->priv->multipress_gesture); } diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c index 6d9c17f7a5..98569ad8d1 100644 --- a/gtk/gtkwidget.c +++ b/gtk/gtkwidget.c @@ -399,6 +399,7 @@ typedef struct { typedef struct { GtkEventController *controller; + GtkPropagationPhase phase; guint evmask_notify_id; guint grab_notify_id; guint sequence_state_changed_id; @@ -4201,7 +4202,6 @@ _gtk_widget_set_sequence_state_internal (GtkWidget *widget, for (l = priv->event_controllers; l; l = l->next) { - GtkPropagationPhase propagation_phase; GtkEventSequenceState gesture_state; gboolean sequence_handled, retval; EventControllerData *data; @@ -4240,7 +4240,6 @@ _gtk_widget_set_sequence_state_internal (GtkWidget *widget, handled |= retval; g_signal_handler_unblock (data->controller, data->sequence_state_changed_id); - propagation_phase = gtk_event_controller_get_propagation_phase (data->controller); /* If the sequence goes denied, check whether this is a controller attached * to the capture phase, that additionally handled the button/touch press (ie. @@ -4248,7 +4247,7 @@ _gtk_widget_set_sequence_state_internal (GtkWidget *widget, * beneath, so the widgets beneath get a coherent stream of events from now on. */ if (retval && sequence_handled && - propagation_phase == GTK_PHASE_CAPTURE && + data->phase == GTK_PHASE_CAPTURE && state == GTK_EVENT_SEQUENCE_DENIED) send_event = TRUE; } @@ -7237,7 +7236,7 @@ _gtk_widget_run_controllers (GtkWidget *widget, { data = l->data; - if (phase == gtk_event_controller_get_propagation_phase (data->controller)) + if (phase == data->phase) handled |= gtk_event_controller_handle_event (data->controller, event); } @@ -11729,7 +11728,7 @@ gtk_widget_dispose (GObject *object) while (priv->event_controllers) { EventControllerData *data = priv->event_controllers->data; - gtk_widget_remove_controller (widget, data->controller); + _gtk_widget_remove_controller (widget, data->controller); } G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object); @@ -16619,7 +16618,6 @@ event_controller_grab_notify (GtkWidget *widget, EventControllerData *data) { GtkWidget *grab_widget, *toplevel; - GtkPropagationPhase phase; GtkWindowGroup *group; GdkDevice *device; @@ -16643,12 +16641,10 @@ event_controller_grab_notify (GtkWidget *widget, if (!grab_widget || grab_widget == widget) return; - phase = gtk_event_controller_get_propagation_phase (data->controller); - - if (((phase == GTK_PHASE_NONE || - phase == GTK_PHASE_BUBBLE) && + if (((data->phase == GTK_PHASE_NONE || + data->phase == GTK_PHASE_BUBBLE) && !gtk_widget_is_ancestor (widget, grab_widget)) || - (phase == GTK_PHASE_CAPTURE && + (data->phase == GTK_PHASE_CAPTURE && !gtk_widget_is_ancestor (widget, grab_widget) && !gtk_widget_is_ancestor (grab_widget, widget))) { @@ -16738,23 +16734,10 @@ _gtk_widget_has_controller (GtkWidget *widget, return NULL; } -/** - * gtk_widget_add_controller: - * @widget: a #GtkWidget, must be the same than the one passed on construction to @controller - * @controller: a #GtkEventController - * - * Adds @controller to the list of controllers that are triggered - * any time @widget receives events. the stage at which the events - * are delivered to @controller is mandated by - * gtk_event_controller_get_propagation_phase(). @widget will also take care - * of calling gtk_event_controller_reset() whenever input is grabbed - * elsewhere. - * - * Since: 3.14 - **/ void -gtk_widget_add_controller (GtkWidget *widget, - GtkEventController *controller) +_gtk_widget_add_controller (GtkWidget *widget, + GtkEventController *controller, + GtkPropagationPhase phase) { EventControllerData *data; GtkWidgetPrivate *priv; @@ -16763,11 +16746,20 @@ gtk_widget_add_controller (GtkWidget *widget, g_return_if_fail (GTK_IS_EVENT_CONTROLLER (controller)); g_return_if_fail (widget == gtk_event_controller_get_widget (controller)); g_return_if_fail (!_gtk_widget_has_controller (widget, controller)); + g_return_if_fail (phase >= GTK_PHASE_NONE && phase <= GTK_PHASE_BUBBLE); priv = widget->priv; + data = _gtk_widget_has_controller (widget, controller); + + if (data) + { + data->phase = phase; + return; + } data = g_new0 (EventControllerData, 1); data->controller = g_object_ref (controller); + data->phase = phase; data->evmask_notify_id = g_signal_connect (controller, "notify::event-mask", G_CALLBACK (event_controller_notify_event_mask), widget); @@ -16787,16 +16779,9 @@ gtk_widget_add_controller (GtkWidget *widget, _gtk_widget_update_evmask (widget); } -/** - * gtk_widget_remove_controller: - * @widget: a #GtkWidget - * @controller: a #GtkEventController attached to @widget - * - * Removes @controller from the list of controllers managed by @widget. - **/ void -gtk_widget_remove_controller (GtkWidget *widget, - GtkEventController *controller) +_gtk_widget_remove_controller (GtkWidget *widget, + GtkEventController *controller) { EventControllerData *data; GtkWidgetPrivate *priv; @@ -16821,34 +16806,3 @@ gtk_widget_remove_controller (GtkWidget *widget, g_object_unref (data->controller); g_free (data); } - -/** - * gtk_widget_list_controllers: - * @widget: a #GtkWidget - * - * Returns the list of controllers that are managed by @widget. - * - * Returns: (transfer container) (element-type GtkEventController): the list of - * controllers, free with g_list_free() - * - * Since: 3.14 - **/ -GList * -gtk_widget_list_controllers (GtkWidget *widget) -{ - EventControllerData *data; - GtkWidgetPrivate *priv; - GList *l, *retval = NULL; - - g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL); - - priv = widget->priv; - - for (l = priv->event_controllers; l; l = l->next) - { - data = l->data; - retval = g_list_prepend (retval, data->controller); - } - - return retval; -} diff --git a/gtk/gtkwidget.h b/gtk/gtkwidget.h index 9a27ee0321..0ef4f866ca 100644 --- a/gtk/gtkwidget.h +++ b/gtk/gtkwidget.h @@ -1469,14 +1469,6 @@ void gtk_widget_class_bind_template_child_full (GtkWidgetClass * const gchar *name, gboolean internal_child, gssize struct_offset); -GDK_AVAILABLE_IN_3_14 -void gtk_widget_add_controller (GtkWidget *widget, - GtkEventController *controller); -GDK_AVAILABLE_IN_3_14 -void gtk_widget_remove_controller (GtkWidget *widget, - GtkEventController *controller); -GDK_AVAILABLE_IN_3_14 -GList * gtk_widget_list_controllers (GtkWidget *widget); G_END_DECLS diff --git a/gtk/gtkwidgetprivate.h b/gtk/gtkwidgetprivate.h index 6e8bb477d4..3708146282 100644 --- a/gtk/gtkwidgetprivate.h +++ b/gtk/gtkwidgetprivate.h @@ -152,6 +152,12 @@ gchar ** _gtk_widget_list_action_prefixes (GtkWidget *widget GActionGroup * _gtk_widget_get_action_group (GtkWidget *widget, const gchar *prefix); +void _gtk_widget_add_controller (GtkWidget *widget, + GtkEventController *controller, + GtkPropagationPhase phase); +void _gtk_widget_remove_controller (GtkWidget *widget, + GtkEventController *controller); + G_END_DECLS #endif /* __GTK_WIDGET_PRIVATE_H__ */ diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c index 1db338d246..0ffa3fe8a9 100644 --- a/gtk/gtkwindow.c +++ b/gtk/gtkwindow.c @@ -1572,15 +1572,12 @@ gtk_window_init (GtkWindow *window) priv->scale = gtk_widget_get_scale_factor (widget); priv->multipress_gesture = gtk_gesture_multi_press_new (GTK_WIDGET (window)); - gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (priv->multipress_gesture), - GTK_PHASE_CAPTURE); gtk_gesture_single_set_touch_only (GTK_GESTURE_SINGLE (priv->multipress_gesture), FALSE); g_signal_connect (priv->multipress_gesture, "pressed", G_CALLBACK (multipress_gesture_pressed_cb), window); g_signal_connect (priv->multipress_gesture, "stopped", G_CALLBACK (multipress_gesture_stopped_cb), window); - gtk_widget_add_controller (GTK_WIDGET (window), - GTK_EVENT_CONTROLLER (priv->multipress_gesture)); + gtk_gesture_attach (priv->multipress_gesture, GTK_PHASE_CAPTURE); } static void @@ -5463,11 +5460,9 @@ gtk_window_finalize (GObject *object) priv->mnemonics_display_timeout_id = 0; } - gtk_widget_remove_controller (GTK_WIDGET (window), - GTK_EVENT_CONTROLLER (priv->multipress_gesture)); + gtk_gesture_detach (priv->multipress_gesture); g_object_unref (priv->multipress_gesture); - G_OBJECT_CLASS (gtk_window_parent_class)->finalize (object); } |