2014-02-27 14:26:48 +00:00
|
|
|
/* GTK - The GIMP Toolkit
|
|
|
|
* Copyright (C) 2014 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>
|
|
|
|
*/
|
|
|
|
|
2014-04-09 16:28:03 +00:00
|
|
|
/**
|
|
|
|
* SECTION:gtkgesturemultipress
|
|
|
|
* @Short_description: Multipress gesture
|
|
|
|
* @Title: GtkGestureMultiPress
|
|
|
|
*
|
|
|
|
* #GtkGestureMultiPress is a #GtkGesture implementation able to recognize
|
|
|
|
* multiple clicks on a nearby zone, which can be listened for through the
|
2014-05-20 02:16:03 +00:00
|
|
|
* #GtkGestureMultiPress::pressed signal. Whenever time or distance between
|
|
|
|
* clicks exceed the GTK+ defaults, #GtkGestureMultiPress::stopped is emitted,
|
|
|
|
* and the click counter is reset.
|
2014-04-09 16:28:03 +00:00
|
|
|
*
|
|
|
|
* Callers may also restrict the area that is considered valid for a >1
|
|
|
|
* touch/button press through gtk_gesture_multi_press_set_area(), so any
|
|
|
|
* click happening outside that area is considered to be a first click of
|
|
|
|
* its own.
|
|
|
|
*/
|
|
|
|
|
2014-02-27 14:26:48 +00:00
|
|
|
#include "config.h"
|
2014-05-06 16:04:25 +00:00
|
|
|
#include "gtkgestureprivate.h"
|
2014-02-27 14:26:48 +00:00
|
|
|
#include "gtkgesturemultipress.h"
|
2014-05-06 02:40:18 +00:00
|
|
|
#include "gtkgesturemultipressprivate.h"
|
2014-02-27 14:26:48 +00:00
|
|
|
#include "gtkprivate.h"
|
|
|
|
#include "gtkintl.h"
|
|
|
|
|
|
|
|
typedef struct _GtkGestureMultiPressPrivate GtkGestureMultiPressPrivate;
|
|
|
|
|
|
|
|
struct _GtkGestureMultiPressPrivate
|
|
|
|
{
|
|
|
|
GdkRectangle rect;
|
2016-02-22 21:38:56 +00:00
|
|
|
GdkDevice *current_device;
|
2014-02-27 14:26:48 +00:00
|
|
|
gdouble initial_press_x;
|
|
|
|
gdouble initial_press_y;
|
|
|
|
guint double_click_timeout_id;
|
|
|
|
guint n_presses;
|
2014-05-12 15:02:03 +00:00
|
|
|
guint n_release;
|
2014-02-27 14:26:48 +00:00
|
|
|
guint current_button;
|
|
|
|
guint rect_is_set : 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
PRESSED,
|
2014-05-12 15:02:03 +00:00
|
|
|
RELEASED,
|
2014-02-27 14:26:48 +00:00
|
|
|
STOPPED,
|
2017-11-21 19:14:52 +00:00
|
|
|
UNPAIRED_RELEASE,
|
2014-02-27 14:26:48 +00:00
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
static guint signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
2014-03-21 18:21:56 +00:00
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (GtkGestureMultiPress, gtk_gesture_multi_press, GTK_TYPE_GESTURE_SINGLE)
|
2014-02-27 14:26:48 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_gesture_multi_press_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GtkGestureMultiPressPrivate *priv;
|
|
|
|
GtkGestureMultiPress *gesture;
|
|
|
|
|
|
|
|
gesture = GTK_GESTURE_MULTI_PRESS (object);
|
|
|
|
priv = gtk_gesture_multi_press_get_instance_private (gesture);
|
|
|
|
|
|
|
|
if (priv->double_click_timeout_id)
|
|
|
|
{
|
|
|
|
g_source_remove (priv->double_click_timeout_id);
|
|
|
|
priv->double_click_timeout_id = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (gtk_gesture_multi_press_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_gesture_multi_press_check (GtkGesture *gesture)
|
|
|
|
{
|
|
|
|
GtkGestureMultiPress *multi_press;
|
|
|
|
GtkGestureMultiPressPrivate *priv;
|
|
|
|
GList *sequences;
|
|
|
|
gboolean active;
|
|
|
|
|
|
|
|
multi_press = GTK_GESTURE_MULTI_PRESS (gesture);
|
|
|
|
priv = gtk_gesture_multi_press_get_instance_private (multi_press);
|
|
|
|
sequences = gtk_gesture_get_sequences (gesture);
|
|
|
|
|
2014-03-21 18:21:56 +00:00
|
|
|
active = g_list_length (sequences) == 1 || priv->double_click_timeout_id;
|
2014-02-27 14:26:48 +00:00
|
|
|
g_list_free (sequences);
|
|
|
|
|
|
|
|
return active;
|
|
|
|
}
|
|
|
|
|
2014-03-21 18:21:56 +00:00
|
|
|
static void
|
|
|
|
_gtk_gesture_multi_press_stop (GtkGestureMultiPress *gesture)
|
|
|
|
{
|
|
|
|
GtkGestureMultiPressPrivate *priv;
|
|
|
|
|
|
|
|
priv = gtk_gesture_multi_press_get_instance_private (gesture);
|
|
|
|
|
|
|
|
if (priv->n_presses == 0)
|
|
|
|
return;
|
|
|
|
|
2016-02-22 21:38:56 +00:00
|
|
|
priv->current_device = NULL;
|
2014-03-21 18:21:56 +00:00
|
|
|
priv->current_button = 0;
|
|
|
|
priv->n_presses = 0;
|
2014-04-08 19:09:44 +00:00
|
|
|
g_signal_emit (gesture, signals[STOPPED], 0);
|
2014-05-06 16:04:25 +00:00
|
|
|
_gtk_gesture_check (GTK_GESTURE (gesture));
|
2014-03-21 18:21:56 +00:00
|
|
|
}
|
|
|
|
|
2014-02-27 14:26:48 +00:00
|
|
|
static gboolean
|
|
|
|
_double_click_timeout_cb (gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkGestureMultiPress *gesture = user_data;
|
|
|
|
GtkGestureMultiPressPrivate *priv;
|
|
|
|
|
|
|
|
priv = gtk_gesture_multi_press_get_instance_private (gesture);
|
|
|
|
priv->double_click_timeout_id = 0;
|
2014-03-21 18:21:56 +00:00
|
|
|
_gtk_gesture_multi_press_stop (gesture);
|
2014-02-27 14:26:48 +00:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_gtk_gesture_multi_press_update_timeout (GtkGestureMultiPress *gesture)
|
|
|
|
{
|
|
|
|
GtkGestureMultiPressPrivate *priv;
|
|
|
|
guint double_click_time;
|
|
|
|
GtkSettings *settings;
|
|
|
|
GtkWidget *widget;
|
|
|
|
|
|
|
|
priv = gtk_gesture_multi_press_get_instance_private (gesture);
|
|
|
|
|
|
|
|
if (priv->double_click_timeout_id)
|
|
|
|
g_source_remove (priv->double_click_timeout_id);
|
|
|
|
|
|
|
|
widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture));
|
|
|
|
settings = gtk_widget_get_settings (widget);
|
|
|
|
g_object_get (settings, "gtk-double-click-time", &double_click_time, NULL);
|
|
|
|
|
2018-02-02 14:51:47 +00:00
|
|
|
priv->double_click_timeout_id = g_timeout_add (double_click_time, _double_click_timeout_cb, gesture);
|
2017-08-13 13:03:40 +00:00
|
|
|
g_source_set_name_by_id (priv->double_click_timeout_id, "[gtk+] _double_click_timeout_cb");
|
2014-02-27 14:26:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
_gtk_gesture_multi_press_check_within_threshold (GtkGestureMultiPress *gesture,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y)
|
|
|
|
{
|
|
|
|
GtkGestureMultiPressPrivate *priv;
|
|
|
|
guint double_click_distance;
|
|
|
|
GtkSettings *settings;
|
|
|
|
GtkWidget *widget;
|
|
|
|
|
|
|
|
priv = gtk_gesture_multi_press_get_instance_private (gesture);
|
|
|
|
|
|
|
|
if (priv->n_presses == 0)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture));
|
|
|
|
settings = gtk_widget_get_settings (widget);
|
|
|
|
g_object_get (settings,
|
|
|
|
"gtk-double-click-distance", &double_click_distance,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (ABS (priv->initial_press_x - x) < double_click_distance &&
|
|
|
|
ABS (priv->initial_press_y - y) < double_click_distance)
|
|
|
|
{
|
|
|
|
if (!priv->rect_is_set ||
|
|
|
|
(x >= priv->rect.x && x < priv->rect.x + priv->rect.width &&
|
|
|
|
y >= priv->rect.y && y < priv->rect.y + priv->rect.height))
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-05-12 14:56:41 +00:00
|
|
|
gtk_gesture_multi_press_begin (GtkGesture *gesture,
|
|
|
|
GdkEventSequence *sequence)
|
2014-02-27 14:26:48 +00:00
|
|
|
{
|
|
|
|
GtkGestureMultiPress *multi_press;
|
|
|
|
GtkGestureMultiPressPrivate *priv;
|
|
|
|
guint n_presses, button = 1;
|
2014-05-12 14:56:41 +00:00
|
|
|
GdkEventSequence *current;
|
2014-02-27 14:26:48 +00:00
|
|
|
const GdkEvent *event;
|
2017-08-25 14:47:11 +00:00
|
|
|
GdkEventType event_type;
|
2016-02-22 21:38:56 +00:00
|
|
|
GdkDevice *device;
|
2014-02-27 14:26:48 +00:00
|
|
|
gdouble x, y;
|
|
|
|
|
2014-05-12 14:56:41 +00:00
|
|
|
if (!gtk_gesture_handles_sequence (gesture, sequence))
|
|
|
|
return;
|
|
|
|
|
2014-02-27 14:26:48 +00:00
|
|
|
multi_press = GTK_GESTURE_MULTI_PRESS (gesture);
|
|
|
|
priv = gtk_gesture_multi_press_get_instance_private (multi_press);
|
|
|
|
event = gtk_gesture_get_last_event (gesture, sequence);
|
2014-05-12 14:56:41 +00:00
|
|
|
current = gtk_gesture_single_get_current_sequence (GTK_GESTURE_SINGLE (gesture));
|
2016-02-22 21:38:56 +00:00
|
|
|
device = gdk_event_get_source_device (event);
|
2017-08-25 14:47:11 +00:00
|
|
|
event_type = gdk_event_get_event_type (event);
|
2014-02-27 14:26:48 +00:00
|
|
|
|
2017-08-25 14:47:11 +00:00
|
|
|
if (event_type == GDK_BUTTON_PRESS)
|
|
|
|
gdk_event_get_button (event, &button);
|
|
|
|
else if (event_type == GDK_TOUCH_BEGIN)
|
2014-05-12 14:56:41 +00:00
|
|
|
button = 1;
|
|
|
|
else
|
2014-03-21 18:21:56 +00:00
|
|
|
return;
|
|
|
|
|
2014-05-12 14:56:41 +00:00
|
|
|
/* Reset the gesture if the button number changes mid-recognition */
|
|
|
|
if (priv->n_presses > 0 &&
|
|
|
|
priv->current_button != button)
|
|
|
|
_gtk_gesture_multi_press_stop (multi_press);
|
|
|
|
|
2016-02-22 21:38:56 +00:00
|
|
|
/* Reset also if the device changed */
|
|
|
|
if (priv->current_device && priv->current_device != device)
|
|
|
|
_gtk_gesture_multi_press_stop (multi_press);
|
|
|
|
|
|
|
|
priv->current_device = device;
|
2014-05-12 14:56:41 +00:00
|
|
|
priv->current_button = button;
|
|
|
|
_gtk_gesture_multi_press_update_timeout (multi_press);
|
|
|
|
gtk_gesture_get_point (gesture, current, &x, &y);
|
|
|
|
|
|
|
|
if (!_gtk_gesture_multi_press_check_within_threshold (multi_press, x, y))
|
|
|
|
_gtk_gesture_multi_press_stop (multi_press);
|
|
|
|
|
|
|
|
/* Increment later the real counter, just if the gesture is
|
|
|
|
* reset on the pressed handler */
|
2014-05-12 15:02:03 +00:00
|
|
|
n_presses = priv->n_release = priv->n_presses + 1;
|
2014-05-12 14:56:41 +00:00
|
|
|
|
|
|
|
g_signal_emit (gesture, signals[PRESSED], 0, n_presses, x, y);
|
|
|
|
|
|
|
|
if (priv->n_presses == 0)
|
2014-02-27 14:26:48 +00:00
|
|
|
{
|
2014-05-12 14:56:41 +00:00
|
|
|
priv->initial_press_x = x;
|
|
|
|
priv->initial_press_y = y;
|
2014-02-27 14:26:48 +00:00
|
|
|
}
|
2014-05-12 14:56:41 +00:00
|
|
|
|
|
|
|
priv->n_presses++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_gesture_multi_press_update (GtkGesture *gesture,
|
|
|
|
GdkEventSequence *sequence)
|
|
|
|
{
|
|
|
|
GtkGestureMultiPress *multi_press;
|
|
|
|
GdkEventSequence *current;
|
|
|
|
gdouble x, y;
|
|
|
|
|
|
|
|
multi_press = GTK_GESTURE_MULTI_PRESS (gesture);
|
|
|
|
current = gtk_gesture_single_get_current_sequence (GTK_GESTURE_SINGLE (gesture));
|
|
|
|
gtk_gesture_get_point (gesture, current, &x, &y);
|
|
|
|
|
|
|
|
if (!_gtk_gesture_multi_press_check_within_threshold (multi_press, x, y))
|
|
|
|
_gtk_gesture_multi_press_stop (multi_press);
|
|
|
|
}
|
|
|
|
|
2014-05-12 15:02:03 +00:00
|
|
|
static void
|
|
|
|
gtk_gesture_multi_press_end (GtkGesture *gesture,
|
|
|
|
GdkEventSequence *sequence)
|
|
|
|
{
|
|
|
|
GtkGestureMultiPress *multi_press;
|
|
|
|
GtkGestureMultiPressPrivate *priv;
|
|
|
|
GdkEventSequence *current;
|
|
|
|
gdouble x, y;
|
2014-05-12 14:56:41 +00:00
|
|
|
|
2014-05-12 15:02:03 +00:00
|
|
|
multi_press = GTK_GESTURE_MULTI_PRESS (gesture);
|
|
|
|
priv = gtk_gesture_multi_press_get_instance_private (multi_press);
|
|
|
|
current = gtk_gesture_single_get_current_sequence (GTK_GESTURE_SINGLE (gesture));
|
|
|
|
gtk_gesture_get_point (gesture, current, &x, &y);
|
|
|
|
|
2018-01-22 14:20:14 +00:00
|
|
|
if (gtk_gesture_get_sequence_state (gesture, current) != GTK_EVENT_SEQUENCE_DENIED)
|
|
|
|
g_signal_emit (gesture, signals[RELEASED], 0, priv->n_release, x, y);
|
|
|
|
|
2014-05-12 15:02:03 +00:00
|
|
|
priv->n_release = 0;
|
2014-02-27 14:26:48 +00:00
|
|
|
}
|
|
|
|
|
2014-03-24 11:21:38 +00:00
|
|
|
static void
|
|
|
|
gtk_gesture_multi_press_cancel (GtkGesture *gesture,
|
|
|
|
GdkEventSequence *sequence)
|
|
|
|
{
|
2014-05-12 14:56:41 +00:00
|
|
|
_gtk_gesture_multi_press_stop (GTK_GESTURE_MULTI_PRESS (gesture));
|
2014-06-12 23:08:16 +00:00
|
|
|
GTK_GESTURE_CLASS (gtk_gesture_multi_press_parent_class)->cancel (gesture, sequence);
|
2014-03-24 11:21:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_gesture_multi_press_reset (GtkEventController *controller)
|
|
|
|
{
|
|
|
|
_gtk_gesture_multi_press_stop (GTK_GESTURE_MULTI_PRESS (controller));
|
|
|
|
GTK_EVENT_CONTROLLER_CLASS (gtk_gesture_multi_press_parent_class)->reset (controller);
|
|
|
|
}
|
|
|
|
|
2017-11-21 19:14:52 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_gesture_multi_press_handle_event (GtkEventController *controller,
|
|
|
|
const GdkEvent *event)
|
|
|
|
{
|
|
|
|
GtkEventControllerClass *parent_controller;
|
|
|
|
GtkGestureMultiPressPrivate *priv;
|
|
|
|
GdkEventSequence *sequence;
|
|
|
|
guint button;
|
|
|
|
gdouble x, y;
|
|
|
|
|
|
|
|
priv = gtk_gesture_multi_press_get_instance_private (GTK_GESTURE_MULTI_PRESS (controller));
|
|
|
|
parent_controller = GTK_EVENT_CONTROLLER_CLASS (gtk_gesture_multi_press_parent_class);
|
|
|
|
sequence = gdk_event_get_event_sequence (event);
|
|
|
|
|
|
|
|
if (priv->n_presses == 0 &&
|
|
|
|
!gtk_gesture_handles_sequence (GTK_GESTURE (controller), sequence) &&
|
|
|
|
(gdk_event_get_event_type (event) == GDK_BUTTON_RELEASE ||
|
|
|
|
gdk_event_get_event_type (event) == GDK_TOUCH_END))
|
|
|
|
{
|
|
|
|
if (!gdk_event_get_button (event, &button))
|
|
|
|
button = 0;
|
|
|
|
gdk_event_get_coords (event, &x, &y);
|
|
|
|
g_signal_emit (controller, signals[UNPAIRED_RELEASE], 0,
|
|
|
|
x, y, button, sequence);
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent_controller->handle_event (controller, event);
|
|
|
|
}
|
|
|
|
|
2014-02-27 14:26:48 +00:00
|
|
|
static void
|
|
|
|
gtk_gesture_multi_press_class_init (GtkGestureMultiPressClass *klass)
|
|
|
|
{
|
2014-03-24 11:21:38 +00:00
|
|
|
GtkEventControllerClass *controller_class = GTK_EVENT_CONTROLLER_CLASS (klass);
|
2014-02-27 14:26:48 +00:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GtkGestureClass *gesture_class = GTK_GESTURE_CLASS (klass);
|
|
|
|
|
|
|
|
object_class->finalize = gtk_gesture_multi_press_finalize;
|
|
|
|
|
|
|
|
gesture_class->check = gtk_gesture_multi_press_check;
|
2014-05-12 14:56:41 +00:00
|
|
|
gesture_class->begin = gtk_gesture_multi_press_begin;
|
2014-02-27 14:26:48 +00:00
|
|
|
gesture_class->update = gtk_gesture_multi_press_update;
|
2014-05-12 15:02:03 +00:00
|
|
|
gesture_class->end = gtk_gesture_multi_press_end;
|
2014-03-24 11:21:38 +00:00
|
|
|
gesture_class->cancel = gtk_gesture_multi_press_cancel;
|
|
|
|
|
|
|
|
controller_class->reset = gtk_gesture_multi_press_reset;
|
2017-11-21 19:14:52 +00:00
|
|
|
controller_class->handle_event = gtk_gesture_multi_press_handle_event;
|
2014-02-27 14:26:48 +00:00
|
|
|
|
2014-04-09 16:28:03 +00:00
|
|
|
/**
|
2014-04-10 11:43:53 +00:00
|
|
|
* GtkGestureMultiPress::pressed:
|
2014-04-09 16:28:03 +00:00
|
|
|
* @gesture: the object which received the signal
|
|
|
|
* @n_press: how many touch/button presses happened with this one
|
|
|
|
* @x: The X coordinate, in widget allocation coordinates
|
|
|
|
* @y: The Y coordinate, in widget allocation coordinates
|
|
|
|
*
|
|
|
|
* This signal is emitted whenever a button or touch press happens.
|
|
|
|
*/
|
2014-02-27 14:26:48 +00:00
|
|
|
signals[PRESSED] =
|
2015-09-12 13:13:00 +00:00
|
|
|
g_signal_new (I_("pressed"),
|
2014-02-27 14:26:48 +00:00
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (GtkGestureMultiPressClass, pressed),
|
|
|
|
NULL, NULL, NULL,
|
2014-05-12 15:02:03 +00:00
|
|
|
G_TYPE_NONE, 3, G_TYPE_INT,
|
|
|
|
G_TYPE_DOUBLE, G_TYPE_DOUBLE);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GtkGestureMultiPress::released:
|
|
|
|
* @gesture: the object which received the signal
|
|
|
|
* @n_press: number of press that is paired with this release
|
|
|
|
* @x: The X coordinate, in widget allocation coordinates
|
|
|
|
* @y: The Y coordinate, in widget allocation coordinates
|
|
|
|
*
|
|
|
|
* This signal is emitted when a button or touch is released. @n_press
|
|
|
|
* will report the number of press that is paired to this event, note
|
|
|
|
* that #GtkGestureMultiPress::stopped may have been emitted between the
|
|
|
|
* press and its release, @n_press will only start over at the next press.
|
|
|
|
*/
|
|
|
|
signals[RELEASED] =
|
2015-09-12 13:13:00 +00:00
|
|
|
g_signal_new (I_("released"),
|
2014-05-12 15:02:03 +00:00
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (GtkGestureMultiPressClass, released),
|
|
|
|
NULL, NULL, NULL,
|
2014-03-24 11:21:38 +00:00
|
|
|
G_TYPE_NONE, 3, G_TYPE_INT,
|
2014-02-27 14:26:48 +00:00
|
|
|
G_TYPE_DOUBLE, G_TYPE_DOUBLE);
|
2014-04-09 16:28:03 +00:00
|
|
|
/**
|
2014-04-10 11:43:53 +00:00
|
|
|
* GtkGestureMultiPress::stopped:
|
2014-04-09 16:28:03 +00:00
|
|
|
* @gesture: the object which received the signal
|
|
|
|
*
|
|
|
|
* This signal is emitted whenever any time/distance threshold has
|
|
|
|
* been exceeded.
|
|
|
|
*/
|
2014-02-27 14:26:48 +00:00
|
|
|
signals[STOPPED] =
|
2015-09-12 13:13:00 +00:00
|
|
|
g_signal_new (I_("stopped"),
|
2014-02-27 14:26:48 +00:00
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (GtkGestureMultiPressClass, stopped),
|
|
|
|
NULL, NULL, NULL,
|
|
|
|
G_TYPE_NONE, 0);
|
2017-11-21 19:14:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* GtkGestureMultiPress::unpaired-release
|
|
|
|
* @gesture: the object which received the signal
|
|
|
|
* @x: X coordinate of the event
|
|
|
|
* @y: Y coordinate of the event
|
|
|
|
* @button: Button being released
|
|
|
|
* @sequence: Sequence being released
|
|
|
|
*
|
|
|
|
* This signal is emitted whenever the gesture receives a release
|
|
|
|
* event that had no previous corresponding press. Due to implicit
|
|
|
|
* grabs, this can only happen on situations where input is grabbed
|
|
|
|
* elsewhere mid-press or the pressed widget voluntarily relinquishes
|
|
|
|
* its implicit grab.
|
|
|
|
*/
|
|
|
|
signals[UNPAIRED_RELEASE] =
|
|
|
|
g_signal_new (I_("unpaired-release"),
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
0, NULL, NULL, NULL,
|
|
|
|
G_TYPE_NONE, 4,
|
|
|
|
G_TYPE_DOUBLE, G_TYPE_DOUBLE,
|
|
|
|
G_TYPE_UINT, GDK_TYPE_EVENT_SEQUENCE);
|
2014-02-27 14:26:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_gesture_multi_press_init (GtkGestureMultiPress *gesture)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_gesture_multi_press_new:
|
|
|
|
* @widget: a #GtkWidget
|
|
|
|
*
|
|
|
|
* Returns a newly created #GtkGesture that recognizes single and multiple
|
|
|
|
* presses.
|
|
|
|
*
|
|
|
|
* Returns: a newly created #GtkGestureMultiPress
|
|
|
|
**/
|
|
|
|
GtkGesture *
|
|
|
|
gtk_gesture_multi_press_new (GtkWidget *widget)
|
|
|
|
{
|
2014-05-27 18:30:47 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
|
|
|
|
|
2014-02-27 14:26:48 +00:00
|
|
|
return g_object_new (GTK_TYPE_GESTURE_MULTI_PRESS,
|
|
|
|
"widget", widget,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_gesture_multi_press_set_area:
|
2017-04-27 15:54:49 +00:00
|
|
|
* @gesture: a #GtkGestureMultiPress
|
2014-05-20 02:16:03 +00:00
|
|
|
* @rect: (allow-none): rectangle to receive coordinates on
|
2014-02-27 14:26:48 +00:00
|
|
|
*
|
2014-05-20 02:16:03 +00:00
|
|
|
* If @rect is non-%NULL, the press area will be checked to be
|
2014-02-27 14:26:48 +00:00
|
|
|
* confined within the rectangle, otherwise the button count
|
|
|
|
* will be reset so the press is seen as being the first one.
|
2017-11-22 19:19:27 +00:00
|
|
|
* If @rect is %NULL, the area will be reset to an unrestricted
|
2014-02-27 14:26:48 +00:00
|
|
|
* state.
|
|
|
|
*
|
|
|
|
* Note: The rectangle is only used to determine whether any
|
|
|
|
* non-first click falls within the expected area. This is not
|
|
|
|
* akin to an input shape.
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
gtk_gesture_multi_press_set_area (GtkGestureMultiPress *gesture,
|
|
|
|
const GdkRectangle *rect)
|
|
|
|
{
|
|
|
|
GtkGestureMultiPressPrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_GESTURE_MULTI_PRESS (gesture));
|
|
|
|
|
|
|
|
priv = gtk_gesture_multi_press_get_instance_private (gesture);
|
|
|
|
|
|
|
|
if (!rect)
|
|
|
|
priv->rect_is_set = FALSE;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
priv->rect_is_set = TRUE;
|
|
|
|
priv->rect = *rect;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_gesture_multi_press_get_area:
|
|
|
|
* @gesture: a #GtkGestureMultiPress
|
|
|
|
* @rect: (out): return location for the press area
|
|
|
|
*
|
|
|
|
* If an area was set through gtk_gesture_multi_press_set_area(),
|
2014-05-20 02:16:03 +00:00
|
|
|
* this function will return %TRUE and fill in @rect with the
|
2014-02-27 14:26:48 +00:00
|
|
|
* press area. See gtk_gesture_multi_press_set_area() for more
|
|
|
|
* details on what the press area represents.
|
|
|
|
*
|
2014-05-20 02:16:03 +00:00
|
|
|
* Returns: %TRUE if @rect was filled with the press area
|
2014-02-27 14:26:48 +00:00
|
|
|
**/
|
|
|
|
gboolean
|
|
|
|
gtk_gesture_multi_press_get_area (GtkGestureMultiPress *gesture,
|
|
|
|
GdkRectangle *rect)
|
|
|
|
{
|
|
|
|
GtkGestureMultiPressPrivate *priv;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_GESTURE_MULTI_PRESS (gesture), FALSE);
|
|
|
|
|
|
|
|
priv = gtk_gesture_multi_press_get_instance_private (gesture);
|
|
|
|
|
|
|
|
if (rect)
|
|
|
|
{
|
|
|
|
if (priv->rect_is_set)
|
|
|
|
*rect = priv->rect;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rect->x = rect->y = G_MININT;
|
|
|
|
rect->width = rect->height = G_MAXINT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return priv->rect_is_set;
|
|
|
|
}
|