Revert "barrier: Get rid of private instance struct"

This reverts commit 4095c2431c.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2626>
This commit is contained in:
Jonas Ådahl 2022-09-15 10:11:32 +02:00 committed by Marge Bot
parent a1873e0c4f
commit cc9d2065e1

View File

@ -26,15 +26,19 @@
struct _MetaBarrier
{
GObject parent;
};
typedef struct _MetaBarrierPrivate
{
MetaBackend *backend;
MetaBorder border;
MetaBarrierImpl *impl;
};
} MetaBarrierPrivate;
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))
@ -100,30 +104,31 @@ meta_barrier_get_property (GObject *object,
GParamSpec *pspec)
{
MetaBarrier *barrier = META_BARRIER (object);
MetaBarrierPrivate *priv = meta_barrier_get_instance_private (barrier);
switch (prop_id)
{
case PROP_BACKEND:
g_value_set_object (value, barrier->backend);
g_value_set_object (value, priv->backend);
break;
case PROP_DISPLAY:
g_value_set_object (value, display_from_backend (barrier->backend));
g_value_set_object (value, display_from_backend (priv->backend));
break;
case PROP_X1:
g_value_set_int (value, barrier->border.line.a.x);
g_value_set_int (value, priv->border.line.a.x);
break;
case PROP_Y1:
g_value_set_int (value, barrier->border.line.a.y);
g_value_set_int (value, priv->border.line.a.y);
break;
case PROP_X2:
g_value_set_int (value, barrier->border.line.b.x);
g_value_set_int (value, priv->border.line.b.x);
break;
case PROP_Y2:
g_value_set_int (value, barrier->border.line.b.y);
g_value_set_int (value, priv->border.line.b.y);
break;
case PROP_DIRECTIONS:
g_value_set_flags (value,
meta_border_get_allows_directions (&barrier->border));
meta_border_get_allows_directions (&priv->border));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@ -138,11 +143,12 @@ meta_barrier_set_property (GObject *object,
GParamSpec *pspec)
{
MetaBarrier *barrier = META_BARRIER (object);
MetaBarrierPrivate *priv = meta_barrier_get_instance_private (barrier);
switch (prop_id)
{
case PROP_BACKEND:
barrier->backend = g_value_get_object (value);
priv->backend = g_value_get_object (value);
break;
case PROP_DISPLAY:
{
@ -150,23 +156,23 @@ meta_barrier_set_property (GObject *object,
display = g_value_get_object (value);
if (display)
barrier->backend = backend_from_display (g_value_get_object (value));
priv->backend = backend_from_display (g_value_get_object (value));
break;
}
case PROP_X1:
barrier->border.line.a.x = g_value_get_int (value);
priv->border.line.a.x = g_value_get_int (value);
break;
case PROP_Y1:
barrier->border.line.a.y = g_value_get_int (value);
priv->border.line.a.y = g_value_get_int (value);
break;
case PROP_X2:
barrier->border.line.b.x = g_value_get_int (value);
priv->border.line.b.x = g_value_get_int (value);
break;
case PROP_Y2:
barrier->border.line.b.y = g_value_get_int (value);
priv->border.line.b.y = g_value_get_int (value);
break;
case PROP_DIRECTIONS:
meta_border_set_allows_directions (&barrier->border,
meta_border_set_allows_directions (&priv->border,
g_value_get_flags (value));
break;
default:
@ -179,6 +185,7 @@ static void
meta_barrier_dispose (GObject *object)
{
MetaBarrier *barrier = META_BARRIER (object);
MetaBarrierPrivate *priv = meta_barrier_get_instance_private (barrier);
if (meta_barrier_is_active (barrier))
{
@ -186,7 +193,7 @@ meta_barrier_dispose (GObject *object)
barrier);
}
g_clear_object (&barrier->impl);
g_clear_object (&priv->impl);
G_OBJECT_CLASS (meta_barrier_parent_class)->dispose (object);
}
@ -194,7 +201,8 @@ meta_barrier_dispose (GObject *object)
gboolean
meta_barrier_is_active (MetaBarrier *barrier)
{
MetaBarrierImpl *impl = barrier->impl;
MetaBarrierPrivate *priv = meta_barrier_get_instance_private (barrier);
MetaBarrierImpl *impl = priv->impl;
if (impl)
return META_BARRIER_IMPL_GET_CLASS (impl)->is_active (impl);
@ -216,7 +224,8 @@ void
meta_barrier_release (MetaBarrier *barrier,
MetaBarrierEvent *event)
{
MetaBarrierImpl *impl = barrier->impl;
MetaBarrierPrivate *priv = meta_barrier_get_instance_private (barrier);
MetaBarrierImpl *impl = priv->impl;
if (impl)
META_BARRIER_IMPL_GET_CLASS (impl)->release (impl, event);
@ -228,8 +237,10 @@ meta_barrier_initable_init (GInitable *initable,
GError **error)
{
MetaBarrier *barrier = META_BARRIER (initable);
MetaBarrierPrivate *priv = meta_barrier_get_instance_private (barrier);
if (!barrier->impl)
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");
@ -248,23 +259,25 @@ initable_iface_init (GInitableIface *initable_iface)
static void
init_barrier_impl (MetaBarrier *barrier)
{
g_return_if_fail (barrier->backend);
g_return_if_fail (barrier->border.line.a.x == barrier->border.line.b.x ||
barrier->border.line.a.y == barrier->border.line.b.y);
g_return_if_fail (barrier->border.line.a.x >= 0);
g_return_if_fail (barrier->border.line.a.y >= 0);
g_return_if_fail (barrier->border.line.b.x >= 0);
g_return_if_fail (barrier->border.line.b.y >= 0);
MetaBarrierPrivate *priv = meta_barrier_get_instance_private (barrier);
g_return_if_fail (priv->backend);
g_return_if_fail (priv->border.line.a.x == priv->border.line.b.x ||
priv->border.line.a.y == priv->border.line.b.y);
g_return_if_fail (priv->border.line.a.x >= 0);
g_return_if_fail (priv->border.line.a.y >= 0);
g_return_if_fail (priv->border.line.b.x >= 0);
g_return_if_fail (priv->border.line.b.y >= 0);
#if defined(HAVE_NATIVE_BACKEND)
if (META_IS_BACKEND_NATIVE (barrier->backend))
barrier->impl = meta_barrier_impl_native_new (barrier);
if (META_IS_BACKEND_NATIVE (priv->backend))
priv->impl = meta_barrier_impl_native_new (barrier);
#endif
if (META_IS_BACKEND_X11 (barrier->backend) &&
if (META_IS_BACKEND_X11 (priv->backend) &&
!meta_is_wayland_compositor ())
barrier->impl = meta_barrier_impl_x11_new (barrier);
priv->impl = meta_barrier_impl_x11_new (barrier);
g_warn_if_fail (barrier->impl);
g_warn_if_fail (priv->impl);
}
static void
@ -397,7 +410,8 @@ meta_barrier_class_init (MetaBarrierClass *klass)
void
meta_barrier_destroy (MetaBarrier *barrier)
{
MetaBarrierImpl *impl = barrier->impl;
MetaBarrierPrivate *priv = meta_barrier_get_instance_private (barrier);
MetaBarrierImpl *impl = priv->impl;
if (impl)
META_BARRIER_IMPL_GET_CLASS (impl)->destroy (impl);
@ -447,13 +461,17 @@ meta_barrier_emit_left_signal (MetaBarrier *barrier,
MetaBackend *
meta_barrier_get_backend (MetaBarrier *barrier)
{
return barrier->backend;
MetaBarrierPrivate *priv = meta_barrier_get_instance_private (barrier);
return priv->backend;
}
MetaBorder *
meta_barrier_get_border (MetaBarrier *barrier)
{
return &barrier->border;
MetaBarrierPrivate *priv = meta_barrier_get_instance_private (barrier);
return &priv->border;
}
static void