2022-03-03 09:15:57 +10:00
|
|
|
/* SPDX-License-Identifier: MIT */
|
2020-07-29 11:53:03 +10:00
|
|
|
/*
|
|
|
|
|
* 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
|
|
|
|
|
|
2020-08-20 11:51:41 +10:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
2020-09-28 16:17:28 +10:00
|
|
|
#include "util-macros.h"
|
2020-07-29 11:53:03 +10:00
|
|
|
#include "util-object.h"
|
|
|
|
|
|
|
|
|
|
#include "libei.h"
|
|
|
|
|
#include "util-list.h"
|
|
|
|
|
#include "util-sources.h"
|
2020-08-18 13:04:01 +10:00
|
|
|
#include "util-structs.h"
|
2020-07-29 11:53:03 +10:00
|
|
|
|
2020-08-05 16:09:27 +10:00
|
|
|
struct ei_backend_interface {
|
|
|
|
|
void (*destroy)(struct ei *ei, void *backend);
|
2020-07-29 11:53:03 +10:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum ei_state {
|
2020-08-07 11:28:39 +10:00
|
|
|
EI_STATE_NEW, /* No backend yet */
|
2020-08-07 10:52:16 +10:00
|
|
|
EI_STATE_BACKEND, /* We have a backend */
|
2020-07-29 11:53:03 +10:00
|
|
|
EI_STATE_CONNECTING, /* client requested connect */
|
|
|
|
|
EI_STATE_CONNECTED, /* server has sent connect */
|
2020-08-07 11:28:39 +10:00
|
|
|
EI_STATE_DISCONNECTING, /* in the process of cleaning up */
|
2020-07-29 11:53:03 +10:00
|
|
|
EI_STATE_DISCONNECTED,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct ei {
|
|
|
|
|
struct object object;
|
|
|
|
|
void *user_data;
|
|
|
|
|
struct sink *sink;
|
|
|
|
|
struct source *source;
|
2020-08-05 16:09:27 +10:00
|
|
|
struct ei_backend_interface backend_interface;
|
|
|
|
|
void *backend;
|
2020-07-29 11:53:03 +10:00
|
|
|
enum ei_state state;
|
|
|
|
|
struct list event_queue;
|
2020-09-14 17:16:50 +10:00
|
|
|
struct list seats;
|
2020-07-30 09:40:16 +10:00
|
|
|
char *name;
|
2020-08-20 11:51:41 +10:00
|
|
|
|
2021-08-24 14:49:39 +10:00
|
|
|
struct list properties;
|
|
|
|
|
|
2020-08-20 11:51:41 +10:00
|
|
|
struct {
|
|
|
|
|
ei_log_handler handler;
|
|
|
|
|
enum ei_log_priority priority;
|
|
|
|
|
} log;
|
2021-08-11 11:05:30 +10:00
|
|
|
|
|
|
|
|
const struct ei_proto_requests *requests;
|
2020-07-29 11:53:03 +10:00
|
|
|
};
|
|
|
|
|
|
2020-10-28 15:32:42 +10:00
|
|
|
enum ei_seat_state {
|
2021-07-16 18:17:15 +10:00
|
|
|
EI_SEAT_STATE_NEW,
|
|
|
|
|
EI_SEAT_STATE_BOUND,
|
|
|
|
|
EI_SEAT_STATE_UNBOUND,
|
2020-10-28 15:32:42 +10:00
|
|
|
EI_SEAT_STATE_REMOVED,
|
|
|
|
|
};
|
|
|
|
|
|
2020-09-14 17:16:50 +10:00
|
|
|
struct ei_seat {
|
|
|
|
|
struct object object;
|
|
|
|
|
void *user_data;
|
|
|
|
|
struct list link;
|
2020-10-28 15:32:42 +10:00
|
|
|
enum ei_seat_state state;
|
2020-09-14 17:16:50 +10:00
|
|
|
struct list devices;
|
2021-07-21 09:27:18 +10:00
|
|
|
struct list devices_removed; /* removed from seat but client still has a ref */
|
2020-09-14 17:16:50 +10:00
|
|
|
uint32_t id;
|
|
|
|
|
uint32_t capabilities;
|
2021-07-16 18:17:15 +10:00
|
|
|
uint32_t capabilities_mask;
|
2020-09-14 17:16:50 +10:00
|
|
|
char *name;
|
|
|
|
|
};
|
|
|
|
|
|
2020-07-29 11:53:03 +10:00
|
|
|
enum ei_device_state {
|
2021-07-21 14:51:00 +10:00
|
|
|
/* Before the DeviceAddedDone was received */
|
|
|
|
|
EI_DEVICE_STATE_NEW,
|
2021-08-23 08:25:33 +10:00
|
|
|
EI_DEVICE_STATE_PAUSED,
|
2020-08-19 13:39:32 +10:00
|
|
|
EI_DEVICE_STATE_RESUMED,
|
2021-08-24 09:53:10 +10:00
|
|
|
EI_DEVICE_STATE_EMULATING,
|
2020-10-26 09:24:43 +10:00
|
|
|
/**
|
|
|
|
|
* Client removed the device, we no longer accept events from the
|
|
|
|
|
* client
|
|
|
|
|
*/
|
|
|
|
|
EI_DEVICE_STATE_REMOVED_FROM_CLIENT,
|
|
|
|
|
/**
|
|
|
|
|
* Server removed the device, we need to remove it ourselves now.
|
|
|
|
|
*/
|
|
|
|
|
EI_DEVICE_STATE_REMOVED_FROM_SERVER,
|
|
|
|
|
/**
|
|
|
|
|
* Device has been removed by both sides.
|
|
|
|
|
*/
|
|
|
|
|
EI_DEVICE_STATE_DEAD,
|
2020-07-29 11:53:03 +10:00
|
|
|
};
|
|
|
|
|
|
2021-07-21 14:52:04 +10:00
|
|
|
struct ei_region {
|
|
|
|
|
struct object object;
|
|
|
|
|
void *user_data;
|
|
|
|
|
struct list link;
|
|
|
|
|
uint32_t x, y;
|
|
|
|
|
uint32_t width, height;
|
2021-07-23 10:30:35 +10:00
|
|
|
double physical_scale;
|
2021-07-21 14:52:04 +10:00
|
|
|
};
|
|
|
|
|
|
2020-07-29 11:53:03 +10:00
|
|
|
struct ei_device {
|
|
|
|
|
struct object object;
|
2020-08-19 11:25:03 +10:00
|
|
|
void *user_data;
|
2020-07-29 11:53:03 +10:00
|
|
|
struct list link;
|
|
|
|
|
uint32_t id;
|
|
|
|
|
enum ei_device_state state;
|
|
|
|
|
uint32_t capabilities;
|
2020-08-06 13:58:40 +10:00
|
|
|
char *name;
|
2020-08-18 13:04:01 +10:00
|
|
|
|
2021-07-21 14:52:04 +10:00
|
|
|
struct list regions;
|
2020-08-21 09:08:45 +10:00
|
|
|
|
2021-08-23 11:28:56 +10:00
|
|
|
struct {
|
|
|
|
|
bool x_is_stopped, y_is_stopped;
|
|
|
|
|
bool x_is_cancelled, y_is_cancelled;
|
|
|
|
|
} scroll;
|
|
|
|
|
|
2020-09-28 13:10:20 +10:00
|
|
|
struct ei_keymap *keymap;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct ei_keymap {
|
|
|
|
|
struct object object;
|
|
|
|
|
struct ei_device *device;
|
2021-08-12 14:21:14 +10:00
|
|
|
void *user_data;
|
2020-09-28 13:10:20 +10:00
|
|
|
enum ei_keymap_type type;
|
|
|
|
|
int fd;
|
|
|
|
|
size_t size;
|
|
|
|
|
bool assigned;
|
2020-07-29 11:53:03 +10:00
|
|
|
};
|
|
|
|
|
|
2020-09-22 14:40:43 +10:00
|
|
|
struct ei_touch {
|
|
|
|
|
struct object object;
|
|
|
|
|
struct ei_device *device;
|
|
|
|
|
void *user_data;
|
|
|
|
|
uint32_t tracking_id;
|
|
|
|
|
enum {
|
|
|
|
|
TOUCH_IS_NEW,
|
|
|
|
|
TOUCH_IS_DOWN,
|
|
|
|
|
TOUCH_IS_UP,
|
|
|
|
|
} state;
|
|
|
|
|
|
|
|
|
|
double x, y;
|
|
|
|
|
};
|
|
|
|
|
|
2021-08-23 09:00:29 +10:00
|
|
|
struct ei_xkb_modifiers {
|
|
|
|
|
uint32_t depressed;
|
|
|
|
|
uint32_t latched;
|
|
|
|
|
uint32_t locked;
|
|
|
|
|
uint32_t group;
|
|
|
|
|
};
|
|
|
|
|
|
2020-07-29 11:53:03 +10:00
|
|
|
struct ei_event {
|
2021-08-23 09:17:33 +10:00
|
|
|
struct object object; /* Parent is struct ei */
|
2020-07-29 11:53:03 +10:00
|
|
|
enum ei_event_type type;
|
|
|
|
|
struct list link;
|
2020-09-14 17:16:50 +10:00
|
|
|
struct ei_seat *seat; /* NULL if device is non-NULL */
|
2020-07-29 11:53:03 +10:00
|
|
|
struct ei_device *device;
|
2021-08-23 09:00:29 +10:00
|
|
|
|
2021-08-24 14:49:39 +10:00
|
|
|
union {
|
|
|
|
|
struct ei_xkb_modifiers modifiers;
|
|
|
|
|
struct {
|
|
|
|
|
char *name;
|
|
|
|
|
char *value;
|
|
|
|
|
uint32_t permissions;
|
|
|
|
|
} prop;
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct ei_property {
|
|
|
|
|
struct object object;
|
|
|
|
|
struct list link;
|
|
|
|
|
char *name;
|
|
|
|
|
char *value;
|
|
|
|
|
uint32_t permissions;
|
2020-07-29 11:53:03 +10:00
|
|
|
};
|
|
|
|
|
|
2021-08-24 14:49:39 +10:00
|
|
|
struct ei_property *
|
|
|
|
|
ei_property_unref(struct ei_property *prop);
|
|
|
|
|
|
|
|
|
|
struct ei_property *
|
|
|
|
|
ei_find_property(struct ei *ei, const char *name);
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
ei_property_update(struct ei *ei, const char *name,
|
|
|
|
|
const char *value, uint32_t permissions);
|
|
|
|
|
|
2021-08-23 09:17:33 +10:00
|
|
|
struct ei_event *
|
|
|
|
|
ei_event_new(struct ei *ei);
|
|
|
|
|
|
2022-02-22 14:27:44 +10:00
|
|
|
struct ei_event *
|
|
|
|
|
ei_event_new_for_device(struct ei_device *device);
|
|
|
|
|
|
2021-08-23 09:17:33 +10:00
|
|
|
struct ei_event *
|
|
|
|
|
ei_event_ref(struct ei_event *event);
|
|
|
|
|
|
|
|
|
|
const char *
|
|
|
|
|
ei_event_type_to_string(enum ei_event_type type);
|
|
|
|
|
|
2020-07-29 11:53:03 +10:00
|
|
|
int
|
|
|
|
|
ei_set_connection(struct ei *ei, int fd);
|
|
|
|
|
|
2020-08-11 20:54:01 +10:00
|
|
|
void
|
|
|
|
|
ei_disconnect(struct ei *ei);
|
|
|
|
|
|
2020-09-14 17:16:50 +10:00
|
|
|
struct ei_seat *
|
|
|
|
|
ei_seat_new(struct ei *ei, uint32_t id, const char *name,
|
|
|
|
|
uint32_t capabilities);
|
|
|
|
|
|
|
|
|
|
struct ei_device *
|
|
|
|
|
ei_seat_find_device(struct ei_seat *seat, uint32_t deviceid);
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ei_seat_remove(struct ei_seat *seat);
|
|
|
|
|
|
|
|
|
|
void
|
2020-10-28 15:32:42 +10:00
|
|
|
ei_seat_drop(struct ei_seat *seat);
|
2020-09-14 17:16:50 +10:00
|
|
|
|
2021-08-24 14:49:39 +10:00
|
|
|
int
|
|
|
|
|
ei_send_property(struct ei *ei, const char *name, const char *value, uint32_t permissions);
|
|
|
|
|
|
2020-07-29 11:53:03 +10:00
|
|
|
int
|
2021-07-16 18:17:15 +10:00
|
|
|
ei_send_seat_bind(struct ei_seat *seat, uint32_t capabilities);
|
2020-07-29 11:53:03 +10:00
|
|
|
|
|
|
|
|
int
|
2021-07-16 18:17:15 +10:00
|
|
|
ei_send_seat_unbind(struct ei_seat *seat);
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
ei_send_close_device(struct ei_device *device);
|
2021-08-23 10:50:23 +10:00
|
|
|
|
2021-08-24 09:53:10 +10:00
|
|
|
int
|
|
|
|
|
ei_send_start_emulating(struct ei_device *device);
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
ei_send_stop_emulating(struct ei_device *device);
|
|
|
|
|
|
2021-08-23 10:50:23 +10:00
|
|
|
int
|
|
|
|
|
ei_send_frame(struct ei_device *device);
|
2020-07-29 11:53:03 +10:00
|
|
|
|
2020-09-14 17:16:50 +10:00
|
|
|
void
|
2020-10-26 09:24:43 +10:00
|
|
|
ei_queue_device_removed_event(struct ei_device *device);
|
2020-10-29 14:02:46 +10:00
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ei_insert_device_removed_event(struct ei_device *device);
|
2020-10-26 09:24:43 +10:00
|
|
|
|
2020-10-28 15:32:42 +10:00
|
|
|
void
|
|
|
|
|
ei_queue_seat_removed_event(struct ei_seat *seat);
|
|
|
|
|
|
2021-07-16 18:17:15 +10:00
|
|
|
struct ei_device *
|
|
|
|
|
ei_device_new(struct ei_seat *seat, uint32_t deviceid);
|
|
|
|
|
|
2021-07-21 14:52:04 +10:00
|
|
|
void
|
|
|
|
|
ei_device_add_region(struct ei_device *device, struct ei_region *r);
|
|
|
|
|
|
2021-07-21 14:51:00 +10:00
|
|
|
void
|
|
|
|
|
ei_device_done(struct ei_device *device);
|
|
|
|
|
|
2020-10-26 09:24:43 +10:00
|
|
|
void
|
|
|
|
|
ei_device_removed_by_server(struct ei_device *device);
|
2020-09-14 17:16:50 +10:00
|
|
|
|
2020-07-29 11:53:03 +10:00
|
|
|
int
|
2020-10-02 12:45:25 +10:00
|
|
|
ei_send_pointer_rel(struct ei_device *device,
|
|
|
|
|
double x, double y);
|
2020-07-29 11:53:03 +10:00
|
|
|
|
2020-09-22 13:17:54 +10:00
|
|
|
int
|
2020-10-02 12:45:25 +10:00
|
|
|
ei_send_pointer_abs(struct ei_device *device,
|
|
|
|
|
double x, double y);
|
2020-09-22 13:17:54 +10:00
|
|
|
|
2020-08-03 12:00:31 +10:00
|
|
|
int
|
2020-10-02 12:45:25 +10:00
|
|
|
ei_send_pointer_button(struct ei_device *device,
|
|
|
|
|
uint32_t button, bool is_press);
|
2020-08-03 12:00:31 +10:00
|
|
|
|
2021-07-14 10:00:59 +02:00
|
|
|
int
|
|
|
|
|
ei_send_pointer_scroll(struct ei_device *device,
|
|
|
|
|
double x, double y);
|
2021-08-23 11:28:56 +10:00
|
|
|
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);
|
2021-07-14 10:00:59 +02:00
|
|
|
|
|
|
|
|
int
|
|
|
|
|
ei_send_pointer_scroll_discrete(struct ei_device *device,
|
|
|
|
|
int32_t x, int32_t y);
|
|
|
|
|
|
2020-08-03 12:00:31 +10:00
|
|
|
int
|
2020-10-02 12:45:25 +10:00
|
|
|
ei_send_keyboard_key(struct ei_device *device,
|
|
|
|
|
uint32_t key, bool is_press);
|
2020-08-03 12:00:31 +10:00
|
|
|
|
2020-09-22 14:40:43 +10:00
|
|
|
int
|
2020-10-02 12:45:25 +10:00
|
|
|
ei_send_touch_down(struct ei_device *device, uint32_t tid,
|
2020-09-22 14:40:43 +10:00
|
|
|
double x, double y);
|
|
|
|
|
int
|
2020-10-02 12:45:25 +10:00
|
|
|
ei_send_touch_motion(struct ei_device *device, uint32_t tid,
|
|
|
|
|
double x, double y);
|
2020-09-22 14:40:43 +10:00
|
|
|
int
|
2020-10-02 12:45:25 +10:00
|
|
|
ei_send_touch_up(struct ei_device *device, uint32_t tid);
|
2020-09-22 14:40:43 +10:00
|
|
|
|
2020-07-29 11:53:03 +10:00
|
|
|
void
|
2020-08-10 08:49:22 +10:00
|
|
|
ei_device_added(struct ei_device *device);
|
2020-08-10 19:32:34 +10:00
|
|
|
|
2020-08-19 13:39:32 +10:00
|
|
|
void
|
2021-08-23 08:25:33 +10:00
|
|
|
ei_device_paused(struct ei_device *device);
|
2020-08-19 13:39:32 +10:00
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ei_device_resumed(struct ei_device *device);
|
|
|
|
|
|
2020-09-23 13:36:15 +10:00
|
|
|
void
|
|
|
|
|
ei_device_set_name(struct ei_device *device, const char *name);
|
|
|
|
|
|
2020-09-14 17:16:50 +10:00
|
|
|
void
|
|
|
|
|
ei_device_set_seat(struct ei_device *device, const char *seat);
|
|
|
|
|
|
2020-08-10 19:32:34 +10:00
|
|
|
void
|
|
|
|
|
ei_device_set_capabilities(struct ei_device *device,
|
|
|
|
|
uint32_t capabilities);
|
2020-08-20 11:51:41 +10:00
|
|
|
|
2020-08-21 13:22:38 +10:00
|
|
|
void
|
|
|
|
|
ei_device_set_keymap(struct ei_device *device,
|
|
|
|
|
enum ei_keymap_type type,
|
2020-08-21 16:58:51 +10:00
|
|
|
int keymap_fd,
|
|
|
|
|
size_t size);
|
2020-08-21 13:22:38 +10:00
|
|
|
|
2021-07-21 14:52:04 +10:00
|
|
|
struct ei_region *
|
|
|
|
|
ei_region_new(void);
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ei_region_set_size(struct ei_region *region, uint32_t w, uint32_t h);
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ei_region_set_offset(struct ei_region *region, uint32_t x, uint32_t y);
|
|
|
|
|
|
2021-07-23 10:30:35 +10:00
|
|
|
void
|
|
|
|
|
ei_region_set_physical_scale(struct ei_region *region, double scale);
|
|
|
|
|
|
2021-07-22 11:23:47 +10:00
|
|
|
_printf_(6, 7) void
|
2020-08-20 11:51:41 +10:00
|
|
|
ei_log_msg(struct ei *ei,
|
|
|
|
|
enum ei_log_priority priority,
|
2021-07-22 11:23:47 +10:00
|
|
|
const char *file, int lineno, const char *func,
|
2020-08-20 11:51:41 +10:00
|
|
|
const char *format, ...);
|
|
|
|
|
|
2021-07-22 11:23:47 +10:00
|
|
|
_printf_(6, 0) void
|
2020-08-20 11:51:41 +10:00
|
|
|
ei_log_msg_va(struct ei *ei,
|
|
|
|
|
enum ei_log_priority priority,
|
2021-07-22 11:23:47 +10:00
|
|
|
const char *file, int lineno, const char *func,
|
2020-08-20 11:51:41 +10:00
|
|
|
const char *format,
|
|
|
|
|
va_list args);
|
|
|
|
|
|
|
|
|
|
#define log_debug(T_, ...) \
|
2021-07-22 11:23:47 +10:00
|
|
|
ei_log_msg((T_), EI_LOG_PRIORITY_DEBUG, __FILE__, __LINE__, __func__, __VA_ARGS__)
|
2020-08-20 11:51:41 +10:00
|
|
|
#define log_info(T_, ...) \
|
2021-07-22 11:23:47 +10:00
|
|
|
ei_log_msg((T_), EI_LOG_PRIORITY_INFO, __FILE__, __LINE__, __func__, __VA_ARGS__)
|
2020-08-20 11:51:41 +10:00
|
|
|
#define log_warn(T_, ...) \
|
2021-07-22 11:23:47 +10:00
|
|
|
ei_log_msg((T_), EI_LOG_PRIORITY_WARNING, __FILE__, __LINE__, __func__, __VA_ARGS__)
|
2020-08-20 11:51:41 +10:00
|
|
|
#define log_error(T_, ...) \
|
2021-07-22 11:23:47 +10:00
|
|
|
ei_log_msg((T_), EI_LOG_PRIORITY_ERROR, __FILE__, __LINE__, __func__, __VA_ARGS__)
|
2020-08-20 11:51:41 +10:00
|
|
|
#define log_bug(T_, ...) \
|
2021-07-22 11:23:47 +10:00
|
|
|
ei_log_msg((T_), EI_LOG_PRIORITY_ERROR, __FILE__, __LINE__, __func__, "🪳 libei bug: " __VA_ARGS__)
|
2020-09-29 11:27:57 +10:00
|
|
|
#define log_bug_client(T_, ...) \
|
2021-07-22 11:23:47 +10:00
|
|
|
ei_log_msg((T_), EI_LOG_PRIORITY_ERROR, __FILE__, __LINE__, __func__, "🪲 Bug: " __VA_ARGS__)
|