Exemplo n.º 1
0
static void
gtk_gesture_long_press_update (GtkGesture       *gesture,
                               GdkEventSequence *sequence)
{
  GtkGestureLongPressPrivate *priv;
  GtkWidget *widget;
  gdouble x, y;

  widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture));
  priv = gtk_gesture_long_press_get_instance_private (GTK_GESTURE_LONG_PRESS (gesture));
  gtk_gesture_get_point (gesture, sequence, &x, &y);

  if (gtk_drag_check_threshold (widget, priv->initial_x, priv->initial_y, x, y))
    {
      if (priv->timeout_id)
        {
          g_source_remove (priv->timeout_id);
          priv->timeout_id = 0;
          g_signal_emit (gesture, signals[CANCELLED], 0);
        }

      priv->cancelled = TRUE;
      _gtk_gesture_check (gesture);
    }
}
Exemplo n.º 2
0
static void
gtk_gesture_long_press_begin (GtkGesture       *gesture,
                              GdkEventSequence *sequence)
{
  GtkGestureLongPressPrivate *priv;
  const GdkEvent *event;
  GtkWidget *widget;
  gint delay;

  priv = gtk_gesture_long_press_get_instance_private (GTK_GESTURE_LONG_PRESS (gesture));
  sequence = gtk_gesture_single_get_current_sequence (GTK_GESTURE_SINGLE (gesture));
  event = gtk_gesture_get_last_event (gesture, sequence);

  if (!event ||
      (event->type != GDK_BUTTON_PRESS &&
       event->type != GDK_TOUCH_BEGIN))
    return;

  widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture));
  g_object_get (gtk_widget_get_settings (widget),
                "gtk-long-press-time", &delay,
                NULL);

  delay = (gint)(priv->delay_factor * delay);

  gtk_gesture_get_point (gesture, sequence,
                         &priv->initial_x, &priv->initial_y);
  priv->timeout_id =
    gdk_threads_add_timeout (delay,
                             _gtk_gesture_long_press_timeout,
                             gesture);
}
Exemplo n.º 3
0
static void
gtk_gesture_multi_press_begin (GtkGesture       *gesture,
                               GdkEventSequence *sequence)
{
    GtkGestureMultiPress *multi_press;
    GtkGestureMultiPressPrivate *priv;
    guint n_presses, button = 1;
    GdkEventSequence *current;
    const GdkEvent *event;
    GdkDevice *device;
    gdouble x, y;

    if (!gtk_gesture_handles_sequence (gesture, sequence))
        return;

    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);
    current = gtk_gesture_single_get_current_sequence (GTK_GESTURE_SINGLE (gesture));
    device = gdk_event_get_source_device (event);

    if (event->type == GDK_BUTTON_PRESS)
        button = event->button.button;
    else if (event->type == GDK_TOUCH_BEGIN)
        button = 1;
    else
        return;

    /* 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);

    /* 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;
    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 */
    n_presses = priv->n_release = priv->n_presses + 1;

    g_signal_emit (gesture, signals[PRESSED], 0, n_presses, x, y);

    if (priv->n_presses == 0)
    {
        priv->initial_press_x = x;
        priv->initial_press_y = y;
    }

    priv->n_presses++;
}
Exemplo n.º 4
0
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);
}
Exemplo n.º 5
0
static void
gtk_gesture_multi_press_end (GtkGesture       *gesture,
                             GdkEventSequence *sequence)
{
    GtkGestureMultiPress *multi_press;
    GtkGestureMultiPressPrivate *priv;
    GdkEventSequence *current;
    gdouble x, y;

    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);

    g_signal_emit (gesture, signals[RELEASED], 0, priv->n_release, x, y);
    priv->n_release = 0;
}
Exemplo n.º 6
0
static gboolean
_gtk_gesture_long_press_timeout (gpointer user_data)
{
  GtkGestureLongPress *gesture = user_data;
  GtkGestureLongPressPrivate *priv;
  GdkEventSequence *sequence;
  gdouble x, y;

  priv = gtk_gesture_long_press_get_instance_private (gesture);
  sequence = gtk_gesture_get_last_updated_sequence (GTK_GESTURE (gesture));
  gtk_gesture_get_point (GTK_GESTURE (gesture), sequence, &x, &y);

  priv->timeout_id = 0;
  priv->triggered = TRUE;
  g_signal_emit (gesture, signals[PRESSED], 0, x, y);

  return G_SOURCE_REMOVE;
}
Exemplo n.º 7
0
static void
gtk_gesture_multi_press_end (GtkGesture       *gesture,
                             GdkEventSequence *sequence)
{
  GtkGestureMultiPress *multi_press;
  GtkGestureMultiPressPrivate *priv;
  GdkEventSequence *current;
  gdouble x, y;
  gboolean interpreted;
  GtkEventSequenceState state;

  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));
  interpreted = gtk_gesture_get_point (gesture, current, &x, &y);
  state = gtk_gesture_get_sequence_state (gesture, current);

  if (state != GTK_EVENT_SEQUENCE_DENIED && interpreted)
    g_signal_emit (gesture, signals[RELEASED], 0, priv->n_release, x, y);

  priv->n_release = 0;
}
Exemplo n.º 8
0
static void
multipress_gesture_update_cb (GtkGesture       *gesture,
                              GdkEventSequence *sequence,
                              GtkButton        *button)
{
  GtkButtonPrivate *priv = button->priv;
  GtkAllocation allocation;
  gboolean in_button;
  gdouble x, y;

  if (sequence != gtk_gesture_single_get_current_sequence (GTK_GESTURE_SINGLE (gesture)))
    return;

  gtk_widget_get_allocation (GTK_WIDGET (button), &allocation);
  gtk_gesture_get_point (gesture, sequence, &x, &y);

  in_button = (x >= 0 && y >= 0 && x < allocation.width && y < allocation.height);

  if (priv->in_button != in_button)
    {
      priv->in_button = in_button;
      gtk_button_update_state (button);
    }
}