scrolledwindow: kinetic scrolling with a finger

Works in old programs too. Taps and a resting finger still go to the
widgets as before.

Modelled on the kinetic scrolling of GTK 3 (f6393199be by
Carlos Garcia Campos).
This commit is contained in:
Daemonratte 2026-10-17 17:22:23 +02:00
commit 57b1fcdede
8 changed files with 610 additions and 1 deletions

View file

@ -781,6 +781,7 @@ gdk_window_remove_redirection
gdk_window_set_debug_updates
gdk_window_set_user_data
gdk_window_thaw_toplevel_updates_libgtk_only
gdk_window_set_touch_emulation_libgtk_only
gdk_window_thaw_updates
gdk_window_set_composited
gdk_pointer_grab

View file

@ -1260,6 +1260,38 @@ note_touch_wanted (GdkWindowObject *private)
get_native_event_mask (impl_window));
}
/**
* gdk_window_set_touch_emulation_libgtk_only:
* @window: a #GdkWindow
*
* The native window of @window takes the touches, so that GDK makes
* the pointer events of the first finger, marked with
* gdk_event_get_pointer_emulated(), for its windows without
* %GDK_TOUCH_MASK; GtkScrolledWindow scrolls with a finger then. Only
* on X11, where the X server makes them otherwise, without the mark;
* Windows marks them itself.
*/
void
gdk_window_set_touch_emulation_libgtk_only (GdkWindow *window)
{
#ifdef GDK_WINDOWING_X11
GdkWindowObject *impl_window;
g_return_if_fail (GDK_IS_WINDOW (window));
impl_window = ((GdkWindowObject *) window)->impl_window;
if (impl_window == NULL || GDK_WINDOW_DESTROYED (impl_window) ||
impl_window->window_type == GDK_WINDOW_ROOT ||
impl_window->window_type == GDK_WINDOW_FOREIGN ||
g_object_get_qdata (G_OBJECT (impl_window), touch_wanted_quark ()))
return;
g_object_set_qdata (G_OBJECT (impl_window), touch_wanted_quark (), GINT_TO_POINTER (1));
GDK_WINDOW_IMPL_GET_IFACE (impl_window->impl)->set_events ((GdkWindow *) impl_window,
get_native_event_mask (impl_window));
#endif
}
static GdkEventMask
get_native_event_mask (GdkWindowObject *private)
{

View file

@ -679,6 +679,7 @@ void gdk_window_thaw_updates (GdkWindow *window);
void gdk_window_freeze_toplevel_updates_libgtk_only (GdkWindow *window);
void gdk_window_thaw_toplevel_updates_libgtk_only (GdkWindow *window);
void gdk_window_set_touch_emulation_libgtk_only (GdkWindow *window);
void gdk_window_process_all_updates (void);
void gdk_window_process_updates (GdkWindow *window,

View file

@ -3751,6 +3751,7 @@ gtk_scrollbar_get_type
gtk_scrolled_window_add_with_viewport
gtk_scrolled_window_get_hadjustment
gtk_scrolled_window_get_hscrollbar
gtk_scrolled_window_get_kinetic_scrolling
gtk_scrolled_window_get_placement
gtk_scrolled_window_get_policy
gtk_scrolled_window_get_shadow_type
@ -3759,6 +3760,7 @@ gtk_scrolled_window_get_vadjustment
gtk_scrolled_window_get_vscrollbar
gtk_scrolled_window_new
gtk_scrolled_window_set_hadjustment
gtk_scrolled_window_set_kinetic_scrolling
gtk_scrolled_window_set_placement
gtk_scrolled_window_set_policy
gtk_scrolled_window_set_shadow_type

View file

@ -1832,6 +1832,13 @@ gtk_main_do_event (GdkEvent *event)
grab_widget = event_widget;
}
/* a finger that drags in a scrolled window scrolls it */
if ((event->type == GDK_BUTTON_PRESS || event->type == GDK_2BUTTON_PRESS ||
event->type == GDK_3BUTTON_PRESS || event->type == GDK_MOTION_NOTIFY ||
event->type == GDK_BUTTON_RELEASE) &&
_gtk_scrolled_window_touch_event (event_widget, grab_widget, event))
goto done;
/* Not all events get sent to the grabbing widget.
* The delete, destroy, expose, focus change and resize
* events still get sent to the event widget because
@ -2003,6 +2010,7 @@ gtk_main_do_event (GdkEvent *event)
_gtk_tooltip_handle_event (event);
}
done:
tmp_list = current_events;
current_events = g_list_remove_link (current_events, tmp_list);
g_list_free_1 (tmp_list);

View file

@ -195,6 +195,9 @@ guint _gtk_scrolled_window_takes_scroll (GtkWidget *widget,
GdkEventScroll *event);
void _gtk_scroll_latch (GtkWidget *widget,
guint32 time);
gboolean _gtk_scrolled_window_touch_event (GtkWidget *event_widget,
GtkWidget *grab_widget,
GdkEvent *event);
gboolean _gtk_translate_keyboard_accel_state (GdkKeymap *keymap,
guint hardware_keycode,

View file

@ -28,6 +28,8 @@
#include <math.h>
#include <gdk/gdkkeysyms.h>
#include "gtkbindings.h"
#include "gtkmain.h"
#include "gtkrange.h"
#include "gtkmarshalers.h"
#include "gtkscrolledwindow.h"
#include "gtkwindow.h"
@ -76,6 +78,13 @@
typedef struct {
gboolean window_placement_set;
GtkCornerType real_window_placement;
/* dragging with a finger (see gtk_scrolled_window_touch_event()) */
gboolean no_kinetic_scrolling;
guint fling_source;
gdouble fling_vx, fling_vy; /* pixels a second */
gdouble fling_x, fling_y; /* where the adjustments are going */
gint64 fling_tick;
} GtkScrolledWindowPrivate;
#define GTK_SCROLLED_WINDOW_GET_PRIVATE(obj) ((GtkScrolledWindowPrivate *) gtk_scrolled_window_get_instance_private (GTK_SCROLLED_WINDOW (obj)))
@ -88,7 +97,8 @@ enum {
PROP_VSCROLLBAR_POLICY,
PROP_WINDOW_PLACEMENT,
PROP_WINDOW_PLACEMENT_SET,
PROP_SHADOW_TYPE
PROP_SHADOW_TYPE,
PROP_KINETIC_SCROLLING
};
/* Signals */
@ -109,6 +119,8 @@ static void gtk_scrolled_window_get_property (GObject *objec
GValue *value,
GParamSpec *pspec);
static void gtk_scrolled_window_realize (GtkWidget *widget);
static void fling_stop (GtkScrolledWindow *scrolled_window);
static void gtk_scrolled_window_screen_changed (GtkWidget *widget,
GdkScreen *previous_screen);
static gboolean gtk_scrolled_window_expose (GtkWidget *widget,
@ -196,6 +208,7 @@ gtk_scrolled_window_class_init (GtkScrolledWindowClass *class)
object_class->destroy = gtk_scrolled_window_destroy;
widget_class->realize = gtk_scrolled_window_realize;
widget_class->screen_changed = gtk_scrolled_window_screen_changed;
widget_class->expose_event = gtk_scrolled_window_expose;
widget_class->size_request = gtk_scrolled_window_size_request;
@ -277,6 +290,23 @@ gtk_scrolled_window_class_init (GtkScrolledWindowClass *class)
GTK_SHADOW_NONE,
GTK_PARAM_READABLE | GTK_PARAM_WRITABLE));
/**
* GtkScrolledWindow:kinetic-scrolling:
*
* Whether a finger on a touchscreen scrolls by dragging, also with a
* swipe that goes on for a while, as in GTK+ 3. A finger that rests
* a moment first, or taps, is for the widgets inside, as is a mouse.
*
* Since: 2.24
*/
g_object_class_install_property (gobject_class,
PROP_KINETIC_SCROLLING,
g_param_spec_boolean ("kinetic-scrolling",
P_("Kinetic Scrolling"),
P_("Kinetic scrolling mode."),
TRUE,
GTK_PARAM_READABLE | GTK_PARAM_WRITABLE));
/**
* GtkScrolledWindow:scrollbars-within-bevel:
*
@ -845,6 +875,8 @@ gtk_scrolled_window_destroy (GtkObject *object)
{
GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (object);
fling_stop (scrolled_window);
if (scrolled_window->hscrollbar)
{
g_signal_handlers_disconnect_by_func (gtk_range_get_adjustment (GTK_RANGE (scrolled_window->hscrollbar)),
@ -910,6 +942,10 @@ gtk_scrolled_window_set_property (GObject *object,
gtk_scrolled_window_set_shadow_type (scrolled_window,
g_value_get_enum (value));
break;
case PROP_KINETIC_SCROLLING:
gtk_scrolled_window_set_kinetic_scrolling (scrolled_window,
g_value_get_boolean (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -950,6 +986,9 @@ gtk_scrolled_window_get_property (GObject *object,
case PROP_SHADOW_TYPE:
g_value_set_enum (value, scrolled_window->shadow_type);
break;
case PROP_KINETIC_SCROLLING:
g_value_set_boolean (value, !priv->no_kinetic_scrolling);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -1807,6 +1846,526 @@ _gtk_scrolled_window_takes_scroll (GtkWidget *widget,
(steps_x != 0 && hbar && gtk_widget_get_visible (hbar) ? 1 : 0);
}
/* Dragging with a finger scrolls, as GTK+ 3's kinetic scrolling, in all
* programs: GDK marks the pointer events that a finger makes
* (gdk_event_get_pointer_emulated()), and gtk_main_do_event() shows
* them here before anyone else. A press of a finger inside a scrolled
* window that can scroll waits: if the finger moves on, the scrolled
* window scrolls with it, and after a swipe goes on, slowing down; if
* it is lifted, or rests for TOUCH_HOLD_TIME, the press goes to the
* widget below after all, so that tapping, selecting and dragging and
* dropping stay as they were. A finger on a scrollbar or slider moves
* that. The mouse is never held back. */
#define TOUCH_HOLD_TIME 300 /* milliseconds */
#define FLING_INTERVAL 16 /* milliseconds */
#define FLING_DECAY 0.325 /* seconds for the speed to fall to 1/e */
#define FLING_MIN_SPEED 50.0 /* pixels a second to start a swipe */
#define FLING_STOP_SPEED 15.0 /* and to end it */
#define SAMPLE_TIME 100 /* milliseconds of motion that tell the speed */
enum
{
TOUCH_IDLE,
TOUCH_HOLD, /* a press waits */
TOUCH_DRAG, /* the finger scrolls */
TOUCH_STOPPED, /* the finger stopped a swipe */
TOUCH_PASS /* the finger is for the widget below */
};
static struct
{
gint state;
GtkWidget *inner; /* innermost scrolled window under the finger */
GtkWidget *scrolling; /* the one that scrolls */
GList *held; /* the presses held back, newest first */
gdouble x0, y0; /* root position of the press */
gdouble h0, v0; /* adjustment values at the press */
guint timeout;
gboolean replaying;
struct { guint32 time; gdouble x, y; } samples[8];
guint nsamples;
} touch;
static GtkAdjustment *
touch_adjustment (GtkScrolledWindow *scrolled_window,
gboolean vertical)
{
GtkWidget *bar = vertical ? scrolled_window->vscrollbar : scrolled_window->hscrollbar;
return bar ? gtk_range_get_adjustment (GTK_RANGE (bar)) : NULL;
}
/* whether the scrolled window has room to scroll that way */
static gboolean
touch_can_scroll (GtkWidget *widget,
gboolean vertical)
{
GtkAdjustment *adj = touch_adjustment (GTK_SCROLLED_WINDOW (widget), vertical);
return adj && adj->upper - adj->page_size > adj->lower + 0.5;
}
static gboolean
touch_takes (GtkWidget *widget)
{
return GTK_IS_SCROLLED_WINDOW (widget) &&
!GTK_SCROLLED_WINDOW_GET_PRIVATE (widget)->no_kinetic_scrolling &&
gtk_widget_is_sensitive (widget);
}
static void
touch_set_widget (GtkWidget **where,
GtkWidget *widget)
{
if (*where)
g_object_remove_weak_pointer (G_OBJECT (*where), (gpointer *) where);
*where = widget;
if (widget)
g_object_add_weak_pointer (G_OBJECT (widget), (gpointer *) where);
}
static void
touch_drop_held (void)
{
g_list_foreach (touch.held, (GFunc) gdk_event_free, NULL);
g_list_free (touch.held);
touch.held = NULL;
if (touch.timeout)
g_source_remove (touch.timeout);
touch.timeout = 0;
}
/* the presses go to the widgets after all */
static void
touch_replay (void)
{
GList *held = g_list_reverse (touch.held), *l;
touch.held = NULL;
if (touch.timeout)
g_source_remove (touch.timeout);
touch.timeout = 0;
touch.replaying = TRUE;
for (l = held; l; l = l->next)
{
gtk_main_do_event (l->data);
gdk_event_free (l->data);
}
touch.replaying = FALSE;
g_list_free (held);
}
static gboolean
touch_hold_timeout (gpointer data)
{
touch.timeout = 0;
touch.state = TOUCH_PASS;
touch_replay ();
return FALSE;
}
static void
fling_stop (GtkScrolledWindow *scrolled_window)
{
GtkScrolledWindowPrivate *priv = GTK_SCROLLED_WINDOW_GET_PRIVATE (scrolled_window);
if (priv->fling_source)
g_source_remove (priv->fling_source);
priv->fling_source = 0;
}
/* stops the swipes of @widget and the scrolled windows around it;
* returns whether there was one */
static gboolean
fling_stop_around (GtkWidget *widget)
{
gboolean stopped = FALSE;
for (; widget; widget = widget->parent)
if (GTK_IS_SCROLLED_WINDOW (widget) &&
GTK_SCROLLED_WINDOW_GET_PRIVATE (widget)->fling_source)
{
fling_stop (GTK_SCROLLED_WINDOW (widget));
stopped = TRUE;
}
return stopped;
}
/* moves one adjustment of a swipe; returns whether it goes on */
static gboolean
fling_axis (GtkAdjustment *adj,
gdouble *speed,
gdouble *last,
gdouble dt,
gdouble decay)
{
gdouble value, top;
if (adj == NULL || *speed == 0)
return FALSE;
/* someone else moved it */
if (fabs (adj->value - *last) >= 1)
{
*speed = 0;
return FALSE;
}
top = adjustment_top (adj);
value = CLAMP (*last + *speed * dt, adj->lower, top);
*speed *= decay;
*last = value;
if (floor (value) != floor (adj->value))
gtk_adjustment_set_value (adj, floor (value));
if (value <= adj->lower || value >= top || fabs (*speed) < FLING_STOP_SPEED)
{
*speed = 0;
return FALSE;
}
return TRUE;
}
static gboolean
fling_tick (gpointer data)
{
GtkScrolledWindow *scrolled_window = data;
GtkScrolledWindowPrivate *priv = GTK_SCROLLED_WINDOW_GET_PRIVATE (scrolled_window);
gint64 now = g_get_monotonic_time ();
gdouble dt = MIN (now - priv->fling_tick, 100000) / (gdouble) G_USEC_PER_SEC;
gdouble decay = exp (- dt / FLING_DECAY);
gboolean more;
priv->fling_tick = now;
g_object_ref (scrolled_window);
more = fling_axis (touch_adjustment (scrolled_window, FALSE), &priv->fling_vx,
&priv->fling_x, dt, decay);
more |= fling_axis (touch_adjustment (scrolled_window, TRUE), &priv->fling_vy,
&priv->fling_y, dt, decay);
if (!more)
priv->fling_source = 0;
g_object_unref (scrolled_window);
return more;
}
/* the speed of the finger in pixels a second, from its last motions */
static void
touch_speed (guint32 time,
gdouble *vx,
gdouble *vy)
{
guint i, last = touch.nsamples - 1;
*vx = *vy = 0;
if (touch.nsamples < 2 || time - touch.samples[last % 8].time > SAMPLE_TIME)
return;
for (i = touch.nsamples > 8 ? touch.nsamples - 8 : 0; i < last; i++)
if (touch.samples[last % 8].time - touch.samples[i % 8].time <= SAMPLE_TIME)
break;
if (touch.samples[last % 8].time > touch.samples[i % 8].time)
{
gdouble dt = (touch.samples[last % 8].time - touch.samples[i % 8].time) / 1000.0;
*vx = (touch.samples[last % 8].x - touch.samples[i % 8].x) / dt;
*vy = (touch.samples[last % 8].y - touch.samples[i % 8].y) / dt;
}
}
static void
touch_fling (guint32 time)
{
GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (touch.scrolling);
GtkScrolledWindowPrivate *priv = GTK_SCROLLED_WINDOW_GET_PRIVATE (scrolled_window);
GtkAdjustment *hadj = touch_adjustment (scrolled_window, FALSE);
GtkAdjustment *vadj = touch_adjustment (scrolled_window, TRUE);
gboolean animations;
gdouble vx, vy;
g_object_get (gtk_widget_get_settings (touch.scrolling), "gtk-enable-animations", &animations, NULL);
if (!animations)
return;
touch_speed (time, &vx, &vy);
priv->fling_vx = touch_can_scroll (touch.scrolling, FALSE) ? -vx : 0;
priv->fling_vy = touch_can_scroll (touch.scrolling, TRUE) ? -vy : 0;
if (hypot (priv->fling_vx, priv->fling_vy) < FLING_MIN_SPEED)
return;
priv->fling_x = hadj ? hadj->value : 0;
priv->fling_y = vadj ? vadj->value : 0;
priv->fling_tick = g_get_monotonic_time ();
fling_stop (scrolled_window);
priv->fling_source = gdk_threads_add_timeout (FLING_INTERVAL, fling_tick, scrolled_window);
}
static void
touch_scroll_to (gdouble x_root,
gdouble y_root)
{
GtkWidget *widget = g_object_ref (touch.scrolling);
GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (widget);
GtkAdjustment *adj;
if (touch_can_scroll (widget, FALSE) &&
(adj = touch_adjustment (scrolled_window, FALSE)))
{
glide_stop (adj);
gtk_adjustment_set_value (adj, CLAMP (floor (touch.h0 - (x_root - touch.x0)),
adj->lower, adjustment_top (adj)));
}
if (touch_can_scroll (widget, TRUE) &&
(adj = touch_adjustment (scrolled_window, TRUE)))
{
glide_stop (adj);
gtk_adjustment_set_value (adj, CLAMP (floor (touch.v0 - (y_root - touch.y0)),
adj->lower, adjustment_top (adj)));
}
g_object_unref (widget);
}
/* The finger went far enough: the scrolled window from the innermost
* one out that can scroll the way it went begins to. Returns FALSE
* where none can. */
static gboolean
touch_begin_drag (gdouble x_root,
gdouble y_root)
{
gboolean vertical = fabs (y_root - touch.y0) >= fabs (x_root - touch.x0);
GtkWidget *w;
GtkAdjustment *adj;
for (w = touch.inner; w; w = w->parent)
if (touch_takes (w) && touch_can_scroll (w, vertical))
break;
if (w == NULL)
return FALSE;
touch_set_widget (&touch.scrolling, w);
adj = touch_adjustment (GTK_SCROLLED_WINDOW (w), FALSE);
touch.h0 = adj ? adj->value : 0;
adj = touch_adjustment (GTK_SCROLLED_WINDOW (w), TRUE);
touch.v0 = adj ? adj->value : 0;
touch.state = TOUCH_DRAG;
touch_drop_held ();
return TRUE;
}
static void
touch_sample (guint32 time,
gdouble x_root,
gdouble y_root)
{
guint i = touch.nsamples++ % 8;
touch.samples[i].time = time;
touch.samples[i].x = x_root;
touch.samples[i].y = y_root;
}
/* Returns whether the event is taken, from gtk_main_do_event() for the
* pointer events; @grab_widget is the one that would get it */
gboolean
_gtk_scrolled_window_touch_event (GtkWidget *event_widget,
GtkWidget *grab_widget,
GdkEvent *event)
{
GtkWidget *w, *inner = NULL;
gboolean finger;
gint threshold;
if (touch.replaying)
return FALSE;
finger = gdk_event_get_pointer_emulated (event);
switch (event->type)
{
case GDK_BUTTON_PRESS:
case GDK_2BUTTON_PRESS:
case GDK_3BUTTON_PRESS:
if (touch.state == TOUCH_HOLD && finger)
{
/* the double click of a second tap waits with its press */
touch.held = g_list_prepend (touch.held, gdk_event_copy (event));
return TRUE;
}
if (touch.state == TOUCH_DRAG || touch.state == TOUCH_STOPPED)
return finger;
if (touch.state == TOUCH_PASS && event->type != GDK_BUTTON_PRESS)
return FALSE;
touch.state = TOUCH_IDLE;
touch_drop_held ();
if (!finger || event->type != GDK_BUTTON_PRESS || event->button.button != 1 ||
grab_widget != event_widget)
return FALSE;
/* where the finger is for a scrollbar or slider, or no scrolled
* window around can scroll, nothing waits */
for (w = event_widget; w; w = w->parent)
{
if (GTK_IS_RANGE (w))
return FALSE;
if (touch_takes (w) &&
(touch_can_scroll (w, FALSE) || touch_can_scroll (w, TRUE) ||
GTK_SCROLLED_WINDOW_GET_PRIVATE (w)->fling_source))
{
inner = w;
break;
}
}
if (inner == NULL)
return FALSE;
touch_set_widget (&touch.inner, inner);
touch_set_widget (&touch.scrolling, NULL);
touch.x0 = event->button.x_root;
touch.y0 = event->button.y_root;
touch.nsamples = 0;
touch_sample (event->button.time, touch.x0, touch.y0);
/* a finger on a swipe stops it, and is not a tap */
if (fling_stop_around (inner))
{
touch.state = TOUCH_STOPPED;
return TRUE;
}
touch.state = TOUCH_HOLD;
touch.held = g_list_prepend (NULL, gdk_event_copy (event));
touch.timeout = gdk_threads_add_timeout (TOUCH_HOLD_TIME, touch_hold_timeout, NULL);
return TRUE;
case GDK_MOTION_NOTIFY:
if (touch.state == TOUCH_IDLE || touch.state == TOUCH_PASS || !finger)
return FALSE;
touch_sample (event->motion.time, event->motion.x_root, event->motion.y_root);
if (touch.state == TOUCH_HOLD || touch.state == TOUCH_STOPPED)
{
g_object_get (gtk_widget_get_settings (event_widget),
"gtk-dnd-drag-threshold", &threshold, NULL);
if (fabs (event->motion.x_root - touch.x0) <= threshold &&
fabs (event->motion.y_root - touch.y0) <= threshold)
return TRUE;
if (!touch.inner || !touch_begin_drag (event->motion.x_root, event->motion.y_root))
{
/* nothing can scroll that way: for the widget below */
if (touch.state == TOUCH_HOLD)
{
touch.state = TOUCH_PASS;
touch_replay ();
return FALSE;
}
return TRUE;
}
}
if (touch.scrolling)
touch_scroll_to (event->motion.x_root, event->motion.y_root);
return TRUE;
case GDK_BUTTON_RELEASE:
switch (touch.state)
{
case TOUCH_HOLD:
touch.state = TOUCH_IDLE;
touch_replay ();
return FALSE;
case TOUCH_DRAG:
touch.state = TOUCH_IDLE;
if (finger && touch.scrolling)
touch_fling (event->button.time);
touch_set_widget (&touch.scrolling, NULL);
return finger;
case TOUCH_STOPPED:
touch.state = TOUCH_IDLE;
return finger;
case TOUCH_PASS:
touch.state = TOUCH_IDLE;
return FALSE;
default:
return FALSE;
}
default:
return FALSE;
}
}
static void
gtk_scrolled_window_realize (GtkWidget *widget)
{
GTK_WIDGET_CLASS (gtk_scrolled_window_parent_class)->realize (widget);
/* for the marks of the pointer events of fingers */
if (!GTK_SCROLLED_WINDOW_GET_PRIVATE (widget)->no_kinetic_scrolling)
gdk_window_set_touch_emulation_libgtk_only (widget->window);
}
/**
* gtk_scrolled_window_set_kinetic_scrolling:
* @scrolled_window: a #GtkScrolledWindow
* @kinetic_scrolling: %TRUE to enable kinetic scrolling
*
* Turns dragging with a finger on a touchscreen on or off, see
* #GtkScrolledWindow:kinetic-scrolling. On by default.
*
* Since: 2.24
*/
void
gtk_scrolled_window_set_kinetic_scrolling (GtkScrolledWindow *scrolled_window,
gboolean kinetic_scrolling)
{
GtkScrolledWindowPrivate *priv;
g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
priv = GTK_SCROLLED_WINDOW_GET_PRIVATE (scrolled_window);
if (priv->no_kinetic_scrolling == !kinetic_scrolling)
return;
priv->no_kinetic_scrolling = !kinetic_scrolling;
if (!kinetic_scrolling)
fling_stop (scrolled_window);
else if (gtk_widget_get_realized (GTK_WIDGET (scrolled_window)))
gdk_window_set_touch_emulation_libgtk_only (GTK_WIDGET (scrolled_window)->window);
g_object_notify (G_OBJECT (scrolled_window), "kinetic-scrolling");
}
/**
* gtk_scrolled_window_get_kinetic_scrolling:
* @scrolled_window: a #GtkScrolledWindow
*
* Returns whether a finger scrolls by dragging.
*
* Returns: the kinetic scrolling behavior flags.
*
* Since: 2.24
*/
gboolean
gtk_scrolled_window_get_kinetic_scrolling (GtkScrolledWindow *scrolled_window)
{
g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), FALSE);
return !GTK_SCROLLED_WINDOW_GET_PRIVATE (scrolled_window)->no_kinetic_scrolling;
}
static gboolean
gtk_scrolled_window_focus (GtkWidget *widget,
GtkDirectionType direction)

View file

@ -126,6 +126,9 @@ void gtk_scrolled_window_set_shadow_type (GtkScrolledWindow *scrolle
GtkShadowType gtk_scrolled_window_get_shadow_type (GtkScrolledWindow *scrolled_window);
void gtk_scrolled_window_add_with_viewport (GtkScrolledWindow *scrolled_window,
GtkWidget *child);
void gtk_scrolled_window_set_kinetic_scrolling (GtkScrolledWindow *scrolled_window,
gboolean kinetic_scrolling);
gboolean gtk_scrolled_window_get_kinetic_scrolling (GtkScrolledWindow *scrolled_window);
gint _gtk_scrolled_window_get_scrollbar_spacing (GtkScrolledWindow *scrolled_window);