From d01b499548d5640266bc0d1b8e5bece6c44cebb6 Mon Sep 17 00:00:00 2001 From: Sung-Jin Park Date: Mon, 22 Apr 2019 12:53:10 +0900 Subject: [PATCH 01/16] headless input: fix seat/evdev assignments Change-Id: I98bbc41d0bb177e76985349f282fca09923de027 Signed-off-by: Sung-Jin Park --- src/bin/headless/input.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/bin/headless/input.c b/src/bin/headless/input.c index cb88ec2..5f36a4d 100644 --- a/src/bin/headless/input.c +++ b/src/bin/headless/input.c @@ -212,10 +212,14 @@ input_init(headless_input_t *hi) seat = pepper_compositor_add_seat(hi->compositor, seat_name); PEPPER_CHECK(seat, goto end, "Failed to add seat (%s)!\n", seat_name); + hi->seat = seat; + /* create pepper evdev */ evdev = pepper_evdev_create(hi->compositor); PEPPER_CHECK(evdev, goto end, "Failed to create evdev !\n"); + hi->evdev = evdev; + /* probe evdev keyboard device(s) */ caps |= WL_SEAT_CAPABILITY_KEYBOARD; probed = pepper_evdev_device_probe(evdev, caps); @@ -225,8 +229,6 @@ input_init(headless_input_t *hi) else PEPPER_TRACE("%d evdev device(s) has been probed.\n", probed); - hi->evdev = evdev; - hi->seat = seat; hi->ndevices = probed; return PEPPER_TRUE; -- 2.7.4 From 2936f4a5fd7bef321fa7e20676701425fdf70e60 Mon Sep 17 00:00:00 2001 From: Sung-Jin Park Date: Mon, 22 Apr 2019 19:40:36 +0900 Subject: [PATCH 02/16] keyrouter: add APIs for setting focus/top view Change-Id: I06ed6b0f028fc1bf48d4c510d785f61911d5ace8 Signed-off-by: Sung-Jin Park --- src/lib/keyrouter/pepper-keyrouter.c | 24 ++++++++++++++++++++++++ src/lib/keyrouter/pepper-keyrouter.h | 2 ++ 2 files changed, 26 insertions(+) diff --git a/src/lib/keyrouter/pepper-keyrouter.c b/src/lib/keyrouter/pepper-keyrouter.c index 62bb8ae..664f575 100644 --- a/src/lib/keyrouter/pepper-keyrouter.c +++ b/src/lib/keyrouter/pepper-keyrouter.c @@ -41,6 +41,9 @@ struct pepper_keyrouter { pepper_list_t resources; keyrouter_t *keyrouter; + + pepper_view_t *focus_view; + pepper_view_t *top_view; }; struct resources_data { @@ -73,6 +76,27 @@ pepper_keyrouter_set_keyboard(pepper_keyrouter_t * pepper_keyrouter, pepper_keyb pepper_keyrouter->keyboard = keyboard; } +PEPPER_API void +pepper_keyrouter_set_focus_view(pepper_keyrouter_t *pk, pepper_view_t *focus_view) +{ + PEPPER_CHECK(pk, return, "pepper keyrouter is invalid.\n"); + PEPPER_CHECK(pk->keyboard, return, "No keyboard is available for pepper keyrouter.\n"); + PEPPER_CHECK(focus_view, return, "Given focus_view is invalid.\n"); + + pk->focus_view = focus_view; + PEPPER_TRACE("[%s] focus_view has been set. (focus=0x%p)\n", __FUNCTION__, focus_view); +} + +PEPPER_API void +pepper_keyrouter_set_top_view(pepper_keyrouter_t *pk, pepper_view_t *top_view) +{ + PEPPER_CHECK(pk, return, "pepper keyrouter is invalid.\n"); + PEPPER_CHECK(top_view, return, "Given top_view is invalid.\n"); + + pk->top_view = top_view; + PEPPER_TRACE("[%s] top_view has been set. (top=0x%p)\n", __FUNCTION__, top_view); +} + static void _pepper_keyrouter_key_send(pepper_keyrouter_t *pepper_keyrouter, pepper_seat_t *seat, struct wl_client *client, diff --git a/src/lib/keyrouter/pepper-keyrouter.h b/src/lib/keyrouter/pepper-keyrouter.h index 83ec15a..b037713 100644 --- a/src/lib/keyrouter/pepper-keyrouter.h +++ b/src/lib/keyrouter/pepper-keyrouter.h @@ -30,5 +30,7 @@ PEPPER_API void pepper_keyrouter_destroy(pepper_keyrouter_t *pepper_keyrouter); PEPPER_API void pepper_keyrouter_set_seat(pepper_keyrouter_t *pepper_keyrouter, pepper_seat_t *seat); PEPPER_API void pepper_keyrouter_set_keyboard(pepper_keyrouter_t * pepper_keyrouter, pepper_keyboard_t *keyboard); +PEPPER_API void pepper_keyrouter_set_focus_view(pepper_keyrouter_t *pepper_keyrouter, pepper_view_t *focus_view); +PEPPER_API void pepper_keyrouter_set_top_view(pepper_keyrouter_t *pepper_keyrouter, pepper_view_t *top_view); PEPPER_API void pepper_keyrouter_key_process(pepper_keyrouter_t *pepper_keyrouter, unsigned int key, unsigned int state, unsigned int time); PEPPER_API void pepper_keyrouter_event_handler(pepper_event_listener_t *listener, pepper_object_t *object, uint32_t id, void *info, void *data); -- 2.7.4 From f25c23a7875a5f873a574caea2d93493b1bf0b85 Mon Sep 17 00:00:00 2001 From: Sung-Jin Park Date: Mon, 22 Apr 2019 19:44:06 +0900 Subject: [PATCH 03/16] headless input: add APIs to set focus/top view, add init/deinit (input) modules Change-Id: If5c09e81dda7ff52f9a2cfb43a6a62a06795dd51 Signed-off-by: Sung-Jin Park --- configure.ac | 3 +- src/bin/headless/headless_server.h | 6 +++ src/bin/headless/input.c | 84 +++++++++++++++++++++++++++++++++++++- 3 files changed, 91 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index bb66dac..86491f1 100644 --- a/configure.ac +++ b/configure.ac @@ -309,8 +309,9 @@ AC_SUBST(SAMPLES_LIBS) # headless server HEADLESS_SERVER_REQUIRES="wayland-server capi-system-peripheral-io xdg-shell-unstable-v6-server tizen-extension-server" PKG_CHECK_MODULES(HEADLESS_SERVER, $[HEADLESS_SERVER_REQUIRES]) -HEADLESS_SERVER_CFLAGS="$PEPPER_DIR $PEPPER_EVDEV_DIR $HEADLESS_SERVER_CFLAGS" +HEADLESS_SERVER_CFLAGS="$PEPPER_DIR $PEPPER_KEYROUTER_DIR $PEPPER_EVDEV_DIR $HEADLESS_SERVER_CFLAGS" HEADLESS_SERVER_LIBS="$PEPPER_LIB $PEPPER_LIBS $PEPPER_EVDEV_LIB $PEPPER_EVDEV_LIBS $HEADLESS_SERVER_LIBS" +HEADLESS_SERVER_LIBS="$PEPPER_KEYROUTER_LIB $PEPPER_KEYROUTER_LIBS $HEADLESS_SERVER_LIBS" AC_SUBST(HEADLESS_SERVER_CFLAGS) AC_SUBST(HEADLESS_SERVER_LIBS) diff --git a/src/bin/headless/headless_server.h b/src/bin/headless/headless_server.h index 63b29f4..2fcf4fe 100644 --- a/src/bin/headless/headless_server.h +++ b/src/bin/headless/headless_server.h @@ -34,7 +34,13 @@ PEPPER_API pepper_bool_t pepper_output_led_init(pepper_compositor_t *compositor) PEPPER_API void pepper_output_led_deinit(pepper_compositor_t *compositor); PEPPER_API pepper_bool_t headless_shell_init(pepper_compositor_t *compositor); + +/* APIs for headless_input */ PEPPER_API pepper_bool_t headless_input_init(pepper_compositor_t *compositor); +PEPPER_API void *headless_input_get(void); +PEPPER_API void headless_input_set_focus_view(void *input, pepper_view_t *view); +PEPPER_API void headless_input_set_top_view(void *input, pepper_view_t *view); + #ifdef __cplusplus } #endif diff --git a/src/bin/headless/input.c b/src/bin/headless/input.c index 5f36a4d..27d2fcd 100644 --- a/src/bin/headless/input.c +++ b/src/bin/headless/input.c @@ -22,12 +22,19 @@ */ #include #include +#include typedef struct { pepper_compositor_t *compositor; - pepper_evdev_t *evdev; pepper_seat_t *seat; + pepper_evdev_t *evdev; + pepper_keyboard_t *keyboard; + + pepper_view_t *focus_view; + pepper_view_t *top_view; + + pepper_keyrouter_t *keyrouter; pepper_event_listener_t *listener_seat_keyboard_key; pepper_event_listener_t *listener_seat_keyboard_add; @@ -38,6 +45,7 @@ typedef struct uint32_t ndevices; } headless_input_t; +headless_input_t *input = NULL; const static int KEY_INPUT = 0xdeadbeaf; static void init_event_listeners(headless_input_t *hi); @@ -78,6 +86,7 @@ _handle_seat_keyboard_add(pepper_event_listener_t *listener, pepper_object_t *ob 0, _handle_keyboard_key, hi); PEPPER_CHECK(h, goto end, "Failed to add keyboard key listener.\n"); hi->listener_seat_keyboard_key = h; + hi->keyboard = keyboard; return; @@ -140,6 +149,45 @@ end: deinit_event_listeners(hi); } +void +headless_input_set_focus_view(void *input, pepper_view_t *focus_view) +{ + headless_input_t *hi = (headless_input_t *)input; + + PEPPER_CHECK(hi, return, "Invalid headless input.\n"); + + if (hi->focus_view != focus_view) + { + if (hi->focus_view) + pepper_keyboard_send_leave(hi->keyboard, hi->focus_view); + pepper_keyboard_set_focus(hi->keyboard, focus_view); + pepper_keyboard_send_enter(hi->keyboard, focus_view); + hi->focus_view = focus_view; + } + + if (hi->keyrouter) + pepper_keyrouter_set_focus_view(hi->keyrouter, focus_view); +} + +void +headless_input_set_top_view(void *input, pepper_view_t *top_view) +{ + headless_input_t *hi = (headless_input_t *)input; + + PEPPER_CHECK(hi, return, "Invalid headless input.\n"); + + hi->top_view = top_view; + + if (hi->keyrouter) + pepper_keyrouter_set_top_view(hi->keyrouter, top_view); +} + +headless_input_t * +headless_input_get(void) +{ + return input; +} + static void init_event_listeners(headless_input_t *hi) { @@ -242,6 +290,35 @@ end: } static void +init_modules(headless_input_t *hi) +{ + pepper_keyrouter_t *keyrouter = NULL; + + PEPPER_TRACE("[%s] ... begin\n", __FUNCTION); + + /* create pepper keyrouter */ + keyrouter = pepper_keyrouter_create(hi->compositor); + PEPPER_CHECK(keyrouter, goto end, "Failed to create keyrouter !\n"); + + hi->keyrouter = keyrouter; + + PEPPER_TRACE("[%s] ... done\n", __FUNCTION); + +end: + if (keyrouter) + pepper_keyrouter_destroy(keyrouter); +} + +static void +deinit_modules(headless_input_t *hi) +{ + if (hi->keyrouter) + pepper_keyrouter_destroy(hi->keyrouter); + + hi->keyrouter = NULL; +} + +static void headless_input_deinit(void *data) { headless_input_t *hi = (headless_input_t*)data; @@ -249,10 +326,13 @@ headless_input_deinit(void *data) if (!hi) return; deinit_event_listeners(hi); + deinit_modules(hi); input_deinit(hi); pepper_object_set_user_data((pepper_object_t *)hi->compositor, &KEY_INPUT, NULL, NULL); free(hi); + + input = hi = NULL; } pepper_bool_t @@ -266,9 +346,11 @@ headless_input_init(pepper_compositor_t *compositor) hi->compositor = compositor; init_event_listeners(hi); + init_modules(hi); init = input_init(hi); PEPPER_CHECK(init, goto error, "input_init() failed\n"); + input = hi; pepper_object_set_user_data((pepper_object_t *)compositor, &KEY_INPUT, NULL, headless_input_deinit); return PEPPER_TRUE; -- 2.7.4 From 0c0e1a499dbf94a4eb9d46f07df0b41f9953260c Mon Sep 17 00:00:00 2001 From: Sung-Jin Park Date: Mon, 22 Apr 2019 19:45:19 +0900 Subject: [PATCH 04/16] shell: add temporary setting focus/top view Change-Id: Ib6a07c327e6fc7281b9bcffa95aa46ea523754b7 Signed-off-by: Sung-Jin Park --- src/bin/headless/shell/shell.c | 72 ++++-------------------------------------- 1 file changed, 6 insertions(+), 66 deletions(-) diff --git a/src/bin/headless/shell/shell.c b/src/bin/headless/shell/shell.c index 0ed3581..83a6e6f 100644 --- a/src/bin/headless/shell/shell.c +++ b/src/bin/headless/shell/shell.c @@ -29,15 +29,13 @@ #include #include +#include "headless_server.h" + typedef struct { pepper_compositor_t *compositor; struct wl_global *zxdg_shell; struct wl_global *tizen_policy; - pepper_seat_t *seat; - - pepper_event_listener_t *seat_add_listener; - pepper_event_listener_t *seat_remove_listener; pepper_event_listener_t *surface_add_listener; pepper_event_listener_t *surface_remove_listener; }headless_shell_t; @@ -430,24 +428,6 @@ zxdg_shell_cb_surface_get(struct wl_client *client, struct wl_resource *resource hs_surface->view, psurface); - /* temporary focus view set */ - if (!hs->seat) - return; - - pepper_keyboard_t *keyboard = pepper_seat_get_keyboard(hs->seat); - PEPPER_CHECK(keyboard, return, "[%s] pepper_keyboard is null !", __FUNCTION__); - - pepper_view_t *focus = pepper_keyboard_get_focus(keyboard); - - if (!focus || focus != hs_surface->view) { - if (focus) pepper_keyboard_send_leave(keyboard, focus); - pepper_keyboard_set_focus(keyboard, hs_surface->view); - pepper_keyboard_send_enter(keyboard, hs_surface->view); - } - - /* temporary top view set */ - pepper_view_stack_top(hs_surface->view, PEPPER_FALSE); - return; error: if (hs_surface) { @@ -602,7 +582,10 @@ tizen_policy_cb_activate(struct wl_client *client, struct wl_resource *resource, hs_surface = pepper_object_get_user_data((pepper_object_t *)psurface, surf); PEPPER_CHECK(hs_surface, return, "fail to get headless_shell_surface\n"); - pepper_view_stack_top(hs_surface->view, PEPPER_TRUE); + /* FIXME: set a view of the given surface as the focus/top view */ + void *input = headless_input_get(); + headless_input_set_focus_view(input, hs_surface->view); + headless_input_set_top_view(input, hs_surface->view); } static void @@ -925,39 +908,6 @@ headless_shell_cb_surface_remove(pepper_event_listener_t *listener, } static void -headless_shell_cb_seat_add(pepper_event_listener_t *listener, - pepper_object_t *object, - uint32_t id, - void *info, - void *data) -{ - headless_shell_t *shell = (headless_shell_t *)data; - shell->seat = (pepper_seat_t *)info; - - if (shell->seat) - PEPPER_TRACE("[%s] seat added (name:%s)\n", __FUNCTION__, pepper_seat_get_name(shell->seat)); - else - PEPPER_TRACE("[%s] seat is NULL.\n", __FUNCTION__); -} - -static void -headless_shell_cb_seat_remove(pepper_event_listener_t *listener, - pepper_object_t *object, - uint32_t id, - void *info, - void *data) -{ - headless_shell_t *shell = (headless_shell_t *)data; - - if (shell->seat) - PEPPER_TRACE("[%s] seat removed (name:%s)\n", __FUNCTION__, pepper_seat_get_name(shell->seat)); - else - PEPPER_TRACE("[%s] seat is NULL.\n", __FUNCTION__); - - shell->seat = NULL; -} - -static void headless_shell_init_listeners(headless_shell_t *shell) { shell->surface_add_listener = pepper_object_add_event_listener((pepper_object_t *)shell->compositor, @@ -967,14 +917,6 @@ headless_shell_init_listeners(headless_shell_t *shell) shell->surface_remove_listener = pepper_object_add_event_listener((pepper_object_t *)shell->compositor, PEPPER_EVENT_COMPOSITOR_SURFACE_REMOVE, 0, headless_shell_cb_surface_remove, shell); - - shell->seat_add_listener = pepper_object_add_event_listener((pepper_object_t *)shell->compositor, - PEPPER_EVENT_COMPOSITOR_SEAT_ADD, - 0, headless_shell_cb_seat_add, shell); - - shell->seat_remove_listener = pepper_object_add_event_listener((pepper_object_t *)shell->compositor, - PEPPER_EVENT_COMPOSITOR_SEAT_REMOVE, - 0, headless_shell_cb_seat_remove, shell); } static void @@ -982,8 +924,6 @@ headless_shell_deinit_listeners(headless_shell_t *shell) { pepper_event_listener_remove(shell->surface_add_listener); pepper_event_listener_remove(shell->surface_remove_listener); - pepper_event_listener_remove(shell->seat_add_listener); - pepper_event_listener_remove(shell->seat_remove_listener); } static void -- 2.7.4 From 1cb41a1dfea85ec70b6cc9eb7a80053b4d42d182 Mon Sep 17 00:00:00 2001 From: Sung-Jin Park Date: Mon, 22 Apr 2019 20:14:24 +0900 Subject: [PATCH 05/16] headless input: fix errors Change-Id: I6f50a32b88e3577dc392209e75c1e797f7573a6e Signed-off-by: Sung-Jin Park --- src/bin/headless/input.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bin/headless/input.c b/src/bin/headless/input.c index 27d2fcd..8f5996c 100644 --- a/src/bin/headless/input.c +++ b/src/bin/headless/input.c @@ -294,7 +294,7 @@ init_modules(headless_input_t *hi) { pepper_keyrouter_t *keyrouter = NULL; - PEPPER_TRACE("[%s] ... begin\n", __FUNCTION); + PEPPER_TRACE("[%s] ... begin\n", __FUNCTION__); /* create pepper keyrouter */ keyrouter = pepper_keyrouter_create(hi->compositor); @@ -302,7 +302,7 @@ init_modules(headless_input_t *hi) hi->keyrouter = keyrouter; - PEPPER_TRACE("[%s] ... done\n", __FUNCTION); + PEPPER_TRACE("[%s] ... done\n", __FUNCTION__); end: if (keyrouter) -- 2.7.4 From 1e6eac5ea6abf852a49bcfcbf051ca9185935a08 Mon Sep 17 00:00:00 2001 From: lsj119 Date: Tue, 23 Apr 2019 06:36:04 +0900 Subject: [PATCH 06/16] shell: add skip_focus Change-Id: I8ba78d25f0590f02496210445847de9e2de8f3ef --- src/bin/headless/shell/shell.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/bin/headless/shell/shell.c b/src/bin/headless/shell/shell.c index 83a6e6f..e273f01 100644 --- a/src/bin/headless/shell/shell.c +++ b/src/bin/headless/shell/shell.c @@ -45,6 +45,8 @@ typedef struct { pepper_view_t *view; struct wl_resource *zxdg_shell_surface; uint32_t last_ack_configure; + + pepper_bool_t skip_focus; }headless_shell_surface_t; const static int KEY_SHELL = 0; @@ -611,11 +613,31 @@ tizen_policy_cb_lower_by_res_id(struct wl_client *client, struct wl_resource *re static void tizen_policy_cb_focus_skip_set(struct wl_client *client, struct wl_resource *resource, struct wl_resource *surf) { + pepper_surface_t *psurface; + headless_shell_surface_t *hs_surface; + + psurface = wl_resource_get_user_data(surf); + PEPPER_CHECK(psurface, return, "fail to get pepper_surface_t\n"); + + hs_surface = pepper_object_get_user_data((pepper_object_t *)psurface, surf); + PEPPER_CHECK(hs_surface, return, "fail to get headless_shell_surface\n"); + + hs_surface->skip_focus = PEPPER_TRUE; } static void tizen_policy_cb_focus_skip_unset(struct wl_client *client, struct wl_resource *resource, struct wl_resource *surf) { + pepper_surface_t *psurface; + headless_shell_surface_t *hs_surface; + + psurface = wl_resource_get_user_data(surf); + PEPPER_CHECK(psurface, return, "fail to get pepper_surface_t\n"); + + hs_surface = pepper_object_get_user_data((pepper_object_t *)psurface, surf); + PEPPER_CHECK(hs_surface, return, "fail to get headless_shell_surface\n"); + + hs_surface->skip_focus = PEPPER_FALSE; } static void -- 2.7.4 From 1d6446f364beb03587b03708047aef9b5de73ca4 Mon Sep 17 00:00:00 2001 From: lsj119 Date: Tue, 23 Apr 2019 09:39:31 +0900 Subject: [PATCH 07/16] keyrouter: support the version 2(drift) Change-Id: Ic887cb0ea438f867e0bb212ac32d407e8f5698f6 --- src/lib/keyrouter/pepper-keyrouter.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/lib/keyrouter/pepper-keyrouter.c b/src/lib/keyrouter/pepper-keyrouter.c index 664f575..fd42621 100644 --- a/src/lib/keyrouter/pepper-keyrouter.c +++ b/src/lib/keyrouter/pepper-keyrouter.c @@ -346,6 +346,13 @@ _pepper_keyrouter_cb_set_input_config(struct wl_client *client, tizen_keyrouter_send_set_input_config_notify(resource, (int)PEPPER_FALSE); } +static void +_pepper_keyrouter_cb_destory(struct wl_client *client, + struct wl_resource *resource) +{ + wl_resource_destroy(resource); +} + static const struct tizen_keyrouter_interface _pepper_keyrouter_implementation = { _pepper_keyrouter_cb_keygrab_set, _pepper_keyrouter_cb_keygrab_unset, @@ -355,12 +362,13 @@ static const struct tizen_keyrouter_interface _pepper_keyrouter_implementation = _pepper_keyrouter_cb_get_keygrab_list, _pepper_keyrouter_cb_set_register_none_key, _pepper_keyrouter_cb_get_keyregister_status, - _pepper_keyrouter_cb_set_input_config + _pepper_keyrouter_cb_set_input_config, + _pepper_keyrouter_cb_destory }; /* tizen_keyrouter global object destroy function */ static void -_pepper_keyrouter_cb_destory(struct wl_resource *resource) +_pepper_keyrouter_cb_resource_destory(struct wl_resource *resource) { resources_data_t *rdata, *rtmp; pepper_list_t *list; @@ -400,7 +408,7 @@ _pepper_keyrouter_cb_bind(struct wl_client *client, void *data, uint32_t version PEPPER_CHECK(client, return, "Invalid client\n"); PEPPER_CHECK(pepper_keyrouter, return, "Invalid pepper_keyrouter_t\n"); - resource = wl_resource_create(client, &tizen_keyrouter_interface, MIN(version, 1), id); + resource = wl_resource_create(client, &tizen_keyrouter_interface, MIN(version, 2), id); if (!resource) { PEPPER_ERROR("Failed to create resource ! (version :%d, id:%d)", version, id); wl_client_post_no_memory(client); @@ -423,7 +431,7 @@ _pepper_keyrouter_cb_bind(struct wl_client *client, void *data, uint32_t version wl_resource_set_implementation(resource, &_pepper_keyrouter_implementation, - pepper_keyrouter, _pepper_keyrouter_cb_destory); + pepper_keyrouter, _pepper_keyrouter_cb_resource_destory); } PEPPER_API void @@ -465,7 +473,7 @@ pepper_keyrouter_create(pepper_compositor_t *compositor) pepper_list_init(&pepper_keyrouter->resources); - global = wl_global_create(display, &tizen_keyrouter_interface, 1, pepper_keyrouter, _pepper_keyrouter_cb_bind); + global = wl_global_create(display, &tizen_keyrouter_interface, 2, pepper_keyrouter, _pepper_keyrouter_cb_bind); PEPPER_CHECK(global, goto failed, "Failed to create wl_global for tizen_keyrouter\n"); pepper_keyrouter->keyrouter = keyrouter_create(); -- 2.7.4 From 737c178a8dce9d35493344091939e6bd92c20e57 Mon Sep 17 00:00:00 2001 From: lsj119 Date: Tue, 23 Apr 2019 09:40:29 +0900 Subject: [PATCH 08/16] input: fix the crash Change-Id: I2c0a4323619254041f61cedceb63dda756afa8a2 --- src/bin/headless/input.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bin/headless/input.c b/src/bin/headless/input.c index 8f5996c..fcc16f2 100644 --- a/src/bin/headless/input.c +++ b/src/bin/headless/input.c @@ -304,6 +304,7 @@ init_modules(headless_input_t *hi) PEPPER_TRACE("[%s] ... done\n", __FUNCTION__); + return; end: if (keyrouter) pepper_keyrouter_destroy(keyrouter); -- 2.7.4 From fde2ac2252d738db9751f6a07350f556934b2622 Mon Sep 17 00:00:00 2001 From: Sung-Jin Park Date: Tue, 23 Apr 2019 10:57:25 +0900 Subject: [PATCH 09/16] headless input: rename functions Change-Id: Ifa211b505d4fd97705c4cdca0f9d5e07e0dcbffa Signed-off-by: Sung-Jin Park --- src/bin/headless/input.c | 58 ++++++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/src/bin/headless/input.c b/src/bin/headless/input.c index fcc16f2..f12daf5 100644 --- a/src/bin/headless/input.c +++ b/src/bin/headless/input.c @@ -48,12 +48,12 @@ typedef struct headless_input_t *input = NULL; const static int KEY_INPUT = 0xdeadbeaf; -static void init_event_listeners(headless_input_t *hi); -static void deinit_event_listeners(headless_input_t *hi); +static void headless_input_init_event_listeners(headless_input_t *hi); +static void headless_input_deinit_event_listeners(headless_input_t *hi); /* PEPPER_EVENT_KEYBOARD_KEY handler (must be changed to pepper_keyrouter_event_handler) */ static void -_handle_keyboard_key(pepper_event_listener_t *listener, pepper_object_t *object, uint32_t id, void *info, void *data) +_cb_handle_keyboard_key(pepper_event_listener_t *listener, pepper_object_t *object, uint32_t id, void *info, void *data) { pepper_input_event_t *event; headless_input_t *hi = (headless_input_t *)data; @@ -72,7 +72,7 @@ _handle_keyboard_key(pepper_event_listener_t *listener, pepper_object_t *object, /* seat keyboard add event handler */ static void -_handle_seat_keyboard_add(pepper_event_listener_t *listener, pepper_object_t *object, uint32_t id, void *info, void *data) +_cb_handle_seat_keyboard_add(pepper_event_listener_t *listener, pepper_object_t *object, uint32_t id, void *info, void *data) { pepper_event_listener_t *h = NULL; pepper_keyboard_t *keyboard = (pepper_keyboard_t *)info; @@ -83,7 +83,7 @@ _handle_seat_keyboard_add(pepper_event_listener_t *listener, pepper_object_t *ob pepper_keyboard_set_keymap_info(keyboard, WL_KEYBOARD_KEYMAP_FORMAT_NO_KEYMAP, -1, 0); h = pepper_object_add_event_listener((pepper_object_t *)keyboard, PEPPER_EVENT_KEYBOARD_KEY, - 0, _handle_keyboard_key, hi); + 0, _cb_handle_keyboard_key, hi); PEPPER_CHECK(h, goto end, "Failed to add keyboard key listener.\n"); hi->listener_seat_keyboard_key = h; hi->keyboard = keyboard; @@ -91,12 +91,12 @@ _handle_seat_keyboard_add(pepper_event_listener_t *listener, pepper_object_t *ob return; end: - deinit_event_listeners(hi); + headless_input_deinit_event_listeners(hi); } /* compositor input device add event handler */ static void -_handle_input_device_add(pepper_event_listener_t *listener, pepper_object_t *object, uint32_t id, void *info, void *data) +_cb_handle_input_device_add(pepper_event_listener_t *listener, pepper_object_t *object, uint32_t id, void *info, void *data) { pepper_input_device_t *device = (pepper_input_device_t *)info; headless_input_t *hi = (headless_input_t *)data; @@ -113,7 +113,7 @@ _handle_input_device_add(pepper_event_listener_t *listener, pepper_object_t *obj /* compositor input device remove event handler */ static void -_handle_input_device_remove(pepper_event_listener_t *listener, pepper_object_t *object, uint32_t id, void *info, void *data) +_cb_handle_input_device_remove(pepper_event_listener_t *listener, pepper_object_t *object, uint32_t id, void *info, void *data) { pepper_input_device_t *device = (pepper_input_device_t *)info; headless_input_t *hi = (headless_input_t *)data; @@ -130,7 +130,7 @@ _handle_input_device_remove(pepper_event_listener_t *listener, pepper_object_t * /* seat add event handler */ static void -_handle_seat_add(pepper_event_listener_t *listener, pepper_object_t *object, uint32_t id, void *info, void *data) +_cb_handle_seat_add(pepper_event_listener_t *listener, pepper_object_t *object, uint32_t id, void *info, void *data) { pepper_event_listener_t *h = NULL; pepper_seat_t *seat = (pepper_seat_t *)info; @@ -139,14 +139,14 @@ _handle_seat_add(pepper_event_listener_t *listener, pepper_object_t *object, uin PEPPER_TRACE("[%s] seat added. name:%s\n", __FUNCTION__, pepper_seat_get_name(seat)); h = pepper_object_add_event_listener((pepper_object_t *)seat, PEPPER_EVENT_SEAT_KEYBOARD_ADD, - 0, _handle_seat_keyboard_add, hi); + 0, _cb_handle_seat_keyboard_add, hi); PEPPER_CHECK(h, goto end, "Failed to add seat keyboard add listener.\n"); hi->listener_seat_keyboard_add = h; return; end: - deinit_event_listeners(hi); + headless_input_deinit_event_listeners(hi); } void @@ -189,36 +189,36 @@ headless_input_get(void) } static void -init_event_listeners(headless_input_t *hi) +headless_input_init_event_listeners(headless_input_t *hi) { pepper_event_listener_t *h = NULL; pepper_object_t *compositor = (pepper_object_t *)hi->compositor; /* register event listeners */ h = pepper_object_add_event_listener((pepper_object_t *)compositor, - PEPPER_EVENT_COMPOSITOR_SEAT_ADD, 0, _handle_seat_add, hi); + PEPPER_EVENT_COMPOSITOR_SEAT_ADD, 0, _cb_handle_seat_add, hi); PEPPER_CHECK(h, goto end, "Failed to add seat add listener.\n"); hi->listener_seat_add = h; h = pepper_object_add_event_listener((pepper_object_t *)compositor, - PEPPER_EVENT_COMPOSITOR_INPUT_DEVICE_ADD, 0, _handle_input_device_add, hi); + PEPPER_EVENT_COMPOSITOR_INPUT_DEVICE_ADD, 0, _cb_handle_input_device_add, hi); PEPPER_CHECK(h, goto end, "Failed to add input device add listener.\n"); hi->listener_input_device_add = h; h = pepper_object_add_event_listener((pepper_object_t *)compositor, - PEPPER_EVENT_COMPOSITOR_INPUT_DEVICE_REMOVE, 0, _handle_input_device_remove, hi); + PEPPER_EVENT_COMPOSITOR_INPUT_DEVICE_REMOVE, 0, _cb_handle_input_device_remove, hi); PEPPER_CHECK(h, goto end, "Failed to add input device remove listener.\n"); hi->listener_input_device_remove = h; return; end: - PEPPER_ERROR("Failed to init listeners"); - deinit_event_listeners(hi); + PEPPER_ERROR("[%s] Failed to init listeners", __FUNCTION__); + headless_input_deinit_event_listeners(hi); } static void -deinit_event_listeners(headless_input_t *hi) +headless_input_deinit_event_listeners(headless_input_t *hi) { pepper_event_listener_remove(hi->listener_seat_keyboard_key); pepper_event_listener_remove(hi->listener_seat_keyboard_add); @@ -230,7 +230,7 @@ deinit_event_listeners(headless_input_t *hi) } static void -input_deinit(headless_input_t *hi) +headless_input_deinit_input(headless_input_t *hi) { if (hi->seat) pepper_seat_destroy(hi->seat); @@ -242,7 +242,7 @@ input_deinit(headless_input_t *hi) } static pepper_bool_t -input_init(headless_input_t *hi) +headless_input_init_input(headless_input_t *hi) { uint32_t caps = 0; uint32_t probed = 0; @@ -290,7 +290,7 @@ end: } static void -init_modules(headless_input_t *hi) +headless_input_init_modules(headless_input_t *hi) { pepper_keyrouter_t *keyrouter = NULL; @@ -311,7 +311,7 @@ end: } static void -deinit_modules(headless_input_t *hi) +headless_input_deinit_modules(headless_input_t *hi) { if (hi->keyrouter) pepper_keyrouter_destroy(hi->keyrouter); @@ -326,9 +326,9 @@ headless_input_deinit(void *data) if (!hi) return; - deinit_event_listeners(hi); - deinit_modules(hi); - input_deinit(hi); + headless_input_deinit_event_listeners(hi); + headless_input_deinit_modules(hi); + headless_input_deinit_input(hi); pepper_object_set_user_data((pepper_object_t *)hi->compositor, &KEY_INPUT, NULL, NULL); free(hi); @@ -346,10 +346,10 @@ headless_input_init(pepper_compositor_t *compositor) PEPPER_CHECK(hi, goto error, "Failed to alloc for input\n"); hi->compositor = compositor; - init_event_listeners(hi); - init_modules(hi); - init = input_init(hi); - PEPPER_CHECK(init, goto error, "input_init() failed\n"); + headless_input_init_event_listeners(hi); + headless_input_init_modules(hi); + init = headless_input_init_input(hi); + PEPPER_CHECK(init, goto error, "headless_input_init_input() failed\n"); input = hi; pepper_object_set_user_data((pepper_object_t *)compositor, &KEY_INPUT, NULL, headless_input_deinit); -- 2.7.4 From 6e3246aab029f1b3724b58e6facd9c184888aa76 Mon Sep 17 00:00:00 2001 From: Sung-Jin Park Date: Tue, 23 Apr 2019 11:41:19 +0900 Subject: [PATCH 10/16] headless client: set STDOUT none-buffered Change-Id: Ic3e81db21fd72d0f3d81a88ea7fac74612de8550 Signed-off-by: Sung-Jin Park --- src/samples/headless_client.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/samples/headless_client.c b/src/samples/headless_client.c index a00f990..e6f36fb 100644 --- a/src/samples/headless_client.c +++ b/src/samples/headless_client.c @@ -42,7 +42,7 @@ _cb_focus_in(void *data, int type EINA_UNUSED, void *event) app_data_t *client = (app_data_t *)data; Ecore_Wl2_Event_Focus_In *ev = (Ecore_Wl2_Event_Focus_In *)event; - TRACE(""); + TRACE("\n"); /* TODO */ (void) client; @@ -57,7 +57,7 @@ _cb_focus_out(void *data, int type EINA_UNUSED, void *event) app_data_t *client = (app_data_t *)data; Ecore_Wl2_Event_Focus_Out *ev = (Ecore_Wl2_Event_Focus_Out *)event; - TRACE(""); + TRACE("\n"); /* TODO */ (void) client; @@ -72,7 +72,7 @@ _cb_window_show(void *data, int type EINA_UNUSED, void *event) app_data_t *client = (app_data_t *)data; Ecore_Wl2_Event_Window_Show *ev = (Ecore_Wl2_Event_Window_Show *)event; - TRACE(""); + TRACE("\n"); /* TODO */ (void) client; @@ -87,7 +87,7 @@ _cb_window_lower(void *data, int type EINA_UNUSED, void *event) app_data_t *client = (app_data_t *)data; Ecore_Wl2_Event_Window_Lower *ev = (Ecore_Wl2_Event_Window_Lower *)event; - TRACE(""); + TRACE("\n"); /* TODO */ (void) client; @@ -102,7 +102,7 @@ _cb_window_activate(void *data, int type EINA_UNUSED, void *event) app_data_t *client = (app_data_t *)data; Ecore_Wl2_Event_Window_Activate *ev = (Ecore_Wl2_Event_Window_Activate *)event; - TRACE(""); + TRACE("\n"); /* TODO */ (void) client; @@ -117,7 +117,7 @@ _cb_window_deactivate(void *data, int type EINA_UNUSED, void *event) app_data_t *client = (app_data_t *)data; Ecore_Wl2_Event_Window_Deactivate *ev = (Ecore_Wl2_Event_Window_Deactivate *)event; - TRACE(""); + TRACE("\n"); /* TODO */ (void) client; @@ -132,7 +132,7 @@ _cb_key_down(void *data EINA_UNUSED, int type EINA_UNUSED, void *event) app_data_t *client = (app_data_t *)data; Ecore_Event_Key *ev = event; - TRACE(""); + TRACE("\n"); /* TODO */ (void) client; @@ -147,7 +147,7 @@ _cb_key_up(void *data EINA_UNUSED, int type EINA_UNUSED, void *event) app_data_t *client = (app_data_t *)data; Ecore_Event_Key *ev = event; - TRACE(""); + TRACE("\n"); /* TODO */ (void) client; @@ -192,6 +192,8 @@ int main(int argc, char **argv) int x, y, w, h; app_data_t *client = NULL; + setvbuf(stdout, NULL, _IONBF, 0); + client = (app_data_t *)calloc(1, sizeof(app_data_t)); ERROR_CHECK(client, goto shutdown, "Failed to allocate memory for app_data_t"); -- 2.7.4 From 237f294497dc54db1b42882ca90cad0f742a0e62 Mon Sep 17 00:00:00 2001 From: Sung-Jin Park Date: Tue, 23 Apr 2019 13:42:48 +0900 Subject: [PATCH 11/16] headless input: add pepper-xkb to send a keymap to client(s) : FIXME Change-Id: Icfe859e5f20436cd164c9973285cc4a95ee9b538 Signed-off-by: Sung-Jin Park --- configure.ac | 2 ++ src/bin/headless/input.c | 25 ++++++++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index 86491f1..2044aa3 100644 --- a/configure.ac +++ b/configure.ac @@ -310,8 +310,10 @@ AC_SUBST(SAMPLES_LIBS) HEADLESS_SERVER_REQUIRES="wayland-server capi-system-peripheral-io xdg-shell-unstable-v6-server tizen-extension-server" PKG_CHECK_MODULES(HEADLESS_SERVER, $[HEADLESS_SERVER_REQUIRES]) HEADLESS_SERVER_CFLAGS="$PEPPER_DIR $PEPPER_KEYROUTER_DIR $PEPPER_EVDEV_DIR $HEADLESS_SERVER_CFLAGS" +HEADLESS_SERVER_CFLAGS="$PEPPER_XKB_DIR $HEADLESS_SERVER_CFLAGS" HEADLESS_SERVER_LIBS="$PEPPER_LIB $PEPPER_LIBS $PEPPER_EVDEV_LIB $PEPPER_EVDEV_LIBS $HEADLESS_SERVER_LIBS" HEADLESS_SERVER_LIBS="$PEPPER_KEYROUTER_LIB $PEPPER_KEYROUTER_LIBS $HEADLESS_SERVER_LIBS" +HEADLESS_SERVER_LIBS="$PEPPER_XKB_LIB $PEPPER_XKB_LIBS $HEADLESS_SERVER_LIBS" AC_SUBST(HEADLESS_SERVER_CFLAGS) AC_SUBST(HEADLESS_SERVER_LIBS) diff --git a/src/bin/headless/input.c b/src/bin/headless/input.c index f12daf5..b791fbc 100644 --- a/src/bin/headless/input.c +++ b/src/bin/headless/input.c @@ -23,6 +23,7 @@ #include #include #include +#include typedef struct { @@ -35,6 +36,7 @@ typedef struct pepper_view_t *top_view; pepper_keyrouter_t *keyrouter; + pepper_xkb_t *xkb; pepper_event_listener_t *listener_seat_keyboard_key; pepper_event_listener_t *listener_seat_keyboard_add; @@ -80,7 +82,9 @@ _cb_handle_seat_keyboard_add(pepper_event_listener_t *listener, pepper_object_t PEPPER_TRACE("[%s] keyboard added\n", __FUNCTION__); - pepper_keyboard_set_keymap_info(keyboard, WL_KEYBOARD_KEYMAP_FORMAT_NO_KEYMAP, -1, 0); + /* FIXME: without a keymap, ecore wl2 based client must work properly. */ + //pepper_keyboard_set_keymap_info(keyboard, WL_KEYBOARD_KEYMAP_FORMAT_NO_KEYMAP, -1, 0); + pepper_xkb_keyboard_set_keymap(hi->xkb, keyboard, NULL); h = pepper_object_add_event_listener((pepper_object_t *)keyboard, PEPPER_EVENT_KEYBOARD_KEY, 0, _cb_handle_keyboard_key, hi); @@ -293,9 +297,16 @@ static void headless_input_init_modules(headless_input_t *hi) { pepper_keyrouter_t *keyrouter = NULL; + pepper_xkb_t *xkb = NULL; PEPPER_TRACE("[%s] ... begin\n", __FUNCTION__); + /* create pepper xkb */ + xkb = pepper_xkb_create(); + PEPPER_CHECK(xkb, goto end, "Failed to create pepper_xkb !\n"); + + hi->xkb = xkb; + /* create pepper keyrouter */ keyrouter = pepper_keyrouter_create(hi->compositor); PEPPER_CHECK(keyrouter, goto end, "Failed to create keyrouter !\n"); @@ -306,16 +317,24 @@ headless_input_init_modules(headless_input_t *hi) return; end: - if (keyrouter) - pepper_keyrouter_destroy(keyrouter); + if (hi->xkb) + pepper_xkb_destroy(hi->xkb); + if (hi->keyrouter) + pepper_keyrouter_destroy(hi->keyrouter); + + hi->xkb = NULL; + hi->keyrouter = NULL; } static void headless_input_deinit_modules(headless_input_t *hi) { + if (hi->xkb) + pepper_xkb_destroy(hi->xkb); if (hi->keyrouter) pepper_keyrouter_destroy(hi->keyrouter); + hi->xkb = NULL; hi->keyrouter = NULL; } -- 2.7.4 From 6dc706c571ec4212d3ca5e0c62914c67e1e3382c Mon Sep 17 00:00:00 2001 From: Sung-Jin Park Date: Tue, 23 Apr 2019 16:28:49 +0900 Subject: [PATCH 12/16] headless input: set pepper_keyrouter_event_handler as a keyboard event handler Change-Id: I81116a4d186d1d93c233da7f81481ec06c0c3068 Signed-off-by: Sung-Jin Park --- src/bin/headless/input.c | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/src/bin/headless/input.c b/src/bin/headless/input.c index b791fbc..cc1e811 100644 --- a/src/bin/headless/input.c +++ b/src/bin/headless/input.c @@ -53,25 +53,6 @@ const static int KEY_INPUT = 0xdeadbeaf; static void headless_input_init_event_listeners(headless_input_t *hi); static void headless_input_deinit_event_listeners(headless_input_t *hi); -/* PEPPER_EVENT_KEYBOARD_KEY handler (must be changed to pepper_keyrouter_event_handler) */ -static void -_cb_handle_keyboard_key(pepper_event_listener_t *listener, pepper_object_t *object, uint32_t id, void *info, void *data) -{ - pepper_input_event_t *event; - headless_input_t *hi = (headless_input_t *)data; - pepper_keyboard_t *keyboard = pepper_seat_get_keyboard(hi->seat); - - event = (pepper_input_event_t *)info; - event->key +=8; - - PEPPER_TRACE("[%s] keycode:%d, state=%d\n", __FUNCTION__, event->key, event->state); - - /* send key event to focused client */ - pepper_view_t *focus_view = pepper_keyboard_get_focus(keyboard); - PEPPER_CHECK(focus_view, return, "[%s] No focused view exists.\n", __FUNCTION__); - pepper_keyboard_send_key(keyboard, focus_view, event->time, event->key, event->state); -} - /* seat keyboard add event handler */ static void _cb_handle_seat_keyboard_add(pepper_event_listener_t *listener, pepper_object_t *object, uint32_t id, void *info, void *data) @@ -86,8 +67,9 @@ _cb_handle_seat_keyboard_add(pepper_event_listener_t *listener, pepper_object_t //pepper_keyboard_set_keymap_info(keyboard, WL_KEYBOARD_KEYMAP_FORMAT_NO_KEYMAP, -1, 0); pepper_xkb_keyboard_set_keymap(hi->xkb, keyboard, NULL); + pepper_keyrouter_set_keyboard(hi->keyrouter, keyboard); h = pepper_object_add_event_listener((pepper_object_t *)keyboard, PEPPER_EVENT_KEYBOARD_KEY, - 0, _cb_handle_keyboard_key, hi); + 0, pepper_keyrouter_event_handler, hi->keyrouter); PEPPER_CHECK(h, goto end, "Failed to add keyboard key listener.\n"); hi->listener_seat_keyboard_key = h; hi->keyboard = keyboard; -- 2.7.4 From ac1bfdd628a09f79b4636b1e933836e2be809b3e Mon Sep 17 00:00:00 2001 From: Sung-Jin Park Date: Tue, 23 Apr 2019 16:32:11 +0900 Subject: [PATCH 13/16] keyrouter: set the given keyboard only if there is no keyboard set on keyrouter Change-Id: I78230b4e03e1148d84e2b5344bcf3319b0e3353e Signed-off-by: Sung-Jin Park --- src/lib/keyrouter/pepper-keyrouter.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lib/keyrouter/pepper-keyrouter.c b/src/lib/keyrouter/pepper-keyrouter.c index fd42621..70f3752 100644 --- a/src/lib/keyrouter/pepper-keyrouter.c +++ b/src/lib/keyrouter/pepper-keyrouter.c @@ -450,7 +450,8 @@ pepper_keyrouter_event_handler(pepper_event_listener_t *listener, event = (pepper_input_event_t *)info; pepper_keyrouter = (pepper_keyrouter_t *)data; - pepper_keyrouter_set_keyboard(pepper_keyrouter, keyboard); + if (!pepper_keyrouter->keyboard) + pepper_keyrouter_set_keyboard(pepper_keyrouter, keyboard); pepper_keyrouter_key_process(pepper_keyrouter, event->key, event->state, event->time); } -- 2.7.4 From 138126bed041eda357bc1d3bbf4f9fce72fec898 Mon Sep 17 00:00:00 2001 From: Sung-Jin Park Date: Tue, 23 Apr 2019 19:54:32 +0900 Subject: [PATCH 14/16] keyrouter: send key to focus_view set by pepper_keyboard_set_focus_view API Change-Id: I1f78676737d7364266016950c42e6bd38acb2251 Signed-off-by: Sung-Jin Park --- src/lib/keyrouter/pepper-keyrouter.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/lib/keyrouter/pepper-keyrouter.c b/src/lib/keyrouter/pepper-keyrouter.c index 70f3752..8b17d53 100644 --- a/src/lib/keyrouter/pepper-keyrouter.c +++ b/src/lib/keyrouter/pepper-keyrouter.c @@ -149,10 +149,11 @@ pepper_keyrouter_key_process(pepper_keyrouter_t *pepper_keyrouter, } } else { - /* send key event to focused client */ - pepper_view_t *focus_view = pepper_keyboard_get_focus(pepper_keyrouter->keyboard); - PEPPER_CHECK(focus_view, return , "No focused view exists.\n"); - pepper_keyboard_send_key(pepper_keyrouter->keyboard, focus_view, time, key, state); + /* send key event to focus view if any */ + if (pepper_keyrouter->focus_view) + pepper_keyboard_send_key(pepper_keyrouter->keyboard, pepper_keyrouter->focus_view, time, key, state); + else + PEPPER_TRACE("No focused view exists.\n", __FUNCTION__); } } -- 2.7.4 From 9cf526d1d2f6d9c326224d89e7d422d78b22f702 Mon Sep 17 00:00:00 2001 From: Sung-Jin Park Date: Tue, 23 Apr 2019 20:17:00 +0900 Subject: [PATCH 15/16] keyrouter core: add keyrouter_set_focus/top_client APIs Change-Id: I92449dc34a89bf91382f7b2de40dd1269e9c3784 Signed-off-by: Sung-Jin Park --- src/lib/keyrouter/keyrouter-internal.h | 3 +++ src/lib/keyrouter/keyrouter.c | 25 +++++++++++++++++++++++++ src/lib/keyrouter/keyrouter.h | 3 +++ src/lib/keyrouter/pepper-keyrouter.c | 21 +++++++++++++++++---- 4 files changed, 48 insertions(+), 4 deletions(-) diff --git a/src/lib/keyrouter/keyrouter-internal.h b/src/lib/keyrouter/keyrouter-internal.h index bda57c0..379f0e3 100644 --- a/src/lib/keyrouter/keyrouter-internal.h +++ b/src/lib/keyrouter/keyrouter-internal.h @@ -34,6 +34,9 @@ typedef struct keyrouter_grabbed keyrouter_grabbed_t; struct keyrouter { pepper_compositor_t *compositor; keyrouter_grabbed_t *hard_keys; + + void *focus_client; + void *top_client; }; struct keyrouter_grabbed { diff --git a/src/lib/keyrouter/keyrouter.c b/src/lib/keyrouter/keyrouter.c index 397b836..15cc3bb 100644 --- a/src/lib/keyrouter/keyrouter.c +++ b/src/lib/keyrouter/keyrouter.c @@ -92,6 +92,31 @@ _keyrouter_grabbed_check(keyrouter_t *keyrouter, return res; } +PEPPER_API void +keyrouter_set_focus_client(keyrouter_t *keyrouter, void *focus_client) +{ + PEPPER_CHECK(keyrouter, return, "keyrouter is invalid.\n"); + keyrouter->focus_client = focus_client; + + if (focus_client) + PEPPER_TRACE("[%s] focus client has been set. (focus_client=0x%p)\n", __FUNCTION__, focus_client); + else + PEPPER_TRACE("[%s] focus client has been set to NULL.\n", __FUNCTION__); +} + +PEPPER_API void +keyrouter_set_top_client(keyrouter_t *keyrouter, void *top_client) +{ + PEPPER_CHECK(keyrouter, return, "keyrouter is invalid.\n"); + + keyrouter->top_client = top_client; + + if (top_client) + PEPPER_TRACE("[%s] top client has been set. (top_client=0x%p)\n", __FUNCTION__, top_client); + else + PEPPER_TRACE("[%s] top client has been set to NULL.\n", __FUNCTION__); +} + PEPPER_API int keyrouter_key_process(keyrouter_t *keyrouter, int keycode, int pressed, pepper_list_t *delivery_list) diff --git a/src/lib/keyrouter/keyrouter.h b/src/lib/keyrouter/keyrouter.h index 26cd439..51ba2a8 100644 --- a/src/lib/keyrouter/keyrouter.h +++ b/src/lib/keyrouter/keyrouter.h @@ -46,6 +46,9 @@ PEPPER_API int keyrouter_grab_key(keyrouter_t *keyrouter, int type, int keycode, PEPPER_API void keyrouter_ungrab_key(keyrouter_t *keyrouter, int type, int keycode, void *data); PEPPER_API int keyrouter_key_process(keyrouter_t *keyrouter, int keycode, int pressed, pepper_list_t *delivery_list); +PEPPER_API void keyrouter_set_focus_client(keyrouter_t *keyrouter, void *focus_client); +PEPPER_API void keyrouter_set_top_client(keyrouter_t *keyrouter, void *top_client); + #ifdef __cplusplus } #endif diff --git a/src/lib/keyrouter/pepper-keyrouter.c b/src/lib/keyrouter/pepper-keyrouter.c index 8b17d53..4ad9d69 100644 --- a/src/lib/keyrouter/pepper-keyrouter.c +++ b/src/lib/keyrouter/pepper-keyrouter.c @@ -62,6 +62,21 @@ struct ungrab_list_data { int err; }; +static struct wl_client * +_pepper_keyrouter_get_client_from_view(pepper_view_t *view) +{ + pepper_surface_t *surface = pepper_view_get_surface(view); + PEPPER_CHECK(surface, return NULL, "No surfce available for the given view.\n"); + + struct wl_resource *resource = pepper_surface_get_resource(surface); + + if (resource) + return wl_resource_get_client(resource); + + return NULL; +} + + PEPPER_API void pepper_keyrouter_set_seat(pepper_keyrouter_t *pepper_keyrouter, pepper_seat_t *seat) { @@ -81,20 +96,18 @@ pepper_keyrouter_set_focus_view(pepper_keyrouter_t *pk, pepper_view_t *focus_vie { PEPPER_CHECK(pk, return, "pepper keyrouter is invalid.\n"); PEPPER_CHECK(pk->keyboard, return, "No keyboard is available for pepper keyrouter.\n"); - PEPPER_CHECK(focus_view, return, "Given focus_view is invalid.\n"); pk->focus_view = focus_view; - PEPPER_TRACE("[%s] focus_view has been set. (focus=0x%p)\n", __FUNCTION__, focus_view); + keyrouter_set_focus_client(pk->keyrouter, _pepper_keyrouter_get_client_from_view(focus_view)); } PEPPER_API void pepper_keyrouter_set_top_view(pepper_keyrouter_t *pk, pepper_view_t *top_view) { PEPPER_CHECK(pk, return, "pepper keyrouter is invalid.\n"); - PEPPER_CHECK(top_view, return, "Given top_view is invalid.\n"); pk->top_view = top_view; - PEPPER_TRACE("[%s] top_view has been set. (top=0x%p)\n", __FUNCTION__, top_view); + keyrouter_set_top_client(pk->keyrouter, _pepper_keyrouter_get_client_from_view(top_view)); } static void -- 2.7.4 From b5a10feae9bf34a4e3ac11d7601507f5dbf39003 Mon Sep 17 00:00:00 2001 From: jeon Date: Tue, 23 Apr 2019 21:49:01 +0900 Subject: [PATCH 16/16] pepper-keyrouter: check a privilege using cynara APIs Change-Id: I5c9deb81355a79e0b8cc0ca20ceb97150940e2ad --- configure.ac | 8 ++ packaging/pepper.spec | 3 + src/lib/keyrouter/Makefile.am | 4 +- src/lib/keyrouter/pepper-keyrouter.c | 254 +++++++++++++++++++++++++++++++++-- 4 files changed, 253 insertions(+), 16 deletions(-) diff --git a/configure.ac b/configure.ac index 2044aa3..537b4a3 100644 --- a/configure.ac +++ b/configure.ac @@ -45,6 +45,14 @@ if test "x${have_dlog}" = "xyes"; then fi AM_CONDITIONAL([HAVE_DLOG], [test "x${have_dlog}" = "xyes"]) +PKG_CHECK_MODULES(CYNARA, [cynara-client, cynara-creds-socket, cynara-session, libsmack], + [have_cynara="yes"], [have_cynara="no"]) +if test "x${have_cynara}" = "xyes"; then + AC_DEFINE([HAVE_CYNARA], [1], [Define to 1 if you have cynara]) + PEPPER_REQUIRES="$PEPPER_REQUIRES cynara-client cynara-creds-socket cynara-session libsmack" +fi +AM_CONDITIONAL([HAVE_CYNARA], [test "x${have_cynara}" = "xyes"]) + PEPPER_DIR="-I\$(top_srcdir)/src/lib/pepper" PEPPER_LIB="\$(top_srcdir)/src/lib/pepper/libpepper.la" diff --git a/packaging/pepper.spec b/packaging/pepper.spec index f580fef..9df7ca0 100644 --- a/packaging/pepper.spec +++ b/packaging/pepper.spec @@ -41,6 +41,9 @@ BuildRequires: pkgconfig(capi-system-peripheral-io) BuildRequires: pkgconfig(xdg-shell-unstable-v6-server) BuildRequires: pkgconfig(tizen-extension-server) %endif +BuildRequires: pkgconfig(cynara-client) +BuildRequires: pkgconfig(cynara-creds-socket) +BuildRequires: pkgconfig(libsmack) %description Pepper is a lightweight and flexible library for developing various types of wayland compositors. diff --git a/src/lib/keyrouter/Makefile.am b/src/lib/keyrouter/Makefile.am index fe36aff..4920e1c 100644 --- a/src/lib/keyrouter/Makefile.am +++ b/src/lib/keyrouter/Makefile.am @@ -5,8 +5,8 @@ AM_CFLAGS = $(GCC_CFLAGS) libpepper_keyrouter_includedir=$(includedir)/pepper libpepper_keyrouter_include_HEADERS = keyrouter.h pepper-keyrouter.h -libpepper_keyrouter_la_CFLAGS = $(AM_CFLAGS) $(PEPPER_KEYROUTER_CFLAGS) -libpepper_keyrouter_la_LIBADD = $(PEPPER_KEYROUTER_LIBS) +libpepper_keyrouter_la_CFLAGS = $(AM_CFLAGS) $(PEPPER_KEYROUTER_CFLAGS) $(CYNARA_CFLAGS) +libpepper_keyrouter_la_LIBADD = $(PEPPER_KEYROUTER_LIBS) $(CYNARA_LIBS) libpepper_keyrouter_la_SOURCES = keyrouter-internal.h \ keyrouter.c \ diff --git a/src/lib/keyrouter/pepper-keyrouter.c b/src/lib/keyrouter/pepper-keyrouter.c index 4ad9d69..53c2669 100644 --- a/src/lib/keyrouter/pepper-keyrouter.c +++ b/src/lib/keyrouter/pepper-keyrouter.c @@ -24,10 +24,19 @@ #include "pepper-keyrouter.h" #include "pepper-internal.h" #include +#ifdef HAVE_CYNARA +#include +#include +#include +#include +#include +#include +#endif #define MIN(a,b) ((a)<(b)?(a):(b)) typedef struct resources_data resources_data_t; +typedef struct clients_data clients_data_t; typedef struct grab_list_data grab_list_data_t; typedef struct ungrab_list_data ungrab_list_data_t; @@ -39,11 +48,15 @@ struct pepper_keyrouter { pepper_keyboard_t *keyboard; pepper_list_t resources; + pepper_list_t grabbed_clients; keyrouter_t *keyrouter; pepper_view_t *focus_view; pepper_view_t *top_view; +#ifdef HAVE_CYNARA + cynara *p_cynara; +#endif }; struct resources_data { @@ -51,6 +64,11 @@ struct resources_data { pepper_list_t link; }; +struct clients_data { + struct wl_client *client; + pepper_list_t link; +}; + struct grab_list_data { int key; int mode; @@ -62,6 +80,124 @@ struct ungrab_list_data { int err; }; +#ifdef HAVE_CYNARA +static void +_pepper_keyrouter_util_cynara_log(int err, const char *fmt, ...) +{ +#define CYNARA_BUFSIZE 128 + char buf[CYNARA_BUFSIZE] = "\0", tmp[CYNARA_BUFSIZE + CYNARA_BUFSIZE] = "\0"; + va_list args; + int ret; + + if (fmt) { + va_start(args, fmt); + vsnprintf(tmp, CYNARA_BUFSIZE + CYNARA_BUFSIZE, fmt, args); + va_end(args); + } + + ret = cynara_strerror(err, buf, CYNARA_BUFSIZE); + if (ret != CYNARA_API_SUCCESS) { + PEPPER_ERROR("Failed to cynara_strerror: %d (error log about %s: %d)\n", ret, tmp, err); + return; + } + + PEPPER_ERROR("%s is failed: %s\n", tmp, buf); +} +#endif + +static pepper_bool_t +_pepper_keyrouter_util_cynara_init(pepper_keyrouter_t *pepper_keyrouter) +{ +#ifdef HAVE_CYNARA + int ret; + if (pepper_keyrouter->p_cynara) return PEPPER_TRUE; + + ret = cynara_initialize(&pepper_keyrouter->p_cynara, NULL); + if (CYNARA_API_SUCCESS != ret) { + _pepper_keyrouter_util_cynara_log(ret, "cynara_initialize"); + return PEPPER_FALSE; + } +#endif + return PEPPER_TRUE; +} + +static void +_pepper_keyrouter_util_cynara_deinit(pepper_keyrouter_t *pepper_keyrouter) +{ +#ifdef HAVE_CYNARA + if (pepper_keyrouter->p_cynara) cynara_finish(pepper_keyrouter->p_cynara); +#else + ; +#endif +} + +static pepper_bool_t +_pepper_keyrouter_util_do_privilege_check(pepper_keyrouter_t *pepper_keyrouter, struct wl_client *client, uint32_t mode, uint32_t keycode) +{ + pepper_bool_t res = PEPPER_TRUE; +#ifdef HAVE_CYNARA + int ret, retry_cnt = 0, len = 0; + char *clientSmack = NULL, *client_session = NULL, uid2[16]={0, }; + clients_data_t *cdata; + static pepper_bool_t retried = PEPPER_FALSE; + pid_t pid = 0; + uid_t uid = 0; + gid_t gid = 0; + + res = PEPPER_FALSE; + + /* Top position grab is always allowed. This mode do not need privilege.*/ + if (mode == TIZEN_KEYROUTER_MODE_TOPMOST) return PEPPER_TRUE; + if (!client) return PEPPER_FALSE; + + /* If initialize cynara is failed, allow keygrabs regardless of the previlege permition. */ + if (pepper_keyrouter->p_cynara == NULL) { + if (retried == PEPPER_FALSE) { + retried = PEPPER_TRUE; + for(retry_cnt = 0; retry_cnt < 5; retry_cnt++) { + PEPPER_TRACE("Retry cynara initialize: %d\n", retry_cnt + 1); + + ret = cynara_initialize(&pepper_keyrouter->p_cynara, NULL); + if (CYNARA_API_SUCCESS != ret) { + _pepper_keyrouter_util_cynara_log(ret, "cynara_initialize retry.."); + pepper_keyrouter->p_cynara = NULL; + } else { + PEPPER_TRACE("Success cynara initialize to try %d times\n", retry_cnt + 1); + break; + } + } + } + if (!pepper_keyrouter->p_cynara) return PEPPER_TRUE; + } + + pepper_list_for_each(cdata, &pepper_keyrouter->grabbed_clients, link) { + if (cdata->client == client) return PEPPER_TRUE; + } + + wl_client_get_credentials(client, &pid, &uid, &gid); + + len = smack_new_label_from_process((int)pid, &clientSmack); + if (len <= 0) goto finish; + + snprintf(uid2, 15, "%d", (int)uid); + client_session = cynara_session_from_pid(pid); + + ret = cynara_check(pepper_keyrouter->p_cynara, clientSmack, client_session, uid2, "http://tizen.org/privilege/keygrab"); + if (CYNARA_API_ACCESS_ALLOWED == ret) { + res = PEPPER_TRUE; + PEPPER_TRACE("Success to check cynara, clientSmack: %s client_session: %s, uid2: %s\n", clientSmack, client_session, uid2); + } else { + //PEPPER_TRACE("Fail to check cynara, error : %d (pid : %d)", ret, pid); + _pepper_keyrouter_util_cynara_log(ret, "clientsmack: %s, pid: %d", clientSmack, pid); + } + +finish: + if (client_session) free(client_session); + if (clientSmack) free(clientSmack); +#endif + return res; +} + static struct wl_client * _pepper_keyrouter_get_client_from_view(pepper_view_t *view) { @@ -190,6 +326,29 @@ _pepper_keyrouter_remove_client_from_list(pepper_keyrouter_t *pepper_keyrouter, } } +static int +_pepper_keyrouter_add_client_to_list(pepper_keyrouter_t *pepper_keyrouter, struct wl_client *client) +{ + clients_data_t *cdata; + + pepper_list_for_each(cdata, &pepper_keyrouter->grabbed_clients, link) { + if (cdata->client == client) return TIZEN_KEYROUTER_ERROR_NONE; + } + + cdata = (clients_data_t *)calloc(1, sizeof(clients_data_t)); + if (!cdata) + { + PEPPER_ERROR("Failed to allocate memory !\n"); + return TIZEN_KEYROUTER_ERROR_NO_SYSTEM_RESOURCES; + } + + cdata->client = client; + pepper_list_init(&cdata->link); + pepper_list_insert(&pepper_keyrouter->grabbed_clients, &cdata->link); + + return TIZEN_KEYROUTER_ERROR_NONE; +} + static void _pepper_keyrouter_cb_keygrab_set(struct wl_client *client, struct wl_resource *resource, @@ -199,12 +358,22 @@ _pepper_keyrouter_cb_keygrab_set(struct wl_client *client, { int res = TIZEN_KEYROUTER_ERROR_NONE; pepper_keyrouter_t *pepper_keyrouter = NULL; + pepper_bool_t ret; pepper_keyrouter = (pepper_keyrouter_t *)wl_resource_get_user_data(resource); PEPPER_CHECK(pepper_keyrouter, goto notify, "Invalid pepper_keyrouter_t\n"); + ret = _pepper_keyrouter_util_do_privilege_check(pepper_keyrouter, client, mode, key); + if (!ret) { + res = TIZEN_KEYROUTER_ERROR_NO_PERMISSION; + goto notify; + } + res = keyrouter_grab_key(pepper_keyrouter->keyrouter, mode, key, (void *)client); + if (res == TIZEN_KEYROUTER_ERROR_NONE) + res = _pepper_keyrouter_add_client_to_list(pepper_keyrouter, client); + notify: tizen_keyrouter_send_keygrab_notify(resource, surface, key, mode, res); } @@ -215,11 +384,24 @@ _pepper_keyrouter_cb_keygrab_unset(struct wl_client *client, struct wl_resource *surface, uint32_t key) { + int res = TIZEN_KEYROUTER_ERROR_NONE; pepper_keyrouter_t *pepper_keyrouter = NULL; + pepper_bool_t ret; pepper_keyrouter = (pepper_keyrouter_t *)wl_resource_get_user_data(resource); PEPPER_CHECK(pepper_keyrouter, goto notify, "Invalid pepper_keyrouter_t\n"); + /* ungrab TOP POSITION grab first, this grab mode is not check privilege */ + keyrouter_ungrab_key(pepper_keyrouter->keyrouter, + TIZEN_KEYROUTER_MODE_TOPMOST, + key, (void *)client); + + ret = _pepper_keyrouter_util_do_privilege_check(pepper_keyrouter, client, TIZEN_KEYROUTER_MODE_NONE, key); + if (!ret) { + res = TIZEN_KEYROUTER_ERROR_NO_PERMISSION; + goto notify; + } + keyrouter_ungrab_key(pepper_keyrouter->keyrouter, TIZEN_KEYROUTER_MODE_EXCLUSIVE, key, (void *)client); @@ -234,7 +416,7 @@ _pepper_keyrouter_cb_keygrab_unset(struct wl_client *client, key, (void *)client); notify: - tizen_keyrouter_send_keygrab_notify(resource, surface, key, TIZEN_KEYROUTER_MODE_NONE, TIZEN_KEYROUTER_ERROR_NONE); + tizen_keyrouter_send_keygrab_notify(resource, surface, key, TIZEN_KEYROUTER_MODE_NONE, res); } static void @@ -269,6 +451,7 @@ _pepper_keyrouter_cb_keygrab_set_list(struct wl_client *client, grab_list_data_t *grab_data = NULL; int res = TIZEN_KEYROUTER_ERROR_NONE; pepper_keyrouter_t *pepper_keyrouter = NULL; + pepper_bool_t ret; pepper_keyrouter = (pepper_keyrouter_t *)wl_resource_get_user_data(resource); @@ -278,8 +461,15 @@ _pepper_keyrouter_cb_keygrab_set_list(struct wl_client *client, "Invalid keycode and grab mode pair. Check arguments in a list\n"); wl_array_for_each(grab_data, grab_list) { - res = keyrouter_grab_key(pepper_keyrouter->keyrouter, grab_data->mode, grab_data->key, (void *)client); - grab_data->err = res; + ret = _pepper_keyrouter_util_do_privilege_check(pepper_keyrouter, client, grab_data->mode, grab_data->key); + if (!ret) { + grab_data->err = TIZEN_KEYROUTER_ERROR_NO_PERMISSION; + } else { + res = keyrouter_grab_key(pepper_keyrouter->keyrouter, grab_data->mode, grab_data->key, (void *)client); + grab_data->err = res; + if (res == TIZEN_KEYROUTER_ERROR_NONE) + res = _pepper_keyrouter_add_client_to_list(pepper_keyrouter, client); + } } return_list = grab_list; @@ -296,6 +486,7 @@ _pepper_keyrouter_cb_keygrab_unset_list(struct wl_client *client, struct wl_array *return_list = NULL; ungrab_list_data_t *ungrab_data = NULL; pepper_keyrouter_t *pepper_keyrouter = NULL; + pepper_bool_t ret; pepper_keyrouter = (pepper_keyrouter_t *)wl_resource_get_user_data(resource); @@ -305,19 +496,31 @@ _pepper_keyrouter_cb_keygrab_unset_list(struct wl_client *client, wl_array_for_each(ungrab_data, ungrab_list) { keyrouter_ungrab_key(pepper_keyrouter->keyrouter, - TIZEN_KEYROUTER_MODE_EXCLUSIVE, - ungrab_data->key, (void *)client); - keyrouter_ungrab_key(pepper_keyrouter->keyrouter, - TIZEN_KEYROUTER_MODE_OVERRIDABLE_EXCLUSIVE, - ungrab_data->key, (void *)client); - keyrouter_ungrab_key(pepper_keyrouter->keyrouter, TIZEN_KEYROUTER_MODE_TOPMOST, ungrab_data->key, (void *)client); - keyrouter_ungrab_key(pepper_keyrouter->keyrouter, - TIZEN_KEYROUTER_MODE_SHARED, - ungrab_data->key, (void *)client); - ungrab_data->err = TIZEN_KEYROUTER_ERROR_NONE;; + ret = _pepper_keyrouter_util_do_privilege_check(pepper_keyrouter, client, TIZEN_KEYROUTER_MODE_TOPMOST, ungrab_data->key); + if (!ret) { + ungrab_data->err = TIZEN_KEYROUTER_ERROR_NO_PERMISSION; + } else { + keyrouter_ungrab_key(pepper_keyrouter->keyrouter, + TIZEN_KEYROUTER_MODE_EXCLUSIVE, + ungrab_data->key, (void *)client); + + keyrouter_ungrab_key(pepper_keyrouter->keyrouter, + TIZEN_KEYROUTER_MODE_OVERRIDABLE_EXCLUSIVE, + ungrab_data->key, (void *)client); + + keyrouter_ungrab_key(pepper_keyrouter->keyrouter, + TIZEN_KEYROUTER_MODE_TOPMOST, + ungrab_data->key, (void *)client); + + keyrouter_ungrab_key(pepper_keyrouter->keyrouter, + TIZEN_KEYROUTER_MODE_SHARED, + ungrab_data->key, (void *)client); + + ungrab_data->err = TIZEN_KEYROUTER_ERROR_NONE; + } } return_list = ungrab_list; @@ -385,6 +588,7 @@ static void _pepper_keyrouter_cb_resource_destory(struct wl_resource *resource) { resources_data_t *rdata, *rtmp; + clients_data_t *cdata, *ctmp; pepper_list_t *list; struct wl_client *client; pepper_keyrouter_t *pepper_keyrouter; @@ -395,7 +599,16 @@ _pepper_keyrouter_cb_resource_destory(struct wl_resource *resource) pepper_keyrouter = wl_resource_get_user_data(resource); PEPPER_CHECK(pepper_keyrouter, return, "Invalid pepper_keyrouter_t\n"); - _pepper_keyrouter_remove_client_from_list(pepper_keyrouter, client); + list = &pepper_keyrouter->grabbed_clients; + if (!pepper_list_empty(list)) { + pepper_list_for_each_safe(cdata, ctmp, list, link) { + if (cdata->client == client) { + _pepper_keyrouter_remove_client_from_list(pepper_keyrouter, client); + pepper_list_remove(&cdata->link); + free(cdata); + } + } + } list = &pepper_keyrouter->resources; @@ -475,6 +688,7 @@ pepper_keyrouter_create(pepper_compositor_t *compositor) struct wl_display *display = NULL; struct wl_global *global = NULL; pepper_keyrouter_t *pepper_keyrouter; + pepper_bool_t ret; PEPPER_CHECK(compositor, return PEPPER_FALSE, "Invalid compositor\n"); @@ -487,6 +701,7 @@ pepper_keyrouter_create(pepper_compositor_t *compositor) pepper_keyrouter->compositor = compositor; pepper_list_init(&pepper_keyrouter->resources); + pepper_list_init(&pepper_keyrouter->grabbed_clients); global = wl_global_create(display, &tizen_keyrouter_interface, 2, pepper_keyrouter, _pepper_keyrouter_cb_bind); PEPPER_CHECK(global, goto failed, "Failed to create wl_global for tizen_keyrouter\n"); @@ -494,6 +709,9 @@ pepper_keyrouter_create(pepper_compositor_t *compositor) pepper_keyrouter->keyrouter = keyrouter_create(); PEPPER_CHECK(pepper_keyrouter->keyrouter, goto failed, "Failed to create keyrouter\n"); + ret = _pepper_keyrouter_util_cynara_init(pepper_keyrouter); + if (!ret) PEPPER_TRACE("cynara initialize is failed, process keyrouter without cynara\n"); + return pepper_keyrouter; failed: @@ -512,9 +730,15 @@ PEPPER_API void pepper_keyrouter_destroy(pepper_keyrouter_t *pepper_keyrouter) { resources_data_t *rdata, *rtmp; + clients_data_t *cdata, *ctmp; PEPPER_CHECK(pepper_keyrouter, return, "Pepper keyrouter is not initialized\n"); + pepper_list_for_each_safe(cdata, ctmp, &pepper_keyrouter->grabbed_clients, link) { + pepper_list_remove(&cdata->link); + free(cdata); + } + pepper_list_for_each_safe(rdata, rtmp, &pepper_keyrouter->resources, link) { wl_resource_destroy(rdata->resource); pepper_list_remove(&rdata->link); @@ -529,6 +753,8 @@ pepper_keyrouter_destroy(pepper_keyrouter_t *pepper_keyrouter) if (pepper_keyrouter->global) wl_global_destroy(pepper_keyrouter->global); + _pepper_keyrouter_util_cynara_deinit(pepper_keyrouter); + free(pepper_keyrouter); pepper_keyrouter = NULL; } -- 2.7.4