[gtk/wip/baedert/for-master: 6/23] main: Add & use gdk_event_dup_axes()




commit e6f6d1e478088e1dc51064f7d35e8525f0fef485
Author: Timm Bäder <mail baedert org>
Date:   Thu Dec 17 16:32:31 2020 +0100

    main: Add & use gdk_event_dup_axes()
    
    The way this code is written trips up scan-build. Add
    gdk_event_dup_axes() and use it in gtkmain.c.

 gdk/gdkevents.c        | 16 ++++++++++++++++
 gdk/gdkeventsprivate.h |  2 ++
 gtk/gtkmain.c          | 19 +++----------------
 3 files changed, 21 insertions(+), 16 deletions(-)
---
diff --git a/gdk/gdkevents.c b/gdk/gdkevents.c
index 141a95a283..a174859a35 100644
--- a/gdk/gdkevents.c
+++ b/gdk/gdkevents.c
@@ -1138,6 +1138,22 @@ gdk_event_get_axes (GdkEvent  *event,
   return GDK_EVENT_GET_CLASS (event)->get_axes (event, axes, n_axes);
 }
 
+double *
+gdk_event_dup_axes (GdkEvent *event)
+{
+  double *axes;
+  guint n_axes;
+
+  if (gdk_event_get_axes (event, &axes, &n_axes))
+    {
+      double *axes_copy = g_memdup (axes, n_axes * sizeof (double));
+
+      return axes_copy;
+    }
+
+  return NULL;
+}
+
 /**
  * gdk_event_get_event_type:
  * @event: a #GdkEvent
diff --git a/gdk/gdkeventsprivate.h b/gdk/gdkeventsprivate.h
index cfc7ab09ab..aca69d551f 100644
--- a/gdk/gdkeventsprivate.h
+++ b/gdk/gdkeventsprivate.h
@@ -603,6 +603,8 @@ void    _gdk_event_queue_handle_motion_compression (GdkDisplay *display);
 void    gdk_event_queue_handle_scroll_compression  (GdkDisplay *display);
 void    _gdk_event_queue_flush                     (GdkDisplay       *display);
 
+double * gdk_event_dup_axes (GdkEvent *event);
+
 
 G_END_DECLS
 
diff --git a/gtk/gtkmain.c b/gtk/gtkmain.c
index 60e4a7b580..498b4ec8d4 100644
--- a/gtk/gtkmain.c
+++ b/gtk/gtkmain.c
@@ -936,8 +936,6 @@ rewrite_event_for_surface (GdkEvent  *event,
   GdkEventType type;
   double x, y;
   double dx, dy;
-  double *axes = NULL;
-  guint n_axes = 0;
 
   type = gdk_event_get_event_type (event);
 
@@ -960,16 +958,6 @@ rewrite_event_for_surface (GdkEvent  *event,
       break;
     }
 
-  if (gdk_event_get_axes (event, &axes, &n_axes))
-    {
-      double *axes_copy = g_memdup (axes, n_axes * sizeof (double));
-
-      /* The newly created event takes ownership of the axes, so
-       * we need a copy
-       */
-      axes = axes_copy;
-    }
-
   switch ((guint) type)
     {
     case GDK_BUTTON_PRESS:
@@ -982,7 +970,7 @@ rewrite_event_for_surface (GdkEvent  *event,
                                    gdk_event_get_modifier_state (event),
                                    gdk_button_event_get_button (event),
                                    x, y,
-                                   g_steal_pointer (&axes));
+                                   gdk_event_dup_axes (event));
     case GDK_MOTION_NOTIFY:
       return gdk_motion_event_new (new_surface,
                                    gdk_event_get_device (event),
@@ -990,7 +978,7 @@ rewrite_event_for_surface (GdkEvent  *event,
                                    gdk_event_get_time (event),
                                    gdk_event_get_modifier_state (event),
                                    x, y,
-                                   g_steal_pointer (&axes));
+                                   gdk_event_dup_axes (event));
     case GDK_TOUCH_BEGIN:
     case GDK_TOUCH_UPDATE:
     case GDK_TOUCH_END:
@@ -1002,7 +990,7 @@ rewrite_event_for_surface (GdkEvent  *event,
                                   gdk_event_get_time (event),
                                   gdk_event_get_modifier_state (event),
                                   x, y,
-                                  g_steal_pointer (&axes),
+                                  gdk_event_dup_axes (event),
                                   gdk_touch_event_get_emulating_pointer (event));
     case GDK_TOUCHPAD_SWIPE:
       gdk_touchpad_event_get_deltas (event, &dx, &dy);
@@ -1030,7 +1018,6 @@ rewrite_event_for_surface (GdkEvent  *event,
       break;
     }
 
-  g_assert (!axes);
   return NULL;
 }
 


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