[clutter] drag-action: Allow destroying the dragged actor inside ::drag-end



commit cd67c7fd243025aac080faf50a1848f1d5842915
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Mon Sep 10 09:21:34 2012 +0100

    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

 clutter/clutter-drag-action.c |   35 ++++++++++++++++++++++++++++++++++-
 1 files changed, 34 insertions(+), 1 deletions(-)
---
diff --git a/clutter/clutter-drag-action.c b/clutter/clutter-drag-action.c
index a9aaa49..669240c 100644
--- a/clutter/clutter-drag-action.c
+++ b/clutter/clutter-drag-action.c
@@ -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);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]