drag-action: Allow destroying the dragged actor inside ::drag-end
It should be possible to destroy the actor currently being dragged from within the ::drag-end signal. In order to do this, we need to keep a reference on the action for the duration of the emit_drag_end() function as well as resetting the action's state inside the dispose() implementation, to avoid trying to access cleared data. https://bugzilla.gnome.org/show_bug.cgi?id=681814
This commit is contained in:
parent
c095de8705
commit
cd67c7fd24
@ -295,6 +295,12 @@ emit_drag_end (ClutterDragAction *action,
|
||||
{
|
||||
ClutterDragActionPrivate *priv = action->priv;
|
||||
|
||||
/* ::drag-end may result in the destruction of the actor, which in turn
|
||||
* will lead to the removal and finalization of the action, so we need
|
||||
* to keep the action alive for the entire emission sequence
|
||||
*/
|
||||
g_object_ref (action);
|
||||
|
||||
/* if we have an event, update our own state, otherwise we'll
|
||||
* just use the currently stored state when emitting the ::drag-end
|
||||
* signal
|
||||
@ -315,6 +321,9 @@ emit_drag_end (ClutterDragAction *action,
|
||||
priv->last_motion_x, priv->last_motion_y,
|
||||
priv->last_motion_state);
|
||||
|
||||
if (priv->stage == NULL)
|
||||
goto out;
|
||||
|
||||
/* disconnect the capture */
|
||||
if (priv->capture_id != 0)
|
||||
{
|
||||
@ -325,7 +334,7 @@ emit_drag_end (ClutterDragAction *action,
|
||||
clutter_stage_set_motion_events_enabled (priv->stage,
|
||||
priv->motion_events_enabled);
|
||||
|
||||
if (priv->last_motion_device != NULL)
|
||||
if (priv->last_motion_device != NULL && event != NULL)
|
||||
{
|
||||
if (clutter_event_type (event) == CLUTTER_BUTTON_RELEASE)
|
||||
_clutter_stage_remove_pointer_drag_actor (priv->stage,
|
||||
@ -335,7 +344,11 @@ emit_drag_end (ClutterDragAction *action,
|
||||
priv->sequence);
|
||||
}
|
||||
|
||||
out:
|
||||
priv->last_motion_device = NULL;
|
||||
priv->sequence = NULL;
|
||||
|
||||
g_object_unref (action);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
@ -641,8 +654,28 @@ clutter_drag_action_dispose (GObject *gobject)
|
||||
{
|
||||
ClutterDragActionPrivate *priv = CLUTTER_DRAG_ACTION (gobject)->priv;
|
||||
|
||||
/* if we're being disposed while a capture is still present, we
|
||||
* need to reset the state we are currently holding
|
||||
*/
|
||||
if (priv->last_motion_device != NULL)
|
||||
{
|
||||
_clutter_stage_remove_pointer_drag_actor (priv->stage,
|
||||
priv->last_motion_device);
|
||||
priv->last_motion_device = NULL;
|
||||
}
|
||||
|
||||
if (priv->sequence != NULL)
|
||||
{
|
||||
_clutter_stage_remove_touch_drag_actor (priv->stage,
|
||||
priv->sequence);
|
||||
priv->sequence = NULL;
|
||||
}
|
||||
|
||||
if (priv->capture_id != 0)
|
||||
{
|
||||
clutter_stage_set_motion_events_enabled (priv->stage,
|
||||
priv->motion_events_enabled);
|
||||
|
||||
if (priv->stage != NULL)
|
||||
g_signal_handler_disconnect (priv->stage, priv->capture_id);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user