2015-06-17 00:10:52 -04: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>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2018-07-10 04:36:24 -04:00
|
|
|
#include "wayland/meta-wayland-pointer-constraints.h"
|
2015-06-17 00:10:52 -04:00
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
|
|
|
#include "backends/meta-backend-private.h"
|
|
|
|
#include "backends/meta-pointer-constraint.h"
|
2018-07-10 04:36:24 -04:00
|
|
|
#include "backends/native/meta-backend-native.h"
|
2016-09-22 22:51:56 -04:00
|
|
|
#include "core/frame.h"
|
2018-07-10 04:36:24 -04:00
|
|
|
#include "core/window-private.h"
|
|
|
|
#include "meta/meta-backend.h"
|
|
|
|
#include "wayland/meta-pointer-confinement-wayland.h"
|
|
|
|
#include "wayland/meta-pointer-lock-wayland.h"
|
|
|
|
#include "wayland/meta-wayland-pointer.h"
|
|
|
|
#include "wayland/meta-wayland-private.h"
|
|
|
|
#include "wayland/meta-wayland-region.h"
|
|
|
|
#include "wayland/meta-wayland-seat.h"
|
|
|
|
#include "wayland/meta-wayland-surface.h"
|
|
|
|
#include "wayland/meta-xwayland.h"
|
2015-06-17 00:10:52 -04:00
|
|
|
|
|
|
|
#include "pointer-constraints-unstable-v1-server-protocol.h"
|
|
|
|
|
|
|
|
static GQuark quark_pending_constraint_state = 0;
|
2016-02-24 03:27:52 -05:00
|
|
|
static GQuark quark_surface_pointer_constraints_data = 0;
|
2015-06-17 00:10:52 -04:00
|
|
|
|
|
|
|
struct _MetaWaylandPointerConstraint
|
|
|
|
{
|
|
|
|
GObject parent;
|
|
|
|
|
|
|
|
MetaWaylandSurface *surface;
|
|
|
|
gboolean is_enabled;
|
|
|
|
cairo_region_t *region;
|
|
|
|
struct wl_resource *resource;
|
|
|
|
MetaWaylandPointerGrab grab;
|
|
|
|
MetaWaylandSeat *seat;
|
|
|
|
enum zwp_pointer_constraints_v1_lifetime lifetime;
|
2016-09-06 01:14:44 -04:00
|
|
|
gulong pointer_focus_surface_handler_id;
|
2015-06-17 00:10:52 -04:00
|
|
|
|
|
|
|
gboolean hint_set;
|
|
|
|
wl_fixed_t x_hint;
|
|
|
|
wl_fixed_t y_hint;
|
|
|
|
|
|
|
|
MetaPointerConstraint *constraint;
|
|
|
|
};
|
|
|
|
|
2016-02-24 03:27:52 -05:00
|
|
|
typedef struct _MetaWaylandSurfacePointerConstraintsData
|
|
|
|
{
|
2016-04-01 09:04:22 -04:00
|
|
|
MetaWaylandSurface *surface;
|
|
|
|
|
2016-02-24 03:27:52 -05:00
|
|
|
GList *pointer_constraints;
|
2016-04-01 09:04:22 -04:00
|
|
|
|
2016-02-24 06:55:58 -05:00
|
|
|
MetaWindow *window;
|
2016-04-01 09:04:22 -04:00
|
|
|
gulong window_associated_handler_id;
|
|
|
|
|
2016-02-24 06:55:58 -05:00
|
|
|
gulong appears_changed_handler_id;
|
2016-02-24 22:27:27 -05:00
|
|
|
gulong raised_handler_id;
|
2016-02-24 03:27:52 -05:00
|
|
|
} MetaWaylandSurfacePointerConstraintsData;
|
|
|
|
|
2015-06-17 00:10:52 -04:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
MetaWaylandPointerConstraint *constraint;
|
|
|
|
cairo_region_t *region;
|
|
|
|
gulong applied_handler_id;
|
|
|
|
} MetaWaylandPendingConstraintState;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GList *pending_constraint_states;
|
|
|
|
} MetaWaylandPendingConstraintStateContainer;
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (MetaWaylandPointerConstraint, meta_wayland_pointer_constraint,
|
|
|
|
G_TYPE_OBJECT);
|
|
|
|
|
|
|
|
static const struct zwp_locked_pointer_v1_interface locked_pointer_interface;
|
|
|
|
static const struct zwp_confined_pointer_v1_interface confined_pointer_interface;
|
|
|
|
static const MetaWaylandPointerGrabInterface locked_pointer_grab_interface;
|
|
|
|
static const MetaWaylandPointerGrabInterface confined_pointer_grab_interface;
|
|
|
|
|
2016-02-24 03:27:52 -05:00
|
|
|
static void
|
|
|
|
meta_wayland_pointer_constraint_destroy (MetaWaylandPointerConstraint *constraint);
|
|
|
|
|
2016-04-01 09:04:22 -04:00
|
|
|
static void
|
|
|
|
meta_wayland_pointer_constraint_maybe_enable (MetaWaylandPointerConstraint *constraint);
|
|
|
|
|
2016-02-24 06:55:58 -05:00
|
|
|
static void
|
|
|
|
meta_wayland_pointer_constraint_maybe_enable_for_window (MetaWindow *window);
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_wayland_pointer_constraint_maybe_remove_for_seat (MetaWaylandSeat *seat,
|
2016-02-24 22:20:09 -05:00
|
|
|
MetaWindow *window);
|
2016-02-24 06:55:58 -05:00
|
|
|
|
2016-02-24 03:27:52 -05:00
|
|
|
static MetaWaylandSurfacePointerConstraintsData *
|
|
|
|
get_surface_constraints_data (MetaWaylandSurface *surface)
|
|
|
|
{
|
|
|
|
return g_object_get_qdata (G_OBJECT (surface),
|
|
|
|
quark_surface_pointer_constraints_data);
|
|
|
|
}
|
|
|
|
|
2016-02-24 06:55:58 -05:00
|
|
|
static void
|
|
|
|
appears_focused_changed (MetaWindow *window,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
MetaWaylandCompositor *wayland_compositor;
|
|
|
|
|
|
|
|
wayland_compositor = meta_wayland_compositor_get_default ();
|
|
|
|
meta_wayland_pointer_constraint_maybe_remove_for_seat (wayland_compositor->seat,
|
|
|
|
window);
|
|
|
|
|
|
|
|
meta_wayland_pointer_constraint_maybe_enable_for_window (window);
|
|
|
|
}
|
|
|
|
|
2016-02-24 22:27:27 -05:00
|
|
|
static void
|
|
|
|
window_raised (MetaWindow *window)
|
|
|
|
{
|
|
|
|
meta_wayland_pointer_constraint_maybe_enable_for_window (window);
|
|
|
|
}
|
|
|
|
|
2016-04-01 09:04:22 -04:00
|
|
|
static void
|
|
|
|
connect_window (MetaWaylandSurfacePointerConstraintsData *data,
|
|
|
|
MetaWindow *window)
|
|
|
|
{
|
|
|
|
data->window = window;
|
|
|
|
g_object_add_weak_pointer (G_OBJECT (data->window),
|
|
|
|
(gpointer *) &data->window);
|
|
|
|
data->appears_changed_handler_id =
|
|
|
|
g_signal_connect (data->window, "notify::appears-focused",
|
|
|
|
G_CALLBACK (appears_focused_changed), NULL);
|
|
|
|
data->raised_handler_id =
|
|
|
|
g_signal_connect (data->window, "raised",
|
|
|
|
G_CALLBACK (window_raised), NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
window_associated (MetaWaylandSurfaceRole *surface_role,
|
|
|
|
MetaWaylandSurfacePointerConstraintsData *data)
|
|
|
|
{
|
|
|
|
MetaWaylandSurface *surface = data->surface;
|
|
|
|
|
|
|
|
connect_window (data, surface->window);
|
|
|
|
g_signal_handler_disconnect (surface, data->window_associated_handler_id);
|
|
|
|
data->window_associated_handler_id = 0;
|
|
|
|
|
|
|
|
meta_wayland_pointer_constraint_maybe_enable_for_window (surface->window);
|
|
|
|
}
|
|
|
|
|
2016-02-24 06:55:58 -05:00
|
|
|
static MetaWaylandSurfacePointerConstraintsData *
|
|
|
|
surface_constraint_data_new (MetaWaylandSurface *surface)
|
|
|
|
{
|
|
|
|
MetaWaylandSurfacePointerConstraintsData *data;
|
|
|
|
|
|
|
|
data = g_new0 (MetaWaylandSurfacePointerConstraintsData, 1);
|
|
|
|
|
2016-04-01 09:04:22 -04:00
|
|
|
data->surface = surface;
|
|
|
|
|
2016-02-24 06:55:58 -05:00
|
|
|
if (surface->window)
|
|
|
|
{
|
2016-04-01 09:04:22 -04:00
|
|
|
connect_window (data, surface->window);
|
|
|
|
}
|
|
|
|
else if (meta_xwayland_is_xwayland_surface (surface))
|
|
|
|
{
|
|
|
|
data->window_associated_handler_id =
|
|
|
|
g_signal_connect (surface->role, "window-associated",
|
|
|
|
G_CALLBACK (window_associated),
|
|
|
|
data);
|
2016-02-24 06:55:58 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* TODO: Support constraints on non-toplevel windows, such as subsurfaces.
|
|
|
|
*/
|
|
|
|
g_warn_if_reached ();
|
|
|
|
}
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
2016-02-24 03:27:52 -05:00
|
|
|
static void
|
|
|
|
surface_constraint_data_free (MetaWaylandSurfacePointerConstraintsData *data)
|
|
|
|
{
|
2016-02-24 06:55:58 -05:00
|
|
|
if (data->window)
|
|
|
|
{
|
|
|
|
g_signal_handler_disconnect (data->window,
|
|
|
|
data->appears_changed_handler_id);
|
2016-02-24 22:27:27 -05:00
|
|
|
g_signal_handler_disconnect (data->window,
|
|
|
|
data->raised_handler_id);
|
2016-02-24 06:55:58 -05:00
|
|
|
g_object_remove_weak_pointer (G_OBJECT (data->window),
|
|
|
|
(gpointer *) &data->window);
|
|
|
|
}
|
2016-04-01 09:04:22 -04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
g_signal_handler_disconnect (data->surface->role,
|
|
|
|
data->window_associated_handler_id);
|
|
|
|
}
|
2016-02-24 06:55:58 -05:00
|
|
|
|
2016-02-24 03:27:52 -05:00
|
|
|
g_list_free_full (data->pointer_constraints,
|
|
|
|
(GDestroyNotify) meta_wayland_pointer_constraint_destroy);
|
|
|
|
g_free (data);
|
|
|
|
}
|
|
|
|
|
2016-04-01 09:04:22 -04:00
|
|
|
static void
|
|
|
|
constrained_surface_destroyed (MetaWaylandSurface *surface,
|
|
|
|
MetaWaylandSurfacePointerConstraintsData *data)
|
|
|
|
{
|
|
|
|
surface_constraint_data_free (data);
|
|
|
|
}
|
|
|
|
|
2016-02-24 03:27:52 -05:00
|
|
|
static MetaWaylandSurfacePointerConstraintsData *
|
|
|
|
ensure_surface_constraints_data (MetaWaylandSurface *surface)
|
|
|
|
{
|
|
|
|
MetaWaylandSurfacePointerConstraintsData *data;
|
|
|
|
|
|
|
|
data = get_surface_constraints_data (surface);
|
|
|
|
if (!data)
|
|
|
|
{
|
2016-02-24 06:55:58 -05:00
|
|
|
data = surface_constraint_data_new (surface);
|
2016-04-01 09:04:22 -04:00
|
|
|
g_object_set_qdata (G_OBJECT (surface),
|
|
|
|
quark_surface_pointer_constraints_data,
|
|
|
|
data);
|
|
|
|
g_signal_connect (surface, "destroy",
|
|
|
|
G_CALLBACK (constrained_surface_destroyed), data);
|
2016-02-24 03:27:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
surface_add_pointer_constraint (MetaWaylandSurface *surface,
|
|
|
|
MetaWaylandPointerConstraint *constraint)
|
|
|
|
{
|
|
|
|
MetaWaylandSurfacePointerConstraintsData *data;
|
|
|
|
|
|
|
|
data = ensure_surface_constraints_data (surface);
|
|
|
|
data->pointer_constraints = g_list_append (data->pointer_constraints,
|
|
|
|
constraint);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
surface_remove_pointer_constraints (MetaWaylandSurface *surface,
|
|
|
|
MetaWaylandPointerConstraint *constraint)
|
|
|
|
{
|
|
|
|
MetaWaylandSurfacePointerConstraintsData *data;
|
|
|
|
|
|
|
|
data = get_surface_constraints_data (surface);
|
|
|
|
data->pointer_constraints =
|
|
|
|
g_list_remove (data->pointer_constraints, constraint);
|
|
|
|
|
|
|
|
if (!data->pointer_constraints)
|
|
|
|
{
|
|
|
|
g_object_set_qdata (G_OBJECT (surface),
|
|
|
|
quark_surface_pointer_constraints_data,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-06 01:14:44 -04:00
|
|
|
static void
|
|
|
|
pointer_focus_surface_changed (MetaWaylandPointer *pointer,
|
|
|
|
MetaWaylandPointerConstraint *constraint)
|
|
|
|
{
|
2016-09-13 01:25:04 -04:00
|
|
|
MetaWindow *window = constraint->surface->window;
|
|
|
|
|
|
|
|
if (window)
|
|
|
|
{
|
|
|
|
MetaWaylandSeat *seat = meta_wayland_pointer_get_seat (pointer);
|
|
|
|
|
|
|
|
meta_wayland_pointer_constraint_maybe_remove_for_seat (seat, window);
|
|
|
|
}
|
|
|
|
|
2016-09-06 01:14:44 -04:00
|
|
|
meta_wayland_pointer_constraint_maybe_enable (constraint);
|
|
|
|
}
|
|
|
|
|
2015-06-17 00:10:52 -04:00
|
|
|
static MetaWaylandPointerConstraint *
|
|
|
|
meta_wayland_pointer_constraint_new (MetaWaylandSurface *surface,
|
|
|
|
MetaWaylandSeat *seat,
|
|
|
|
MetaWaylandRegion *region,
|
|
|
|
enum zwp_pointer_constraints_v1_lifetime lifetime,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
const MetaWaylandPointerGrabInterface *grab_interface)
|
|
|
|
{
|
|
|
|
MetaWaylandPointerConstraint *constraint;
|
|
|
|
|
|
|
|
constraint = g_object_new (META_TYPE_WAYLAND_POINTER_CONSTRAINT, NULL);
|
|
|
|
if (!constraint)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
constraint->surface = surface;
|
|
|
|
constraint->seat = seat;
|
|
|
|
constraint->lifetime = lifetime;
|
|
|
|
constraint->resource = resource;
|
|
|
|
constraint->grab.interface = grab_interface;
|
|
|
|
|
|
|
|
if (region)
|
|
|
|
{
|
|
|
|
constraint->region =
|
|
|
|
cairo_region_copy (meta_wayland_region_peek_cairo_region (region));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-02-23 09:21:29 -05:00
|
|
|
constraint->region = NULL;
|
2015-06-17 00:10:52 -04:00
|
|
|
}
|
|
|
|
|
2016-09-06 01:14:44 -04:00
|
|
|
constraint->pointer_focus_surface_handler_id =
|
|
|
|
g_signal_connect (seat->pointer, "focus-surface-changed",
|
|
|
|
G_CALLBACK (pointer_focus_surface_changed),
|
|
|
|
constraint);
|
|
|
|
|
2015-06-17 00:10:52 -04:00
|
|
|
return constraint;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
meta_wayland_pointer_constraint_is_enabled (MetaWaylandPointerConstraint *constraint)
|
|
|
|
{
|
|
|
|
return constraint->is_enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_wayland_pointer_constraint_notify_activated (MetaWaylandPointerConstraint *constraint)
|
|
|
|
{
|
|
|
|
struct wl_resource *resource = constraint->resource;
|
|
|
|
|
|
|
|
if (wl_resource_instance_of (resource,
|
|
|
|
&zwp_locked_pointer_v1_interface,
|
|
|
|
&locked_pointer_interface))
|
|
|
|
{
|
|
|
|
zwp_locked_pointer_v1_send_locked (resource);
|
|
|
|
}
|
|
|
|
else if (wl_resource_instance_of (resource,
|
|
|
|
&zwp_confined_pointer_v1_interface,
|
|
|
|
&confined_pointer_interface))
|
|
|
|
{
|
|
|
|
zwp_confined_pointer_v1_send_confined (resource);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_wayland_pointer_constraint_notify_deactivated (MetaWaylandPointerConstraint *constraint)
|
|
|
|
{
|
|
|
|
struct wl_resource *resource = constraint->resource;
|
|
|
|
|
|
|
|
if (wl_resource_instance_of (resource,
|
|
|
|
&zwp_locked_pointer_v1_interface,
|
|
|
|
&locked_pointer_interface))
|
|
|
|
zwp_locked_pointer_v1_send_unlocked (resource);
|
|
|
|
else if (wl_resource_instance_of (resource,
|
|
|
|
&zwp_confined_pointer_v1_interface,
|
|
|
|
&confined_pointer_interface))
|
|
|
|
zwp_confined_pointer_v1_send_unconfined (resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
static MetaPointerConstraint *
|
|
|
|
meta_wayland_pointer_constraint_create_pointer_constraint (MetaWaylandPointerConstraint *constraint)
|
|
|
|
{
|
|
|
|
struct wl_resource *resource = constraint->resource;
|
|
|
|
|
|
|
|
if (wl_resource_instance_of (resource,
|
|
|
|
&zwp_locked_pointer_v1_interface,
|
|
|
|
&locked_pointer_interface))
|
|
|
|
{
|
|
|
|
return meta_pointer_lock_wayland_new ();
|
|
|
|
}
|
|
|
|
else if (wl_resource_instance_of (resource,
|
|
|
|
&zwp_confined_pointer_v1_interface,
|
|
|
|
&confined_pointer_interface))
|
|
|
|
{
|
|
|
|
return meta_pointer_confinement_wayland_new (constraint);
|
|
|
|
}
|
|
|
|
g_assert_not_reached ();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_wayland_pointer_constraint_enable (MetaWaylandPointerConstraint *constraint)
|
|
|
|
{
|
|
|
|
MetaBackend *backend = meta_get_backend ();
|
|
|
|
|
|
|
|
g_assert (!constraint->is_enabled);
|
|
|
|
|
|
|
|
constraint->is_enabled = TRUE;
|
|
|
|
meta_wayland_pointer_constraint_notify_activated (constraint);
|
2016-04-01 04:39:30 -04:00
|
|
|
meta_wayland_pointer_start_grab (constraint->seat->pointer,
|
2015-06-17 00:10:52 -04:00
|
|
|
&constraint->grab);
|
|
|
|
|
|
|
|
constraint->constraint =
|
|
|
|
meta_wayland_pointer_constraint_create_pointer_constraint (constraint);
|
|
|
|
meta_backend_set_client_pointer_constraint (backend, constraint->constraint);
|
|
|
|
g_object_add_weak_pointer (G_OBJECT (constraint->constraint),
|
|
|
|
(gpointer *) &constraint->constraint);
|
|
|
|
g_object_unref (constraint->constraint);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_wayland_pointer_constraint_disable (MetaWaylandPointerConstraint *constraint)
|
|
|
|
{
|
2016-02-24 22:13:30 -05:00
|
|
|
constraint->is_enabled = FALSE;
|
2015-06-17 00:10:52 -04:00
|
|
|
meta_wayland_pointer_constraint_notify_deactivated (constraint);
|
|
|
|
meta_wayland_pointer_end_grab (constraint->grab.pointer);
|
|
|
|
meta_backend_set_client_pointer_constraint (meta_get_backend (), NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_wayland_pointer_constraint_destroy (MetaWaylandPointerConstraint *constraint)
|
|
|
|
{
|
|
|
|
if (meta_wayland_pointer_constraint_is_enabled (constraint))
|
|
|
|
meta_wayland_pointer_constraint_disable (constraint);
|
|
|
|
|
|
|
|
wl_resource_set_user_data (constraint->resource, NULL);
|
2016-02-23 09:21:29 -05:00
|
|
|
g_clear_pointer (&constraint->region, cairo_region_destroy);
|
2015-06-17 00:10:52 -04:00
|
|
|
g_object_unref (constraint);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
is_within_constraint_region (MetaWaylandPointerConstraint *constraint,
|
|
|
|
wl_fixed_t sx,
|
|
|
|
wl_fixed_t sy)
|
|
|
|
{
|
|
|
|
cairo_region_t *region;
|
|
|
|
gboolean is_within;
|
|
|
|
|
|
|
|
region = meta_wayland_pointer_constraint_calculate_effective_region (constraint);
|
2016-02-23 08:26:52 -05:00
|
|
|
is_within = cairo_region_contains_point (region,
|
2015-06-17 00:10:52 -04:00
|
|
|
wl_fixed_to_int (sx),
|
|
|
|
wl_fixed_to_int (sy));
|
|
|
|
cairo_region_destroy (region);
|
|
|
|
|
|
|
|
return is_within;
|
|
|
|
}
|
|
|
|
|
2016-09-21 05:28:51 -04:00
|
|
|
static gboolean
|
|
|
|
should_constraint_be_enabled (MetaWaylandPointerConstraint *constraint)
|
2015-06-17 00:10:52 -04:00
|
|
|
{
|
2016-09-13 01:23:52 -04:00
|
|
|
MetaWindow *window;
|
2016-04-01 09:10:15 -04:00
|
|
|
|
2016-09-13 01:23:52 -04:00
|
|
|
window = constraint->surface->window;
|
|
|
|
if (!window)
|
2016-02-24 22:15:29 -05:00
|
|
|
{
|
2016-04-01 09:04:22 -04:00
|
|
|
/*
|
|
|
|
* Locks from Xwayland may come before we have had the opportunity to
|
|
|
|
* associate the X11 Window with the wl_surface.
|
|
|
|
*/
|
|
|
|
g_warn_if_fail (meta_xwayland_is_xwayland_surface (constraint->surface));
|
2016-09-21 05:28:51 -04:00
|
|
|
return FALSE;
|
2016-02-24 22:15:29 -05:00
|
|
|
}
|
|
|
|
|
2016-09-13 01:23:52 -04:00
|
|
|
if (window->unmanaging)
|
2016-09-21 05:28:51 -04:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (constraint->seat->pointer->focus_surface != constraint->surface)
|
|
|
|
return FALSE;
|
2016-09-13 01:23:52 -04:00
|
|
|
|
2016-04-01 09:13:10 -04:00
|
|
|
if (meta_xwayland_is_xwayland_surface (constraint->surface))
|
|
|
|
{
|
|
|
|
MetaDisplay *display = meta_get_display ();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We need to handle Xwayland surfaces differently in order to allow
|
|
|
|
* Xwayland to be able to lock the pointer. For example, we cannot require
|
|
|
|
* the locked window to "appear focused" because the surface Xwayland
|
|
|
|
* locks might not be able to appear focused (for example it may be a
|
|
|
|
* override redirect window).
|
|
|
|
*
|
|
|
|
* Since we don't have any way to know what focused window an override
|
|
|
|
* redirect is associated with, nor have a way to know if the override
|
|
|
|
* redirect window even shares the same connection as a focused window,
|
|
|
|
* we simply can only really restrict it to enable the lock if any
|
|
|
|
* Xwayland window appears focused.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (display->focus_window &&
|
|
|
|
display->focus_window->client_type != META_WINDOW_CLIENT_TYPE_X11)
|
2016-09-21 05:28:51 -04:00
|
|
|
return FALSE;
|
2016-04-01 09:13:10 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-09-21 05:28:51 -04:00
|
|
|
MetaWindow *window = constraint->surface->window;
|
|
|
|
|
2016-09-13 01:23:52 -04:00
|
|
|
if (!meta_window_appears_focused (window))
|
2016-09-21 05:28:51 -04:00
|
|
|
return FALSE;
|
2016-04-01 09:13:10 -04:00
|
|
|
}
|
2015-06-17 00:10:52 -04:00
|
|
|
|
2016-09-21 05:28:51 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_wayland_pointer_constraint_maybe_enable (MetaWaylandPointerConstraint *constraint)
|
|
|
|
{
|
|
|
|
wl_fixed_t sx, sy;
|
|
|
|
|
|
|
|
if (constraint->is_enabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!should_constraint_be_enabled (constraint))
|
|
|
|
return;
|
|
|
|
|
2016-04-01 04:39:30 -04:00
|
|
|
meta_wayland_pointer_get_relative_coordinates (constraint->seat->pointer,
|
2015-06-17 00:10:52 -04:00
|
|
|
constraint->surface,
|
|
|
|
&sx, &sy);
|
|
|
|
if (!is_within_constraint_region (constraint, sx, sy))
|
|
|
|
return;
|
|
|
|
|
|
|
|
meta_wayland_pointer_constraint_enable (constraint);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_wayland_pointer_constraint_remove (MetaWaylandPointerConstraint *constraint)
|
|
|
|
{
|
|
|
|
MetaWaylandSurface *surface = constraint->surface;
|
|
|
|
|
2016-02-24 03:27:52 -05:00
|
|
|
surface_remove_pointer_constraints (surface, constraint);
|
2015-06-17 00:10:52 -04:00
|
|
|
meta_wayland_pointer_constraint_destroy (constraint);
|
|
|
|
}
|
|
|
|
|
2016-09-21 04:32:55 -04:00
|
|
|
static void
|
|
|
|
meta_wayland_pointer_constraint_deactivate (MetaWaylandPointerConstraint *constraint)
|
|
|
|
{
|
|
|
|
switch (constraint->lifetime)
|
|
|
|
{
|
|
|
|
case ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_ONESHOT:
|
|
|
|
meta_wayland_pointer_constraint_remove (constraint);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_PERSISTENT:
|
|
|
|
meta_wayland_pointer_constraint_disable (constraint);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-17 00:10:52 -04:00
|
|
|
void
|
|
|
|
meta_wayland_pointer_constraint_maybe_remove_for_seat (MetaWaylandSeat *seat,
|
2016-02-24 22:20:09 -05:00
|
|
|
MetaWindow *window)
|
2015-06-17 00:10:52 -04:00
|
|
|
{
|
2016-04-01 04:39:30 -04:00
|
|
|
MetaWaylandPointer *pointer = seat->pointer;
|
2016-02-24 22:20:09 -05:00
|
|
|
MetaWaylandPointerConstraint *constraint;
|
|
|
|
|
|
|
|
if ((pointer->grab->interface != &confined_pointer_grab_interface &&
|
|
|
|
pointer->grab->interface != &locked_pointer_grab_interface))
|
|
|
|
return;
|
|
|
|
|
|
|
|
constraint = wl_container_of (pointer->grab, constraint, grab);
|
|
|
|
|
2016-09-21 05:28:51 -04:00
|
|
|
if (should_constraint_be_enabled (constraint))
|
2016-02-24 22:20:09 -05:00
|
|
|
return;
|
2015-06-17 00:10:52 -04:00
|
|
|
|
2016-09-21 04:32:55 -04:00
|
|
|
meta_wayland_pointer_constraint_deactivate (constraint);
|
2015-06-17 00:10:52 -04:00
|
|
|
}
|
|
|
|
|
2016-02-24 06:55:58 -05:00
|
|
|
static void
|
2015-06-17 00:10:52 -04:00
|
|
|
meta_wayland_pointer_constraint_maybe_enable_for_window (MetaWindow *window)
|
|
|
|
{
|
|
|
|
MetaWaylandSurface *surface = window->surface;
|
2016-02-24 03:27:52 -05:00
|
|
|
MetaWaylandSurfacePointerConstraintsData *surface_data;
|
|
|
|
GList *l;
|
|
|
|
|
2016-04-01 09:04:22 -04:00
|
|
|
if (!surface)
|
|
|
|
{
|
|
|
|
g_warn_if_fail (window->client_type == META_WINDOW_CLIENT_TYPE_X11);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-02-24 03:27:52 -05:00
|
|
|
surface_data = get_surface_constraints_data (surface);
|
|
|
|
if (!surface_data)
|
|
|
|
return;
|
2015-06-17 00:10:52 -04:00
|
|
|
|
2016-02-24 03:27:52 -05:00
|
|
|
for (l = surface_data->pointer_constraints; l; l = l->next)
|
2015-06-17 00:10:52 -04:00
|
|
|
{
|
2016-02-24 03:27:52 -05:00
|
|
|
MetaWaylandPointerConstraint *constraint = l->data;
|
2015-06-17 00:10:52 -04:00
|
|
|
|
|
|
|
meta_wayland_pointer_constraint_maybe_enable (constraint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MetaWaylandSeat *
|
|
|
|
meta_wayland_pointer_constraint_get_seat (MetaWaylandPointerConstraint *constraint)
|
|
|
|
{
|
|
|
|
return constraint->seat;
|
|
|
|
}
|
|
|
|
|
|
|
|
cairo_region_t *
|
|
|
|
meta_wayland_pointer_constraint_calculate_effective_region (MetaWaylandPointerConstraint *constraint)
|
|
|
|
{
|
|
|
|
cairo_region_t *region;
|
2016-09-22 22:51:56 -04:00
|
|
|
MetaWindow *window;
|
2015-06-17 00:10:52 -04:00
|
|
|
|
2016-02-23 08:26:52 -05:00
|
|
|
region = meta_wayland_surface_calculate_input_region (constraint->surface);
|
2016-02-23 09:21:29 -05:00
|
|
|
if (constraint->region)
|
|
|
|
cairo_region_intersect (region, constraint->region);
|
2015-06-17 00:10:52 -04:00
|
|
|
|
2016-09-22 22:51:56 -04:00
|
|
|
window = constraint->surface->window;
|
|
|
|
if (window && window->frame)
|
|
|
|
{
|
|
|
|
MetaFrame *frame = window->frame;
|
|
|
|
int actual_width, actual_height;
|
|
|
|
|
|
|
|
g_assert (meta_xwayland_is_xwayland_surface (constraint->surface));
|
|
|
|
|
|
|
|
actual_width = window->buffer_rect.width - (frame->child_x +
|
|
|
|
frame->right_width);
|
|
|
|
actual_height = window->buffer_rect.height - (frame->child_y +
|
|
|
|
frame->bottom_height);
|
|
|
|
cairo_region_intersect_rectangle (region, &(cairo_rectangle_int_t) {
|
|
|
|
.x = frame->child_x,
|
|
|
|
.y = frame->child_y,
|
|
|
|
.width = actual_width,
|
|
|
|
.height = actual_height
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-06-17 00:10:52 -04:00
|
|
|
return region;
|
|
|
|
}
|
|
|
|
|
|
|
|
MetaWaylandSurface *
|
|
|
|
meta_wayland_pointer_constraint_get_surface (MetaWaylandPointerConstraint *constraint)
|
|
|
|
{
|
|
|
|
return constraint->surface;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pointer_constraint_resource_destroyed (struct wl_resource *resource)
|
|
|
|
{
|
|
|
|
MetaWaylandPointerConstraint *constraint =
|
|
|
|
wl_resource_get_user_data (resource);
|
|
|
|
|
|
|
|
if (!constraint)
|
|
|
|
return;
|
|
|
|
|
|
|
|
meta_wayland_pointer_constraint_remove (constraint);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pending_constraint_state_free (MetaWaylandPendingConstraintState *constraint_pending)
|
|
|
|
{
|
|
|
|
g_clear_pointer (&constraint_pending->region, cairo_region_destroy);
|
|
|
|
if (constraint_pending->constraint)
|
|
|
|
g_object_remove_weak_pointer (G_OBJECT (constraint_pending->constraint),
|
|
|
|
(gpointer *) &constraint_pending->constraint);
|
|
|
|
}
|
|
|
|
|
|
|
|
static MetaWaylandPendingConstraintStateContainer *
|
|
|
|
get_pending_constraint_state_container (MetaWaylandPendingState *pending)
|
|
|
|
{
|
|
|
|
return g_object_get_qdata (G_OBJECT (pending),
|
|
|
|
quark_pending_constraint_state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static MetaWaylandPendingConstraintState *
|
|
|
|
get_pending_constraint_state (MetaWaylandPointerConstraint *constraint)
|
|
|
|
{
|
|
|
|
MetaWaylandPendingState *pending = constraint->surface->pending;
|
|
|
|
MetaWaylandPendingConstraintStateContainer *container;
|
|
|
|
GList *l;
|
|
|
|
|
|
|
|
container = get_pending_constraint_state_container (pending);
|
|
|
|
for (l = container->pending_constraint_states; l; l = l->next)
|
|
|
|
{
|
|
|
|
MetaWaylandPendingConstraintState *constraint_pending = l->data;
|
|
|
|
|
|
|
|
if (constraint_pending->constraint == constraint)
|
|
|
|
return constraint_pending;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pending_constraint_state_container_free (MetaWaylandPendingConstraintStateContainer *container)
|
|
|
|
{
|
|
|
|
g_list_free_full (container->pending_constraint_states,
|
|
|
|
(GDestroyNotify) pending_constraint_state_free);
|
|
|
|
g_free (container);
|
|
|
|
}
|
|
|
|
|
|
|
|
static MetaWaylandPendingConstraintStateContainer *
|
|
|
|
ensure_pending_constraint_state_container (MetaWaylandPendingState *pending)
|
|
|
|
{
|
|
|
|
MetaWaylandPendingConstraintStateContainer *container;
|
|
|
|
|
|
|
|
container = get_pending_constraint_state_container (pending);
|
|
|
|
if (!container)
|
|
|
|
{
|
|
|
|
container = g_new0 (MetaWaylandPendingConstraintStateContainer, 1);
|
|
|
|
g_object_set_qdata_full (G_OBJECT (pending),
|
|
|
|
quark_pending_constraint_state,
|
|
|
|
container,
|
|
|
|
(GDestroyNotify) pending_constraint_state_container_free);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return container;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
remove_pending_constraint_state (MetaWaylandPointerConstraint *constraint,
|
|
|
|
MetaWaylandPendingState *pending)
|
|
|
|
{
|
|
|
|
MetaWaylandPendingConstraintStateContainer *container;
|
|
|
|
GList *l;
|
|
|
|
|
|
|
|
container = get_pending_constraint_state_container (pending);
|
|
|
|
for (l = container->pending_constraint_states; l; l = l->next)
|
|
|
|
{
|
|
|
|
MetaWaylandPendingConstraintState *constraint_pending = l->data;
|
|
|
|
if (constraint_pending->constraint != constraint)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
pending_constraint_state_free (l->data);
|
|
|
|
container->pending_constraint_states =
|
|
|
|
g_list_remove_link (container->pending_constraint_states, l);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pending_constraint_state_applied (MetaWaylandPendingState *pending,
|
|
|
|
MetaWaylandPendingConstraintState *constraint_pending)
|
|
|
|
{
|
|
|
|
MetaWaylandPointerConstraint *constraint = constraint_pending->constraint;
|
|
|
|
|
|
|
|
if (!constraint)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_clear_pointer (&constraint->region, cairo_region_destroy);
|
|
|
|
if (constraint_pending->region)
|
|
|
|
{
|
|
|
|
constraint->region = constraint_pending->region;
|
|
|
|
constraint_pending->region = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-02-23 09:21:29 -05:00
|
|
|
constraint->region = NULL;
|
2015-06-17 00:10:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
g_signal_handler_disconnect (pending,
|
|
|
|
constraint_pending->applied_handler_id);
|
|
|
|
remove_pending_constraint_state (constraint, pending);
|
|
|
|
|
|
|
|
/* The pointer is potentially warped by the actor paint signal callback if
|
|
|
|
* the new region proved it necessary.
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
static MetaWaylandPendingConstraintState *
|
|
|
|
ensure_pending_constraint_state (MetaWaylandPointerConstraint *constraint)
|
|
|
|
{
|
|
|
|
MetaWaylandPendingState *pending = constraint->surface->pending;
|
|
|
|
MetaWaylandPendingConstraintStateContainer *container;
|
|
|
|
MetaWaylandPendingConstraintState *constraint_pending;
|
|
|
|
|
|
|
|
container = ensure_pending_constraint_state_container (pending);
|
|
|
|
constraint_pending = get_pending_constraint_state (constraint);
|
|
|
|
if (!constraint_pending)
|
|
|
|
{
|
|
|
|
constraint_pending = g_new0 (MetaWaylandPendingConstraintState, 1);
|
|
|
|
constraint_pending->constraint = constraint;
|
|
|
|
constraint_pending->applied_handler_id =
|
|
|
|
g_signal_connect (pending, "applied",
|
|
|
|
G_CALLBACK (pending_constraint_state_applied),
|
|
|
|
constraint_pending);
|
|
|
|
g_object_add_weak_pointer (G_OBJECT (constraint),
|
|
|
|
(gpointer *) &constraint_pending->constraint);
|
|
|
|
|
|
|
|
container->pending_constraint_states =
|
|
|
|
g_list_append (container->pending_constraint_states,
|
|
|
|
constraint_pending);
|
|
|
|
}
|
|
|
|
|
|
|
|
return constraint_pending;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_wayland_pointer_constraint_set_pending_region (MetaWaylandPointerConstraint *constraint,
|
|
|
|
MetaWaylandRegion *region)
|
|
|
|
{
|
|
|
|
MetaWaylandPendingConstraintState *constraint_pending;
|
|
|
|
|
|
|
|
constraint_pending = ensure_pending_constraint_state (constraint);
|
|
|
|
|
|
|
|
g_clear_pointer (&constraint_pending->region, cairo_region_destroy);
|
|
|
|
if (region)
|
|
|
|
{
|
|
|
|
constraint_pending->region =
|
|
|
|
cairo_region_copy (meta_wayland_region_peek_cairo_region (region));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-24 03:27:52 -05:00
|
|
|
static MetaWaylandPointerConstraint *
|
|
|
|
get_pointer_constraint_for_seat (MetaWaylandSurface *surface,
|
|
|
|
MetaWaylandSeat *seat)
|
|
|
|
{
|
|
|
|
MetaWaylandSurfacePointerConstraintsData *surface_data;
|
|
|
|
GList *l;
|
|
|
|
|
|
|
|
surface_data = get_surface_constraints_data (surface);
|
|
|
|
if (!surface_data)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
for (l = surface_data->pointer_constraints; l; l = l->next)
|
|
|
|
{
|
|
|
|
MetaWaylandPointerConstraint *constraint = l->data;
|
|
|
|
|
|
|
|
if (seat == constraint->seat)
|
|
|
|
return constraint;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-06-17 00:10:52 -04:00
|
|
|
static void
|
|
|
|
init_pointer_constraint (struct wl_resource *resource,
|
|
|
|
uint32_t id,
|
|
|
|
MetaWaylandSurface *surface,
|
|
|
|
MetaWaylandSeat *seat,
|
|
|
|
MetaWaylandRegion *region,
|
|
|
|
enum zwp_pointer_constraints_v1_lifetime lifetime,
|
|
|
|
const struct wl_interface *interface,
|
|
|
|
const void *implementation,
|
|
|
|
const MetaWaylandPointerGrabInterface *grab_interface)
|
|
|
|
{
|
|
|
|
struct wl_client *client = wl_resource_get_client (resource);
|
|
|
|
struct wl_resource *cr;
|
|
|
|
MetaWaylandPointerConstraint *constraint;
|
|
|
|
|
2016-02-24 03:27:52 -05:00
|
|
|
if (get_pointer_constraint_for_seat (surface, seat))
|
2015-06-17 00:10:52 -04:00
|
|
|
{
|
|
|
|
wl_resource_post_error (resource,
|
|
|
|
WL_DISPLAY_ERROR_INVALID_OBJECT,
|
|
|
|
"the pointer as already requested to be "
|
|
|
|
"locked or confined on that surface");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
cr = wl_resource_create (client, interface,
|
|
|
|
wl_resource_get_version (resource),
|
|
|
|
id);
|
|
|
|
if (cr == NULL)
|
|
|
|
{
|
|
|
|
wl_client_post_no_memory (client);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
constraint = meta_wayland_pointer_constraint_new (surface, seat,
|
|
|
|
region,
|
|
|
|
lifetime,
|
|
|
|
cr, grab_interface);
|
|
|
|
if (constraint == NULL)
|
|
|
|
{
|
|
|
|
wl_client_post_no_memory (client);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-02-24 03:27:52 -05:00
|
|
|
surface_add_pointer_constraint (surface, constraint);
|
2015-06-17 00:10:52 -04:00
|
|
|
|
|
|
|
wl_resource_set_implementation (cr, implementation, constraint,
|
|
|
|
pointer_constraint_resource_destroyed);
|
|
|
|
|
|
|
|
meta_wayland_pointer_constraint_maybe_enable (constraint);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
locked_pointer_destroy (struct wl_client *client,
|
|
|
|
struct wl_resource *resource)
|
|
|
|
{
|
|
|
|
MetaWaylandPointerConstraint *constraint =
|
|
|
|
wl_resource_get_user_data (resource);
|
|
|
|
gboolean warp_pointer = FALSE;
|
|
|
|
int warp_x, warp_y;
|
|
|
|
|
|
|
|
if (constraint && constraint->is_enabled && constraint->hint_set &&
|
|
|
|
is_within_constraint_region (constraint,
|
|
|
|
constraint->x_hint,
|
|
|
|
constraint->y_hint))
|
|
|
|
{
|
|
|
|
float sx, sy;
|
|
|
|
float x, y;
|
|
|
|
|
|
|
|
sx = (float)wl_fixed_to_double (constraint->x_hint);
|
|
|
|
sy = (float)wl_fixed_to_double (constraint->y_hint);
|
|
|
|
meta_wayland_surface_get_absolute_coordinates (constraint->surface,
|
|
|
|
sx, sy,
|
|
|
|
&x, &y);
|
|
|
|
warp_pointer = TRUE;
|
|
|
|
warp_x = (int) x;
|
|
|
|
warp_y = (int) y;
|
|
|
|
}
|
|
|
|
wl_resource_destroy (resource);
|
|
|
|
|
|
|
|
if (warp_pointer)
|
|
|
|
meta_backend_warp_pointer (meta_get_backend (), warp_x, warp_y);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
locked_pointer_set_cursor_position_hint (struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
wl_fixed_t surface_x,
|
|
|
|
wl_fixed_t surface_y)
|
|
|
|
{
|
|
|
|
MetaWaylandPointerConstraint *constraint =
|
|
|
|
wl_resource_get_user_data (resource);
|
|
|
|
|
|
|
|
/* Ignore a set cursor hint that was already sent after the constraint
|
|
|
|
* was cancelled. */
|
2016-02-23 04:59:47 -05:00
|
|
|
if (!constraint || !constraint->resource || constraint->resource != resource)
|
2015-06-17 00:10:52 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
constraint->hint_set = TRUE;
|
|
|
|
constraint->x_hint = surface_x;
|
|
|
|
constraint->y_hint = surface_y;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
locked_pointer_set_region (struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
struct wl_resource *region_resource)
|
|
|
|
{
|
|
|
|
MetaWaylandPointerConstraint *constraint =
|
|
|
|
wl_resource_get_user_data (resource);
|
|
|
|
MetaWaylandRegion *region =
|
|
|
|
region_resource ? wl_resource_get_user_data (region_resource) : NULL;
|
|
|
|
|
2016-02-23 04:59:47 -05:00
|
|
|
if (!constraint)
|
|
|
|
return;
|
|
|
|
|
2015-06-17 00:10:52 -04:00
|
|
|
meta_wayland_pointer_constraint_set_pending_region (constraint, region);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct zwp_locked_pointer_v1_interface locked_pointer_interface = {
|
|
|
|
locked_pointer_destroy,
|
|
|
|
locked_pointer_set_cursor_position_hint,
|
|
|
|
locked_pointer_set_region,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
locked_pointer_grab_pointer_focus (MetaWaylandPointerGrab *grab,
|
|
|
|
MetaWaylandSurface *surface)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
locked_pointer_grab_pointer_motion (MetaWaylandPointerGrab *grab,
|
|
|
|
const ClutterEvent *event)
|
|
|
|
{
|
|
|
|
meta_wayland_pointer_send_relative_motion (grab->pointer, event);
|
2016-09-06 00:45:01 -04:00
|
|
|
meta_wayland_pointer_broadcast_frame (grab->pointer);
|
2015-06-17 00:10:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
locked_pointer_grab_pointer_button (MetaWaylandPointerGrab *grab,
|
|
|
|
const ClutterEvent *event)
|
|
|
|
{
|
|
|
|
meta_wayland_pointer_send_button (grab->pointer, event);
|
|
|
|
}
|
|
|
|
|
2016-09-21 04:32:55 -04:00
|
|
|
static void
|
|
|
|
locked_pointer_grab_pointer_cancel (MetaWaylandPointerGrab *grab)
|
|
|
|
{
|
|
|
|
MetaWaylandPointerConstraint *constraint =
|
|
|
|
wl_container_of (grab, constraint, grab);
|
|
|
|
|
|
|
|
meta_wayland_pointer_constraint_deactivate (constraint);
|
|
|
|
}
|
|
|
|
|
2015-06-17 00:10:52 -04:00
|
|
|
static const MetaWaylandPointerGrabInterface locked_pointer_grab_interface = {
|
|
|
|
locked_pointer_grab_pointer_focus,
|
|
|
|
locked_pointer_grab_pointer_motion,
|
|
|
|
locked_pointer_grab_pointer_button,
|
2016-09-21 04:32:55 -04:00
|
|
|
locked_pointer_grab_pointer_cancel,
|
2015-06-17 00:10:52 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
pointer_constraints_destroy (struct wl_client *client,
|
|
|
|
struct wl_resource *resource)
|
|
|
|
{
|
|
|
|
wl_resource_destroy (resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pointer_constraints_lock_pointer (struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
uint32_t id,
|
|
|
|
struct wl_resource *surface_resource,
|
|
|
|
struct wl_resource *pointer_resource,
|
|
|
|
struct wl_resource *region_resource,
|
|
|
|
uint32_t lifetime)
|
|
|
|
{
|
|
|
|
MetaWaylandSurface *surface = wl_resource_get_user_data (surface_resource);
|
|
|
|
MetaWaylandPointer *pointer = wl_resource_get_user_data (pointer_resource);
|
|
|
|
MetaWaylandSeat *seat = meta_wayland_pointer_get_seat (pointer);
|
|
|
|
MetaWaylandRegion *region =
|
|
|
|
region_resource ? wl_resource_get_user_data (region_resource) : NULL;
|
|
|
|
|
|
|
|
init_pointer_constraint (resource, id, surface, seat, region, lifetime,
|
|
|
|
&zwp_locked_pointer_v1_interface,
|
|
|
|
&locked_pointer_interface,
|
|
|
|
&locked_pointer_grab_interface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
confined_pointer_grab_pointer_focus (MetaWaylandPointerGrab *grab,
|
|
|
|
MetaWaylandSurface *surface)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
confined_pointer_grab_pointer_motion (MetaWaylandPointerGrab *grab,
|
|
|
|
const ClutterEvent *event)
|
|
|
|
{
|
|
|
|
MetaWaylandPointerConstraint *constraint =
|
|
|
|
wl_container_of (grab, constraint, grab);
|
|
|
|
MetaWaylandPointer *pointer = grab->pointer;
|
|
|
|
|
|
|
|
g_assert (pointer->focus_surface);
|
|
|
|
g_assert (pointer->focus_surface == constraint->surface);
|
|
|
|
|
|
|
|
meta_wayland_pointer_send_motion (pointer, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
confined_pointer_grab_pointer_button (MetaWaylandPointerGrab *grab,
|
|
|
|
const ClutterEvent *event)
|
|
|
|
{
|
|
|
|
meta_wayland_pointer_send_button (grab->pointer, event);
|
|
|
|
}
|
|
|
|
|
2016-09-21 04:32:55 -04:00
|
|
|
static void
|
|
|
|
confined_pointer_grab_pointer_cancel (MetaWaylandPointerGrab *grab)
|
|
|
|
{
|
|
|
|
MetaWaylandPointerConstraint *constraint =
|
|
|
|
wl_container_of (grab, constraint, grab);
|
|
|
|
|
|
|
|
meta_wayland_pointer_constraint_deactivate (constraint);
|
|
|
|
}
|
|
|
|
|
2015-06-17 00:10:52 -04:00
|
|
|
static const MetaWaylandPointerGrabInterface confined_pointer_grab_interface = {
|
|
|
|
confined_pointer_grab_pointer_focus,
|
|
|
|
confined_pointer_grab_pointer_motion,
|
|
|
|
confined_pointer_grab_pointer_button,
|
2016-09-21 04:32:55 -04:00
|
|
|
confined_pointer_grab_pointer_cancel,
|
2015-06-17 00:10:52 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
confined_pointer_destroy (struct wl_client *client,
|
|
|
|
struct wl_resource *resource)
|
|
|
|
{
|
|
|
|
wl_resource_destroy (resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
confined_pointer_set_region (struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
struct wl_resource *region_resource)
|
|
|
|
{
|
|
|
|
MetaWaylandPointerConstraint *constraint =
|
|
|
|
wl_resource_get_user_data (resource);
|
|
|
|
MetaWaylandRegion *region =
|
|
|
|
region_resource ? wl_resource_get_user_data (region_resource) : NULL;
|
|
|
|
|
2016-02-23 04:59:47 -05:00
|
|
|
if (!constraint)
|
|
|
|
return;
|
|
|
|
|
2015-06-17 00:10:52 -04:00
|
|
|
meta_wayland_pointer_constraint_set_pending_region (constraint, region);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct zwp_confined_pointer_v1_interface confined_pointer_interface = {
|
|
|
|
confined_pointer_destroy,
|
|
|
|
confined_pointer_set_region,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
pointer_constraints_confine_pointer (struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
uint32_t id,
|
|
|
|
struct wl_resource *surface_resource,
|
|
|
|
struct wl_resource *pointer_resource,
|
|
|
|
struct wl_resource *region_resource,
|
|
|
|
uint32_t lifetime)
|
|
|
|
{
|
|
|
|
MetaWaylandSurface *surface = wl_resource_get_user_data (surface_resource);
|
|
|
|
MetaWaylandPointer *pointer = wl_resource_get_user_data (pointer_resource);
|
|
|
|
MetaWaylandSeat *seat = meta_wayland_pointer_get_seat (pointer);
|
|
|
|
MetaWaylandRegion *region =
|
|
|
|
region_resource ? wl_resource_get_user_data (region_resource) : NULL;
|
|
|
|
|
|
|
|
init_pointer_constraint (resource, id, surface, seat, region, lifetime,
|
|
|
|
&zwp_confined_pointer_v1_interface,
|
|
|
|
&confined_pointer_interface,
|
|
|
|
&confined_pointer_grab_interface);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct zwp_pointer_constraints_v1_interface pointer_constraints = {
|
|
|
|
pointer_constraints_destroy,
|
|
|
|
pointer_constraints_lock_pointer,
|
|
|
|
pointer_constraints_confine_pointer,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
bind_pointer_constraints (struct wl_client *client,
|
|
|
|
void *data,
|
|
|
|
uint32_t version,
|
|
|
|
uint32_t id)
|
|
|
|
{
|
|
|
|
MetaWaylandCompositor *compositor = data;
|
|
|
|
struct wl_resource *resource;
|
|
|
|
|
|
|
|
resource = wl_resource_create (client,
|
|
|
|
&zwp_pointer_constraints_v1_interface,
|
|
|
|
1, id);
|
|
|
|
|
|
|
|
wl_resource_set_implementation (resource,
|
|
|
|
&pointer_constraints,
|
|
|
|
compositor,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2016-09-06 01:14:44 -04:00
|
|
|
static void
|
|
|
|
meta_wayland_pointer_constraint_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
MetaWaylandPointerConstraint *constraint =
|
|
|
|
META_WAYLAND_POINTER_CONSTRAINT (object);
|
|
|
|
|
|
|
|
g_signal_handler_disconnect (constraint->seat->pointer,
|
|
|
|
constraint->pointer_focus_surface_handler_id);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (meta_wayland_pointer_constraint_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2015-06-17 00:10:52 -04:00
|
|
|
void
|
|
|
|
meta_wayland_pointer_constraints_init (MetaWaylandCompositor *compositor)
|
|
|
|
{
|
|
|
|
if (!wl_global_create (compositor->wayland_display,
|
|
|
|
&zwp_pointer_constraints_v1_interface, 1,
|
|
|
|
compositor, bind_pointer_constraints))
|
|
|
|
g_error ("Could not create wp_pointer_constraints global");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_wayland_pointer_constraint_init (MetaWaylandPointerConstraint *constraint)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_wayland_pointer_constraint_class_init (MetaWaylandPointerConstraintClass *klass)
|
|
|
|
{
|
2016-09-06 01:14:44 -04:00
|
|
|
GObjectClass *object_class;
|
|
|
|
|
|
|
|
object_class = G_OBJECT_CLASS (klass);
|
|
|
|
object_class->finalize = meta_wayland_pointer_constraint_finalize;
|
|
|
|
|
2015-06-17 00:10:52 -04:00
|
|
|
quark_pending_constraint_state =
|
|
|
|
g_quark_from_static_string ("-meta-wayland-pointer-constraint-pending_state");
|
2016-02-24 03:27:52 -05:00
|
|
|
quark_surface_pointer_constraints_data =
|
|
|
|
g_quark_from_static_string ("-meta-wayland-surface-constraints-data");
|
2015-06-17 00:10:52 -04:00
|
|
|
}
|