[gtk+/wip/carlosg/event-as-object: 21/23] gtk: Avoid some event copies



commit 81c55bae462478f6d3962b79e1f31732b7218a26
Author: Carlos Garnacho <carlosg gnome org>
Date:   Tue Oct 31 13:55:33 2017 +0100

    gtk: Avoid some event copies
    
    Those places can do with an extra reference.

 gtk/gtkdnd.c        |    4 ++--
 gtk/gtkdragsource.c |    7 ++-----
 gtk/gtkentry.c      |    2 +-
 gtk/gtkgesture.c    |    2 +-
 gtk/gtktextview.c   |    2 +-
 5 files changed, 7 insertions(+), 10 deletions(-)
---
diff --git a/gtk/gtkdnd.c b/gtk/gtkdnd.c
index 0dd4d65..6ff7ad5 100644
--- a/gtk/gtkdnd.c
+++ b/gtk/gtkdnd.c
@@ -1459,7 +1459,7 @@ gtk_drag_begin_internal (GtkWidget          *widget,
  *
  * 3. During a timeout handler, if you want to start a drag after the mouse
  * button is held down for some time.  Try to save the last event that you got
- * from the mouse, using gdk_event_copy(), and pass it to this function
+ * from the mouse, using g_object_ref(), and pass it to this function
  * (remember to free the event with g_object_unref() when you are done).
  * If you can really not pass a real event, pass #NULL instead.
  *
@@ -2146,7 +2146,7 @@ gtk_drag_update (GtkDragSourceInfo *info,
   info->cur_y = y_root;
   g_clear_object (&info->last_event);
   if (event)
-    info->last_event = gdk_event_copy ((GdkEvent *)event);
+    info->last_event = g_object_ref ((GdkEvent *)event);
 
   gtk_drag_add_update_idle (info);
 }
diff --git a/gtk/gtkdragsource.c b/gtk/gtkdragsource.c
index 5518a72..8fc5777 100644
--- a/gtk/gtkdragsource.c
+++ b/gtk/gtkdragsource.c
@@ -86,11 +86,11 @@ gtk_drag_source_event_cb (GtkWidget *widget,
                                     start_x + offset_x, start_y + offset_y))
         {
           GdkEventSequence *sequence;
-          GdkEvent *last_event;
+          const GdkEvent *last_event;
           guint button;
 
           sequence = gtk_gesture_single_get_current_sequence (GTK_GESTURE_SINGLE (site->drag_gesture));
-          last_event = gdk_event_copy (gtk_gesture_get_last_event (site->drag_gesture, sequence));
+          last_event = gtk_gesture_get_last_event (site->drag_gesture, sequence);
 
           button = gtk_gesture_single_get_current_button (GTK_GESTURE_SINGLE (site->drag_gesture));
           gtk_event_controller_reset (GTK_EVENT_CONTROLLER (site->drag_gesture));
@@ -98,9 +98,6 @@ gtk_drag_source_event_cb (GtkWidget *widget,
           gtk_drag_begin_internal (widget, site->image_def, site->target_list,
                                    site->actions, button, last_event,
                                    start_x, start_y);
-
-          g_object_unref (last_event);
-
           return TRUE;
         }
     }
diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c
index 433a482..2197bdd 100644
--- a/gtk/gtkentry.c
+++ b/gtk/gtkentry.c
@@ -8581,7 +8581,7 @@ gtk_entry_do_popup (GtkEntry       *entry,
    * we get them, then we actually pop up the menu.
    */
   info->entry = g_object_ref (entry);
-  info->trigger_event = event ? gdk_event_copy (event) : gtk_get_current_event ();
+  info->trigger_event = event ? g_object_ref (event) : gtk_get_current_event ();
 
   gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_CLIPBOARD),
                                  gdk_atom_intern_static_string ("TARGETS"),
diff --git a/gtk/gtkgesture.c b/gtk/gtkgesture.c
index fddbe23..53cc0a0 100644
--- a/gtk/gtkgesture.c
+++ b/gtk/gtkgesture.c
@@ -531,7 +531,7 @@ _gtk_gesture_update_point (GtkGesture     *gesture,
   if (data->event)
     g_object_unref (data->event);
 
-  data->event = gdk_event_copy (event);
+  data->event = g_object_ref (event);
   _update_touchpad_deltas (data);
   _update_widget_coordinates (gesture, data);
 
diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c
index 133c9d4..5654e5e 100644
--- a/gtk/gtktextview.c
+++ b/gtk/gtktextview.c
@@ -9373,7 +9373,7 @@ gtk_text_view_do_popup (GtkTextView    *text_view,
    * we get them, then we actually pop up the menu.
    */
   info->text_view = g_object_ref (text_view);
-  info->trigger_event = event ? gdk_event_copy (event) : gtk_get_current_event ();
+  info->trigger_event = event ? g_object_ref (event) : gtk_get_current_event ();
 
   gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (text_view),
                                                            GDK_SELECTION_CLIPBOARD),


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