From 8a735a3ee6695778c9907f6bd044e9be7db1ef37 Mon Sep 17 00:00:00 2001 From: "Tran Ba Khang(MS/EMC31-XC)" Date: Thu, 8 Dec 2022 13:28:33 +0700 Subject: ivi-input-modules: read default seat name from weston.ini file Currently, the default seat name is "default". On weston 10, the wayland backend is using 'seat0' as the default seat name. This resulted in failing input examples and tests. To avoid this situation in the future, the default seat name should be configured in weston.ini file. Signed-off-by: Tran Ba Khang(MS/EMC31-XC) --- .../src/ivi-input-controller.c | 51 +++++++++++++++++++--- 1 file changed, 46 insertions(+), 5 deletions(-) diff --git a/ivi-input-modules/ivi-input-controller/src/ivi-input-controller.c b/ivi-input-modules/ivi-input-controller/src/ivi-input-controller.c index 82900dc..a3c0ea5 100644 --- a/ivi-input-modules/ivi-input-controller/src/ivi-input-controller.c +++ b/ivi-input-modules/ivi-input-controller/src/ivi-input-controller.c @@ -73,6 +73,8 @@ struct input_context { struct wl_listener surface_destroyed; struct wl_listener compositor_destroy_listener; struct wl_listener seat_create_listener; + + char *seat_default_name; }; enum kbd_events { @@ -997,12 +999,12 @@ handle_seat_create(struct wl_listener *listener, void *data) /* If default seat is created, we have to add it to the accepted_seat_list * of all surfaces. Also we have to send an acceptance event to all clients */ - if (!strcmp(ctx->west_seat->seat_name, "default")) { + if (!strcmp(ctx->west_seat->seat_name, input_ctx->seat_default_name)) { wl_list_for_each(surf, &input_ctx->ivishell->list_surface, link) { add_accepted_seat(surf, ctx); send_input_acceptance(input_ctx, interface->get_id_of_surface(surf->layout_surface), - "default", ILM_TRUE); + input_ctx->seat_default_name, ILM_TRUE); } } } @@ -1049,12 +1051,12 @@ handle_surface_create(struct wl_listener *listener, void *data) wl_list_init(&ivisurface->accepted_seat_list); - seat_ctx = input_ctrl_get_seat_ctx(input_ctx, "default"); + seat_ctx = input_ctrl_get_seat_ctx(input_ctx, input_ctx->seat_default_name); if (seat_ctx) { add_accepted_seat(ivisurface, seat_ctx); send_input_acceptance(input_ctx, interface->get_id_of_surface(ivisurface->layout_surface), - "default", ILM_TRUE); + input_ctx->seat_default_name, ILM_TRUE); } } @@ -1263,6 +1265,10 @@ destroy_input_context(struct input_context *ctx) * free up the controller structure*/ wl_resource_destroy(resource); } + + if (ctx->seat_default_name) { + free(ctx->seat_default_name); + } free(ctx); } @@ -1304,6 +1310,36 @@ input_controller_destroy(struct wl_listener *listener, void *data) } } +static int +get_config( struct input_context *ctx) +{ + int ret = 0; + struct weston_config *config = NULL; + struct weston_config_section *section = NULL; + ctx->seat_default_name = NULL; + + config = wet_get_config(ctx->ivishell->compositor); + if (!config) + goto exit; + + section = weston_config_get_section(config, "ivi-shell", NULL, NULL); + if (!section) + goto exit; + + weston_config_section_get_string(section, + "default-seat", + &ctx->seat_default_name, "default"); +exit: + if (!ctx->seat_default_name) { + ctx->seat_default_name = strdup("default"); + if (!ctx->seat_default_name) { + weston_log("%s: Failed to allocate memory for seat default name\n", __FUNCTION__); + ret = -1; + } + } + + return ret; +} static struct input_context * create_input_context(struct ivishell *shell) @@ -1321,6 +1357,12 @@ create_input_context(struct ivishell *shell) wl_list_init(&ctx->resource_list); wl_list_init(&ctx->seat_list); + /* get the default seat*/ + if (get_config(ctx) != 0) { + free(ctx); + return NULL; + } + /* Add signal handlers for ivi surfaces. */ ctx->surface_created.notify = handle_surface_create; ctx->surface_destroyed.notify = handle_surface_destroy; @@ -1341,7 +1383,6 @@ create_input_context(struct ivishell *shell) return ctx; } - static int input_controller_init(struct ivishell *shell) { -- cgit v1.2.1 From 765e844c296f5db8ecd0b29e539698c82dceaf22 Mon Sep 17 00:00:00 2001 From: "Tran Ba Khang(MS/EMC31-XC)" Date: Mon, 20 Mar 2023 18:00:41 +0700 Subject: ilmInput: support ilm_getDefaultSeat api to return default seat name Sometimes the client need to know the default seat is available or not, or it wants to know which seat is default among multi seats. The seat_create_event should add more an argument for identification of default seat. The ilm_getDefaultSeat is going to query the list of seats to find the default seat name. Signed-off-by: Tran Ba Khang(MS/EMC31-XC) --- .../src/ivi-input-controller.c | 12 ++++++++--- .../ilmControl/include/ilm_control_platform.h | 1 + .../ilmControl/src/ilm_control_wayland_platform.c | 7 ++++--- .../ilmInput/include/ilm_input.h | 12 +++++++++++ ivi-layermanagement-api/ilmInput/src/ilm_input.c | 24 ++++++++++++++++++++++ protocol/ivi-input.xml | 4 +++- 6 files changed, 53 insertions(+), 7 deletions(-) diff --git a/ivi-input-modules/ivi-input-controller/src/ivi-input-controller.c b/ivi-input-modules/ivi-input-controller/src/ivi-input-controller.c index a3c0ea5..661215e 100644 --- a/ivi-input-modules/ivi-input-controller/src/ivi-input-controller.c +++ b/ivi-input-modules/ivi-input-controller/src/ivi-input-controller.c @@ -971,6 +971,7 @@ handle_seat_create(struct wl_listener *listener, void *data) struct ivisurface *surf; const struct ivi_layout_interface *interface = input_ctx->ivishell->interface; + int32_t is_default_seat = ILM_FALSE; struct seat_ctx *ctx = calloc(1, sizeof *ctx); if (ctx == NULL) { weston_log("%s: Failed to allocate memory\n", __FUNCTION__); @@ -991,10 +992,12 @@ handle_seat_create(struct wl_listener *listener, void *data) ctx->updated_caps_listener.notify = &handle_seat_updated_caps; wl_signal_add(&seat->updated_caps_signal, &ctx->updated_caps_listener); + is_default_seat = (strcmp(input_ctx->seat_default_name, seat->seat_name)) + ? ILM_FALSE : ILM_TRUE; wl_resource_for_each(resource, &input_ctx->resource_list) { ivi_input_send_seat_created(resource, seat->seat_name, - get_seat_capabilities(seat)); + get_seat_capabilities(seat), is_default_seat); } /* If default seat is created, we have to add it to the accepted_seat_list @@ -1211,6 +1214,7 @@ bind_ivi_input(struct wl_client *client, void *data, ctx->ivishell->interface; struct seat_focus *st_focus; uint32_t ivi_surf_id; + int32_t is_default_seat = ILM_FALSE; resource = wl_resource_create(client, &ivi_input_interface, 1, id); wl_resource_set_implementation(resource, &input_implementation, @@ -1220,8 +1224,10 @@ bind_ivi_input(struct wl_client *client, void *data, /* Send seat events for all known seats to the client */ wl_list_for_each(seat, &ctx->ivishell->compositor->seat_list, link) { + is_default_seat = (strcmp(ctx->seat_default_name, seat->seat_name)) + ? ILM_FALSE : ILM_TRUE; ivi_input_send_seat_created(resource, seat->seat_name, - get_seat_capabilities(seat)); + get_seat_capabilities(seat), is_default_seat); } /* Send focus and acceptance events for all known surfaces to the client */ wl_list_for_each(ivisurface, &ctx->ivishell->list_surface, link) { @@ -1402,7 +1408,7 @@ input_controller_init(struct ivishell *shell) successful_init_stage++; break; case 1: - if (wl_global_create(shell->compositor->wl_display, &ivi_input_interface, 1, + if (wl_global_create(shell->compositor->wl_display, &ivi_input_interface, 2, ctx, bind_ivi_input) != NULL) { successful_init_stage++; } diff --git a/ivi-layermanagement-api/ilmControl/include/ilm_control_platform.h b/ivi-layermanagement-api/ilmControl/include/ilm_control_platform.h index db672cc..5053b19 100644 --- a/ivi-layermanagement-api/ilmControl/include/ilm_control_platform.h +++ b/ivi-layermanagement-api/ilmControl/include/ilm_control_platform.h @@ -66,6 +66,7 @@ struct ilm_control_context { struct seat_context { struct wl_list link; char *seat_name; + bool is_default; ilmInputDevice capabilities; }; diff --git a/ivi-layermanagement-api/ilmControl/src/ilm_control_wayland_platform.c b/ivi-layermanagement-api/ilmControl/src/ilm_control_wayland_platform.c index b4fdfbf..533c053 100644 --- a/ivi-layermanagement-api/ilmControl/src/ilm_control_wayland_platform.c +++ b/ivi-layermanagement-api/ilmControl/src/ilm_control_wayland_platform.c @@ -754,7 +754,8 @@ static void input_listener_seat_created(void *data, struct ivi_input *ivi_input, const char *name, - uint32_t capabilities) + uint32_t capabilities, + int32_t is_default) { struct wayland_context *ctx = data; struct seat_context *seat; @@ -771,6 +772,7 @@ input_listener_seat_created(void *data, } seat->seat_name = strdup(name); seat->capabilities = capabilities; + seat->is_default = (is_default == ILM_TRUE) ? true : false; wl_list_insert(&ctx->list_seat, &seat->link); } @@ -900,7 +902,6 @@ registry_handle_control(void *data, { struct wayland_context *ctx = data; (void)version; - if (strcmp(interface, "ivi_wm") == 0) { ctx->controller = wl_registry_bind(registry, name, &ivi_wm_interface, 1); @@ -913,7 +914,7 @@ registry_handle_control(void *data, } else if (strcmp(interface, "ivi_input") == 0) { ctx->input_controller = - wl_registry_bind(registry, name, &ivi_input_interface, 1); + wl_registry_bind(registry, name, &ivi_input_interface, 2); if (ctx->input_controller == NULL) { fprintf(stderr, "Failed to registry bind input controller\n"); diff --git a/ivi-layermanagement-api/ilmInput/include/ilm_input.h b/ivi-layermanagement-api/ilmInput/include/ilm_input.h index 7c0008e..fd1fa91 100644 --- a/ivi-layermanagement-api/ilmInput/include/ilm_input.h +++ b/ivi-layermanagement-api/ilmInput/include/ilm_input.h @@ -117,6 +117,18 @@ ilmErrorTypes ilm_getInputFocus(t_ilm_surface **surfaceIDs, ilmInputDevice** bitmasks, t_ilm_uint *num_ids); +/** + * \brief get the name of default seat + * \ingroup ilmControl + * \param[out] seat_name A pointer to the memory where the seat name is + * stored. It is the caller's responsibility to free + * this memory after use. + * \return ILM_SUCCESS if the default seat is available + * \return ILM_FAILED if the default seat isn't available + */ +ilmErrorTypes +ilm_getDefaultSeat(t_ilm_string *seat_name); + #ifdef __cplusplus } /**/ #endif /* __cplusplus */ diff --git a/ivi-layermanagement-api/ilmInput/src/ilm_input.c b/ivi-layermanagement-api/ilmInput/src/ilm_input.c index eae9b61..979bf56 100644 --- a/ivi-layermanagement-api/ilmInput/src/ilm_input.c +++ b/ivi-layermanagement-api/ilmInput/src/ilm_input.c @@ -333,3 +333,27 @@ ilm_getInputFocus(t_ilm_surface **surfaceIDs, ilmInputDevice **bitmasks, return ILM_SUCCESS; } + +ILM_EXPORT ilmErrorTypes +ilm_getDefaultSeat(t_ilm_string *seat_name) +{ + struct ilm_control_context *ctx = NULL; + struct seat_context *seat = NULL; + + if (seat_name == NULL) { + fprintf(stderr, "Invalid Argument\n"); + return ILM_FAILED; + } + + *seat_name = NULL; + ctx = sync_and_acquire_instance(); + wl_list_for_each(seat, &ctx->wl.list_seat, link) { + if (seat->is_default) { + *seat_name = strdup(seat->seat_name); + break; + } + } + + release_instance(); + return (*seat_name) ? ILM_SUCCESS : ILM_FAILED; +} diff --git a/protocol/ivi-input.xml b/protocol/ivi-input.xml index f8ca77e..50eb19d 100644 --- a/protocol/ivi-input.xml +++ b/protocol/ivi-input.xml @@ -21,7 +21,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - + This includes handling the existence of seats, seat capabilities, seat acceptance and input focus. @@ -31,6 +31,8 @@ + + -- cgit v1.2.1 From b986ce06bf7552c3ee5fe8d7ec80531d3e2aa85f Mon Sep 17 00:00:00 2001 From: "Tran Ba Khang(MS/EMC31-XC)" Date: Mon, 3 Apr 2023 10:02:30 +0700 Subject: ilm_input_test: update tests with default seat Currently, tests are using the 'default' as the default seat name. In the case, the default seat name is not the 'default', tests will return a failure. ilm_getDefaultSeat is used to get the default seat name. If it returned ILM_SUCCESS, execute the tests with the seat name got from the API. Otherwise, skip the tests. Signed-off-by: Tran Ba Khang(MS/EMC31-XC) --- ivi-layermanagement-api/test/ilm_input_test.cpp | 26 ++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/ivi-layermanagement-api/test/ilm_input_test.cpp b/ivi-layermanagement-api/test/ilm_input_test.cpp index 032a7e3..2edb301 100644 --- a/ivi-layermanagement-api/test/ilm_input_test.cpp +++ b/ivi-layermanagement-api/test/ilm_input_test.cpp @@ -96,6 +96,13 @@ TEST_F(IlmInputTest, ilm_input_focus) { ilmInputDevice *bitmasks; t_ilm_uint num_ids; t_ilm_uint layer = 0xbeef; + t_ilm_string set_seats = NULL; + + /*ilm_set/get_input_focus test only work if default seat is avaiable*/ + if (ilm_getDefaultSeat(&set_seats) == ILM_FAILED) { + GTEST_SKIP() << "Skipping input focus, there isn't a default seat"; + } + free(set_seats); /* We have to add surfaces to a layer. Otherwise, they would not have a view. We need a view to be able to set pointer focus. */ @@ -120,7 +127,6 @@ TEST_F(IlmInputTest, ilm_input_focus) { /* Can set all focus to keyboard */ ASSERT_EQ(ILM_SUCCESS, ilm_setInputFocus(&surfaces[0], surfaceCount, ILM_INPUT_DEVICE_KEYBOARD, ILM_TRUE)); - ASSERT_EQ(ILM_SUCCESS, ilm_getInputFocus(&surfaceIDs, &bitmasks, &num_ids)); for (unsigned int i = 0; i < num_ids; i++) { /* All surfaces now have keyboard focus */ @@ -174,16 +180,20 @@ TEST_F(IlmInputTest, ilm_input_event_acceptance) { t_ilm_surface surface1 = iviSurfaces[0].surface_id; t_ilm_uint num_seats = 0; t_ilm_string *seats = NULL; - char const *set_seats = "default"; + t_ilm_string set_seats = NULL; t_ilm_uint set_seats_count = 1; + /*ilm_input_event_acceptance test only work if default seat is available*/ + if (ilm_getDefaultSeat(&set_seats) == ILM_FAILED) { + GTEST_SKIP() << "Skipping input event acceptace, there isn't a default seat"; + } /* All seats accept the "default" seat when created */ ASSERT_EQ(ILM_SUCCESS, ilm_getInputAcceptanceOn(surface1, &num_seats, &seats)); EXPECT_EQ(1, num_seats); /* googletest doesn't like comparing to null pointers */ ASSERT_FALSE(seats == NULL); - EXPECT_STREQ("default", seats[0]); + EXPECT_STREQ(set_seats, seats[0]); free(seats[0]); free(seats); @@ -196,12 +206,12 @@ TEST_F(IlmInputTest, ilm_input_event_acceptance) { /* Can add a seat to acceptance */ ASSERT_EQ(ILM_SUCCESS, ilm_setInputAcceptanceOn(surface1, set_seats_count, - (t_ilm_string*)&set_seats)); + &set_seats)); ASSERT_EQ(ILM_SUCCESS, ilm_getInputAcceptanceOn(surface1, &num_seats, &seats)); EXPECT_EQ(set_seats_count, num_seats); bool found = false; - if (!strcmp(*seats, (t_ilm_string)set_seats)) + if (!strcmp(*seats, set_seats)) found = true; EXPECT_EQ(true, found) << set_seats[0] << " not found in returned seats"; @@ -209,7 +219,9 @@ TEST_F(IlmInputTest, ilm_input_event_acceptance) { free(seats); /* Seats can be set, unset, then reset */ - ASSERT_EQ(ILM_SUCCESS, ilm_setInputAcceptanceOn(surface1, 1, (t_ilm_string*)&set_seats)); + ASSERT_EQ(ILM_SUCCESS, ilm_setInputAcceptanceOn(surface1, 1, &set_seats)); ASSERT_EQ(ILM_SUCCESS, ilm_setInputAcceptanceOn(surface1, 0, NULL)); - ASSERT_EQ(ILM_SUCCESS, ilm_setInputAcceptanceOn(surface1, 1, (t_ilm_string*)&set_seats)); + ASSERT_EQ(ILM_SUCCESS, ilm_setInputAcceptanceOn(surface1, 1, &set_seats)); + + free(set_seats); } -- cgit v1.2.1