From 3c6c1af0a0e5161a503ee661619475d25269d2c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Fri, 18 Mar 2022 17:31:25 +0100 Subject: [PATCH] barrier: Add GInitable based constructor method This one does proper error reporting. Via Javascript, barriers are constructed directly via GObject construction, which currently can't handle error reporting, but when calling from C we can. However, if we initialize using GInitable, and use that in our constructor method, once gjs gains support for construction using GInitable, including the error reporting, we'll automatically get proper error reporting to Javascript. Part-of: --- src/backends/meta-barrier.c | 53 ++++++++++++++++++++++++++++++++++++- src/meta/barrier.h | 9 +++++++ 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/src/backends/meta-barrier.c b/src/backends/meta-barrier.c index 45ccd99f9..e227a83f1 100644 --- a/src/backends/meta-barrier.c +++ b/src/backends/meta-barrier.c @@ -35,7 +35,13 @@ typedef struct _MetaBarrierPrivate MetaBarrierImpl *impl; } MetaBarrierPrivate; -G_DEFINE_TYPE_WITH_PRIVATE (MetaBarrier, meta_barrier, G_TYPE_OBJECT) +static void initable_iface_init (GInitableIface *initable_iface); + +G_DEFINE_TYPE_WITH_CODE (MetaBarrier, meta_barrier, G_TYPE_OBJECT, + G_ADD_PRIVATE (MetaBarrier) + G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, + initable_iface_init)) + G_DEFINE_TYPE (MetaBarrierImpl, meta_barrier_impl, G_TYPE_OBJECT) G_STATIC_ASSERT ((int) META_BARRIER_DIRECTION_POSITIVE_X == @@ -225,6 +231,31 @@ meta_barrier_release (MetaBarrier *barrier, META_BARRIER_IMPL_GET_CLASS (impl)->release (impl, event); } +static gboolean +meta_barrier_initable_init (GInitable *initable, + GCancellable *cancellable, + GError **error) +{ + MetaBarrier *barrier = META_BARRIER (initable); + MetaBarrierPrivate *priv = meta_barrier_get_instance_private (barrier); + + priv = meta_barrier_get_instance_private (barrier); + if (!priv->impl) + { + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, + "Failed to create barrier impl"); + return FALSE; + } + + return TRUE; +} + +static void +initable_iface_init (GInitableIface *initable_iface) +{ + initable_iface->init = meta_barrier_initable_init; +} + static void init_barrier_impl (MetaBarrier *barrier) { @@ -393,6 +424,26 @@ meta_barrier_init (MetaBarrier *barrier) { } +MetaBarrier * +meta_barrier_new (MetaBackend *backend, + int x1, + int y1, + int x2, + int y2, + MetaBarrierDirection directions, + GError **error) +{ + return g_initable_new (META_TYPE_BARRIER, + NULL, error, + "backend", backend, + "x1", x1, + "y1", y1, + "x2", x2, + "y2", y2, + "directions", directions, + NULL); +} + void meta_barrier_emit_hit_signal (MetaBarrier *barrier, MetaBarrierEvent *event) diff --git a/src/meta/barrier.h b/src/meta/barrier.h index a73bcd25b..374c42f0b 100644 --- a/src/meta/barrier.h +++ b/src/meta/barrier.h @@ -33,6 +33,15 @@ G_DECLARE_FINAL_TYPE (MetaBarrier, meta_barrier, typedef struct _MetaBarrierEvent MetaBarrierEvent; +META_EXPORT +MetaBarrier * meta_barrier_new (MetaBackend *backend, + int x1, + int y1, + int x2, + int y2, + MetaBarrierDirection directions, + GError **error); + META_EXPORT gboolean meta_barrier_is_active (MetaBarrier *barrier);