2017-09-15 11:22:57 +00:00
|
|
|
/* GTK - The GIMP Toolkit
|
|
|
|
* Copyright (C) 2017, Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* Author(s): Carlos Garnacho <carlosg@gnome.org>
|
|
|
|
*/
|
|
|
|
|
2017-12-01 23:18:07 +00:00
|
|
|
/**
|
2021-03-01 06:37:08 +00:00
|
|
|
* GtkEventControllerScroll:
|
2017-12-01 23:18:07 +00:00
|
|
|
*
|
2021-03-01 06:37:08 +00:00
|
|
|
* `GtkEventControllerScroll` is an event controller that handles scroll
|
|
|
|
* events.
|
2017-12-01 23:18:07 +00:00
|
|
|
*
|
2021-03-01 06:37:08 +00:00
|
|
|
* It is capable of handling both discrete and continuous scroll
|
|
|
|
* events from mice or touchpads, abstracting them both with the
|
|
|
|
* [signal@Gtk.EventControllerScroll::scroll] signal. Deltas in
|
|
|
|
* the discrete case are multiples of 1.
|
2017-12-01 23:18:07 +00:00
|
|
|
*
|
2021-03-01 06:37:08 +00:00
|
|
|
* In the case of continuous scroll events, `GtkEventControllerScroll`
|
|
|
|
* encloses all [signal@Gtk.EventControllerScroll::scroll] emissions
|
|
|
|
* between two [signal@Gtk.EventControllerScroll::scroll-begin] and
|
|
|
|
* [signal@Gtk.EventControllerScroll::scroll-end] signals.
|
|
|
|
*
|
|
|
|
* The behavior of the event controller can be modified by the flags
|
|
|
|
* given at creation time, or modified at a later point through
|
|
|
|
* [method@Gtk.EventControllerScroll.set_flags] (e.g. because the scrolling
|
2017-12-01 23:18:07 +00:00
|
|
|
* conditions of the widget changed).
|
|
|
|
*
|
|
|
|
* The controller can be set up to emit motion for either/both vertical
|
2021-03-01 06:37:08 +00:00
|
|
|
* and horizontal scroll events through %GTK_EVENT_CONTROLLER_SCROLL_VERTICAL,
|
|
|
|
* %GTK_EVENT_CONTROLLER_SCROLL_HORIZONTAL and %GTK_EVENT_CONTROLLER_SCROLL_BOTH_AXES.
|
|
|
|
* If any axis is disabled, the respective [signal@Gtk.EventControllerScroll::scroll]
|
2017-12-01 23:18:07 +00:00
|
|
|
* delta will be 0. Vertical scroll events will be translated to horizontal
|
|
|
|
* motion for the devices incapable of horizontal scrolling.
|
|
|
|
*
|
2021-03-01 06:37:08 +00:00
|
|
|
* The event controller can also be forced to emit discrete events on all
|
|
|
|
* devices through %GTK_EVENT_CONTROLLER_SCROLL_DISCRETE. This can be used
|
|
|
|
* to implement discrete actions triggered through scroll events (e.g.
|
|
|
|
* switching across combobox options).
|
2017-12-01 23:18:07 +00:00
|
|
|
*
|
2021-03-01 06:37:08 +00:00
|
|
|
* The %GTK_EVENT_CONTROLLER_SCROLL_KINETIC flag toggles the emission of the
|
|
|
|
* [signal@Gtk.EventControllerScroll::decelerate] signal, emitted at the end
|
|
|
|
* of scrolling with two X/Y velocity arguments that are consistent with the
|
|
|
|
* motion that was received.
|
|
|
|
*/
|
2017-09-15 11:22:57 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "gtkintl.h"
|
|
|
|
#include "gtkwidget.h"
|
|
|
|
#include "gtkeventcontrollerprivate.h"
|
|
|
|
#include "gtkeventcontrollerscroll.h"
|
|
|
|
#include "gtktypebuiltins.h"
|
|
|
|
#include "gtkmarshalers.h"
|
2017-12-27 01:04:07 +00:00
|
|
|
#include "gtkprivate.h"
|
2017-09-15 11:22:57 +00:00
|
|
|
|
|
|
|
#define SCROLL_CAPTURE_THRESHOLD_MS 150
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2020-07-24 20:32:16 +00:00
|
|
|
double dx;
|
|
|
|
double dy;
|
2017-09-15 11:22:57 +00:00
|
|
|
guint32 evtime;
|
|
|
|
} ScrollHistoryElem;
|
|
|
|
|
|
|
|
struct _GtkEventControllerScroll
|
|
|
|
{
|
|
|
|
GtkEventController parent_instance;
|
|
|
|
GtkEventControllerScrollFlags flags;
|
|
|
|
GArray *scroll_history;
|
|
|
|
|
|
|
|
/* For discrete event coalescing */
|
2020-07-24 20:32:16 +00:00
|
|
|
double cur_dx;
|
|
|
|
double cur_dy;
|
2017-09-15 11:22:57 +00:00
|
|
|
|
|
|
|
guint active : 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _GtkEventControllerScrollClass
|
|
|
|
{
|
|
|
|
GtkEventControllerClass parent_class;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
SCROLL_BEGIN,
|
|
|
|
SCROLL,
|
|
|
|
SCROLL_END,
|
|
|
|
DECELERATE,
|
|
|
|
N_SIGNALS
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
PROP_0,
|
|
|
|
PROP_FLAGS,
|
|
|
|
N_PROPS
|
|
|
|
};
|
|
|
|
|
|
|
|
static GParamSpec *pspecs[N_PROPS] = { NULL };
|
|
|
|
static guint signals[N_SIGNALS] = { 0 };
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (GtkEventControllerScroll, gtk_event_controller_scroll,
|
|
|
|
GTK_TYPE_EVENT_CONTROLLER)
|
|
|
|
|
|
|
|
static void
|
|
|
|
scroll_history_push (GtkEventControllerScroll *scroll,
|
2020-07-24 20:32:16 +00:00
|
|
|
double delta_x,
|
|
|
|
double delta_y,
|
2017-09-15 11:22:57 +00:00
|
|
|
guint32 evtime)
|
|
|
|
{
|
|
|
|
ScrollHistoryElem new_item;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
for (i = 0; i < scroll->scroll_history->len; i++)
|
|
|
|
{
|
|
|
|
ScrollHistoryElem *elem;
|
|
|
|
|
|
|
|
elem = &g_array_index (scroll->scroll_history, ScrollHistoryElem, i);
|
|
|
|
|
|
|
|
if (elem->evtime >= evtime - SCROLL_CAPTURE_THRESHOLD_MS)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i > 0)
|
|
|
|
g_array_remove_range (scroll->scroll_history, 0, i);
|
|
|
|
|
|
|
|
new_item.dx = delta_x;
|
|
|
|
new_item.dy = delta_y;
|
|
|
|
new_item.evtime = evtime;
|
|
|
|
g_array_append_val (scroll->scroll_history, new_item);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
scroll_history_reset (GtkEventControllerScroll *scroll)
|
|
|
|
{
|
|
|
|
if (scroll->scroll_history->len == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_array_remove_range (scroll->scroll_history, 0,
|
|
|
|
scroll->scroll_history->len);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
scroll_history_finish (GtkEventControllerScroll *scroll,
|
2020-07-24 20:32:16 +00:00
|
|
|
double *velocity_x,
|
|
|
|
double *velocity_y)
|
2017-09-15 11:22:57 +00:00
|
|
|
{
|
2020-07-24 20:32:16 +00:00
|
|
|
double accum_dx = 0, accum_dy = 0;
|
2017-09-15 11:22:57 +00:00
|
|
|
guint32 first = 0, last = 0;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
*velocity_x = 0;
|
|
|
|
*velocity_y = 0;
|
|
|
|
|
|
|
|
if (scroll->scroll_history->len == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i < scroll->scroll_history->len; i++)
|
|
|
|
{
|
|
|
|
ScrollHistoryElem *elem;
|
|
|
|
|
|
|
|
elem = &g_array_index (scroll->scroll_history, ScrollHistoryElem, i);
|
|
|
|
accum_dx += elem->dx;
|
|
|
|
accum_dy += elem->dy;
|
|
|
|
last = elem->evtime;
|
|
|
|
|
|
|
|
if (i == 0)
|
|
|
|
first = elem->evtime;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (last != first)
|
|
|
|
{
|
|
|
|
*velocity_x = (accum_dx * 1000) / (last - first);
|
|
|
|
*velocity_y = (accum_dy * 1000) / (last - first);
|
|
|
|
}
|
|
|
|
|
|
|
|
scroll_history_reset (scroll);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_event_controller_scroll_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GtkEventControllerScroll *scroll = GTK_EVENT_CONTROLLER_SCROLL (object);
|
|
|
|
|
|
|
|
g_array_unref (scroll->scroll_history);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (gtk_event_controller_scroll_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_event_controller_scroll_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkEventControllerScroll *scroll = GTK_EVENT_CONTROLLER_SCROLL (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_FLAGS:
|
2017-12-27 01:04:07 +00:00
|
|
|
gtk_event_controller_scroll_set_flags (scroll, g_value_get_flags (value));
|
2017-09-15 11:22:57 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_event_controller_scroll_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkEventControllerScroll *scroll = GTK_EVENT_CONTROLLER_SCROLL (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_FLAGS:
|
|
|
|
g_value_set_flags (value, scroll->flags);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_event_controller_scroll_handle_event (GtkEventController *controller,
|
2020-02-16 16:09:02 +00:00
|
|
|
GdkEvent *event,
|
2020-02-13 05:08:49 +00:00
|
|
|
double x,
|
|
|
|
double y)
|
2017-09-15 11:22:57 +00:00
|
|
|
{
|
|
|
|
GtkEventControllerScroll *scroll = GTK_EVENT_CONTROLLER_SCROLL (controller);
|
|
|
|
GdkScrollDirection direction = GDK_SCROLL_SMOOTH;
|
2020-07-24 20:32:16 +00:00
|
|
|
double dx = 0, dy = 0;
|
2019-09-25 15:10:34 +00:00
|
|
|
gboolean handled = GDK_EVENT_PROPAGATE;
|
2017-09-15 11:22:57 +00:00
|
|
|
|
|
|
|
if (gdk_event_get_event_type (event) != GDK_SCROLL)
|
|
|
|
return FALSE;
|
2020-02-18 03:11:56 +00:00
|
|
|
|
2017-09-15 11:22:57 +00:00
|
|
|
if ((scroll->flags & (GTK_EVENT_CONTROLLER_SCROLL_VERTICAL |
|
|
|
|
GTK_EVENT_CONTROLLER_SCROLL_HORIZONTAL)) == 0)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* FIXME: Handle device changes */
|
2020-02-18 03:11:56 +00:00
|
|
|
direction = gdk_scroll_event_get_direction (event);
|
|
|
|
if (direction == GDK_SCROLL_SMOOTH)
|
2017-09-15 11:22:57 +00:00
|
|
|
{
|
2020-02-18 03:11:56 +00:00
|
|
|
gdk_scroll_event_get_deltas (event, &dx, &dy);
|
|
|
|
|
2020-09-28 21:30:05 +00:00
|
|
|
if (!scroll->active)
|
2017-09-15 11:22:57 +00:00
|
|
|
{
|
|
|
|
g_signal_emit (controller, signals[SCROLL_BEGIN], 0);
|
|
|
|
scroll_history_reset (scroll);
|
|
|
|
scroll->active = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((scroll->flags & GTK_EVENT_CONTROLLER_SCROLL_VERTICAL) == 0)
|
|
|
|
dy = 0;
|
|
|
|
if ((scroll->flags & GTK_EVENT_CONTROLLER_SCROLL_HORIZONTAL) == 0)
|
|
|
|
dx = 0;
|
|
|
|
|
|
|
|
if (scroll->flags & GTK_EVENT_CONTROLLER_SCROLL_DISCRETE)
|
|
|
|
{
|
2020-07-24 13:54:49 +00:00
|
|
|
int steps;
|
2017-09-15 11:22:57 +00:00
|
|
|
|
|
|
|
scroll->cur_dx += dx;
|
|
|
|
scroll->cur_dy += dy;
|
|
|
|
dx = dy = 0;
|
|
|
|
|
2017-10-11 06:06:33 +00:00
|
|
|
if (ABS (scroll->cur_dx) >= 1)
|
2017-09-15 11:22:57 +00:00
|
|
|
{
|
|
|
|
steps = trunc (scroll->cur_dx);
|
|
|
|
scroll->cur_dx -= steps;
|
|
|
|
dx = steps;
|
|
|
|
}
|
|
|
|
|
2017-10-11 06:06:33 +00:00
|
|
|
if (ABS (scroll->cur_dy) >= 1)
|
2017-09-15 11:22:57 +00:00
|
|
|
{
|
|
|
|
steps = trunc (scroll->cur_dy);
|
|
|
|
scroll->cur_dy -= steps;
|
|
|
|
dy = steps;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-02-18 03:11:56 +00:00
|
|
|
else
|
2017-09-15 11:22:57 +00:00
|
|
|
{
|
|
|
|
switch (direction)
|
|
|
|
{
|
|
|
|
case GDK_SCROLL_UP:
|
|
|
|
dy -= 1;
|
|
|
|
break;
|
|
|
|
case GDK_SCROLL_DOWN:
|
|
|
|
dy += 1;
|
|
|
|
break;
|
|
|
|
case GDK_SCROLL_LEFT:
|
|
|
|
dx -= 1;
|
|
|
|
break;
|
|
|
|
case GDK_SCROLL_RIGHT:
|
|
|
|
dx += 1;
|
|
|
|
break;
|
2017-10-06 19:19:42 +00:00
|
|
|
case GDK_SCROLL_SMOOTH:
|
2017-09-15 11:22:57 +00:00
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((scroll->flags & GTK_EVENT_CONTROLLER_SCROLL_VERTICAL) == 0)
|
|
|
|
dy = 0;
|
|
|
|
if ((scroll->flags & GTK_EVENT_CONTROLLER_SCROLL_HORIZONTAL) == 0)
|
|
|
|
dx = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dx != 0 || dy != 0)
|
2020-05-14 20:20:38 +00:00
|
|
|
g_signal_emit (controller, signals[SCROLL], 0, dx, dy, &handled);
|
2020-12-11 23:37:12 +00:00
|
|
|
else if (direction == GDK_SCROLL_SMOOTH &&
|
|
|
|
(scroll->flags & GTK_EVENT_CONTROLLER_SCROLL_DISCRETE) != 0)
|
|
|
|
handled = scroll->active;
|
2017-09-15 11:22:57 +00:00
|
|
|
|
2020-05-14 20:20:38 +00:00
|
|
|
if (direction == GDK_SCROLL_SMOOTH &&
|
|
|
|
scroll->flags & GTK_EVENT_CONTROLLER_SCROLL_KINETIC)
|
|
|
|
scroll_history_push (scroll, dx, dy, gdk_event_get_time (event));
|
2017-09-15 11:22:57 +00:00
|
|
|
|
2020-02-18 03:11:56 +00:00
|
|
|
if (scroll->active && gdk_scroll_event_is_stop (event))
|
2017-09-15 11:22:57 +00:00
|
|
|
{
|
|
|
|
g_signal_emit (controller, signals[SCROLL_END], 0);
|
|
|
|
scroll->active = FALSE;
|
2020-12-11 23:37:12 +00:00
|
|
|
handled = FALSE;
|
2017-09-15 11:22:57 +00:00
|
|
|
|
|
|
|
if (scroll->flags & GTK_EVENT_CONTROLLER_SCROLL_KINETIC)
|
|
|
|
{
|
2020-07-24 20:32:16 +00:00
|
|
|
double vel_x, vel_y;
|
2017-09-15 11:22:57 +00:00
|
|
|
|
|
|
|
scroll_history_finish (scroll, &vel_x, &vel_y);
|
|
|
|
g_signal_emit (controller, signals[DECELERATE], 0, vel_x, vel_y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-18 13:34:39 +00:00
|
|
|
return handled;
|
2017-09-15 11:22:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_event_controller_scroll_class_init (GtkEventControllerScrollClass *klass)
|
|
|
|
{
|
|
|
|
GtkEventControllerClass *controller_class = GTK_EVENT_CONTROLLER_CLASS (klass);
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
object_class->finalize = gtk_event_controller_scroll_finalize;
|
|
|
|
object_class->set_property = gtk_event_controller_scroll_set_property;
|
|
|
|
object_class->get_property = gtk_event_controller_scroll_get_property;
|
|
|
|
|
|
|
|
controller_class->handle_event = gtk_event_controller_scroll_handle_event;
|
|
|
|
|
2017-12-01 23:18:07 +00:00
|
|
|
/**
|
2021-03-01 06:37:08 +00:00
|
|
|
* GtkEventControllerScroll:flags: (attributes org.gtk.Property.get=gtk_event_controller_scroll_get_flags org.gtk.Property.set=gtk_event_controller_scroll_set_flags)
|
2017-12-01 23:18:07 +00:00
|
|
|
*
|
2021-03-01 06:37:08 +00:00
|
|
|
* The flags affecting event controller behavior.
|
|
|
|
*/
|
2017-09-15 11:22:57 +00:00
|
|
|
pspecs[PROP_FLAGS] =
|
|
|
|
g_param_spec_flags ("flags",
|
|
|
|
P_("Flags"),
|
|
|
|
P_("Flags"),
|
|
|
|
GTK_TYPE_EVENT_CONTROLLER_SCROLL_FLAGS,
|
|
|
|
GTK_EVENT_CONTROLLER_SCROLL_NONE,
|
2017-12-27 01:04:07 +00:00
|
|
|
GTK_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
|
2017-09-15 11:22:57 +00:00
|
|
|
|
2017-12-01 23:18:07 +00:00
|
|
|
/**
|
|
|
|
* GtkEventControllerScroll::scroll-begin:
|
|
|
|
* @controller: The object that received the signal
|
|
|
|
*
|
2021-03-01 06:37:08 +00:00
|
|
|
* Signals that a new scrolling operation has begun.
|
|
|
|
*
|
|
|
|
* It will only be emitted on devices capable of it.
|
|
|
|
*/
|
2017-09-15 11:22:57 +00:00
|
|
|
signals[SCROLL_BEGIN] =
|
|
|
|
g_signal_new (I_("scroll-begin"),
|
|
|
|
GTK_TYPE_EVENT_CONTROLLER_SCROLL,
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
0, NULL, NULL,
|
2019-05-29 20:05:19 +00:00
|
|
|
NULL,
|
2017-09-15 11:22:57 +00:00
|
|
|
G_TYPE_NONE, 0);
|
2021-03-01 06:37:08 +00:00
|
|
|
|
2017-12-01 23:18:07 +00:00
|
|
|
/**
|
|
|
|
* GtkEventControllerScroll::scroll:
|
|
|
|
* @controller: The object that received the signal
|
|
|
|
* @dx: X delta
|
|
|
|
* @dy: Y delta
|
|
|
|
*
|
|
|
|
* Signals that the widget should scroll by the
|
|
|
|
* amount specified by @dx and @dy.
|
2018-07-18 13:34:39 +00:00
|
|
|
*
|
2021-03-01 06:37:08 +00:00
|
|
|
* Returns: %TRUE if the scroll event was handled,
|
|
|
|
* %FALSE otherwise.
|
|
|
|
*/
|
2017-09-15 11:22:57 +00:00
|
|
|
signals[SCROLL] =
|
|
|
|
g_signal_new (I_("scroll"),
|
|
|
|
GTK_TYPE_EVENT_CONTROLLER_SCROLL,
|
2018-07-18 13:34:39 +00:00
|
|
|
G_SIGNAL_RUN_LAST,
|
2017-09-15 11:22:57 +00:00
|
|
|
0, NULL, NULL,
|
2019-06-06 22:27:54 +00:00
|
|
|
_gtk_marshal_BOOLEAN__DOUBLE_DOUBLE,
|
2018-07-18 13:34:39 +00:00
|
|
|
G_TYPE_BOOLEAN, 2, G_TYPE_DOUBLE, G_TYPE_DOUBLE);
|
2019-06-06 22:27:54 +00:00
|
|
|
g_signal_set_va_marshaller (signals[SCROLL],
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
_gtk_marshal_BOOLEAN__DOUBLE_DOUBLEv);
|
2021-03-01 06:37:08 +00:00
|
|
|
|
2017-12-01 23:18:07 +00:00
|
|
|
/**
|
|
|
|
* GtkEventControllerScroll::scroll-end:
|
|
|
|
* @controller: The object that received the signal
|
|
|
|
*
|
2021-03-01 06:37:08 +00:00
|
|
|
* Signals that a scrolling operation has finished.
|
|
|
|
*
|
|
|
|
* It will only be emitted on devices capable of it.
|
|
|
|
*/
|
2017-09-15 11:22:57 +00:00
|
|
|
signals[SCROLL_END] =
|
|
|
|
g_signal_new (I_("scroll-end"),
|
|
|
|
GTK_TYPE_EVENT_CONTROLLER_SCROLL,
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
0, NULL, NULL,
|
2019-05-29 20:05:19 +00:00
|
|
|
NULL,
|
2017-09-15 11:22:57 +00:00
|
|
|
G_TYPE_NONE, 0);
|
2017-12-01 23:18:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* GtkEventControllerScroll::decelerate:
|
|
|
|
* @controller: The object that received the signal
|
|
|
|
* @vel_x: X velocity
|
|
|
|
* @vel_y: Y velocity
|
|
|
|
*
|
2021-03-01 06:37:08 +00:00
|
|
|
* Emitted after scroll is finished if the
|
|
|
|
* %GTK_EVENT_CONTROLLER_SCROLL_KINETIC flag is set.
|
|
|
|
*
|
|
|
|
* @vel_x and @vel_y express the initial velocity that was
|
2017-12-01 23:18:07 +00:00
|
|
|
* imprinted by the scroll events. @vel_x and @vel_y are expressed in
|
|
|
|
* pixels/ms.
|
2021-03-01 06:37:08 +00:00
|
|
|
*/
|
2017-09-15 11:22:57 +00:00
|
|
|
signals[DECELERATE] =
|
|
|
|
g_signal_new (I_("decelerate"),
|
|
|
|
GTK_TYPE_EVENT_CONTROLLER_SCROLL,
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
0, NULL, NULL,
|
2019-06-06 22:27:54 +00:00
|
|
|
_gtk_marshal_VOID__DOUBLE_DOUBLE,
|
2017-09-15 11:22:57 +00:00
|
|
|
G_TYPE_NONE, 2, G_TYPE_DOUBLE, G_TYPE_DOUBLE);
|
2019-06-06 22:27:54 +00:00
|
|
|
g_signal_set_va_marshaller (signals[DECELERATE],
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
_gtk_marshal_VOID__DOUBLE_DOUBLEv);
|
2017-09-15 11:22:57 +00:00
|
|
|
|
|
|
|
g_object_class_install_properties (object_class, N_PROPS, pspecs);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_event_controller_scroll_init (GtkEventControllerScroll *scroll)
|
|
|
|
{
|
|
|
|
scroll->scroll_history = g_array_new (FALSE, FALSE,
|
|
|
|
sizeof (ScrollHistoryElem));
|
|
|
|
}
|
|
|
|
|
2017-12-01 23:18:07 +00:00
|
|
|
/**
|
|
|
|
* gtk_event_controller_scroll_new:
|
2021-03-01 06:37:08 +00:00
|
|
|
* @flags: flags affecting the controller behavior
|
2017-12-01 23:18:07 +00:00
|
|
|
*
|
2018-03-10 17:29:57 +00:00
|
|
|
* Creates a new event controller that will handle scroll events.
|
2017-12-01 23:18:07 +00:00
|
|
|
*
|
2021-03-01 06:37:08 +00:00
|
|
|
* Returns: a new `GtkEventControllerScroll`
|
|
|
|
*/
|
2017-09-15 11:22:57 +00:00
|
|
|
GtkEventController *
|
2018-03-10 17:29:57 +00:00
|
|
|
gtk_event_controller_scroll_new (GtkEventControllerScrollFlags flags)
|
2017-09-15 11:22:57 +00:00
|
|
|
{
|
|
|
|
return g_object_new (GTK_TYPE_EVENT_CONTROLLER_SCROLL,
|
|
|
|
"flags", flags,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2017-12-01 23:18:07 +00:00
|
|
|
/**
|
2021-03-01 06:37:08 +00:00
|
|
|
* gtk_event_controller_scroll_set_flags: (attributes org.gtk.Method.set_property=flags)
|
|
|
|
* @scroll: a `GtkEventControllerScroll`
|
|
|
|
* @flags: flags affecting the controller behavior
|
2017-12-01 23:18:07 +00:00
|
|
|
*
|
|
|
|
* Sets the flags conditioning scroll controller behavior.
|
2021-03-01 06:37:08 +00:00
|
|
|
*/
|
2017-09-15 11:22:57 +00:00
|
|
|
void
|
|
|
|
gtk_event_controller_scroll_set_flags (GtkEventControllerScroll *scroll,
|
|
|
|
GtkEventControllerScrollFlags flags)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GTK_IS_EVENT_CONTROLLER_SCROLL (scroll));
|
|
|
|
|
2017-12-27 01:04:07 +00:00
|
|
|
if (scroll->flags == flags)
|
|
|
|
return;
|
|
|
|
|
|
|
|
scroll->flags = flags;
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (scroll), pspecs[PROP_FLAGS]);
|
2017-09-15 11:22:57 +00:00
|
|
|
}
|
|
|
|
|
2017-12-01 23:18:07 +00:00
|
|
|
/**
|
2021-03-01 06:37:08 +00:00
|
|
|
* gtk_event_controller_scroll_get_flags: (attributes org.gtk.Method.get_property=flags)
|
|
|
|
* @scroll: a `GtkEventControllerScroll`
|
2017-12-01 23:18:07 +00:00
|
|
|
*
|
|
|
|
* Gets the flags conditioning the scroll controller behavior.
|
|
|
|
*
|
|
|
|
* Returns: the controller flags.
|
2021-03-01 06:37:08 +00:00
|
|
|
*/
|
2017-09-15 11:22:57 +00:00
|
|
|
GtkEventControllerScrollFlags
|
|
|
|
gtk_event_controller_scroll_get_flags (GtkEventControllerScroll *scroll)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_EVENT_CONTROLLER_SCROLL (scroll),
|
|
|
|
GTK_EVENT_CONTROLLER_SCROLL_NONE);
|
|
|
|
|
|
|
|
return scroll->flags;
|
|
|
|
}
|