summaryrefslogtreecommitdiff
path: root/gtk/gtkwidget.c
diff options
context:
space:
mode:
authorNelson Benítez León <nbenitezl@gmail.com>2022-01-19 15:33:03 -0400
committerNelson Benítez León <nbenitezl@gmail.com>2022-01-20 20:05:39 -0400
commitd1bf21ea43ae601542e94193907d56794bcc87fd (patch)
treef4feb4608d7ff135e66e22ec4c4491fdd7dcede5 /gtk/gtkwidget.c
parent10efc3cb0d8e30f4d7ac31da2cc904606a921ffe (diff)
downloadgtk+-combos_not_scroll.tar.gz
containers that can be scrolled should have precedencecombos_not_scroll
over child widgets that also react to scrolling like GtkComboBox, GtkScale and GtkSpinButton, because otherwise when you're in the middle of scrolling the view/window you can involuntarily scroll over the widgets and change its values. This problem can be seen in applications like pavucontrol, gnome-tweaks prefs, devhelp prefs, and so on. Fixes issue #3092
Diffstat (limited to 'gtk/gtkwidget.c')
-rw-r--r--gtk/gtkwidget.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index b6e00115bb..ed85c47d1d 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -11662,6 +11662,36 @@ gtk_widget_get_ancestor (GtkWidget *widget,
}
/**
+ * gtk_widget_inside_scrollable_container:
+ * @widget: a #GtkWidget
+ *
+ * Private function used by GtkComboBox, GtkRange, GtkSpinButton - See issue #3092
+ *
+ * Returns: whether @widget is inside a scrollable container (like eg.
+ * GtkScrolledWindow, GtkViewPort) and the view can currently be scrolled
+ * i.e. the scrollbars can move because the content excedes the page_size
+ **/
+gboolean
+gtk_widget_inside_scrollable_container (GtkWidget *widget)
+{
+ GtkWidget *ancestor;
+ GtkAdjustment *vadj;
+ gdouble upper, page_size;
+
+ ancestor = gtk_widget_get_ancestor (gtk_widget_get_parent (widget), GTK_TYPE_SCROLLABLE);
+ if (ancestor && GTK_IS_SCROLLABLE (ancestor))
+ {
+ vadj = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (ancestor));
+ g_object_get (vadj, "upper", &upper, "page_size", &page_size, NULL);
+
+ if (!G_APPROX_VALUE ((upper - page_size), 0.0, DBL_EPSILON))
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+/**
* gtk_widget_set_visual:
* @widget: a #GtkWidget
* @visual: (allow-none): visual to be used or %NULL to unset a previous one