libei.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2020 Red Hat, Inc.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21  * DEALINGS IN THE SOFTWARE.
22  */
23 
24 #pragma once
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 #include <stdbool.h>
31 #include <stdint.h>
32 #include <stddef.h>
33 
52 struct ei;
53 
65 struct ei_device;
66 
80 struct ei_seat;
81 
90 struct ei_event;
91 
99 struct ei_keymap;
100 
122 };
123 
134 };
135 
150 };
151 
179 
190 
202 
217 
229 
239 };
240 
255 struct ei *
256 ei_new(void *user_data);
257 
263 };
264 
274 typedef void (*ei_log_handler)(struct ei *ei,
275  enum ei_log_priority priority,
276  const char *message,
277  bool is_continuation);
286 void
287 ei_log_set_handler(struct ei *ei, ei_log_handler log_handler);
288 
289 void
290 ei_log_set_priority(struct ei *ei, enum ei_log_priority priority);
291 
292 enum ei_log_priority
293 ei_log_get_priority(const struct ei *ei);
294 
307 void
308 ei_configure_name(struct ei * ei, const char *name);
309 
329 int
330 ei_setup_backend_socket(struct ei *ei, const char *socketpath);
331 
346 int
347 ei_setup_backend_fd(struct ei *ei, int fd);
348 
354 int
356 
366 int
367 ei_setup_backend_portal_busname(struct ei *ei, const char *busname);
368 
375 struct ei *
376 ei_ref(struct ei *ei);
377 
385 struct ei *
386 ei_unref(struct ei *ei);
387 
393 void
394 ei_set_user_data(struct ei *ei, void *user_data);
395 
400 void *
402 
409 int
410 ei_get_fd(struct ei *ei);
411 
421 void
422 ei_dispatch(struct ei *ei);
423 
429 struct ei_event *
430 ei_get_event(struct ei *ei);
431 
448 struct ei_event *
449 ei_peek_event(struct ei *ei);
450 
460 struct ei_event *
461 ei_event_unref(struct ei_event *event);
462 
463 const char *
464 ei_seat_get_name(struct ei_seat *seat);
465 
466 bool
468  enum ei_device_capability cap);
469 
470 struct ei_seat *
471 ei_seat_ref(struct ei_seat *seat);
472 
473 struct ei_seat *
474 ei_seat_unref(struct ei_seat *seat);
475 
479 struct ei *
481 
485 enum ei_event_type
486 ei_event_get_type(struct ei_event *event);
487 
497 struct ei_device *
499 
503 uint64_t
505 
512 struct ei_device *
513 ei_device_ref(struct ei_device *device);
514 
522 struct ei_device *
523 ei_device_unref(struct ei_device *device);
524 
541 struct ei_device *
543 
544 struct ei_seat *
546 
552 void
553 ei_seat_set_user_data(struct ei_seat *seat, void *user_data);
554 
559 void *
561 
567 void
568 ei_device_set_user_data(struct ei_device *device, void *user_data);
569 
574 void *
576 
592 void
593 ei_device_configure_name(struct ei_device *device, const char *name);
594 
606 bool
608  enum ei_device_capability cap);
609 
640 void
642  uint32_t width,
643  uint32_t height);
644 
650 void
652  uint32_t width,
653  uint32_t height);
654 
655 
672 struct ei_keymap *
673 ei_keymap_new(enum ei_keymap_type type, int fd, size_t size);
674 
678 size_t
680 
685 enum ei_keymap_type
686 ei_keymap_get_type(struct ei_keymap *keymap);
687 
693 int
694 ei_keymap_get_fd(struct ei_keymap *keymap);
695 
709 enum ei_keymap_source
710 ei_keymap_get_source(struct ei_keymap *keymap);
711 
724 struct ei_device *
726 
733 struct ei_keymap *
734 ei_keymap_ref(struct ei_keymap *keymap);
735 
743 struct ei_keymap *
744 ei_keymap_unref(struct ei_keymap *keymap);
745 
775 void
777  struct ei_keymap *keymap);
778 
796 void
797 ei_device_add(struct ei_device *device);
798 
815 void
816 ei_device_remove(struct ei_device *device);
817 
828 const char *
830 
838 bool
840  enum ei_device_capability cap);
841 
847 uint32_t
849 
855 uint32_t
857 
863 uint32_t
865 
871 uint32_t
873 
889 struct ei_keymap *
891 
895 struct ei_device *
897 
901 struct ei *
903 
912 void
913 ei_device_pointer_motion(struct ei_device *device, double x, double y);
914 
928 void
930  double x, double y);
931 
943 void
945  uint32_t button, bool is_press);
946 
962 void
963 ei_device_pointer_scroll(struct ei_device *device, double x, double y);
964 
984 void
985 ei_device_pointer_scroll_discrete(struct ei_device *device, int32_t x, int32_t y);
986 
998 void
999 ei_device_keyboard_key(struct ei_device *device, uint32_t keycode, bool is_press);
1000 
1009 struct ei_touch *
1011 
1024 void
1025 ei_touch_down(struct ei_touch *touch, double x, double y);
1026 
1030 void
1031 ei_touch_motion(struct ei_touch *touch, double x, double y);
1032 
1038 void
1039 ei_touch_up(struct ei_touch *touch);
1040 
1047 struct ei_touch *
1048 ei_touch_ref(struct ei_touch *touch);
1049 
1057 struct ei_touch *
1058 ei_touch_unref(struct ei_touch *touch);
1059 
1064 void
1065 ei_touch_set_user_data(struct ei_touch *touch, void *user_data);
1066 
1072 void *
1073 ei_touch_get_user_data(struct ei_touch *touch);
1074 
1078 struct ei_device *
1079 ei_touch_get_device(struct ei_touch *touch);
1080 
1090 struct ei_seat *
1092 
1097 #ifdef __cplusplus
1098 }
1099 #endif
@ EI_KEYMAP_SOURCE_SERVER
The keymap is provided by the server.
Definition: libei.h:149
struct ei * ei_seat_get_context(struct ei_seat *seat)
Return the struct EI - the client implementation context this seat is associated with.
A single device to generate input events from.
Definition: libei.h:52
void ei_device_keyboard_key(struct ei_device *device, uint32_t keycode, bool is_press)
Generate a key event on a device with the EI_DEVICE_CAP_KEYBOARD capability.
void * ei_get_user_data(struct ei *ei)
Return the custom data pointer for this context.
bool ei_device_configure_capability(struct ei_device *device, enum ei_device_capability cap)
Enable the given capability on this device.
int ei_keymap_get_fd(struct ei_keymap *keymap)
Return a memmap-able file descriptor pointing to the keymap used by the device.
void ei_device_pointer_scroll(struct ei_device *device, double x, double y)
Generate a scroll event on a device with the EI_DEVICE_CAP_POINTER_ABSOLUTE or EI_DEVICE_CAP_POINTER ...
struct ei_device * ei_event_get_device(struct ei_event *event)
Return the device from this event.
@ EI_DEVICE_CAP_POINTER
Definition: libei.h:118
@ EI_LOG_PRIORITY_INFO
Definition: libei.h:260
void ei_log_set_priority(struct ei *ei, enum ei_log_priority priority)
struct ei_keymap * ei_device_keyboard_get_keymap(struct ei_device *device)
Return the keymap for this device or NULL.
void ei_configure_name(struct ei *ei, const char *name)
Set the name for this client.
struct ei_seat * ei_seat_unref(struct ei_seat *seat)
uint32_t ei_device_touch_get_height(struct ei_device *device)
Return the requested height for an EI_DEVICE_CAP_TOUCH device.
An event received from the EIS implementation.
Definition: libei.h:80
@ EI_EVENT_SEAT_ADDED
The server has added a seat available to this client.
Definition: libei.h:189
void ei_device_pointer_button(struct ei_device *device, uint32_t button, bool is_press)
Generate a button event on a device with the EI_DEVICE_CAP_POINTER_ABSOLUTE or EI_DEVICE_CAP_POINTER ...
struct ei_event * ei_peek_event(struct ei *ei)
Returns the next event in the internal event queue (or NULL) without removing that event from the que...
int ei_setup_backend_portal_busname(struct ei *ei, const char *busname)
Connect to an org.freedesktop.portal.Desktop implementation on the given busname.
void ei_touch_down(struct ei_touch *touch, double x, double y)
This function can only be called once on an ei_touch object.
void ei_device_remove(struct ei_device *device)
Notify the server that the device should be removed.
struct ei_seat * ei_device_get_seat(struct ei_device *device)
ei_keymap_source
Identifies who provided a struct ei_keymap.
Definition: libei.h:141
struct ei_device * ei_device_new(struct ei_seat *ei_seat)
Create a new device in the given seat.
int ei_setup_backend_socket(struct ei *ei, const char *socketpath)
Set this ei context to use the socket backend.
int ei_setup_backend_portal(struct ei *ei)
Connect to the org.freedesktop.portal.Desktop portal.
void ei_log_set_handler(struct ei *ei, ei_log_handler log_handler)
Change the log handler for this context.
@ EI_EVENT_DEVICE_ADDED
The server has added a device for this client.
Definition: libei.h:216
void ei_device_add(struct ei_device *device)
Request that the device be added to the server.
uint64_t ei_event_get_time(struct ei_event *event)
@ EI_EVENT_DISCONNECT
The server has disconnected this client - all resources left to reference this server are now obsolet...
Definition: libei.h:178
const char * ei_device_get_name(struct ei_device *device)
Return the name of this device.
struct ei * ei_unref(struct ei *ei)
Decrease the refcount of this struct by one.
struct ei_touch * ei_device_touch_new(struct ei_device *device)
Initiate a new touch on a device with the EI_DEVICE_CAP_TOUCH capability.
size_t ei_keymap_get_size(struct ei_keymap *keymap)
void * ei_seat_get_user_data(struct ei_seat *seat)
Return the custom data pointer for this context.
void ei_device_pointer_scroll_discrete(struct ei_device *device, int32_t x, int32_t y)
Generate a discrete scroll event on a device with the EI_DEVICE_CAP_POINTER_ABSOLUTE or EI_DEVICE_CAP...
@ EI_DEVICE_CAP_TOUCH
Definition: libei.h:121
struct ei * ei_ref(struct ei *ei)
Increase the refcount of this struct by one.
struct ei_keymap * ei_keymap_ref(struct ei_keymap *keymap)
Increase the refcount of this struct by one.
@ EI_DEVICE_CAP_POINTER_ABSOLUTE
Definition: libei.h:119
@ EI_EVENT_SEAT_REMOVED
The server has removed a seat previously available to this client.
Definition: libei.h:201
void ei_dispatch(struct ei *ei)
Main event dispatching function.
struct ei_touch * ei_touch_ref(struct ei_touch *touch)
Increase the refcount of this struct by one.
bool ei_seat_has_capability(struct ei_seat *seat, enum ei_device_capability cap)
void * ei_device_get_user_data(struct ei_device *device)
Return the custom data pointer for this context.
enum ei_keymap_type ei_keymap_get_type(struct ei_keymap *keymap)
Returns the type for this keymap.
int ei_setup_backend_fd(struct ei *ei, int fd)
Initialize the ei context on the given socket.
void ei_device_set_user_data(struct ei_device *device, void *user_data)
Set a custom data pointer for this context.
struct ei_device * ei_touch_get_device(struct ei_touch *touch)
ei_event_type
Definition: libei.h:155
@ EI_EVENT_DEVICE_REMOVED
The server has removed a device belonging to this client.
Definition: libei.h:228
void ei_device_pointer_configure_range(struct ei_device *device, uint32_t width, uint32_t height)
Set the range of the absolute pointer device in logical pixels.
enum ei_log_priority ei_log_get_priority(const struct ei *ei)
struct ei * ei_new(void *user_data)
Create a new ei context.
void ei_set_user_data(struct ei *ei, void *user_data)
Set a custom data pointer for this context.
bool ei_device_has_capability(struct ei_device *device, enum ei_device_capability cap)
Return true if the device has the requested capability.
void * ei_touch_get_user_data(struct ei_touch *touch)
Set a custom data pointer for this context.
struct ei_event * ei_get_event(struct ei *ei)
Return the next event from the event queue, removing it from the queue.
const char * ei_seat_get_name(struct ei_seat *seat)
int ei_get_fd(struct ei *ei)
libei keeps a single file descriptor for all events.
void ei_touch_motion(struct ei_touch *touch, double x, double y)
Move this touch to the new coordinates.
void ei_seat_set_user_data(struct ei_seat *seat, void *user_data)
Set a custom data pointer for this context.
struct ei_device * ei_device_unref(struct ei_device *device)
Decrease the refcount of this struct by one.
The main context to interact with libei.
void ei_device_keyboard_configure_keymap(struct ei_device *device, struct ei_keymap *keymap)
Request this keymap for this device with the EI_DEVICE_CAP_KEYBOARD capability.
struct ei_keymap * ei_keymap_new(enum ei_keymap_type type, int fd, size_t size)
Create a new keymap of the given type.
struct ei_device * ei_keymap_get_context(struct ei_keymap *keymap)
Return the struct ei_device this keymap is associated with.
@ EI_KEYMAP_TYPE_XKB
A libxkbcommon-compatible XKB keymap.
Definition: libei.h:133
void ei_touch_up(struct ei_touch *touch)
Release this touch.
struct ei_seat * ei_seat_ref(struct ei_seat *seat)
void(* ei_log_handler)(struct ei *ei, enum ei_log_priority priority, const char *message, bool is_continuation)
The log handler for library logging.
Definition: libei.h:274
@ EI_KEYMAP_SOURCE_CLIENT
The keymap is the one provided by the client.
Definition: libei.h:145
ei_device_capability
The set of supported capabilities.
Definition: libei.h:117
struct ei_device * ei_keymap_get_device(struct ei_keymap *keymap)
Return the device this keymap belongs to, or NULL if it has not yet been assigned to a device.
void ei_touch_set_user_data(struct ei_touch *touch, void *user_data)
Return the custom data pointer for this context.
uint32_t ei_device_touch_get_width(struct ei_device *device)
Return the requested width for an EI_DEVICE_CAP_TOUCH device.
@ EI_EVENT_CONNECT
The server has approved the connection to this client.
Definition: libei.h:165
A logical seat for a group of devices.
Definition: libei.h:65
struct ei_device * ei_device_ref(struct ei_device *device)
Increase the refcount of this struct by one.
@ EI_EVENT_DEVICE_RESUMED
The client may send events.
Definition: libei.h:238
void ei_device_touch_configure_range(struct ei_device *device, uint32_t width, uint32_t height)
Set the range of the touch device in logical pixels.
@ EI_LOG_PRIORITY_WARNING
Definition: libei.h:261
@ EI_EVENT_DEVICE_SUSPENDED
Any events sent from this device will be discarded until the next resume.
Definition: libei.h:234
@ EI_DEVICE_CAP_KEYBOARD
Definition: libei.h:120
@ EI_LOG_PRIORITY_ERROR
Definition: libei.h:262
@ EI_LOG_PRIORITY_DEBUG
Definition: libei.h:259
uint32_t ei_device_pointer_get_height(struct ei_device *device)
Return the requested height for an EI_DEVICE_CAP_POINTER_ABSOLUTE device.
struct ei_keymap * ei_keymap_unref(struct ei_keymap *keymap)
Decrease the refcount of this struct by one.
struct ei * ei_device_get_context(struct ei_device *device)
Return the struct EI - the client implementation context this device is associated with.
An keymap for a device with the EI_DEVICE_CAP_KEYBOARD capability.
Definition: libei.h:90
ei_log_priority
Definition: libei.h:258
void ei_device_configure_name(struct ei_device *device, const char *name)
Set the name for this device.
struct ei_touch * ei_touch_unref(struct ei_touch *touch)
Decrease the refcount of this struct by one.
void ei_device_pointer_motion_absolute(struct ei_device *device, double x, double y)
Generate an absolute motion event on a device with the EI_DEVICE_CAP_POINTER_ABSOLUTE capability.
struct ei_event * ei_event_unref(struct ei_event *event)
Release resources associated with this event.
ei_keymap_type
The set of supported keymap types for a struct ei_keymap.
Definition: libei.h:129
uint32_t ei_device_pointer_get_width(struct ei_device *device)
Return the requested width for an EI_DEVICE_CAP_POINTER_ABSOLUTE device.
struct ei_seat * ei_event_get_seat(struct ei_event *event)
Return the seat from this event.
enum ei_event_type ei_event_get_type(struct ei_event *event)
enum ei_keymap_source ei_keymap_get_source(struct ei_keymap *keymap)
Returns the source for the keymap on this device, if any.
void ei_device_pointer_motion(struct ei_device *device, double x, double y)
Generate a relative motion event on a device with the EI_DEVICE_CAP_POINTER capability.