libinput  0.2.0
A wrapper library for input devices
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Groups
libinput.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2013 Jonas Ådahl
3  *
4  * Permission to use, copy, modify, distribute, and sell this software and
5  * its documentation for any purpose is hereby granted without fee, provided
6  * that the above copyright notice appear in all copies and that both that
7  * copyright notice and this permission notice appear in supporting
8  * documentation, and that the name of the copyright holders not be used in
9  * advertising or publicity pertaining to distribution of the software
10  * without specific, written prior permission. The copyright holders make
11  * no representations about the suitability of this software for any
12  * purpose. It is provided "as is" without express or implied warranty.
13  *
14  * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
15  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
16  * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
17  * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
18  * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
19  * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
20  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21  */
22 
23 #ifndef LIBINPUT_H
24 #define LIBINPUT_H
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 #include <stdlib.h>
31 #include <stdint.h>
32 #include <libudev.h>
33 
46 typedef int32_t li_fixed_t;
47 
55 };
56 
68 };
69 
79 };
80 
90 };
91 
101 };
102 
103 
112 };
113 
126 
136 
142 
144 
149 
159 };
160 
161 struct libinput;
162 struct libinput_device;
163 struct libinput_seat;
164 
165 struct libinput_event;
166 struct libinput_event_device_notify;
167 struct libinput_event_keyboard;
168 struct libinput_event_pointer;
169 
180 struct libinput_event_touch;
181 
194 static inline double
195 li_fixed_to_double (li_fixed_t f)
196 {
197  union {
198  double d;
199  int64_t i;
200  } u;
201 
202  u.i = ((1023LL + 44LL) << 52) + (1LL << 51) + f;
203 
204  return u.d - (3LL << 43);
205 }
206 
215 static inline int
216 li_fixed_to_int(li_fixed_t f)
217 {
218  return f / 256;
219 }
220 
232 void
233 libinput_event_destroy(struct libinput_event *event);
234 
243 libinput_event_get_type(struct libinput_event *event);
244 
253 struct libinput *
254 libinput_event_get_context(struct libinput_event *event);
255 
269 struct libinput_device *
270 libinput_event_get_device(struct libinput_event *event);
271 
282 struct libinput_event_pointer *
283 libinput_event_get_pointer_event(struct libinput_event *event);
284 
295 struct libinput_event_keyboard *
296 libinput_event_get_keyboard_event(struct libinput_event *event);
297 
308 struct libinput_event_touch *
309 libinput_event_get_touch_event(struct libinput_event *event);
310 
322 struct libinput_event_device_notify *
323 libinput_event_get_device_notify_event(struct libinput_event *event);
324 
330 struct libinput_event *
331 libinput_event_device_notify_get_base_event(struct libinput_event_device_notify *event);
332 
345 uint32_t
346 libinput_event_keyboard_get_time(struct libinput_event_keyboard *event);
347 
353 uint32_t
354 libinput_event_keyboard_get_key(struct libinput_event_keyboard *event);
355 
362 libinput_event_keyboard_get_key_state(struct libinput_event_keyboard *event);
363 
364 
370 struct libinput_event *
371 libinput_event_keyboard_get_base_event(struct libinput_event_keyboard *event);
372 
385 uint32_t
387  struct libinput_event_keyboard *event);
388 
401 uint32_t
402 libinput_event_pointer_get_time(struct libinput_event_pointer *event);
403 
416 li_fixed_t
417 libinput_event_pointer_get_dx(struct libinput_event_pointer *event);
418 
431 li_fixed_t
432 libinput_event_pointer_get_dy(struct libinput_event_pointer *event);
433 
451 li_fixed_t
452 libinput_event_pointer_get_absolute_x(struct libinput_event_pointer *event);
453 
471 li_fixed_t
472 libinput_event_pointer_get_absolute_y(struct libinput_event_pointer *event);
473 
491 li_fixed_t
493  struct libinput_event_pointer *event,
494  uint32_t width);
495 
513 li_fixed_t
515  struct libinput_event_pointer *event,
516  uint32_t height);
517 
530 uint32_t
531 libinput_event_pointer_get_button(struct libinput_event_pointer *event);
532 
546 libinput_event_pointer_get_button_state(struct libinput_event_pointer *event);
547 
560 uint32_t
562  struct libinput_event_pointer *event);
563 
577 libinput_event_pointer_get_axis(struct libinput_event_pointer *event);
578 
599 li_fixed_t
600 libinput_event_pointer_get_axis_value(struct libinput_event_pointer *event);
601 
607 struct libinput_event *
608 libinput_event_pointer_get_base_event(struct libinput_event_pointer *event);
609 
610 
622 uint32_t
624 
639 int32_t
641 
656 int32_t
658 
674 li_fixed_t
676 
694 li_fixed_t
696 
710 li_fixed_t
712  uint32_t width);
713 
727 li_fixed_t
729  uint32_t height);
730 
736 struct libinput_event *
738 
755  int (*open_restricted)(const char *path, int flags, void *user_data);
763  void (*close_restricted)(int fd, void *user_data);
764 };
765 
789 struct libinput *
790 libinput_udev_create_for_seat(const struct libinput_interface *interface,
791  void *user_data,
792  struct udev *udev,
793  const char *seat_id);
794 
811 struct libinput *
812 libinput_path_create_context(const struct libinput_interface *interface,
813  void *user_data);
814 
835 struct libinput_device *
836 libinput_path_add_device(struct libinput *libinput,
837  const char *path);
838 
857 void
858 libinput_path_remove_device(struct libinput_device *device);
859 
868 int
869 libinput_get_fd(struct libinput *libinput);
870 
884 int
885 libinput_dispatch(struct libinput *libinput);
886 
898 struct libinput_event *
899 libinput_get_event(struct libinput *libinput);
900 
913 libinput_next_event_type(struct libinput *libinput);
914 
922 void *
923 libinput_get_user_data(struct libinput *libinput);
924 
936 int
937 libinput_resume(struct libinput *libinput);
938 
948 void
949 libinput_suspend(struct libinput *libinput);
950 
959 void
960 libinput_destroy(struct libinput *libinput);
961 
974 void
976 
991 
1006 typedef void (*libinput_log_handler)(enum libinput_log_priority priority,
1007  void *user_data,
1008  const char *format, va_list args);
1009 
1025 void
1027  void *user_data);
1028 
1065 void
1066 libinput_seat_ref(struct libinput_seat *seat);
1067 
1078 void
1079 libinput_seat_unref(struct libinput_seat *seat);
1080 
1092 void
1093 libinput_seat_set_user_data(struct libinput_seat *seat, void *user_data);
1094 
1104 void *
1105 libinput_seat_get_user_data(struct libinput_seat *seat);
1106 
1123 const char *
1124 libinput_seat_get_physical_name(struct libinput_seat *seat);
1125 
1135 const char *
1136 libinput_seat_get_logical_name(struct libinput_seat *seat);
1137 
1152 void
1153 libinput_device_ref(struct libinput_device *device);
1154 
1165 void
1166 libinput_device_unref(struct libinput_device *device);
1167 
1179 void
1180 libinput_device_set_user_data(struct libinput_device *device, void *user_data);
1181 
1191 void *
1192 libinput_device_get_user_data(struct libinput_device *device);
1193 
1202 const char *
1203 libinput_device_get_sysname(struct libinput_device *device);
1204 
1216 const char *
1217 libinput_device_get_output_name(struct libinput_device *device);
1218 
1232 struct libinput_seat *
1233 libinput_device_get_seat(struct libinput_device *device);
1234 
1245 void
1246 libinput_device_led_update(struct libinput_device *device,
1247  enum libinput_led leds);
1248 
1261 int
1262 libinput_device_get_keys(struct libinput_device *device,
1263  char *keys, size_t size);
1264 
1278 void
1279 libinput_device_calibrate(struct libinput_device *device,
1280  float calibration[6]);
1281 
1289 int
1290 libinput_device_has_capability(struct libinput_device *device,
1291  enum libinput_device_capability capability);
1292 
1293 #ifdef __cplusplus
1294 }
1295 #endif
1296 
1297 #endif /* LIBINPUT_H */
const char * libinput_seat_get_physical_name(struct libinput_seat *seat)
Return the physical name of the seat.
libinput_log_priority
Log priority for internal logging messages.
Definition: libinput.h:51
enum libinput_log_priority libinput_log_get_priority(void)
Get the global log priority.
Definition: libinput.h:67
uint32_t libinput_event_pointer_get_button(struct libinput_event_pointer *event)
Return the button that triggered this event.
void(* close_restricted)(int fd, void *user_data)
Close the file descriptor.
Definition: libinput.h:763
Definition: libinput.h:152
int libinput_dispatch(struct libinput *libinput)
Main event dispatchment function.
void libinput_log_set_priority(enum libinput_log_priority priority)
Set the global log priority.
Definition: libinput.h:743
void libinput_log_set_handler(libinput_log_handler log_handler, void *user_data)
Set the global log handler.
Definition: libinput.h:148
libinput_led
Mask reflecting LEDs on a device.
Definition: libinput.h:86
Touch event representing a touch down, move or up, as well as a touch cancel and touch frame events...
Definition: libinput.h:168
Definition: libinput.h:150
int32_t libinput_event_touch_get_slot(struct libinput_event_touch *event)
Get the slot of this touch event.
Definition: libinput.h:77
void * libinput_device_get_user_data(struct libinput_device *device)
Get the caller-specific data associated with this input device, if any.
Signals the end of a set of touchpoints at one device sample time.
Definition: libinput.h:158
static double li_fixed_to_double(li_fixed_t f)
Convert li_fixed_t to a double.
Definition: libinput.h:195
Definition: libinput.h:89
uint32_t libinput_event_keyboard_get_seat_key_count(struct libinput_event_keyboard *event)
For the key of a LIBINPUT_EVENT_KEYBOARD_KEY event, return the total number of keys pressed on all de...
void * libinput_seat_get_user_data(struct libinput_seat *seat)
Get the caller-specific data associated with this seat, if any.
struct libinput_event * libinput_event_device_notify_get_base_event(struct libinput_event_device_notify *event)
void libinput_seat_ref(struct libinput_seat *seat)
Increase the refcount of the seat.
void libinput_seat_unref(struct libinput_seat *seat)
Decrease the refcount of the seat.
static int li_fixed_to_int(li_fixed_t f)
Convert li_fixed_t to a int.
Definition: libinput.h:216
Definition: libinput.h:143
Signals that a device has been added to the context.
Definition: libinput.h:135
Definition: libinput.h:145
int32_t li_fixed_t
libinput 24.8 fixed point real number.
Definition: libinput.h:46
void libinput_path_remove_device(struct libinput_device *device)
Remove a device from a libinput context initialized with libinput_path_create_context() or added to s...
Signals that a device has been removed.
Definition: libinput.h:141
void libinput_device_calibrate(struct libinput_device *device, float calibration[6])
Apply the 3x3 transformation matrix to absolute device coordinates.
li_fixed_t libinput_event_pointer_get_absolute_y(struct libinput_event_pointer *event)
Return the current absolute y coordinate of the pointer event.
li_fixed_t libinput_event_pointer_get_absolute_y_transformed(struct libinput_event_pointer *event, uint32_t height)
Return the current absolute y coordinate of the pointer event, transformed to screen coordinates...
uint32_t libinput_event_touch_get_time(struct libinput_event_touch *event)
uint32_t libinput_event_pointer_get_seat_button_count(struct libinput_event_pointer *event)
For the button of a LIBINPUT_EVENT_POINTER_BUTTON event, return the total number of buttons pressed o...
Definition: libinput.h:147
Definition: libinput.h:53
struct libinput_event_device_notify * libinput_event_get_device_notify_event(struct libinput_event *event)
Return the device event that is this input event.
libinput_pointer_axis
Axes on a device that are not x or y coordinates.
Definition: libinput.h:109
int(* open_restricted)(const char *path, int flags, void *user_data)
Open the device at the given path with the flags provided and return the fd.
Definition: libinput.h:755
Definition: libinput.h:65
struct libinput * libinput_udev_create_for_seat(const struct libinput_interface *interface, void *user_data, struct udev *udev, const char *seat_id)
Create a new libinput context from udev, for input devices matching the given seat ID...
libinput_device_capability
Capabilities on a device.
Definition: libinput.h:64
Definition: libinput.h:151
int32_t libinput_event_touch_get_seat_slot(struct libinput_event_touch *event)
Get the seat slot of the touch event.
void libinput_device_led_update(struct libinput_device *device, enum libinput_led leds)
Update the LEDs on the device, if any.
struct libinput_device * libinput_path_add_device(struct libinput *libinput, const char *path)
Add a device to a libinput context initialized with libinput_path_create_context().
Definition: libinput.h:52
struct libinput * libinput_event_get_context(struct libinput_event *event)
Get the libinput context from the event.
li_fixed_t libinput_event_pointer_get_dx(struct libinput_event_pointer *event)
Return the delta between the last event and the current event.
Definition: libinput.h:78
Definition: libinput.h:153
enum libinput_keyboard_key_state libinput_event_keyboard_get_key_state(struct libinput_event_keyboard *event)
void libinput_device_unref(struct libinput_device *device)
Decrease the refcount of the input device.
struct libinput * libinput_path_create_context(const struct libinput_interface *interface, void *user_data)
Create a new libinput context that requires the caller to manually add or remove devices with libinpu...
enum libinput_event_type libinput_event_get_type(struct libinput_event *event)
Get the type of the event.
li_fixed_t libinput_event_pointer_get_dy(struct libinput_event_pointer *event)
Return the delta between the last event and the current event.
struct libinput_device * libinput_event_get_device(struct libinput_event *event)
Return the device associated with this event, if applicable.
void * libinput_get_user_data(struct libinput *libinput)
Definition: libinput.h:66
Definition: libinput.h:100
li_fixed_t libinput_event_touch_get_y(struct libinput_event_touch *event)
Return the current absolute y coordinate of the touch event.
void libinput_event_destroy(struct libinput_event *event)
Destroy the event.
Definition: libinput.h:110
Definition: libinput.h:146
void libinput_suspend(struct libinput *libinput)
Suspend monitoring for new devices and close existing devices.
void libinput_device_ref(struct libinput_device *device)
Increase the refcount of the input device.
Definition: libinput.h:87
libinput_pointer_button_state
Logical state of a physical button.
Definition: libinput.h:98
Definition: libinput.h:111
libinput_keyboard_key_state
Logical state of a key.
Definition: libinput.h:76
uint32_t libinput_event_keyboard_get_key(struct libinput_event_keyboard *event)
int libinput_get_fd(struct libinput *libinput)
libinput keeps a single file descriptor for all events.
int libinput_resume(struct libinput *libinput)
Resume a suspended libinput context.
int libinput_device_get_keys(struct libinput_device *device, char *keys, size_t size)
Set the bitmask in keys to the bitmask of the keys present on the device (see linux/input.h), up to size characters.
libinput_event_type
Event type for events returned by libinput_get_event().
Definition: libinput.h:119
struct libinput_event * libinput_get_event(struct libinput *libinput)
Retrieve the next event from libinput's internal event queue.
enum libinput_event_type libinput_next_event_type(struct libinput *libinput)
Return the type of the next event in the internal queue.
int libinput_device_has_capability(struct libinput_device *device, enum libinput_device_capability capability)
Check if the given device has the specified capability.
uint32_t libinput_event_keyboard_get_time(struct libinput_event_keyboard *event)
struct libinput_event_keyboard * libinput_event_get_keyboard_event(struct libinput_event *event)
Return the keyboard event that is this input event.
li_fixed_t libinput_event_touch_get_x(struct libinput_event_touch *event)
Return the current absolute x coordinate of the touch event.
Definition: libinput.h:88
void libinput_destroy(struct libinput *libinput)
Destroy the libinput context.
enum libinput_pointer_button_state libinput_event_pointer_get_button_state(struct libinput_event_pointer *event)
Return the button state that triggered this event.
struct libinput_seat * libinput_device_get_seat(struct libinput_device *device)
Get the seat associated with this input device.
li_fixed_t libinput_event_pointer_get_axis_value(struct libinput_event_pointer *event)
Return the axis value of the given axis.
const char * libinput_device_get_sysname(struct libinput_device *device)
Get the system name of the device.
void libinput_seat_set_user_data(struct libinput_seat *seat, void *user_data)
Set caller-specific data associated with this seat.
const char * libinput_seat_get_logical_name(struct libinput_seat *seat)
Return the logical name of the seat.
li_fixed_t libinput_event_pointer_get_absolute_x(struct libinput_event_pointer *event)
Return the current absolute x coordinate of the pointer event.
enum libinput_pointer_axis libinput_event_pointer_get_axis(struct libinput_event_pointer *event)
Return the axis that triggered this event.
li_fixed_t libinput_event_touch_get_y_transformed(struct libinput_event_touch *event, uint32_t height)
Return the current absolute y coordinate of the touch event, transformed to screen coordinates...
li_fixed_t libinput_event_touch_get_x_transformed(struct libinput_event_touch *event, uint32_t width)
Return the current absolute x coordinate of the touch event, transformed to screen coordinates...
struct libinput_event * libinput_event_keyboard_get_base_event(struct libinput_event_keyboard *event)
const char * libinput_device_get_output_name(struct libinput_device *device)
A device may be mapped to a single output, or all available outputs.
uint32_t libinput_event_pointer_get_time(struct libinput_event_pointer *event)
struct libinput_event * libinput_event_touch_get_base_event(struct libinput_event_touch *event)
li_fixed_t libinput_event_pointer_get_absolute_x_transformed(struct libinput_event_pointer *event, uint32_t width)
Return the current absolute x coordinate of the pointer event, transformed to screen coordinates...
void(* libinput_log_handler)(enum libinput_log_priority priority, void *user_data, const char *format, va_list args)
Log handler type for custom logging.
Definition: libinput.h:1006
This is not a real event type, and is only used to tell the user that no new event is available in th...
Definition: libinput.h:125
void libinput_device_set_user_data(struct libinput_device *device, void *user_data)
Set caller-specific data associated with this input device.
struct libinput_event * libinput_event_pointer_get_base_event(struct libinput_event_pointer *event)
struct libinput_event_pointer * libinput_event_get_pointer_event(struct libinput_event *event)
Return the pointer event that is this input event.
Definition: libinput.h:54
struct libinput_event_touch * libinput_event_get_touch_event(struct libinput_event *event)
Return the touch event that is this input event.