mirror of
https://gitlab.freedesktop.org/libinput/libei.git
synced 2026-05-01 22:08:00 +02:00
libeis: remove existing devices before disconnecting the client
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
parent
f7a24b2fbd
commit
b840c510bf
3 changed files with 39 additions and 0 deletions
|
|
@ -144,6 +144,17 @@ client_send_accepted(struct eis_client *client, struct eis_device *device)
|
|||
return min(0, xwrite(source_get_fd(client->source), buf, strlen(buf)));
|
||||
}
|
||||
|
||||
static int
|
||||
client_send_removed(struct eis_client *client, struct eis_device *device)
|
||||
{
|
||||
char buf[64];
|
||||
|
||||
if (!xsnprintf(buf, sizeof(buf), "remove %d\n", device->id))
|
||||
return -ENOMEM;
|
||||
|
||||
return min(0, xwrite(source_get_fd(client->source), buf, strlen(buf)));
|
||||
}
|
||||
|
||||
_public_ void
|
||||
eis_client_connect(struct eis_client *client)
|
||||
{
|
||||
|
|
@ -172,6 +183,11 @@ eis_client_disconnect(struct eis_client *client)
|
|||
return;
|
||||
case EIS_CLIENT_STATE_CONNECTING:
|
||||
case EIS_CLIENT_STATE_CONNECTED:
|
||||
{
|
||||
struct eis_device *d, *tmp;
|
||||
list_for_each_safe(d, tmp, &client->devices, link)
|
||||
eis_device_disconnect(d);
|
||||
}
|
||||
eis_queue_disconnect_event(client);
|
||||
/* fallthrough */
|
||||
case EIS_CLIENT_STATE_HELLO:
|
||||
|
|
@ -457,3 +473,12 @@ eis_client_connect_device(struct eis_client *client, struct eis_device *device)
|
|||
{
|
||||
client_send_accepted(client, device);
|
||||
}
|
||||
|
||||
void
|
||||
eis_client_disconnect_device(struct eis_client *client, struct eis_device *device)
|
||||
{
|
||||
client_send_removed(client, device);
|
||||
eis_queue_removed_event(device);
|
||||
list_remove(&device->link);
|
||||
eis_device_unref(device);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -100,3 +100,13 @@ eis_device_connect(struct eis_device *device)
|
|||
device->state = EIS_DEVICE_STATE_ACCEPTED;
|
||||
eis_client_connect_device(eis_device_get_client(device), device);
|
||||
}
|
||||
|
||||
_public_ void
|
||||
eis_device_disconnect(struct eis_device *device)
|
||||
{
|
||||
if (device->state != EIS_DEVICE_STATE_ACCEPTED)
|
||||
return;
|
||||
|
||||
device->state = EIS_DEVICE_STATE_REMOVED;
|
||||
eis_client_disconnect_device(eis_device_get_client(device), device);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,6 +65,7 @@ struct eis_client {
|
|||
enum eis_device_state {
|
||||
EIS_DEVICE_STATE_NEW,
|
||||
EIS_DEVICE_STATE_ACCEPTED,
|
||||
EIS_DEVICE_STATE_REMOVED,
|
||||
};
|
||||
|
||||
struct eis_device {
|
||||
|
|
@ -107,6 +108,9 @@ eis_client_get_context(struct eis_client *client);
|
|||
void
|
||||
eis_client_connect_device(struct eis_client *client,
|
||||
struct eis_device *device);
|
||||
void
|
||||
eis_client_disconnect_device(struct eis_client *client,
|
||||
struct eis_device *device);
|
||||
|
||||
struct eis_device *
|
||||
eis_device_new(struct eis_client *client,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue