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-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;
|
|
|
|
|
struct list devices;
|
2020-07-30 09:40:16 +10:00
|
|
|
char *name;
|
2020-08-20 11:51:41 +10:00
|
|
|
|
|
|
|
|
struct {
|
|
|
|
|
ei_log_handler handler;
|
|
|
|
|
enum ei_log_priority priority;
|
|
|
|
|
} log;
|
2020-07-29 11:53:03 +10:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum ei_device_state {
|
|
|
|
|
EI_DEVICE_STATE_NEW,
|
2020-08-04 11:08:50 +10:00
|
|
|
EI_DEVICE_STATE_CONNECTING,
|
2020-08-19 13:39:32 +10:00
|
|
|
EI_DEVICE_STATE_SUSPENDED,
|
|
|
|
|
EI_DEVICE_STATE_RESUMED,
|
2020-07-29 11:53:03 +10:00
|
|
|
EI_DEVICE_STATE_REMOVED,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
struct {
|
|
|
|
|
struct dimensions dim;
|
|
|
|
|
} abs;
|
|
|
|
|
|
|
|
|
|
struct {
|
|
|
|
|
struct dimensions dim;
|
|
|
|
|
} touch;
|
2020-08-21 09:08:45 +10:00
|
|
|
|
|
|
|
|
struct {
|
|
|
|
|
enum ei_keymap_source source;
|
|
|
|
|
enum ei_keymap_type type;
|
|
|
|
|
int fd;
|
2020-08-21 16:58:51 +10:00
|
|
|
size_t size;
|
2020-08-21 09:08:45 +10:00
|
|
|
} keymap;
|
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;
|
|
|
|
|
};
|
|
|
|
|
|
2020-07-29 11:53:03 +10:00
|
|
|
struct ei_event {
|
|
|
|
|
struct object object;
|
|
|
|
|
enum ei_event_type type;
|
|
|
|
|
struct list link;
|
|
|
|
|
struct ei_client *client;
|
|
|
|
|
struct ei_device *device;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
ei_set_connection(struct ei *ei, int fd);
|
|
|
|
|
|
2020-08-11 20:54:01 +10:00
|
|
|
void
|
|
|
|
|
ei_disconnect(struct ei *ei);
|
|
|
|
|
|
2020-07-29 11:53:03 +10:00
|
|
|
int
|
|
|
|
|
ei_add_device(struct ei_device *device);
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
ei_remove_device(struct ei_device *device);
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
ei_pointer_rel(struct ei_device *device,
|
2020-08-13 15:03:27 +10:00
|
|
|
double x, double y);
|
2020-07-29 11:53:03 +10:00
|
|
|
|
2020-09-22 13:17:54 +10:00
|
|
|
int
|
|
|
|
|
ei_pointer_abs(struct ei_device *device,
|
|
|
|
|
double x, double y);
|
|
|
|
|
|
2020-08-03 12:00:31 +10:00
|
|
|
int
|
|
|
|
|
ei_pointer_button(struct ei_device *device,
|
|
|
|
|
uint32_t button, bool is_press);
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
ei_keyboard_key(struct ei_device *device,
|
|
|
|
|
uint32_t key, bool is_press);
|
|
|
|
|
|
2020-09-22 14:40:43 +10:00
|
|
|
int
|
|
|
|
|
ei_touch_touch_down(struct ei_device *device, uint32_t tid,
|
|
|
|
|
double x, double y);
|
|
|
|
|
int
|
|
|
|
|
ei_touch_touch_motion(struct ei_device *device, uint32_t tid,
|
|
|
|
|
double x, double y);
|
|
|
|
|
int
|
|
|
|
|
ei_touch_touch_up(struct ei_device *device, uint32_t tid);
|
|
|
|
|
|
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
|
|
|
|
|
ei_device_suspended(struct ei_device *device);
|
|
|
|
|
|
|
|
|
|
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-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
|
|
|
|
2020-08-20 11:51:41 +10:00
|
|
|
void
|
|
|
|
|
ei_log_msg(struct ei *ei,
|
|
|
|
|
enum ei_log_priority priority,
|
|
|
|
|
const char *format, ...);
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ei_log_msg_va(struct ei *ei,
|
|
|
|
|
enum ei_log_priority priority,
|
|
|
|
|
const char *format,
|
|
|
|
|
va_list args);
|
|
|
|
|
|
|
|
|
|
#define log_debug(T_, ...) \
|
|
|
|
|
ei_log_msg((T_), EI_LOG_PRIORITY_DEBUG, __VA_ARGS__)
|
|
|
|
|
#define log_info(T_, ...) \
|
|
|
|
|
ei_log_msg((T_), EI_LOG_PRIORITY_INFO, __VA_ARGS__)
|
|
|
|
|
#define log_warn(T_, ...) \
|
|
|
|
|
ei_log_msg((T_), EI_LOG_PRIORITY_WARNING, __VA_ARGS__)
|
|
|
|
|
#define log_error(T_, ...) \
|
|
|
|
|
ei_log_msg((T_), EI_LOG_PRIORITY_ERROR, __VA_ARGS__)
|
|
|
|
|
#define log_bug(T_, ...) \
|
2020-09-28 16:10:44 +10:00
|
|
|
ei_log_msg((T_), EI_LOG_PRIORITY_ERROR, "🪳 BUG: " __VA_ARGS__)
|