summaryrefslogtreecommitdiff
path: root/src/libinput.h
blob: 0fce3e86cbc4cf1d53f6d54e0863d6844ceee309 (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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
/*
 * Copyright © 2013 Jonas Ådahl
 *
 * Permission to use, copy, modify, distribute, and sell this software and
 * its documentation for any purpose is hereby granted without fee, provided
 * that the above copyright notice appear in all copies and that both that
 * copyright notice and this permission notice appear in supporting
 * documentation, and that the name of the copyright holders not be used in
 * advertising or publicity pertaining to distribution of the software
 * without specific, written prior permission.  The copyright holders make
 * no representations about the suitability of this software for any
 * purpose.  It is provided "as is" without express or implied warranty.
 *
 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#ifndef LIBINPUT_H
#define LIBINPUT_H

#include <stdlib.h>
#include <stdint.h>
#include <libudev.h>

typedef int32_t li_fixed_t;

enum libinput_device_capability {
	LIBINPUT_DEVICE_CAP_KEYBOARD = 0,
	LIBINPUT_DEVICE_CAP_POINTER = 1,
	LIBINPUT_DEVICE_CAP_TOUCH = 2,
};

enum libinput_keyboard_key_state {
	LIBINPUT_KEYBOARD_KEY_STATE_RELEASED = 0,
	LIBINPUT_KEYBOARD_KEY_STATE_PRESSED = 1,
};

enum libinput_led {
	LIBINPUT_LED_NUM_LOCK = (1 << 0),
	LIBINPUT_LED_CAPS_LOCK = (1 << 1),
	LIBINPUT_LED_SCROLL_LOCK = (1 << 2),
};

enum libinput_pointer_button_state {
	LIBINPUT_POINTER_BUTTON_STATE_RELEASED = 0,
	LIBINPUT_POINTER_BUTTON_STATE_PRESSED = 1,
};

enum libinput_pointer_axis {
	LIBINPUT_POINTER_AXIS_VERTICAL_SCROLL = 0,
	LIBINPUT_POINTER_AXIS_HORIZONTAL_SCROLL = 1,
};

enum libinput_touch_type {
	LIBINPUT_TOUCH_TYPE_DOWN = 0,
	LIBINPUT_TOUCH_TYPE_UP = 1,
	LIBINPUT_TOUCH_TYPE_MOTION = 2,
	LIBINPUT_TOUCH_TYPE_FRAME = 3,
	LIBINPUT_TOUCH_TYPE_CANCEL = 4,
};

enum libinput_event_type {
	LIBINPUT_EVENT_ADDED_SEAT = 0,
	LIBINPUT_EVENT_REMOVED_SEAT,
	LIBINPUT_EVENT_ADDED_DEVICE,
	LIBINPUT_EVENT_REMOVED_DEVICE,

	LIBINPUT_EVENT_DEVICE_REGISTER_CAPABILITY = 200,
	LIBINPUT_EVENT_DEVICE_UNREGISTER_CAPABILITY,

	LIBINPUT_EVENT_KEYBOARD_KEY = 300,

	LIBINPUT_EVENT_POINTER_MOTION = 400,
	LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE,
	LIBINPUT_EVENT_POINTER_BUTTON,
	LIBINPUT_EVENT_POINTER_AXIS,

	LIBINPUT_EVENT_TOUCH_TOUCH = 500,
};

struct libinput;
struct libinput_device;
struct libinput_seat;

union libinput_event_target {
	struct libinput *libinput;
	struct libinput_seat *seat;
	struct libinput_device *device;
};

struct libinput_event {
	enum libinput_event_type type;
	union libinput_event_target target;
};

struct libinput_event_added_seat {
	struct libinput_event base;
	struct libinput_seat *seat;
};

struct libinput_event_removed_seat {
	struct libinput_event base;
	struct libinput_seat *seat;
};

struct libinput_event_added_device {
	struct libinput_event base;
	struct libinput_device *device;
};

struct libinput_event_removed_device {
	struct libinput_event base;
	struct libinput_device *device;
};

struct libinput_event_device_register_capability {
	struct libinput_event base;
	enum libinput_device_capability capability;
};

struct libinput_event_device_unregister_capability {
	struct libinput_event base;
	enum libinput_device_capability capability;
};

struct libinput_event_keyboard_key {
	struct libinput_event base;
	uint32_t time;
	uint32_t key;
	enum libinput_keyboard_key_state state;
};

struct libinput_event_pointer_motion {
	struct libinput_event base;
	uint32_t time;
	li_fixed_t dx;
	li_fixed_t dy;
};

struct libinput_event_pointer_motion_absolute {
	struct libinput_event base;
	uint32_t time;
	li_fixed_t x;
	li_fixed_t y;
};

struct libinput_event_pointer_button {
	struct libinput_event base;
	uint32_t time;
	uint32_t button;
	enum libinput_pointer_button_state state;
};

struct libinput_event_pointer_axis {
	struct libinput_event base;
	uint32_t time;
	enum libinput_pointer_axis axis;
	li_fixed_t value;
};

struct libinput_event_touch_touch {
	struct libinput_event base;
	uint32_t time;
	uint32_t slot;
	li_fixed_t x;
	li_fixed_t y;
	enum libinput_touch_type touch_type;
};

struct libinput_interface {
	int (*open_restricted)(const char *path, int flags, void *user_data);
	void (*close_restricted)(int fd, void *user_data);

	void (*get_current_screen_dimensions)(struct libinput_device *device,
					      int *width,
					      int *height,
					      void *user_data);
};

/*
 * Base
 */

struct libinput *
libinput_create_from_udev(const struct libinput_interface *interface,
			  void *user_data,
			  struct udev *udev,
			  const char *seat_id);

int
libinput_get_fd(struct libinput *libinput);

int
libinput_dispatch(struct libinput *libinput);

struct libinput_event *
libinput_get_event(struct libinput *libinput);

void *
libinput_get_user_data(struct libinput *libinput);

int
libinput_resume(struct libinput *libinput);

void
libinput_suspend(struct libinput *libinput);

void
libinput_destroy(struct libinput *libinput);

/*
 * Seat
 */

void
libinput_seat_ref(struct libinput_seat *seat);

void
libinput_seat_unref(struct libinput_seat *seat);

void
libinput_seat_set_user_data(struct libinput_seat *seat, void *user_data);

void *
libinput_seat_get_user_data(struct libinput_seat *seat);

const char *
libinput_seat_get_name(struct libinput_seat *seat);

/*
 * Device
 */

void
libinput_device_ref(struct libinput_device *device);

void
libinput_device_unref(struct libinput_device *device);

void
libinput_device_set_user_data(struct libinput_device *device, void *user_data);

void *
libinput_device_get_user_data(struct libinput_device *device);

const char *
libinput_device_get_output_name(struct libinput_device *device);

struct libinput_seat *
libinput_device_get_seat(struct libinput_device *device);

void
libinput_device_led_update(struct libinput_device *device,
			   enum libinput_led leds);

int
libinput_device_get_keys(struct libinput_device *device,
			 char *keys, size_t size);

void
libinput_device_calibrate(struct libinput_device *device,
			  float calibration[6]);

#endif /* LIBINPUT_H */