summaryrefslogtreecommitdiff
path: root/src/backends/meta-pointer-constraint.c
blob: 0bc57a4c4a4dde55e43830e8ed966597fc08201c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/* -*- 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>
 */

/**
 * SECTION:meta-pointer-constraint
 * @title: MetaPointerConstraint
 * @short_description: Pointer client constraints.
 *
 * A MetaPointerConstraint can be used to implement any kind of pointer
 * constraint as requested by a client, such as cursor lock.
 *
 * Examples of pointer constraints are "pointer confinement" and "pointer
 * locking" (as defined in the wayland pointer constraint protocol extension),
 * which restrict movement in relation to a given client.
 */

#include "config.h"

#include "backends/meta-pointer-constraint.h"

#ifdef HAVE_NATIVE_BACKEND
#include "backends/native/meta-backend-native.h"
#include "backends/native/meta-pointer-constraint-native.h"
#endif

#include <glib-object.h>

struct _MetaPointerConstraint
{
  GObject parent_instance;
  cairo_region_t *region;
  double min_edge_distance;
};

G_DEFINE_TYPE (MetaPointerConstraint, meta_pointer_constraint, G_TYPE_OBJECT);

G_DEFINE_TYPE (MetaPointerConstraintImpl, meta_pointer_constraint_impl,
               G_TYPE_OBJECT);

static void
meta_pointer_constraint_finalize (GObject *object)
{
  MetaPointerConstraint *constraint = META_POINTER_CONSTRAINT (object);

  g_clear_pointer (&constraint->region, cairo_region_destroy);

  G_OBJECT_CLASS (meta_pointer_constraint_parent_class)->finalize (object);
}

static void
meta_pointer_constraint_init (MetaPointerConstraint *constraint)
{
}

static void
meta_pointer_constraint_class_init (MetaPointerConstraintClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);

  object_class->finalize = meta_pointer_constraint_finalize;
}


MetaPointerConstraint *
meta_pointer_constraint_new (const cairo_region_t *region,
                             double                min_edge_distance)
{
  MetaPointerConstraint *constraint;

  constraint = g_object_new (META_TYPE_POINTER_CONSTRAINT, NULL);
  constraint->region = cairo_region_copy (region);
  constraint->min_edge_distance = min_edge_distance;

  return constraint;
}

cairo_region_t *
meta_pointer_constraint_get_region (MetaPointerConstraint *constraint)
{
  return constraint->region;
}

double
meta_pointer_constraint_get_min_edge_distance (MetaPointerConstraint *constraint)
{
  return constraint->min_edge_distance;
}

static void
meta_pointer_constraint_impl_init (MetaPointerConstraintImpl *constraint_impl)
{
}

static void
meta_pointer_constraint_impl_class_init (MetaPointerConstraintImplClass *klass)
{
}

/**
 * meta_pointer_constraint_impl_constrain:
 * @constraint_impl: a #MetaPointerConstraintImpl.
 * @device; the device of the pointer.
 * @time: the timestamp (in ms) of the event.
 * @prev_x: X-coordinate of the previous pointer position.
 * @prev_y: Y-coordinate of the previous pointer position.
 * @x: The modifiable X-coordinate to which the pointer would like to go to.
 * @y: The modifiable Y-coordinate to which the pointer would like to go to.
 *
 * Constrains the pointer movement from point (@prev_x, @prev_y) to (@x, @y),
 * if needed.
 */
void
meta_pointer_constraint_impl_constrain (MetaPointerConstraintImpl *constraint_impl,
                                        ClutterInputDevice        *device,
                                        uint32_t                   time,
                                        float                      prev_x,
                                        float                      prev_y,
                                        float                     *x,
                                        float                     *y)
{
  META_POINTER_CONSTRAINT_IMPL_GET_CLASS (constraint_impl)->constrain (constraint_impl,
                                                                       device,
                                                                       time,
                                                                       prev_x, prev_y,
                                                                       x, y);
}

void
meta_pointer_constraint_impl_ensure_constrained (MetaPointerConstraintImpl *constraint_impl,
                                                 ClutterInputDevice        *device)
{
  META_POINTER_CONSTRAINT_IMPL_GET_CLASS (constraint_impl)->ensure_constrained (constraint_impl,
                                                                                device);
}