/* SPDX-License-Identifier: MIT */ /* * Copyright © 2020 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #pragma once #include #include "util-macros.h" #include "util-object.h" #include "libei.h" #include "brei-shared.h" #include "util-list.h" #include "util-sources.h" #include "util-structs.h" #include "libei-callback.h" #include "libei-connection.h" #include "libei-connection-setup.h" #include "libei-seat.h" #include "libei-device.h" #include "libei-event.h" #include "libei-region.h" struct ei_backend_interface { void (*destroy)(struct ei *ei, void *backend); }; enum ei_state { EI_STATE_NEW, /* No backend yet */ EI_STATE_BACKEND, /* We have a backend */ EI_STATE_CONNECTING, /* client requested connect */ EI_STATE_CONNECTED, /* server has sent connect */ EI_STATE_DISCONNECTING, /* in the process of cleaning up */ EI_STATE_DISCONNECTED, }; struct ei { struct object object; struct ei_connection *connection; struct list proto_objects; /* brei_object list */ uint32_t next_object_id; void *user_data; struct sink *sink; struct source *source; struct ei_backend_interface backend_interface; void *backend; enum ei_state state; struct list event_queue; struct list seats; char *name; struct { ei_log_handler handler; enum ei_log_priority priority; } log; bool is_sender; uint32_t server_version; uint32_t client_version; }; const struct ei_connection_interface * ei_get_interface(struct ei *ei); int ei_set_socket(struct ei *ei, int fd); void ei_disconnect(struct ei *ei); struct ei * ei_get_context(struct ei *ei); struct ei_connection * ei_get_connection(struct ei *ei); uint32_t ei_get_new_id(struct ei *ei); void ei_register_object(struct ei *ei, struct brei_object *object); void ei_unregister_object(struct ei *ei, struct brei_object *object); int ei_send_message(struct ei *ei, const struct brei_object *object, uint32_t opcode, const char *signature, size_t nargs, ...); void ei_add_seat(struct ei_seat *seat); int ei_send_close_device(struct ei_device *device); int ei_send_start_emulating(struct ei_device *device, uint32_t sequence); int ei_send_stop_emulating(struct ei_device *device); int ei_send_frame(struct ei_device *device, uint64_t time); void ei_queue_device_removed_event(struct ei_device *device); void ei_insert_device_removed_event(struct ei_device *device); void ei_queue_seat_removed_event(struct ei_seat *seat); void ei_queue_device_start_emulating_event(struct ei_device *device, uint32_t sequence); void ei_queue_device_stop_emulating_event(struct ei_device *device); void ei_queue_frame_event(struct ei_device *device, uint64_t time); void ei_queue_pointer_rel_event(struct ei_device *device, double x, double y); void ei_queue_pointer_abs_event(struct ei_device *device, double x, double y); void ei_queue_pointer_button_event(struct ei_device *device, uint32_t button, bool is_press); void ei_queue_keyboard_key_event(struct ei_device *device, uint32_t key, bool is_press); void ei_queue_pointer_scroll_event(struct ei_device *device, double x, double y); void ei_queue_pointer_scroll_discrete_event(struct ei_device *device, int32_t x, int32_t y); void ei_queue_pointer_scroll_stop_event(struct ei_device *device, bool x, bool y); void ei_queue_pointer_scroll_cancel_event(struct ei_device *device, bool x, bool y); void ei_queue_touch_down_event(struct ei_device *device, uint32_t touchid, double x, double y); void ei_queue_touch_motion_event(struct ei_device *device, uint32_t touchid, double x, double y); void ei_queue_touch_up_event(struct ei_device *device, uint32_t touchid); int ei_send_pointer_rel(struct ei_device *device, double x, double y); int ei_send_pointer_abs(struct ei_device *device, double x, double y); int ei_send_pointer_button(struct ei_device *device, uint32_t button, bool is_press); int ei_send_pointer_scroll(struct ei_device *device, double x, double y); int ei_send_pointer_scroll_stop(struct ei_device *device, double x, double y); int ei_send_pointer_scroll_cancel(struct ei_device *device, double x, double y); int ei_send_pointer_scroll_discrete(struct ei_device *device, int32_t x, int32_t y); int ei_send_keyboard_key(struct ei_device *device, uint32_t key, bool is_press); int ei_send_touch_down(struct ei_device *device, uint32_t tid, double x, double y); int ei_send_touch_motion(struct ei_device *device, uint32_t tid, double x, double y); int ei_send_touch_up(struct ei_device *device, uint32_t tid); _printf_(6, 7) void ei_log_msg(struct ei *ei, enum ei_log_priority priority, const char *file, int lineno, const char *func, const char *format, ...); _printf_(6, 0) void ei_log_msg_va(struct ei *ei, enum ei_log_priority priority, const char *file, int lineno, const char *func, const char *format, va_list args); #define log_debug(T_, ...) \ ei_log_msg((T_), EI_LOG_PRIORITY_DEBUG, __FILE__, __LINE__, __func__, __VA_ARGS__) #define log_info(T_, ...) \ ei_log_msg((T_), EI_LOG_PRIORITY_INFO, __FILE__, __LINE__, __func__, __VA_ARGS__) #define log_warn(T_, ...) \ ei_log_msg((T_), EI_LOG_PRIORITY_WARNING, __FILE__, __LINE__, __func__, __VA_ARGS__) #define log_error(T_, ...) \ ei_log_msg((T_), EI_LOG_PRIORITY_ERROR, __FILE__, __LINE__, __func__, __VA_ARGS__) #define log_bug(T_, ...) \ ei_log_msg((T_), EI_LOG_PRIORITY_ERROR, __FILE__, __LINE__, __func__, "🪳 libei bug: " __VA_ARGS__) #define log_bug_client(T_, ...) \ ei_log_msg((T_), EI_LOG_PRIORITY_ERROR, __FILE__, __LINE__, __func__, "🪲 Bug: " __VA_ARGS__)