st: Use ClutterGrab for StButton implicit grab

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2045>
This commit is contained in:
Carlos Garnacho 2021-11-18 00:00:01 +01:00
parent a4797390fc
commit bcfcacdb56

View File

@ -76,6 +76,7 @@ struct _StButtonPrivate
ClutterInputDevice *device; ClutterInputDevice *device;
ClutterEventSequence *press_sequence; ClutterEventSequence *press_sequence;
ClutterGrab *grab;
guint button_mask : 3; guint button_mask : 3;
guint is_toggle : 1; guint is_toggle : 1;
@ -191,8 +192,12 @@ st_button_button_press (ClutterActor *actor,
if (priv->button_mask & mask) if (priv->button_mask & mask)
{ {
ClutterActor *stage;
stage = clutter_actor_get_stage (actor);
if (priv->grabbed == 0) if (priv->grabbed == 0)
clutter_input_device_grab (device, actor); priv->grab = clutter_stage_grab (CLUTTER_STAGE (stage), actor);
priv->grabbed |= mask; priv->grabbed |= mask;
st_button_press (button, device, mask, NULL); st_button_press (button, device, mask, NULL);
@ -220,8 +225,11 @@ st_button_button_release (ClutterActor *actor,
st_button_release (button, device, mask, is_click ? event->button : 0, NULL); st_button_release (button, device, mask, is_click ? event->button : 0, NULL);
priv->grabbed &= ~mask; priv->grabbed &= ~mask;
if (priv->grabbed == 0) if (priv->grab && priv->grabbed == 0)
clutter_input_device_ungrab (device); {
clutter_grab_dismiss (priv->grab);
g_clear_pointer (&priv->grab, clutter_grab_unref);
}
return TRUE; return TRUE;
} }
@ -247,21 +255,16 @@ st_button_touch_event (ClutterActor *actor,
device = clutter_event_get_device ((ClutterEvent*) event); device = clutter_event_get_device ((ClutterEvent*) event);
sequence = clutter_event_get_event_sequence ((ClutterEvent*) event); sequence = clutter_event_get_event_sequence ((ClutterEvent*) event);
if (event->type == CLUTTER_TOUCH_BEGIN && !priv->press_sequence) if (event->type == CLUTTER_TOUCH_BEGIN && !priv->grab && !priv->press_sequence)
{ {
clutter_input_device_sequence_grab (device, sequence, actor); st_button_press (button, device, 0, sequence);
if (!clutter_event_is_pointer_emulated ((ClutterEvent*) event))
st_button_press (button, device, 0, sequence);
return CLUTTER_EVENT_STOP; return CLUTTER_EVENT_STOP;
} }
else if (event->type == CLUTTER_TOUCH_END && else if (event->type == CLUTTER_TOUCH_END &&
priv->device == device && priv->device == device &&
priv->press_sequence == sequence) priv->press_sequence == sequence)
{ {
if (!clutter_event_is_pointer_emulated ((ClutterEvent*) event)) st_button_release (button, device, mask, 0, sequence);
st_button_release (button, device, mask, 0, sequence);
clutter_input_device_sequence_ungrab (device, sequence);
return CLUTTER_EVENT_STOP; return CLUTTER_EVENT_STOP;
} }
else if (event->type == CLUTTER_TOUCH_CANCEL) else if (event->type == CLUTTER_TOUCH_CANCEL)
@ -810,17 +813,15 @@ st_button_fake_release (StButton *button)
g_return_if_fail (ST_IS_BUTTON (button)); g_return_if_fail (ST_IS_BUTTON (button));
priv = st_button_get_instance_private (button); priv = st_button_get_instance_private (button);
if (priv->device && priv->press_sequence)
if (priv->grab)
{ {
clutter_input_device_sequence_ungrab (priv->device, clutter_grab_dismiss (priv->grab);
priv->press_sequence); g_clear_pointer (&priv->grab, clutter_grab_unref);
}
else if (priv->grabbed)
{
priv->grabbed = 0;
clutter_input_device_ungrab (priv->device);
} }
priv->grabbed = 0;
if (priv->pressed || priv->press_sequence) if (priv->pressed || priv->press_sequence)
st_button_release (button, priv->device, st_button_release (button, priv->device,
priv->pressed, 0, NULL); priv->pressed, 0, NULL);