libeis.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 
25 #pragma once
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 #include <stddef.h>
32 #include <stdbool.h>
33 #include <stdint.h>
34 
44 struct eis;
45 struct eis_client;
46 struct eis_device;
47 struct eis_seat;
48 struct eis_event;
49 struct eis_keymap;
50 
56 };
57 
60 };
61 
75 
92 
98 
100 
104 };
105 
109 struct eis *
110 eis_new(void *user_data);
111 
117 };
118 
128 typedef void (*eis_log_handler)(struct eis *eis,
129  enum eis_log_priority priority,
130  const char *message,
131  bool is_continuation);
140 void
141 eis_log_set_handler(struct eis *eis, eis_log_handler log_handler);
142 
143 void
144 eis_log_set_priority(struct eis *eis, enum eis_log_priority priority);
145 
146 enum eis_log_priority
147 eis_log_get_priority(const struct eis *eis);
148 
149 struct eis *
150 eis_ref(struct eis *eis);
151 
152 struct eis *
153 eis_unref(struct eis *eis);
154 
155 void *
156 eis_get_user_data(struct eis *eis);
157 
158 void
159 eis_set_user_data(struct eis *eis, void *user_data);
160 
165 int
166 eis_setup_backend_socket(struct eis *ctx, const char *path);
167 
171 int
172 eis_setup_backend_fd(struct eis *ctx);
173 
177 int
178 eis_backend_fd_add_fd(struct eis *ctx, int fd);
179 
186 int
187 eis_get_fd(struct eis *eis);
188 
198 void
199 eis_dispatch(struct eis *eis);
200 
211 struct eis_event *
212 eis_get_event(struct eis *eis);
213 
230 struct eis_event *
231 eis_peek_event(struct eis *eis);
232 
242 struct eis_event *
243 eis_event_unref(struct eis_event *event);
244 
245 struct eis_client *
246 eis_client_ref(struct eis_client *client);
247 
248 struct eis_client *
249 eis_client_unref(struct eis_client *client);
250 
251 void *
252 eis_client_get_user_data(struct eis_client *eis_client);
253 
254 void
255 eis_client_set_user_data(struct eis_client *eis_client, void *user_data);
256 
261 const char *
262 eis_client_get_name(struct eis_client *client);
263 
273 void
274 eis_client_connect(struct eis_client *client);
275 
284 void
285 eis_client_disconnect(struct eis_client *client);
286 
298 struct eis_seat *
299 eis_client_new_seat(struct eis_client *client, const char *name);
300 
301 struct eis_seat *
302 eis_seat_ref(struct eis_seat *seat);
303 
304 struct eis_seat *
305 eis_seat_unref(struct eis_seat *seat);
306 
307 struct eis_client *
308 eis_seat_get_client(struct eis_seat *eis_seat);
309 
310 const char *
311 eis_seat_get_name(struct eis_seat *eis_seat);
312 
313 void *
314 eis_seat_get_user_data(struct eis_seat *eis_seat);
315 
316 void
317 eis_seat_set_user_data(struct eis_seat *eis_seat, void *user_data);
318 
329 void
330 eis_seat_allow_capability(struct eis_seat *seat,
331  enum eis_device_capability cap);
332 
337 void
338 eis_seat_add(struct eis_seat *seat);
339 
343 void
344 eis_seat_remove(struct eis_seat *seat);
345 
346 enum eis_event_type
347 eis_event_get_type(struct eis_event *event);
348 
349 struct eis_client *
350 eis_event_get_client(struct eis_event *event);
351 
352 struct eis_client *
353 eis_device_get_client(struct eis_device *device);
354 
355 struct eis_seat *
356 eis_device_get_seat(struct eis_device *device);
357 
358 struct eis_device *
359 eis_device_ref(struct eis_device *device);
360 
361 struct eis_device *
362 eis_device_unref(struct eis_device *device);
363 
364 void *
365 eis_device_get_user_data(struct eis_device *eis_device);
366 
367 void
368 eis_device_set_user_data(struct eis_device *eis_device, void *user_data);
369 
375 const char *
376 eis_device_get_name(struct eis_device *device);
377 
382 void
383 eis_device_set_name(struct eis_device *device, const char *name);
384 
385 bool
386 eis_device_has_capability(struct eis_device *device,
387  enum eis_device_capability cap);
388 
400 void
401 eis_device_allow_capability(struct eis_device *device,
402  enum eis_device_capability cap);
403 
421 void
422 eis_device_connect(struct eis_device *device);
423 
429 void
430 eis_device_disconnect(struct eis_device *device);
431 
444 void
445 eis_device_suspend(struct eis_device *device);
446 
453 void
454 eis_device_resume(struct eis_device *device);
455 
483 uint32_t
484 eis_device_pointer_get_width(struct eis_device *device);
485 
489 uint32_t
490 eis_device_pointer_get_height(struct eis_device *device);
491 
495 uint32_t
496 eis_device_touch_get_width(struct eis_device *device);
497 
503 uint32_t
504 eis_device_touch_get_height(struct eis_device *device);
505 
522 struct eis_keymap *
523 eis_keymap_new(enum eis_keymap_type type, int fd, size_t size);
524 
528 size_t
529 eis_keymap_get_size(struct eis_keymap *keymap);
530 
535 enum eis_keymap_type
536 eis_keymap_get_type(struct eis_keymap *keymap);
537 
543 int
544 eis_keymap_get_fd(struct eis_keymap *keymap);
545 
546 struct eis_keymap *
547 eis_keymap_ref(struct eis_keymap *keymap);
548 
549 struct eis_keymap *
550 eis_keymap_unref(struct eis_keymap *keymap);
551 
561 struct eis_device *
562 eis_keymap_get_device(struct eis_keymap *keymap);
563 
569 struct eis_keymap *
570 eis_device_keyboard_get_keymap(struct eis_device *device);
571 
589 void
590 eis_device_keyboard_set_keymap(struct eis_device *device,
591  struct eis_keymap *keymap);
592 
599 struct eis_device *
600 eis_event_get_device(struct eis_event *event);
601 
606 double
607 eis_event_pointer_get_dx(struct eis_event *event);
608 
613 double
614 eis_event_pointer_get_dy(struct eis_event *event);
615 
620 double
621 eis_event_pointer_get_absolute_x(struct eis_event *event);
622 
627 double
628 eis_event_pointer_get_absolute_y(struct eis_event *event);
629 
634 uint32_t
635 eis_event_pointer_get_button(struct eis_event *event);
636 
641 bool
642 eis_event_pointer_get_button_is_press(struct eis_event *event);
643 
648 double
649 eis_event_pointer_get_scroll_x(struct eis_event *event);
650 
655 double
656 eis_event_pointer_get_scroll_y(struct eis_event *event);
657 
662 int32_t
664 
669 int32_t
671 
676 uint32_t
677 eis_event_keyboard_get_key(struct eis_event *event);
678 
683 bool
684 eis_event_keyboard_get_key_is_press(struct eis_event *event);
685 
696 uint32_t
697 eis_event_touch_get_id(struct eis_event *event);
698 
703 double
704 eis_event_touch_get_x(struct eis_event *event);
705 
710 double
711 eis_event_touch_get_y(struct eis_event *event);
712 
717 #ifdef __cplusplus
718 }
719 #endif
uint32_t eis_device_pointer_get_height(struct eis_device *device)
void * eis_seat_get_user_data(struct eis_seat *eis_seat)
void eis_device_set_name(struct eis_device *device, const char *name)
Set the name of the device.
@ EIS_EVENT_POINTER_SCROLL_DISCRETE
Definition: libeis.h:97
void eis_seat_remove(struct eis_seat *seat)
Remove this seat and all its remaining devices.
@ EIS_EVENT_POINTER_SCROLL
Definition: libeis.h:96
uint32_t eis_device_pointer_get_width(struct eis_device *device)
Get the width of the absolute pointer device in logical pixels.
struct eis_keymap * eis_device_keyboard_get_keymap(struct eis_device *device)
Return the keymap assigned to this device.
void * eis_client_get_user_data(struct eis_client *eis_client)
struct eis_device * eis_device_unref(struct eis_device *device)
struct eis_seat * eis_seat_ref(struct eis_seat *seat)
void eis_device_connect(struct eis_device *device)
Connects the device.
eis_device_capability
Definition: libeis.h:51
void eis_client_set_user_data(struct eis_client *eis_client, void *user_data)
double eis_event_pointer_get_absolute_x(struct eis_event *event)
For an event of type EIS_EVENT_POINTER_MOTION_ABSOLUTE return the x position in logical pixels.
@ EIS_EVENT_POINTER_BUTTON
Definition: libeis.h:95
@ EIS_EVENT_CLIENT_DISCONNECT
The client has disconnected, any pending requests for this client should be discarded.
Definition: libeis.h:74
double eis_event_pointer_get_dx(struct eis_event *event)
For an event of type EIS_EVENT_POINTER_MOTION return the relative x movement in logical pixels.
struct eis_seat * eis_seat_unref(struct eis_seat *seat)
@ EIS_DEVICE_CAP_POINTER
Definition: libeis.h:52
void(* eis_log_handler)(struct eis *eis, enum eis_log_priority priority, const char *message, bool is_continuation)
The log handler for library logging.
Definition: libeis.h:128
int eis_get_fd(struct eis *eis)
libeis keeps a single file descriptor for all events.
int32_t eis_event_pointer_get_scroll_discrete_y(struct eis_event *event)
For an event of type EIS_EVENT_POINTER_SCROLL_DISCRETE return the y scroll distance in fractions or m...
enum eis_log_priority eis_log_get_priority(const struct eis *eis)
int eis_keymap_get_fd(struct eis_keymap *keymap)
Return a memmap-able file descriptor pointing to the keymap used by the device.
const char * eis_seat_get_name(struct eis_seat *eis_seat)
@ EIS_EVENT_POINTER_MOTION_ABSOLUTE
Definition: libeis.h:94
@ EIS_DEVICE_CAP_TOUCH
Definition: libeis.h:55
const char * eis_device_get_name(struct eis_device *device)
Return the name of the device.
void eis_seat_add(struct eis_seat *seat)
Add this seat to its client and notify the client of the seat's availability.
@ EIS_LOG_PRIORITY_INFO
Definition: libeis.h:114
@ EIS_LOG_PRIORITY_WARNING
Definition: libeis.h:115
uint32_t eis_event_touch_get_id(struct eis_event *event)
For an event of type EIS_EVENT_TOUCH_DOWN, EIS_EVENT_TOUCH_MOTION, or EIS_EVENT_TOUCH_UP,...
uint32_t eis_device_touch_get_width(struct eis_device *device)
eis_event_type
Definition: libeis.h:62
@ EIS_LOG_PRIORITY_DEBUG
Definition: libeis.h:113
@ EIS_DEVICE_CAP_POINTER_ABSOLUTE
Definition: libeis.h:53
void eis_seat_allow_capability(struct eis_seat *seat, enum eis_device_capability cap)
Allow a capability on the seat.
@ EIS_EVENT_DEVICE_REMOVED
The device created by the client was removed.
Definition: libeis.h:91
double eis_event_pointer_get_scroll_x(struct eis_event *event)
For an event of type EIS_EVENT_POINTER_SCROLL return the x scroll distance in logical pixels.
void eis_seat_set_user_data(struct eis_seat *eis_seat, void *user_data)
int eis_setup_backend_socket(struct eis *ctx, const char *path)
Initialize the context with a UNIX socket name.
void eis_device_allow_capability(struct eis_device *device, enum eis_device_capability cap)
Allow a capability on the device.
void eis_set_user_data(struct eis *eis, void *user_data)
struct eis_keymap * eis_keymap_ref(struct eis_keymap *keymap)
void eis_client_disconnect(struct eis_client *client)
Disconnect this client.
@ EIS_EVENT_CLIENT_CONNECT
A client has connected.
Definition: libeis.h:69
@ EIS_DEVICE_CAP_KEYBOARD
Definition: libeis.h:54
struct eis_client * eis_client_ref(struct eis_client *client)
struct eis_keymap * eis_keymap_unref(struct eis_keymap *keymap)
@ EIS_EVENT_KEYBOARD_KEY
Definition: libeis.h:99
bool eis_event_pointer_get_button_is_press(struct eis_event *event)
For an event of type EIS_EVENT_POINTER_BUTTON return true if the event is a button press,...
struct eis_keymap * eis_keymap_new(enum eis_keymap_type type, int fd, size_t size)
Create a new keymap of the given type.
struct eis_client * eis_event_get_client(struct eis_event *event)
uint32_t eis_device_touch_get_height(struct eis_device *device)
struct eis_client * eis_device_get_client(struct eis_device *device)
enum eis_keymap_type eis_keymap_get_type(struct eis_keymap *keymap)
Returns the type for this keymap.
bool eis_device_has_capability(struct eis_device *device, enum eis_device_capability cap)
uint32_t eis_event_pointer_get_button(struct eis_event *event)
For an event of type EIS_EVENT_POINTER_BUTTON return the button code as defined in linux/input-event-...
@ EIS_EVENT_DEVICE_ADDED
The client requests creation of a device with a given set of capabilities.
Definition: libeis.h:83
double eis_event_pointer_get_scroll_y(struct eis_event *event)
For an event of type EIS_EVENT_POINTER_SCROLL return the y scroll distance in logical pixels.
@ EIS_EVENT_TOUCH_MOTION
Definition: libeis.h:103
void * eis_get_user_data(struct eis *eis)
struct eis_device * eis_event_get_device(struct eis_event *event)
Return the device from this event.
double eis_event_pointer_get_dy(struct eis_event *event)
For an event of type EIS_EVENT_POINTER_MOTION return the relative y movement in logical pixels.
struct eis_client * eis_seat_get_client(struct eis_seat *eis_seat)
void eis_device_keyboard_set_keymap(struct eis_device *device, struct eis_keymap *keymap)
Set the keymap on the device.
uint32_t eis_event_keyboard_get_key(struct eis_event *event)
For an event of type EIS_EVENT_KEYBOARD_KEY return the key code (as defined in include/linux/input-ev...
struct eis_event * eis_get_event(struct eis *eis)
Returns the next event in the internal event queue (or NULL) and removes it from the queue.
struct eis_client * eis_client_unref(struct eis_client *client)
void eis_log_set_handler(struct eis *eis, eis_log_handler log_handler)
Change the log handler for this context.
@ EIS_EVENT_TOUCH_UP
Definition: libeis.h:102
void eis_dispatch(struct eis *eis)
Main event dispatching function.
eis_keymap_type
Definition: libeis.h:58
double eis_event_pointer_get_absolute_y(struct eis_event *event)
For an event of type EIS_EVENT_POINTER_MOTION_ABSOLUTE return the y position in logical pixels.
void * eis_device_get_user_data(struct eis_device *eis_device)
size_t eis_keymap_get_size(struct eis_keymap *keymap)
struct eis_seat * eis_client_new_seat(struct eis_client *client, const char *name)
Create a new logical seat with a given name.
void eis_device_suspend(struct eis_device *device)
Notify the client that the device is suspended and that no events from the client will be processed.
const char * eis_client_get_name(struct eis_client *client)
Return the name set by this client.
struct eis_event * eis_peek_event(struct eis *eis)
Returns the next event in the internal event queue (or NULL) without removing that event from the que...
@ EIS_KEYMAP_TYPE_XKB
Definition: libeis.h:59
struct eis_event * eis_event_unref(struct eis_event *event)
Release resources associated with this event.
void eis_device_disconnect(struct eis_device *device)
Disconnect the device.
double eis_event_touch_get_y(struct eis_event *event)
For an event of type EIS_EVENT_TOUCH_DOWN, or EIS_EVENT_TOUCH_MOTION, return the y coordinate of the ...
struct eis * eis_unref(struct eis *eis)
void eis_device_set_user_data(struct eis_device *eis_device, void *user_data)
eis_log_priority
Definition: libeis.h:112
int32_t eis_event_pointer_get_scroll_discrete_x(struct eis_event *event)
For an event of type EIS_EVENT_POINTER_SCROLL_DISCRETE return the x scroll distance in fractions or m...
@ EIS_LOG_PRIORITY_ERROR
Definition: libeis.h:116
enum eis_event_type eis_event_get_type(struct eis_event *event)
void eis_client_connect(struct eis_client *client)
Allow connection from the client.
struct eis_seat * eis_device_get_seat(struct eis_device *device)
int eis_setup_backend_fd(struct eis *ctx)
Initialize the context that can take pre-configured sockets.
int eis_backend_fd_add_fd(struct eis *ctx, int fd)
Add a new client to a context set up with eis_setup_backend_fd()
void eis_log_set_priority(struct eis *eis, enum eis_log_priority priority)
struct eis_device * eis_keymap_get_device(struct eis_keymap *keymap)
Return the device this keymap belongs to, or NULL if it has not yet been assigned to a device.
struct eis_device * eis_device_ref(struct eis_device *device)
@ EIS_EVENT_POINTER_MOTION
Definition: libeis.h:93
struct eis * eis_ref(struct eis *eis)
bool eis_event_keyboard_get_key_is_press(struct eis_event *event)
For an event of type EIS_EVENT_KEYBOARD_KEY return true if the event is a key down,...
void eis_device_resume(struct eis_device *device)
Notify the client that the capabilities are resumed and that events from the device will be processed...
struct eis * eis_new(void *user_data)
Create a new libeis context with a refcount of 1.
@ EIS_EVENT_TOUCH_DOWN
Definition: libeis.h:101
double eis_event_touch_get_x(struct eis_event *event)
For an event of type EIS_EVENT_TOUCH_DOWN, or EIS_EVENT_TOUCH_MOTION, return the x coordinate of the ...