[gtk+/wip/carlosg/event-as-object: 12/23] gdk: Make GdkEvent type a construct only property



commit 60adc1084826cdbc9f9e483ef92ecafc2be1dd63
Author: Carlos Garnacho <carlosg gnome org>
Date:   Wed Oct 25 15:46:47 2017 +0200

    gdk: Make GdkEvent type a construct only property
    
    So it must be set at the time of doing g_object_new().

 gdk/gdkevents.c |   66 +++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 62 insertions(+), 4 deletions(-)
---
diff --git a/gdk/gdkevents.c b/gdk/gdkevents.c
index 5ad6ee1..a8eeff9 100644
--- a/gdk/gdkevents.c
+++ b/gdk/gdkevents.c
@@ -24,6 +24,7 @@
 
 #include "config.h"
 
+#include "gdkintl.h"
 #include "gdkeventsprivate.h"
 #include "gdkinternals.h"
 #include "gdkdisplayprivate.h"
@@ -71,6 +72,14 @@ static void gdk_event_finalize (GObject *object);
 
 G_DEFINE_TYPE (GdkEvent, gdk_event, G_TYPE_OBJECT)
 
+enum {
+  PROP_0,
+  PROP_EVENT_TYPE,
+  N_PROPS
+};
+
+static GParamSpec *event_props[N_PROPS] = { NULL, };
+
 #define EVENT_PAYLOAD(ev) (&(ev)->any.type)
 #define EVENT_PAYLOAD_SIZE (sizeof (GdkEvent) - sizeof (GObject))
 
@@ -80,12 +89,61 @@ gdk_event_init (GdkEvent *event)
 }
 
 static void
+gdk_event_real_get_property (GObject    *object,
+                             guint       prop_id,
+                             GValue     *value,
+                             GParamSpec *pspec)
+{
+  GdkEvent *event = GDK_EVENT (object);
+
+  switch (prop_id)
+    {
+    case PROP_EVENT_TYPE:
+      g_value_set_enum (value, event->any.type);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+static void
+gdk_event_real_set_property (GObject      *object,
+                             guint         prop_id,
+                             const GValue *value,
+                             GParamSpec   *pspec)
+{
+  GdkEvent *event = GDK_EVENT (object);
+
+  switch (prop_id)
+    {
+    case PROP_EVENT_TYPE:
+      event->any.type = g_value_get_enum (value);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+static void
 gdk_event_class_init (GdkEventClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
+  object_class->get_property = gdk_event_real_get_property;
+  object_class->set_property = gdk_event_real_set_property;
   object_class->finalize = gdk_event_finalize;
 
+  event_props[PROP_EVENT_TYPE] =
+    g_param_spec_enum ("event-type",
+                       P_("Event type"),
+                       P_("Event type"),
+                       GDK_TYPE_EVENT_TYPE, GDK_NOTHING,
+                       G_PARAM_READWRITE |
+                       G_PARAM_CONSTRUCT_ONLY);
+  g_object_class_install_properties (object_class, N_PROPS, event_props);
+
   quark_event_user_data = g_quark_from_static_string ("gdk-event-user-data");
 }
 
@@ -521,9 +579,9 @@ gdk_event_new (GdkEventType type)
 {
   GdkEvent *new_event;
 
-  new_event = g_object_new (GDK_TYPE_EVENT, NULL);
-
-  new_event->any.type = type;
+  new_event = g_object_new (GDK_TYPE_EVENT,
+                            "event-type", type,
+                            NULL);
 
   /*
    * Bytewise 0 initialization is reasonable for most of the 
@@ -640,7 +698,7 @@ gdk_event_copy (const GdkEvent *event)
 
   g_return_val_if_fail (event != NULL, NULL);
 
-  new_event = gdk_event_new (GDK_NOTHING);
+  new_event = gdk_event_new (event->any.type);
 
   memcpy (EVENT_PAYLOAD (new_event),
           EVENT_PAYLOAD (event),


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