mirror of
https://github.com/brl/mutter.git
synced 2024-11-26 18:11:05 -05:00
pointer-constraints: Move min edge distance from backend to Wayland
The min distance to the right/bottom edge depends on Wayland concepts (wl_fixed_t) and eventually geometry scale. Move the logic the Wayland side of the pointer constraints machinery to avoid the backend trying to figure this out without the proper data. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2460>
This commit is contained in:
parent
94aaa65bd2
commit
6d46ffccbc
@ -50,6 +50,7 @@ struct _MetaPointerConstraint
|
|||||||
{
|
{
|
||||||
GObject parent_instance;
|
GObject parent_instance;
|
||||||
cairo_region_t *region;
|
cairo_region_t *region;
|
||||||
|
double min_edge_distance;
|
||||||
};
|
};
|
||||||
|
|
||||||
G_DEFINE_TYPE (MetaPointerConstraint, meta_pointer_constraint, G_TYPE_OBJECT);
|
G_DEFINE_TYPE (MetaPointerConstraint, meta_pointer_constraint, G_TYPE_OBJECT);
|
||||||
@ -82,12 +83,14 @@ meta_pointer_constraint_class_init (MetaPointerConstraintClass *klass)
|
|||||||
|
|
||||||
|
|
||||||
MetaPointerConstraint *
|
MetaPointerConstraint *
|
||||||
meta_pointer_constraint_new (const cairo_region_t *region)
|
meta_pointer_constraint_new (const cairo_region_t *region,
|
||||||
|
double min_edge_distance)
|
||||||
{
|
{
|
||||||
MetaPointerConstraint *constraint;
|
MetaPointerConstraint *constraint;
|
||||||
|
|
||||||
constraint = g_object_new (META_TYPE_POINTER_CONSTRAINT, NULL);
|
constraint = g_object_new (META_TYPE_POINTER_CONSTRAINT, NULL);
|
||||||
constraint->region = cairo_region_copy (region);
|
constraint->region = cairo_region_copy (region);
|
||||||
|
constraint->min_edge_distance = min_edge_distance;
|
||||||
|
|
||||||
return constraint;
|
return constraint;
|
||||||
}
|
}
|
||||||
@ -98,6 +101,12 @@ meta_pointer_constraint_get_region (MetaPointerConstraint *constraint)
|
|||||||
return constraint->region;
|
return constraint->region;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double
|
||||||
|
meta_pointer_constraint_get_min_edge_distance (MetaPointerConstraint *constraint)
|
||||||
|
{
|
||||||
|
return constraint->min_edge_distance;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
meta_pointer_constraint_impl_init (MetaPointerConstraintImpl *constraint_impl)
|
meta_pointer_constraint_impl_init (MetaPointerConstraintImpl *constraint_impl)
|
||||||
{
|
{
|
||||||
|
@ -35,9 +35,13 @@ G_BEGIN_DECLS
|
|||||||
G_DECLARE_FINAL_TYPE (MetaPointerConstraint, meta_pointer_constraint,
|
G_DECLARE_FINAL_TYPE (MetaPointerConstraint, meta_pointer_constraint,
|
||||||
META, POINTER_CONSTRAINT, GObject);
|
META, POINTER_CONSTRAINT, GObject);
|
||||||
|
|
||||||
MetaPointerConstraint * meta_pointer_constraint_new (const cairo_region_t *region);
|
MetaPointerConstraint * meta_pointer_constraint_new (const cairo_region_t *region,
|
||||||
|
double min_edge_distance);
|
||||||
|
|
||||||
cairo_region_t * meta_pointer_constraint_get_region (MetaPointerConstraint *constraint);
|
cairo_region_t * meta_pointer_constraint_get_region (MetaPointerConstraint *constraint);
|
||||||
|
|
||||||
|
double meta_pointer_constraint_get_min_edge_distance (MetaPointerConstraint *constraint);
|
||||||
|
|
||||||
#define META_TYPE_POINTER_CONSTRAINT_IMPL (meta_pointer_constraint_impl_get_type ())
|
#define META_TYPE_POINTER_CONSTRAINT_IMPL (meta_pointer_constraint_impl_get_type ())
|
||||||
G_DECLARE_DERIVABLE_TYPE (MetaPointerConstraintImpl, meta_pointer_constraint_impl,
|
G_DECLARE_DERIVABLE_TYPE (MetaPointerConstraintImpl, meta_pointer_constraint_impl,
|
||||||
META, POINTER_CONSTRAINT_IMPL, GObject);
|
META, POINTER_CONSTRAINT_IMPL, GObject);
|
||||||
|
@ -407,9 +407,14 @@ meta_backend_native_set_pointer_constraint (MetaBackend *backend,
|
|||||||
|
|
||||||
if (constraint)
|
if (constraint)
|
||||||
{
|
{
|
||||||
|
double min_edge_distance;
|
||||||
|
|
||||||
region = meta_pointer_constraint_get_region (constraint);
|
region = meta_pointer_constraint_get_region (constraint);
|
||||||
|
min_edge_distance =
|
||||||
|
meta_pointer_constraint_get_min_edge_distance (constraint);
|
||||||
constraint_impl = meta_pointer_constraint_impl_native_new (constraint,
|
constraint_impl = meta_pointer_constraint_impl_native_new (constraint,
|
||||||
region);
|
region,
|
||||||
|
min_edge_distance);
|
||||||
}
|
}
|
||||||
|
|
||||||
meta_seat_native_set_pointer_constraint (META_SEAT_NATIVE (seat),
|
meta_seat_native_set_pointer_constraint (META_SEAT_NATIVE (seat),
|
||||||
|
@ -35,6 +35,7 @@ struct _MetaPointerConstraintImplNative
|
|||||||
MetaPointerConstraintImpl parent;
|
MetaPointerConstraintImpl parent;
|
||||||
MetaPointerConstraint *constraint;
|
MetaPointerConstraint *constraint;
|
||||||
cairo_region_t *region;
|
cairo_region_t *region;
|
||||||
|
double min_edge_distance;
|
||||||
};
|
};
|
||||||
|
|
||||||
G_DEFINE_TYPE (MetaPointerConstraintImplNative,
|
G_DEFINE_TYPE (MetaPointerConstraintImplNative,
|
||||||
@ -402,18 +403,13 @@ get_closest_border (GArray *borders,
|
|||||||
static void
|
static void
|
||||||
clamp_to_border (MetaBorder *border,
|
clamp_to_border (MetaBorder *border,
|
||||||
MetaLine2 *motion,
|
MetaLine2 *motion,
|
||||||
uint32_t *motion_dir)
|
uint32_t *motion_dir,
|
||||||
|
double min_edge_distance)
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
* When clamping either rightward or downward motions, the motion needs to be
|
|
||||||
* clamped so that the destination coordinate does not end up on the border
|
|
||||||
* (see weston_pointer_clamp_event_to_region). Do this by clamping such
|
|
||||||
* motions to the border minus the smallest possible wl_fixed_t value.
|
|
||||||
*/
|
|
||||||
if (meta_border_is_horizontal (border))
|
if (meta_border_is_horizontal (border))
|
||||||
{
|
{
|
||||||
if (*motion_dir & META_BORDER_MOTION_DIRECTION_POSITIVE_Y)
|
if (*motion_dir & META_BORDER_MOTION_DIRECTION_POSITIVE_Y)
|
||||||
motion->b.y = border->line.a.y - wl_fixed_to_double (1);
|
motion->b.y = border->line.a.y - min_edge_distance;
|
||||||
else
|
else
|
||||||
motion->b.y = border->line.a.y;
|
motion->b.y = border->line.a.y;
|
||||||
*motion_dir &= ~(META_BORDER_MOTION_DIRECTION_POSITIVE_Y |
|
*motion_dir &= ~(META_BORDER_MOTION_DIRECTION_POSITIVE_Y |
|
||||||
@ -422,7 +418,7 @@ clamp_to_border (MetaBorder *border,
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (*motion_dir & META_BORDER_MOTION_DIRECTION_POSITIVE_X)
|
if (*motion_dir & META_BORDER_MOTION_DIRECTION_POSITIVE_X)
|
||||||
motion->b.x = border->line.a.x - wl_fixed_to_double (1);
|
motion->b.x = border->line.a.x - min_edge_distance;
|
||||||
else
|
else
|
||||||
motion->b.x = border->line.a.x;
|
motion->b.x = border->line.a.x;
|
||||||
*motion_dir &= ~(META_BORDER_MOTION_DIRECTION_POSITIVE_X |
|
*motion_dir &= ~(META_BORDER_MOTION_DIRECTION_POSITIVE_X |
|
||||||
@ -510,9 +506,14 @@ meta_pointer_constraint_impl_native_constraint (MetaPointerConstraintImpl *const
|
|||||||
&motion,
|
&motion,
|
||||||
directions);
|
directions);
|
||||||
if (closest_border)
|
if (closest_border)
|
||||||
clamp_to_border (closest_border, &motion, &directions);
|
{
|
||||||
|
clamp_to_border (closest_border, &motion, &directions,
|
||||||
|
constraint_impl_native->min_edge_distance);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
break;
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*x_inout = motion.b.x;
|
*x_inout = motion.b.x;
|
||||||
@ -671,7 +672,8 @@ meta_pointer_constraint_impl_native_class_init (MetaPointerConstraintImplNativeC
|
|||||||
|
|
||||||
MetaPointerConstraintImpl *
|
MetaPointerConstraintImpl *
|
||||||
meta_pointer_constraint_impl_native_new (MetaPointerConstraint *constraint,
|
meta_pointer_constraint_impl_native_new (MetaPointerConstraint *constraint,
|
||||||
const cairo_region_t *region)
|
const cairo_region_t *region,
|
||||||
|
double min_edge_distance)
|
||||||
{
|
{
|
||||||
MetaPointerConstraintImplNative *constraint_impl;
|
MetaPointerConstraintImplNative *constraint_impl;
|
||||||
|
|
||||||
@ -679,6 +681,7 @@ meta_pointer_constraint_impl_native_new (MetaPointerConstraint *constraint,
|
|||||||
NULL);
|
NULL);
|
||||||
constraint_impl->constraint = constraint;
|
constraint_impl->constraint = constraint;
|
||||||
constraint_impl->region = cairo_region_copy (region);
|
constraint_impl->region = cairo_region_copy (region);
|
||||||
|
constraint_impl->min_edge_distance = min_edge_distance;
|
||||||
|
|
||||||
return META_POINTER_CONSTRAINT_IMPL (constraint_impl);
|
return META_POINTER_CONSTRAINT_IMPL (constraint_impl);
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,8 @@ G_DECLARE_FINAL_TYPE (MetaPointerConstraintImplNative,
|
|||||||
MetaPointerConstraintImpl)
|
MetaPointerConstraintImpl)
|
||||||
|
|
||||||
MetaPointerConstraintImpl * meta_pointer_constraint_impl_native_new (MetaPointerConstraint *constraint_impl,
|
MetaPointerConstraintImpl * meta_pointer_constraint_impl_native_new (MetaPointerConstraint *constraint_impl,
|
||||||
const cairo_region_t *region);
|
const cairo_region_t *region,
|
||||||
|
double min_edge_distance);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
|
@ -212,6 +212,7 @@ meta_pointer_confinement_wayland_create_constraint (MetaPointerConfinementWaylan
|
|||||||
MetaWaylandSurface *surface;
|
MetaWaylandSurface *surface;
|
||||||
cairo_region_t *region;
|
cairo_region_t *region;
|
||||||
float dx, dy;
|
float dx, dy;
|
||||||
|
double min_edge_distance;
|
||||||
|
|
||||||
priv = meta_pointer_confinement_wayland_get_instance_private (confinement);
|
priv = meta_pointer_confinement_wayland_get_instance_private (confinement);
|
||||||
|
|
||||||
@ -222,7 +223,8 @@ meta_pointer_confinement_wayland_create_constraint (MetaPointerConfinementWaylan
|
|||||||
meta_wayland_surface_get_absolute_coordinates (surface, 0, 0, &dx, &dy);
|
meta_wayland_surface_get_absolute_coordinates (surface, 0, 0, &dx, &dy);
|
||||||
cairo_region_translate (region, dx, dy);
|
cairo_region_translate (region, dx, dy);
|
||||||
|
|
||||||
constraint = meta_pointer_constraint_new (region);
|
min_edge_distance = wl_fixed_to_double (1);
|
||||||
|
constraint = meta_pointer_constraint_new (region, min_edge_distance);
|
||||||
cairo_region_destroy (region);
|
cairo_region_destroy (region);
|
||||||
|
|
||||||
return constraint;
|
return constraint;
|
||||||
|
@ -74,7 +74,7 @@ meta_pointer_lock_wayland_create_constraint (MetaPointerConfinementWayland *conf
|
|||||||
meta_wayland_surface_get_absolute_coordinates (surface, sx, sy, &x, &y);
|
meta_wayland_surface_get_absolute_coordinates (surface, sx, sy, &x, &y);
|
||||||
region = cairo_region_create_rectangle (&(cairo_rectangle_int_t) { (int) x, (int) y, 1 , 1 });
|
region = cairo_region_create_rectangle (&(cairo_rectangle_int_t) { (int) x, (int) y, 1 , 1 });
|
||||||
|
|
||||||
constraint = meta_pointer_constraint_new (region);
|
constraint = meta_pointer_constraint_new (region, 0.0);
|
||||||
cairo_region_destroy (region);
|
cairo_region_destroy (region);
|
||||||
|
|
||||||
return constraint;
|
return constraint;
|
||||||
|
Loading…
Reference in New Issue
Block a user