2015-06-17 04:10:52 +00:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 Red Hat
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
* 02111-1307, USA.
|
|
|
|
*
|
|
|
|
* Written by:
|
|
|
|
* Jonas Ådahl <jadahl@gmail.com>
|
|
|
|
*/
|
|
|
|
|
2018-10-19 07:15:54 +00:00
|
|
|
/**
|
|
|
|
* SECTION:meta-pointer-lock-wayland
|
|
|
|
* @title: MetaPointerLockWayland
|
|
|
|
* @short_description: A #MetaPointerConstraint implementing pointer lock.
|
|
|
|
*
|
|
|
|
* A MetaPointerLockConstraint implements the client pointer constraint "pointer
|
|
|
|
* lock": the cursor should not make any movement.
|
|
|
|
*/
|
|
|
|
|
2015-06-17 04:10:52 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "wayland/meta-pointer-lock-wayland.h"
|
|
|
|
|
|
|
|
#include <glib-object.h>
|
|
|
|
|
2020-07-08 16:17:13 +00:00
|
|
|
#include "backends/meta-backend-private.h"
|
|
|
|
#include "compositor/meta-surface-actor-wayland.h"
|
2015-06-17 04:10:52 +00:00
|
|
|
|
|
|
|
struct _MetaPointerLockWayland
|
|
|
|
{
|
2020-07-08 16:17:13 +00:00
|
|
|
GObject parent;
|
2015-06-17 04:10:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (MetaPointerLockWayland, meta_pointer_lock_wayland,
|
2020-07-08 16:17:13 +00:00
|
|
|
META_TYPE_POINTER_CONFINEMENT_WAYLAND)
|
2015-06-17 04:10:52 +00:00
|
|
|
|
2020-07-08 16:17:13 +00:00
|
|
|
static MetaPointerConstraint *
|
|
|
|
meta_pointer_lock_wayland_create_constraint (MetaPointerConfinementWayland *confinement)
|
2015-06-17 04:10:52 +00:00
|
|
|
{
|
2022-12-18 08:56:41 +00:00
|
|
|
MetaWaylandPointerConstraint *wayland_constraint =
|
|
|
|
meta_pointer_confinement_wayland_get_wayland_pointer_constraint (confinement);
|
|
|
|
MetaWaylandSurface *surface =
|
|
|
|
meta_wayland_pointer_constraint_get_surface (wayland_constraint);
|
|
|
|
MetaWaylandCompositor *compositor = surface->compositor;
|
2022-05-30 21:48:44 +00:00
|
|
|
MetaContext *context = meta_wayland_compositor_get_context (compositor);
|
|
|
|
MetaBackend *backend = meta_context_get_backend (context);
|
2020-07-08 16:17:13 +00:00
|
|
|
ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
|
|
|
|
ClutterSeat *seat = clutter_backend_get_default_seat (clutter_backend);
|
|
|
|
ClutterInputDevice *pointer = clutter_seat_get_pointer (seat);
|
|
|
|
MetaPointerConstraint *constraint;
|
|
|
|
graphene_point_t point;
|
2022-12-18 12:17:49 +00:00
|
|
|
cairo_rectangle_int_t rect;
|
2020-07-08 16:17:13 +00:00
|
|
|
cairo_region_t *region;
|
|
|
|
float sx, sy, x, y;
|
|
|
|
|
2020-11-18 14:49:02 +00:00
|
|
|
clutter_seat_query_state (seat, pointer, NULL, &point, NULL);
|
2020-07-08 16:17:13 +00:00
|
|
|
wayland_constraint =
|
|
|
|
meta_pointer_confinement_wayland_get_wayland_pointer_constraint (confinement);
|
|
|
|
surface = meta_wayland_pointer_constraint_get_surface (wayland_constraint);
|
|
|
|
meta_wayland_surface_get_relative_coordinates (surface,
|
|
|
|
point.x, point.y,
|
|
|
|
&sx, &sy);
|
|
|
|
|
|
|
|
meta_wayland_surface_get_absolute_coordinates (surface, sx, sy, &x, &y);
|
2022-12-18 12:17:49 +00:00
|
|
|
rect = (cairo_rectangle_int_t) { .x = x, .y = y, .width = 1, .height = 1 };
|
|
|
|
region = cairo_region_create_rectangle (&rect);
|
2020-07-08 16:17:13 +00:00
|
|
|
|
2022-06-13 08:23:40 +00:00
|
|
|
constraint = meta_pointer_constraint_new (region, 0.0);
|
2020-07-08 16:17:13 +00:00
|
|
|
cairo_region_destroy (region);
|
|
|
|
|
|
|
|
return constraint;
|
2015-06-17 04:10:52 +00:00
|
|
|
}
|
|
|
|
|
2020-07-08 16:17:13 +00:00
|
|
|
MetaPointerConfinementWayland *
|
|
|
|
meta_pointer_lock_wayland_new (MetaWaylandPointerConstraint *constraint)
|
2015-06-17 04:10:52 +00:00
|
|
|
{
|
2020-07-08 16:17:13 +00:00
|
|
|
return g_object_new (META_TYPE_POINTER_LOCK_WAYLAND,
|
|
|
|
"wayland-pointer-constraint", constraint,
|
|
|
|
NULL);
|
2015-06-17 04:10:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_pointer_lock_wayland_init (MetaPointerLockWayland *lock_wayland)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_pointer_lock_wayland_class_init (MetaPointerLockWaylandClass *klass)
|
|
|
|
{
|
2020-07-08 16:17:13 +00:00
|
|
|
MetaPointerConfinementWaylandClass *confinement_class =
|
|
|
|
META_POINTER_CONFINEMENT_WAYLAND_CLASS (klass);
|
2015-06-17 04:10:52 +00:00
|
|
|
|
2020-07-08 16:17:13 +00:00
|
|
|
confinement_class->create_constraint =
|
|
|
|
meta_pointer_lock_wayland_create_constraint;
|
2015-06-17 04:10:52 +00:00
|
|
|
}
|