eis: send out the list of existing properties on connect

Any property that was set by the server or a libreis intermediary before
connect needs to be sent to the client.

Fixes #22
This commit is contained in:
Peter Hutterer 2022-07-28 16:00:23 +10:00
parent b4efd0fa5f
commit 41a106fafc
2 changed files with 73 additions and 0 deletions

View file

@ -192,6 +192,17 @@ client_send_keyboard_modifiers(struct eis_client *client, struct eis_device *dev
return eis->requests->keyboard_modifiers(device, mods);
}
static int
client_send_property(struct eis_client *client, struct eis_property *property)
{
struct eis *eis = eis_client_get_context(client);
if ((property->permissions & EIS_PROPERTY_PERM_READ) == 0)
return 0;
return eis->requests->property(client, property->name, property->value, property->permissions);
}
_public_ void
eis_client_connect(struct eis_client *client)
{
@ -210,6 +221,11 @@ eis_client_connect(struct eis_client *client)
eis_client_disconnect(client);
} else {
client->state = EIS_CLIENT_STATE_CONNECTED;
struct eis_property *prop;
list_for_each(prop, &client->properties, link)
client_send_property(client, prop);
}
}

View file

@ -330,3 +330,60 @@ MUNIT_TEST(eistest_device_ignore_paused_device)
return MUNIT_OK;
}
MUNIT_TEST(eistest_property_list_on_connect)
{
_unref_(peck) *peck = peck_new_context_with_reis(PECK_EI_RECEIVER);
peck_enable_eis_behavior(peck, PECK_EIS_BEHAVIOR_ACCEPT_CLIENT);
peck_enable_ei_behavior(peck, PECK_EI_BEHAVIOR_NONE);
peck_dispatch_until_stable(peck);
with_reis(peck) {
reis_set_property_with_permissions(reis, "testprop.all", "all", REIS_PROPERTY_PERM_ALL);
reis_set_property_with_permissions(reis, "testprop.r", "r", REIS_PROPERTY_PERM_READ);
reis_set_property_with_permissions(reis, "testprop.rw", "rw", REIS_PROPERTY_PERM_READ|REIS_PROPERTY_PERM_WRITE);
reis_set_property_with_permissions(reis, "testprop.w", "w", REIS_PROPERTY_PERM_WRITE);
}
peck_ei_connect(peck);
peck_dispatch_until_stable(peck);
with_client(peck) {
_unref_(ei_event) *connect = peck_ei_next_event(ei, EI_EVENT_CONNECT);
_unref_(ei_event) *prop_all = peck_ei_next_event(ei, EI_EVENT_PROPERTY);
_unref_(ei_event) *prop_r = peck_ei_next_event(ei, EI_EVENT_PROPERTY);
_unref_(ei_event) *prop_rw = peck_ei_next_event(ei, EI_EVENT_PROPERTY);
const char *name, *value;
uint32_t perms;
name = ei_event_property_get_name(prop_all);
value = ei_event_property_get_value(prop_all);
perms = ei_event_property_get_permissions(prop_all);
munit_assert_string_equal(name, "testprop.all");
munit_assert_string_equal(value, "all");
munit_assert_uint32(perms, ==, EI_PROPERTY_PERM_ALL);
name = ei_event_property_get_name(prop_r);
value = ei_event_property_get_value(prop_r);
perms = ei_event_property_get_permissions(prop_r);
munit_assert_string_equal(name, "testprop.r");
munit_assert_string_equal(value, "r");
munit_assert_uint32(perms, ==, EI_PROPERTY_PERM_READ);
name = ei_event_property_get_name(prop_rw);
value = ei_event_property_get_value(prop_rw);
perms = ei_event_property_get_permissions(prop_rw);
munit_assert_string_equal(name, "testprop.rw");
munit_assert_string_equal(value, "rw");
munit_assert_uint32(perms, ==, EI_PROPERTY_PERM_READ|EI_PROPERTY_PERM_WRITE);
peck_assert_no_ei_events(ei);
}
return MUNIT_OK;
}