[gtk/scroll-event-propagation: 7/7] eventcontrollerscroll: Conditionally propagate ::scroll
- From: Ernestas Kulik <ernestask src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/scroll-event-propagation: 7/7] eventcontrollerscroll: Conditionally propagate ::scroll
- Date: Wed, 17 Oct 2018 08:35:19 +0000 (UTC)
commit bac6b9d1e40577231dc85a8e0d3baf783ed3fab2
Author: Ernestas Kulik <ernestask gnome org>
Date: Wed Jul 18 16:34:39 2018 +0300
eventcontrollerscroll: Conditionally propagate ::scroll
Currently, gtk_event_controller_scroll_handle_event() always returns
TRUE if it is handled, which stops the propagation of the event. If
there’s a single GtkEventControllerScroll in the widget hierarchy, that
means that no others will run, depending on the propagation phase. In
Nautilus, this can be observed when adding a scroll controller to the
GtkScrolledWindow (ctrl-scrolling controls the zoom level) - either the
scrolling or the zooming breaks.
Fixes https://gitlab.gnome.org/GNOME/gtk/issues/45
gtk/gtkcalendar.c | 12 +++++++-----
gtk/gtkcombobox.c | 8 +++++---
gtk/gtkeventcontrollerscroll.c | 13 ++++++++-----
gtk/gtkmarshalers.list | 1 +
gtk/gtkmenu.c | 6 ++++--
gtk/gtkpathbar.c | 12 +++++++-----
gtk/gtkrange.c | 6 ++++--
gtk/gtkscalebutton.c | 6 ++++--
gtk/gtkscrolledwindow.c | 6 ++++--
gtk/gtkspinbutton.c | 4 +++-
gtk/gtktreeview.c | 6 ++++--
11 files changed, 51 insertions(+), 29 deletions(-)
---
diff --git a/gtk/gtkcalendar.c b/gtk/gtkcalendar.c
index 643b86e5b9..a016e00fef 100644
--- a/gtk/gtkcalendar.c
+++ b/gtk/gtkcalendar.c
@@ -340,10 +340,10 @@ static gint calendar_get_xsep (GtkCalendar *calendar);
static gint calendar_get_ysep (GtkCalendar *calendar);
static gint calendar_get_inner_border (GtkCalendar *calendar);
-static void gtk_calendar_scroll_controller_scroll (GtkEventControllerScroll *scroll,
- gdouble dx,
- gdouble dy,
- GtkWidget *widget);
+static gboolean gtk_calendar_scroll_controller_scroll (GtkEventControllerScroll *scroll,
+ gdouble dx,
+ gdouble dy,
+ GtkWidget *widget);
static char *default_abbreviated_dayname[7];
static char *default_monthname[12];
@@ -2686,7 +2686,7 @@ gtk_calendar_drag_update (GtkGestureDrag *gesture,
gtk_drag_set_icon_default (drag);
}
-static void
+static gboolean
gtk_calendar_scroll_controller_scroll (GtkEventControllerScroll *scroll,
gdouble dx,
gdouble dy,
@@ -2701,6 +2701,8 @@ gtk_calendar_scroll_controller_scroll (GtkEventControllerScroll *scroll,
calendar_set_month_prev (calendar);
else if (dy > 0)
calendar_set_month_next (calendar);
+
+ return GDK_EVENT_STOP;
}
diff --git a/gtk/gtkcombobox.c b/gtk/gtkcombobox.c
index 553b9498ad..0799aff93e 100644
--- a/gtk/gtkcombobox.c
+++ b/gtk/gtkcombobox.c
@@ -249,7 +249,7 @@ static void gtk_combo_box_real_move_active (GtkComboBox *combo_box,
static void gtk_combo_box_real_popup (GtkComboBox *combo_box);
static gboolean gtk_combo_box_real_popdown (GtkComboBox *combo_box);
-static void gtk_combo_box_scroll_controller_scroll (GtkEventControllerScroll *scroll,
+static gboolean gtk_combo_box_scroll_controller_scroll (GtkEventControllerScroll *scroll,
gdouble dx,
gdouble dy,
GtkComboBox *combo_box);
@@ -1801,7 +1801,7 @@ tree_first (GtkComboBox *combo,
return search_data.set;
}
-static void
+static gboolean
gtk_combo_box_scroll_controller_scroll (GtkEventControllerScroll *scroll,
gdouble dx,
gdouble dy,
@@ -1813,7 +1813,7 @@ gtk_combo_box_scroll_controller_scroll (GtkEventControllerScroll *scroll,
GtkTreeIter new_iter;
if (!gtk_combo_box_get_active_iter (combo_box, &iter))
- return;
+ return GDK_EVENT_PROPAGATE;
if (dy < 0)
found = tree_prev (combo_box, priv->model, &iter, &new_iter);
@@ -1823,6 +1823,8 @@ gtk_combo_box_scroll_controller_scroll (GtkEventControllerScroll *scroll,
if (found)
gtk_combo_box_set_active_iter (combo_box, &new_iter);
+ return found;
+
}
/* callbacks */
diff --git a/gtk/gtkeventcontrollerscroll.c b/gtk/gtkeventcontrollerscroll.c
index db5db881d1..cef8257ec0 100644
--- a/gtk/gtkeventcontrollerscroll.c
+++ b/gtk/gtkeventcontrollerscroll.c
@@ -243,6 +243,7 @@ gtk_event_controller_scroll_handle_event (GtkEventController *controller,
GtkEventControllerScroll *scroll = GTK_EVENT_CONTROLLER_SCROLL (controller);
GdkScrollDirection direction = GDK_SCROLL_SMOOTH;
gdouble dx = 0, dy = 0;
+ gboolean handled = TRUE;
if (gdk_event_get_event_type (event) != GDK_SCROLL)
return FALSE;
@@ -324,7 +325,7 @@ gtk_event_controller_scroll_handle_event (GtkEventController *controller,
if (dx != 0 || dy != 0)
{
- g_signal_emit (controller, signals[SCROLL], 0, dx, dy);
+ g_signal_emit (controller, signals[SCROLL], 0, dx, dy, &handled);
if (scroll->flags & GTK_EVENT_CONTROLLER_SCROLL_KINETIC)
scroll_history_push (scroll, dx, dy, gdk_event_get_time (event));
@@ -344,7 +345,7 @@ gtk_event_controller_scroll_handle_event (GtkEventController *controller,
}
}
- return TRUE;
+ return handled;
}
static void
@@ -394,14 +395,16 @@ gtk_event_controller_scroll_class_init (GtkEventControllerScrollClass *klass)
*
* Signals that the widget should scroll by the
* amount specified by @dx and @dy.
+ *
+ * Returns: %TRUE if the scroll event was handled, %FALSE otherwise.
**/
signals[SCROLL] =
g_signal_new (I_("scroll"),
GTK_TYPE_EVENT_CONTROLLER_SCROLL,
- G_SIGNAL_RUN_FIRST,
+ G_SIGNAL_RUN_LAST,
0, NULL, NULL,
- _gtk_marshal_VOID__DOUBLE_DOUBLE,
- G_TYPE_NONE, 2, G_TYPE_DOUBLE, G_TYPE_DOUBLE);
+ _gtk_marshal_BOOLEAN__DOUBLE_DOUBLE,
+ G_TYPE_BOOLEAN, 2, G_TYPE_DOUBLE, G_TYPE_DOUBLE);
/**
* GtkEventControllerScroll::scroll-end:
* @controller: The object that received the signal
diff --git a/gtk/gtkmarshalers.list b/gtk/gtkmarshalers.list
index 322feb18b6..322428e76d 100644
--- a/gtk/gtkmarshalers.list
+++ b/gtk/gtkmarshalers.list
@@ -23,6 +23,7 @@
BOOLEAN:BOXED
BOOLEAN:BOXED,BOXED
+BOOLEAN:DOUBLE,DOUBLE
BOOLEAN:ENUM
BOOLEAN:ENUM,BOOLEAN
BOOLEAN:ENUM,DOUBLE
diff --git a/gtk/gtkmenu.c b/gtk/gtkmenu.c
index 97fb763a3b..b28732f3a0 100644
--- a/gtk/gtkmenu.c
+++ b/gtk/gtkmenu.c
@@ -247,7 +247,7 @@ static void gtk_menu_grab_notify (GtkWidget *widget,
static gboolean gtk_menu_captured_event (GtkWidget *widget,
GdkEvent *event);
-static void gtk_menu_scroll_controller_scroll (GtkEventControllerScroll *scroll,
+static gboolean gtk_menu_scroll_controller_scroll (GtkEventControllerScroll *scroll,
gdouble dx,
gdouble dy,
GtkMenu *menu);
@@ -3062,13 +3062,15 @@ gtk_menu_scroll_timeout (gpointer data)
return TRUE;
}
-static void
+static gboolean
gtk_menu_scroll_controller_scroll (GtkEventControllerScroll *scroll,
gdouble dx,
gdouble dy,
GtkMenu *menu)
{
gtk_menu_scroll_by (menu, dy * MENU_SCROLL_STEP2);
+
+ return GDK_EVENT_STOP;
}
static void
diff --git a/gtk/gtkpathbar.c b/gtk/gtkpathbar.c
index a52ca9920f..5c1f7620d9 100644
--- a/gtk/gtkpathbar.c
+++ b/gtk/gtkpathbar.c
@@ -157,10 +157,10 @@ static void gtk_path_bar_update_button_appearance (GtkPathBar *path_bar,
ButtonData *button_data,
gboolean current_dir);
-static void gtk_path_bar_scroll_controller_scroll (GtkEventControllerScroll *scroll,
- gdouble dx,
- gdouble dy,
- GtkPathBar *path_bar);
+static gboolean gtk_path_bar_scroll_controller_scroll (GtkEventControllerScroll *scroll,
+ gdouble dx,
+ gdouble dy,
+ GtkPathBar *path_bar);
static void
add_cancellable (GtkPathBar *path_bar,
@@ -740,7 +740,7 @@ gtk_path_bar_display_changed (GtkWidget *widget,
gtk_path_bar_check_icon_theme (GTK_PATH_BAR (widget));
}
-static void
+static gboolean
gtk_path_bar_scroll_controller_scroll (GtkEventControllerScroll *scroll,
gdouble dx,
gdouble dy,
@@ -750,6 +750,8 @@ gtk_path_bar_scroll_controller_scroll (GtkEventControllerScroll *scroll,
gtk_path_bar_scroll_down (path_bar);
else if (dy < 0)
gtk_path_bar_scroll_up (path_bar);
+
+ return GDK_EVENT_STOP;
}
static void
diff --git a/gtk/gtkrange.c b/gtk/gtkrange.c
index 009293dd74..2412b26894 100644
--- a/gtk/gtkrange.c
+++ b/gtk/gtkrange.c
@@ -236,7 +236,7 @@ static void gtk_range_allocate_trough (GtkGizmo *gi
static gboolean gtk_range_render_trough (GtkGizmo *gizmo,
GtkSnapshot *snapshot);
-static void gtk_range_scroll_controller_scroll (GtkEventControllerScroll *scroll,
+static gboolean gtk_range_scroll_controller_scroll (GtkEventControllerScroll *scroll,
gdouble dx,
gdouble dy,
GtkRange *range);
@@ -2228,7 +2228,7 @@ stop_scrolling (GtkRange *range)
remove_autoscroll (range);
}
-static void
+static gboolean
gtk_range_scroll_controller_scroll (GtkEventControllerScroll *scroll,
gdouble dx,
gdouble dy,
@@ -2262,6 +2262,8 @@ gtk_range_scroll_controller_scroll (GtkEventControllerScroll *scroll,
g_signal_emit (range, signals[CHANGE_VALUE], 0,
GTK_SCROLL_JUMP, gtk_adjustment_get_value (priv->adjustment) + delta,
&handled);
+
+ return GDK_EVENT_STOP;
}
static void
diff --git a/gtk/gtkscalebutton.c b/gtk/gtkscalebutton.c
index b15404146a..116ccef306 100644
--- a/gtk/gtkscalebutton.c
+++ b/gtk/gtkscalebutton.c
@@ -149,7 +149,7 @@ static void cb_scale_value_changed (GtkRange *range,
static void cb_popup_mapped (GtkWidget *popup,
gpointer user_data);
-static void gtk_scale_button_scroll_controller_scroll (GtkEventControllerScroll *scroll,
+static gboolean gtk_scale_button_scroll_controller_scroll (GtkEventControllerScroll *scroll,
gdouble dx,
gdouble dy,
GtkScaleButton *button);
@@ -765,7 +765,7 @@ gtk_scale_button_set_orientation_private (GtkScaleButton *button,
}
}
-static void
+static gboolean
gtk_scale_button_scroll_controller_scroll (GtkEventControllerScroll *scroll,
gdouble dx,
gdouble dy,
@@ -783,6 +783,8 @@ gtk_scale_button_scroll_controller_scroll (GtkEventControllerScroll *scroll,
gtk_adjustment_get_upper (adjustment));
gtk_scale_button_set_value (button, d);
+
+ return GDK_EVENT_STOP;
}
/*
diff --git a/gtk/gtkscrolledwindow.c b/gtk/gtkscrolledwindow.c
index 68e048c929..8738cafb4f 100644
--- a/gtk/gtkscrolledwindow.c
+++ b/gtk/gtkscrolledwindow.c
@@ -1252,7 +1252,7 @@ scroll_controller_scroll_begin (GtkEventControllerScroll *scroll,
priv->smooth_scroll = TRUE;
}
-static void
+static gboolean
scroll_controller_scroll (GtkEventControllerScroll *scroll,
gdouble delta_x,
gdouble delta_y,
@@ -1263,7 +1263,7 @@ scroll_controller_scroll (GtkEventControllerScroll *scroll,
GdkModifierType state;
if (!gtk_get_current_event_state (&state))
- return;
+ return GDK_EVENT_PROPAGATE;
shifted = (state & GDK_SHIFT_MASK) != 0;
@@ -1322,6 +1322,8 @@ scroll_controller_scroll (GtkEventControllerScroll *scroll,
g_source_set_name_by_id (priv->scroll_events_overshoot_id,
"[gtk+] start_scroll_deceleration_cb");
}
+
+ return GDK_EVENT_STOP;
}
static void
diff --git a/gtk/gtkspinbutton.c b/gtk/gtkspinbutton.c
index 08bc849f38..b891bec711 100644
--- a/gtk/gtkspinbutton.c
+++ b/gtk/gtkspinbutton.c
@@ -689,7 +689,7 @@ swipe_gesture_update (GtkGesture *gesture,
gtk_spin_button_real_spin (spin_button, -vel_y / 20);
}
-static void
+static gboolean
scroll_controller_scroll (GtkEventControllerScroll *Scroll,
gdouble dx,
gdouble dy,
@@ -701,6 +701,8 @@ scroll_controller_scroll (GtkEventControllerScroll *Scroll,
if (!gtk_widget_has_focus (widget))
gtk_widget_grab_focus (widget);
gtk_spin_button_real_spin (spin, -dy * gtk_adjustment_get_step_increment (priv->adjustment));
+
+ return GDK_EVENT_STOP;
}
static gboolean
diff --git a/gtk/gtktreeview.c b/gtk/gtktreeview.c
index ce68c88b6f..0926b0622f 100644
--- a/gtk/gtktreeview.c
+++ b/gtk/gtktreeview.c
@@ -811,7 +811,7 @@ static void gtk_tree_view_search_pressed_cb (GtkGesture *gestu
double x,
double y,
GtkTreeView *tree_view);
-static void gtk_tree_view_search_scroll_event (GtkWidget *entry,
+static gboolean gtk_tree_view_search_scroll_event (GtkWidget *entry,
gdouble dx,
gdouble dy,
GtkTreeView *tree_view);
@@ -13914,7 +13914,7 @@ gtk_tree_view_search_pressed_cb (GtkGesture *gesture,
gtk_tree_view_search_window_hide (widget, tree_view, keyb_device);
}
-static void
+static gboolean
gtk_tree_view_search_scroll_event (GtkWidget *widget,
gdouble dx,
gdouble dy,
@@ -13940,6 +13940,8 @@ gtk_tree_view_search_scroll_event (GtkWidget *widget,
tree_view);
g_source_set_name_by_id (tree_view->priv->typeselect_flush_timeout, "[gtk+]
gtk_tree_view_search_entry_flush_timeout");
}
+
+ return GDK_EVENT_STOP;
}
static gboolean
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]