barrier: Modernize type implementation

This means using G_DECLARE*() to declare the type, using
`_get_private_instance()` everywhere, and other smaller cleanups.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2442>
This commit is contained in:
Jonas Ådahl 2022-03-18 15:48:23 +01:00 committed by Marge Bot
parent 1992aa1567
commit 27b75d3c96
5 changed files with 82 additions and 97 deletions

View File

@ -56,13 +56,8 @@ void meta_barrier_event_unref (MetaBarrierEvent *event);
MetaBackend * meta_barrier_get_backend (MetaBarrier *barrier);
MetaBorder * meta_barrier_get_border (MetaBarrier *barrier);
G_END_DECLS
struct _MetaBarrierPrivate
{
MetaBackend *backend;
MetaBorder border;
MetaBarrierImpl *impl;
};
#endif /* META_BARRIER_PRIVATE_H */

View File

@ -23,6 +23,18 @@
#include "backends/native/meta-barrier-native.h"
#endif
struct _MetaBarrier
{
GObject parent;
};
typedef struct _MetaBarrierPrivate
{
MetaBackend *backend;
MetaBorder border;
MetaBarrierImpl *impl;
} MetaBarrierPrivate;
G_DEFINE_TYPE_WITH_PRIVATE (MetaBarrier, meta_barrier, G_TYPE_OBJECT)
G_DEFINE_TYPE (MetaBarrierImpl, meta_barrier_impl, G_TYPE_OBJECT)
@ -86,7 +98,7 @@ meta_barrier_get_property (GObject *object,
GParamSpec *pspec)
{
MetaBarrier *barrier = META_BARRIER (object);
MetaBarrierPrivate *priv = barrier->priv;
MetaBarrierPrivate *priv = meta_barrier_get_instance_private (barrier);
switch (prop_id)
{
@ -125,7 +137,8 @@ meta_barrier_set_property (GObject *object,
GParamSpec *pspec)
{
MetaBarrier *barrier = META_BARRIER (object);
MetaBarrierPrivate *priv = barrier->priv;
MetaBarrierPrivate *priv = meta_barrier_get_instance_private (barrier);
switch (prop_id)
{
case PROP_BACKEND:
@ -166,7 +179,7 @@ static void
meta_barrier_dispose (GObject *object)
{
MetaBarrier *barrier = META_BARRIER (object);
MetaBarrierPrivate *priv = barrier->priv;
MetaBarrierPrivate *priv = meta_barrier_get_instance_private (barrier);
if (meta_barrier_is_active (barrier))
{
@ -182,7 +195,8 @@ meta_barrier_dispose (GObject *object)
gboolean
meta_barrier_is_active (MetaBarrier *barrier)
{
MetaBarrierImpl *impl = barrier->priv->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);
@ -204,7 +218,8 @@ void
meta_barrier_release (MetaBarrier *barrier,
MetaBarrierEvent *event)
{
MetaBarrierImpl *impl = barrier->priv->impl;
MetaBarrierPrivate *priv = meta_barrier_get_instance_private (barrier);
MetaBarrierImpl *impl = priv->impl;
if (impl)
META_BARRIER_IMPL_GET_CLASS (impl)->release (impl, event);
@ -213,7 +228,7 @@ meta_barrier_release (MetaBarrier *barrier,
static void
init_barrier_impl (MetaBarrier *barrier)
{
MetaBarrierPrivate *priv = barrier->priv;
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 ||
@ -364,7 +379,8 @@ meta_barrier_class_init (MetaBarrierClass *klass)
void
meta_barrier_destroy (MetaBarrier *barrier)
{
MetaBarrierImpl *impl = barrier->priv->impl;
MetaBarrierPrivate *priv = meta_barrier_get_instance_private (barrier);
MetaBarrierImpl *impl = priv->impl;
if (impl)
META_BARRIER_IMPL_GET_CLASS (impl)->destroy (impl);
@ -375,7 +391,6 @@ meta_barrier_destroy (MetaBarrier *barrier)
static void
meta_barrier_init (MetaBarrier *barrier)
{
barrier->priv = meta_barrier_get_instance_private (barrier);
}
void
@ -395,15 +410,22 @@ meta_barrier_emit_left_signal (MetaBarrier *barrier,
MetaBackend *
meta_barrier_get_backend (MetaBarrier *barrier)
{
return barrier->priv->backend;
MetaBarrierPrivate *priv = meta_barrier_get_instance_private (barrier);
return priv->backend;
}
MetaBorder *
meta_barrier_get_border (MetaBarrier *barrier)
{
MetaBarrierPrivate *priv = meta_barrier_get_instance_private (barrier);
return &priv->border;
}
static void
meta_barrier_impl_class_init (MetaBarrierImplClass *klass)
{
klass->is_active = NULL;
klass->release = NULL;
klass->destroy = NULL;
}
static void

View File

@ -102,18 +102,20 @@ next_serial (void)
static gboolean
is_barrier_horizontal (MetaBarrier *barrier)
{
return meta_border_is_horizontal (&barrier->priv->border);
MetaBorder *border = meta_barrier_get_border (barrier);
return meta_border_is_horizontal (border);
}
static gboolean
is_barrier_blocking_directions (MetaBarrier *barrier,
MetaBarrierDirection directions)
{
MetaBorder *border = meta_barrier_get_border (barrier);
MetaBorderMotionDirection border_motion_directions =
(MetaBorderMotionDirection) directions;
return meta_border_is_blocking_directions (&barrier->priv->border,
border_motion_directions);
return meta_border_is_blocking_directions (border, border_motion_directions);
}
static void
@ -131,7 +133,8 @@ dismiss_pointer (MetaBarrierImplNative *self)
static MetaLine2
calculate_barrier_hit_box (MetaBarrier *barrier)
{
MetaLine2 hit_box = barrier->priv->border.line;
MetaBorder *border = meta_barrier_get_border (barrier);
MetaLine2 hit_box = border->line;
if (is_barrier_horizontal (barrier))
{
@ -170,6 +173,7 @@ maybe_release_barrier (gpointer key,
{
MetaBarrierImplNative *self = key;
MetaBarrier *barrier = self->barrier;
MetaBorder *border = meta_barrier_get_border (barrier);
MetaLine2 *motion = user_data;
MetaLine2 hit_box;
@ -179,10 +183,8 @@ maybe_release_barrier (gpointer key,
/* Release if we end up outside barrier end points. */
if (is_barrier_horizontal (barrier))
{
if (motion->b.x > MAX (barrier->priv->border.line.a.x,
barrier->priv->border.line.b.x) ||
motion->b.x < MIN (barrier->priv->border.line.a.x,
barrier->priv->border.line.b.x))
if (motion->b.x > MAX (border->line.a.x, border->line.b.x) ||
motion->b.x < MIN (border->line.a.x, border->line.b.x))
{
dismiss_pointer (self);
return;
@ -190,10 +192,8 @@ maybe_release_barrier (gpointer key,
}
else
{
if (motion->b.y > MAX (barrier->priv->border.line.a.y,
barrier->priv->border.line.b.y) ||
motion->b.y < MIN (barrier->priv->border.line.a.y,
barrier->priv->border.line.b.y))
if (motion->b.y > MAX (border->line.a.y, border->line.b.y) ||
motion->b.y < MIN (border->line.a.y, border->line.b.y))
{
dismiss_pointer (self);
return;
@ -254,6 +254,7 @@ update_closest_barrier (gpointer key,
{
MetaBarrierImplNative *self = key;
MetaBarrier *barrier = self->barrier;
MetaBorder *border = meta_barrier_get_border (barrier);
MetaClosestBarrierData *data = user_data;
MetaVector2 intersection;
float dx, dy;
@ -274,7 +275,7 @@ update_closest_barrier (gpointer key,
/* Check if the motion intersects with the barrier, and retrieve the
* intersection point if any. */
if (!meta_line2_intersects_with (&barrier->priv->border.line,
if (!meta_line2_intersects_with (&border->line,
&data->in.motion,
&intersection))
return;
@ -473,13 +474,14 @@ clamp_to_barrier (MetaBarrierImplNative *self,
float *y)
{
MetaBarrier *barrier = self->barrier;
MetaBorder *border = meta_barrier_get_border (barrier);
if (is_barrier_horizontal (barrier))
{
if (*motion_dir & META_BARRIER_DIRECTION_POSITIVE_Y)
*y = barrier->priv->border.line.a.y;
*y = border->line.a.y;
else if (*motion_dir & META_BARRIER_DIRECTION_NEGATIVE_Y)
*y = barrier->priv->border.line.a.y;
*y = border->line.a.y;
self->blocked_dir = *motion_dir & (META_BARRIER_DIRECTION_POSITIVE_Y |
META_BARRIER_DIRECTION_NEGATIVE_Y);
@ -489,9 +491,9 @@ clamp_to_barrier (MetaBarrierImplNative *self,
else
{
if (*motion_dir & META_BARRIER_DIRECTION_POSITIVE_X)
*x = barrier->priv->border.line.a.x;
*x = border->line.a.x;
else if (*motion_dir & META_BARRIER_DIRECTION_NEGATIVE_X)
*x = barrier->priv->border.line.a.x;
*x = border->line.a.x;
self->blocked_dir = *motion_dir & (META_BARRIER_DIRECTION_POSITIVE_X |
META_BARRIER_DIRECTION_NEGATIVE_X);

View File

@ -71,7 +71,7 @@ meta_barrier_impl_x11_release (MetaBarrierImpl *impl,
MetaBarrierEvent *event)
{
MetaBarrierImplX11 *self = META_BARRIER_IMPL_X11 (impl);
MetaBackend *backend = self->barrier->priv->backend;
MetaBackend *backend = meta_barrier_get_backend (self->barrier);
MetaBackendX11 *backend_x11 = META_BACKEND_X11 (backend);
Display *xdisplay = meta_backend_x11_get_xdisplay (backend_x11);
@ -84,7 +84,7 @@ static void
meta_barrier_impl_x11_destroy (MetaBarrierImpl *impl)
{
MetaBarrierImplX11 *self = META_BARRIER_IMPL_X11 (impl);
MetaBackend *backend = self->barrier->priv->backend;
MetaBackend *backend = meta_barrier_get_backend (self->barrier);
MetaBackendX11 *backend_x11 = META_BACKEND_X11 (backend);
MetaX11Barriers *barriers = meta_backend_x11_get_barriers (backend_x11);
Display *xdisplay = meta_backend_x11_get_xdisplay (backend_x11);
@ -106,23 +106,24 @@ meta_barrier_impl_x11_new (MetaBarrier *barrier)
MetaX11Barriers *barriers;
Display *xdisplay;
Window root;
MetaBorder *border;
unsigned int allowed_motion_dirs;
self = g_object_new (META_TYPE_BARRIER_IMPL_X11, NULL);
self->barrier = barrier;
backend = self->barrier->priv->backend;
backend = meta_barrier_get_backend (self->barrier);
backend_x11 = META_BACKEND_X11 (backend);
xdisplay = meta_backend_x11_get_xdisplay (backend_x11);
root = DefaultRootWindow (xdisplay);
allowed_motion_dirs =
meta_border_get_allows_directions (&barrier->priv->border);
border = meta_barrier_get_border (barrier);
allowed_motion_dirs = meta_border_get_allows_directions (border);
self->xbarrier = XFixesCreatePointerBarrier (xdisplay, root,
barrier->priv->border.line.a.x,
barrier->priv->border.line.a.y,
barrier->priv->border.line.b.x,
barrier->priv->border.line.b.y,
border->line.a.x,
border->line.a.y,
border->line.b.x,
border->line.b.y,
allowed_motion_dirs,
0, NULL);

View File

@ -9,58 +9,6 @@
G_BEGIN_DECLS
#define META_TYPE_BARRIER (meta_barrier_get_type ())
#define META_BARRIER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), META_TYPE_BARRIER, MetaBarrier))
#define META_BARRIER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), META_TYPE_BARRIER, MetaBarrierClass))
#define META_IS_BARRIER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), META_TYPE_BARRIER))
#define META_IS_BARRIER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), META_TYPE_BARRIER))
#define META_BARRIER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), META_TYPE_BARRIER, MetaBarrierClass))
typedef struct _MetaBarrier MetaBarrier;
typedef struct _MetaBarrierClass MetaBarrierClass;
typedef struct _MetaBarrierPrivate MetaBarrierPrivate;
typedef struct _MetaBarrierEvent MetaBarrierEvent;
/**
* MetaBarrier:
*
* The <structname>MetaBarrier</structname> structure contains
* only private data and should be accessed using the provided API
*
**/
struct _MetaBarrier
{
GObject parent;
MetaBarrierPrivate *priv;
};
/**
* MetaBarrierClass:
*
* The <structname>MetaBarrierClass</structname> structure contains only
* private data.
*/
struct _MetaBarrierClass
{
/*< private >*/
GObjectClass parent_class;
};
META_EXPORT
GType meta_barrier_get_type (void) G_GNUC_CONST;
META_EXPORT
gboolean meta_barrier_is_active (MetaBarrier *barrier);
META_EXPORT
void meta_barrier_destroy (MetaBarrier *barrier);
META_EXPORT
void meta_barrier_release (MetaBarrier *barrier,
MetaBarrierEvent *event);
/**
* MetaBarrierDirection:
* @META_BARRIER_DIRECTION_POSITIVE_X: Positive direction in the X axis
@ -78,6 +26,23 @@ typedef enum
META_BARRIER_DIRECTION_NEGATIVE_Y = 1 << 3,
} MetaBarrierDirection;
#define META_TYPE_BARRIER (meta_barrier_get_type ())
META_EXPORT
G_DECLARE_FINAL_TYPE (MetaBarrier, meta_barrier,
META, BARRIER, GObject)
typedef struct _MetaBarrierEvent MetaBarrierEvent;
META_EXPORT
gboolean meta_barrier_is_active (MetaBarrier *barrier);
META_EXPORT
void meta_barrier_destroy (MetaBarrier *barrier);
META_EXPORT
void meta_barrier_release (MetaBarrier *barrier,
MetaBarrierEvent *event);
/**
* MetaBarrierEvent:
* @event_id: A unique integer ID identifying a