Blame SOURCES/0008-clutter-event-Use-all-events-Hash-table-as-a-Set-wit.patch

79df40
From 1a5275cdb099e3b15f82cabdd55d2eb6c5196c39 Mon Sep 17 00:00:00 2001
79df40
From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= <mail@3v1n0.net>
79df40
Date: Thu, 11 Jul 2019 13:32:01 +0200
79df40
Subject: [PATCH 08/28] clutter/event: Use all-events Hash table as a Set with
79df40
 auto deletion
79df40
79df40
Avoid allocating memory for the value, since we don't use it, just add the key
79df40
to the table, and check for its presence.
79df40
79df40
Use a custom free function to free the event data and unref the GOBjects, so
79df40
that in clutter_event_free we don't have to both check for the event presence
79df40
in the set, clear the data and eventually remove it from the table, but we
79df40
can just rely on a single g_hash_table_remove() call.
79df40
79df40
This required to change the event data free/copy functions signatures so that
79df40
we can pass to them the platform data directly, otherwise we might try to call
79df40
get_platform_data on an even that has already been removed from the table, and
79df40
thus that is not considered allocated anymore, causing a leak.
79df40
79df40
https://gitlab.gnome.org/GNOME/mutter/merge_requests/682
79df40
---
79df40
 clutter/clutter/clutter-backend-private.h     | 16 +++----
79df40
 clutter/clutter/clutter-backend.c             | 21 ++++-----
79df40
 .../clutter/clutter-device-manager-private.h  |  7 ++-
79df40
 clutter/clutter/clutter-event.c               | 45 +++++++++++--------
79df40
 .../evdev/clutter-device-manager-evdev.c      | 15 +++----
79df40
 .../clutter/x11/clutter-device-manager-xi2.c  | 17 +++----
79df40
 6 files changed, 60 insertions(+), 61 deletions(-)
79df40
79df40
diff --git a/clutter/clutter/clutter-backend-private.h b/clutter/clutter/clutter-backend-private.h
79df40
index 864d896a3..2438f83e1 100644
79df40
--- a/clutter/clutter/clutter-backend-private.h
79df40
+++ b/clutter/clutter/clutter-backend-private.h
79df40
@@ -63,100 +63,98 @@ struct _ClutterBackend
79df40
 };
79df40
 
79df40
 struct _ClutterBackendClass
79df40
 {
79df40
   /*< private >*/
79df40
   GObjectClass parent_class;
79df40
 
79df40
   /* vfuncs */
79df40
   gboolean              (* pre_parse)          (ClutterBackend  *backend,
79df40
                                                 GError         **error);
79df40
   gboolean              (* post_parse)         (ClutterBackend  *backend,
79df40
                                                 GError         **error);
79df40
   ClutterStageWindow *  (* create_stage)       (ClutterBackend  *backend,
79df40
                                                 ClutterStage    *wrapper,
79df40
                                                 GError         **error);
79df40
   void                  (* init_events)        (ClutterBackend  *backend);
79df40
   void                  (* init_features)      (ClutterBackend  *backend);
79df40
   void                  (* add_options)        (ClutterBackend  *backend,
79df40
                                                 GOptionGroup    *group);
79df40
   ClutterFeatureFlags   (* get_features)       (ClutterBackend  *backend);
79df40
   CoglRenderer *        (* get_renderer)       (ClutterBackend  *backend,
79df40
                                                 GError         **error);
79df40
   CoglDisplay *         (* get_display)        (ClutterBackend  *backend,
79df40
                                                 CoglRenderer    *renderer,
79df40
                                                 CoglSwapChain   *swap_chain,
79df40
                                                 GError         **error);
79df40
   gboolean              (* create_context)     (ClutterBackend  *backend,
79df40
                                                 GError         **error);
79df40
   ClutterDeviceManager *(* get_device_manager) (ClutterBackend  *backend);
79df40
 
79df40
-  void                  (* copy_event_data)    (ClutterBackend     *backend,
79df40
-                                                const ClutterEvent *src,
79df40
-                                                ClutterEvent       *dest);
79df40
-  void                  (* free_event_data)    (ClutterBackend     *backend,
79df40
-                                                ClutterEvent       *event);
79df40
+  gpointer              (* copy_event_data)    (ClutterBackend *backend,
79df40
+                                                gpointer        data);
79df40
+  void                  (* free_event_data)    (ClutterBackend *backend,
79df40
+                                                gpointer        data);
79df40
 
79df40
   gboolean              (* translate_event)    (ClutterBackend     *backend,
79df40
                                                 gpointer            native,
79df40
                                                 ClutterEvent       *event);
79df40
 
79df40
   PangoDirection        (* get_keymap_direction) (ClutterBackend   *backend);
79df40
 
79df40
   void                  (* bell_notify)          (ClutterBackend   *backend);
79df40
 
79df40
   /* signals */
79df40
   void (* resolution_changed) (ClutterBackend *backend);
79df40
   void (* font_changed)       (ClutterBackend *backend);
79df40
   void (* settings_changed)   (ClutterBackend *backend);
79df40
 };
79df40
 
79df40
 ClutterBackend *        _clutter_create_backend                         (void);
79df40
 
79df40
 ClutterStageWindow *    _clutter_backend_create_stage                   (ClutterBackend         *backend,
79df40
                                                                          ClutterStage           *wrapper,
79df40
                                                                          GError                **error);
79df40
 gboolean                _clutter_backend_create_context                 (ClutterBackend         *backend,
79df40
                                                                          GError                **error);
79df40
 
79df40
 void                    _clutter_backend_add_options                    (ClutterBackend         *backend,
79df40
                                                                          GOptionGroup           *group);
79df40
 gboolean                _clutter_backend_pre_parse                      (ClutterBackend         *backend,
79df40
                                                                          GError                **error);
79df40
 gboolean                _clutter_backend_post_parse                     (ClutterBackend         *backend,
79df40
                                                                          GError                **error);
79df40
 
79df40
 void                    _clutter_backend_init_events                    (ClutterBackend         *backend);
79df40
-void                    _clutter_backend_copy_event_data                (ClutterBackend         *backend,
79df40
-                                                                         const ClutterEvent     *src,
79df40
-                                                                         ClutterEvent           *dest);
79df40
+gpointer                _clutter_backend_copy_event_data                (ClutterBackend         *backend,
79df40
+                                                                         const gpointer          data);
79df40
 void                    _clutter_backend_free_event_data                (ClutterBackend         *backend,
79df40
-                                                                         ClutterEvent           *event);
79df40
+                                                                         gpointer                data);
79df40
 gboolean                _clutter_backend_translate_event                (ClutterBackend         *backend,
79df40
                                                                          gpointer                native,
79df40
                                                                          ClutterEvent           *event);
79df40
 
79df40
 CLUTTER_AVAILABLE_IN_MUTTER
79df40
 void                    _clutter_backend_add_event_translator           (ClutterBackend         *backend,
79df40
                                                                          ClutterEventTranslator *translator);
79df40
 
79df40
 void                    _clutter_backend_remove_event_translator        (ClutterBackend         *backend,
79df40
                                                                          ClutterEventTranslator *translator);
79df40
 
79df40
 ClutterFeatureFlags     _clutter_backend_get_features                   (ClutterBackend         *backend);
79df40
 
79df40
 gfloat                  _clutter_backend_get_units_per_em               (ClutterBackend         *backend,
79df40
                                                                          PangoFontDescription   *font_desc);
79df40
 gint32                  _clutter_backend_get_units_serial               (ClutterBackend         *backend);
79df40
 
79df40
 PangoDirection          _clutter_backend_get_keymap_direction           (ClutterBackend         *backend);
79df40
 
79df40
 CLUTTER_AVAILABLE_IN_MUTTER
79df40
 void                    _clutter_backend_reset_cogl_framebuffer         (ClutterBackend         *backend);
79df40
 
79df40
 void                    clutter_set_allowed_drivers                     (const char             *drivers);
79df40
 
79df40
 void                    clutter_try_set_windowing_backend               (const char             *drivers);
79df40
 
79df40
 G_END_DECLS
79df40
 
79df40
 #endif /* __CLUTTER_BACKEND_PRIVATE_H__ */
79df40
diff --git a/clutter/clutter/clutter-backend.c b/clutter/clutter/clutter-backend.c
79df40
index 69aeec5eb..41ea3daed 100644
79df40
--- a/clutter/clutter/clutter-backend.c
79df40
+++ b/clutter/clutter/clutter-backend.c
79df40
@@ -804,96 +804,97 @@ _clutter_backend_get_features (ClutterBackend *backend)
79df40
     return klass->get_features (backend);
79df40
   
79df40
   return 0;
79df40
 }
79df40
 
79df40
 void
79df40
 _clutter_backend_init_events (ClutterBackend *backend)
79df40
 {
79df40
   ClutterBackendClass *klass;
79df40
 
79df40
   g_assert (CLUTTER_IS_BACKEND (backend));
79df40
 
79df40
   klass = CLUTTER_BACKEND_GET_CLASS (backend);
79df40
   klass->init_events (backend);
79df40
 }
79df40
 
79df40
 gfloat
79df40
 _clutter_backend_get_units_per_em (ClutterBackend       *backend,
79df40
                                    PangoFontDescription *font_desc)
79df40
 {
79df40
   /* recompute for the font description, but do not cache the result */
79df40
   if (font_desc != NULL)
79df40
     return get_units_per_em (backend, font_desc);
79df40
 
79df40
   if (backend->units_per_em < 0)
79df40
     backend->units_per_em = get_units_per_em (backend, NULL);
79df40
 
79df40
   return backend->units_per_em;
79df40
 }
79df40
 
79df40
-void
79df40
-_clutter_backend_copy_event_data (ClutterBackend     *backend,
79df40
-                                  const ClutterEvent *src,
79df40
-                                  ClutterEvent       *dest)
79df40
+gpointer
79df40
+_clutter_backend_copy_event_data (ClutterBackend *backend,
79df40
+                                  gpointer        data)
79df40
 {
79df40
   ClutterEventExtenderInterface *iface;
79df40
   ClutterBackendClass *klass;
79df40
 
79df40
   klass = CLUTTER_BACKEND_GET_CLASS (backend);
79df40
   if (CLUTTER_IS_EVENT_EXTENDER (backend->device_manager))
79df40
     {
79df40
       iface = CLUTTER_EVENT_EXTENDER_GET_IFACE (backend->device_manager);
79df40
-      iface->copy_event_data (CLUTTER_EVENT_EXTENDER (backend->device_manager),
79df40
-                              src, dest);
79df40
+      return iface->copy_event_data (CLUTTER_EVENT_EXTENDER (backend->device_manager),
79df40
+                                     data);
79df40
     }
79df40
   else if (klass->copy_event_data != NULL)
79df40
-    klass->copy_event_data (backend, src, dest);
79df40
+    return klass->copy_event_data (backend, data);
79df40
+
79df40
+  return NULL;
79df40
 }
79df40
 
79df40
 void
79df40
 _clutter_backend_free_event_data (ClutterBackend *backend,
79df40
-                                  ClutterEvent   *event)
79df40
+                                  gpointer        data)
79df40
 {
79df40
   ClutterEventExtenderInterface *iface;
79df40
   ClutterBackendClass *klass;
79df40
 
79df40
   klass = CLUTTER_BACKEND_GET_CLASS (backend);
79df40
 
79df40
   if (CLUTTER_IS_EVENT_EXTENDER (backend->device_manager))
79df40
     {
79df40
       iface = CLUTTER_EVENT_EXTENDER_GET_IFACE (backend->device_manager);
79df40
       iface->free_event_data (CLUTTER_EVENT_EXTENDER (backend->device_manager),
79df40
-                              event);
79df40
+                              data);
79df40
     }
79df40
   else if (klass->free_event_data != NULL)
79df40
-    klass->free_event_data (backend, event);
79df40
+    klass->free_event_data (backend, data);
79df40
 }
79df40
 
79df40
 /**
79df40
  * clutter_get_default_backend:
79df40
  *
79df40
  * Retrieves the default #ClutterBackend used by Clutter. The
79df40
  * #ClutterBackend holds backend-specific configuration options.
79df40
  *
79df40
  * Return value: (transfer none): the default backend. You should
79df40
  *   not ref or unref the returned object. Applications should rarely
79df40
  *   need to use this.
79df40
  *
79df40
  * Since: 0.4
79df40
  */
79df40
 ClutterBackend *
79df40
 clutter_get_default_backend (void)
79df40
 {
79df40
   ClutterMainContext *clutter_context;
79df40
 
79df40
   clutter_context = _clutter_context_get_default ();
79df40
 
79df40
   return clutter_context->backend;
79df40
 }
79df40
 
79df40
 /**
79df40
  * clutter_backend_set_double_click_time:
79df40
  * @backend: a #ClutterBackend
79df40
  * @msec: milliseconds between two button press events
79df40
  *
79df40
  * Sets the maximum time between two button press events, used to
79df40
diff --git a/clutter/clutter/clutter-device-manager-private.h b/clutter/clutter/clutter-device-manager-private.h
79df40
index 2364fd27c..6b2c20c72 100644
79df40
--- a/clutter/clutter/clutter-device-manager-private.h
79df40
+++ b/clutter/clutter/clutter-device-manager-private.h
79df40
@@ -159,65 +159,64 @@ struct _ClutterInputDeviceClass
79df40
                              ClutterInputDeviceTool *tool);
79df40
 
79df40
   gboolean (* is_mode_switch_button) (ClutterInputDevice *device,
79df40
                                       guint               group,
79df40
                                       guint               button);
79df40
   gint (* get_group_n_modes) (ClutterInputDevice *device,
79df40
                               gint                group);
79df40
 
79df40
   gboolean (* is_grouped) (ClutterInputDevice *device,
79df40
                            ClutterInputDevice *other_device);
79df40
 
79df40
   /* Keyboard accessbility */
79df40
   void (* process_kbd_a11y_event) (ClutterEvent               *event,
79df40
                                    ClutterInputDevice         *device,
79df40
                                    ClutterEmitInputDeviceEvent emit_event_func);
79df40
 };
79df40
 
79df40
 /* Platform-dependent interface */
79df40
 typedef struct _ClutterEventExtender ClutterEventExtender;
79df40
 typedef struct _ClutterEventExtenderInterface ClutterEventExtenderInterface;
79df40
 
79df40
 #define CLUTTER_TYPE_EVENT_EXTENDER         (clutter_event_extender_get_type ())
79df40
 #define CLUTTER_EVENT_EXTENDER(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), CLUTTER_TYPE_EVENT_EXTENDER, ClutterEventExtender))
79df40
 #define CLUTTER_IS_EVENT_EXTENDER(o)	     (G_TYPE_CHECK_INSTANCE_TYPE ((o), CLUTTER_TYPE_EVENT_EXTENDER))
79df40
 #define CLUTTER_EVENT_EXTENDER_GET_IFACE(o) (G_TYPE_INSTANCE_GET_INTERFACE ((o), CLUTTER_TYPE_EVENT_EXTENDER, ClutterEventExtenderInterface))
79df40
 
79df40
 struct _ClutterEventExtenderInterface
79df40
 {
79df40
   GTypeInterface g_iface;
79df40
 
79df40
-  void (* copy_event_data) (ClutterEventExtender *event_extender,
79df40
-                            const ClutterEvent   *src,
79df40
-                            ClutterEvent         *dest);
79df40
+  gpointer (* copy_event_data) (ClutterEventExtender *event_extender,
79df40
+                                gpointer              data);
79df40
   void (* free_event_data) (ClutterEventExtender *event_extender,
79df40
-                            ClutterEvent         *event);
79df40
+                            gpointer              data);
79df40
 };
79df40
 
79df40
 GType           clutter_event_extender_get_type        (void) G_GNUC_CONST;
79df40
 
79df40
 /* device manager */
79df40
 void            _clutter_device_manager_add_device              (ClutterDeviceManager *device_manager,
79df40
                                                                  ClutterInputDevice   *device);
79df40
 void            _clutter_device_manager_remove_device           (ClutterDeviceManager *device_manager,
79df40
                                                                  ClutterInputDevice   *device);
79df40
 void            _clutter_device_manager_update_devices          (ClutterDeviceManager *device_manager);
79df40
 void            _clutter_device_manager_select_stage_events     (ClutterDeviceManager *device_manager,
79df40
                                                                  ClutterStage         *stage);
79df40
 ClutterBackend *_clutter_device_manager_get_backend             (ClutterDeviceManager *device_manager);
79df40
 
79df40
 void            _clutter_device_manager_compress_motion         (ClutterDeviceManager *device_manger,
79df40
                                                                  ClutterEvent         *event,
79df40
                                                                  const ClutterEvent   *to_discard);
79df40
 
79df40
 /* input device */
79df40
 gboolean        _clutter_input_device_has_sequence              (ClutterInputDevice   *device,
79df40
                                                                  ClutterEventSequence *sequence);
79df40
 void            _clutter_input_device_add_event_sequence        (ClutterInputDevice   *device,
79df40
                                                                  ClutterEvent         *event);
79df40
 void            _clutter_input_device_remove_event_sequence     (ClutterInputDevice   *device,
79df40
                                                                  ClutterEvent         *event);
79df40
 void            _clutter_input_device_set_coords                (ClutterInputDevice   *device,
79df40
                                                                  ClutterEventSequence *sequence,
79df40
                                                                  gfloat                x,
79df40
                                                                  gfloat                y,
79df40
                                                                  ClutterStage         *stage);
79df40
diff --git a/clutter/clutter/clutter-event.c b/clutter/clutter/clutter-event.c
79df40
index 1b21b6a97..60bdd325c 100644
79df40
--- a/clutter/clutter/clutter-event.c
79df40
+++ b/clutter/clutter/clutter-event.c
79df40
@@ -77,61 +77,73 @@ typedef struct _ClutterEventFilter {
79df40
 
79df40
 static GHashTable *all_events = NULL;
79df40
 
79df40
 G_DEFINE_BOXED_TYPE (ClutterEvent, clutter_event,
79df40
                      clutter_event_copy,
79df40
                      clutter_event_free);
79df40
 
79df40
 static ClutterEventSequence *
79df40
 clutter_event_sequence_copy (ClutterEventSequence *sequence)
79df40
 {
79df40
   /* Nothing to copy here */
79df40
   return sequence;
79df40
 }
79df40
 
79df40
 static void
79df40
 clutter_event_sequence_free (ClutterEventSequence *sequence)
79df40
 {
79df40
   /* Nothing to free here */
79df40
 }
79df40
 
79df40
 G_DEFINE_BOXED_TYPE (ClutterEventSequence, clutter_event_sequence,
79df40
                      clutter_event_sequence_copy,
79df40
                      clutter_event_sequence_free);
79df40
 
79df40
 static gboolean
79df40
 is_event_allocated (const ClutterEvent *event)
79df40
 {
79df40
   if (all_events == NULL)
79df40
     return FALSE;
79df40
 
79df40
-  return g_hash_table_lookup (all_events, event) != NULL;
79df40
+  return g_hash_table_contains (all_events, event);
79df40
+}
79df40
+
79df40
+static void
79df40
+clutter_event_private_data_free (ClutterEvent *event)
79df40
+{
79df40
+  ClutterEventPrivate *real_event = (ClutterEventPrivate *) event;
79df40
+
79df40
+  _clutter_backend_free_event_data (clutter_get_default_backend (),
79df40
+                                    real_event->platform_data);
79df40
+
79df40
+  g_clear_object (&real_event->device);
79df40
+  g_clear_object (&real_event->source_device);
79df40
 }
79df40
 
79df40
 /*
79df40
  * _clutter_event_get_platform_data:
79df40
  * @event: a #ClutterEvent
79df40
  *
79df40
  * Retrieves the pointer to platform-specific data inside an event
79df40
  *
79df40
  * Return value: a pointer to platform-specific data
79df40
  *
79df40
  * Since: 1.4
79df40
  */
79df40
 gpointer
79df40
 _clutter_event_get_platform_data (const ClutterEvent *event)
79df40
 {
79df40
   if (!is_event_allocated (event))
79df40
     return NULL;
79df40
 
79df40
   return ((ClutterEventPrivate *) event)->platform_data;
79df40
 }
79df40
 
79df40
 /*< private >
79df40
  * _clutter_event_set_platform_data:
79df40
  * @event: a #ClutterEvent
79df40
  * @data: a pointer to platform-specific data
79df40
  *
79df40
  * Sets the pointer to platform-specific data inside an event
79df40
  *
79df40
  * Since: 1.4
79df40
  */
79df40
@@ -1303,200 +1315,195 @@ clutter_event_get_device_tool (const ClutterEvent *event)
79df40
   if (is_event_allocated (event))
79df40
     {
79df40
       ClutterEventPrivate *real_event = (ClutterEventPrivate *) event;
79df40
 
79df40
       return real_event->tool;
79df40
     }
79df40
 
79df40
   return NULL;
79df40
 }
79df40
 
79df40
 /**
79df40
  * clutter_event_new:
79df40
  * @type: The type of event.
79df40
  *
79df40
  * Creates a new #ClutterEvent of the specified type.
79df40
  *
79df40
  * Return value: (transfer full): A newly allocated #ClutterEvent.
79df40
  */
79df40
 ClutterEvent *
79df40
 clutter_event_new (ClutterEventType type)
79df40
 {
79df40
   ClutterEvent *new_event;
79df40
   ClutterEventPrivate *priv;
79df40
 
79df40
   priv = g_slice_new0 (ClutterEventPrivate);
79df40
 
79df40
   new_event = (ClutterEvent *) priv;
79df40
   new_event->type = new_event->any.type = type;
79df40
 
79df40
   if (G_UNLIKELY (all_events == NULL))
79df40
-    all_events = g_hash_table_new (NULL, NULL);
79df40
+    {
79df40
+      all_events =
79df40
+        g_hash_table_new_full (NULL, NULL,
79df40
+                               (GDestroyNotify) clutter_event_private_data_free,
79df40
+                               NULL);
79df40
+    }
79df40
 
79df40
-  g_hash_table_replace (all_events, priv, GUINT_TO_POINTER (1));
79df40
+  g_hash_table_add (all_events, priv);
79df40
 
79df40
   return new_event;
79df40
 }
79df40
 
79df40
 /**
79df40
  * clutter_event_copy:
79df40
  * @event: A #ClutterEvent.
79df40
  *
79df40
  * Copies @event.
79df40
  *
79df40
  * Return value: (transfer full): A newly allocated #ClutterEvent
79df40
  */
79df40
 ClutterEvent *
79df40
 clutter_event_copy (const ClutterEvent *event)
79df40
 {
79df40
   ClutterEvent *new_event;
79df40
   ClutterEventPrivate *new_real_event;
79df40
   ClutterInputDevice *device;
79df40
   gint n_axes = 0;
79df40
 
79df40
   g_return_val_if_fail (event != NULL, NULL);
79df40
 
79df40
   new_event = clutter_event_new (CLUTTER_NOTHING);
79df40
   new_real_event = (ClutterEventPrivate *) new_event;
79df40
 
79df40
   *new_event = *event;
79df40
 
79df40
   if (is_event_allocated (event))
79df40
     {
79df40
       ClutterEventPrivate *real_event = (ClutterEventPrivate *) event;
79df40
 
79df40
       g_set_object (&new_real_event->device, real_event->device);
79df40
       g_set_object (&new_real_event->source_device, real_event->source_device);
79df40
       new_real_event->delta_x = real_event->delta_x;
79df40
       new_real_event->delta_y = real_event->delta_y;
79df40
       new_real_event->is_pointer_emulated = real_event->is_pointer_emulated;
79df40
       new_real_event->base_state = real_event->base_state;
79df40
       new_real_event->button_state = real_event->button_state;
79df40
       new_real_event->latched_state = real_event->latched_state;
79df40
       new_real_event->locked_state = real_event->locked_state;
79df40
       new_real_event->tool = real_event->tool;
79df40
+      new_real_event->platform_data =
79df40
+        _clutter_backend_copy_event_data (clutter_get_default_backend (),
79df40
+                                          real_event->platform_data);
79df40
     }
79df40
 
79df40
   device = clutter_event_get_device (event);
79df40
   if (device != NULL)
79df40
     n_axes = clutter_input_device_get_n_axes (device);
79df40
 
79df40
   switch (event->type)
79df40
     {
79df40
     case CLUTTER_BUTTON_PRESS:
79df40
     case CLUTTER_BUTTON_RELEASE:
79df40
       if (event->button.axes != NULL)
79df40
         new_event->button.axes = g_memdup (event->button.axes,
79df40
                                            sizeof (gdouble) * n_axes);
79df40
       break;
79df40
 
79df40
     case CLUTTER_SCROLL:
79df40
       if (event->scroll.axes != NULL)
79df40
         new_event->scroll.axes = g_memdup (event->scroll.axes,
79df40
                                            sizeof (gdouble) * n_axes);
79df40
       break;
79df40
 
79df40
     case CLUTTER_MOTION:
79df40
       if (event->motion.axes != NULL)
79df40
         new_event->motion.axes = g_memdup (event->motion.axes,
79df40
                                            sizeof (gdouble) * n_axes);
79df40
       break;
79df40
 
79df40
     case CLUTTER_TOUCH_BEGIN:
79df40
     case CLUTTER_TOUCH_UPDATE:
79df40
     case CLUTTER_TOUCH_END:
79df40
     case CLUTTER_TOUCH_CANCEL:
79df40
       if (event->touch.axes != NULL)
79df40
         new_event->touch.axes = g_memdup (event->touch.axes,
79df40
                                           sizeof (gdouble) * n_axes);
79df40
       break;
79df40
 
79df40
     default:
79df40
       break;
79df40
     }
79df40
 
79df40
-  if (is_event_allocated (event))
79df40
-    _clutter_backend_copy_event_data (clutter_get_default_backend (),
79df40
-                                      event,
79df40
-                                      new_event);
79df40
-
79df40
   return new_event;
79df40
 }
79df40
 
79df40
 /**
79df40
  * clutter_event_free:
79df40
  * @event: A #ClutterEvent.
79df40
  *
79df40
  * Frees all resources used by @event.
79df40
  */
79df40
 void
79df40
 clutter_event_free (ClutterEvent *event)
79df40
 {
79df40
   if (G_LIKELY (event != NULL))
79df40
     {
79df40
-      _clutter_backend_free_event_data (clutter_get_default_backend (), event);
79df40
-
79df40
-      if (is_event_allocated (event))
79df40
-        {
79df40
-          ClutterEventPrivate *real_event = (ClutterEventPrivate *) event;
79df40
-
79df40
-          g_clear_object (&real_event->device);
79df40
-          g_clear_object (&real_event->source_device);
79df40
-        }
79df40
-
79df40
       switch (event->type)
79df40
         {
79df40
         case CLUTTER_BUTTON_PRESS:
79df40
         case CLUTTER_BUTTON_RELEASE:
79df40
           g_free (event->button.axes);
79df40
           break;
79df40
 
79df40
         case CLUTTER_MOTION:
79df40
           g_free (event->motion.axes);
79df40
           break;
79df40
 
79df40
         case CLUTTER_SCROLL:
79df40
           g_free (event->scroll.axes);
79df40
           break;
79df40
 
79df40
         case CLUTTER_TOUCH_BEGIN:
79df40
         case CLUTTER_TOUCH_UPDATE:
79df40
         case CLUTTER_TOUCH_END:
79df40
         case CLUTTER_TOUCH_CANCEL:
79df40
           g_free (event->touch.axes);
79df40
           break;
79df40
 
79df40
         default:
79df40
           break;
79df40
         }
79df40
 
79df40
-      g_hash_table_remove (all_events, event);
79df40
+      if (G_LIKELY (all_events))
79df40
+        g_hash_table_remove (all_events, event);
79df40
+
79df40
       g_slice_free (ClutterEventPrivate, (ClutterEventPrivate *) event);
79df40
     }
79df40
 }
79df40
 
79df40
 /**
79df40
  * clutter_event_get:
79df40
  *
79df40
  * Pops an event off the event queue. Applications should not need to call 
79df40
  * this.
79df40
  *
79df40
  * Return value: A #ClutterEvent or NULL if queue empty
79df40
  *
79df40
  * Since: 0.4
79df40
  */
79df40
 ClutterEvent *
79df40
 clutter_event_get (void)
79df40
 {
79df40
   ClutterMainContext *context = _clutter_context_get_default ();
79df40
 
79df40
   if (context->events_queue == NULL)
79df40
     return NULL;
79df40
 
79df40
   if (g_queue_is_empty (context->events_queue))
79df40
     return NULL;
79df40
 
79df40
   return g_queue_pop_tail (context->events_queue);
79df40
 }
79df40
 
79df40
 /**
79df40
  * clutter_event_peek:
79df40
diff --git a/clutter/clutter/evdev/clutter-device-manager-evdev.c b/clutter/clutter/evdev/clutter-device-manager-evdev.c
79df40
index f2aeda696..11cb4781a 100644
79df40
--- a/clutter/clutter/evdev/clutter-device-manager-evdev.c
79df40
+++ b/clutter/clutter/evdev/clutter-device-manager-evdev.c
79df40
@@ -128,77 +128,76 @@ static gchar *                    evdev_seat_id;
79df40
 
79df40
 #ifdef CLUTTER_ENABLE_DEBUG
79df40
 static const char *device_type_str[] = {
79df40
   "pointer",            /* CLUTTER_POINTER_DEVICE */
79df40
   "keyboard",           /* CLUTTER_KEYBOARD_DEVICE */
79df40
   "extension",          /* CLUTTER_EXTENSION_DEVICE */
79df40
   "joystick",           /* CLUTTER_JOYSTICK_DEVICE */
79df40
   "tablet",             /* CLUTTER_TABLET_DEVICE */
79df40
   "touchpad",           /* CLUTTER_TOUCHPAD_DEVICE */
79df40
   "touchscreen",        /* CLUTTER_TOUCHSCREEN_DEVICE */
79df40
   "pen",                /* CLUTTER_PEN_DEVICE */
79df40
   "eraser",             /* CLUTTER_ERASER_DEVICE */
79df40
   "cursor",             /* CLUTTER_CURSOR_DEVICE */
79df40
   "pad",                /* CLUTTER_PAD_DEVICE */
79df40
 };
79df40
 #endif /* CLUTTER_ENABLE_DEBUG */
79df40
 
79df40
 /*
79df40
  * ClutterEventSource management
79df40
  *
79df40
  * The device manager is responsible for managing the GSource when devices
79df40
  * appear and disappear from the system.
79df40
  */
79df40
 
79df40
 static const char *option_xkb_layout = "us";
79df40
 static const char *option_xkb_variant = "";
79df40
 static const char *option_xkb_options = "";
79df40
 
79df40
 static void
79df40
 clutter_device_manager_evdev_copy_event_data (ClutterEventExtender *event_extender,
79df40
-                                              const ClutterEvent   *src,
79df40
-                                              ClutterEvent         *dest)
79df40
+                                              gpointer              data)
79df40
 {
79df40
-  ClutterEventEvdev *event_evdev;
79df40
+  ClutterEventEvdev *event_evdev = data;
79df40
 
79df40
-  event_evdev = _clutter_event_get_platform_data (src);
79df40
   if (event_evdev != NULL)
79df40
-    _clutter_event_set_platform_data (dest, _clutter_event_evdev_copy (event_evdev));
79df40
+    return _clutter_event_evdev_copy (event_evdev);
79df40
+
79df40
+  return NULL;
79df40
 }
79df40
 
79df40
 static void
79df40
 clutter_device_manager_evdev_free_event_data (ClutterEventExtender *event_extender,
79df40
-                                              ClutterEvent         *event)
79df40
+                                              gpointer              data)
79df40
 {
79df40
-  ClutterEventEvdev *event_evdev;
79df40
+  ClutterEventEvdev *event_evdev = data;
79df40
 
79df40
-  event_evdev = _clutter_event_get_platform_data (event);
79df40
   if (event_evdev != NULL)
79df40
     _clutter_event_evdev_free (event_evdev);
79df40
 }
79df40
 
79df40
 static void
79df40
 clutter_device_manager_evdev_event_extender_init (ClutterEventExtenderInterface *iface)
79df40
 {
79df40
   iface->copy_event_data = clutter_device_manager_evdev_copy_event_data;
79df40
   iface->free_event_data = clutter_device_manager_evdev_free_event_data;
79df40
 }
79df40
 
79df40
 /*
79df40
  * ClutterEventSource for reading input devices
79df40
  */
79df40
 
79df40
 struct _ClutterEventSource
79df40
 {
79df40
   GSource source;
79df40
 
79df40
   ClutterDeviceManagerEvdev *manager_evdev;
79df40
   GPollFD event_poll_fd;
79df40
 };
79df40
 
79df40
 static void
79df40
 process_events (ClutterDeviceManagerEvdev *manager_evdev);
79df40
 
79df40
 static gboolean
79df40
 clutter_event_prepare (GSource *source,
79df40
                        gint    *timeout)
79df40
 {
79df40
diff --git a/clutter/clutter/x11/clutter-device-manager-xi2.c b/clutter/clutter/x11/clutter-device-manager-xi2.c
79df40
index 0718cd975..35e3808e7 100644
79df40
--- a/clutter/clutter/x11/clutter-device-manager-xi2.c
79df40
+++ b/clutter/clutter/x11/clutter-device-manager-xi2.c
79df40
@@ -63,79 +63,74 @@ static const char *clutter_input_axis_atom_names[] = {
79df40
   "Abs Tilt Y",         /* CLUTTER_INPUT_AXIS_YTILT */
79df40
   "Abs Wheel",          /* CLUTTER_INPUT_AXIS_WHEEL */
79df40
   "Abs Distance",       /* CLUTTER_INPUT_AXIS_DISTANCE */
79df40
 };
79df40
 
79df40
 #define N_AXIS_ATOMS    G_N_ELEMENTS (clutter_input_axis_atom_names)
79df40
 
79df40
 enum {
79df40
   PAD_AXIS_FIRST  = 3, /* First axes are always x/y/pressure, ignored in pads */
79df40
   PAD_AXIS_STRIP1 = PAD_AXIS_FIRST,
79df40
   PAD_AXIS_STRIP2,
79df40
   PAD_AXIS_RING1,
79df40
   PAD_AXIS_RING2,
79df40
 };
79df40
 
79df40
 static Atom clutter_input_axis_atoms[N_AXIS_ATOMS] = { 0, };
79df40
 
79df40
 static void clutter_event_translator_iface_init (ClutterEventTranslatorIface *iface);
79df40
 static void clutter_event_extender_iface_init   (ClutterEventExtenderInterface *iface);
79df40
 
79df40
 #define clutter_device_manager_xi2_get_type     _clutter_device_manager_xi2_get_type
79df40
 
79df40
 G_DEFINE_TYPE_WITH_CODE (ClutterDeviceManagerXI2,
79df40
                          clutter_device_manager_xi2,
79df40
                          CLUTTER_TYPE_DEVICE_MANAGER,
79df40
                          G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_EVENT_TRANSLATOR,
79df40
                                                 clutter_event_translator_iface_init)
79df40
                          G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_EVENT_EXTENDER,
79df40
                                                 clutter_event_extender_iface_init))
79df40
 
79df40
-static void
79df40
+static gpointer
79df40
 clutter_device_manager_x11_copy_event_data (ClutterEventExtender *event_extender,
79df40
-                                            const ClutterEvent   *src,
79df40
-                                            ClutterEvent         *dest)
79df40
+                                            gpointer              event_x11)
79df40
 {
79df40
-  gpointer event_x11;
79df40
-
79df40
-  event_x11 = _clutter_event_get_platform_data (src);
79df40
   if (event_x11 != NULL)
79df40
-    _clutter_event_set_platform_data (dest, _clutter_event_x11_copy (event_x11));
79df40
+    return _clutter_event_x11_copy (event_x11);
79df40
+
79df40
+  return NULL;
79df40
 }
79df40
 
79df40
 static void
79df40
 clutter_device_manager_x11_free_event_data (ClutterEventExtender *event_extender,
79df40
-                                            ClutterEvent         *event)
79df40
+                                            gpointer              event_x11)
79df40
 {
79df40
-  gpointer event_x11;
79df40
-
79df40
-  event_x11 = _clutter_event_get_platform_data (event);
79df40
   if (event_x11 != NULL)
79df40
     _clutter_event_x11_free (event_x11);
79df40
 }
79df40
 
79df40
 static void
79df40
 clutter_event_extender_iface_init (ClutterEventExtenderInterface *iface)
79df40
 {
79df40
   iface->copy_event_data = clutter_device_manager_x11_copy_event_data;
79df40
   iface->free_event_data = clutter_device_manager_x11_free_event_data;
79df40
 }
79df40
 
79df40
 static void
79df40
 translate_valuator_class (Display             *xdisplay,
79df40
                           ClutterInputDevice  *device,
79df40
                           XIValuatorClassInfo *class)
79df40
 {
79df40
   static gboolean atoms_initialized = FALSE;
79df40
   ClutterInputAxis i, axis = CLUTTER_INPUT_AXIS_IGNORE;
79df40
 
79df40
   if (G_UNLIKELY (!atoms_initialized))
79df40
     {
79df40
       XInternAtoms (xdisplay,
79df40
                     (char **) clutter_input_axis_atom_names, N_AXIS_ATOMS,
79df40
                     False,
79df40
                     clutter_input_axis_atoms);
79df40
 
79df40
       atoms_initialized = TRUE;
79df40
     }
79df40
 
79df40
   for (i = 0;
79df40
-- 
79df40
2.26.2
79df40