Esempio n. 1
0
/**
 * st_button_fake_release:
 * @button: an #StButton
 *
 * If this widget is holding a pointer grab, this function will
 * will ungrab it, and reset the pressed state.  The effect is
 * similar to if the user had released the mouse button, but without
 * emitting the clicked signal.
 *
 * This function is useful if for example you want to do something
 * after the user is holding the mouse button for a given period of
 * time, breaking the grab.
 */
void
st_button_fake_release (StButton *button)
{
  StButtonPrivate *priv;

  g_return_if_fail (ST_IS_BUTTON (button));

  priv = st_button_get_instance_private (button);
  if (priv->device && priv->press_sequence)
    {
      clutter_input_device_sequence_ungrab (priv->device,
                                            priv->press_sequence);
    }

  if (priv->pressed || priv->press_sequence)
    st_button_release (button, priv->device,
                       priv->pressed, 0, NULL);

  if (priv->grabbed)
    {
      priv->grabbed = 0;
      clutter_ungrab_pointer ();
    }

  priv->device = NULL;
}
Esempio n. 2
0
static gboolean
st_button_touch_event (ClutterActor      *actor,
                       ClutterTouchEvent *event)
{
  StButton *button = ST_BUTTON (actor);
  StButtonPrivate *priv = st_button_get_instance_private (button);
  StButtonMask mask = ST_BUTTON_MASK_FROM_BUTTON (1);
  ClutterEventSequence *sequence;
  ClutterInputDevice *device;

  if (priv->pressed != 0)
    return CLUTTER_EVENT_PROPAGATE;

  device = clutter_event_get_device ((ClutterEvent*) event);
  sequence = clutter_event_get_event_sequence ((ClutterEvent*) event);

  if (event->type == CLUTTER_TOUCH_BEGIN && !priv->press_sequence)
    {
      clutter_input_device_sequence_grab (device, sequence, actor);
      st_button_press (button, device, 0, sequence);
      return CLUTTER_EVENT_STOP;
    }
  else if (event->type == CLUTTER_TOUCH_END &&
           priv->device == device &&
           priv->press_sequence == sequence)
    {
      st_button_release (button, device, mask, 0, sequence);
      clutter_input_device_sequence_ungrab (device, sequence);
      return CLUTTER_EVENT_STOP;
    }

  return CLUTTER_EVENT_PROPAGATE;
}