summaryrefslogtreecommitdiff
path: root/src/backends/native/meta-event-native.c
blob: 61603d19efa7d04da50403aebda87542b59f4e91 (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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/*
 * Copyright (C) 2015 Red Hat
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
 *
 * Authored by:
 *      Carlos Garnacho <carlosg@gnome.org>
 */

#include "config.h"

#include "backends/native/meta-event-native.h"
#include "backends/native/meta-input-device-native.h"
#include "clutter/clutter-mutter.h"

typedef struct _MetaEventNative MetaEventNative;

struct _MetaEventNative
{
  uint32_t evcode;

  uint64_t time_usec;

  gboolean has_relative_motion;
  double dx;
  double dy;
  double dx_unaccel;
  double dy_unaccel;
};

static MetaEventNative *
meta_event_native_new (void)
{
  return g_slice_new0 (MetaEventNative);
}

MetaEventNative *
meta_event_native_copy (MetaEventNative *event_evdev)
{
  if (event_evdev != NULL)
    return g_slice_dup (MetaEventNative, event_evdev);

  return NULL;
}

void
meta_event_native_free (MetaEventNative *event_evdev)
{
  if (event_evdev != NULL)
    g_slice_free (MetaEventNative, event_evdev);
}

static MetaEventNative *
meta_event_native_ensure_platform_data (ClutterEvent *event)
{
  MetaEventNative *event_evdev = _clutter_event_get_platform_data (event);

  if (!event_evdev)
    {
      event_evdev = meta_event_native_new ();
      _clutter_event_set_platform_data (event, event_evdev);
    }

  return event_evdev;
}

void
meta_event_native_set_event_code (ClutterEvent *event,
                                  uint32_t      evcode)
{
  MetaEventNative *event_evdev;

  event_evdev = meta_event_native_ensure_platform_data (event);
  event_evdev->evcode = evcode;
}

void
meta_event_native_set_time_usec (ClutterEvent *event,
                                 uint64_t      time_usec)
{
  MetaEventNative *event_evdev;

  event_evdev = meta_event_native_ensure_platform_data (event);
  event_evdev->time_usec = time_usec;
}

void
meta_event_native_set_relative_motion (ClutterEvent *event,
                                       double        dx,
                                       double        dy,
                                       double        dx_unaccel,
                                       double        dy_unaccel)
{
  MetaEventNative *event_evdev;

  event_evdev = meta_event_native_ensure_platform_data (event);
  event_evdev->dx = dx;
  event_evdev->dy = dy;
  event_evdev->dx_unaccel = dx_unaccel;
  event_evdev->dy_unaccel = dy_unaccel;
  event_evdev->has_relative_motion = TRUE;
}

/**
 * meta_event_native_get_event_code:
 * @event: a #ClutterEvent
 *
 * Returns the event code of the original event. See linux/input.h for more
 * information.
 *
 * Returns: The event code.
 **/
uint32_t
meta_event_native_get_event_code (const ClutterEvent *event)
{
  MetaEventNative *event_evdev = _clutter_event_get_platform_data (event);

  if (event_evdev)
    return event_evdev->evcode;

  return 0;
}

/**
 * meta_event_native_get_time_usec:
 * @event: a #ClutterEvent
 *
 * Returns the time in microsecond granularity, or 0 if unavailable.
 *
 * Returns: The time in microsecond granularity, or 0 if unavailable.
 */
uint64_t
meta_event_native_get_time_usec (const ClutterEvent *event)
{
  MetaEventNative *event_evdev = _clutter_event_get_platform_data (event);

  if (event_evdev)
    return event_evdev->time_usec;

  return 0;
}

/**
 * meta_event_get_pointer_motion
 * @event: a #ClutterEvent
 *
 * If available, the normal and unaccelerated motion deltas are written
 * to the dx, dy, dx_unaccel and dy_unaccel and TRUE is returned.
 *
 * If unavailable, FALSE is returned.
 *
 * Returns: TRUE on success, otherwise FALSE.
 **/
gboolean
meta_event_native_get_relative_motion (const ClutterEvent *event,
                                       double             *dx,
                                       double             *dy,
                                       double             *dx_unaccel,
                                       double             *dy_unaccel)
{
  MetaEventNative *event_evdev = _clutter_event_get_platform_data (event);

  if (event_evdev && event_evdev->has_relative_motion)
    {
      if (dx)
        *dx = event_evdev->dx;
      if (dy)
        *dy = event_evdev->dy;
      if (dx_unaccel)
        *dx_unaccel = event_evdev->dx_unaccel;
      if (dy_unaccel)
        *dy_unaccel = event_evdev->dy_unaccel;
      return TRUE;
    }
  else
    return FALSE;
}

/**
 * meta_event_native_sequence_get_slot:
 * @sequence: a #ClutterEventSequence
 *
 * Retrieves the touch slot triggered by this @sequence
 *
 * Returns: the libinput touch slot.
 *
 * Since: 1.20
 * Stability: unstable
 **/
int32_t
meta_event_native_sequence_get_slot (const ClutterEventSequence *sequence)
{
  if (!sequence)
    return -1;

  return GPOINTER_TO_INT (sequence) - 1;
}