mirror of
https://gitlab.freedesktop.org/libinput/libei.git
synced 2025-12-28 16:40:08 +01:00
ei: abstract the requests into an interface struct too
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
parent
1a38bad756
commit
e3fd50bae7
4 changed files with 100 additions and 110 deletions
|
|
@ -62,6 +62,8 @@ struct ei {
|
|||
ei_log_handler handler;
|
||||
enum ei_log_priority priority;
|
||||
} log;
|
||||
|
||||
const struct ei_proto_requests *requests;
|
||||
};
|
||||
|
||||
enum ei_seat_state {
|
||||
|
|
|
|||
|
|
@ -197,7 +197,7 @@ ei_proto_send_msg_with_fds(struct ei *ei, const ClientMessage *msg, int *fds)
|
|||
return rc;
|
||||
}
|
||||
|
||||
int
|
||||
static int
|
||||
ei_proto_send_connect(struct ei *ei)
|
||||
{
|
||||
ClientMessage msg = CLIENT_MESSAGE__INIT;
|
||||
|
|
@ -210,7 +210,7 @@ ei_proto_send_connect(struct ei *ei)
|
|||
return ei_proto_send_msg(ei, &msg);
|
||||
}
|
||||
|
||||
int
|
||||
static int
|
||||
ei_proto_send_disconnect(struct ei *ei)
|
||||
{
|
||||
ClientMessage msg = CLIENT_MESSAGE__INIT;
|
||||
|
|
@ -222,8 +222,8 @@ ei_proto_send_disconnect(struct ei *ei)
|
|||
return ei_proto_send_msg(ei, &msg);
|
||||
}
|
||||
|
||||
int
|
||||
ei_proto_send_bind_seat(struct ei *ei, struct ei_seat *seat, uint32_t capabilities)
|
||||
static int
|
||||
ei_proto_send_bind_seat(struct ei_seat *seat, uint32_t capabilities)
|
||||
{
|
||||
ClientMessage msg = CLIENT_MESSAGE__INIT;
|
||||
BindSeat bind = BIND_SEAT__INIT;
|
||||
|
|
@ -234,11 +234,11 @@ ei_proto_send_bind_seat(struct ei *ei, struct ei_seat *seat, uint32_t capabiliti
|
|||
msg.bind_seat = &bind;
|
||||
msg.msg_case = CLIENT_MESSAGE__MSG_BIND_SEAT;
|
||||
|
||||
return ei_proto_send_msg(ei, &msg);
|
||||
return ei_proto_send_msg(ei_seat_get_context(seat), &msg);
|
||||
}
|
||||
|
||||
int
|
||||
ei_proto_send_unbind_seat(struct ei *ei, struct ei_seat *seat)
|
||||
static int
|
||||
ei_proto_send_unbind_seat(struct ei_seat *seat)
|
||||
{
|
||||
ClientMessage msg = CLIENT_MESSAGE__INIT;
|
||||
UnbindSeat unbind = UNBIND_SEAT__INIT;
|
||||
|
|
@ -248,11 +248,11 @@ ei_proto_send_unbind_seat(struct ei *ei, struct ei_seat *seat)
|
|||
msg.unbind_seat = &unbind;
|
||||
msg.msg_case = CLIENT_MESSAGE__MSG_UNBIND_SEAT;
|
||||
|
||||
return ei_proto_send_msg(ei, &msg);
|
||||
return ei_proto_send_msg(ei_seat_get_context(seat), &msg);
|
||||
}
|
||||
|
||||
int
|
||||
ei_proto_send_close_device(struct ei *ei, struct ei_device *device)
|
||||
static int
|
||||
ei_proto_send_close_device(struct ei_device *device)
|
||||
{
|
||||
ClientMessage msg = CLIENT_MESSAGE__INIT;
|
||||
CloseDevice close = CLOSE_DEVICE__INIT;
|
||||
|
|
@ -262,12 +262,11 @@ ei_proto_send_close_device(struct ei *ei, struct ei_device *device)
|
|||
msg.close_device = &close;
|
||||
msg.msg_case = CLIENT_MESSAGE__MSG_CLOSE_DEVICE;
|
||||
|
||||
return ei_proto_send_msg(ei, &msg);
|
||||
return ei_proto_send_msg(ei_device_get_context(device), &msg);
|
||||
}
|
||||
|
||||
int
|
||||
ei_proto_send_rel(struct ei *ei, struct ei_device *device,
|
||||
double x, double y)
|
||||
static int
|
||||
ei_proto_send_rel(struct ei_device *device, double x, double y)
|
||||
{
|
||||
ClientMessage msg = CLIENT_MESSAGE__INIT;
|
||||
PointerRelative rel = POINTER_RELATIVE__INIT;
|
||||
|
|
@ -279,12 +278,11 @@ ei_proto_send_rel(struct ei *ei, struct ei_device *device,
|
|||
msg.rel = &rel;
|
||||
msg.msg_case = CLIENT_MESSAGE__MSG_REL;
|
||||
|
||||
return ei_proto_send_msg(ei, &msg);
|
||||
return ei_proto_send_msg(ei_device_get_context(device), &msg);
|
||||
}
|
||||
|
||||
int
|
||||
ei_proto_send_abs(struct ei *ei, struct ei_device *device,
|
||||
double x, double y)
|
||||
static int
|
||||
ei_proto_send_abs(struct ei_device *device, double x, double y)
|
||||
{
|
||||
ClientMessage msg = CLIENT_MESSAGE__INIT;
|
||||
PointerAbsolute abs = POINTER_ABSOLUTE__INIT;
|
||||
|
|
@ -296,12 +294,11 @@ ei_proto_send_abs(struct ei *ei, struct ei_device *device,
|
|||
msg.abs = &abs;
|
||||
msg.msg_case = CLIENT_MESSAGE__MSG_ABS;
|
||||
|
||||
return ei_proto_send_msg(ei, &msg);
|
||||
return ei_proto_send_msg(ei_device_get_context(device), &msg);
|
||||
}
|
||||
|
||||
int
|
||||
ei_proto_send_button(struct ei *ei, struct ei_device *device,
|
||||
uint32_t b, bool is_press)
|
||||
static int
|
||||
ei_proto_send_button(struct ei_device *device, uint32_t b, bool is_press)
|
||||
{
|
||||
ClientMessage msg = CLIENT_MESSAGE__INIT;
|
||||
PointerButton button = POINTER_BUTTON__INIT;
|
||||
|
|
@ -313,11 +310,11 @@ ei_proto_send_button(struct ei *ei, struct ei_device *device,
|
|||
msg.button = &button;
|
||||
msg.msg_case = CLIENT_MESSAGE__MSG_BUTTON;
|
||||
|
||||
return ei_proto_send_msg(ei, &msg);
|
||||
return ei_proto_send_msg(ei_device_get_context(device), &msg);
|
||||
}
|
||||
|
||||
int ei_proto_send_scroll(struct ei *ei, struct ei_device *device,
|
||||
double x, double y)
|
||||
static int
|
||||
ei_proto_send_scroll(struct ei_device *device, double x, double y)
|
||||
{
|
||||
ClientMessage msg = CLIENT_MESSAGE__INIT;
|
||||
Scroll scroll = SCROLL__INIT;
|
||||
|
|
@ -329,11 +326,11 @@ int ei_proto_send_scroll(struct ei *ei, struct ei_device *device,
|
|||
msg.scroll = &scroll;
|
||||
msg.msg_case = CLIENT_MESSAGE__MSG_SCROLL;
|
||||
|
||||
return ei_proto_send_msg(ei, &msg);
|
||||
return ei_proto_send_msg(ei_device_get_context(device), &msg);
|
||||
}
|
||||
|
||||
int ei_proto_send_scroll_discrete(struct ei *ei, struct ei_device *device,
|
||||
int32_t x, int32_t y)
|
||||
static int
|
||||
ei_proto_send_scroll_discrete(struct ei_device *device, int32_t x, int32_t y)
|
||||
{
|
||||
ClientMessage msg = CLIENT_MESSAGE__INIT;
|
||||
ScrollDiscrete disc = SCROLL_DISCRETE__INIT;
|
||||
|
|
@ -345,12 +342,11 @@ int ei_proto_send_scroll_discrete(struct ei *ei, struct ei_device *device,
|
|||
msg.disc = &disc;
|
||||
msg.msg_case = CLIENT_MESSAGE__MSG_DISC;
|
||||
|
||||
return ei_proto_send_msg(ei, &msg);
|
||||
return ei_proto_send_msg(ei_device_get_context(device), &msg);
|
||||
}
|
||||
|
||||
int
|
||||
ei_proto_send_key(struct ei *ei, struct ei_device *device,
|
||||
uint32_t k, bool is_press)
|
||||
static int
|
||||
ei_proto_send_key(struct ei_device *device, uint32_t k, bool is_press)
|
||||
{
|
||||
ClientMessage msg = CLIENT_MESSAGE__INIT;
|
||||
KeyboardKey key = KEYBOARD_KEY__INIT;
|
||||
|
|
@ -362,13 +358,12 @@ ei_proto_send_key(struct ei *ei, struct ei_device *device,
|
|||
msg.key = &key;
|
||||
msg.msg_case = CLIENT_MESSAGE__MSG_KEY;
|
||||
|
||||
return ei_proto_send_msg(ei, &msg);
|
||||
return ei_proto_send_msg(ei_device_get_context(device), &msg);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
ei_proto_send_touch_down(struct ei *ei, struct ei_device *device,
|
||||
uint32_t tid, double x, double y)
|
||||
static int
|
||||
ei_proto_send_touch_down(struct ei_device *device, uint32_t tid, double x, double y)
|
||||
{
|
||||
ClientMessage msg = CLIENT_MESSAGE__INIT;
|
||||
Touch touch = TOUCH__INIT;
|
||||
|
|
@ -383,12 +378,11 @@ ei_proto_send_touch_down(struct ei *ei, struct ei_device *device,
|
|||
msg.touch = &touch;
|
||||
msg.msg_case = CLIENT_MESSAGE__MSG_TOUCH;
|
||||
|
||||
return ei_proto_send_msg(ei, &msg);
|
||||
return ei_proto_send_msg(ei_device_get_context(device), &msg);
|
||||
}
|
||||
|
||||
int
|
||||
ei_proto_send_touch_motion(struct ei *ei, struct ei_device *device,
|
||||
uint32_t tid, double x, double y)
|
||||
static int
|
||||
ei_proto_send_touch_motion(struct ei_device *device, uint32_t tid, double x, double y)
|
||||
{
|
||||
ClientMessage msg = CLIENT_MESSAGE__INIT;
|
||||
Touch touch = TOUCH__INIT;
|
||||
|
|
@ -403,11 +397,11 @@ ei_proto_send_touch_motion(struct ei *ei, struct ei_device *device,
|
|||
msg.touch = &touch;
|
||||
msg.msg_case = CLIENT_MESSAGE__MSG_TOUCH;
|
||||
|
||||
return ei_proto_send_msg(ei, &msg);
|
||||
return ei_proto_send_msg(ei_device_get_context(device), &msg);
|
||||
}
|
||||
|
||||
int
|
||||
ei_proto_send_touch_up(struct ei *ei, struct ei_device *device, uint32_t tid)
|
||||
static int
|
||||
ei_proto_send_touch_up(struct ei_device *device, uint32_t tid)
|
||||
{
|
||||
ClientMessage msg = CLIENT_MESSAGE__INIT;
|
||||
Touch touch = TOUCH__INIT;
|
||||
|
|
@ -420,5 +414,28 @@ ei_proto_send_touch_up(struct ei *ei, struct ei_device *device, uint32_t tid)
|
|||
msg.touch = &touch;
|
||||
msg.msg_case = CLIENT_MESSAGE__MSG_TOUCH;
|
||||
|
||||
return ei_proto_send_msg(ei, &msg);
|
||||
return ei_proto_send_msg(ei_device_get_context(device), &msg);
|
||||
}
|
||||
|
||||
static const struct ei_proto_requests requests = {
|
||||
.connect = ei_proto_send_connect,
|
||||
.disconnect = ei_proto_send_disconnect,
|
||||
.bind_seat = ei_proto_send_bind_seat,
|
||||
.unbind_seat = ei_proto_send_unbind_seat,
|
||||
.close_device = ei_proto_send_close_device,
|
||||
.rel = ei_proto_send_rel,
|
||||
.abs = ei_proto_send_abs,
|
||||
.button = ei_proto_send_button,
|
||||
.scroll = ei_proto_send_scroll,
|
||||
.scroll_discrete = ei_proto_send_scroll_discrete,
|
||||
.key = ei_proto_send_key,
|
||||
.touch_down = ei_proto_send_touch_down,
|
||||
.touch_motion = ei_proto_send_touch_motion,
|
||||
.touch_up = ei_proto_send_touch_up,
|
||||
};
|
||||
|
||||
const struct ei_proto_requests *
|
||||
ei_proto_get_requests(void)
|
||||
{
|
||||
return &requests;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,60 +53,30 @@ struct ei_proto_interface {
|
|||
size_t keymap_size);
|
||||
};
|
||||
|
||||
struct ei_proto_requests {
|
||||
int (*connect)(struct ei *ei);
|
||||
int (*disconnect)(struct ei *ei);
|
||||
int (*bind_seat)(struct ei_seat *seat, uint32_t capabilities);
|
||||
int (*unbind_seat)(struct ei_seat *seat);
|
||||
int (*close_device)(struct ei_device *device);
|
||||
|
||||
int (*rel)(struct ei_device *device, double x, double y);
|
||||
int (*abs)(struct ei_device *device, double x, double y);
|
||||
int (*button)(struct ei_device *device, uint32_t b, bool is_press);
|
||||
int (*key)(struct ei_device *device, uint32_t k, bool is_press);
|
||||
int (*scroll)(struct ei_device *device, double x, double y);
|
||||
int (*scroll_discrete)(struct ei_device *device, int32_t x, int32_t y);
|
||||
int (*touch_down)(struct ei_device *device,
|
||||
uint32_t tid, double x, double y);
|
||||
int (*touch_motion)(struct ei_device *device,
|
||||
uint32_t tid, double x, double y);
|
||||
int (*touch_up)(struct ei_device *device, uint32_t tid);
|
||||
};
|
||||
|
||||
int
|
||||
ei_proto_handle_message(struct ei *ei,
|
||||
const struct ei_proto_interface *interface,
|
||||
struct brei_message *message);
|
||||
|
||||
int
|
||||
ei_proto_send_connect(struct ei *ei);
|
||||
|
||||
int
|
||||
ei_proto_send_disconnect(struct ei *ei);
|
||||
|
||||
int
|
||||
ei_proto_send_add(struct ei *ei, struct ei_device *device);
|
||||
|
||||
int
|
||||
ei_proto_send_bind_seat(struct ei *ei, struct ei_seat *seat, uint32_t capabilities);
|
||||
|
||||
int
|
||||
ei_proto_send_unbind_seat(struct ei *ei, struct ei_seat *seat);
|
||||
|
||||
int
|
||||
ei_proto_send_close_device(struct ei *ei, struct ei_device *device);
|
||||
|
||||
int
|
||||
ei_proto_send_rel(struct ei *ei, struct ei_device *device,
|
||||
double x, double y);
|
||||
|
||||
int
|
||||
ei_proto_send_abs(struct ei *ei, struct ei_device *device,
|
||||
double x, double y);
|
||||
|
||||
int
|
||||
ei_proto_send_button(struct ei *ei, struct ei_device *device,
|
||||
uint32_t b, bool is_press);
|
||||
|
||||
int
|
||||
ei_proto_send_scroll(struct ei *ei, struct ei_device *device,
|
||||
double x, double y);
|
||||
|
||||
int
|
||||
ei_proto_send_scroll_discrete(struct ei *ei, struct ei_device *device,
|
||||
int32_t x, int32_t y);
|
||||
|
||||
int
|
||||
ei_proto_send_key(struct ei *ei, struct ei_device *device,
|
||||
uint32_t k, bool is_press);
|
||||
|
||||
int
|
||||
ei_proto_send_touch_down(struct ei *ei, struct ei_device *device,
|
||||
uint32_t tid, double x, double y);
|
||||
|
||||
int
|
||||
ei_proto_send_touch_motion(struct ei *ei, struct ei_device *device,
|
||||
uint32_t tid, double x, double y);
|
||||
|
||||
int
|
||||
ei_proto_send_touch_up(struct ei *ei, struct ei_device *device, uint32_t tid);
|
||||
const struct ei_proto_requests *
|
||||
ei_proto_get_requests(void);
|
||||
|
|
|
|||
29
src/libei.c
29
src/libei.c
|
|
@ -156,6 +156,7 @@ ei_new(void *user_data)
|
|||
_unref_(ei) *ei = ei_create(NULL);
|
||||
|
||||
ei->state = EI_STATE_NEW;
|
||||
ei->requests = ei_proto_get_requests();
|
||||
list_init(&ei->event_queue);
|
||||
list_init(&ei->seats);
|
||||
|
||||
|
|
@ -322,7 +323,7 @@ connection_send_connect(struct ei *ei)
|
|||
ei->state == EI_STATE_DISCONNECTED)
|
||||
return 0;
|
||||
|
||||
return ei_proto_send_connect(ei);
|
||||
return ei->requests->connect(ei);
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
@ -332,7 +333,7 @@ connection_send_disconnect(struct ei *ei)
|
|||
ei->state == EI_STATE_DISCONNECTED)
|
||||
return 0;
|
||||
|
||||
return ei_proto_send_disconnect(ei);
|
||||
return ei->requests->disconnect(ei);
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
@ -342,7 +343,7 @@ connection_send_bind_seat(struct ei *ei, struct ei_seat *seat, uint32_t capabili
|
|||
ei->state == EI_STATE_DISCONNECTED)
|
||||
return 0;
|
||||
|
||||
return ei_proto_send_bind_seat(ei, seat, capabilities);
|
||||
return ei->requests->bind_seat(seat, capabilities);
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
@ -352,7 +353,7 @@ connection_send_unbind_seat(struct ei *ei, struct ei_seat *seat)
|
|||
ei->state == EI_STATE_DISCONNECTED)
|
||||
return 0;
|
||||
|
||||
return ei_proto_send_unbind_seat(ei, seat);
|
||||
return ei->requests->unbind_seat(seat);
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
@ -362,7 +363,7 @@ connection_send_close_device(struct ei *ei, struct ei_device *device)
|
|||
ei->state == EI_STATE_DISCONNECTED)
|
||||
return 0;
|
||||
|
||||
return ei_proto_send_close_device(ei, device);
|
||||
return ei->requests->close_device(device);
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
@ -373,7 +374,7 @@ connection_send_rel(struct ei *ei, struct ei_device *device,
|
|||
ei->state == EI_STATE_DISCONNECTED)
|
||||
return 0;
|
||||
|
||||
return ei_proto_send_rel(ei, device, x, y);
|
||||
return ei->requests->rel(device, x, y);
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
@ -384,7 +385,7 @@ connection_send_abs(struct ei *ei, struct ei_device *device,
|
|||
ei->state == EI_STATE_DISCONNECTED)
|
||||
return 0;
|
||||
|
||||
return ei_proto_send_abs(ei, device, x, y);
|
||||
return ei->requests->abs(device, x, y);
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
@ -395,7 +396,7 @@ connection_send_button(struct ei *ei, struct ei_device *device,
|
|||
ei->state == EI_STATE_DISCONNECTED)
|
||||
return 0;
|
||||
|
||||
return ei_proto_send_button(ei, device, b, is_press);
|
||||
return ei->requests->button(device, b, is_press);
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
@ -406,7 +407,7 @@ connection_send_scroll(struct ei *ei, struct ei_device *device,
|
|||
ei->state == EI_STATE_DISCONNECTED)
|
||||
return 0;
|
||||
|
||||
return ei_proto_send_scroll(ei, device, x, y);
|
||||
return ei->requests->scroll(device, x, y);
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
@ -417,7 +418,7 @@ connection_send_scroll_discrete(struct ei *ei, struct ei_device *device,
|
|||
ei->state == EI_STATE_DISCONNECTED)
|
||||
return 0;
|
||||
|
||||
return ei_proto_send_scroll_discrete(ei, device, x, y);
|
||||
return ei->requests->scroll_discrete(device, x, y);
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
@ -428,7 +429,7 @@ connection_send_key(struct ei *ei, struct ei_device *device,
|
|||
ei->state == EI_STATE_DISCONNECTED)
|
||||
return 0;
|
||||
|
||||
return ei_proto_send_key(ei, device, k, is_press);
|
||||
return ei->requests->key(device, k, is_press);
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
@ -439,7 +440,7 @@ connection_send_touch_down(struct ei *ei, struct ei_device *device,
|
|||
ei->state == EI_STATE_DISCONNECTED)
|
||||
return 0;
|
||||
|
||||
return ei_proto_send_touch_down(ei, device, tid, x, y);
|
||||
return ei->requests->touch_down(device, tid, x, y);
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
@ -450,7 +451,7 @@ connection_send_touch_motion(struct ei *ei, struct ei_device *device,
|
|||
ei->state == EI_STATE_DISCONNECTED)
|
||||
return 0;
|
||||
|
||||
return ei_proto_send_touch_motion(ei, device, tid, x, y);
|
||||
return ei->requests->touch_motion(device, tid, x, y);
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
@ -460,7 +461,7 @@ connection_send_touch_up(struct ei *ei, struct ei_device *device, uint32_t tid)
|
|||
ei->state == EI_STATE_DISCONNECTED)
|
||||
return 0;
|
||||
|
||||
return ei_proto_send_touch_up(ei, device, tid);
|
||||
return ei->requests->touch_up(device, tid);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue