Add a DeviceAddedDone message to the protocol

Similar to wayland's done message, this signals the end of the device
configuration.

Signed-off-by:	Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer 2021-07-21 14:51:00 +10:00
parent 0578a8cbb6
commit 12b04fdeb0
9 changed files with 82 additions and 6 deletions

View file

@ -181,6 +181,10 @@ message DeviceAdded {
uint32 touch_height = 11;
}
message DeviceAddedDone {
uint32 deviceid = 1;
}
message DeviceRemoved {
uint32 deviceid = 1;
}
@ -200,9 +204,10 @@ message ServerMessage {
SeatAdded seat_added = 4;
SeatRemoved seat_removed = 5;
DeviceAdded device_added = 6;
DeviceRemoved device_removed = 7;
DeviceResumed device_resumed = 8;
DeviceSuspended device_suspended = 9;
DeviceAddedDone device_added_done = 8;
DeviceRemoved device_removed = 9;
DeviceResumed device_resumed = 10;
DeviceSuspended device_suspended = 11;
}
}

View file

@ -37,6 +37,7 @@ static const char *
ei_device_state_to_string(enum ei_device_state state)
{
switch (state) {
CASE_RETURN_STRING(EI_DEVICE_STATE_NEW);
CASE_RETURN_STRING(EI_DEVICE_STATE_SUSPENDED);
CASE_RETURN_STRING(EI_DEVICE_STATE_RESUMED);
CASE_RETURN_STRING(EI_DEVICE_STATE_REMOVED_FROM_CLIENT);
@ -105,7 +106,7 @@ ei_device_new(struct ei_seat *seat, uint32_t deviceid)
device->capabilities = 0;
device->id = deviceid;
device->state = EI_DEVICE_STATE_SUSPENDED;
device->state = EI_DEVICE_STATE_NEW;
device->name = xaprintf("unnamed device %d", device->id);
/* We have a ref to the seat to make sure our seat doesn't get
@ -122,6 +123,12 @@ ei_device_new(struct ei_seat *seat, uint32_t deviceid)
return device;
}
void
ei_device_done(struct ei_device *device)
{
ei_device_set_state(device, EI_DEVICE_STATE_SUSPENDED);
}
_public_
OBJECT_IMPLEMENT_REF(ei_keymap);
_public_
@ -241,6 +248,7 @@ _public_ void
ei_device_close(struct ei_device *device)
{
switch (device->state) {
case EI_DEVICE_STATE_NEW:
case EI_DEVICE_STATE_DEAD:
case EI_DEVICE_STATE_REMOVED_FROM_CLIENT:
case EI_DEVICE_STATE_REMOVED_FROM_SERVER:
@ -259,6 +267,7 @@ ei_device_removed_by_server(struct ei_device *device)
struct ei_seat *seat = ei_device_get_seat(device);
switch (device->state) {
case EI_DEVICE_STATE_NEW:
case EI_DEVICE_STATE_DEAD:
case EI_DEVICE_STATE_REMOVED_FROM_SERVER:
break;

View file

@ -85,6 +85,8 @@ struct ei_seat {
};
enum ei_device_state {
/* Before the DeviceAddedDone was received */
EI_DEVICE_STATE_NEW,
EI_DEVICE_STATE_SUSPENDED,
EI_DEVICE_STATE_RESUMED,
/**
@ -195,6 +197,9 @@ ei_queue_seat_removed_event(struct ei_seat *seat);
struct ei_device *
ei_device_new(struct ei_seat *seat, uint32_t deviceid);
void
ei_device_done(struct ei_device *device);
void
ei_device_removed_by_server(struct ei_device *device);

View file

@ -122,6 +122,15 @@ ei_proto_parse_message(struct brei_message *bmsg, size_t *consumed)
msg->device_added.keymap_fd = brei_message_take_fd(bmsg);
}
break;
case SERVER_MESSAGE__MSG_DEVICE_ADDED_DONE:
{
DeviceAddedDone *d = proto->device_added_done;
*msg = (struct message) {
.type = MESSAGE_DEVICE_ADDED_DONE,
.device_added_done.deviceid = d->deviceid,
};
}
break;
case SERVER_MESSAGE__MSG_DEVICE_REMOVED:
{
DeviceRemoved *r = proto->device_removed;

View file

@ -38,6 +38,7 @@ enum message_type {
MESSAGE_SEAT_ADDED,
MESSAGE_SEAT_REMOVED,
MESSAGE_DEVICE_ADDED,
MESSAGE_DEVICE_ADDED_DONE,
MESSAGE_DEVICE_REMOVED,
MESSAGE_DEVICE_RESUMED,
MESSAGE_DEVICE_SUSPENDED,
@ -52,6 +53,7 @@ message_type_to_string(enum message_type type)
CASE_RETURN_STRING(MESSAGE_SEAT_ADDED);
CASE_RETURN_STRING(MESSAGE_SEAT_REMOVED);
CASE_RETURN_STRING(MESSAGE_DEVICE_ADDED);
CASE_RETURN_STRING(MESSAGE_DEVICE_ADDED_DONE);
CASE_RETURN_STRING(MESSAGE_DEVICE_REMOVED);
CASE_RETURN_STRING(MESSAGE_DEVICE_RESUMED);
CASE_RETURN_STRING(MESSAGE_DEVICE_SUSPENDED);
@ -90,6 +92,9 @@ struct message {
uint32_t touch_width;
uint32_t touch_height;
} device_added;
struct message_device_added_done {
uint32_t deviceid;
} device_added_done;
struct message_device_removed {
uint32_t deviceid;
} device_removed;

View file

@ -565,7 +565,6 @@ handle_msg_device_added(struct ei *ei, uint32_t deviceid,
ei_device_has_capability(device, EI_DEVICE_CAP_TOUCH) ? "t" : "",
ei_seat_get_name(seat));
queue_device_added_event(device);
return 0;
}
@ -581,6 +580,21 @@ ei_insert_device_removed_event(struct ei_device *device)
insert_device_removed_event(device);
}
static int
handle_msg_device_added_done(struct ei *ei, uint32_t deviceid)
{
log_debug(ei, "Done with device %#x\n", deviceid);
struct ei_device *device = ei_find_device(ei, deviceid);
if (!device)
return 0;
queue_device_added_event(device);
ei_device_done(device);
return 0;
}
static int
handle_msg_device_removed(struct ei *ei, uint32_t deviceid)
{
@ -777,6 +791,7 @@ connection_new_handle_msg(struct ei *ei, struct message *msg)
case MESSAGE_SEAT_ADDED:
case MESSAGE_SEAT_REMOVED:
case MESSAGE_DEVICE_ADDED:
case MESSAGE_DEVICE_ADDED_DONE:
case MESSAGE_DEVICE_REMOVED:
case MESSAGE_DEVICE_RESUMED:
case MESSAGE_DEVICE_SUSPENDED:
@ -803,6 +818,7 @@ connection_connecting_handle_msg(struct ei *ei, struct message *msg)
case MESSAGE_SEAT_ADDED:
case MESSAGE_SEAT_REMOVED:
case MESSAGE_DEVICE_ADDED:
case MESSAGE_DEVICE_ADDED_DONE:
case MESSAGE_DEVICE_REMOVED:
case MESSAGE_DEVICE_RESUMED:
case MESSAGE_DEVICE_SUSPENDED:
@ -850,6 +866,9 @@ connection_connected_handle_msg(struct ei *ei, struct message *msg)
msg->device_added.touch_height
);
break;
case MESSAGE_DEVICE_ADDED_DONE:
rc = handle_msg_device_added_done(ei, msg->device_added_done.deviceid);
break;
case MESSAGE_DEVICE_REMOVED:
rc = handle_msg_device_removed(ei, msg->device_removed.deviceid);
break;

View file

@ -100,7 +100,11 @@ client_send_seat_removed(struct eis_client *client, struct eis_seat *seat)
static int
client_send_device_added(struct eis_client *client, struct eis_device *device)
{
return eis_proto_send_device_added(client, device);
int rc = eis_proto_send_device_added(client, device);
if (rc >= 0)
rc = eis_proto_send_device_added_done(client, device);
return rc;
}
static int

View file

@ -66,6 +66,7 @@ log_wire_message(struct eis *eis, const ServerMessage *msg)
MSG_STRING_CASE(SEAT_ADDED);
MSG_STRING_CASE(SEAT_REMOVED);
MSG_STRING_CASE(DEVICE_ADDED);
MSG_STRING_CASE(DEVICE_ADDED_DONE);
MSG_STRING_CASE(DEVICE_REMOVED);
MSG_STRING_CASE(DEVICE_RESUMED);
MSG_STRING_CASE(DEVICE_SUSPENDED);
@ -177,6 +178,7 @@ eis_proto_send_device_added(struct eis_client *client, struct eis_device *device
int fds[2] = {-1, -1};
added.deviceid = device->id;
added.seatid = seat->id;
added.name = device->name;
added.capabilities = device->capabilities;
@ -204,6 +206,20 @@ eis_proto_send_device_added(struct eis_client *client, struct eis_device *device
return eis_proto_send_msg_with_fds(client, &msg, fds);
}
int
eis_proto_send_device_added_done(struct eis_client *client, struct eis_device *device)
{
ServerMessage msg = SERVER_MESSAGE__INIT;
DeviceAddedDone done = DEVICE_ADDED_DONE__INIT;
done.deviceid = device->id;
msg.device_added_done = &done;
msg.msg_case = SERVER_MESSAGE__MSG_DEVICE_ADDED_DONE;
return eis_proto_send_msg(client, &msg);
}
int
eis_proto_send_device_removed(struct eis_client *client, struct eis_device *device)
{

View file

@ -165,6 +165,10 @@ int
eis_proto_send_device_added(struct eis_client *client,
struct eis_device *device);
int
eis_proto_send_device_added_done(struct eis_client *client,
struct eis_device *device);
int
eis_proto_send_device_removed(struct eis_client *client,
struct eis_device *device);