[gtk+/wip/carlosg/event-as-object: 13/23] gdk: Move additional code in gdk_event_new() to GdkEvent::constructed



commit 1d89f6e6c0da9e4b8962703ce4f26bfc4813b387
Author: Carlos Garnacho <carlosg gnome org>
Date:   Wed Oct 25 15:49:19 2017 +0200

    gdk: Move additional code in gdk_event_new() to GdkEvent::constructed
    
    Now that the type is a construct only property, we can initialize the
    event fields properly here.

 gdk/gdkevents.c |   20 +++++++++++++-------
 1 files changed, 13 insertions(+), 7 deletions(-)
---
diff --git a/gdk/gdkevents.c b/gdk/gdkevents.c
index a8eeff9..01405c5 100644
--- a/gdk/gdkevents.c
+++ b/gdk/gdkevents.c
@@ -68,6 +68,7 @@ static GDestroyNotify _gdk_event_notify = NULL;
 
 static GQuark quark_event_user_data = 0;
 
+static void gdk_event_constructed (GObject *object);
 static void gdk_event_finalize (GObject *object);
 
 G_DEFINE_TYPE (GdkEvent, gdk_event, G_TYPE_OBJECT)
@@ -133,6 +134,7 @@ gdk_event_class_init (GdkEventClass *klass)
 
   object_class->get_property = gdk_event_real_get_property;
   object_class->set_property = gdk_event_real_set_property;
+  object_class->constructed = gdk_event_constructed;
   object_class->finalize = gdk_event_finalize;
 
   event_props[PROP_EVENT_TYPE] =
@@ -577,11 +579,15 @@ gdk_event_put (const GdkEvent *event)
 GdkEvent*
 gdk_event_new (GdkEventType type)
 {
-  GdkEvent *new_event;
+  return g_object_new (GDK_TYPE_EVENT,
+                       "event-type", type,
+                       NULL);
+}
 
-  new_event = g_object_new (GDK_TYPE_EVENT,
-                            "event-type", type,
-                            NULL);
+static void
+gdk_event_constructed (GObject *object)
+{
+  GdkEvent *new_event = GDK_EVENT (object);
 
   /*
    * Bytewise 0 initialization is reasonable for most of the 
@@ -589,7 +595,7 @@ gdk_event_new (GdkEventType type)
    * since I trust bytewise 0 == 0. less than for integers
    * or pointers.
    */
-  switch ((guint) type)
+  switch ((guint) new_event->any.type)
     {
     case GDK_MOTION_NOTIFY:
       new_event->motion.x = 0.;
@@ -650,8 +656,8 @@ gdk_event_new (GdkEventType type)
     default:
       break;
     }
-  
-  return new_event;
+
+  G_OBJECT_CLASS (gdk_event_parent_class)->constructed (object);
 }
 
 void


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