summaryrefslogtreecommitdiff
path: root/src/backends/native/meta-seat-impl.h
blob: a62af83f5df4e6f9c89bda1ac0ff6a8b6912457a (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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
/*
 * Copyright (C) 2010  Intel Corp.
 * Copyright (C) 2014  Jonas Ådahl
 * Copyright (C) 2016  Red Hat Inc.
 *
 * 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/>.
 *
 * Author: Damien Lespiau <damien.lespiau@intel.com>
 * Author: Jonas Ådahl <jadahl@gmail.com>
 */

#ifndef META_SEAT_IMPL_H
#define META_SEAT_IMPL_H

#include <gudev/gudev.h>
#include <libinput.h>
#include <linux/input-event-codes.h>

#include "backends/meta-input-settings-private.h"
#include "backends/meta-viewport-info.h"
#include "backends/native/meta-backend-native-types.h"
#include "backends/native/meta-barrier-native.h"
#include "backends/native/meta-cursor-renderer-native.h"
#include "backends/native/meta-keymap-native.h"
#include "backends/native/meta-pointer-constraint-native.h"
#include "backends/native/meta-xkb-utils.h"
#include "clutter/clutter.h"

typedef struct _MetaTouchState MetaTouchState;
typedef struct _MetaSeatImpl MetaSeatImpl;
typedef struct _MetaEventSource  MetaEventSource;

struct _MetaTouchState
{
  MetaSeatImpl *seat_impl;

  int device_slot;
  int seat_slot;
  graphene_point_t coords;
};

struct _MetaSeatImpl
{
  GObject parent_instance;

  MetaSeatNative *seat_native;
  char *seat_id;
  MetaEventSource *event_source;
  struct libinput *libinput;
  GRWLock state_lock;

  GSList *devices;

  ClutterInputDevice *core_pointer;
  ClutterInputDevice *core_keyboard;

  GHashTable *touch_states;
  GHashTable *cursor_renderers;

  struct xkb_state *xkb;
  xkb_led_index_t caps_lock_led;
  xkb_led_index_t num_lock_led;
  xkb_led_index_t scroll_lock_led;
  xkb_layout_index_t layout_idx;
  uint32_t button_state;
  int button_count[KEY_CNT];

  MetaBarrierManagerNative *barrier_manager;
  MetaPointerConstraintImpl *pointer_constraint;

  MetaKeymapNative *keymap;
  MetaInputSettings *input_settings;

  MetaViewportInfo *viewports;

  GUdevClient *udev_client;
  gboolean tablet_mode_switch_state;
  gboolean has_touchscreen;
  gboolean has_tablet_switch;
  gboolean touch_mode;

  /* keyboard repeat */
  gboolean repeat;
  uint32_t repeat_delay;
  uint32_t repeat_interval;
  uint32_t repeat_key;
  uint32_t repeat_count;
  uint32_t repeat_timer;
  ClutterInputDevice *repeat_device;

  float pointer_x;
  float pointer_y;

  /* Emulation of discrete scroll events out of smooth ones */
  float accum_scroll_dx;
  float accum_scroll_dy;

  gboolean released;
};

#define META_TYPE_SEAT_IMPL meta_seat_impl_get_type ()
G_DECLARE_FINAL_TYPE (MetaSeatImpl, meta_seat_impl,
                      META, SEAT_IMPL, GObject)

MetaSeatImpl * meta_seat_impl_new (MetaSeatNative *seat_native,
                                   const char     *seat_id);

void meta_seat_impl_notify_key (MetaSeatImpl       *seat_impl,
                                ClutterInputDevice *device,
                                uint64_t            time_us,
                                uint32_t            key,
                                uint32_t            state,
                                gboolean            update_keys);

void meta_seat_impl_notify_relative_motion (MetaSeatImpl       *seat_impl,
                                            ClutterInputDevice *input_device,
                                            uint64_t            time_us,
                                            float               dx,
                                            float               dy,
                                            float               dx_unaccel,
                                            float               dy_unaccel);

void meta_seat_impl_notify_absolute_motion (MetaSeatImpl       *seat_impl,
                                            ClutterInputDevice *input_device,
                                            uint64_t            time_us,
                                            float               x,
                                            float               y,
                                            double             *axes);

void meta_seat_impl_notify_button (MetaSeatImpl       *seat_impl,
                                   ClutterInputDevice *input_device,
                                   uint64_t            time_us,
                                   uint32_t            button,
                                   uint32_t            state);

void meta_seat_impl_notify_scroll_continuous (MetaSeatImpl             *seat_impl,
                                              ClutterInputDevice       *input_device,
                                              uint64_t                  time_us,
                                              double                    dx,
                                              double                    dy,
                                              ClutterScrollSource       source,
                                              ClutterScrollFinishFlags  flags);

void meta_seat_impl_notify_discrete_scroll (MetaSeatImpl        *seat_impl,
                                            ClutterInputDevice  *input_device,
                                            uint64_t             time_us,
                                            double               discrete_dx,
                                            double               discrete_dy,
                                            ClutterScrollSource  source);

void meta_seat_impl_notify_touch_event (MetaSeatImpl       *seat_impl,
                                        ClutterInputDevice *input_device,
                                        ClutterEventType    evtype,
                                        uint64_t            time_us,
                                        int                 slot,
                                        double              x,
                                        double              y);

void meta_seat_impl_sync_leds (MetaSeatImpl *seat_impl);

MetaTouchState * meta_seat_impl_acquire_touch_state (MetaSeatImpl *seat_impl,
                                                     int           seat_slot);
MetaTouchState * meta_seat_impl_lookup_touch_state (MetaSeatImpl *seat_impl,
                                                    int           seat_slot);
void meta_seat_impl_release_touch_state (MetaSeatImpl   *seat_impl,
                                         int             seat_slot);

void meta_seat_impl_update_xkb_state (MetaSeatImpl *seat_impl);

/**
 * MetaOpenDeviceCallback:
 * @path: the device path
 * @flags: flags to be passed to open
 *
 * This callback will be called when Clutter needs to access an input
 * device. It should return an open file descriptor for the file at @path,
 * or -1 if opening failed.
 */
typedef int (* MetaOpenDeviceCallback) (const char  *path,
                                        int          flags,
                                        gpointer     user_data,
                                        GError     **error);
typedef void (* MetaCloseDeviceCallback) (int          fd,
                                          gpointer     user_data);

void  meta_seat_impl_set_device_callbacks (MetaOpenDeviceCallback  open_callback,
                                           MetaCloseDeviceCallback close_callback,
                                           gpointer                user_data);

void  meta_seat_impl_release_devices (MetaSeatImpl *seat_impl);
void  meta_seat_impl_reclaim_devices (MetaSeatImpl *seat_impl);

struct xkb_state * meta_seat_impl_get_xkb_state (MetaSeatImpl *seat_impl);

void               meta_seat_impl_set_keyboard_map   (MetaSeatImpl      *seat_impl,
                                                      struct xkb_keymap *keymap);

void meta_seat_impl_set_keyboard_layout_index (MetaSeatImpl       *seat_impl,
                                               xkb_layout_index_t  idx);

void meta_seat_impl_set_keyboard_numlock (MetaSeatImpl *seat_impl,
                                          gboolean      numlock_state);

void meta_seat_impl_set_keyboard_repeat (MetaSeatImpl *seat_impl,
                                         gboolean      repeat,
                                         uint32_t      delay,
                                         uint32_t      interval);

MetaBarrierManagerNative * meta_seat_impl_get_barrier_manager (MetaSeatImpl *seat_impl);

void meta_seat_impl_set_pointer_constraint (MetaSeatImpl              *seat_impl,
                                            MetaPointerConstraintImpl *constraint_impl);
void meta_seat_impl_set_viewports (MetaSeatImpl     *seat_impl,
                                   MetaViewportInfo *viewports);

void meta_seat_impl_warp_pointer (MetaSeatImpl *seat_impl,
                                  int           x,
                                  int           y);
gboolean meta_seat_impl_query_state (MetaSeatImpl         *seat_impl,
                                     ClutterInputDevice   *device,
                                     ClutterEventSequence *sequence,
                                     graphene_point_t     *coords,
                                     ClutterModifierType  *modifiers);
ClutterInputDevice * meta_seat_impl_get_pointer (MetaSeatImpl *seat_impl);
ClutterInputDevice * meta_seat_impl_get_keyboard (MetaSeatImpl *seat_impl);
GSList * meta_seat_impl_get_devices (MetaSeatImpl *seat_impl);

MetaKeymapNative * meta_seat_impl_get_keymap (MetaSeatImpl *seat_impl);

void meta_seat_impl_notify_kbd_a11y_flags_changed (MetaSeatImpl          *seat_impl,
                                                   MetaKeyboardA11yFlags  new_flags,
                                                   MetaKeyboardA11yFlags  what_changed);
void meta_seat_impl_notify_kbd_a11y_mods_state_changed (MetaSeatImpl   *seat_impl,
                                                        xkb_mod_mask_t  new_latched_mods,
                                                        xkb_mod_mask_t  new_locked_mods);
void meta_seat_impl_notify_bell (MetaSeatImpl *seat_impl);

MetaInputSettings * meta_seat_impl_get_input_settings (MetaSeatImpl *seat_impl);

#endif /* META_SEAT_IMPL_H */