From 9b2ff241cf17b7f708c0a7d00b590c9cb63f4e81 Mon Sep 17 00:00:00 2001 From: Seunghun Lee Date: Fri, 10 Jun 2022 11:07:32 +0900 Subject: [PATCH 01/16] keyrouter: Rename keyrouter_grab for shorter name Change-Id: I30b62158ede60976ac760d39bafb894f274acf21 --- src/keyrouter/keyrouter.c | 32 ++++++------ src/keyrouter/keyrouter.h | 16 +++--- src/keyrouter/keyrouter_grab.c | 116 ++++++++++++++++++++--------------------- 3 files changed, 82 insertions(+), 82 deletions(-) diff --git a/src/keyrouter/keyrouter.c b/src/keyrouter/keyrouter.c index 199af6b..730b8a8 100644 --- a/src/keyrouter/keyrouter.c +++ b/src/keyrouter/keyrouter.c @@ -42,7 +42,7 @@ keyrouter_handle_display_destroy(struct wl_listener *listener, void *data) wl_global_destroy(keyrouter->global); - keyrouter_grab_destroy(keyrouter->keyrouter_grab); + keyrouter_grab_destroy(keyrouter->keygrab); free(keyrouter); } @@ -57,8 +57,8 @@ ds_tizen_keyrouter_create(struct wl_display *display) return NULL; } - keyrouter->keyrouter_grab = keyrouter_grab_create(); - if (keyrouter->keyrouter_grab == NULL) { + keyrouter->keygrab = keyrouter_grab_create(); + if (keyrouter->keygrab == NULL) { ds_err("Failed to create keyrouter."); free(keyrouter); return NULL; @@ -67,7 +67,7 @@ ds_tizen_keyrouter_create(struct wl_display *display) keyrouter->global = wl_global_create(display, &tizen_keyrouter_interface, TIZEN_KEYROUTER_VERSION, keyrouter, keyrouter_bind); if (!keyrouter->global) { - keyrouter_grab_destroy(keyrouter->keyrouter_grab); + keyrouter_grab_destroy(keyrouter->keygrab); free(keyrouter); return NULL; } @@ -119,7 +119,7 @@ keyrouter_handle_keygrab_set(struct wl_client *wl_client, return; } - res = keyrouter_grab_grab_key(keyrouter->keyrouter_grab, + res = keyrouter_grab_grab_key(keyrouter->keygrab, mode, key, (void *)wl_client); tizen_keyrouter_send_keygrab_notify(resource, surface, key, mode, res); @@ -138,7 +138,7 @@ keyrouter_handle_keygrab_unset(struct wl_client *wl_client, keyrouter = client->keyrouter; /* ungrab TOP POSITION grab first, this grab mode is not check privilege */ - keyrouter_grab_ungrab_key(keyrouter->keyrouter_grab, + keyrouter_grab_ungrab_key(keyrouter->keygrab, TIZEN_KEYROUTER_MODE_TOPMOST, key, (void *)wl_client); ret = keyrouter_check_privilege(client, @@ -149,13 +149,13 @@ keyrouter_handle_keygrab_unset(struct wl_client *wl_client, return; } - keyrouter_grab_ungrab_key(keyrouter->keyrouter_grab, + keyrouter_grab_ungrab_key(keyrouter->keygrab, TIZEN_KEYROUTER_MODE_EXCLUSIVE, key, (void *)wl_client); - keyrouter_grab_ungrab_key(keyrouter->keyrouter_grab, + keyrouter_grab_ungrab_key(keyrouter->keygrab, TIZEN_KEYROUTER_MODE_OVERRIDABLE_EXCLUSIVE, key, (void *)wl_client); - keyrouter_grab_ungrab_key(keyrouter->keyrouter_grab, + keyrouter_grab_ungrab_key(keyrouter->keygrab, TIZEN_KEYROUTER_MODE_TOPMOST, key, (void *)wl_client); - keyrouter_grab_ungrab_key(keyrouter->keyrouter_grab, + keyrouter_grab_ungrab_key(keyrouter->keygrab, TIZEN_KEYROUTER_MODE_SHARED, key, (void *)wl_client); tizen_keyrouter_send_keygrab_notify(resource, surface, key, TIZEN_KEYROUTER_MODE_NONE, res); @@ -207,7 +207,7 @@ keyrouter_handle_keygrab_set_list(struct wl_client *wl_client, if (ret == false) { grab_data->err = TIZEN_KEYROUTER_ERROR_NO_PERMISSION; } else { - res = keyrouter_grab_grab_key(keyrouter->keyrouter_grab, + res = keyrouter_grab_grab_key(keyrouter->keygrab, grab_data->mode, grab_data->key, (void *)wl_client); grab_data->err = res; @@ -240,7 +240,7 @@ keyrouter_handle_keygrab_unset_list(struct wl_client *wl_client, } wl_array_for_each(ungrab_data, ungrab_list) { - keyrouter_grab_ungrab_key(keyrouter->keyrouter_grab, + keyrouter_grab_ungrab_key(keyrouter->keygrab, TIZEN_KEYROUTER_MODE_TOPMOST, ungrab_data->key, (void *)wl_client); ret = keyrouter_check_privilege(client, wl_client, @@ -248,16 +248,16 @@ keyrouter_handle_keygrab_unset_list(struct wl_client *wl_client, if (!ret) { ungrab_data->err = TIZEN_KEYROUTER_ERROR_NO_PERMISSION; } else { - keyrouter_grab_ungrab_key(keyrouter->keyrouter_grab, + keyrouter_grab_ungrab_key(keyrouter->keygrab, TIZEN_KEYROUTER_MODE_EXCLUSIVE, ungrab_data->key, (void *)wl_client); - keyrouter_grab_ungrab_key(keyrouter->keyrouter_grab, + keyrouter_grab_ungrab_key(keyrouter->keygrab, TIZEN_KEYROUTER_MODE_OVERRIDABLE_EXCLUSIVE, ungrab_data->key, (void *)wl_client); - keyrouter_grab_ungrab_key(keyrouter->keyrouter_grab, + keyrouter_grab_ungrab_key(keyrouter->keygrab, TIZEN_KEYROUTER_MODE_TOPMOST, ungrab_data->key, (void *)wl_client); - keyrouter_grab_ungrab_key(keyrouter->keyrouter_grab, + keyrouter_grab_ungrab_key(keyrouter->keygrab, TIZEN_KEYROUTER_MODE_SHARED, ungrab_data->key, (void *)wl_client); ungrab_data->err = TIZEN_KEYROUTER_ERROR_NONE; diff --git a/src/keyrouter/keyrouter.h b/src/keyrouter/keyrouter.h index ab10f9b..11fbadc 100644 --- a/src/keyrouter/keyrouter.h +++ b/src/keyrouter/keyrouter.h @@ -55,7 +55,7 @@ struct ds_tizen_keyrouter struct ds_tizen_keyrouter_key_options *opts; - struct ds_tizen_keyrouter_grab *keyrouter_grab; + struct ds_tizen_keyrouter_grab *keygrab; bool security_initialized; }; @@ -87,24 +87,24 @@ struct ds_tizen_ungrab_data struct ds_tizen_keyrouter_grab * keyrouter_grab_create(void); void -keyrouter_grab_destroy(struct ds_tizen_keyrouter_grab *keyrouter_grab); +keyrouter_grab_destroy(struct ds_tizen_keyrouter_grab *keygrab); int -keyrouter_grab_grab_key(struct ds_tizen_keyrouter_grab *keyrouter_grab, +keyrouter_grab_grab_key(struct ds_tizen_keyrouter_grab *keygrab, int type, int keycode, void *data); void -keyrouter_grab_ungrab_key(struct ds_tizen_keyrouter_grab *keyrouter_grab, +keyrouter_grab_ungrab_key(struct ds_tizen_keyrouter_grab *keygrab, int type, int keycode, void *data); int -keyrouter_grab_key_process(struct ds_tizen_keyrouter_grab *keyrouter_grab, +keyrouter_grab_key_process(struct ds_tizen_keyrouter_grab *keygrab, int keycode, int pressed, struct wl_list *delivery_list); void -keyrouter_grab_set_focus_client(struct ds_tizen_keyrouter_grab *keyrouter_grab, +keyrouter_grab_set_focus_client(struct ds_tizen_keyrouter_grab *keygrab, void *focus_client); void -keyrouter_grab_set_top_client(struct ds_tizen_keyrouter_grab *keyrouter_grab, +keyrouter_grab_set_top_client(struct ds_tizen_keyrouter_grab *keygrab, void *top_client); bool -keyrouter_grab_check_grabbed_key(struct ds_tizen_keyrouter_grab *keyrouter_grab, +keyrouter_grab_check_grabbed_key(struct ds_tizen_keyrouter_grab *keygrab, int keycode); #endif diff --git a/src/keyrouter/keyrouter_grab.c b/src/keyrouter/keyrouter_grab.c index 6af0c85..755f6d4 100644 --- a/src/keyrouter/keyrouter_grab.c +++ b/src/keyrouter/keyrouter_grab.c @@ -6,41 +6,41 @@ #include "keyrouter.h" static struct wl_list * -keyrouter_grab_get_grabbed_list(struct ds_tizen_keyrouter_grab *keyrouter_grab, +keyrouter_grab_get_grabbed_list(struct ds_tizen_keyrouter_grab *keygrab, int type, int keycode) { switch(type) { case TIZEN_KEYROUTER_MODE_EXCLUSIVE: - return &keyrouter_grab->hard_keys[keycode].grab.excl; + return &keygrab->hard_keys[keycode].grab.excl; case TIZEN_KEYROUTER_MODE_OVERRIDABLE_EXCLUSIVE: - return &keyrouter_grab->hard_keys[keycode].grab.or_excl; + return &keygrab->hard_keys[keycode].grab.or_excl; case TIZEN_KEYROUTER_MODE_TOPMOST: - return &keyrouter_grab->hard_keys[keycode].grab.top; + return &keygrab->hard_keys[keycode].grab.top; case TIZEN_KEYROUTER_MODE_SHARED: - return &keyrouter_grab->hard_keys[keycode].grab.shared; + return &keygrab->hard_keys[keycode].grab.shared; default: return NULL; } } bool -keyrouter_grab_check_grabbed_key(struct ds_tizen_keyrouter_grab *keyrouter_grab, int keycode) +keyrouter_grab_check_grabbed_key(struct ds_tizen_keyrouter_grab *keygrab, int keycode) { struct wl_list *list; - list = keyrouter_grab_get_grabbed_list(keyrouter_grab, TIZEN_KEYROUTER_MODE_EXCLUSIVE, keycode); + list = keyrouter_grab_get_grabbed_list(keygrab, TIZEN_KEYROUTER_MODE_EXCLUSIVE, keycode); if (list && !wl_list_empty(list)) return true; - list = keyrouter_grab_get_grabbed_list(keyrouter_grab, TIZEN_KEYROUTER_MODE_OVERRIDABLE_EXCLUSIVE, keycode); + list = keyrouter_grab_get_grabbed_list(keygrab, TIZEN_KEYROUTER_MODE_OVERRIDABLE_EXCLUSIVE, keycode); if (list && !wl_list_empty(list)) return true; - list = keyrouter_grab_get_grabbed_list(keyrouter_grab, TIZEN_KEYROUTER_MODE_TOPMOST, keycode); + list = keyrouter_grab_get_grabbed_list(keygrab, TIZEN_KEYROUTER_MODE_TOPMOST, keycode); if (list && !wl_list_empty(list)) return true; - list = keyrouter_grab_get_grabbed_list(keyrouter_grab, TIZEN_KEYROUTER_MODE_SHARED, keycode); + list = keyrouter_grab_get_grabbed_list(keygrab, TIZEN_KEYROUTER_MODE_SHARED, keycode); if (list && !wl_list_empty(list)) return true; @@ -64,13 +64,13 @@ keyrouter_grab_check_duplicated_data(struct wl_list *list, void *data) } static bool -keyrouter_grab_check_grabbed(struct ds_tizen_keyrouter_grab *keyrouter_grab, +keyrouter_grab_check_grabbed(struct ds_tizen_keyrouter_grab *keygrab, int type, int keycode, void *data) { struct wl_list *list; bool ret; - list = keyrouter_grab_get_grabbed_list(keyrouter_grab, type, keycode); + list = keyrouter_grab_get_grabbed_list(keygrab, type, keycode); if (list == NULL) { ds_err("keycode(%d) had no list for type(%d).", keycode, type); return false; @@ -101,10 +101,10 @@ keyrouter_grab_check_grabbed(struct ds_tizen_keyrouter_grab *keyrouter_grab, } void -keyrouter_grab_set_focus_client(struct ds_tizen_keyrouter_grab *keyrouter_grab, +keyrouter_grab_set_focus_client(struct ds_tizen_keyrouter_grab *keygrab, void *focus_client) { - keyrouter_grab->focus_client = focus_client; + keygrab->focus_client = focus_client; if (focus_client) ds_dbg("[%s] focus client has been set. (focus_client=0x%p)", __FUNCTION__, focus_client); @@ -113,9 +113,9 @@ keyrouter_grab_set_focus_client(struct ds_tizen_keyrouter_grab *keyrouter_grab, } void -keyrouter_grab_set_top_client(struct ds_tizen_keyrouter_grab *keyrouter_grab, void *top_client) +keyrouter_grab_set_top_client(struct ds_tizen_keyrouter_grab *keygrab, void *top_client) { - keyrouter_grab->top_client = top_client; + keygrab->top_client = top_client; if (top_client) ds_dbg("[%s] top client has been set. (top_client=0x%p)", __FUNCTION__, top_client); @@ -124,7 +124,7 @@ keyrouter_grab_set_top_client(struct ds_tizen_keyrouter_grab *keyrouter_grab, vo } int -keyrouter_grab_key_process(struct ds_tizen_keyrouter_grab *keyrouter_grab, +keyrouter_grab_key_process(struct ds_tizen_keyrouter_grab *keygrab, int keycode, int pressed, struct wl_list *delivery_list) { struct ds_tizen_keyrouter_key_info *info, *delivery; @@ -135,8 +135,8 @@ keyrouter_grab_key_process(struct ds_tizen_keyrouter_grab *keyrouter_grab, return 0; } - if (!wl_list_empty(&keyrouter_grab->hard_keys[keycode].grab.excl)) { - info = wl_container_of(keyrouter_grab->hard_keys[keycode].grab.excl.next, info, link); + if (!wl_list_empty(&keygrab->hard_keys[keycode].grab.excl)) { + info = wl_container_of(keygrab->hard_keys[keycode].grab.excl.next, info, link); if (info) { delivery = calloc(1, sizeof(struct ds_tizen_keyrouter_key_info)); if (delivery == NULL) { @@ -148,8 +148,8 @@ keyrouter_grab_key_process(struct ds_tizen_keyrouter_grab *keyrouter_grab, ds_dbg("Exclusive Mode: keycode: %d to data: %p", keycode, info->data); return 1; } - } else if (!wl_list_empty(&keyrouter_grab->hard_keys[keycode].grab.or_excl)) { - info = wl_container_of(keyrouter_grab->hard_keys[keycode].grab.or_excl.next, info, link); + } else if (!wl_list_empty(&keygrab->hard_keys[keycode].grab.or_excl)) { + info = wl_container_of(keygrab->hard_keys[keycode].grab.or_excl.next, info, link); if (info) { delivery = calloc(1, sizeof(struct ds_tizen_keyrouter_key_info)); if (delivery == NULL) { @@ -161,9 +161,9 @@ keyrouter_grab_key_process(struct ds_tizen_keyrouter_grab *keyrouter_grab, ds_dbg("OR-Excl Mode: keycode: %d to data: %p", keycode, info->data); return 1; } - } else if (!wl_list_empty(&keyrouter_grab->hard_keys[keycode].grab.top)) { - wl_list_for_each(info, &keyrouter_grab->hard_keys[keycode].grab.top, link) { - if (keyrouter_grab->top_client && keyrouter_grab->top_client == info->data) { + } else if (!wl_list_empty(&keygrab->hard_keys[keycode].grab.top)) { + wl_list_for_each(info, &keygrab->hard_keys[keycode].grab.top, link) { + if (keygrab->top_client && keygrab->top_client == info->data) { delivery = calloc(1, sizeof(struct ds_tizen_keyrouter_key_info)); if (delivery == NULL) { ds_err("Failed to allocate memory."); @@ -177,21 +177,21 @@ keyrouter_grab_key_process(struct ds_tizen_keyrouter_grab *keyrouter_grab, } } - if (keyrouter_grab->focus_client) { + if (keygrab->focus_client) { delivery = calloc(1, sizeof(struct ds_tizen_keyrouter_key_info)); if (delivery == NULL) { ds_err("Failed to allocate memory."); return 0; } - delivery->data = keyrouter_grab->focus_client; + delivery->data = keygrab->focus_client; wl_list_insert(delivery_list, &delivery->link); count++; ds_dbg("Focus: keycode: %d to data: %p, count: %d", keycode, delivery->data, count); } - if (!wl_list_empty(&keyrouter_grab->hard_keys[keycode].grab.shared)) { - wl_list_for_each(info, &keyrouter_grab->hard_keys[keycode].grab.shared, link) { - if (keyrouter_grab->focus_client && keyrouter_grab->focus_client == info->data) + if (!wl_list_empty(&keygrab->hard_keys[keycode].grab.shared)) { + wl_list_for_each(info, &keygrab->hard_keys[keycode].grab.shared, link) { + if (keygrab->focus_client && keygrab->focus_client == info->data) continue; delivery = calloc(1, sizeof(struct ds_tizen_keyrouter_key_info)); if (delivery == NULL) { @@ -209,7 +209,7 @@ keyrouter_grab_key_process(struct ds_tizen_keyrouter_grab *keyrouter_grab, } int -keyrouter_grab_grab_key(struct ds_tizen_keyrouter_grab *keyrouter_grab, +keyrouter_grab_grab_key(struct ds_tizen_keyrouter_grab *keygrab, int type, int keycode, void *data) { struct ds_tizen_keyrouter_key_info *info = NULL; @@ -220,7 +220,7 @@ keyrouter_grab_grab_key(struct ds_tizen_keyrouter_grab *keyrouter_grab, return TIZEN_KEYROUTER_ERROR_INVALID_KEY; } - if (keyrouter_grab_check_grabbed(keyrouter_grab, type, keycode, data)) + if (keyrouter_grab_check_grabbed(keygrab, type, keycode, data)) return TIZEN_KEYROUTER_ERROR_GRABBED_ALREADY; info = calloc(1, sizeof(struct ds_tizen_keyrouter_key_info)); @@ -232,15 +232,15 @@ keyrouter_grab_grab_key(struct ds_tizen_keyrouter_grab *keyrouter_grab, wl_list_init(&info->link); - list = keyrouter_grab_get_grabbed_list(keyrouter_grab, type, keycode); + list = keyrouter_grab_get_grabbed_list(keygrab, type, keycode); if (!list) { ds_err("keycode(%d) had no list for type(%d)", keycode, type); free(info); return TIZEN_KEYROUTER_ERROR_INVALID_MODE; } - if (!keyrouter_grab->hard_keys[keycode].keycode) - keyrouter_grab->hard_keys[keycode].keycode = keycode; + if (!keygrab->hard_keys[keycode].keycode) + keygrab->hard_keys[keycode].keycode = keycode; wl_list_insert(list, &info->link); @@ -264,7 +264,7 @@ keyrouter_list_remove_data(struct wl_list *list, void *data) } void -keyrouter_grab_ungrab_key(struct ds_tizen_keyrouter_grab *keyrouter_grab, +keyrouter_grab_ungrab_key(struct ds_tizen_keyrouter_grab *keygrab, int type, int keycode, void *data) { struct wl_list *list; @@ -274,10 +274,10 @@ keyrouter_grab_ungrab_key(struct ds_tizen_keyrouter_grab *keyrouter_grab, return; } - if (keyrouter_grab->hard_keys[keycode].keycode == 0) + if (keygrab->hard_keys[keycode].keycode == 0) return; - list = keyrouter_grab_get_grabbed_list(keyrouter_grab, type, keycode); + list = keyrouter_grab_get_grabbed_list(keygrab, type, keycode); if (list == NULL) { ds_err("keycode(%d) had no list for type(%d)", keycode, type); return; @@ -289,34 +289,34 @@ keyrouter_grab_ungrab_key(struct ds_tizen_keyrouter_grab *keyrouter_grab, struct ds_tizen_keyrouter_grab * keyrouter_grab_create(void) { - struct ds_tizen_keyrouter_grab *keyrouter_grab = NULL; + struct ds_tizen_keyrouter_grab *keygrab = NULL; int i; - keyrouter_grab = calloc(1, sizeof(struct ds_tizen_keyrouter_grab)); - if (keyrouter_grab == NULL) { + keygrab = calloc(1, sizeof(struct ds_tizen_keyrouter_grab)); + if (keygrab == NULL) { ds_err("Failed to allocate memory."); return NULL; } /* FIXME: Who defined max keycode? */ - keyrouter_grab->hard_keys = calloc(KEYROUTER_MAX_KEYS, sizeof(struct ds_tizen_keyrouter_grabbed)); - if (keyrouter_grab->hard_keys == NULL) { + keygrab->hard_keys = calloc(KEYROUTER_MAX_KEYS, sizeof(struct ds_tizen_keyrouter_grabbed)); + if (keygrab->hard_keys == NULL) { ds_err("Failed to allocate memory."); - free(keyrouter_grab); + free(keygrab); return NULL; } for (i = 0; i < KEYROUTER_MAX_KEYS; i++) { /* Enable all of keys to grab */ - //keyrouter_grab->hard_keys[i].keycode = i; - wl_list_init(&keyrouter_grab->hard_keys[i].grab.excl); - wl_list_init(&keyrouter_grab->hard_keys[i].grab.or_excl); - wl_list_init(&keyrouter_grab->hard_keys[i].grab.top); - wl_list_init(&keyrouter_grab->hard_keys[i].grab.shared); - wl_list_init(&keyrouter_grab->hard_keys[i].pressed); + //keygrab->hard_keys[i].keycode = i; + wl_list_init(&keygrab->hard_keys[i].grab.excl); + wl_list_init(&keygrab->hard_keys[i].grab.or_excl); + wl_list_init(&keygrab->hard_keys[i].grab.top); + wl_list_init(&keygrab->hard_keys[i].grab.shared); + wl_list_init(&keygrab->hard_keys[i].pressed); } - return keyrouter_grab; + return keygrab; } static void @@ -334,18 +334,18 @@ keyrouter_grab_delete_list(struct wl_list *list) } void -keyrouter_grab_destroy(struct ds_tizen_keyrouter_grab *keyrouter_grab) +keyrouter_grab_destroy(struct ds_tizen_keyrouter_grab *keygrab) { int i; for (i = 0; i < KEYROUTER_MAX_KEYS; i++) { - keyrouter_grab_delete_list(&keyrouter_grab->hard_keys[i].grab.excl); - keyrouter_grab_delete_list(&keyrouter_grab->hard_keys[i].grab.or_excl); - keyrouter_grab_delete_list(&keyrouter_grab->hard_keys[i].grab.top); - keyrouter_grab_delete_list(&keyrouter_grab->hard_keys[i].grab.shared); - keyrouter_grab_delete_list(&keyrouter_grab->hard_keys[i].pressed); + keyrouter_grab_delete_list(&keygrab->hard_keys[i].grab.excl); + keyrouter_grab_delete_list(&keygrab->hard_keys[i].grab.or_excl); + keyrouter_grab_delete_list(&keygrab->hard_keys[i].grab.top); + keyrouter_grab_delete_list(&keygrab->hard_keys[i].grab.shared); + keyrouter_grab_delete_list(&keygrab->hard_keys[i].pressed); } - free(keyrouter_grab->hard_keys); - free(keyrouter_grab); + free(keygrab->hard_keys); + free(keygrab); } -- 2.7.4 From fcec353fd01820db2973ab1b1e6ef577e54ce9f6 Mon Sep 17 00:00:00 2001 From: Seunghun Lee Date: Fri, 10 Jun 2022 14:55:24 +0900 Subject: [PATCH 02/16] keyrouter: Drop unnecessary NULL check for wl_container_of() If wl_container_of() returned null, it's not something that we treat as an exception case, but is something that we'd better fail immediately. The result of wl_container_of() is never null. Change-Id: I1812a2f148888cbd64441a2a39916c13f2f68a27 --- src/keyrouter/keyrouter_grab.c | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/src/keyrouter/keyrouter_grab.c b/src/keyrouter/keyrouter_grab.c index 755f6d4..ae29e8e 100644 --- a/src/keyrouter/keyrouter_grab.c +++ b/src/keyrouter/keyrouter_grab.c @@ -136,31 +136,27 @@ keyrouter_grab_key_process(struct ds_tizen_keyrouter_grab *keygrab, } if (!wl_list_empty(&keygrab->hard_keys[keycode].grab.excl)) { - info = wl_container_of(keygrab->hard_keys[keycode].grab.excl.next, info, link); - if (info) { - delivery = calloc(1, sizeof(struct ds_tizen_keyrouter_key_info)); - if (delivery == NULL) { - ds_err("Failed to allocate memory."); - return 0; - } - delivery->data = info->data; - wl_list_insert(delivery_list, &delivery->link); - ds_dbg("Exclusive Mode: keycode: %d to data: %p", keycode, info->data); - return 1; + delivery = calloc(1, sizeof(struct ds_tizen_keyrouter_key_info)); + if (delivery == NULL) { + ds_err("Failed to allocate memory."); + return 0; } + info = wl_container_of(keygrab->hard_keys[keycode].grab.excl.next, info, link); + delivery->data = info->data; + wl_list_insert(delivery_list, &delivery->link); + ds_dbg("Exclusive Mode: keycode: %d to data: %p", keycode, info->data); + return 1; } else if (!wl_list_empty(&keygrab->hard_keys[keycode].grab.or_excl)) { - info = wl_container_of(keygrab->hard_keys[keycode].grab.or_excl.next, info, link); - if (info) { - delivery = calloc(1, sizeof(struct ds_tizen_keyrouter_key_info)); - if (delivery == NULL) { - ds_err("Failed to allocate memory."); - return 0; - } - delivery->data = info->data; - wl_list_insert(delivery_list, &delivery->link); - ds_dbg("OR-Excl Mode: keycode: %d to data: %p", keycode, info->data); - return 1; + delivery = calloc(1, sizeof(struct ds_tizen_keyrouter_key_info)); + if (delivery == NULL) { + ds_err("Failed to allocate memory."); + return 0; } + info = wl_container_of(keygrab->hard_keys[keycode].grab.or_excl.next, info, link); + delivery->data = info->data; + wl_list_insert(delivery_list, &delivery->link); + ds_dbg("OR-Excl Mode: keycode: %d to data: %p", keycode, info->data); + return 1; } else if (!wl_list_empty(&keygrab->hard_keys[keycode].grab.top)) { wl_list_for_each(info, &keygrab->hard_keys[keycode].grab.top, link) { if (keygrab->top_client && keygrab->top_client == info->data) { -- 2.7.4 From d67d917ad16c8e89ee5cfd94371b04fc426ebd29 Mon Sep 17 00:00:00 2001 From: Seunghun Lee Date: Fri, 10 Jun 2022 14:42:22 +0900 Subject: [PATCH 03/16] keyrouter: Refactor out ds_tizen_keyrouter Change-Id: I35add1ab1c81c8589789708b8ef38f4693cc1ee2 --- include/libds-tizen/keyrouter.h | 55 +++++ src/keyrouter/keyrouter.c | 398 ++++++++++++++++----------------- src/keyrouter/keyrouter.h | 71 +++--- src/keyrouter/keyrouter_grab.c | 478 +++++++++++++++++++--------------------- 4 files changed, 509 insertions(+), 493 deletions(-) diff --git a/include/libds-tizen/keyrouter.h b/include/libds-tizen/keyrouter.h index a870003..bd47b54 100644 --- a/include/libds-tizen/keyrouter.h +++ b/include/libds-tizen/keyrouter.h @@ -7,15 +7,70 @@ extern "C" { #endif +/** + * A handle for accessing ds_tizen_keyrouter. + */ struct ds_tizen_keyrouter; +/** + * The information of keyroute + */ +struct ds_tizen_keyroute_info +{ + struct wl_client *wl_client; +}; + +/** + * Keyroute mode of keyroutes returned by ds_tizen_keyrouter_get_keyroutes() + * for a given keycode. + */ +enum ds_tizen_keyroute_mode { + /** + * The keycode is not under any keyroute mode. + * The compositor may send a keycode to a focused wayland cliet as usual. + */ + DS_TIZEN_KEYROUTE_MODE_NONE, + /** + * Exclusive mode means that a given keycode is required to be sent + * exclusively to wayland clients of returned keyroutes. So the compositor + * must not send this keycode to any other wayland clients except for + * returned wayland clients. + */ + DS_TIZEN_KEYROUTE_MODE_EXCLUSIVE, + /** + * The keycode is required to be shared with returned wayland clients. + * The compositor must send the keycode not only to returned wayland + * clients, but also to a focused wayland client. + */ + DS_TIZEN_KEYROUTE_MODE_SHARED, +}; + +/** + * Creates a ds_tizen_keyrouter. + */ struct ds_tizen_keyrouter * ds_tizen_keyrouter_create(struct wl_display *display); +/** + * Adds destroy listener of ds_tizen_keyrouter + */ void ds_tizen_keyrouter_add_destroy_listener(struct ds_tizen_keyrouter *keyrouter, struct wl_listener *listener); +/** + * Gets keyroutes and mode for a given keycode. + * The compositor must send a keycode to returned wayland clients according to + * the mode. The parameter, topmost_client, should be given to determine whether + * the given topmost_client require a keycode exclusively when one of its + * surfaces is on very top of stack. See tizen_keyrouter protocol in + * tizen-extension.xml for more detail. + */ +enum ds_tizen_keyroute_mode +ds_tizen_keyrouter_get_keyroutes(struct ds_tizen_keyrouter *keyrouter, + int keycode, struct wl_client *topmost_client, + struct wl_array *keyroutes); + #ifdef __cplusplus } #endif diff --git a/src/keyrouter/keyrouter.c b/src/keyrouter/keyrouter.c index 730b8a8..4bcee93 100644 --- a/src/keyrouter/keyrouter.c +++ b/src/keyrouter/keyrouter.c @@ -13,39 +13,21 @@ #define TIZEN_KEYROUTER_VERSION 2 #define TIZEN_KEYROUTER_PRIVILEGE "http://tizen.org/privilege/keygrab" -static void -keyrouter_bind(struct wl_client *wl_client, void *data, uint32_t version, - uint32_t id); +static void keyrouter_bind(struct wl_client *wl_client, void *data, + uint32_t version, uint32_t id); +static void keyrouter_handle_display_destroy(struct wl_listener *listener, + void *data); +static void keyrouter_options_set(struct ds_tizen_keyrouter *keyrouter); +static void create_keyrouter_client(struct ds_tizen_keyrouter *keyrouter, + struct wl_client *wl_client, uint32_t version, uint32_t id); +static void destroy_keyrouter_client(struct keyrouter_client *client); static bool -keyrouter_check_privilege(struct ds_tizen_keyrouter_client *client, - struct wl_client *wl_client, uint32_t mode, uint32_t keycode); -static void -keyrouter_options_set(struct ds_tizen_keyrouter *keyrouter); - -static void -keyrouter_handle_display_destroy(struct wl_listener *listener, void *data) -{ - struct ds_tizen_keyrouter *keyrouter; - - keyrouter = wl_container_of(listener, keyrouter, display_destroy); - - ds_inf("Global destroy: ds_tizen_keyrouter(%p)", keyrouter); - - wl_signal_emit(&keyrouter->events.destroy, keyrouter); - - if (keyrouter->security_initialized) - tizen_security_finish(); - - free(keyrouter->opts); - - wl_list_remove(&keyrouter->display_destroy.link); - - wl_global_destroy(keyrouter->global); - - keyrouter_grab_destroy(keyrouter->keygrab); - - free(keyrouter); -} +keyrouter_client_check_privilege(struct keyrouter_client *client, uint32_t mode, + uint32_t keycode); +static int keyrouter_client_grab_key(struct keyrouter_client *client, int mode, + int keycode); +static int keyrouter_client_ungrab_key(struct keyrouter_client *client, + int keycode); WL_EXPORT struct ds_tizen_keyrouter * ds_tizen_keyrouter_create(struct wl_display *display) @@ -57,21 +39,15 @@ ds_tizen_keyrouter_create(struct wl_display *display) return NULL; } - keyrouter->keygrab = keyrouter_grab_create(); - if (keyrouter->keygrab == NULL) { - ds_err("Failed to create keyrouter."); - free(keyrouter); - return NULL; - } - keyrouter->global = wl_global_create(display, &tizen_keyrouter_interface, TIZEN_KEYROUTER_VERSION, keyrouter, keyrouter_bind); if (!keyrouter->global) { - keyrouter_grab_destroy(keyrouter->keygrab); free(keyrouter); return NULL; } + keyrouter_grab_init(&keyrouter->keygrab); + wl_list_init(&keyrouter->clients); wl_signal_init(&keyrouter->events.destroy); @@ -99,70 +75,43 @@ ds_tizen_keyrouter_add_destroy_listener(struct ds_tizen_keyrouter *keyrouter, wl_signal_add(&keyrouter->events.destroy, listener); } +WL_EXPORT enum ds_tizen_keyroute_mode +ds_tizen_keyrouter_get_keyroutes(struct ds_tizen_keyrouter *keyrouter, + int keycode, struct wl_client *topmost_client, + struct wl_array *keyroutes) +{ + return keyrouter_grab_get_keyroutes(&keyrouter->keygrab, + keycode, topmost_client, keyroutes); +} + static void -keyrouter_handle_keygrab_set(struct wl_client *wl_client, +keyrouter_client_handle_set_keygrab(struct wl_client *wl_client, struct wl_resource *resource, struct wl_resource *surface, uint32_t key, uint32_t mode) { - struct ds_tizen_keyrouter_client *client; - struct ds_tizen_keyrouter *keyrouter; - int res = TIZEN_KEYROUTER_ERROR_NONE; - bool ret; + struct keyrouter_client *client; + int err; client = wl_resource_get_user_data(resource); - keyrouter = client->keyrouter; - - ret = keyrouter_check_privilege(client, wl_client, mode, key); - if (ret == false) { - tizen_keyrouter_send_keygrab_notify(resource, surface, - key, mode, TIZEN_KEYROUTER_ERROR_NO_PERMISSION); - return; - } - - res = keyrouter_grab_grab_key(keyrouter->keygrab, - mode, key, (void *)wl_client); - - tizen_keyrouter_send_keygrab_notify(resource, surface, key, mode, res); + err = keyrouter_client_grab_key(client, mode, key); + tizen_keyrouter_send_keygrab_notify(resource, surface, key, mode, err); } static void -keyrouter_handle_keygrab_unset(struct wl_client *wl_client, +keyrouter_client_handle_unset_keygrab(struct wl_client *wl_client, struct wl_resource *resource, struct wl_resource *surface, uint32_t key) { - struct ds_tizen_keyrouter_client *client; - struct ds_tizen_keyrouter *keyrouter; - int res = TIZEN_KEYROUTER_ERROR_NONE; - bool ret; + struct keyrouter_client *client; + int err; client = wl_resource_get_user_data(resource); - keyrouter = client->keyrouter; - - /* ungrab TOP POSITION grab first, this grab mode is not check privilege */ - keyrouter_grab_ungrab_key(keyrouter->keygrab, - TIZEN_KEYROUTER_MODE_TOPMOST, key, (void *)wl_client); - - ret = keyrouter_check_privilege(client, - wl_client, TIZEN_KEYROUTER_MODE_NONE, key); - if (ret == false) { - tizen_keyrouter_send_keygrab_notify(resource, surface, key, - TIZEN_KEYROUTER_MODE_NONE, TIZEN_KEYROUTER_ERROR_NO_PERMISSION); - return; - } - - keyrouter_grab_ungrab_key(keyrouter->keygrab, - TIZEN_KEYROUTER_MODE_EXCLUSIVE, key, (void *)wl_client); - keyrouter_grab_ungrab_key(keyrouter->keygrab, - TIZEN_KEYROUTER_MODE_OVERRIDABLE_EXCLUSIVE, key, (void *)wl_client); - keyrouter_grab_ungrab_key(keyrouter->keygrab, - TIZEN_KEYROUTER_MODE_TOPMOST, key, (void *)wl_client); - keyrouter_grab_ungrab_key(keyrouter->keygrab, - TIZEN_KEYROUTER_MODE_SHARED, key, (void *)wl_client); - - tizen_keyrouter_send_keygrab_notify(resource, surface, key, TIZEN_KEYROUTER_MODE_NONE, res); + err = keyrouter_client_ungrab_key(client, key); + tizen_keyrouter_send_keygrab_notify(resource, surface, key, + TIZEN_KEYROUTER_MODE_NONE, err); } static void -keyrouter_handle_get_keygrab_status(struct wl_client *wl_client, +keyrouter_client_handle_get_keygrab_status(struct wl_client *wl_client, struct wl_resource *resource, struct wl_resource *surface, uint32_t key) { tizen_keyrouter_send_keygrab_notify(resource, surface, key, @@ -172,29 +121,22 @@ keyrouter_handle_get_keygrab_status(struct wl_client *wl_client, static int keyrouter_get_array_length(const struct wl_array *array) { - int *data = NULL; + int *data; int count = 0; - wl_array_for_each(data, array) { + wl_array_for_each(data, array) count++; - } return count; } static void -keyrouter_handle_keygrab_set_list(struct wl_client *wl_client, +keyrouter_client_handle_set_keygrab_list(struct wl_client *wl_client, struct wl_resource *resource, struct wl_resource *surface, struct wl_array *grab_list) { - struct ds_tizen_keyrouter_client *client; - struct ds_tizen_keyrouter *keyrouter; + struct keyrouter_client *client; + struct ds_tizen_grab_data *grab_data; struct wl_array *return_list; - struct ds_tizen_grab_data *grab_data = NULL; - int res = TIZEN_KEYROUTER_ERROR_NONE; - bool ret; - - client = wl_resource_get_user_data(resource); - keyrouter = client->keyrouter; if ((keyrouter_get_array_length(grab_list) % 3) != 0) { ds_err("Invalid keycode and grab mode pair. Check arguments in a list."); @@ -202,16 +144,11 @@ keyrouter_handle_keygrab_set_list(struct wl_client *wl_client, return; } + client = wl_resource_get_user_data(resource); + wl_array_for_each(grab_data, grab_list) { - ret = keyrouter_check_privilege(client, wl_client, grab_data->mode, grab_data->key); - if (ret == false) { - grab_data->err = TIZEN_KEYROUTER_ERROR_NO_PERMISSION; - } else { - res = keyrouter_grab_grab_key(keyrouter->keygrab, - grab_data->mode, grab_data->key, (void *)wl_client); - - grab_data->err = res; - } + grab_data->err = keyrouter_client_grab_key(client, grab_data->mode, + grab_data->key); } return_list = grab_list; @@ -220,18 +157,13 @@ keyrouter_handle_keygrab_set_list(struct wl_client *wl_client, } static void -keyrouter_handle_keygrab_unset_list(struct wl_client *wl_client, +keyrouter_client_handle_unset_keygrab_list(struct wl_client *wl_client, struct wl_resource *resource, struct wl_resource *surface, struct wl_array *ungrab_list) { - struct ds_tizen_keyrouter_client *client; - struct ds_tizen_keyrouter *keyrouter; - struct wl_array *return_list = NULL; - struct ds_tizen_ungrab_data *ungrab_data = NULL; - bool ret; - - client = wl_resource_get_user_data(resource); - keyrouter = client->keyrouter; + struct keyrouter_client *client; + struct wl_array *return_list; + struct ds_tizen_ungrab_data *ungrab_data; if ((keyrouter_get_array_length(ungrab_list) % 3) != 0) { ds_err("Invalid keycode and grab mode pair. Check arguments in a list."); @@ -239,29 +171,11 @@ keyrouter_handle_keygrab_unset_list(struct wl_client *wl_client, return; } - wl_array_for_each(ungrab_data, ungrab_list) { - keyrouter_grab_ungrab_key(keyrouter->keygrab, - TIZEN_KEYROUTER_MODE_TOPMOST, ungrab_data->key, (void *)wl_client); - - ret = keyrouter_check_privilege(client, wl_client, - TIZEN_KEYROUTER_MODE_TOPMOST, ungrab_data->key); - if (!ret) { - ungrab_data->err = TIZEN_KEYROUTER_ERROR_NO_PERMISSION; - } else { - keyrouter_grab_ungrab_key(keyrouter->keygrab, - TIZEN_KEYROUTER_MODE_EXCLUSIVE, ungrab_data->key, (void *)wl_client); - - keyrouter_grab_ungrab_key(keyrouter->keygrab, - TIZEN_KEYROUTER_MODE_OVERRIDABLE_EXCLUSIVE, ungrab_data->key, (void *)wl_client); - - keyrouter_grab_ungrab_key(keyrouter->keygrab, - TIZEN_KEYROUTER_MODE_TOPMOST, ungrab_data->key, (void *)wl_client); - - keyrouter_grab_ungrab_key(keyrouter->keygrab, - TIZEN_KEYROUTER_MODE_SHARED, ungrab_data->key, (void *)wl_client); + client = wl_resource_get_user_data(resource); - ungrab_data->err = TIZEN_KEYROUTER_ERROR_NONE; - } + wl_array_for_each(ungrab_data, ungrab_list) { + ungrab_data->err = keyrouter_client_ungrab_key(client, + ungrab_data->key); } return_list = ungrab_list; @@ -270,14 +184,14 @@ keyrouter_handle_keygrab_unset_list(struct wl_client *wl_client, } static void -keyrouter_handle_get_keygrab_list(struct wl_client *wl_client, +keyrouter_client_handle_get_keygrab_list(struct wl_client *wl_client, struct wl_resource *resource, struct wl_resource *surface) { tizen_keyrouter_send_getgrab_notify_list(resource, surface, NULL); } static void -keyrouter_handle_set_register_none_key(struct wl_client *wl_client, +keyrouter_client_handle_set_register_none_key(struct wl_client *wl_client, struct wl_resource *resource, struct wl_resource *surface, uint32_t data) { @@ -285,14 +199,14 @@ keyrouter_handle_set_register_none_key(struct wl_client *wl_client, } static void -keyrouter_handle_get_keyregister_status(struct wl_client *wl_client, +keyrouter_client_handle_get_keyregister_status(struct wl_client *wl_client, struct wl_resource *resource, uint32_t key) { tizen_keyrouter_send_keyregister_notify(resource, (int)false); } static void -keyrouter_handle_set_input_config(struct wl_client *wl_client, +keyrouter_client_handle_set_input_config(struct wl_client *wl_client, struct wl_resource *resource, struct wl_resource *surface, uint32_t config_mode, uint32_t value) { @@ -300,32 +214,32 @@ keyrouter_handle_set_input_config(struct wl_client *wl_client, } static void -keyrouter_handle_destory(struct wl_client *wl_client, +keyrouter_client_handle_destroy(struct wl_client *wl_client, struct wl_resource *resource) { wl_resource_destroy(resource); } static const struct tizen_keyrouter_interface tizen_keyrouter_impl = { - keyrouter_handle_keygrab_set, - keyrouter_handle_keygrab_unset, - keyrouter_handle_get_keygrab_status, - keyrouter_handle_keygrab_set_list, - keyrouter_handle_keygrab_unset_list, - keyrouter_handle_get_keygrab_list, - keyrouter_handle_set_register_none_key, - keyrouter_handle_get_keyregister_status, - keyrouter_handle_set_input_config, - keyrouter_handle_destory + .set_keygrab = keyrouter_client_handle_set_keygrab, + .unset_keygrab = keyrouter_client_handle_unset_keygrab, + .get_keygrab_status = keyrouter_client_handle_get_keygrab_status, + .set_keygrab_list = keyrouter_client_handle_set_keygrab_list, + .unset_keygrab_list = keyrouter_client_handle_unset_keygrab_list, + .get_keygrab_list = keyrouter_client_handle_get_keygrab_list, + .set_register_none_key = keyrouter_client_handle_set_register_none_key, + .get_keyregister_status = keyrouter_client_handle_get_keyregister_status, + .set_input_config = keyrouter_client_handle_set_input_config, + .destroy = keyrouter_client_handle_destroy }; static void -keyrouter_handle_resource_destory(struct wl_resource *resource) +keyrouter_client_handle_resource_destroy(struct wl_resource *resource) { - struct ds_tizen_keyrouter_client *client = wl_resource_get_user_data(resource); + struct keyrouter_client *client; - wl_list_remove(&client->link); - free(client); + client = wl_resource_get_user_data(resource); + destroy_keyrouter_client(client); } static void @@ -333,61 +247,33 @@ keyrouter_bind(struct wl_client *wl_client, void *data, uint32_t version, uint32_t id) { struct ds_tizen_keyrouter *keyrouter = data; - struct ds_tizen_keyrouter_client *client; - - client = calloc(1, sizeof *client); - if (client == NULL) { - wl_client_post_no_memory(wl_client); - return; - } - - client->keyrouter = keyrouter; - client->resource = - wl_resource_create(wl_client, &tizen_keyrouter_interface, - MIN(version, TIZEN_KEYROUTER_VERSION), id); - if (client->resource == NULL) { - ds_err("wl_resource_create() failed.(version :%d, id:%d)", version, id); - free(client); - wl_client_post_no_memory(wl_client); - return; - } - wl_resource_set_implementation(client->resource, &tizen_keyrouter_impl, - client, keyrouter_handle_resource_destory); - - wl_list_insert(&keyrouter->clients, &client->link); + create_keyrouter_client(keyrouter, wl_client, version, id); } -static bool -keyrouter_check_privilege(struct ds_tizen_keyrouter_client *client, - struct wl_client *wl_client, uint32_t mode, uint32_t keycode) +static void +keyrouter_handle_display_destroy(struct wl_listener *listener, void *data) { - struct ds_tizen_keyrouter *keyrouter = client->keyrouter; + struct ds_tizen_keyrouter *keyrouter; - pid_t pid = 0; - uid_t uid = 0; - gid_t gid = 0; + keyrouter = wl_container_of(listener, keyrouter, display_destroy); - /* Top position grab is always allowed. This mode do not need privilege.*/ - if (mode == TIZEN_KEYROUTER_MODE_TOPMOST) - return true; + ds_inf("Global destroy: ds_tizen_keyrouter(%p)", keyrouter); - // check no privilege option on the keycode - if (keyrouter->opts) { - if (keyrouter->opts[keycode].no_privilege) - return true; - } + wl_signal_emit(&keyrouter->events.destroy, keyrouter); - // already checked the privilege before. - if (client->privileged) - return true; + if (keyrouter->security_initialized) + tizen_security_finish(); - wl_client_get_credentials(wl_client, &pid, &uid, &gid); + free(keyrouter->opts); - client->privileged = tizen_security_check_privilege(pid, uid, - TIZEN_KEYROUTER_PRIVILEGE); + wl_list_remove(&keyrouter->display_destroy.link); - return client->privileged; + wl_global_destroy(keyrouter->global); + + keyrouter_grab_finish(&keyrouter->keygrab); + + free(keyrouter); } static void @@ -398,7 +284,7 @@ keyrouter_options_set(struct ds_tizen_keyrouter *keyrouter) char *ret, *tmp, *buf_ptr, buf[1024] = {0,}; keyrouter->opts = calloc(KEYROUTER_MAX_KEYS, - sizeof(struct ds_tizen_keyrouter_key_options)); + sizeof(struct keyrouter_key_options)); if (!keyrouter->opts) { return; } @@ -433,3 +319,107 @@ keyrouter_options_set(struct ds_tizen_keyrouter *keyrouter) fclose(file); } + +static void +create_keyrouter_client(struct ds_tizen_keyrouter *keyrouter, + struct wl_client *wl_client, uint32_t version, uint32_t id) +{ + struct keyrouter_client *client; + + client = calloc(1, sizeof *client); + if (!client) { + wl_client_post_no_memory(wl_client); + return; + } + + client->keyrouter = keyrouter; + client->wl_client = wl_client; + client->resource = wl_resource_create(wl_client, &tizen_keyrouter_interface, + MIN(version, TIZEN_KEYROUTER_VERSION), id); + if (!client->resource) { + ds_err("wl_resource_create() failed. (version :%d, id:%d)", + version, id); + free(client); + wl_client_post_no_memory(wl_client); + return; + } + + wl_resource_set_implementation(client->resource, &tizen_keyrouter_impl, + client, keyrouter_client_handle_resource_destroy); + + wl_list_insert(&keyrouter->clients, &client->link); +} + +static void +destroy_keyrouter_client(struct keyrouter_client *client) +{ + wl_list_remove(&client->link); + free(client); +} + +static bool +keyrouter_client_check_privilege(struct keyrouter_client *client, uint32_t mode, + uint32_t keycode) +{ + struct ds_tizen_keyrouter *keyrouter = client->keyrouter; + pid_t pid = 0; + uid_t uid = 0; + + /* Top position grab is always allowed. This mode do not need privilege.*/ + if (mode == TIZEN_KEYROUTER_MODE_TOPMOST) + return true; + + // check no privilege option on the keycode + if (keyrouter->opts && keyrouter->opts[keycode].no_privilege) + return true; + + // already checked the privilege before. + if (client->privileged) + return true; + + wl_client_get_credentials(client->wl_client, &pid, &uid, NULL); + + client->privileged = tizen_security_check_privilege(pid, uid, + TIZEN_KEYROUTER_PRIVILEGE); + + return client->privileged; +} + +static int +keyrouter_client_grab_key(struct keyrouter_client *client, int mode, + int keycode) +{ + struct ds_tizen_keyrouter *keyrouter = client->keyrouter; + + if (!keyrouter_client_check_privilege(client, mode, keycode)) + return TIZEN_KEYROUTER_ERROR_NO_PERMISSION; + + return keyrouter_grab_grab_key(&keyrouter->keygrab, mode, keycode, + client->wl_client); +} + +static int +keyrouter_client_ungrab_key(struct keyrouter_client *client, int keycode) +{ + struct ds_tizen_keyrouter *keyrouter = client->keyrouter; + + /* ungrab TOP POSITION grab first, this grab mode is not check privilege */ + keyrouter_grab_ungrab_key(&keyrouter->keygrab, + TIZEN_KEYROUTER_MODE_TOPMOST, keycode, client->wl_client); + + if (!keyrouter_client_check_privilege(client, TIZEN_KEYROUTER_MODE_NONE, + keycode)) + return TIZEN_KEYROUTER_ERROR_NO_PERMISSION; + + keyrouter_grab_ungrab_key(&keyrouter->keygrab, + TIZEN_KEYROUTER_MODE_EXCLUSIVE, keycode, client->wl_client); + keyrouter_grab_ungrab_key(&keyrouter->keygrab, + TIZEN_KEYROUTER_MODE_OVERRIDABLE_EXCLUSIVE, keycode, + client->wl_client); + keyrouter_grab_ungrab_key(&keyrouter->keygrab, + TIZEN_KEYROUTER_MODE_TOPMOST, keycode, client->wl_client); + keyrouter_grab_ungrab_key(&keyrouter->keygrab, + TIZEN_KEYROUTER_MODE_SHARED, keycode, client->wl_client); + + return TIZEN_KEYROUTER_ERROR_NONE; +} diff --git a/src/keyrouter/keyrouter.h b/src/keyrouter/keyrouter.h index 11fbadc..bea9ab1 100644 --- a/src/keyrouter/keyrouter.h +++ b/src/keyrouter/keyrouter.h @@ -5,37 +5,34 @@ #include #include +#include "libds-tizen/keyrouter.h" + #define KEYROUTER_MAX_KEYS 512 -struct ds_tizen_keyrouter_key_info +struct keyroute_info { - void *data; - struct wl_list link; + struct wl_client *wl_client; + struct wl_list link; }; -struct ds_tizen_keyrouter_grabbed +struct keyrouter_grabbed { - int keycode; - struct { - struct wl_list excl; - struct wl_list or_excl; - struct wl_list top; - struct wl_list shared; + struct wl_list excl; // keyroute_info::link + struct wl_list or_excl; // keyroute_info::link + struct wl_list top; // keyroute_info::link + struct wl_list shared; // keyroute_info::link } grab; struct wl_list pressed; }; -struct ds_tizen_keyrouter_grab +struct keyrouter_grab { - struct ds_tizen_keyrouter_grabbed *hard_keys; - - void *focus_client; - void *top_client; + struct keyrouter_grabbed hard_keys[KEYROUTER_MAX_KEYS]; }; -struct ds_tizen_keyrouter_key_options +struct keyrouter_key_options { bool enabled; bool no_privilege; @@ -53,18 +50,19 @@ struct ds_tizen_keyrouter struct wl_signal destroy; } events; - struct ds_tizen_keyrouter_key_options *opts; + struct keyrouter_key_options *opts; - struct ds_tizen_keyrouter_grab *keygrab; + struct keyrouter_grab keygrab; bool security_initialized; }; -struct ds_tizen_keyrouter_client +struct keyrouter_client { struct ds_tizen_keyrouter *keyrouter; struct wl_resource *resource; + struct wl_client *wl_client; bool privileged; @@ -84,27 +82,18 @@ struct ds_tizen_ungrab_data int err; }; -struct ds_tizen_keyrouter_grab * -keyrouter_grab_create(void); -void -keyrouter_grab_destroy(struct ds_tizen_keyrouter_grab *keygrab); -int -keyrouter_grab_grab_key(struct ds_tizen_keyrouter_grab *keygrab, - int type, int keycode, void *data); -void -keyrouter_grab_ungrab_key(struct ds_tizen_keyrouter_grab *keygrab, - int type, int keycode, void *data); -int -keyrouter_grab_key_process(struct ds_tizen_keyrouter_grab *keygrab, - int keycode, int pressed, struct wl_list *delivery_list); -void -keyrouter_grab_set_focus_client(struct ds_tizen_keyrouter_grab *keygrab, - void *focus_client); -void -keyrouter_grab_set_top_client(struct ds_tizen_keyrouter_grab *keygrab, - void *top_client); -bool -keyrouter_grab_check_grabbed_key(struct ds_tizen_keyrouter_grab *keygrab, - int keycode); +void keyrouter_grab_init(struct keyrouter_grab *keygrab); + +void keyrouter_grab_finish(struct keyrouter_grab *keygrab); + +int keyrouter_grab_grab_key(struct keyrouter_grab *keygrab, int mode, + int keycode, struct wl_client *wl_client); + +void keyrouter_grab_ungrab_key(struct keyrouter_grab *keygrab, int mode, + int keycode, struct wl_client *wl_client); + +enum ds_tizen_keyroute_mode +keyrouter_grab_get_keyroutes(struct keyrouter_grab *keygrab, int keycode, + struct wl_client *topmost_client, struct wl_array *keyroutes); #endif diff --git a/src/keyrouter/keyrouter_grab.c b/src/keyrouter/keyrouter_grab.c index ae29e8e..fed301b 100644 --- a/src/keyrouter/keyrouter_grab.c +++ b/src/keyrouter/keyrouter_grab.c @@ -1,3 +1,4 @@ +#include #include #include @@ -5,343 +6,324 @@ #include "keyrouter.h" +#define KEYGRAB_IS_VALID_KEYCODE(code) \ + ((code > 0) && (code < KEYROUTER_MAX_KEYS)) +#define KEYGRAB_LIST_FIRST(head, sample, member) \ + wl_container_of((head)->next, sample, member) + static struct wl_list * -keyrouter_grab_get_grabbed_list(struct ds_tizen_keyrouter_grab *keygrab, - int type, int keycode) +keyrouter_grab_get_mode_list(struct keyrouter_grab *keygrab, int mode, + int keycode); +static void mode_list_clean(struct wl_list *list); +static void mode_list_remove_wl_client(struct wl_list *list, + struct wl_client *wl_client); +static bool mode_list_check_duplicated(struct wl_list *list, + struct wl_client *wl_client); +static struct keyroute_info *create_keyroute_info(struct wl_client *wl_client); +static void destroy_key_info(struct keyroute_info *info); +static struct keyroute_info * +keyrouter_grab_get_exclusive_first(struct keyrouter_grab *keygrab, int keycode); +static struct keyroute_info * +keyrouter_grab_get_overridable_exclusive_first(struct keyrouter_grab *keygrab, + int keycode); +static struct keyroute_info * +keyrouter_grab_topmost_find(struct keyrouter_grab *keygrab, int keycode, + struct wl_client *topmost_client); +static bool keyrouter_grab_get_shared_keyroutes(struct keyrouter_grab *keygrab, + int keycode, struct wl_array *keyroutes); +static bool keyroutes_add_info(struct wl_array *keyroutes, + struct wl_client *wl_client); + +void +keyrouter_grab_init(struct keyrouter_grab *keygrab) { - switch(type) { - case TIZEN_KEYROUTER_MODE_EXCLUSIVE: - return &keygrab->hard_keys[keycode].grab.excl; - case TIZEN_KEYROUTER_MODE_OVERRIDABLE_EXCLUSIVE: - return &keygrab->hard_keys[keycode].grab.or_excl; - case TIZEN_KEYROUTER_MODE_TOPMOST: - return &keygrab->hard_keys[keycode].grab.top; - case TIZEN_KEYROUTER_MODE_SHARED: - return &keygrab->hard_keys[keycode].grab.shared; - default: - return NULL; + for (size_t i = 0; i < KEYROUTER_MAX_KEYS; i++) { + wl_list_init(&keygrab->hard_keys[i].grab.excl); + wl_list_init(&keygrab->hard_keys[i].grab.or_excl); + wl_list_init(&keygrab->hard_keys[i].grab.top); + wl_list_init(&keygrab->hard_keys[i].grab.shared); + wl_list_init(&keygrab->hard_keys[i].pressed); } } -bool -keyrouter_grab_check_grabbed_key(struct ds_tizen_keyrouter_grab *keygrab, int keycode) +void +keyrouter_grab_finish(struct keyrouter_grab *keygrab) { - struct wl_list *list; + for (size_t i = 0; i < KEYROUTER_MAX_KEYS; i++) { + mode_list_clean(&keygrab->hard_keys[i].grab.excl); + mode_list_clean(&keygrab->hard_keys[i].grab.or_excl); + mode_list_clean(&keygrab->hard_keys[i].grab.top); + mode_list_clean(&keygrab->hard_keys[i].grab.shared); + mode_list_clean(&keygrab->hard_keys[i].pressed); + } +} - list = keyrouter_grab_get_grabbed_list(keygrab, TIZEN_KEYROUTER_MODE_EXCLUSIVE, keycode); - if (list && !wl_list_empty(list)) - return true; +enum ds_tizen_keyroute_mode +keyrouter_grab_get_keyroutes(struct keyrouter_grab *keygrab, int keycode, + struct wl_client *topmost_client, struct wl_array *keyroutes) +{ + struct keyroute_info *info; - list = keyrouter_grab_get_grabbed_list(keygrab, TIZEN_KEYROUTER_MODE_OVERRIDABLE_EXCLUSIVE, keycode); - if (list && !wl_list_empty(list)) - return true; + if (!KEYGRAB_IS_VALID_KEYCODE(keycode)) { + ds_err("Invalid keycode(%d)", keycode); + goto none_out; + } - list = keyrouter_grab_get_grabbed_list(keygrab, TIZEN_KEYROUTER_MODE_TOPMOST, keycode); - if (list && !wl_list_empty(list)) - return true; + info = keyrouter_grab_get_exclusive_first(keygrab, keycode); + if (info) + goto exclusive_out; - list = keyrouter_grab_get_grabbed_list(keygrab, TIZEN_KEYROUTER_MODE_SHARED, keycode); - if (list && !wl_list_empty(list)) - return true; + info = keyrouter_grab_get_overridable_exclusive_first(keygrab, keycode); + if (info) + goto exclusive_out; - return false; -} + info = keyrouter_grab_topmost_find(keygrab, keycode, topmost_client); + if (info) + goto exclusive_out; -static bool -keyrouter_grab_check_duplicated_data(struct wl_list *list, void *data) -{ - struct ds_tizen_keyrouter_key_info *info; + if (keyrouter_grab_get_shared_keyroutes(keygrab, keycode, keyroutes)) + return DS_TIZEN_KEYROUTE_MODE_SHARED; - if (wl_list_empty(list)) - return false; +none_out: + return DS_TIZEN_KEYROUTE_MODE_NONE; - wl_list_for_each(info, list, link) { - if (info->data == data) - return true; - } +exclusive_out: + if (!keyroutes_add_info(keyroutes, info->wl_client)) + ds_err("Could not add wl_client to keyroutes"); - return false; + return DS_TIZEN_KEYROUTE_MODE_EXCLUSIVE; } -static bool -keyrouter_grab_check_grabbed(struct ds_tizen_keyrouter_grab *keygrab, - int type, int keycode, void *data) +int +keyrouter_grab_grab_key(struct keyrouter_grab *keygrab, int mode, int keycode, + struct wl_client *wl_client) { + struct keyroute_info *info; struct wl_list *list; - bool ret; - list = keyrouter_grab_get_grabbed_list(keygrab, type, keycode); - if (list == NULL) { - ds_err("keycode(%d) had no list for type(%d).", keycode, type); - return false; + if (!KEYGRAB_IS_VALID_KEYCODE(keycode)) { + ds_err("Invalid keycode(%d)", keycode); + return TIZEN_KEYROUTER_ERROR_INVALID_KEY; } - switch(type) { + switch (mode) { case TIZEN_KEYROUTER_MODE_EXCLUSIVE: - if (wl_list_empty(list) == false) - ret = true; - else - ret = false; + list = &keygrab->hard_keys[keycode].grab.excl; + if (!wl_list_empty(list)) + return TIZEN_KEYROUTER_ERROR_GRABBED_ALREADY; break; case TIZEN_KEYROUTER_MODE_OVERRIDABLE_EXCLUSIVE: - ret = keyrouter_grab_check_duplicated_data(list, data); - break; case TIZEN_KEYROUTER_MODE_TOPMOST: - ret = keyrouter_grab_check_duplicated_data(list, data); - break; case TIZEN_KEYROUTER_MODE_SHARED: - ret = keyrouter_grab_check_duplicated_data(list, data); + if (mode == TIZEN_KEYROUTER_MODE_OVERRIDABLE_EXCLUSIVE) + list = &keygrab->hard_keys[keycode].grab.or_excl; + else if (mode == TIZEN_KEYROUTER_MODE_TOPMOST) + list = &keygrab->hard_keys[keycode].grab.top; + else + list = &keygrab->hard_keys[keycode].grab.shared; + + if (mode_list_check_duplicated(list, wl_client)) + return TIZEN_KEYROUTER_ERROR_GRABBED_ALREADY; break; default: - ret = true; - break; + return TIZEN_KEYROUTER_ERROR_INVALID_MODE; } - return ret; -} + info = create_keyroute_info(wl_client); + if (!info) { + ds_err("Could not create key info"); + return TIZEN_KEYROUTER_ERROR_NO_SYSTEM_RESOURCES; + } -void -keyrouter_grab_set_focus_client(struct ds_tizen_keyrouter_grab *keygrab, - void *focus_client) -{ - keygrab->focus_client = focus_client; + wl_list_insert(list, &info->link); - if (focus_client) - ds_dbg("[%s] focus client has been set. (focus_client=0x%p)", __FUNCTION__, focus_client); - else - ds_dbg("[%s] focus client has been set to NULL.", __FUNCTION__); + return TIZEN_KEYROUTER_ERROR_NONE; } void -keyrouter_grab_set_top_client(struct ds_tizen_keyrouter_grab *keygrab, void *top_client) -{ - keygrab->top_client = top_client; - - if (top_client) - ds_dbg("[%s] top client has been set. (top_client=0x%p)", __FUNCTION__, top_client); - else - ds_dbg("[%s] top client has been set to NULL.", __FUNCTION__); -} - -int -keyrouter_grab_key_process(struct ds_tizen_keyrouter_grab *keygrab, - int keycode, int pressed, struct wl_list *delivery_list) +keyrouter_grab_ungrab_key(struct keyrouter_grab *keygrab, + int mode, int keycode, struct wl_client *wl_client) { - struct ds_tizen_keyrouter_key_info *info, *delivery; - int count = 0; + struct wl_list *list; - if (keycode <= 0 || keycode >= KEYROUTER_MAX_KEYS) { + if (!KEYGRAB_IS_VALID_KEYCODE(keycode)) { ds_err("Invalid keycode(%d)", keycode); - return 0; + return; } - if (!wl_list_empty(&keygrab->hard_keys[keycode].grab.excl)) { - delivery = calloc(1, sizeof(struct ds_tizen_keyrouter_key_info)); - if (delivery == NULL) { - ds_err("Failed to allocate memory."); - return 0; - } - info = wl_container_of(keygrab->hard_keys[keycode].grab.excl.next, info, link); - delivery->data = info->data; - wl_list_insert(delivery_list, &delivery->link); - ds_dbg("Exclusive Mode: keycode: %d to data: %p", keycode, info->data); - return 1; - } else if (!wl_list_empty(&keygrab->hard_keys[keycode].grab.or_excl)) { - delivery = calloc(1, sizeof(struct ds_tizen_keyrouter_key_info)); - if (delivery == NULL) { - ds_err("Failed to allocate memory."); - return 0; - } - info = wl_container_of(keygrab->hard_keys[keycode].grab.or_excl.next, info, link); - delivery->data = info->data; - wl_list_insert(delivery_list, &delivery->link); - ds_dbg("OR-Excl Mode: keycode: %d to data: %p", keycode, info->data); - return 1; - } else if (!wl_list_empty(&keygrab->hard_keys[keycode].grab.top)) { - wl_list_for_each(info, &keygrab->hard_keys[keycode].grab.top, link) { - if (keygrab->top_client && keygrab->top_client == info->data) { - delivery = calloc(1, sizeof(struct ds_tizen_keyrouter_key_info)); - if (delivery == NULL) { - ds_err("Failed to allocate memory."); - return 0; - } - delivery->data = info->data; - wl_list_insert(delivery_list, &delivery->link); - ds_dbg("Topmost Mode: keycode: %d to data: %p", keycode, info->data); - return 1; - } - } + list = keyrouter_grab_get_mode_list(keygrab, mode, keycode); + if (!list) { + ds_err("keycode(%d) had no list for mode(%d)", keycode, mode); + return; } - if (keygrab->focus_client) { - delivery = calloc(1, sizeof(struct ds_tizen_keyrouter_key_info)); - if (delivery == NULL) { - ds_err("Failed to allocate memory."); - return 0; - } - delivery->data = keygrab->focus_client; - wl_list_insert(delivery_list, &delivery->link); - count++; - ds_dbg("Focus: keycode: %d to data: %p, count: %d", keycode, delivery->data, count); - } + mode_list_remove_wl_client(list, wl_client); +} - if (!wl_list_empty(&keygrab->hard_keys[keycode].grab.shared)) { - wl_list_for_each(info, &keygrab->hard_keys[keycode].grab.shared, link) { - if (keygrab->focus_client && keygrab->focus_client == info->data) - continue; - delivery = calloc(1, sizeof(struct ds_tizen_keyrouter_key_info)); - if (delivery == NULL) { - ds_err("Failed to allocate memory."); - return 0; - } - delivery->data = info->data; - wl_list_insert(delivery_list, &delivery->link); - count++; - ds_dbg("Shared: keycode: %d to data: %p, count: %d", keycode, info->data, count); - } - } +static void +mode_list_clean(struct wl_list *list) +{ + struct keyroute_info *info, *tmp; - return count; + wl_list_for_each_safe(info, tmp, list, link) + destroy_key_info(info); } -int -keyrouter_grab_grab_key(struct ds_tizen_keyrouter_grab *keygrab, - int type, int keycode, void *data) +static void +mode_list_remove_wl_client(struct wl_list *list, struct wl_client *wl_client) { - struct ds_tizen_keyrouter_key_info *info = NULL; - struct wl_list *list = NULL; + struct keyroute_info *info, *tmp; - if (keycode <= 0 || keycode >= KEYROUTER_MAX_KEYS) { - ds_err("Invalid keycode(%d)", keycode); - return TIZEN_KEYROUTER_ERROR_INVALID_KEY; + wl_list_for_each_safe(info ,tmp, list, link) { + if (info->wl_client == wl_client) + destroy_key_info(info); } +} - if (keyrouter_grab_check_grabbed(keygrab, type, keycode, data)) - return TIZEN_KEYROUTER_ERROR_GRABBED_ALREADY; - - info = calloc(1, sizeof(struct ds_tizen_keyrouter_key_info)); - if (info == NULL) { - ds_err("Failed to allocate memory."); - return TIZEN_KEYROUTER_ERROR_NO_SYSTEM_RESOURCES; +static struct wl_list * +keyrouter_grab_get_mode_list(struct keyrouter_grab *keygrab, + int mode, int keycode) +{ + switch(mode) { + case TIZEN_KEYROUTER_MODE_EXCLUSIVE: + return &keygrab->hard_keys[keycode].grab.excl; + case TIZEN_KEYROUTER_MODE_OVERRIDABLE_EXCLUSIVE: + return &keygrab->hard_keys[keycode].grab.or_excl; + case TIZEN_KEYROUTER_MODE_TOPMOST: + return &keygrab->hard_keys[keycode].grab.top; + case TIZEN_KEYROUTER_MODE_SHARED: + return &keygrab->hard_keys[keycode].grab.shared; + default: + return NULL; } - info->data = data; +} - wl_list_init(&info->link); +static bool +mode_list_check_duplicated(struct wl_list *list, struct wl_client *wl_client) +{ + struct keyroute_info *info; - list = keyrouter_grab_get_grabbed_list(keygrab, type, keycode); - if (!list) { - ds_err("keycode(%d) had no list for type(%d)", keycode, type); - free(info); - return TIZEN_KEYROUTER_ERROR_INVALID_MODE; + wl_list_for_each(info, list, link) { + if (info->wl_client == wl_client) + return true; } - if (!keygrab->hard_keys[keycode].keycode) - keygrab->hard_keys[keycode].keycode = keycode; + return false; +} + +static struct keyroute_info * +create_keyroute_info(struct wl_client *wl_client) +{ + struct keyroute_info *info; - wl_list_insert(list, &info->link); + info = calloc(1, sizeof *info); + if (!info) + return NULL; - return TIZEN_KEYROUTER_ERROR_NONE; + info->wl_client = wl_client; + + return info; } static void -keyrouter_list_remove_data(struct wl_list *list, void *data) +destroy_key_info(struct keyroute_info *info) { - struct ds_tizen_keyrouter_key_info *info, *tmp; + wl_list_remove(&info->link); + free(info); +} + +static struct keyroute_info * +keyrouter_grab_get_exclusive_first(struct keyrouter_grab *keygrab, int keycode) +{ + struct wl_list *list = &keygrab->hard_keys[keycode].grab.excl; + struct keyroute_info *info; if (wl_list_empty(list)) - return; + return NULL; - wl_list_for_each_safe(info ,tmp, list, link) { - if (info->data == data) { - wl_list_remove(&info->link); - free(info); - } - } + info = KEYGRAB_LIST_FIRST(list, info, link); + + ds_dbg("Exclusive Mode: keycode: %d to wl_client: %p", + keycode, info->wl_client); + + return info; } -void -keyrouter_grab_ungrab_key(struct ds_tizen_keyrouter_grab *keygrab, - int type, int keycode, void *data) +static struct keyroute_info * +keyrouter_grab_get_overridable_exclusive_first(struct keyrouter_grab *keygrab, + int keycode) { - struct wl_list *list; + struct wl_list *list = &keygrab->hard_keys[keycode].grab.or_excl; + struct keyroute_info *info; - if (keycode <= 0 || keycode >= KEYROUTER_MAX_KEYS) { - ds_err("Invalid keycode(%d)", keycode); - return; - } + if (wl_list_empty(list)) + return NULL; - if (keygrab->hard_keys[keycode].keycode == 0) - return; + info = KEYGRAB_LIST_FIRST(list, info, link); - list = keyrouter_grab_get_grabbed_list(keygrab, type, keycode); - if (list == NULL) { - ds_err("keycode(%d) had no list for type(%d)", keycode, type); - return; - } + ds_dbg("OR-Excl Mode: keycode: %d to wl_client: %p", + keycode, info->wl_client); - keyrouter_list_remove_data(list, data); + return info; } -struct ds_tizen_keyrouter_grab * -keyrouter_grab_create(void) +static struct keyroute_info * +keyrouter_grab_topmost_find(struct keyrouter_grab *keygrab, + int keycode, struct wl_client *topmost_client) { - struct ds_tizen_keyrouter_grab *keygrab = NULL; - int i; + struct wl_list *list = &keygrab->hard_keys[keycode].grab.top; + struct keyroute_info *info; - keygrab = calloc(1, sizeof(struct ds_tizen_keyrouter_grab)); - if (keygrab == NULL) { - ds_err("Failed to allocate memory."); + if (!topmost_client) return NULL; - } - /* FIXME: Who defined max keycode? */ - keygrab->hard_keys = calloc(KEYROUTER_MAX_KEYS, sizeof(struct ds_tizen_keyrouter_grabbed)); - if (keygrab->hard_keys == NULL) { - ds_err("Failed to allocate memory."); - free(keygrab); - return NULL; - } + wl_list_for_each(info, list, link) { + if (info->wl_client != topmost_client) + continue; - for (i = 0; i < KEYROUTER_MAX_KEYS; i++) { - /* Enable all of keys to grab */ - //keygrab->hard_keys[i].keycode = i; - wl_list_init(&keygrab->hard_keys[i].grab.excl); - wl_list_init(&keygrab->hard_keys[i].grab.or_excl); - wl_list_init(&keygrab->hard_keys[i].grab.top); - wl_list_init(&keygrab->hard_keys[i].grab.shared); - wl_list_init(&keygrab->hard_keys[i].pressed); + ds_dbg("Topmost Mode: keycode: %d to wl_client: %p", + keycode, info->wl_client); + + return info; } - return keygrab; + return NULL; } -static void -keyrouter_grab_delete_list(struct wl_list *list) +static bool +keyrouter_grab_get_shared_keyroutes(struct keyrouter_grab *keygrab, + int keycode, struct wl_array *keyroutes) { - struct ds_tizen_keyrouter_key_info *info, *tmp; + struct wl_list *list = &keygrab->hard_keys[keycode].grab.shared; + struct keyroute_info *info; + int count = 0; - if (wl_list_empty(list)) - return; + wl_list_for_each(info, list, link) { + if (!keyroutes_add_info(keyroutes, info->wl_client)) { + ds_err("Could not prepend wl_client to delivery_list"); + continue; + } - wl_list_for_each_safe(info, tmp, list, link) { - wl_list_remove(&info->link); - free(info); + count++; + + ds_dbg("Shared: keycode: %d to wl_client: %p, count: %d", + keycode, info->wl_client, count); } + + return !!count; } -void -keyrouter_grab_destroy(struct ds_tizen_keyrouter_grab *keygrab) +static bool +keyroutes_add_info(struct wl_array *keyroutes, + struct wl_client *wl_client) { - int i; - - for (i = 0; i < KEYROUTER_MAX_KEYS; i++) { - keyrouter_grab_delete_list(&keygrab->hard_keys[i].grab.excl); - keyrouter_grab_delete_list(&keygrab->hard_keys[i].grab.or_excl); - keyrouter_grab_delete_list(&keygrab->hard_keys[i].grab.top); - keyrouter_grab_delete_list(&keygrab->hard_keys[i].grab.shared); - keyrouter_grab_delete_list(&keygrab->hard_keys[i].pressed); - } + struct ds_tizen_keyroute_info *info; + + info = wl_array_add(keyroutes, sizeof *info); + if (!info) + return false; + + info->wl_client = wl_client; - free(keygrab->hard_keys); - free(keygrab); + return true; } -- 2.7.4 From 2761e0c3dfae0d221b53c77b63149e0af8315c86 Mon Sep 17 00:00:00 2001 From: "duna.oh" Date: Tue, 28 Jun 2022 13:59:10 +0900 Subject: [PATCH 04/16] devicemgr: implement input generator (pointer & touch) Change-Id: Ia27ed1fd2baa29db0df19ee2b3e18cb7d020cad7 --- clients/input-generator.c | 152 ++++++-- examples/tinyds-tdm-libinput.c | 2 + include/libds-tizen/input-devicemgr.h | 4 + src/input-devicemgr/input-devicemgr.c | 674 +++++++++++++++++++++++++++++----- src/input-devicemgr/input-devicemgr.h | 25 +- 5 files changed, 727 insertions(+), 130 deletions(-) diff --git a/clients/input-generator.c b/clients/input-generator.c index f61e84b..73b7ab4 100644 --- a/clients/input-generator.c +++ b/clients/input-generator.c @@ -19,10 +19,10 @@ enum enum_key_type enum enum_touch_type { - TOUCH_BEGIN = 0, - TOUCH_UPDATE, - TOUCH_END, - TOUCH_ALL + POINTER_BEGIN = 0, + POINTER_UPDATE, + POINTER_END, + POINTER_ALL }; struct display @@ -60,8 +60,7 @@ usage(void) printf("init {device type}\n"); printf(" : device type:\n"); printf(" - default: all\n"); - printf(" - key/keyboard: keyboard\n"); - printf(" - touch: touch screen\n"); + printf(" - keyboard / touch / mouse\n"); printf(" - all: all of devices\n"); printf(" : ex> init keyboard / init\n"); printf("\n"); @@ -78,15 +77,33 @@ usage(void) printf("touch {index} {type} {x} {y}\n"); printf(" : index:\n"); printf(" - default: first finger(0)\n"); - printf(" - first finger is 0\n"); printf(" : type:\n"); printf(" - default: generate sample touch events\n"); - printf(" - touch begin: 1\n"); - printf(" - touch update: 2\n"); - printf(" - touch end: 3\n"); + printf(" - touch down: 0\n"); + printf(" - touch move: 1\n"); + printf(" - touch up: 2\n"); printf(" : x/y:\n"); printf(" - default: 0\n"); - printf(" : ex> touch / touch 0 1 100 100\n"); + printf(" : ex> touch\n"); + printf(" : ex> touch 0 0 400 400\n"); + printf(" : touch 0 1 410 410\n"); + printf(" : touch 0 2 0 0\n"); + printf("mouse {button} {type} {x} {y}\n"); + printf(" : button:\n"); + printf(" - default: left button(1)\n"); + printf(" : type:\n"); + printf(" - default: generate sample mouse events\n"); + printf(" - button down: 0\n"); + printf(" - mouse move: 1\n"); + printf(" - button up: 2\n"); + printf(" : x/y:\n"); + printf(" - default: 0\n"); + printf(" - relative motion\n"); + printf(" : ex> mouse\n"); + printf(" : ex> mouse 1 0 0 0\n"); + printf(" : mouse 1 1 10 10\n"); + printf(" : mouse 1 1 -10 -10\n"); + printf(" : mouse 1 2 0 0\n"); printf("\n"); } @@ -162,7 +179,7 @@ key_generate(char *name, int type) printf("name: %s, type: %d\n", name, type); if (!data_wl.init) { - printf("Input genrator is not initialized\n"); + printf("Input generator is not initialized\n"); return; } @@ -180,7 +197,7 @@ key_generate(char *name, int type) } static char * -touch_type_string_get(int type) +type_string_get(int type) { switch (type) { case TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_BEGIN: @@ -204,10 +221,10 @@ input_generator_touch(int idx, int type, int x, int y) if (data_wl.request_notified == TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE) { if (data_wl.enable_log) { - printf("Success to generate touch: %d finger %s on (%d, %d)\n", idx, touch_type_string_get(type), x, y); + printf("Success to generate touch: %d finger %s on (%d, %d)\n", idx, type_string_get(type), x, y); } } else { - printf("Failed to generate touch(%d finger %s on (%d, %d)): %d\n", idx, touch_type_string_get(type), x, y, data_wl.request_notified); + printf("Failed to generate touch(%d finger %s on (%d, %d)): %d\n", idx, type_string_get(type), x, y, data_wl.request_notified); } data_wl.request_notified = -1; @@ -217,38 +234,77 @@ static void touch_generate(int idx, int type, int x, int y) { if (!data_wl.init) { - printf("Input genrator is not initialized\n"); + printf("Input generator is not initialized\n"); return; } - if (type == TOUCH_ALL) { - input_generator_touch(0, TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_BEGIN, 100, 100); - input_generator_touch(1, TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_BEGIN, 200, 200); - input_generator_touch(2, TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_BEGIN, 300, 300); + if (type == POINTER_ALL) { + input_generator_touch(0, TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_BEGIN, 300, 300); + input_generator_touch(1, TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_BEGIN, 400, 400); + input_generator_touch(2, TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_BEGIN, 500, 500); - input_generator_touch(0, TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_UPDATE, 110, 110); - input_generator_touch(1, TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_UPDATE, 210, 210); - input_generator_touch(2, TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_UPDATE, 310, 310); + input_generator_touch(0, TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_UPDATE, 310, 310); + input_generator_touch(1, TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_UPDATE, 410, 410); + input_generator_touch(2, TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_UPDATE, 510, 510); - input_generator_touch(0, TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_UPDATE, 120, 120); - input_generator_touch(1, TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_UPDATE, 220, 220); - input_generator_touch(2, TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_UPDATE, 320, 320); + input_generator_touch(0, TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_UPDATE, 320, 320); + input_generator_touch(1, TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_UPDATE, 420, 420); + input_generator_touch(2, TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_UPDATE, 520, 520); - input_generator_touch(0, TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_END, 120, 120); - input_generator_touch(1, TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_END, 220, 220); - input_generator_touch(2, TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_END, 320, 320); + input_generator_touch(0, TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_END, 320, 320); + input_generator_touch(1, TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_END, 420, 420); + input_generator_touch(2, TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_END, 520, 520); } else { input_generator_touch(idx, type, x, y); } } static void +input_generator_mouse(int type, int x, int y, int button) +{ + tizen_input_device_manager_generate_pointer(data_wl.devicemgr, type, x, y, button); + + while (data_wl.request_notified == -1) + wl_display_dispatch_queue(data_wl.display, data_wl.queue); + + if (data_wl.request_notified == TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE) { + if (data_wl.enable_log) { + printf("Success to generate mouse: %s on (%d, %d)\n", type_string_get(type), x, y); + } + } else { + printf("Failed to generate mouse(%s on (%d, %d)): %d\n", type_string_get(type), x, y, data_wl.request_notified); + } + + data_wl.request_notified = -1; +} + +static void +mouse_generate(int btn, int type, int x, int y) +{ + if (!data_wl.init) { + printf("Input generator is not initialized\n"); + return; + } + + if (type == POINTER_ALL) { + input_generator_mouse(TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_BEGIN, -1, -1, 1); + input_generator_mouse(TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_UPDATE, 10, 10, 1); + input_generator_mouse(TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_UPDATE, 10, 10, 1); + input_generator_mouse(TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_UPDATE, 10, 10, 1); + input_generator_mouse(TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_END, -1, -1, 1); + + } else { + input_generator_mouse(type, x, y, btn); + } +} + +static void stdin_read(void) { int c; char buf[MAX_STR] = {0, }, *tmp, *buf_ptr, key_name[MAX_STR] = {0, }; int count = 0; - int key_type = KEY_ALL, touch_idx = 0, touch_type = TOUCH_ALL, touch_x = 0, touch_y = 0; + int key_type = KEY_ALL, idx = 0, type = POINTER_ALL, x = 0, y = 0; while ((c = getchar()) != EOF) { if (c == '\n') break; @@ -272,6 +328,8 @@ stdin_read(void) init_input_generator(TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD); else if (!strncmp("touch", tmp, MAX_STR-1)) init_input_generator(TIZEN_INPUT_DEVICE_MANAGER_CLAS_TOUCHSCREEN); + else if (!strncmp("mouse", tmp, MAX_STR-1)) + init_input_generator(TIZEN_INPUT_DEVICE_MANAGER_CLAS_MOUSE); break; default: break; @@ -305,16 +363,40 @@ stdin_read(void) if (tmp) { switch (count) { case 0: - touch_idx = atoi(tmp); + idx = atoi(tmp); + break; + case 1: + type = atoi(tmp); + break; + case 2: + x = atoi(tmp); + break; + case 3: + y = atoi(tmp); + break; + default: + break; + } + } + count++; + } + touch_generate(idx, type, x, y); + } else if (!strncmp(tmp, "mouse", sizeof("mouse"))) { + while (tmp) { + tmp = strtok_r(NULL, " ", &buf_ptr); + if (tmp) { + switch (count) { + case 0: + idx = atoi(tmp); break; case 1: - touch_type = atoi(tmp); + type = atoi(tmp); break; case 2: - touch_x = atoi(tmp); + x = atoi(tmp); break; case 3: - touch_y = atoi(tmp); + y = atoi(tmp); break; default: break; @@ -322,7 +404,7 @@ stdin_read(void) } count++; } - touch_generate(touch_idx, touch_type, touch_x, touch_y); + mouse_generate(idx, type, x, y); } else if (!strncmp(buf, "q", MAX_STR) || !strncmp(buf, "quit", MAX_STR)) { data_wl.run = 0; } else if (!strncmp(buf, "help", MAX_STR)) { diff --git a/examples/tinyds-tdm-libinput.c b/examples/tinyds-tdm-libinput.c index 5634707..3feb932 100644 --- a/examples/tinyds-tdm-libinput.c +++ b/examples/tinyds-tdm-libinput.c @@ -352,6 +352,8 @@ backend_handle_new_output(struct wl_listener *listener, void *data) output->output_frame.notify = output_handle_frame; ds_output_add_frame_listener(ds_output, &output->output_frame); + ds_tizen_input_devicemgr_set_output_width_height(server->devicemgr, (uint32_t)output->width, (uint32_t)output->height); + server->output = output; draw_output(output); diff --git a/include/libds-tizen/input-devicemgr.h b/include/libds-tizen/input-devicemgr.h index a9ed808..fc1060e 100644 --- a/include/libds-tizen/input-devicemgr.h +++ b/include/libds-tizen/input-devicemgr.h @@ -33,6 +33,10 @@ ds_tizen_input_devicemgr_set_keymap_list( struct ds_tizen_input_devicemgr *devicemgr, struct wl_list *list); +bool +ds_tizen_input_devicemgr_set_output_width_height( + struct ds_tizen_input_devicemgr *devicemgr, + uint32_t width, uint32_t height); #ifdef __cplusplus } #endif diff --git a/src/input-devicemgr/input-devicemgr.c b/src/input-devicemgr/input-devicemgr.c index 3e69d0e..c825b4c 100644 --- a/src/input-devicemgr/input-devicemgr.c +++ b/src/input-devicemgr/input-devicemgr.c @@ -5,6 +5,8 @@ #include #include #include +#include +#include #include "util.h" #include "input-devicemgr.h" @@ -12,6 +14,7 @@ #define TIZEN_INPUT_DEVICEMGR_VERSION 4 #define TIZEN_PRIV_INPUT_GENERATOR "http://tizen.org/privilege/inputgenerator" #define TIZEN_PRIV_INPUT_BLOCK "http://tizen.org/privilege/internal/inputdevice.block" +#define TIZEN_INPUT_DEVICEMGR_MAX_BTN 16 static const struct ds_keyboard_grab_interface devicemgr_keyboard_grab_iface; @@ -52,6 +55,14 @@ device_manager_handle_generate_key(struct wl_client *client, struct wl_resource *resource, const char *keyname, uint32_t pressed); static void +device_manager_handle_generate_touch(struct wl_client *client, + struct wl_resource *resource, uint32_t type, uint32_t x, uint32_t y, + uint32_t finger); +static void +device_manager_handle_generate_pointer(struct wl_client *client, + struct wl_resource *resource, uint32_t type, uint32_t x, uint32_t y, + uint32_t button); +static void device_manager_handle_destroy(struct wl_client *client, struct wl_resource *resource); @@ -59,7 +70,7 @@ device_manager_handle_destroy(struct wl_client *client, static void tz_devicemgr_destroy(struct ds_tizen_input_devicemgr *tz_devicemgr); static int tz_devicemgr_init_generator(struct ds_tizen_input_devicemgr *tz_devicemgr, - struct wl_resource *resource, const char *name); + struct wl_resource *resource, uint32_t clas, const char *name); static int tz_devicemgr_deinit_generator(struct ds_tizen_input_devicemgr *tz_devicemgr, struct wl_resource *resource); @@ -77,6 +88,19 @@ static int tz_devicemgr_keyname_to_keycode(struct wl_list *list, const char *name); static bool +tz_devicemgr_generate_touch_move(struct ds_input_device *device, double x, double y, + uint32_t finger); +static bool +tz_devicemgr_generate_touch_down(struct ds_input_device *device, double x, double y, + uint32_t finger); +static bool +tz_devicemgr_generate_touch_up(struct ds_input_device *device, uint32_t finger); +static bool +tz_devicemgr_generate_mouse_move(struct ds_input_device *device, double x, double y); +static bool +tz_devicemgr_generate_mouse_button(struct ds_input_device *device, uint32_t button, bool state); + +static bool tz_devicemgr_check_privilege(struct ds_tizen_input_devicemgr *tz_devicemgr, struct wl_client *client, const char *rule); @@ -125,6 +149,17 @@ ds_tizen_input_devicemgr_create(struct ds_backend *backend, if (!tz_devicemgr->devices.kbd) { goto err_kbd; } + tz_devicemgr->devices.ptr = calloc(1, + sizeof(struct ds_tizen_input_devicemgr_device)); + if (!tz_devicemgr->devices.ptr) { + goto err_ptr; + } + tz_devicemgr->devices.touch = calloc(1, + sizeof(struct ds_tizen_input_devicemgr_device)); + if (!tz_devicemgr->devices.touch) { + goto err_touch; + } + tz_devicemgr->touch_max_count = 5;//TODO: make this variable configurable tz_devicemgr->grab = ds_seat_create_keyboard_grab( tz_devicemgr->seat, &devicemgr_keyboard_grab_iface, tz_devicemgr); @@ -134,7 +169,7 @@ ds_tizen_input_devicemgr_create(struct ds_backend *backend, wl_signal_init(&tz_devicemgr->events.destroy); wl_list_init(&tz_devicemgr->clients); - wl_list_init(&tz_devicemgr->pressed_keys); + wl_list_init(&tz_devicemgr->devices.kbd->key.pressed); wl_list_init(&tz_devicemgr->keymap_list); wl_list_init(&tz_devicemgr->blocked_keys); @@ -146,6 +181,10 @@ ds_tizen_input_devicemgr_create(struct ds_backend *backend, return tz_devicemgr; err_grab: + free(tz_devicemgr->devices.touch); +err_touch: + free(tz_devicemgr->devices.ptr); +err_ptr: free(tz_devicemgr->devices.kbd); err_kbd: wl_global_destroy(tz_devicemgr->global); @@ -192,6 +231,21 @@ ds_tizen_input_devicemgr_set_keymap_list( return true; } +WL_EXPORT bool +ds_tizen_input_devicemgr_set_output_width_height( + struct ds_tizen_input_devicemgr *tz_devicemgr, + uint32_t width, uint32_t height) +{ + if (!tz_devicemgr) return false; + + tz_devicemgr->output.width = width; + tz_devicemgr->output.height = height; + + ds_inf("output's width: %d, height:%d", width, height); + + return true; +} + static void tz_devicemgr_destroy(struct ds_tizen_input_devicemgr *tz_devicemgr) { @@ -219,6 +273,8 @@ tz_devicemgr_destroy(struct ds_tizen_input_devicemgr *tz_devicemgr) free(client_data); } + free(tz_devicemgr->devices.touch); + free(tz_devicemgr->devices.ptr); free(tz_devicemgr->devices.kbd); free(tz_devicemgr); } @@ -248,6 +304,14 @@ seat_handle_destroy(struct wl_listener *listener, void *data) } static void +tz_devicemgr_device_close(struct ds_tizen_input_devicemgr_device *dev) +{ + if (!dev->input_device) return; + ds_input_device_destroy(dev->input_device); + dev->input_device = NULL; +} + +static void backend_handle_input_device_add(struct wl_listener *listener, void *data) { struct ds_input_device *dev = data; @@ -259,14 +323,18 @@ backend_handle_input_device_add(struct wl_listener *listener, void *data) dev_type = ds_input_device_get_type(dev); if (dev_type == DS_INPUT_DEVICE_KEYBOARD) { if (tz_devicemgr->devices.kbd->input_device) return; - ds_inf("devicemgr's kbd device is set"); + ds_inf("devicemgr's kbd device is set to dev(%p)", dev); tz_devicemgr->devices.kbd->input_device = dev; } else if (dev_type == DS_INPUT_DEVICE_POINTER) { - //TODO: assign input_device 'dev' to devices.ptr + if (tz_devicemgr->devices.ptr->input_device) return; + ds_inf("devicemgr's ptr device is set to dev(%p)", dev); + tz_devicemgr->devices.ptr->input_device = dev; } else if (dev_type == DS_INPUT_DEVICE_TOUCH) { - //TODO: assign input_device 'dev' to devices.ptr + if (tz_devicemgr->devices.touch->input_device) return; + ds_inf("devicemgr's touch device is set to dev(%p)", dev); + tz_devicemgr->devices.touch->input_device = dev; } } @@ -276,8 +344,8 @@ static const struct tizen_input_device_manager_interface _devicemgr_impl = { .init_generator = device_manager_handle_init_generator, .deinit_generator = device_manager_handle_deinit_generator, .generate_key = device_manager_handle_generate_key, - .generate_pointer = NULL, - .generate_touch = NULL, + .generate_pointer = device_manager_handle_generate_pointer, + .generate_touch = device_manager_handle_generate_touch, .pointer_warp = NULL, .init_generator_with_name = device_manager_handle_init_generator_with_name, // v2 @@ -359,13 +427,7 @@ device_manager_handle_init_generator(struct wl_client *client, goto finish; } - if (clas != TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD) { - ds_err("only support keyboard device. (requested: 0x%x)\n", clas); - ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_PARAMETER; - goto finish; - } - - ret = tz_devicemgr_init_generator(tz_devicemgr, resource, + ret = tz_devicemgr_init_generator(tz_devicemgr, resource, clas, "Input Generator"); if (ret != TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE) { ds_err("Failed to init input generator\n"); @@ -398,13 +460,7 @@ device_manager_handle_init_generator_with_name(struct wl_client *client, goto finish; } - if (clas != TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD) { - ds_err("only support keyboard device. (requested: 0x%x)\n", clas); - ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_PARAMETER; - goto finish; - } - - ret = tz_devicemgr_init_generator(tz_devicemgr, resource, + ret = tz_devicemgr_init_generator(tz_devicemgr, resource, clas, name); if (ret != TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE) { ds_err("Failed to init input generator\n"); @@ -417,7 +473,7 @@ finish: static void device_manager_handle_deinit_generator(struct wl_client *client, - struct wl_resource *resource, uint32_t clas) + struct wl_resource *resource, uint32_t clas __attribute__((unused))) { struct ds_tizen_input_devicemgr *tz_devicemgr; int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES; @@ -431,12 +487,6 @@ device_manager_handle_deinit_generator(struct wl_client *client, goto finish; } - if (clas != TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD) { - ds_err("only support keyboard device. (requested: 0x%x)\n", clas); - ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_PARAMETER; - goto finish; - } - ret = tz_devicemgr_deinit_generator(tz_devicemgr, resource); if (ret != TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE) { ds_err("Failed to deinit input generator\n"); @@ -498,6 +548,19 @@ tz_devicemgr_xkb_keyname_to_keycode(struct xkb_keymap *keymap, return keycode; } +static uint32_t +tz_devicemgr_client_get_device_clas(struct ds_tizen_input_devicemgr *tz_devicemgr, + struct wl_resource *resource) +{ + struct ds_tizen_input_devicemgr_client *client_data; + + wl_list_for_each(client_data, &tz_devicemgr->clients, link) { + if (client_data->resource == resource) + return client_data->clas; + } + return 0; +} + static void device_manager_handle_generate_key(struct wl_client *client, struct wl_resource *resource, const char *keyname, uint32_t pressed) @@ -507,9 +570,17 @@ device_manager_handle_generate_key(struct wl_client *client, int keycode = 0; bool res; struct ds_keyboard *kbd; + uint32_t clas; tz_devicemgr = wl_resource_get_user_data(resource); + clas = tz_devicemgr_client_get_device_clas(tz_devicemgr, resource); + if ((clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD) == 0) + { + ds_err("Keyboard generator is not initialized by client"); + goto finish; + } + if (!tz_devicemgr->devices.kbd || !tz_devicemgr->devices.kbd->input_device) { ds_err("Keyboard device is not initialized\n"); @@ -557,6 +628,144 @@ finish: } static void +device_manager_handle_generate_pointer(struct wl_client *client, + struct wl_resource *resource, uint32_t type, uint32_t x, uint32_t y, + uint32_t button) +{ + struct ds_tizen_input_devicemgr *tz_devicemgr; + int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES; + bool res; + bool state; + uint32_t clas; + + tz_devicemgr = wl_resource_get_user_data(resource); + + clas = tz_devicemgr_client_get_device_clas(tz_devicemgr, resource); + if ((clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_MOUSE) == 0) + { + ds_err("Pointer generator is not initialized by client"); + goto finish; + } + + if (!tz_devicemgr->devices.ptr || + !tz_devicemgr->devices.ptr->input_device) { + ds_err("Pointer device is not initialized\n"); + goto finish; + } + + if (!tz_devicemgr_check_privilege(tz_devicemgr, client, + TIZEN_PRIV_INPUT_GENERATOR)) { + ds_err("No permission to input generate"); + ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_PERMISSION; + goto finish; + } + + if (button <= 0 || button >= TIZEN_INPUT_DEVICEMGR_MAX_BTN) + { + ds_err("Invalid button: %d\n", button); + ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_PARAMETER; + goto finish; + } + + if (type == TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_UPDATE) { + res = tz_devicemgr_generate_mouse_move( + tz_devicemgr->devices.ptr->input_device, (double)x, (double)y); + if (!res) goto finish; + ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE; + } + else { + state = (type == TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_BEGIN) ? + true : false; + res = tz_devicemgr_generate_mouse_button( + tz_devicemgr->devices.ptr->input_device, button, state); + if (!res) goto finish; + if (state) tz_devicemgr->devices.ptr->mouse.pressed |= 1 << (button - 1); + else tz_devicemgr->devices.ptr->mouse.pressed &= ~(1 << (button - 1)); + ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE; + } + +finish: + tizen_input_device_manager_send_error(resource, ret); +} + +static void +device_manager_handle_generate_touch(struct wl_client *client, + struct wl_resource *resource, uint32_t type, uint32_t x, uint32_t y, + uint32_t finger) +{ + struct ds_tizen_input_devicemgr *tz_devicemgr; + double transformed_x = .0, transformed_y = .0; + int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES; + bool res; + uint32_t clas; + + tz_devicemgr = wl_resource_get_user_data(resource); + + clas = tz_devicemgr_client_get_device_clas(tz_devicemgr, resource); + if ((clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_TOUCHSCREEN) == 0) + { + ds_err("Touch generator is not initialized by client"); + goto finish; + } + + if (!tz_devicemgr->devices.touch || + !tz_devicemgr->devices.touch->input_device) { + ds_err("Touch device is not initialized\n"); + goto finish; + } + + if (!tz_devicemgr_check_privilege(tz_devicemgr, client, + TIZEN_PRIV_INPUT_GENERATOR)) { + ds_err("No permission to input generate"); + ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_PERMISSION; + goto finish; + } + + if (finger >= tz_devicemgr->touch_max_count) + { + ds_err("Invalid fingers: %d\n", finger); + ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_PARAMETER; + goto finish; + } + + if (tz_devicemgr->output.width != 0 && tz_devicemgr->output.height != 0) { + transformed_x = x / (double)tz_devicemgr->output.width; + transformed_y = y / (double)tz_devicemgr->output.height; + } + + switch(type) { + case TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_BEGIN: // 0 + res = tz_devicemgr_generate_touch_move( + tz_devicemgr->devices.touch->input_device, transformed_x, transformed_y, finger); + if (!res) break; + res= tz_devicemgr_generate_touch_down( + tz_devicemgr->devices.touch->input_device, transformed_x, transformed_y, finger); + if (!res) break; + tz_devicemgr->devices.touch->touch.pressed |= 1 << finger; + ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE; + break; + case TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_END: // 2 + res = tz_devicemgr_generate_touch_up( + tz_devicemgr->devices.touch->input_device, finger); + if (!res) break; + tz_devicemgr->devices.touch->touch.pressed &= ~(1 << finger); + ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE; + break; + case TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_UPDATE: // 1 + res = tz_devicemgr_generate_touch_move( + tz_devicemgr->devices.touch->input_device, transformed_x, transformed_y, finger); + if (!res) break; + ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE; + break; + default: + break; + } + +finish: + tizen_input_device_manager_send_error(resource, ret); +} + +static void device_manager_handle_destroy(struct wl_client *client, struct wl_resource *resource) { @@ -597,58 +806,242 @@ create_ds_keyboard() return kbd; } +static struct ds_pointer * +create_ds_pointer() +{ + struct ds_pointer *pointer; + pointer = calloc(1, sizeof *pointer); + if (!pointer) { + ds_err("Could not allocate memory"); + return NULL; + } + ds_pointer_init(pointer, NULL); + + return pointer; +} + +static struct ds_touch * +create_ds_touch() +{ + struct ds_touch *touch; + touch = calloc(1, sizeof *touch); + if (!touch) { + ds_err("Could not allocate memory"); + return NULL; + } + ds_touch_init(touch, NULL); + + return touch; +} + static int -tz_devicemgr_init_generator(struct ds_tizen_input_devicemgr *tz_devicemgr, - struct wl_resource *resource, const char *name) +tz_devicemgr_create_device(struct ds_tizen_input_devicemgr_device *dev, + uint32_t clas, const char *name) { int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES; - struct ds_tizen_input_devicemgr_client *client_data; - struct ds_tizen_input_devicemgr_device *kbd; - - ds_inf("Init generator. name:%s", name); + const char *dev_name; - kbd = tz_devicemgr->devices.kbd; - if (strlen(kbd->name) > 0) { - ds_inf("devices.kbd already has name. name:%s", kbd->name); + if (dev->name && strlen(dev->name) > 0) { + ds_inf("device already has name. name:%s", dev->name); return TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE; } - if (kbd->input_device) { - ds_inf("devices.kbd is already set. name:%s", - ds_input_device_get_name(kbd->input_device)); + if (dev->input_device) { + dev_name = ds_input_device_get_name(dev->input_device); + ds_inf("device was already set. name:%s", dev_name); + dev->name = strdup(dev_name); return TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE; } //input_device create - kbd->input_device = calloc(1, sizeof(struct ds_input_device)); - if(!kbd->input_device) { + dev->input_device = calloc(1, sizeof(struct ds_input_device)); + if(!dev->input_device) { ds_err("Failed to create input device !\n"); return ret; } - ds_input_device_init(kbd->input_device, DS_INPUT_DEVICE_KEYBOARD, - &input_device_iface, name, -1, -1); - kbd->input_device->keyboard = create_ds_keyboard(); + if (clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD) + { + ds_input_device_init(dev->input_device, DS_INPUT_DEVICE_KEYBOARD, + &input_device_iface, name, -1, -1); + dev->input_device->keyboard = create_ds_keyboard(); + } + else if (clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_MOUSE) + { + ds_input_device_init(dev->input_device, DS_INPUT_DEVICE_POINTER, + &input_device_iface, name, -1, -1); + dev->input_device->pointer = create_ds_pointer(); + } + else if (clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_TOUCHSCREEN) + { + ds_input_device_init(dev->input_device, DS_INPUT_DEVICE_TOUCH, + &input_device_iface, name, -1, -1); + dev->input_device->touch = create_ds_touch(); + } - wl_signal_emit(&tz_devicemgr->backend->events.new_input, - kbd->input_device); + dev->created = true; + dev->name = strdup(name); - kbd->created = true; - strncpy(kbd->name, name, UINPUT_MAX_NAME_SIZE); + return TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE; +} +static int +tz_devicemgr_init_generator(struct ds_tizen_input_devicemgr *tz_devicemgr, + struct wl_resource *resource, uint32_t clas, const char *name) +{ + int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES; + struct ds_tizen_input_devicemgr_client *client_data; + struct ds_tizen_input_devicemgr_device *dev; + bool inited = false; + + ds_inf("Init generator. name:%s", name); + + if (clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD) { + dev = tz_devicemgr->devices.kbd; + ret = tz_devicemgr_create_device(dev, clas, name); + if (ret == TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE) { + inited = true; + tz_devicemgr->devices.kbd->ref++; + } + if (dev->created) { + wl_signal_emit(&tz_devicemgr->backend->events.new_input, + dev->input_device); + } + } + if (clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_MOUSE) { + dev = tz_devicemgr->devices.ptr; + ret = tz_devicemgr_create_device(dev, clas, name); + if (ret == TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE) { + inited = true; + tz_devicemgr->devices.ptr->ref++; + } + if (dev->created) { + wl_signal_emit(&tz_devicemgr->backend->events.new_input, + dev->input_device); + } + } + if (clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_TOUCHSCREEN) { + dev = tz_devicemgr->devices.touch; + ret = tz_devicemgr_create_device(dev, clas, name); + if (ret == TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE) { + inited = true; + tz_devicemgr->devices.touch->ref++; + } + if (dev->created) { + wl_signal_emit(&tz_devicemgr->backend->events.new_input, + dev->input_device); + } + } + + if (inited) { + wl_list_for_each(client_data, &tz_devicemgr->clients, link) { + if (client_data->resource == resource) { + if (client_data->init == false) { + client_data->init = true; + client_data->clas = clas; + } + break; + } + } + } + + return ret; +} + +static int +tz_devicemgr_deinit_generator(struct ds_tizen_input_devicemgr *tz_devicemgr, + struct wl_resource *resource) +{ + int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES; + struct ds_tizen_input_devicemgr_client *client_data; + struct ds_tizen_input_devicemgr_device *dev; + uint32_t clas = 0; + int i = 0; + bool res; + + ds_inf("Deinit generator."); wl_list_for_each(client_data, &tz_devicemgr->clients, link) { if (client_data->resource == resource) { - if (client_data->init == false) { - client_data->init = true; - tz_devicemgr->ref++; + if (client_data->init == true) { + client_data->init = false; + clas = client_data->clas; + break; + } else { + return ret; } - break; } } + if (clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD) { + dev = tz_devicemgr->devices.kbd; + dev->ref--; + if (dev->ref<= 0) { + dev->ref = 0; + tz_devicemgr_pressed_keys_cleanup(tz_devicemgr); + + if (dev->created) { + tz_devicemgr_device_close(dev); + dev->created = false; + } + free(dev->name); + dev->name = NULL; + } + } + if (clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_MOUSE) { + dev = tz_devicemgr->devices.ptr; + dev->ref--; + if (dev->ref <= 0) { + dev->ref = 0; + while(dev->mouse.pressed) + { + if (dev->mouse.pressed & (1 << i)) + { + res = tz_devicemgr_generate_mouse_button(dev->input_device, + i + 1, false); + if (!res) break; + dev->mouse.pressed &= ~(1 << i); + } + i++; + if (i >= TIZEN_INPUT_DEVICEMGR_MAX_BTN) break; + } - ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE; + if (dev->created) + { + tz_devicemgr_device_close(dev); + dev->created = false; + } + free(dev->name); + dev->name = NULL; + } + } + if (clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_TOUCHSCREEN) { + dev = tz_devicemgr->devices.touch; + dev->ref--; + if (dev->ref <= 0) { + dev->ref = 0; + while(dev->touch.pressed) + { + if (dev->touch.pressed & (1 << i)) + { + res = tz_devicemgr_generate_touch_up(dev->input_device, + i); + if (!res) break; + dev->touch.pressed &= ~(1 << i); + } + i++; + if (i >= tz_devicemgr->touch_max_count) break; + } - return ret; + if (dev->created) + { + tz_devicemgr_device_close(dev); + dev->created = false; + } + free(dev->name); + dev->name = NULL; + } + } + + return TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE; } static int @@ -715,10 +1108,10 @@ tz_devicemgr_pressed_keys_update(struct ds_tizen_input_devicemgr *tz_devicemgr, } key->keycode = keycode; wl_list_init(&key->link); - wl_list_insert(&tz_devicemgr->pressed_keys, &key->link); + wl_list_insert(&tz_devicemgr->devices.kbd->key.pressed, &key->link); } else { - wl_list_for_each_safe(key, tmp, &tz_devicemgr->pressed_keys, link) { + wl_list_for_each_safe(key, tmp, &tz_devicemgr->devices.kbd->key.pressed, link) { if (key->keycode == keycode) { wl_list_remove(&key->link); free(key); @@ -728,7 +1121,7 @@ tz_devicemgr_pressed_keys_update(struct ds_tizen_input_devicemgr *tz_devicemgr, } ds_inf("Update pressed keys. length: %d, keycode:%d, pressed:%d", - wl_list_length(&tz_devicemgr->pressed_keys), keycode, pressed); + wl_list_length(&tz_devicemgr->devices.kbd->key.pressed), keycode, pressed); return true; } @@ -738,10 +1131,10 @@ tz_devicemgr_pressed_keys_cleanup(struct ds_tizen_input_devicemgr *tz_devicemgr) { struct ds_tizen_input_devicemgr_key_info *keydata, *tmp; - ds_inf("Clean up the pressed_keys. length: %d", - wl_list_length(&tz_devicemgr->pressed_keys)); + ds_inf("Clean up the kbd.pressed_keys. length: %d", + wl_list_length(&tz_devicemgr->devices.kbd->key.pressed)); - wl_list_for_each_safe(keydata, tmp, &tz_devicemgr->pressed_keys, link) { + wl_list_for_each_safe(keydata, tmp, &tz_devicemgr->devices.kbd->key.pressed, link) { if (tz_devicemgr->devices.kbd) tz_devicemgr_generate_key(tz_devicemgr->devices.kbd->input_device, keydata->keycode, false); @@ -765,48 +1158,145 @@ tz_devicemgr_keymap_list_cleanup(struct ds_tizen_input_devicemgr *tz_devicemgr) } } -static void -tz_devicemgr_keyboard_close(struct ds_tizen_input_devicemgr *tz_devicemgr) +static bool +tz_devicemgr_generate_touch_move(struct ds_input_device *device, double x, double y, + uint32_t finger) +{ + struct ds_event_touch_motion ds_event; + struct timeval time; + unsigned int timestamp; + struct ds_touch *touch; + + touch = ds_input_device_get_touch(device); + if (!touch) { + ds_err("No ds_touch to notify event"); + return false; + } + + gettimeofday(&time, NULL); + timestamp = time.tv_sec * 1000 + time.tv_usec / 1000; + + ds_event.time_msec = timestamp; + ds_event.id = finger; + ds_event.x = x; + ds_event.y = y; + ds_inf("Generate touch motion. touch:%p, id:%d (%d, %d)", touch, ds_event.id, x, y); + + wl_signal_emit(&touch->events.motion, &ds_event); + + return true; +} + +static bool +tz_devicemgr_generate_touch_down(struct ds_input_device *device, double x, double y, + uint32_t finger) { - if (!tz_devicemgr->devices.kbd->input_device) return; - ds_input_device_destroy(tz_devicemgr->devices.kbd->input_device); - tz_devicemgr->devices.kbd->input_device = NULL; - tz_devicemgr->devices.kbd->created = false; + struct ds_event_touch_down ds_event; + struct timeval time; + unsigned int timestamp; + struct ds_touch *touch; + + touch = ds_input_device_get_touch(device); + if (!touch) { + ds_err("No ds_touch to notify event"); + return false; + } + + gettimeofday(&time, NULL); + timestamp = time.tv_sec * 1000 + time.tv_usec / 1000; + + ds_event.time_msec = timestamp; + ds_event.id = finger; + ds_event.x = x; + ds_event.y = y; + ds_inf("Generate touch down. touch:%p, id:%d (%d, %d)", touch, ds_event.id, x, y); + + wl_signal_emit(&touch->events.down, &ds_event); + + return true; } -static int -tz_devicemgr_deinit_generator(struct ds_tizen_input_devicemgr *tz_devicemgr, - struct wl_resource *resource) +static bool +tz_devicemgr_generate_touch_up(struct ds_input_device *device, uint32_t finger) { - int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE; - struct ds_tizen_input_devicemgr_client *client_data; + struct ds_event_touch_up ds_event; + struct timeval time; + unsigned int timestamp; + struct ds_touch *touch; - ds_inf("Deinit generator."); - wl_list_for_each(client_data, &tz_devicemgr->clients, link) { - if (client_data->resource == resource) { - if (client_data->init == true) { - client_data->init = false; - tz_devicemgr->ref--; - if (tz_devicemgr->ref < 0) tz_devicemgr->ref = 0; - break; - } else { - return ret; - } - } + touch = ds_input_device_get_touch(device); + if (!touch) { + ds_err("No ds_touch to notify event"); + return false; + } + + gettimeofday(&time, NULL); + timestamp = time.tv_sec * 1000 + time.tv_usec / 1000; + + ds_event.time_msec = timestamp; + ds_event.id = finger; + ds_inf("Generate touch up. touch:%p, id:%d", touch, ds_event.id); + + wl_signal_emit(&touch->events.up, &ds_event); + + return true; +} + +static bool +tz_devicemgr_generate_mouse_move(struct ds_input_device *device, double x, double y) +{ + struct ds_event_pointer_motion ds_event; + struct timeval time; + unsigned int timestamp; + struct ds_pointer *pointer; + + pointer = ds_input_device_get_pointer(device); + if (!pointer) { + ds_err("No ds_pointer to notify event"); + return false; } - if (tz_devicemgr->ref <= 0) { - tz_devicemgr_pressed_keys_cleanup(tz_devicemgr); + gettimeofday(&time, NULL); + timestamp = time.tv_sec * 1000 + time.tv_usec / 1000; + + ds_event.time_msec = timestamp; + ds_event.delta_x = x; + ds_event.delta_y = y; + ds_inf("Generate mouse motion. pointer:%p, x:%f, y:%f", pointer, ds_event.delta_x, ds_event.delta_y); - if (!tz_devicemgr->devices.kbd) - return TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE; + wl_signal_emit(&pointer->events.motion, &ds_event); - if (tz_devicemgr->devices.kbd->created) - tz_devicemgr_keyboard_close(tz_devicemgr); - memset(tz_devicemgr->devices.kbd->name, 0, UINPUT_MAX_NAME_SIZE); + return true; +} + +static bool +tz_devicemgr_generate_mouse_button(struct ds_input_device *device, uint32_t button, bool state) +{ + struct ds_event_pointer_button ds_event; + struct timeval time; + unsigned int timestamp; + struct ds_pointer *pointer; + + pointer = ds_input_device_get_pointer(device); + if (!pointer) { + ds_err("No ds_pointer to notify event"); + return false; } - return ret; + gettimeofday(&time, NULL); + timestamp = time.tv_sec * 1000 + time.tv_usec / 1000; + + ds_event.time_msec = timestamp; + ds_event.button = button; + if (state) + ds_event.state = DS_BUTTON_PRESSED; + else + ds_event.state = DS_BUTTON_RELEASED; + ds_inf("Generate mouse button. pointer:%p, button:%d, state:%s", pointer, ds_event.button, state ? "PRESSED" : "RELEASED"); + + wl_signal_emit(&pointer->events.button, &ds_event); + + return true; } static void diff --git a/src/input-devicemgr/input-devicemgr.h b/src/input-devicemgr/input-devicemgr.h index 52bd2ef..a4428ee 100644 --- a/src/input-devicemgr/input-devicemgr.h +++ b/src/input-devicemgr/input-devicemgr.h @@ -9,9 +9,23 @@ #include struct ds_tizen_input_devicemgr_device { - char name[UINPUT_MAX_NAME_SIZE + 1]; + char *name; struct ds_input_device *input_device; + int ref; + bool created; + + struct { + struct wl_list pressed; + } key; + + struct { + unsigned int pressed; + } touch; + + struct { + unsigned int pressed; + } mouse; }; struct ds_tizen_input_devicemgr { @@ -34,20 +48,25 @@ struct ds_tizen_input_devicemgr { } devices; struct wl_list clients; - int ref; - struct wl_list pressed_keys; struct wl_list keymap_list; struct wl_list blocked_keys; struct wl_resource *block_resource; struct wl_event_source *timer; struct ds_seat_keyboard_grab *grab; + int touch_max_count; + + struct { + uint32_t width; + uint32_t height; + } output; }; struct ds_tizen_input_devicemgr_client { struct wl_resource *resource; bool init; + uint32_t clas; struct wl_list link; // ds_tizen_input_devicemgr::clients }; -- 2.7.4 From 08b81f339305fddb4bcabaf20c9cb29c31bb2abc Mon Sep 17 00:00:00 2001 From: "duna.oh" Date: Wed, 29 Jun 2022 10:46:54 +0900 Subject: [PATCH 05/16] devicemgr: use seat_destroy listener in seat_handle_destoy() func. Change-Id: If5556f8ec94836470981691efa5d9d40742f23fa --- src/input-devicemgr/input-devicemgr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/input-devicemgr/input-devicemgr.c b/src/input-devicemgr/input-devicemgr.c index c825b4c..91b7d57 100644 --- a/src/input-devicemgr/input-devicemgr.c +++ b/src/input-devicemgr/input-devicemgr.c @@ -296,7 +296,7 @@ seat_handle_destroy(struct wl_listener *listener, void *data) { struct ds_tizen_input_devicemgr *tz_devicemgr; - tz_devicemgr = wl_container_of(listener, tz_devicemgr, backend_destroy); + tz_devicemgr = wl_container_of(listener, tz_devicemgr, seat_destroy); wl_list_remove(&tz_devicemgr->seat_destroy.link); wl_list_init(&tz_devicemgr->seat_destroy.link); -- 2.7.4 From a7a4dff1726404c925b393b4244884d5567b2bfb Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Wed, 29 Jun 2022 17:36:40 +0900 Subject: [PATCH 06/16] make libds-tizen-backend-tdm change the build script and change tdm.h to tdm_internal.h for libds-tizen-backend-tdm. Change-Id: I7c1db1ae8acdb81bd1ce4fc01edd121782ef1f2d --- examples/meson.build | 9 ++++++++- packaging/libds-tizen.spec | 30 ++++++++++++++++++++++++++++ src/backend/tdm/backend.c | 2 +- src/backend/tdm/meson.build | 33 ++++++++++++++++++++++++------- src/backend/tdm/output.c | 2 +- src/backend/tdm/tdm_buffer_queue.c | 2 +- src/backend/tdm/tdm_buffer_queue.h | 2 +- src/backend/tdm/{tdm.h => tdm_internal.h} | 2 +- src/backend/tdm/tdm_output_hwc.c | 3 ++- src/backend/tdm/tdm_output_hwc.h | 4 +++- src/meson.build | 3 +-- 11 files changed, 75 insertions(+), 17 deletions(-) rename src/backend/tdm/{tdm.h => tdm_internal.h} (98%) diff --git a/examples/meson.build b/examples/meson.build index b7500a1..ca7c6ab 100644 --- a/examples/meson.build +++ b/examples/meson.build @@ -5,7 +5,10 @@ common_deps = [ executable('tdm-backend', 'tdm-backend.c', - dependencies: common_deps, + dependencies: [ + common_deps, + dep_libds_tizen_backend_tdm, + ], install_dir: libds_tizen_bindir, install : true ) @@ -21,6 +24,7 @@ executable('tinyds-tdm', tinyds_tdm_files, dependencies: [ common_deps, + dep_libds_tizen_backend_tdm, dependency('pixman-1', required: true), dependency('threads', required: true), ], @@ -39,6 +43,7 @@ executable('tinyds-tdm-libinput', tinyds_tdm_libinput_files, dependencies: [ common_deps, + dep_libds_tizen_backend_tdm, dep_libds_tizen_input_devicemgr, dependency('pixman-1', required: true), dependency('threads', required: true), @@ -54,6 +59,7 @@ executable('tinyds-tdm-dpms', 'tinyds-tdm-renderer.c', dependencies: [ common_deps, + dep_libds_tizen_backend_tdm, dependency('pixman-1', required: true), dependency('threads', required: true), ], @@ -71,6 +77,7 @@ executable('tinyds-tdm-hwc', tinyds_tdm_hwc_files, dependencies: [ common_deps, + dep_libds_tizen_backend_tdm, dependency('pixman-1', required: true), dependency('threads', required: true), ], diff --git a/packaging/libds-tizen.spec b/packaging/libds-tizen.spec index 000f5a9..99b47ae 100644 --- a/packaging/libds-tizen.spec +++ b/packaging/libds-tizen.spec @@ -39,6 +39,21 @@ Requires: %{name} = %{version}-%{release} %description devel Development package of Wayland Compositor Library for Tizen +## libds-tizen-backend-tdm +%package backend-tdm +Summary: Display Backend Library with TDM +Group: Development/Libraries + +%description backend-tdm +Display Backend Library with TDM + +%package backend-tdm-devel +Summary: TDM Display Backend Development package +Group: Development/Libraries + +%description backend-tdm-devel +TDM Display Backend Development package + %package keyrouter Summary: Wayland Compositor Library for keyrouter Group: Development/Libraries @@ -106,6 +121,21 @@ ninja -C builddir install %{_bindir}/tinyds-tdm-libinput %{_bindir}/input-generator +%files backend-tdm +%manifest %{name}.manifest +%defattr(-,root,root,-) +%license LICENSE +%{_libdir}/libds-tizen-backend-tdm.so.* + +%files backend-tdm-devel +%manifest %{name}.manifest +%defattr(-,root,root,-) +%license LICENSE +%{_includedir}/libds-tizen/backend/tdm.h +%{_includedir}/libds-tizen/backend/tdm_output_hwc.h +%{_libdir}/pkgconfig/libds-tizen-backend-tdm.pc +%{_libdir}/libds-tizen-backend-tdm.so + %files keyrouter %manifest %{name}.manifest %defattr(-,root,root,-) diff --git a/src/backend/tdm/backend.c b/src/backend/tdm/backend.c index 2337204..8ca365e 100644 --- a/src/backend/tdm/backend.c +++ b/src/backend/tdm/backend.c @@ -3,7 +3,7 @@ #include -#include "tdm.h" +#include "tdm_internal.h" static const struct ds_backend_interface tdm_backend_iface; diff --git a/src/backend/tdm/meson.build b/src/backend/tdm/meson.build index 7a7c25f..04ecbcf 100644 --- a/src/backend/tdm/meson.build +++ b/src/backend/tdm/meson.build @@ -1,14 +1,33 @@ -libds_tizen_files += files( +libds_tizen_backend_tdm_files = files( 'backend.c', 'output.c', 'tdm_buffer_queue.c', 'tdm_output_hwc.c', ) -libtdm = dependency('libtdm', required: true) -libtbm = dependency('libtbm', required: true) - -libds_tizen_deps += [ - libtdm, - libtbm +libds_tizen_backend_tdm_deps = [ + dep_libds_tizen, + dependency('libtdm', required: true), + dependency('libtbm', required: true) ] + +lib_libds_tizen_backend_tdm = shared_library('ds-tizen-backend-tdm', libds_tizen_backend_tdm_files, + dependencies: libds_tizen_backend_tdm_deps, + include_directories: [ include_directories('/usr/include'), common_inc, include_directories('.'), include_directories('..')], + version: meson.project_version(), + install: true +) + +dep_libds_tizen_backend_tdm = declare_dependency( + link_with: lib_libds_tizen_backend_tdm, + dependencies: libds_tizen_backend_tdm_deps, + include_directories: [ common_inc, include_directories('.') ], +) + +pkgconfig = import('pkgconfig') +pkgconfig.generate(lib_libds_tizen_backend_tdm, + version: meson.project_version(), + filebase: 'libds-tizen-backend-tdm', + name: 'libds-tizen-backend-tdm', + description: 'tdm backend of libds-tizen for tizen platform', +) \ No newline at end of file diff --git a/src/backend/tdm/output.c b/src/backend/tdm/output.c index 5e874df..c9ad137 100644 --- a/src/backend/tdm/output.c +++ b/src/backend/tdm/output.c @@ -6,7 +6,7 @@ #include #include "libds-tizen/allocator/tbm.h" -#include "tdm.h" +#include "tdm_internal.h" #include "tdm_output_hwc.h" #include "tdm_buffer_queue.h" diff --git a/src/backend/tdm/tdm_buffer_queue.c b/src/backend/tdm/tdm_buffer_queue.c index 3acec8f..40e6353 100644 --- a/src/backend/tdm/tdm_buffer_queue.c +++ b/src/backend/tdm/tdm_buffer_queue.c @@ -6,7 +6,7 @@ #include #include "libds/interfaces/buffer.h" -#include "tdm.h" +#include "tdm_internal.h" #include "tdm_buffer_queue.h" static void diff --git a/src/backend/tdm/tdm_buffer_queue.h b/src/backend/tdm/tdm_buffer_queue.h index a983265..51eab37 100644 --- a/src/backend/tdm/tdm_buffer_queue.h +++ b/src/backend/tdm/tdm_buffer_queue.h @@ -4,7 +4,7 @@ #include #include -#include "tdm.h" +#include "tdm_internal.h" struct ds_tdm_buffer_queue { diff --git a/src/backend/tdm/tdm.h b/src/backend/tdm/tdm_internal.h similarity index 98% rename from src/backend/tdm/tdm.h rename to src/backend/tdm/tdm_internal.h index 7c00202..ef7d88f 100644 --- a/src/backend/tdm/tdm.h +++ b/src/backend/tdm/tdm_internal.h @@ -2,8 +2,8 @@ #define DS_TIZEN_BACKEND_TDM_H #include - #include +#include #include #include diff --git a/src/backend/tdm/tdm_output_hwc.c b/src/backend/tdm/tdm_output_hwc.c index 8db2984..48aef1d 100644 --- a/src/backend/tdm/tdm_output_hwc.c +++ b/src/backend/tdm/tdm_output_hwc.c @@ -3,10 +3,11 @@ #include #include -#include #include #include + +#include "tdm_internal.h" #include "tdm_output_hwc.h" static void diff --git a/src/backend/tdm/tdm_output_hwc.h b/src/backend/tdm/tdm_output_hwc.h index 07b3699..bb634d2 100644 --- a/src/backend/tdm/tdm_output_hwc.h +++ b/src/backend/tdm/tdm_output_hwc.h @@ -1,13 +1,15 @@ #ifndef DS_TIZEN_BACKEND_TDM_OUTPUT_HWC_H #define DS_TIZEN_BACKEND_TDM_OUTPUT_HWC_H -#include #include #include #include #include +#include "tdm_internal.h" + + struct ds_tdm_output_hwc_window { struct wl_list link; diff --git a/src/meson.build b/src/meson.build index 1ee9b99..7b61b9a 100644 --- a/src/meson.build +++ b/src/meson.build @@ -34,7 +34,6 @@ libds_tizen_deps = [ ] subdir('allocator') -subdir('backend') subdir('util') lib_libds_tizen = shared_library('ds-tizen', libds_tizen_files, @@ -58,6 +57,6 @@ pkgconfig.generate(lib_libds_tizen, description: 'extension of libds for tizen platform', ) +subdir('backend') subdir('keyrouter') subdir('input-devicemgr') - -- 2.7.4 From 3c94d20bfe406ea2c4ae26609dcd76145e87ef68 Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Wed, 29 Jun 2022 18:27:21 +0900 Subject: [PATCH 07/16] make libds-tizen-allocator-tbm change the build script for libds-tizen-allocator-tbm Change-Id: I7dd36d43879e2708f4ead2545849954355f721d2 --- packaging/libds-tizen.spec | 29 +++++++++++++++++++++++++++++ src/allocator/meson.build | 3 +-- src/allocator/tbm/meson.build | 29 +++++++++++++++++++++++++++++ src/allocator/{ => tbm}/tbm.c | 1 - src/backend/tdm/meson.build | 1 + src/backend/tdm/output.c | 3 +-- src/meson.build | 2 +- 7 files changed, 62 insertions(+), 6 deletions(-) create mode 100644 src/allocator/tbm/meson.build rename src/allocator/{ => tbm}/tbm.c (99%) diff --git a/packaging/libds-tizen.spec b/packaging/libds-tizen.spec index 99b47ae..13c2be3 100644 --- a/packaging/libds-tizen.spec +++ b/packaging/libds-tizen.spec @@ -39,6 +39,21 @@ Requires: %{name} = %{version}-%{release} %description devel Development package of Wayland Compositor Library for Tizen +## libds-tizen-allocator-tbm +%package allocator-tbm +Summary: Allocator Library with TBM +Group: Development/Libraries + +%description allocator-tbm +Allocator Library with TBM + +%package allocator-tbm-devel +Summary: TBM Allocator Development package +Group: Development/Libraries + +%description allocator-tbm-devel +TBM Allocator Development package + ## libds-tizen-backend-tdm %package backend-tdm Summary: Display Backend Library with TDM @@ -121,6 +136,20 @@ ninja -C builddir install %{_bindir}/tinyds-tdm-libinput %{_bindir}/input-generator +%files allocator-tbm +%manifest %{name}.manifest +%defattr(-,root,root,-) +%license LICENSE +%{_libdir}/libds-tizen-allocator-tbm.so.* + +%files allocator-tbm-devel +%manifest %{name}.manifest +%defattr(-,root,root,-) +%license LICENSE +%{_includedir}/libds-tizen/allocator/tbm.h +%{_libdir}/pkgconfig/libds-tizen-allocator-tbm.pc +%{_libdir}/libds-tizen-allocator-tbm.so + %files backend-tdm %manifest %{name}.manifest %defattr(-,root,root,-) diff --git a/src/allocator/meson.build b/src/allocator/meson.build index fe869bd..ddc6385 100644 --- a/src/allocator/meson.build +++ b/src/allocator/meson.build @@ -1,2 +1 @@ -libds_tizen_files += files('tbm.c') -libds_tizen_deps += dependency('libtbm', required: true) +subdir('tbm') diff --git a/src/allocator/tbm/meson.build b/src/allocator/tbm/meson.build new file mode 100644 index 0000000..b2ee630 --- /dev/null +++ b/src/allocator/tbm/meson.build @@ -0,0 +1,29 @@ +libds_tizen_allocator_tbm_files = files( + 'tbm.c', +) + +libds_tizen_allocator_tbm_deps = [ + dep_libds_tizen, + dependency('libtbm', required: true) +] + +lib_libds_tizen_allocator_tbm = shared_library('ds-tizen-allocator-tbm', libds_tizen_allocator_tbm_files, + dependencies: libds_tizen_allocator_tbm_deps, + include_directories: [ include_directories('/usr/include'), common_inc, include_directories('.'), include_directories('..')], + version: meson.project_version(), + install: true +) + +dep_libds_tizen_allocator_tbm = declare_dependency( + link_with: lib_libds_tizen_allocator_tbm, + dependencies: libds_tizen_allocator_tbm_deps, + include_directories: [ common_inc, include_directories('.') ], +) + +pkgconfig = import('pkgconfig') +pkgconfig.generate(lib_libds_tizen_allocator_tbm, + version: meson.project_version(), + filebase: 'libds-tizen-allocator-tbm', + name: 'libds-tizen-allocator-tbm', + description: 'tbm allocator of libds-tizen for tizen platform', +) \ No newline at end of file diff --git a/src/allocator/tbm.c b/src/allocator/tbm/tbm.c similarity index 99% rename from src/allocator/tbm.c rename to src/allocator/tbm/tbm.c index 0d00793..89591c4 100644 --- a/src/allocator/tbm.c +++ b/src/allocator/tbm/tbm.c @@ -1,7 +1,6 @@ #include #include -#include #include #include #include diff --git a/src/backend/tdm/meson.build b/src/backend/tdm/meson.build index 04ecbcf..7d4102d 100644 --- a/src/backend/tdm/meson.build +++ b/src/backend/tdm/meson.build @@ -7,6 +7,7 @@ libds_tizen_backend_tdm_files = files( libds_tizen_backend_tdm_deps = [ dep_libds_tizen, + dep_libds_tizen_allocator_tbm, dependency('libtdm', required: true), dependency('libtbm', required: true) ] diff --git a/src/backend/tdm/output.c b/src/backend/tdm/output.c index c9ad137..1baefd2 100644 --- a/src/backend/tdm/output.c +++ b/src/backend/tdm/output.c @@ -1,11 +1,10 @@ #include #include - #include #include -#include "libds-tizen/allocator/tbm.h" +#include "libds-tizen/allocator/tbm.h" #include "tdm_internal.h" #include "tdm_output_hwc.h" #include "tdm_buffer_queue.h" diff --git a/src/meson.build b/src/meson.build index 7b61b9a..49dcc09 100644 --- a/src/meson.build +++ b/src/meson.build @@ -33,7 +33,6 @@ libds_tizen_deps = [ dependency('tizen-dpms-server', required: true), ] -subdir('allocator') subdir('util') lib_libds_tizen = shared_library('ds-tizen', libds_tizen_files, @@ -57,6 +56,7 @@ pkgconfig.generate(lib_libds_tizen, description: 'extension of libds for tizen platform', ) +subdir('allocator') subdir('backend') subdir('keyrouter') subdir('input-devicemgr') -- 2.7.4 From 71b81f381cfb515aa79ee92431d5c29b00bfb109 Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Wed, 29 Jun 2022 18:45:23 +0900 Subject: [PATCH 08/16] add comments at spec file Change-Id: Ib6548d595ccc18899ac1be40b485070ff987e951 --- packaging/libds-tizen.spec | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packaging/libds-tizen.spec b/packaging/libds-tizen.spec index 13c2be3..77774fe 100644 --- a/packaging/libds-tizen.spec +++ b/packaging/libds-tizen.spec @@ -69,6 +69,7 @@ Group: Development/Libraries %description backend-tdm-devel TDM Display Backend Development package +## libds-tizen-keyrouter %package keyrouter Summary: Wayland Compositor Library for keyrouter Group: Development/Libraries @@ -83,6 +84,7 @@ Group: Development/Libraries %description keyrouter-devel Keyrouter Development package for Wayland Compositor Library +## libds-tizen-input-devicemgr %package input-devicemgr Summary: Library for tizen input devicemgr Group: Development/Libraries -- 2.7.4 From a105b8f7dca369c08c88c0a8ae4c8e9f102b4200 Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Wed, 29 Jun 2022 18:50:51 +0900 Subject: [PATCH 09/16] make libds-tizen-dpms change the build script for libds-tizen-dpms Change-Id: I8b0c2827ff715962302807875aee119b04ac8029 --- examples/meson.build | 1 + packaging/libds-tizen.spec | 33 +++++++++++++++++++++++++++++++-- src/{ => dpms}/dpms.c | 0 src/dpms/meson.build | 29 +++++++++++++++++++++++++++++ src/meson.build | 3 +-- 5 files changed, 62 insertions(+), 4 deletions(-) rename src/{ => dpms}/dpms.c (100%) create mode 100644 src/dpms/meson.build diff --git a/examples/meson.build b/examples/meson.build index ca7c6ab..7927407 100644 --- a/examples/meson.build +++ b/examples/meson.build @@ -60,6 +60,7 @@ executable('tinyds-tdm-dpms', dependencies: [ common_deps, dep_libds_tizen_backend_tdm, + dep_libds_tizen_dpms, dependency('pixman-1', required: true), dependency('threads', required: true), ], diff --git a/packaging/libds-tizen.spec b/packaging/libds-tizen.spec index 77774fe..4072644 100644 --- a/packaging/libds-tizen.spec +++ b/packaging/libds-tizen.spec @@ -99,6 +99,21 @@ Group: Development/Libraries %description input-devicemgr-devel Development package for tizen input devicemgr +## libds-tizen-dpms +%package dpms +Summary: Library for tizen dpms +Group: Development/Libraries + +%description dpms +Library for tizen dpms + +%package dpms-devel +Summary: Development package for tizen dpms +Group: Development/Libraries + +%description dpms-devel +Development package for tizen dpms + %prep %setup -q cp %{SOURCE1001} . @@ -133,8 +148,6 @@ ninja -C builddir install %{_bindir}/tinyds-tdm %{_bindir}/tinyds-tdm-hwc %{_bindir}/ds-simple-tbm -%{_bindir}/tinyds-tdm-dpms -%{_bindir}/ds-simple-dpms %{_bindir}/tinyds-tdm-libinput %{_bindir}/input-generator @@ -196,3 +209,19 @@ ninja -C builddir install %{_libdir}/libds-tizen-input-devicemgr.so %{_bindir}/tinyds-tdm-libinput %{_bindir}/input-generator + +%files dpms +%manifest %{name}.manifest +%defattr(-,root,root,-) +%license LICENSE +%{_libdir}/libds-tizen-dpms.so.* + +%files dpms-devel +%manifest %{name}.manifest +%defattr(-,root,root,-) +%license LICENSE +%{_includedir}/libds-tizen/dpms.h +%{_libdir}/pkgconfig/libds-tizen-dpms.pc +%{_libdir}/libds-tizen-dpms.so +%{_bindir}/tinyds-tdm-dpms +%{_bindir}/ds-simple-dpms diff --git a/src/dpms.c b/src/dpms/dpms.c similarity index 100% rename from src/dpms.c rename to src/dpms/dpms.c diff --git a/src/dpms/meson.build b/src/dpms/meson.build new file mode 100644 index 0000000..2de950f --- /dev/null +++ b/src/dpms/meson.build @@ -0,0 +1,29 @@ +libds_tizen_dpms_files = [ + 'dpms.c', +] + +libds_tizen_dpms_deps = [ + dep_libds_tizen, + dependency('tizen-dpms-server', required: true), +] + +lib_libds_tizen_dpms = shared_library('ds-tizen-dpms', libds_tizen_dpms_files, + dependencies: libds_tizen_dpms_deps, + include_directories: [ common_inc, include_directories('.'), include_directories('..') ], + version: meson.project_version(), + install: true +) + +dep_libds_tizen_dpms = declare_dependency( + link_with: lib_libds_tizen_dpms, + dependencies: libds_tizen_dpms_deps, + include_directories: [ common_inc, include_directories('.') ], +) + +pkgconfig = import('pkgconfig') +pkgconfig.generate(lib_libds_tizen_dpms, + version: meson.project_version(), + filebase: 'libds-tizen-dpms', + name: 'libds-tizen-dpms', + description: 'tizen dpms extension of libds-tizen for tizen platform', +) diff --git a/src/meson.build b/src/meson.build index 49dcc09..538b837 100644 --- a/src/meson.build +++ b/src/meson.build @@ -1,7 +1,6 @@ libds_tizen_files = [ 'pixel_format.c', 'tbm_server.c', - 'dpms.c', ] math = meson.get_compiler('c').find_library('m') @@ -30,7 +29,6 @@ libds_tizen_deps = [ dependency('libdrm', required: true), dependency('libtbm', required: true), dependency('wayland-tbm-server', required: true), - dependency('tizen-dpms-server', required: true), ] subdir('util') @@ -60,3 +58,4 @@ subdir('allocator') subdir('backend') subdir('keyrouter') subdir('input-devicemgr') +subdir('dpms') -- 2.7.4 From e3a8bf20803272a85b98954179ee78e7593e5f17 Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Wed, 29 Jun 2022 19:16:14 +0900 Subject: [PATCH 10/16] make libds-tizen-tbm-server change the build script for libds-tizen-tbm-server Change-Id: I3bfa4f72ea9298d847f72d1246d0d04f575f162c --- examples/meson.build | 3 ++ examples/tinyds-tdm-dpms.c | 2 +- examples/tinyds-tdm-hwc.c | 2 +- examples/tinyds-tdm-libinput.c | 2 +- examples/tinyds-tdm.c | 2 +- include/libds-tizen/{tbm_server.h => tbm-server.h} | 0 packaging/libds-tizen.spec | 29 ++++++++++++++++++++ src/backend/tdm/meson.build | 1 + src/backend/tdm/tdm_output_hwc.c | 2 +- src/meson.build | 12 ++------ src/tbm-server/meson.build | 32 ++++++++++++++++++++++ src/{ => tbm-server}/pixel_format.c | 0 src/{ => tbm-server}/pixel_format.h | 0 src/{tbm_server.c => tbm-server/tbm-server.c} | 2 +- src/{tbm_server.h => tbm-server/tbm-server.h} | 0 15 files changed, 73 insertions(+), 16 deletions(-) rename include/libds-tizen/{tbm_server.h => tbm-server.h} (100%) create mode 100644 src/tbm-server/meson.build rename src/{ => tbm-server}/pixel_format.c (100%) rename src/{ => tbm-server}/pixel_format.h (100%) rename src/{tbm_server.c => tbm-server/tbm-server.c} (99%) rename src/{tbm_server.h => tbm-server/tbm-server.h} (100%) diff --git a/examples/meson.build b/examples/meson.build index 7927407..56fcd61 100644 --- a/examples/meson.build +++ b/examples/meson.build @@ -1,5 +1,6 @@ common_deps = [ dep_libds_tizen, + dependency('pixman-1', required: true), dependency('wayland-server', required: true), ] @@ -8,6 +9,7 @@ executable('tdm-backend', dependencies: [ common_deps, dep_libds_tizen_backend_tdm, + dep_libds_tizen_tbm_server, ], install_dir: libds_tizen_bindir, install : true @@ -25,6 +27,7 @@ executable('tinyds-tdm', dependencies: [ common_deps, dep_libds_tizen_backend_tdm, + dep_libds_tizen_tbm_server, dependency('pixman-1', required: true), dependency('threads', required: true), ], diff --git a/examples/tinyds-tdm-dpms.c b/examples/tinyds-tdm-dpms.c index dc32e8f..ab34297 100644 --- a/examples/tinyds-tdm-dpms.c +++ b/examples/tinyds-tdm-dpms.c @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #define USE_TDM_BUFFER_QUEUE diff --git a/examples/tinyds-tdm-hwc.c b/examples/tinyds-tdm-hwc.c index 46925f1..762fe07 100644 --- a/examples/tinyds-tdm-hwc.c +++ b/examples/tinyds-tdm-hwc.c @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #define USE_TDM_BUFFER_QUEUE diff --git a/examples/tinyds-tdm-libinput.c b/examples/tinyds-tdm-libinput.c index 3feb932..809f8cf 100644 --- a/examples/tinyds-tdm-libinput.c +++ b/examples/tinyds-tdm-libinput.c @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include #include diff --git a/examples/tinyds-tdm.c b/examples/tinyds-tdm.c index 4bc08f1..57b502c 100644 --- a/examples/tinyds-tdm.c +++ b/examples/tinyds-tdm.c @@ -15,7 +15,7 @@ #include #include #include -#include +#include #define USE_TDM_BUFFER_QUEUE diff --git a/include/libds-tizen/tbm_server.h b/include/libds-tizen/tbm-server.h similarity index 100% rename from include/libds-tizen/tbm_server.h rename to include/libds-tizen/tbm-server.h diff --git a/packaging/libds-tizen.spec b/packaging/libds-tizen.spec index 4072644..cf44015 100644 --- a/packaging/libds-tizen.spec +++ b/packaging/libds-tizen.spec @@ -69,6 +69,21 @@ Group: Development/Libraries %description backend-tdm-devel TDM Display Backend Development package +## libds-tizen-tbm-server +%package tbm-server +Summary: Library for wayland-tbm-server +Group: Development/Libraries + +%description tbm-server +Library for tizen input devicemgr + +%package tbm-server-devel +Summary: Development package for wayland-tbm-server +Group: Development/Libraries + +%description tbm-server-devel +Development package for tizen wayland-tbm-server + ## libds-tizen-keyrouter %package keyrouter Summary: Wayland Compositor Library for keyrouter @@ -180,6 +195,20 @@ ninja -C builddir install %{_libdir}/pkgconfig/libds-tizen-backend-tdm.pc %{_libdir}/libds-tizen-backend-tdm.so +%files tbm-server +%manifest %{name}.manifest +%defattr(-,root,root,-) +%license LICENSE +%{_libdir}/libds-tizen-tbm-server.so.* + +%files tbm-server-devel +%manifest %{name}.manifest +%defattr(-,root,root,-) +%license LICENSE +%{_includedir}/libds-tizen/tbm-server.h +%{_libdir}/pkgconfig/libds-tizen-tbm-server.pc +%{_libdir}/libds-tizen-tbm-server.so + %files keyrouter %manifest %{name}.manifest %defattr(-,root,root,-) diff --git a/src/backend/tdm/meson.build b/src/backend/tdm/meson.build index 7d4102d..bca5bca 100644 --- a/src/backend/tdm/meson.build +++ b/src/backend/tdm/meson.build @@ -8,6 +8,7 @@ libds_tizen_backend_tdm_files = files( libds_tizen_backend_tdm_deps = [ dep_libds_tizen, dep_libds_tizen_allocator_tbm, + dep_libds_tizen_tbm_server, dependency('libtdm', required: true), dependency('libtbm', required: true) ] diff --git a/src/backend/tdm/tdm_output_hwc.c b/src/backend/tdm/tdm_output_hwc.c index 48aef1d..e66b5fa 100644 --- a/src/backend/tdm/tdm_output_hwc.c +++ b/src/backend/tdm/tdm_output_hwc.c @@ -4,7 +4,7 @@ #include #include -#include +#include #include "tdm_internal.h" diff --git a/src/meson.build b/src/meson.build index 538b837..7f7447e 100644 --- a/src/meson.build +++ b/src/meson.build @@ -1,14 +1,10 @@ libds_tizen_files = [ - 'pixel_format.c', - 'tbm_server.c', ] math = meson.get_compiler('c').find_library('m') wayland_server = dependency('wayland-server', required: true) -pixman = dependency('pixman-1', required: true) -libdrm = dependency('libdrm', required: true) -xkbcommon = dependency('xkbcommon', required: true) rt = meson.get_compiler('c').find_library('rt') +xkbcommon = dependency('xkbcommon', required: true) if wayland_server.version().version_compare('>= 1.19') cdata.set('HAVE_WL_SEAT_ERROR_MISSING_CAPABILITY', '1') @@ -17,8 +13,6 @@ endif base_deps = [ math, wayland_server, - pixman, - libdrm, xkbcommon, rt, ] @@ -26,9 +20,6 @@ base_deps = [ libds_tizen_deps = [ base_deps, dependency('libds', required: true), - dependency('libdrm', required: true), - dependency('libtbm', required: true), - dependency('wayland-tbm-server', required: true), ] subdir('util') @@ -55,6 +46,7 @@ pkgconfig.generate(lib_libds_tizen, ) subdir('allocator') +subdir('tbm-server') subdir('backend') subdir('keyrouter') subdir('input-devicemgr') diff --git a/src/tbm-server/meson.build b/src/tbm-server/meson.build new file mode 100644 index 0000000..c83ff6c --- /dev/null +++ b/src/tbm-server/meson.build @@ -0,0 +1,32 @@ +libds_tizen_tbm_server_files = [ + 'pixel_format.c', + 'tbm-server.c', +] + +libds_tizen_tbm_server_deps = [ + dep_libds_tizen, + dependency('libdrm', required: true), + dependency('libtbm', required: true), + dependency('wayland-tbm-server', required: true), +] + +lib_libds_tizen_tbm_server = shared_library('ds-tizen-tbm-server', libds_tizen_tbm_server_files, + dependencies: libds_tizen_tbm_server_deps, + include_directories: [ common_inc, include_directories('.'), include_directories('..') ], + version: meson.project_version(), + install: true +) + +dep_libds_tizen_tbm_server = declare_dependency( + link_with: lib_libds_tizen_tbm_server, + dependencies: libds_tizen_tbm_server_deps, + include_directories: [ common_inc, include_directories('.') ], +) + +pkgconfig = import('pkgconfig') +pkgconfig.generate(lib_libds_tizen_tbm_server, + version: meson.project_version(), + filebase: 'libds-tizen-tbm-server', + name: 'libds-tizen-tbm-server', + description: 'wayland-tbm extension of libds-tizen for tizen platform', +) diff --git a/src/pixel_format.c b/src/tbm-server/pixel_format.c similarity index 100% rename from src/pixel_format.c rename to src/tbm-server/pixel_format.c diff --git a/src/pixel_format.h b/src/tbm-server/pixel_format.h similarity index 100% rename from src/pixel_format.h rename to src/tbm-server/pixel_format.h diff --git a/src/tbm_server.c b/src/tbm-server/tbm-server.c similarity index 99% rename from src/tbm_server.c rename to src/tbm-server/tbm-server.c index 0fd25cd..9dde248 100644 --- a/src/tbm_server.c +++ b/src/tbm-server/tbm-server.c @@ -6,7 +6,7 @@ #include #include "pixel_format.h" -#include "tbm_server.h" +#include "tbm-server.h" static const struct ds_buffer_resource_interface tbm_buffer_resource_iface; static const struct ds_buffer_interface tbm_client_buffer_iface; diff --git a/src/tbm_server.h b/src/tbm-server/tbm-server.h similarity index 100% rename from src/tbm_server.h rename to src/tbm-server/tbm-server.h -- 2.7.4 From 7c579832443cb0074ea9841775e8564060102878 Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Thu, 30 Jun 2022 09:29:41 +0900 Subject: [PATCH 11/16] seperate security to util keyrouter and input-device only depends on security. dpms does not need to depends on security. Change-Id: I84f319dce5d7fb8f8a4c7e1c0d92ce871aeb7986 --- src/input-devicemgr/input-devicemgr.c | 1 + src/input-devicemgr/meson.build | 2 ++ src/keyrouter/keyrouter.c | 1 + src/keyrouter/meson.build | 2 ++ src/meson.build | 11 ++++++++++- src/{util => }/security.c | 0 src/security.h | 15 +++++++++++++++ src/util.h | 15 ++------------- src/util/meson.build | 6 ------ 9 files changed, 33 insertions(+), 20 deletions(-) rename src/{util => }/security.c (100%) create mode 100644 src/security.h delete mode 100644 src/util/meson.build diff --git a/src/input-devicemgr/input-devicemgr.c b/src/input-devicemgr/input-devicemgr.c index 91b7d57..b3fc567 100644 --- a/src/input-devicemgr/input-devicemgr.c +++ b/src/input-devicemgr/input-devicemgr.c @@ -9,6 +9,7 @@ #include #include "util.h" +#include "security.h" #include "input-devicemgr.h" #define TIZEN_INPUT_DEVICEMGR_VERSION 4 diff --git a/src/input-devicemgr/meson.build b/src/input-devicemgr/meson.build index 7006326..1e69463 100644 --- a/src/input-devicemgr/meson.build +++ b/src/input-devicemgr/meson.build @@ -1,9 +1,11 @@ libds_tizen_input_devicemgr_files = [ + tizen_security_files, 'input-devicemgr.c', ] libds_tizen_input_devicemgr_deps = [ dep_libds_tizen, + deps_tizen_security, dependency('tizen-extension-server', required: true), ] diff --git a/src/keyrouter/keyrouter.c b/src/keyrouter/keyrouter.c index 4bcee93..2e825c6 100644 --- a/src/keyrouter/keyrouter.c +++ b/src/keyrouter/keyrouter.c @@ -8,6 +8,7 @@ #include "libds-tizen/keyrouter.h" #include "util.h" +#include "security.h" #include "keyrouter.h" #define TIZEN_KEYROUTER_VERSION 2 diff --git a/src/keyrouter/meson.build b/src/keyrouter/meson.build index 7c9f01c..af235ce 100644 --- a/src/keyrouter/meson.build +++ b/src/keyrouter/meson.build @@ -1,10 +1,12 @@ libds_tizen_keyrouter_files = [ + tizen_security_files, 'keyrouter_grab.c', 'keyrouter.c', ] libds_tizen_keyrouter_deps = [ dep_libds_tizen, + deps_tizen_security, dependency('tizen-extension-server', required: true), ] diff --git a/src/meson.build b/src/meson.build index 7f7447e..4d8a290 100644 --- a/src/meson.build +++ b/src/meson.build @@ -22,7 +22,16 @@ libds_tizen_deps = [ dependency('libds', required: true), ] -subdir('util') +tizen_security_files = [ + '../security.c', +] + +deps_tizen_security = [ + base_deps, + dependency('cynara-client', required: true), + dependency('cynara-session', required: true), + dependency('libsmack', required: true) +] lib_libds_tizen = shared_library('ds-tizen', libds_tizen_files, dependencies: libds_tizen_deps, diff --git a/src/util/security.c b/src/security.c similarity index 100% rename from src/util/security.c rename to src/security.c diff --git a/src/security.h b/src/security.h new file mode 100644 index 0000000..0c522a0 --- /dev/null +++ b/src/security.h @@ -0,0 +1,15 @@ +#ifndef DS_TIZEN_SECURITY_H +#define DS_TIZEN_SECURITY_H + +#include + +bool +tizen_security_init(void); + +void +tizen_security_finish(void); + +bool +tizen_security_check_privilege(pid_t pid, uid_t uid, const char *privilege); + +#endif diff --git a/src/util.h b/src/util.h index 126467c..425caf3 100644 --- a/src/util.h +++ b/src/util.h @@ -1,17 +1,6 @@ -#ifndef DS_UTIL_H -#define DS_UTIL_H - -#include +#ifndef DS_TIZEN_UTIL_H +#define DS_TIZEN_UTIL_H #define MIN(a,b) ((a)<(b)?(a):(b)) -bool -tizen_security_init(void); - -void -tizen_security_finish(void); - -bool -tizen_security_check_privilege(pid_t pid, uid_t uid, const char *privilege); - #endif diff --git a/src/util/meson.build b/src/util/meson.build deleted file mode 100644 index 0ec6a9d..0000000 --- a/src/util/meson.build +++ /dev/null @@ -1,6 +0,0 @@ -libds_tizen_files += files('security.c') -libds_tizen_deps += [ - dependency('cynara-client', required: true), - dependency('cynara-session', required: true), - dependency('libsmack', required: true) -] -- 2.7.4 From 89860b5de69ab9aa97b832243670aa2fc0955047 Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Thu, 30 Jun 2022 09:39:21 +0900 Subject: [PATCH 12/16] Donot make libds-tizen package Remove libds-tizen/libds-tizen-devel packages and libds-tizen library Change-Id: Id66b15da9fe591eb7dc249c7e9faa78205458aae --- examples/meson.build | 2 +- packaging/libds-tizen.spec | 32 ++++---------------------------- src/allocator/tbm/meson.build | 2 +- src/backend/tdm/meson.build | 2 +- src/dpms/meson.build | 2 +- src/input-devicemgr/meson.build | 2 +- src/keyrouter/meson.build | 2 +- src/meson.build | 28 ++-------------------------- src/tbm-server/meson.build | 2 +- tests/meson.build | 2 +- 10 files changed, 14 insertions(+), 62 deletions(-) diff --git a/examples/meson.build b/examples/meson.build index 56fcd61..21b6ef9 100644 --- a/examples/meson.build +++ b/examples/meson.build @@ -1,5 +1,5 @@ common_deps = [ - dep_libds_tizen, + deps_libds_tizen, dependency('pixman-1', required: true), dependency('wayland-server', required: true), ] diff --git a/packaging/libds-tizen.spec b/packaging/libds-tizen.spec index cf44015..f2702ee 100644 --- a/packaging/libds-tizen.spec +++ b/packaging/libds-tizen.spec @@ -31,14 +31,6 @@ BuildRequires: pkgconfig(libsmack) %description Wayland Compositor Library for Tizen -%package devel -Summary: Wayland Compositor Library for Tizen -Group: Development/Libraries -Requires: %{name} = %{version}-%{release} - -%description devel -Development package of Wayland Compositor Library for Tizen - ## libds-tizen-allocator-tbm %package allocator-tbm Summary: Allocator Library with TBM @@ -146,26 +138,6 @@ ninja -C builddir all export DESTDIR=%{buildroot} ninja -C builddir install -%files -%manifest %{name}.manifest -%defattr(-,root,root,-) -%license LICENSE -%{_libdir}/libds-tizen.so.* - -%files devel -%manifest %{name}.manifest -%defattr(-,root,root,-) -%license LICENSE -%{_includedir}/libds-tizen/* -%{_libdir}/pkgconfig/libds-tizen.pc -%{_libdir}/libds-tizen.so -%{_bindir}/tdm-backend -%{_bindir}/tinyds-tdm -%{_bindir}/tinyds-tdm-hwc -%{_bindir}/ds-simple-tbm -%{_bindir}/tinyds-tdm-libinput -%{_bindir}/input-generator - %files allocator-tbm %manifest %{name}.manifest %defattr(-,root,root,-) @@ -194,6 +166,10 @@ ninja -C builddir install %{_includedir}/libds-tizen/backend/tdm_output_hwc.h %{_libdir}/pkgconfig/libds-tizen-backend-tdm.pc %{_libdir}/libds-tizen-backend-tdm.so +%{_bindir}/tdm-backend +%{_bindir}/tinyds-tdm +%{_bindir}/tinyds-tdm-hwc +%{_bindir}/ds-simple-tbm %files tbm-server %manifest %{name}.manifest diff --git a/src/allocator/tbm/meson.build b/src/allocator/tbm/meson.build index b2ee630..8a6b882 100644 --- a/src/allocator/tbm/meson.build +++ b/src/allocator/tbm/meson.build @@ -3,7 +3,7 @@ libds_tizen_allocator_tbm_files = files( ) libds_tizen_allocator_tbm_deps = [ - dep_libds_tizen, + deps_libds_tizen, dependency('libtbm', required: true) ] diff --git a/src/backend/tdm/meson.build b/src/backend/tdm/meson.build index bca5bca..131a2f3 100644 --- a/src/backend/tdm/meson.build +++ b/src/backend/tdm/meson.build @@ -6,7 +6,7 @@ libds_tizen_backend_tdm_files = files( ) libds_tizen_backend_tdm_deps = [ - dep_libds_tizen, + deps_libds_tizen, dep_libds_tizen_allocator_tbm, dep_libds_tizen_tbm_server, dependency('libtdm', required: true), diff --git a/src/dpms/meson.build b/src/dpms/meson.build index 2de950f..61ff9f5 100644 --- a/src/dpms/meson.build +++ b/src/dpms/meson.build @@ -3,7 +3,7 @@ libds_tizen_dpms_files = [ ] libds_tizen_dpms_deps = [ - dep_libds_tizen, + deps_libds_tizen, dependency('tizen-dpms-server', required: true), ] diff --git a/src/input-devicemgr/meson.build b/src/input-devicemgr/meson.build index 1e69463..dcf898c 100644 --- a/src/input-devicemgr/meson.build +++ b/src/input-devicemgr/meson.build @@ -4,7 +4,7 @@ libds_tizen_input_devicemgr_files = [ ] libds_tizen_input_devicemgr_deps = [ - dep_libds_tizen, + deps_libds_tizen, deps_tizen_security, dependency('tizen-extension-server', required: true), ] diff --git a/src/keyrouter/meson.build b/src/keyrouter/meson.build index af235ce..6f49792 100644 --- a/src/keyrouter/meson.build +++ b/src/keyrouter/meson.build @@ -5,7 +5,7 @@ libds_tizen_keyrouter_files = [ ] libds_tizen_keyrouter_deps = [ - dep_libds_tizen, + deps_libds_tizen, deps_tizen_security, dependency('tizen-extension-server', required: true), ] diff --git a/src/meson.build b/src/meson.build index 4d8a290..a77f291 100644 --- a/src/meson.build +++ b/src/meson.build @@ -1,6 +1,3 @@ -libds_tizen_files = [ -] - math = meson.get_compiler('c').find_library('m') wayland_server = dependency('wayland-server', required: true) rt = meson.get_compiler('c').find_library('rt') @@ -12,13 +9,13 @@ endif base_deps = [ math, - wayland_server, xkbcommon, rt, ] -libds_tizen_deps = [ +deps_libds_tizen = [ base_deps, + wayland_server, dependency('libds', required: true), ] @@ -33,27 +30,6 @@ deps_tizen_security = [ dependency('libsmack', required: true) ] -lib_libds_tizen = shared_library('ds-tizen', libds_tizen_files, - dependencies: libds_tizen_deps, - include_directories: [ common_inc, include_directories('.') ], - version: meson.project_version(), - install: true -) - -dep_libds_tizen = declare_dependency( - link_with: lib_libds_tizen, - dependencies: libds_tizen_deps, - include_directories: [ common_inc, include_directories('.') ], -) - -pkgconfig = import('pkgconfig') -pkgconfig.generate(lib_libds_tizen, - version: meson.project_version(), - filebase: 'libds-tizen', - name: 'libds-tizen', - description: 'extension of libds for tizen platform', -) - subdir('allocator') subdir('tbm-server') subdir('backend') diff --git a/src/tbm-server/meson.build b/src/tbm-server/meson.build index c83ff6c..25f186e 100644 --- a/src/tbm-server/meson.build +++ b/src/tbm-server/meson.build @@ -4,7 +4,7 @@ libds_tizen_tbm_server_files = [ ] libds_tizen_tbm_server_deps = [ - dep_libds_tizen, + deps_libds_tizen, dependency('libdrm', required: true), dependency('libtbm', required: true), dependency('wayland-tbm-server', required: true), diff --git a/tests/meson.build b/tests/meson.build index 19f1e1d..dae7875 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -12,7 +12,7 @@ tests = [ ] foreach t : tests - t_deps = [ dep_libds_tizen ] + t_deps = [ deps_libds_tizen ] t_deps += t.get('deps', []) test('libds-tizen-' + t.get('name'), -- 2.7.4 From b13ff5ae71c1d8c47ba192f9e3f043928ac7df48 Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Thu, 30 Jun 2022 09:40:29 +0900 Subject: [PATCH 13/16] change the var name Change-Id: I9b4cdb7b7d86f4abb05c1e5840aaf9be94d690f1 --- examples/meson.build | 18 +++++++++--------- src/allocator/tbm/meson.build | 2 +- src/backend/tdm/meson.build | 6 +++--- src/dpms/meson.build | 2 +- src/input-devicemgr/meson.build | 2 +- src/keyrouter/meson.build | 2 +- src/tbm-server/meson.build | 2 +- 7 files changed, 17 insertions(+), 17 deletions(-) diff --git a/examples/meson.build b/examples/meson.build index 21b6ef9..d9fca10 100644 --- a/examples/meson.build +++ b/examples/meson.build @@ -8,8 +8,8 @@ executable('tdm-backend', 'tdm-backend.c', dependencies: [ common_deps, - dep_libds_tizen_backend_tdm, - dep_libds_tizen_tbm_server, + deps_libds_tizen_backend_tdm, + deps_libds_tizen_tbm_server, ], install_dir: libds_tizen_bindir, install : true @@ -26,8 +26,8 @@ executable('tinyds-tdm', tinyds_tdm_files, dependencies: [ common_deps, - dep_libds_tizen_backend_tdm, - dep_libds_tizen_tbm_server, + deps_libds_tizen_backend_tdm, + deps_libds_tizen_tbm_server, dependency('pixman-1', required: true), dependency('threads', required: true), ], @@ -46,8 +46,8 @@ executable('tinyds-tdm-libinput', tinyds_tdm_libinput_files, dependencies: [ common_deps, - dep_libds_tizen_backend_tdm, - dep_libds_tizen_input_devicemgr, + deps_libds_tizen_backend_tdm, + deps_libds_tizen_input_devicemgr, dependency('pixman-1', required: true), dependency('threads', required: true), ], @@ -62,8 +62,8 @@ executable('tinyds-tdm-dpms', 'tinyds-tdm-renderer.c', dependencies: [ common_deps, - dep_libds_tizen_backend_tdm, - dep_libds_tizen_dpms, + deps_libds_tizen_backend_tdm, + deps_libds_tizen_dpms, dependency('pixman-1', required: true), dependency('threads', required: true), ], @@ -81,7 +81,7 @@ executable('tinyds-tdm-hwc', tinyds_tdm_hwc_files, dependencies: [ common_deps, - dep_libds_tizen_backend_tdm, + deps_libds_tizen_backend_tdm, dependency('pixman-1', required: true), dependency('threads', required: true), ], diff --git a/src/allocator/tbm/meson.build b/src/allocator/tbm/meson.build index 8a6b882..09e16bb 100644 --- a/src/allocator/tbm/meson.build +++ b/src/allocator/tbm/meson.build @@ -14,7 +14,7 @@ lib_libds_tizen_allocator_tbm = shared_library('ds-tizen-allocator-tbm', libds_t install: true ) -dep_libds_tizen_allocator_tbm = declare_dependency( +deps_libds_tizen_allocator_tbm = declare_dependency( link_with: lib_libds_tizen_allocator_tbm, dependencies: libds_tizen_allocator_tbm_deps, include_directories: [ common_inc, include_directories('.') ], diff --git a/src/backend/tdm/meson.build b/src/backend/tdm/meson.build index 131a2f3..359f88d 100644 --- a/src/backend/tdm/meson.build +++ b/src/backend/tdm/meson.build @@ -7,8 +7,8 @@ libds_tizen_backend_tdm_files = files( libds_tizen_backend_tdm_deps = [ deps_libds_tizen, - dep_libds_tizen_allocator_tbm, - dep_libds_tizen_tbm_server, + deps_libds_tizen_allocator_tbm, + deps_libds_tizen_tbm_server, dependency('libtdm', required: true), dependency('libtbm', required: true) ] @@ -20,7 +20,7 @@ lib_libds_tizen_backend_tdm = shared_library('ds-tizen-backend-tdm', libds_tizen install: true ) -dep_libds_tizen_backend_tdm = declare_dependency( +deps_libds_tizen_backend_tdm = declare_dependency( link_with: lib_libds_tizen_backend_tdm, dependencies: libds_tizen_backend_tdm_deps, include_directories: [ common_inc, include_directories('.') ], diff --git a/src/dpms/meson.build b/src/dpms/meson.build index 61ff9f5..e752c68 100644 --- a/src/dpms/meson.build +++ b/src/dpms/meson.build @@ -14,7 +14,7 @@ lib_libds_tizen_dpms = shared_library('ds-tizen-dpms', libds_tizen_dpms_files, install: true ) -dep_libds_tizen_dpms = declare_dependency( +deps_libds_tizen_dpms = declare_dependency( link_with: lib_libds_tizen_dpms, dependencies: libds_tizen_dpms_deps, include_directories: [ common_inc, include_directories('.') ], diff --git a/src/input-devicemgr/meson.build b/src/input-devicemgr/meson.build index dcf898c..f84f542 100644 --- a/src/input-devicemgr/meson.build +++ b/src/input-devicemgr/meson.build @@ -16,7 +16,7 @@ lib_libds_tizen_input_devicemgr = shared_library('ds-tizen-input-devicemgr', lib install: true ) -dep_libds_tizen_input_devicemgr = declare_dependency( +deps_libds_tizen_input_devicemgr = declare_dependency( link_with: lib_libds_tizen_input_devicemgr, dependencies: libds_tizen_input_devicemgr_deps, include_directories: [ common_inc, include_directories('.') ], diff --git a/src/keyrouter/meson.build b/src/keyrouter/meson.build index 6f49792..db1fec9 100644 --- a/src/keyrouter/meson.build +++ b/src/keyrouter/meson.build @@ -20,7 +20,7 @@ lib_libds_tizen_keyrouter = shared_library('ds-tizen-keyrouter', libds_tizen_key install: true ) -dep_libds_tizen_keyrouter = declare_dependency( +deps_libds_tizen_keyrouter = declare_dependency( link_with: lib_libds_tizen_keyrouter, dependencies: libds_tizen_keyrouter_deps, include_directories: [ common_inc, include_directories('.') ], diff --git a/src/tbm-server/meson.build b/src/tbm-server/meson.build index 25f186e..ced06a4 100644 --- a/src/tbm-server/meson.build +++ b/src/tbm-server/meson.build @@ -17,7 +17,7 @@ lib_libds_tizen_tbm_server = shared_library('ds-tizen-tbm-server', libds_tizen_t install: true ) -dep_libds_tizen_tbm_server = declare_dependency( +deps_libds_tizen_tbm_server = declare_dependency( link_with: lib_libds_tizen_tbm_server, dependencies: libds_tizen_tbm_server_deps, include_directories: [ common_inc, include_directories('.') ], -- 2.7.4 From 60ffc8f415be010523435d85ac55613916ff69fa Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Thu, 30 Jun 2022 09:47:07 +0900 Subject: [PATCH 14/16] remove xkbcommon from base_dep Change-Id: I43f6bea638488d1c066a984ee1623285405e8f58 --- src/input-devicemgr/meson.build | 1 + src/meson.build | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/input-devicemgr/meson.build b/src/input-devicemgr/meson.build index f84f542..4616f6f 100644 --- a/src/input-devicemgr/meson.build +++ b/src/input-devicemgr/meson.build @@ -7,6 +7,7 @@ libds_tizen_input_devicemgr_deps = [ deps_libds_tizen, deps_tizen_security, dependency('tizen-extension-server', required: true), + dependency('xkbcommon', required: true), ] lib_libds_tizen_input_devicemgr = shared_library('ds-tizen-input-devicemgr', libds_tizen_input_devicemgr_files, diff --git a/src/meson.build b/src/meson.build index a77f291..64f5d1f 100644 --- a/src/meson.build +++ b/src/meson.build @@ -1,7 +1,6 @@ math = meson.get_compiler('c').find_library('m') wayland_server = dependency('wayland-server', required: true) rt = meson.get_compiler('c').find_library('rt') -xkbcommon = dependency('xkbcommon', required: true) if wayland_server.version().version_compare('>= 1.19') cdata.set('HAVE_WL_SEAT_ERROR_MISSING_CAPABILITY', '1') @@ -9,7 +8,6 @@ endif base_deps = [ math, - xkbcommon, rt, ] -- 2.7.4 From 706e87bb9aa05678a0a0d664587c0148cde8feb6 Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Thu, 30 Jun 2022 09:48:07 +0900 Subject: [PATCH 15/16] change the name of base_deps into deps_base Change-Id: Ifb6fe3f03cc1d8d9e86341f54c000f7f03f9f1ef --- src/meson.build | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/meson.build b/src/meson.build index 64f5d1f..b4b92f5 100644 --- a/src/meson.build +++ b/src/meson.build @@ -6,13 +6,13 @@ if wayland_server.version().version_compare('>= 1.19') cdata.set('HAVE_WL_SEAT_ERROR_MISSING_CAPABILITY', '1') endif -base_deps = [ +deps_base = [ math, rt, ] deps_libds_tizen = [ - base_deps, + deps_base, wayland_server, dependency('libds', required: true), ] @@ -22,7 +22,6 @@ tizen_security_files = [ ] deps_tizen_security = [ - base_deps, dependency('cynara-client', required: true), dependency('cynara-session', required: true), dependency('libsmack', required: true) -- 2.7.4 From 60ea1f4373e6ceb6eb99ef2dd7699a7468a098e0 Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Mon, 4 Jul 2022 19:23:19 +0900 Subject: [PATCH 16/16] change file names and folder names use the underbar instead of a hyphen when you name files and folders. Change-Id: I72c903fef3f5e2dc4fbc4df09524b7215c211685 --- examples/tinyds-tdm-dpms.c | 2 +- examples/tinyds-tdm-hwc.c | 2 +- examples/tinyds-tdm-libinput.c | 4 +- examples/tinyds-tdm.c | 2 +- include/libds-tizen/input-devicemgr.h | 44 - include/libds-tizen/tbm-server.h | 33 - packaging/libds-tizen.spec | 4 +- src/backend/tdm/tdm_output_hwc.c | 2 +- src/input-devicemgr/input-devicemgr.c | 1551 --------------------------------- src/input-devicemgr/input-devicemgr.h | 78 -- src/input-devicemgr/meson.build | 32 - src/meson.build | 4 +- src/tbm-server/meson.build | 32 - src/tbm-server/pixel_format.c | 61 -- src/tbm-server/pixel_format.h | 10 - src/tbm-server/tbm-server.c | 268 ------ src/tbm-server/tbm-server.h | 34 - tests/meson.build | 8 +- tests/test-backend.c | 80 -- tests/test-compositor.c | 63 -- tests/test-subsurface.c | 211 ----- tests/test-surface.c | 162 ---- 22 files changed, 14 insertions(+), 2673 deletions(-) delete mode 100644 include/libds-tizen/input-devicemgr.h delete mode 100644 include/libds-tizen/tbm-server.h delete mode 100644 src/input-devicemgr/input-devicemgr.c delete mode 100644 src/input-devicemgr/input-devicemgr.h delete mode 100644 src/input-devicemgr/meson.build delete mode 100644 src/tbm-server/meson.build delete mode 100644 src/tbm-server/pixel_format.c delete mode 100644 src/tbm-server/pixel_format.h delete mode 100644 src/tbm-server/tbm-server.c delete mode 100644 src/tbm-server/tbm-server.h delete mode 100644 tests/test-backend.c delete mode 100644 tests/test-compositor.c delete mode 100644 tests/test-subsurface.c delete mode 100644 tests/test-surface.c diff --git a/examples/tinyds-tdm-dpms.c b/examples/tinyds-tdm-dpms.c index ab34297..dc32e8f 100644 --- a/examples/tinyds-tdm-dpms.c +++ b/examples/tinyds-tdm-dpms.c @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #define USE_TDM_BUFFER_QUEUE diff --git a/examples/tinyds-tdm-hwc.c b/examples/tinyds-tdm-hwc.c index 762fe07..46925f1 100644 --- a/examples/tinyds-tdm-hwc.c +++ b/examples/tinyds-tdm-hwc.c @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #define USE_TDM_BUFFER_QUEUE diff --git a/examples/tinyds-tdm-libinput.c b/examples/tinyds-tdm-libinput.c index 809f8cf..b1974f1 100644 --- a/examples/tinyds-tdm-libinput.c +++ b/examples/tinyds-tdm-libinput.c @@ -16,14 +16,14 @@ #include #include #include -#include +#include #include #include #include #include #include -#include +#include #include #include diff --git a/examples/tinyds-tdm.c b/examples/tinyds-tdm.c index 57b502c..4bc08f1 100644 --- a/examples/tinyds-tdm.c +++ b/examples/tinyds-tdm.c @@ -15,7 +15,7 @@ #include #include #include -#include +#include #define USE_TDM_BUFFER_QUEUE diff --git a/include/libds-tizen/input-devicemgr.h b/include/libds-tizen/input-devicemgr.h deleted file mode 100644 index fc1060e..0000000 --- a/include/libds-tizen/input-devicemgr.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef LIBDS_TIZEN_INPUT_DEVICEMGR_H -#define LIBDS_TIZEN_INPUT_DEVICEMGR_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -struct ds_tizen_input_devicemgr; -struct ds_backend; -struct ds_seat; - -struct ds_tizen_input_devicemgr_keymap_data -{ - char *name; - int keycode; - - struct wl_list link; -}; - -struct ds_tizen_input_devicemgr * -ds_tizen_input_devicemgr_create(struct ds_backend *backend, - struct ds_seat *seat); - -void -ds_tizen_input_devicemgr_add_destroy_listener( - struct ds_tizen_input_devicemgr *devicemgr, - struct wl_listener *listener); - -bool -ds_tizen_input_devicemgr_set_keymap_list( - struct ds_tizen_input_devicemgr *devicemgr, - struct wl_list *list); - -bool -ds_tizen_input_devicemgr_set_output_width_height( - struct ds_tizen_input_devicemgr *devicemgr, - uint32_t width, uint32_t height); -#ifdef __cplusplus -} -#endif - -#endif diff --git a/include/libds-tizen/tbm-server.h b/include/libds-tizen/tbm-server.h deleted file mode 100644 index 6e3b148..0000000 --- a/include/libds-tizen/tbm-server.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef LIBDS_TIZEN_TBM_SERVER_H -#define LIBDS_TIZEN_TBM_SERVER_H - -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -struct ds_tbm_server; - -struct ds_tbm_client_buffer; - -struct ds_tbm_server * -ds_tbm_server_create(struct wl_display *display); - -void -ds_tbm_server_add_destroy_listener(struct ds_tbm_server *tbm, - struct wl_listener *listener); - -struct ds_tbm_client_buffer * -ds_tbm_client_buffer_from_buffer(struct ds_buffer *ds_buffer); - -tbm_surface_h -ds_tbm_client_buffer_get_tbm_surface(struct ds_tbm_client_buffer *buffer); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/packaging/libds-tizen.spec b/packaging/libds-tizen.spec index f2702ee..fe34941 100644 --- a/packaging/libds-tizen.spec +++ b/packaging/libds-tizen.spec @@ -181,7 +181,7 @@ ninja -C builddir install %manifest %{name}.manifest %defattr(-,root,root,-) %license LICENSE -%{_includedir}/libds-tizen/tbm-server.h +%{_includedir}/libds-tizen/tbm_server.h %{_libdir}/pkgconfig/libds-tizen-tbm-server.pc %{_libdir}/libds-tizen-tbm-server.so @@ -209,7 +209,7 @@ ninja -C builddir install %manifest %{name}.manifest %defattr(-,root,root,-) %license LICENSE -%{_includedir}/libds-tizen/input-devicemgr.h +%{_includedir}/libds-tizen/input_devicemgr.h %{_libdir}/pkgconfig/libds-tizen-input-devicemgr.pc %{_libdir}/libds-tizen-input-devicemgr.so %{_bindir}/tinyds-tdm-libinput diff --git a/src/backend/tdm/tdm_output_hwc.c b/src/backend/tdm/tdm_output_hwc.c index e66b5fa..48aef1d 100644 --- a/src/backend/tdm/tdm_output_hwc.c +++ b/src/backend/tdm/tdm_output_hwc.c @@ -4,7 +4,7 @@ #include #include -#include +#include #include "tdm_internal.h" diff --git a/src/input-devicemgr/input-devicemgr.c b/src/input-devicemgr/input-devicemgr.c deleted file mode 100644 index b3fc567..0000000 --- a/src/input-devicemgr/input-devicemgr.c +++ /dev/null @@ -1,1551 +0,0 @@ -#include -#include // gettimeofday() -#include -#include -#include -#include -#include -#include -#include - -#include "util.h" -#include "security.h" -#include "input-devicemgr.h" - -#define TIZEN_INPUT_DEVICEMGR_VERSION 4 -#define TIZEN_PRIV_INPUT_GENERATOR "http://tizen.org/privilege/inputgenerator" -#define TIZEN_PRIV_INPUT_BLOCK "http://tizen.org/privilege/internal/inputdevice.block" -#define TIZEN_INPUT_DEVICEMGR_MAX_BTN 16 - -static const struct ds_keyboard_grab_interface devicemgr_keyboard_grab_iface; - -//listeners -static void -backend_handle_destroy(struct wl_listener *listener, void *data); -static void -backend_handle_input_device_add(struct wl_listener *listener, void *data); -static void -seat_handle_destroy(struct wl_listener *listener, void *data); - -//tizen_input_device_manager bind/unbind -static void -device_manager_handle_bind(struct wl_client *client, void *data, - uint32_t version, uint32_t id); -static void -device_manager_client_handle_resource_destroy(struct wl_resource *resource); - -//tizen_input_device_manager's handlers for requests -static void -device_manager_handle_block_events(struct wl_client *client, - struct wl_resource *resource, uint32_t serial, - uint32_t clas, uint32_t duration); -static void -device_manager_handle_unblock_events(struct wl_client *client, - struct wl_resource *resource, uint32_t serial); -static void -device_manager_handle_init_generator(struct wl_client *client, - struct wl_resource *resource, uint32_t clas); -static void -device_manager_handle_init_generator_with_name(struct wl_client *client, - struct wl_resource *resource, uint32_t clas, const char *name); -static void -device_manager_handle_deinit_generator(struct wl_client *client, - struct wl_resource *resource, uint32_t clas); -static void -device_manager_handle_generate_key(struct wl_client *client, - struct wl_resource *resource, - const char *keyname, uint32_t pressed); -static void -device_manager_handle_generate_touch(struct wl_client *client, - struct wl_resource *resource, uint32_t type, uint32_t x, uint32_t y, - uint32_t finger); -static void -device_manager_handle_generate_pointer(struct wl_client *client, - struct wl_resource *resource, uint32_t type, uint32_t x, uint32_t y, - uint32_t button); -static void -device_manager_handle_destroy(struct wl_client *client, - struct wl_resource *resource); - -// -static void tz_devicemgr_destroy(struct ds_tizen_input_devicemgr *tz_devicemgr); -static int -tz_devicemgr_init_generator(struct ds_tizen_input_devicemgr *tz_devicemgr, - struct wl_resource *resource, uint32_t clas, const char *name); -static int -tz_devicemgr_deinit_generator(struct ds_tizen_input_devicemgr *tz_devicemgr, - struct wl_resource *resource); -static bool -tz_devicemgr_generate_key(struct ds_input_device *device, int keycode, - int pressed); -static bool -tz_devicemgr_pressed_keys_update(struct ds_tizen_input_devicemgr *tz_devicemgr, - int keycode, bool pressed); -static void -tz_devicemgr_pressed_keys_cleanup(struct ds_tizen_input_devicemgr *tz_devicemgr); -static void -tz_devicemgr_keymap_list_cleanup(struct ds_tizen_input_devicemgr *tz_devicemgr); -static int -tz_devicemgr_keyname_to_keycode(struct wl_list *list, const char *name); - -static bool -tz_devicemgr_generate_touch_move(struct ds_input_device *device, double x, double y, - uint32_t finger); -static bool -tz_devicemgr_generate_touch_down(struct ds_input_device *device, double x, double y, - uint32_t finger); -static bool -tz_devicemgr_generate_touch_up(struct ds_input_device *device, uint32_t finger); -static bool -tz_devicemgr_generate_mouse_move(struct ds_input_device *device, double x, double y); -static bool -tz_devicemgr_generate_mouse_button(struct ds_input_device *device, uint32_t button, bool state); - -static bool -tz_devicemgr_check_privilege(struct ds_tizen_input_devicemgr *tz_devicemgr, - struct wl_client *client, const char *rule); - -static void -tz_devicemgr_grab_keyboard(struct ds_tizen_input_devicemgr *tz_devicemgr); -static void -tz_devicemgr_ungrab_keyboard(struct ds_tizen_input_devicemgr *tz_devicemgr); -static void -tz_devicemgr_ungrab_keyboard_check(struct ds_tizen_input_devicemgr *tz_devicemgr); -static void -tz_devicemgr_blocked_keys_cleanup(struct ds_tizen_input_devicemgr *tz_devicemgr); - -WL_EXPORT struct ds_tizen_input_devicemgr * -ds_tizen_input_devicemgr_create(struct ds_backend *backend, - struct ds_seat *seat) -{ - struct ds_tizen_input_devicemgr *tz_devicemgr; - - tz_devicemgr = calloc(1, sizeof *tz_devicemgr); - if (!tz_devicemgr) { - ds_err("Fail to allocate ds_tizen_input_devicemgr"); - return NULL; - } - - tz_devicemgr->backend = backend; - tz_devicemgr->backend_destroy.notify = backend_handle_destroy; - ds_backend_add_destroy_listener(backend, &tz_devicemgr->backend_destroy); - - tz_devicemgr->seat = seat; - tz_devicemgr->seat_destroy.notify = seat_handle_destroy; - ds_seat_add_destroy_listener(seat, &tz_devicemgr->seat_destroy); - - tz_devicemgr->new_input.notify = backend_handle_input_device_add; - ds_backend_add_new_input_listener(backend, &tz_devicemgr->new_input); - - tz_devicemgr->global = wl_global_create(backend->display, - &tizen_input_device_manager_interface, - TIZEN_INPUT_DEVICEMGR_VERSION, - tz_devicemgr, device_manager_handle_bind); - if (!tz_devicemgr->global) { - goto err_global; - } - - tz_devicemgr->devices.kbd = calloc(1, - sizeof(struct ds_tizen_input_devicemgr_device)); - if (!tz_devicemgr->devices.kbd) { - goto err_kbd; - } - tz_devicemgr->devices.ptr = calloc(1, - sizeof(struct ds_tizen_input_devicemgr_device)); - if (!tz_devicemgr->devices.ptr) { - goto err_ptr; - } - tz_devicemgr->devices.touch = calloc(1, - sizeof(struct ds_tizen_input_devicemgr_device)); - if (!tz_devicemgr->devices.touch) { - goto err_touch; - } - tz_devicemgr->touch_max_count = 5;//TODO: make this variable configurable - - tz_devicemgr->grab = ds_seat_create_keyboard_grab( - tz_devicemgr->seat, &devicemgr_keyboard_grab_iface, tz_devicemgr); - if (!tz_devicemgr->grab) { - goto err_grab; - } - - wl_signal_init(&tz_devicemgr->events.destroy); - wl_list_init(&tz_devicemgr->clients); - wl_list_init(&tz_devicemgr->devices.kbd->key.pressed); - wl_list_init(&tz_devicemgr->keymap_list); - wl_list_init(&tz_devicemgr->blocked_keys); - - if (!tizen_security_init()) { - ds_inf("tizen_security_init() is failed. go on without security"); - } - - ds_inf("Global created: ds_tizen_input_devicemgr(%p) ", tz_devicemgr); - return tz_devicemgr; - -err_grab: - free(tz_devicemgr->devices.touch); -err_touch: - free(tz_devicemgr->devices.ptr); -err_ptr: - free(tz_devicemgr->devices.kbd); -err_kbd: - wl_global_destroy(tz_devicemgr->global); -err_global: - wl_list_remove(&tz_devicemgr->backend_destroy.link); - wl_list_remove(&tz_devicemgr->seat_destroy.link); - wl_list_remove(&tz_devicemgr->new_input.link); - free(tz_devicemgr); - return NULL; -} - -WL_EXPORT void -ds_tizen_input_devicemgr_add_destroy_listener( - struct ds_tizen_input_devicemgr *tz_devicemgr, - struct wl_listener *listener) -{ - wl_signal_add(&tz_devicemgr->events.destroy, listener); -} - -WL_EXPORT bool -ds_tizen_input_devicemgr_set_keymap_list( - struct ds_tizen_input_devicemgr *tz_devicemgr, struct wl_list *list) -{ - struct ds_tizen_input_devicemgr_keymap_data *data, *new_data; - - if (!tz_devicemgr || !list) { - ds_err("Please insert correct data\n"); - return false; - } - - wl_list_for_each(data, list, link) { - new_data = calloc(1, sizeof *data); - if (!new_data) { - ds_err("Failed to alloc memory"); - return false; - } - new_data->name = strdup(data->name); - new_data->keycode = data->keycode; - wl_list_insert(&tz_devicemgr->keymap_list, &new_data->link); - } - ds_inf("keymap set. length:%d", - wl_list_length(&tz_devicemgr->keymap_list)); - - return true; -} - -WL_EXPORT bool -ds_tizen_input_devicemgr_set_output_width_height( - struct ds_tizen_input_devicemgr *tz_devicemgr, - uint32_t width, uint32_t height) -{ - if (!tz_devicemgr) return false; - - tz_devicemgr->output.width = width; - tz_devicemgr->output.height = height; - - ds_inf("output's width: %d, height:%d", width, height); - - return true; -} - -static void -tz_devicemgr_destroy(struct ds_tizen_input_devicemgr *tz_devicemgr) -{ - struct ds_tizen_input_devicemgr_client *client_data, *tmp; - - tizen_security_finish(); - - tz_devicemgr_keymap_list_cleanup(tz_devicemgr); - tz_devicemgr_blocked_keys_cleanup(tz_devicemgr); - tz_devicemgr_ungrab_keyboard(tz_devicemgr); - ds_seat_keyboard_destroy_grab(tz_devicemgr->grab); - - wl_signal_emit(&tz_devicemgr->events.destroy, tz_devicemgr); - wl_list_remove(&tz_devicemgr->backend_destroy.link); - wl_list_remove(&tz_devicemgr->seat_destroy.link); - wl_list_remove(&tz_devicemgr->new_input.link); - - wl_global_destroy(tz_devicemgr->global); - - wl_list_for_each_safe(client_data, tmp, &tz_devicemgr->clients, link) { - wl_list_remove(&client_data->link); - tz_devicemgr_deinit_generator(tz_devicemgr, client_data->resource); - - wl_resource_set_user_data(client_data->resource, NULL); - free(client_data); - } - - free(tz_devicemgr->devices.touch); - free(tz_devicemgr->devices.ptr); - free(tz_devicemgr->devices.kbd); - free(tz_devicemgr); -} - -static void -backend_handle_destroy(struct wl_listener *listener, void *data) -{ - struct ds_tizen_input_devicemgr *tz_devicemgr; - - tz_devicemgr = wl_container_of(listener, tz_devicemgr, backend_destroy); - - ds_inf("Global destroy: ds_tizen_input_devicemgr(%p)", tz_devicemgr); - - tz_devicemgr_destroy(tz_devicemgr); -} - -static void -seat_handle_destroy(struct wl_listener *listener, void *data) -{ - struct ds_tizen_input_devicemgr *tz_devicemgr; - - tz_devicemgr = wl_container_of(listener, tz_devicemgr, seat_destroy); - - wl_list_remove(&tz_devicemgr->seat_destroy.link); - wl_list_init(&tz_devicemgr->seat_destroy.link); - tz_devicemgr->seat = NULL; -} - -static void -tz_devicemgr_device_close(struct ds_tizen_input_devicemgr_device *dev) -{ - if (!dev->input_device) return; - ds_input_device_destroy(dev->input_device); - dev->input_device = NULL; -} - -static void -backend_handle_input_device_add(struct wl_listener *listener, void *data) -{ - struct ds_input_device *dev = data; - struct ds_tizen_input_devicemgr *tz_devicemgr; - enum ds_input_device_type dev_type; - - tz_devicemgr = wl_container_of(listener, tz_devicemgr, new_input); - - dev_type = ds_input_device_get_type(dev); - if (dev_type == DS_INPUT_DEVICE_KEYBOARD) { - if (tz_devicemgr->devices.kbd->input_device) return; - ds_inf("devicemgr's kbd device is set to dev(%p)", dev); - tz_devicemgr->devices.kbd->input_device = dev; - } - else if (dev_type == DS_INPUT_DEVICE_POINTER) { - if (tz_devicemgr->devices.ptr->input_device) return; - ds_inf("devicemgr's ptr device is set to dev(%p)", dev); - tz_devicemgr->devices.ptr->input_device = dev; - } - else if (dev_type == DS_INPUT_DEVICE_TOUCH) { - if (tz_devicemgr->devices.touch->input_device) return; - ds_inf("devicemgr's touch device is set to dev(%p)", dev); - tz_devicemgr->devices.touch->input_device = dev; - } -} - -static const struct tizen_input_device_manager_interface _devicemgr_impl = { - .block_events = device_manager_handle_block_events, - .unblock_events = device_manager_handle_unblock_events, - .init_generator = device_manager_handle_init_generator, - .deinit_generator = device_manager_handle_deinit_generator, - .generate_key = device_manager_handle_generate_key, - .generate_pointer = device_manager_handle_generate_pointer, - .generate_touch = device_manager_handle_generate_touch, - .pointer_warp = NULL, - .init_generator_with_name = - device_manager_handle_init_generator_with_name, // v2 - .destroy = device_manager_handle_destroy, // v3 - .generate_axis = NULL, // v3 - .set_touch_count = NULL, // v4 -}; - -static void -device_manager_client_handle_resource_destroy(struct wl_resource *resource) -{ - struct ds_tizen_input_devicemgr *tz_devicemgr; - struct ds_tizen_input_devicemgr_client *client_data, *tmp; - - tz_devicemgr = wl_resource_get_user_data(resource); - - tz_devicemgr_deinit_generator(tz_devicemgr, resource); - - if (resource == tz_devicemgr->block_resource) { - tz_devicemgr_ungrab_keyboard_check(tz_devicemgr); - if (tz_devicemgr->timer) { - wl_event_source_remove(tz_devicemgr->timer); - tz_devicemgr->timer = NULL; - } - } - - wl_list_for_each_safe(client_data, tmp, &tz_devicemgr->clients, link) { - if (client_data->resource == resource) { - wl_list_remove(&client_data->link); - free(client_data); - } - } -} - -static void -device_manager_handle_bind(struct wl_client *client, void *data, - uint32_t version, uint32_t id) -{ - struct ds_tizen_input_devicemgr *tz_devicemgr = data; - struct ds_tizen_input_devicemgr_client *client_data; - - client_data = calloc(1, sizeof *client_data); - if (!client_data) { - ds_err("Failed to allocate memory !\n"); - wl_client_post_no_memory(client); - return; - } - - client_data->resource = wl_resource_create(client, - &tizen_input_device_manager_interface, MIN(version,4), id); - if (!client_data->resource) { - ds_err("Failed to create resource! (ver. :%d, id:%d)", version, id); - free(client_data); - wl_client_post_no_memory(client); - return; - } - - client_data->init = false; - wl_list_init(&client_data->link); - wl_list_insert(&tz_devicemgr->clients, &client_data->link); - - wl_resource_set_implementation(client_data->resource, &_devicemgr_impl, - tz_devicemgr, device_manager_client_handle_resource_destroy); -} - -static void -device_manager_handle_init_generator(struct wl_client *client, - struct wl_resource *resource, uint32_t clas) -{ - struct ds_tizen_input_devicemgr *tz_devicemgr; - int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES; - - tz_devicemgr = wl_resource_get_user_data(resource); - - if (!tz_devicemgr_check_privilege(tz_devicemgr, client, - TIZEN_PRIV_INPUT_GENERATOR)) { - ds_err("No permission to input generate"); - ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_PERMISSION; - goto finish; - } - - ret = tz_devicemgr_init_generator(tz_devicemgr, resource, clas, - "Input Generator"); - if (ret != TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE) { - ds_err("Failed to init input generator\n"); - goto finish; - } - -finish: - tizen_input_device_manager_send_error(resource, ret); -} - -static void -device_manager_handle_init_generator_with_name(struct wl_client *client, - struct wl_resource *resource, uint32_t clas, const char *name) -{ - struct ds_tizen_input_devicemgr *tz_devicemgr; - int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES; - - tz_devicemgr = wl_resource_get_user_data(resource); - - if (!name) { - ds_err("no name for device"); - ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_PARAMETER; - goto finish; - } - - if (!tz_devicemgr_check_privilege(tz_devicemgr, client, - TIZEN_PRIV_INPUT_GENERATOR)) { - ds_err("No permission to input generate"); - ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_PERMISSION; - goto finish; - } - - ret = tz_devicemgr_init_generator(tz_devicemgr, resource, clas, - name); - if (ret != TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE) { - ds_err("Failed to init input generator\n"); - goto finish; - } - -finish: - tizen_input_device_manager_send_error(resource, ret); -} - -static void -device_manager_handle_deinit_generator(struct wl_client *client, - struct wl_resource *resource, uint32_t clas __attribute__((unused))) -{ - struct ds_tizen_input_devicemgr *tz_devicemgr; - int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES; - - tz_devicemgr = wl_resource_get_user_data(resource); - - if (!tz_devicemgr_check_privilege(tz_devicemgr, client, - TIZEN_PRIV_INPUT_GENERATOR)) { - ds_err("No permission to input generate"); - ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_PERMISSION; - goto finish; - } - - ret = tz_devicemgr_deinit_generator(tz_devicemgr, resource); - if (ret != TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE) { - ds_err("Failed to deinit input generator\n"); - goto finish; - } - -finish: - tizen_input_device_manager_send_error(resource, ret); -} - -struct keycode_map{ - xkb_keysym_t keysym; - xkb_keycode_t keycode; -}; - -static void -find_keycode(struct xkb_keymap *keymap, xkb_keycode_t key, void *data) -{ - struct keycode_map *found_keycodes = (struct keycode_map *)data; - xkb_keysym_t keysym = found_keycodes->keysym; - int nsyms = 0; - const xkb_keysym_t *syms_out = NULL; - - if (found_keycodes->keycode) return; - - nsyms = xkb_keymap_key_get_syms_by_level(keymap, key, 0, 0, &syms_out); - if (nsyms && syms_out) { - if (*syms_out == keysym) { - found_keycodes->keycode = key; - } - } -} - -static void -tz_devicemgr_xkb_keycode_from_keysym(struct xkb_keymap *keymap, - xkb_keysym_t keysym, xkb_keycode_t *keycode) -{ - struct keycode_map found_keycodes = {0,}; - found_keycodes.keysym = keysym; - xkb_keymap_key_for_each(keymap, find_keycode, &found_keycodes); - - *keycode = found_keycodes.keycode; -} - -static int -tz_devicemgr_xkb_keyname_to_keycode(struct xkb_keymap *keymap, - const char *name) -{ - xkb_keysym_t keysym = 0x0; - xkb_keycode_t keycode = 0; - - if (!strncmp(name, "Keycode-", sizeof("Keycode-")-1)) { - keycode = atoi(name + 8); - } else { - keysym = xkb_keysym_from_name(name, XKB_KEYSYM_NO_FLAGS); - tz_devicemgr_xkb_keycode_from_keysym(keymap, keysym, &keycode); - } - - return keycode; -} - -static uint32_t -tz_devicemgr_client_get_device_clas(struct ds_tizen_input_devicemgr *tz_devicemgr, - struct wl_resource *resource) -{ - struct ds_tizen_input_devicemgr_client *client_data; - - wl_list_for_each(client_data, &tz_devicemgr->clients, link) { - if (client_data->resource == resource) - return client_data->clas; - } - return 0; -} - -static void -device_manager_handle_generate_key(struct wl_client *client, - struct wl_resource *resource, const char *keyname, uint32_t pressed) -{ - struct ds_tizen_input_devicemgr *tz_devicemgr; - int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES; - int keycode = 0; - bool res; - struct ds_keyboard *kbd; - uint32_t clas; - - tz_devicemgr = wl_resource_get_user_data(resource); - - clas = tz_devicemgr_client_get_device_clas(tz_devicemgr, resource); - if ((clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD) == 0) - { - ds_err("Keyboard generator is not initialized by client"); - goto finish; - } - - if (!tz_devicemgr->devices.kbd || - !tz_devicemgr->devices.kbd->input_device) { - ds_err("Keyboard device is not initialized\n"); - goto finish; - } - - if (!tz_devicemgr_check_privilege(tz_devicemgr, client, - TIZEN_PRIV_INPUT_GENERATOR)) { - ds_err("No permission to input generate"); - ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_PERMISSION; - goto finish; - } - - // keyname to keycode using xkb_info - kbd = ds_input_device_get_keyboard( - tz_devicemgr->devices.kbd->input_device); - if (kbd->keymap) { - keycode = tz_devicemgr_xkb_keyname_to_keycode(kbd->keymap, keyname); - } - - if (keycode <= 0) { - keycode = tz_devicemgr_keyname_to_keycode(&tz_devicemgr->keymap_list, - keyname); - } - if (keycode <= 0) - goto finish; - - res = tz_devicemgr_generate_key(tz_devicemgr->devices.kbd->input_device, - keycode, pressed); - if (!res) { - ds_err("Generating key is failed. key: %s, pressed: %d", - keyname, pressed); - goto finish; - } - res = tz_devicemgr_pressed_keys_update(tz_devicemgr, keycode, pressed); - if (!res) { - ds_err("Updating pressed keys is failed. key: %s, pressed: %d", - keyname, pressed); - goto finish; - } - ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE; - -finish: - tizen_input_device_manager_send_error(resource, ret); -} - -static void -device_manager_handle_generate_pointer(struct wl_client *client, - struct wl_resource *resource, uint32_t type, uint32_t x, uint32_t y, - uint32_t button) -{ - struct ds_tizen_input_devicemgr *tz_devicemgr; - int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES; - bool res; - bool state; - uint32_t clas; - - tz_devicemgr = wl_resource_get_user_data(resource); - - clas = tz_devicemgr_client_get_device_clas(tz_devicemgr, resource); - if ((clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_MOUSE) == 0) - { - ds_err("Pointer generator is not initialized by client"); - goto finish; - } - - if (!tz_devicemgr->devices.ptr || - !tz_devicemgr->devices.ptr->input_device) { - ds_err("Pointer device is not initialized\n"); - goto finish; - } - - if (!tz_devicemgr_check_privilege(tz_devicemgr, client, - TIZEN_PRIV_INPUT_GENERATOR)) { - ds_err("No permission to input generate"); - ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_PERMISSION; - goto finish; - } - - if (button <= 0 || button >= TIZEN_INPUT_DEVICEMGR_MAX_BTN) - { - ds_err("Invalid button: %d\n", button); - ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_PARAMETER; - goto finish; - } - - if (type == TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_UPDATE) { - res = tz_devicemgr_generate_mouse_move( - tz_devicemgr->devices.ptr->input_device, (double)x, (double)y); - if (!res) goto finish; - ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE; - } - else { - state = (type == TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_BEGIN) ? - true : false; - res = tz_devicemgr_generate_mouse_button( - tz_devicemgr->devices.ptr->input_device, button, state); - if (!res) goto finish; - if (state) tz_devicemgr->devices.ptr->mouse.pressed |= 1 << (button - 1); - else tz_devicemgr->devices.ptr->mouse.pressed &= ~(1 << (button - 1)); - ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE; - } - -finish: - tizen_input_device_manager_send_error(resource, ret); -} - -static void -device_manager_handle_generate_touch(struct wl_client *client, - struct wl_resource *resource, uint32_t type, uint32_t x, uint32_t y, - uint32_t finger) -{ - struct ds_tizen_input_devicemgr *tz_devicemgr; - double transformed_x = .0, transformed_y = .0; - int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES; - bool res; - uint32_t clas; - - tz_devicemgr = wl_resource_get_user_data(resource); - - clas = tz_devicemgr_client_get_device_clas(tz_devicemgr, resource); - if ((clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_TOUCHSCREEN) == 0) - { - ds_err("Touch generator is not initialized by client"); - goto finish; - } - - if (!tz_devicemgr->devices.touch || - !tz_devicemgr->devices.touch->input_device) { - ds_err("Touch device is not initialized\n"); - goto finish; - } - - if (!tz_devicemgr_check_privilege(tz_devicemgr, client, - TIZEN_PRIV_INPUT_GENERATOR)) { - ds_err("No permission to input generate"); - ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_PERMISSION; - goto finish; - } - - if (finger >= tz_devicemgr->touch_max_count) - { - ds_err("Invalid fingers: %d\n", finger); - ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_PARAMETER; - goto finish; - } - - if (tz_devicemgr->output.width != 0 && tz_devicemgr->output.height != 0) { - transformed_x = x / (double)tz_devicemgr->output.width; - transformed_y = y / (double)tz_devicemgr->output.height; - } - - switch(type) { - case TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_BEGIN: // 0 - res = tz_devicemgr_generate_touch_move( - tz_devicemgr->devices.touch->input_device, transformed_x, transformed_y, finger); - if (!res) break; - res= tz_devicemgr_generate_touch_down( - tz_devicemgr->devices.touch->input_device, transformed_x, transformed_y, finger); - if (!res) break; - tz_devicemgr->devices.touch->touch.pressed |= 1 << finger; - ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE; - break; - case TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_END: // 2 - res = tz_devicemgr_generate_touch_up( - tz_devicemgr->devices.touch->input_device, finger); - if (!res) break; - tz_devicemgr->devices.touch->touch.pressed &= ~(1 << finger); - ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE; - break; - case TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_UPDATE: // 1 - res = tz_devicemgr_generate_touch_move( - tz_devicemgr->devices.touch->input_device, transformed_x, transformed_y, finger); - if (!res) break; - ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE; - break; - default: - break; - } - -finish: - tizen_input_device_manager_send_error(resource, ret); -} - -static void -device_manager_handle_destroy(struct wl_client *client, - struct wl_resource *resource) -{ - wl_resource_destroy(resource); -} - -static bool -tz_devicemgr_check_privilege(struct ds_tizen_input_devicemgr *tz_devicemgr, - struct wl_client *client, const char *rule) -{ - pid_t pid = 0; - uid_t uid = 0; - gid_t gid = 0; - - if (!client) return false; - - wl_client_get_credentials(client, &pid, &uid, &gid); - - return tizen_security_check_privilege(pid, uid, rule); -} - -static const struct ds_input_device_interface input_device_iface = -{ - .destroy = NULL, -}; - -static struct ds_keyboard * -create_ds_keyboard() -{ - struct ds_keyboard *kbd; - kbd = calloc(1, sizeof *kbd); - if (!kbd) { - ds_err("Could not allocate memory"); - return NULL; - } - ds_keyboard_init(kbd, NULL); - - return kbd; -} - -static struct ds_pointer * -create_ds_pointer() -{ - struct ds_pointer *pointer; - pointer = calloc(1, sizeof *pointer); - if (!pointer) { - ds_err("Could not allocate memory"); - return NULL; - } - ds_pointer_init(pointer, NULL); - - return pointer; -} - -static struct ds_touch * -create_ds_touch() -{ - struct ds_touch *touch; - touch = calloc(1, sizeof *touch); - if (!touch) { - ds_err("Could not allocate memory"); - return NULL; - } - ds_touch_init(touch, NULL); - - return touch; -} - -static int -tz_devicemgr_create_device(struct ds_tizen_input_devicemgr_device *dev, - uint32_t clas, const char *name) -{ - int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES; - const char *dev_name; - - if (dev->name && strlen(dev->name) > 0) { - ds_inf("device already has name. name:%s", dev->name); - return TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE; - } - - if (dev->input_device) { - dev_name = ds_input_device_get_name(dev->input_device); - ds_inf("device was already set. name:%s", dev_name); - dev->name = strdup(dev_name); - return TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE; - } - - //input_device create - dev->input_device = calloc(1, sizeof(struct ds_input_device)); - if(!dev->input_device) { - ds_err("Failed to create input device !\n"); - return ret; - } - - if (clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD) - { - ds_input_device_init(dev->input_device, DS_INPUT_DEVICE_KEYBOARD, - &input_device_iface, name, -1, -1); - dev->input_device->keyboard = create_ds_keyboard(); - } - else if (clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_MOUSE) - { - ds_input_device_init(dev->input_device, DS_INPUT_DEVICE_POINTER, - &input_device_iface, name, -1, -1); - dev->input_device->pointer = create_ds_pointer(); - } - else if (clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_TOUCHSCREEN) - { - ds_input_device_init(dev->input_device, DS_INPUT_DEVICE_TOUCH, - &input_device_iface, name, -1, -1); - dev->input_device->touch = create_ds_touch(); - } - - dev->created = true; - dev->name = strdup(name); - - return TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE; -} - -static int -tz_devicemgr_init_generator(struct ds_tizen_input_devicemgr *tz_devicemgr, - struct wl_resource *resource, uint32_t clas, const char *name) -{ - int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES; - struct ds_tizen_input_devicemgr_client *client_data; - struct ds_tizen_input_devicemgr_device *dev; - bool inited = false; - - ds_inf("Init generator. name:%s", name); - - if (clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD) { - dev = tz_devicemgr->devices.kbd; - ret = tz_devicemgr_create_device(dev, clas, name); - if (ret == TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE) { - inited = true; - tz_devicemgr->devices.kbd->ref++; - } - if (dev->created) { - wl_signal_emit(&tz_devicemgr->backend->events.new_input, - dev->input_device); - } - } - if (clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_MOUSE) { - dev = tz_devicemgr->devices.ptr; - ret = tz_devicemgr_create_device(dev, clas, name); - if (ret == TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE) { - inited = true; - tz_devicemgr->devices.ptr->ref++; - } - if (dev->created) { - wl_signal_emit(&tz_devicemgr->backend->events.new_input, - dev->input_device); - } - } - if (clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_TOUCHSCREEN) { - dev = tz_devicemgr->devices.touch; - ret = tz_devicemgr_create_device(dev, clas, name); - if (ret == TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE) { - inited = true; - tz_devicemgr->devices.touch->ref++; - } - if (dev->created) { - wl_signal_emit(&tz_devicemgr->backend->events.new_input, - dev->input_device); - } - } - - if (inited) { - wl_list_for_each(client_data, &tz_devicemgr->clients, link) { - if (client_data->resource == resource) { - if (client_data->init == false) { - client_data->init = true; - client_data->clas = clas; - } - break; - } - } - } - - return ret; -} - -static int -tz_devicemgr_deinit_generator(struct ds_tizen_input_devicemgr *tz_devicemgr, - struct wl_resource *resource) -{ - int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES; - struct ds_tizen_input_devicemgr_client *client_data; - struct ds_tizen_input_devicemgr_device *dev; - uint32_t clas = 0; - int i = 0; - bool res; - - ds_inf("Deinit generator."); - wl_list_for_each(client_data, &tz_devicemgr->clients, link) { - if (client_data->resource == resource) { - if (client_data->init == true) { - client_data->init = false; - clas = client_data->clas; - break; - } else { - return ret; - } - } - } - if (clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD) { - dev = tz_devicemgr->devices.kbd; - dev->ref--; - if (dev->ref<= 0) { - dev->ref = 0; - tz_devicemgr_pressed_keys_cleanup(tz_devicemgr); - - if (dev->created) { - tz_devicemgr_device_close(dev); - dev->created = false; - } - free(dev->name); - dev->name = NULL; - } - } - if (clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_MOUSE) { - dev = tz_devicemgr->devices.ptr; - dev->ref--; - if (dev->ref <= 0) { - dev->ref = 0; - while(dev->mouse.pressed) - { - if (dev->mouse.pressed & (1 << i)) - { - res = tz_devicemgr_generate_mouse_button(dev->input_device, - i + 1, false); - if (!res) break; - dev->mouse.pressed &= ~(1 << i); - } - i++; - if (i >= TIZEN_INPUT_DEVICEMGR_MAX_BTN) break; - } - - if (dev->created) - { - tz_devicemgr_device_close(dev); - dev->created = false; - } - free(dev->name); - dev->name = NULL; - } - } - if (clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_TOUCHSCREEN) { - dev = tz_devicemgr->devices.touch; - dev->ref--; - if (dev->ref <= 0) { - dev->ref = 0; - while(dev->touch.pressed) - { - if (dev->touch.pressed & (1 << i)) - { - res = tz_devicemgr_generate_touch_up(dev->input_device, - i); - if (!res) break; - dev->touch.pressed &= ~(1 << i); - } - i++; - if (i >= tz_devicemgr->touch_max_count) break; - } - - if (dev->created) - { - tz_devicemgr_device_close(dev); - dev->created = false; - } - free(dev->name); - dev->name = NULL; - } - } - - return TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE; -} - -static int -tz_devicemgr_keyname_to_keycode(struct wl_list *list, const char *name) -{ - struct ds_tizen_input_devicemgr_keymap_data *data; - - if (!wl_list_empty(list)) { - wl_list_for_each(data, list, link) { - if (!strcmp(data->name, name)) { - return data->keycode; - } - } - } - - return 0; -} - -static bool -tz_devicemgr_generate_key(struct ds_input_device *device, int keycode, - int pressed) -{ - struct ds_event_keyboard_key ds_event; - struct timeval time; - unsigned int timestamp; - struct ds_keyboard *kbd; - - kbd = ds_input_device_get_keyboard(device); - if (!kbd) { - ds_err("No ds_keyboard to notify event"); - return false; - } - - gettimeofday(&time, NULL); - timestamp = time.tv_sec * 1000 + time.tv_usec / 1000; - - ds_event.time_msec = timestamp; - ds_event.keycode = keycode - 8; - if (pressed) - ds_event.state = WL_KEYBOARD_KEY_STATE_PRESSED; - else - ds_event.state = WL_KEYBOARD_KEY_STATE_RELEASED; - - ds_inf("Generate key. kbd:%p, key:%d, state:%s", kbd, ds_event.keycode, - (ds_event.state == WL_KEYBOARD_KEY_STATE_PRESSED) ? - "PRESSED" : "RELEASED"); - - ds_keyboard_notify_key(kbd, &ds_event); - - return true; -} - -static bool -tz_devicemgr_pressed_keys_update(struct ds_tizen_input_devicemgr *tz_devicemgr, - int keycode, bool pressed) -{ - struct ds_tizen_input_devicemgr_key_info *key, *tmp; - - if (pressed) { - key = calloc(1, sizeof(*key)); - if (!key) { - ds_err("Failed to alloc keydata memory.\n"); - return false; - } - key->keycode = keycode; - wl_list_init(&key->link); - wl_list_insert(&tz_devicemgr->devices.kbd->key.pressed, &key->link); - } - else { - wl_list_for_each_safe(key, tmp, &tz_devicemgr->devices.kbd->key.pressed, link) { - if (key->keycode == keycode) { - wl_list_remove(&key->link); - free(key); - break; - } - } - } - - ds_inf("Update pressed keys. length: %d, keycode:%d, pressed:%d", - wl_list_length(&tz_devicemgr->devices.kbd->key.pressed), keycode, pressed); - - return true; -} - -static void -tz_devicemgr_pressed_keys_cleanup(struct ds_tizen_input_devicemgr *tz_devicemgr) -{ - struct ds_tizen_input_devicemgr_key_info *keydata, *tmp; - - ds_inf("Clean up the kbd.pressed_keys. length: %d", - wl_list_length(&tz_devicemgr->devices.kbd->key.pressed)); - - wl_list_for_each_safe(keydata, tmp, &tz_devicemgr->devices.kbd->key.pressed, link) { - if (tz_devicemgr->devices.kbd) - tz_devicemgr_generate_key(tz_devicemgr->devices.kbd->input_device, - keydata->keycode, false); - wl_list_remove(&keydata->link); - free(keydata); - } -} - -static void -tz_devicemgr_keymap_list_cleanup(struct ds_tizen_input_devicemgr *tz_devicemgr) -{ - struct ds_tizen_input_devicemgr_keymap_data *keymap, *tmp; - - ds_inf("Clean up the keymap_list. length: %d", - wl_list_length(&tz_devicemgr->keymap_list)); - - wl_list_for_each_safe(keymap, tmp, &tz_devicemgr->keymap_list, link) { - free(keymap->name); - wl_list_remove(&keymap->link); - free(keymap); - } -} - -static bool -tz_devicemgr_generate_touch_move(struct ds_input_device *device, double x, double y, - uint32_t finger) -{ - struct ds_event_touch_motion ds_event; - struct timeval time; - unsigned int timestamp; - struct ds_touch *touch; - - touch = ds_input_device_get_touch(device); - if (!touch) { - ds_err("No ds_touch to notify event"); - return false; - } - - gettimeofday(&time, NULL); - timestamp = time.tv_sec * 1000 + time.tv_usec / 1000; - - ds_event.time_msec = timestamp; - ds_event.id = finger; - ds_event.x = x; - ds_event.y = y; - ds_inf("Generate touch motion. touch:%p, id:%d (%d, %d)", touch, ds_event.id, x, y); - - wl_signal_emit(&touch->events.motion, &ds_event); - - return true; -} - -static bool -tz_devicemgr_generate_touch_down(struct ds_input_device *device, double x, double y, - uint32_t finger) -{ - struct ds_event_touch_down ds_event; - struct timeval time; - unsigned int timestamp; - struct ds_touch *touch; - - touch = ds_input_device_get_touch(device); - if (!touch) { - ds_err("No ds_touch to notify event"); - return false; - } - - gettimeofday(&time, NULL); - timestamp = time.tv_sec * 1000 + time.tv_usec / 1000; - - ds_event.time_msec = timestamp; - ds_event.id = finger; - ds_event.x = x; - ds_event.y = y; - ds_inf("Generate touch down. touch:%p, id:%d (%d, %d)", touch, ds_event.id, x, y); - - wl_signal_emit(&touch->events.down, &ds_event); - - return true; -} - -static bool -tz_devicemgr_generate_touch_up(struct ds_input_device *device, uint32_t finger) -{ - struct ds_event_touch_up ds_event; - struct timeval time; - unsigned int timestamp; - struct ds_touch *touch; - - touch = ds_input_device_get_touch(device); - if (!touch) { - ds_err("No ds_touch to notify event"); - return false; - } - - gettimeofday(&time, NULL); - timestamp = time.tv_sec * 1000 + time.tv_usec / 1000; - - ds_event.time_msec = timestamp; - ds_event.id = finger; - ds_inf("Generate touch up. touch:%p, id:%d", touch, ds_event.id); - - wl_signal_emit(&touch->events.up, &ds_event); - - return true; -} - -static bool -tz_devicemgr_generate_mouse_move(struct ds_input_device *device, double x, double y) -{ - struct ds_event_pointer_motion ds_event; - struct timeval time; - unsigned int timestamp; - struct ds_pointer *pointer; - - pointer = ds_input_device_get_pointer(device); - if (!pointer) { - ds_err("No ds_pointer to notify event"); - return false; - } - - gettimeofday(&time, NULL); - timestamp = time.tv_sec * 1000 + time.tv_usec / 1000; - - ds_event.time_msec = timestamp; - ds_event.delta_x = x; - ds_event.delta_y = y; - ds_inf("Generate mouse motion. pointer:%p, x:%f, y:%f", pointer, ds_event.delta_x, ds_event.delta_y); - - wl_signal_emit(&pointer->events.motion, &ds_event); - - return true; -} - -static bool -tz_devicemgr_generate_mouse_button(struct ds_input_device *device, uint32_t button, bool state) -{ - struct ds_event_pointer_button ds_event; - struct timeval time; - unsigned int timestamp; - struct ds_pointer *pointer; - - pointer = ds_input_device_get_pointer(device); - if (!pointer) { - ds_err("No ds_pointer to notify event"); - return false; - } - - gettimeofday(&time, NULL); - timestamp = time.tv_sec * 1000 + time.tv_usec / 1000; - - ds_event.time_msec = timestamp; - ds_event.button = button; - if (state) - ds_event.state = DS_BUTTON_PRESSED; - else - ds_event.state = DS_BUTTON_RELEASED; - ds_inf("Generate mouse button. pointer:%p, button:%d, state:%s", pointer, ds_event.button, state ? "PRESSED" : "RELEASED"); - - wl_signal_emit(&pointer->events.button, &ds_event); - - return true; -} - -static void -devicemgr_keyboard_grab_iface_enter(struct ds_seat_keyboard_grab *grab, - struct ds_surface *surface, uint32_t keycodes[], - size_t num_keycodes, struct ds_keyboard_modifiers *modifiers) -{ - ds_inf("devicemgr. keyboard_grab_iface_enter"); -} - -static void -devicemgr_keyboard_grab_iface_clear_focus(struct ds_seat_keyboard_grab *grab) -{ - ds_inf("devicemgr. keyboard_grab_iface_clear_focus"); -} - -static void -tz_devicemgr_blocked_keys_cleanup(struct ds_tizen_input_devicemgr *tz_devicemgr) -{ - struct ds_tizen_input_devicemgr_key_info *keydata, *tmp; - - ds_inf("Clean up the blocked keys. length: %d", - wl_list_length(&tz_devicemgr->blocked_keys)); - - wl_list_for_each_safe(keydata, tmp, &tz_devicemgr->blocked_keys, link) { - wl_list_remove(&keydata->link); - free(keydata); - } -} - -static void -devicemgr_keyboard_grab_iface_key(struct ds_seat_keyboard_grab *grab, - uint32_t time_msec, uint32_t key, uint32_t state) -{ - struct ds_tizen_input_devicemgr *devicemgr; - struct ds_tizen_input_devicemgr_key_info *keydata, *tmp; - bool key_blocked = false; - - ds_inf("devicemgr. keyboard_grab_iface_key"); - - devicemgr = ds_seat_keyboard_grab_get_data(grab); - if (!devicemgr->block_resource) { - if (state == WL_KEYBOARD_KEY_STATE_PRESSED) { - goto finish; - } - else { - wl_list_for_each_safe(keydata, tmp, &devicemgr->blocked_keys, link) { - if (keydata->keycode == (int)key) { - wl_list_remove(&keydata->link); - free(keydata); - key_blocked = true; - break; - } - } - if (wl_list_empty(&devicemgr->blocked_keys)) { - tz_devicemgr_ungrab_keyboard(devicemgr); - } - if (key_blocked) { - goto finish; - } - } - } - - if (state == WL_KEYBOARD_KEY_STATE_PRESSED) { - keydata = calloc(1, sizeof (*keydata)); - if (!keydata) - goto finish; - keydata->keycode = key; - wl_list_init(&keydata->link); - wl_list_insert(&devicemgr->blocked_keys, &keydata->link); - key_blocked = true; - } - else { - if (wl_list_empty(&devicemgr->blocked_keys)) - goto finish; - wl_list_for_each_safe(keydata, tmp, &devicemgr->blocked_keys, link) { - if (keydata->keycode == (int)key) { - wl_list_remove(&keydata->link); - free(keydata); - key_blocked = true; - } - } - } - -finish: - if (!key_blocked) - ds_inf("block key event: (%d %s)\n", key, (state ? "press" : "release")); -} - -static void -devicemgr_modifiers_grab_iface_key(struct ds_seat_keyboard_grab *grab, - struct ds_keyboard_modifiers *modifiers) -{ - ds_inf("devicemgr. modifiers_grab_iface_key"); -} - -static void -devicemgr_cancel_grab_iface_key(struct ds_seat_keyboard_grab *grab) -{ - ds_inf("devicemgr. cancel_grab_iface_key"); -} - -static const struct ds_keyboard_grab_interface devicemgr_keyboard_grab_iface = { - .enter = devicemgr_keyboard_grab_iface_enter, - .clear_focus = devicemgr_keyboard_grab_iface_clear_focus, - .key = devicemgr_keyboard_grab_iface_key, - .modifiers = devicemgr_modifiers_grab_iface_key, - .cancel = devicemgr_cancel_grab_iface_key, -}; - -static void -tz_devicemgr_grab_keyboard(struct ds_tizen_input_devicemgr *tz_devicemgr) -{ - ds_seat_keyboard_start_grab(tz_devicemgr->seat, tz_devicemgr->grab); -} - -static void -tz_devicemgr_ungrab_keyboard(struct ds_tizen_input_devicemgr *tz_devicemgr) -{ - ds_seat_keyboard_end_grab(tz_devicemgr->seat); -} - -static void -tz_devicemgr_ungrab_keyboard_check(struct ds_tizen_input_devicemgr *tz_devicemgr) -{ - if (wl_list_empty(&tz_devicemgr->blocked_keys)) - tz_devicemgr_ungrab_keyboard(tz_devicemgr); - - tz_devicemgr->block_resource = NULL; -} - -static bool -devicemgr_add_timer(struct ds_tizen_input_devicemgr *tz_devicemgr, - wl_event_loop_timer_func_t func, int time) -{ - struct wl_event_loop *event_loop; - - event_loop = wl_display_get_event_loop(tz_devicemgr->backend->display); - if (!event_loop) { - ds_err("Failed to get event_loop from display: %p", - tz_devicemgr->backend->display); - return false; - } - - tz_devicemgr->timer = wl_event_loop_add_timer(event_loop, func, - tz_devicemgr); - if (!tz_devicemgr->timer) { - ds_err("Failed to timer"); - return false; - } - wl_event_source_timer_update(tz_devicemgr->timer, time); - - return true; -} - -static int -devicemgr_block_timer(void *data) -{ - struct ds_tizen_input_devicemgr *devicemgr = data; - - tizen_input_device_manager_send_block_expired(devicemgr->block_resource); - - tz_devicemgr_ungrab_keyboard_check(devicemgr); - - wl_event_source_remove(devicemgr->timer); - devicemgr->timer = NULL; - - return 1; -} - -static void -device_manager_handle_block_events(struct wl_client *client, - struct wl_resource *resource, uint32_t serial, uint32_t clas, - uint32_t duration) -{ - struct ds_tizen_input_devicemgr *tz_devicemgr; - int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES; - bool res; - - tz_devicemgr = wl_resource_get_user_data(resource); - - if (!tz_devicemgr_check_privilege(tz_devicemgr, client, - TIZEN_PRIV_INPUT_BLOCK)) { - ds_err("No permission to input generate"); - ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_PERMISSION; - goto finish; - } - - if (clas != TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD) { - ds_err("only support keyboard device. (requested: 0x%x)\n", clas); - ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_PARAMETER; - goto finish; - } - - if(tz_devicemgr->block_resource) { - ds_err("currently the input system is already blocked\n"); - ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_PARAMETER; - goto finish; - } - - res = devicemgr_add_timer(tz_devicemgr, devicemgr_block_timer, duration); - if (!res) { - ds_err("Failed to add a timer\n"); - goto finish; - } - - tz_devicemgr_grab_keyboard(tz_devicemgr); - tz_devicemgr->block_resource = resource; - ds_inf("Block events. clas: %d, duration:%d", clas, duration); - ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE; - -finish: - tizen_input_device_manager_send_error(resource, ret); -} - -static void -device_manager_handle_unblock_events(struct wl_client *client, - struct wl_resource *resource, uint32_t serial) -{ - struct ds_tizen_input_devicemgr *tz_devicemgr; - int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES; - - tz_devicemgr = wl_resource_get_user_data(resource); - - if (!tz_devicemgr_check_privilege(tz_devicemgr, client, - TIZEN_PRIV_INPUT_BLOCK)) { - ds_err("No permission to input generate"); - ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_PERMISSION; - goto finish; - } - - if (tz_devicemgr->block_resource != resource) { - ds_err("currently the input system is blocked by another resource"); - ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_PARAMETER; - goto finish; - } - - tz_devicemgr_ungrab_keyboard_check(tz_devicemgr); - tz_devicemgr->block_resource = NULL; - ds_inf("Unblock events."); - ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE; - - if (tz_devicemgr->timer) { - wl_event_source_remove(tz_devicemgr->timer); - tz_devicemgr->timer = NULL; - } - -finish: - tizen_input_device_manager_send_error(resource, ret); -} - diff --git a/src/input-devicemgr/input-devicemgr.h b/src/input-devicemgr/input-devicemgr.h deleted file mode 100644 index a4428ee..0000000 --- a/src/input-devicemgr/input-devicemgr.h +++ /dev/null @@ -1,78 +0,0 @@ -#ifndef DS_TIZEN_DEVICEMGR_H -#define DS_TIZEN_DEVICEMGR_H - -#include -#include -#include -#include -#include -#include - -struct ds_tizen_input_devicemgr_device { - char *name; - struct ds_input_device *input_device; - int ref; - - bool created; - - struct { - struct wl_list pressed; - } key; - - struct { - unsigned int pressed; - } touch; - - struct { - unsigned int pressed; - } mouse; -}; - -struct ds_tizen_input_devicemgr { - struct wl_global *global; - struct wl_display *display; - struct ds_backend *backend; - struct ds_seat *seat; - - struct { - struct wl_signal destroy; - } events; - - struct wl_listener new_input; - struct wl_listener backend_destroy; - struct wl_listener seat_destroy; - struct { - struct ds_tizen_input_devicemgr_device *kbd; - struct ds_tizen_input_devicemgr_device *ptr; - struct ds_tizen_input_devicemgr_device *touch; - } devices; - - struct wl_list clients; - - struct wl_list keymap_list; - - struct wl_list blocked_keys; - struct wl_resource *block_resource; - struct wl_event_source *timer; - struct ds_seat_keyboard_grab *grab; - int touch_max_count; - - struct { - uint32_t width; - uint32_t height; - } output; -}; - -struct ds_tizen_input_devicemgr_client { - struct wl_resource *resource; - bool init; - uint32_t clas; - struct wl_list link; // ds_tizen_input_devicemgr::clients -}; - -struct ds_tizen_input_devicemgr_key_info { - int keycode; - struct wl_list link; // ds_tizen_input_devicemgr::pressed_keys; -}; - -#endif diff --git a/src/input-devicemgr/meson.build b/src/input-devicemgr/meson.build deleted file mode 100644 index 4616f6f..0000000 --- a/src/input-devicemgr/meson.build +++ /dev/null @@ -1,32 +0,0 @@ -libds_tizen_input_devicemgr_files = [ - tizen_security_files, - 'input-devicemgr.c', -] - -libds_tizen_input_devicemgr_deps = [ - deps_libds_tizen, - deps_tizen_security, - dependency('tizen-extension-server', required: true), - dependency('xkbcommon', required: true), -] - -lib_libds_tizen_input_devicemgr = shared_library('ds-tizen-input-devicemgr', libds_tizen_input_devicemgr_files, - dependencies: libds_tizen_input_devicemgr_deps, - include_directories: [ common_inc, include_directories('.'), include_directories('..') ], - version: meson.project_version(), - install: true -) - -deps_libds_tizen_input_devicemgr = declare_dependency( - link_with: lib_libds_tizen_input_devicemgr, - dependencies: libds_tizen_input_devicemgr_deps, - include_directories: [ common_inc, include_directories('.') ], -) - -pkgconfig = import('pkgconfig') -pkgconfig.generate(lib_libds_tizen_input_devicemgr, - version: meson.project_version(), - filebase: 'libds-tizen-input-devicemgr', - name: 'libds-tizen-input-devicemgr', - description: 'tizen input devicemgr extension of libds-tizen for tizen platform', -) diff --git a/src/meson.build b/src/meson.build index b4b92f5..46d807d 100644 --- a/src/meson.build +++ b/src/meson.build @@ -28,8 +28,8 @@ deps_tizen_security = [ ] subdir('allocator') -subdir('tbm-server') +subdir('tbm_server') subdir('backend') subdir('keyrouter') -subdir('input-devicemgr') +subdir('input_devicemgr') subdir('dpms') diff --git a/src/tbm-server/meson.build b/src/tbm-server/meson.build deleted file mode 100644 index ced06a4..0000000 --- a/src/tbm-server/meson.build +++ /dev/null @@ -1,32 +0,0 @@ -libds_tizen_tbm_server_files = [ - 'pixel_format.c', - 'tbm-server.c', -] - -libds_tizen_tbm_server_deps = [ - deps_libds_tizen, - dependency('libdrm', required: true), - dependency('libtbm', required: true), - dependency('wayland-tbm-server', required: true), -] - -lib_libds_tizen_tbm_server = shared_library('ds-tizen-tbm-server', libds_tizen_tbm_server_files, - dependencies: libds_tizen_tbm_server_deps, - include_directories: [ common_inc, include_directories('.'), include_directories('..') ], - version: meson.project_version(), - install: true -) - -deps_libds_tizen_tbm_server = declare_dependency( - link_with: lib_libds_tizen_tbm_server, - dependencies: libds_tizen_tbm_server_deps, - include_directories: [ common_inc, include_directories('.') ], -) - -pkgconfig = import('pkgconfig') -pkgconfig.generate(lib_libds_tizen_tbm_server, - version: meson.project_version(), - filebase: 'libds-tizen-tbm-server', - name: 'libds-tizen-tbm-server', - description: 'wayland-tbm extension of libds-tizen for tizen platform', -) diff --git a/src/tbm-server/pixel_format.c b/src/tbm-server/pixel_format.c deleted file mode 100644 index 030f211..0000000 --- a/src/tbm-server/pixel_format.c +++ /dev/null @@ -1,61 +0,0 @@ -#include -#include -#include - -#include -#include "pixel_format.h" - -#ifdef ARRAY_LENGTH -#undef ARRAY_LENGTH -#endif - -#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0]) - -struct ds_tbm_format -{ - uint32_t drm_format; - uint32_t tbm_format; -}; - -static const struct ds_tbm_format formats[] = -{ - { - .drm_format = DRM_FORMAT_ARGB8888, - .tbm_format = TBM_FORMAT_ARGB8888, - }, - { - .drm_format = DRM_FORMAT_XRGB8888, - .tbm_format = TBM_FORMAT_XRGB8888, - }, - /* TODO more format */ -}; - -uint32_t -convert_drm_format_to_tbm(uint32_t fmt) -{ - size_t i; - - for (i = 0; i < ARRAY_LENGTH(formats); i++) { - if (formats[i].drm_format == fmt) - return formats[i].tbm_format; - } - - ds_err("DRM format 0x%"PRIX32" has no TBM equivalent", fmt); - - return 0; -} - -uint32_t -convert_tbm_format_to_drm(uint32_t fmt) -{ - size_t i; - - for (i = 0; i < ARRAY_LENGTH(formats); i++) { - if (formats[i].tbm_format == fmt) - return formats[i].drm_format; - } - - ds_err("TBM format 0x%"PRIX32" has no DRM equivalent", fmt); - - return 0; -} diff --git a/src/tbm-server/pixel_format.h b/src/tbm-server/pixel_format.h deleted file mode 100644 index a63d096..0000000 --- a/src/tbm-server/pixel_format.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef DS_TIZEN_PIXEL_FORMAT_H -#define DS_TIZEN_PIXEL_FORMAT_H - -#include - -uint32_t convert_drm_format_to_tbm(uint32_t fmt); - -uint32_t convert_tbm_format_to_drm(uint32_t fmt); - -#endif diff --git a/src/tbm-server/tbm-server.c b/src/tbm-server/tbm-server.c deleted file mode 100644 index 9dde248..0000000 --- a/src/tbm-server/tbm-server.c +++ /dev/null @@ -1,268 +0,0 @@ -#include -#include -#include - -#include - -#include -#include "pixel_format.h" -#include "tbm-server.h" - -static const struct ds_buffer_resource_interface tbm_buffer_resource_iface; -static const struct ds_buffer_interface tbm_client_buffer_iface; - -static void tbm_server_handle_display_destroy(struct wl_listener *listener, - void *data); - -WL_EXPORT struct ds_tbm_server * -ds_tbm_server_create(struct wl_display *display) -{ - struct ds_tbm_server *tbm; - tbm_bufmgr bufmgr; - - tbm = calloc(1, sizeof *tbm); - if (!tbm) - return NULL; - - wl_signal_init(&tbm->events.destroy); - - tbm->wl_tbm = wayland_tbm_server_init(display, NULL, -1, 0); - if (!tbm->wl_tbm) { - goto err_wl_tbm; - } - - bufmgr = wayland_tbm_server_get_bufmgr(tbm->wl_tbm); - if (!bufmgr) { - goto err_bind; - } - - if (!tbm_bufmgr_bind_native_display(bufmgr, (void *)display)) { - goto err_bind; - } - - tbm->display_destroy.notify = tbm_server_handle_display_destroy; - wl_display_add_destroy_listener(display, &tbm->display_destroy); - - ds_buffer_register_resource_interface(&tbm_buffer_resource_iface); - - return tbm; - -err_bind: - wayland_tbm_server_deinit(tbm->wl_tbm); -err_wl_tbm: - free(tbm); - - return NULL; -} - -WL_EXPORT void -ds_tbm_server_add_destroy_listener(struct ds_tbm_server *tbm, - struct wl_listener *listener) -{ - wl_signal_add(&tbm->events.destroy, listener); -} - -WL_EXPORT struct ds_tbm_client_buffer * -ds_tbm_client_buffer_from_buffer(struct ds_buffer *ds_buffer) -{ - if (ds_buffer->iface != &tbm_client_buffer_iface) - return NULL; - return (struct ds_tbm_client_buffer *)ds_buffer; -} - -WL_EXPORT tbm_surface_h -ds_tbm_client_buffer_get_tbm_surface(struct ds_tbm_client_buffer *buffer) -{ - if (buffer->base.iface != &tbm_client_buffer_iface) - return NULL; - return buffer->surface; -} - -static void -tbm_server_handle_display_destroy(struct wl_listener *listener, void *data) -{ - struct ds_tbm_server *tbm; - - tbm = wl_container_of(listener, tbm, display_destroy); - - wl_signal_emit(&tbm->events.destroy, tbm); - - wayland_tbm_server_deinit(tbm->wl_tbm); - free(tbm); -} - -static void -tbm_client_buffer_handle_release(struct wl_listener *listener, void *data) -{ - struct ds_tbm_client_buffer *buffer; - - buffer = wl_container_of(listener, buffer, buffer_release); - if (buffer->resource) - wl_buffer_send_release(buffer->resource); -} - -static void -tbm_client_buffer_handle_resource_destroy(struct wl_listener *listener, - void *data) -{ - struct ds_tbm_client_buffer *buffer; - - buffer = wl_container_of(listener, buffer, resource_destroy); - - buffer->resource = NULL; - buffer->surface = NULL; - wl_list_remove(&buffer->resource_destroy.link); - wl_list_init(&buffer->resource_destroy.link); - - ds_buffer_drop(&buffer->base); -} - -static struct ds_tbm_client_buffer * -tbm_client_buffer_from_buffer(struct ds_buffer *ds_buffer) -{ - assert(ds_buffer->iface == &tbm_client_buffer_iface); - return (struct ds_tbm_client_buffer *)ds_buffer; -} - -static void -tbm_client_buffer_iface_destroy(struct ds_buffer *ds_buffer) -{ - struct ds_tbm_client_buffer *buffer; - - buffer = tbm_client_buffer_from_buffer(ds_buffer); - - ds_inf("Destroy TBM client buffer(%p)", buffer); - - wl_list_remove(&buffer->resource_destroy.link); - wl_list_remove(&buffer->buffer_release.link); - free(buffer); -} - -static bool -tbm_client_buffer_iface_begin_data_ptr_access(struct ds_buffer *ds_buffer, - enum ds_buffer_data_ptr_access_flag flags, void **data, - uint32_t *format, size_t *stride) -{ - struct ds_tbm_client_buffer *buffer; - tbm_surface_info_s info; - tbm_bo_access_option op = TBM_OPTION_NONE; - int err; - - buffer = tbm_client_buffer_from_buffer(ds_buffer); - - if (flags & DS_BUFFER_DATA_PTR_ACCESS_READ) - op |= TBM_OPTION_READ; - - if (flags & DS_BUFFER_DATA_PTR_ACCESS_WRITE) - op |= TBM_OPTION_WRITE; - - err = tbm_surface_map(buffer->surface, op, &info); - if (err != TBM_SURFACE_ERROR_NONE) { - ds_err("Failed tbm_surface_map()"); - return false; - } - - *format = convert_tbm_format_to_drm(buffer->format); - *stride = info.planes[0].stride; - *data = info.planes[0].ptr; - - return true; -} - -static void -tbm_client_buffer_iface_end_ptr_access(struct ds_buffer *ds_buffer) -{ - struct ds_tbm_client_buffer *buffer; - - buffer = tbm_client_buffer_from_buffer(ds_buffer); - - tbm_surface_unmap(buffer->surface); -} - -static const struct ds_buffer_interface tbm_client_buffer_iface = { - .destroy = tbm_client_buffer_iface_destroy, - .begin_data_ptr_access = tbm_client_buffer_iface_begin_data_ptr_access, - .end_data_ptr_access = tbm_client_buffer_iface_end_ptr_access, -}; - -static struct ds_tbm_client_buffer * -tbm_client_buffer_create(struct wl_resource *resource) -{ - struct ds_tbm_client_buffer *buffer; - tbm_surface_h surface; - int32_t width, height; - - surface = wayland_tbm_server_get_surface(NULL, resource); - if (!surface) { - ds_err("Could not get tbm_surface from wl_resource@%d", - wl_resource_get_id(resource)); - return NULL; - } - - width = tbm_surface_get_width(surface); - height = tbm_surface_get_height(surface); - - buffer = calloc(1, sizeof *buffer); - if (!buffer) - return NULL; - - ds_buffer_init(&buffer->base, &tbm_client_buffer_iface, width, height); - - buffer->resource = resource; - buffer->surface = surface; - buffer->format = tbm_surface_get_format(surface); - - buffer->buffer_release.notify = tbm_client_buffer_handle_release; - ds_buffer_add_release_listener(&buffer->base, &buffer->buffer_release); - - buffer->resource_destroy.notify = - tbm_client_buffer_handle_resource_destroy; - wl_resource_add_destroy_listener(resource, &buffer->resource_destroy); - - ds_inf("TBM client buffer(%p) created", buffer); - - return buffer; -} - -static struct ds_tbm_client_buffer * -tbm_client_buffer_get_or_create(struct wl_resource *resource) -{ - struct ds_tbm_client_buffer *buffer; - struct wl_listener *resource_destroy_listener; - - resource_destroy_listener = wl_resource_get_destroy_listener(resource, - tbm_client_buffer_handle_resource_destroy);; - if (resource_destroy_listener) { - buffer = wl_container_of(resource_destroy_listener, - buffer, resource_destroy); - return buffer; - } - - return tbm_client_buffer_create(resource); -} - -static bool -tbm_buffer_resource_iface_is_instance(struct wl_resource *resource) -{ - return !!wayland_tbm_server_get_surface(NULL, resource); -} - -static struct ds_buffer * -tbm_buffer_resource_iface_from_resource(struct wl_resource *resource) -{ - struct ds_tbm_client_buffer *buffer; - - buffer = tbm_client_buffer_get_or_create(resource); - if (!buffer) { - ds_err("Could not get or create ds_tbm_client_buffer"); - return NULL; - } - - return &buffer->base; -} - -static const struct ds_buffer_resource_interface tbm_buffer_resource_iface = { - .name = "tbm", - .is_instance = tbm_buffer_resource_iface_is_instance, - .from_resource = tbm_buffer_resource_iface_from_resource, -}; diff --git a/src/tbm-server/tbm-server.h b/src/tbm-server/tbm-server.h deleted file mode 100644 index 58e391b..0000000 --- a/src/tbm-server/tbm-server.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef DS_TIZEN_TBM_SERVER_H -#define DS_TIZEN_TBM_SERVER_H - -#include -#include -#include -#include - -struct ds_tbm_server -{ - struct wayland_tbm_server *wl_tbm; - - struct wl_listener display_destroy; - - struct { - struct wl_signal destroy; - } events; -}; - -struct ds_tbm_client_buffer -{ - struct ds_buffer base; - - tbm_surface_h surface; - struct wl_resource *resource; - - struct wl_listener buffer_release; - struct wl_listener resource_destroy; - - uint32_t format; - size_t stride; -}; - -#endif diff --git a/tests/meson.build b/tests/meson.build index dae7875..324c760 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -1,12 +1,12 @@ tests = [ - { 'name': 'test-compositor' }, - { 'name': 'test-backend' }, + { 'name': 'test_compositor' }, + { 'name': 'test_backend' }, { - 'name': 'test-surface', + 'name': 'test_surface', 'deps': [ dependency('wayland-client') ], }, { - 'name': 'test-subsurface', + 'name': 'test_subsurface', 'deps': [ dependency('wayland-client') ], }, ] diff --git a/tests/test-backend.c b/tests/test-backend.c deleted file mode 100644 index 69417b6..0000000 --- a/tests/test-backend.c +++ /dev/null @@ -1,80 +0,0 @@ -#include -#include -#include - -#include -#include - -static struct ds_backend * -create_possible_wl_backend(struct wl_display *display) -{ - struct ds_backend *backend; - char wl_name[512]; - - for (int i = 0; i < 5; i++) { - snprintf(wl_name, sizeof wl_name, "wayland-%d", i); - backend = ds_wl_backend_create(display, wl_name); - if (backend) - break; - } - - return backend; -} - -static void -test_wl_backend_create(void) -{ - struct wl_display *display; - struct ds_backend *backend; - - display = wl_display_create(); - - backend = create_possible_wl_backend(display); - assert(backend); - - ds_backend_destroy(backend); -} - -struct test -{ - struct wl_listener backend_destroy; - bool cb_called; -}; - -static void -cb_backend_destroy(struct wl_listener *listener, void *data) -{ - struct test *test; - - test = wl_container_of(listener, test, backend_destroy); - test->cb_called = true; -} - -static void -test_wl_backend_destroy_signal(void) -{ - struct wl_display *display; - struct ds_backend *backend; - struct test test; - - display = wl_display_create(); - - backend = create_possible_wl_backend(display); - assert(backend); - - test.cb_called = false; - test.backend_destroy.notify = cb_backend_destroy; - ds_backend_add_destroy_listener(backend, &test.backend_destroy); - - wl_display_destroy(display); - assert(test.cb_called); -} - -int -main(void) -{ - test_wl_backend_create(); - test_wl_backend_destroy_signal(); - - return 0; -} diff --git a/tests/test-compositor.c b/tests/test-compositor.c deleted file mode 100644 index b5883a5..0000000 --- a/tests/test-compositor.c +++ /dev/null @@ -1,63 +0,0 @@ -#include -#include - -#include -#include -#include - -static void -test_compositor_create(void) -{ - struct wl_display *display; - struct ds_compositor *compositor; - - display = wl_display_create(); - compositor = ds_compositor_create(display); - assert(compositor); - - wl_display_destroy(display); -} - -struct test -{ - struct wl_listener compositor_destroy; - bool destroyed; -}; - -static void -cb_compositor_destroy(struct wl_listener *listener, void *data) -{ - struct test *test; - - test = wl_container_of(listener, test, compositor_destroy); - test->destroyed = true; -} - -static void -test_compositor_destroy_signal(void) -{ - struct wl_display *display; - struct ds_compositor *compositor; - struct test test; - - display = wl_display_create(); - compositor = ds_compositor_create(display); - assert(compositor); - - test.destroyed = false; - test.compositor_destroy.notify = cb_compositor_destroy; - ds_compositor_add_destroy_listener(compositor, - &test.compositor_destroy); - - wl_display_destroy(display); - assert(test.destroyed == true); -} - -int -main(void) -{ - test_compositor_create(); - test_compositor_destroy_signal(); - - return 0; -} diff --git a/tests/test-subsurface.c b/tests/test-subsurface.c deleted file mode 100644 index 98e830d..0000000 --- a/tests/test-subsurface.c +++ /dev/null @@ -1,211 +0,0 @@ -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -struct server_base -{ - struct wl_display *display; - struct ds_compositor *compositor; - const char *socket; -}; - -const char * -test_server_init(struct server_base *server) -{ - server->display = wl_display_create(); - assert(server->display); - server->compositor = ds_compositor_create(server->display); - assert(server->compositor); - server->socket = wl_display_add_socket_auto(server->display); - assert(server->socket); - - return server->socket; -} - -void -test_server_finish(struct server_base *server) -{ - wl_display_destroy(server->display); -} - -struct client -{ - struct wl_display *display; - struct wl_registry *registry; - struct wl_compositor *compositor; - struct wl_subcompositor *subcompositor; - struct wl_surface *surface; - struct wl_subsurface *subsurface; -}; - -static void -handle_global(void *data, struct wl_registry *registry, uint32_t id, - const char *interface, uint32_t version) -{ - struct client *client = data; - - if (strcmp(interface, "wl_compositor") == 0) { - client->compositor = - wl_registry_bind(registry, id, &wl_compositor_interface, version); - } - else if (strcmp(interface, "wl_subcompositor") == 0) { - client->subcompositor = - wl_registry_bind(registry, id, &wl_subcompositor_interface, version); - } -} - -static const struct wl_registry_listener registry_listener = { - .global = handle_global, -}; - -void -test_client_init(struct client *client, const char *name) -{ - client->display = wl_display_connect(name); - assert(client->display); - client->registry = wl_display_get_registry(client->display); - assert(client->registry); - - wl_registry_add_listener(client->registry, ®istry_listener, client); - - wl_display_roundtrip(client->display); - - assert(client->compositor); - assert(client->subcompositor); -} - -void -test_client_finish(struct client *client) -{ - wl_subcompositor_destroy(client->subcompositor); - wl_compositor_destroy(client->compositor); - wl_registry_destroy(client->registry); - wl_display_disconnect(client->display); -} - -struct test_server -{ - struct server_base base; - bool cb_called; - - struct wl_listener new_surface; - struct wl_listener new_subsurface1; - struct wl_listener new_subsurface2; -}; - -static void -cb_new_subsurface1(struct wl_listener *listener, void *data) -{ - struct ds_subsurface *subsurface = data; - struct test_server *server; - - assert(subsurface); - - server = wl_container_of(listener, server, new_subsurface1); - server->cb_called = true; - wl_display_terminate(server->base.display); -} - -static void -cb_new_subsurface2(struct wl_listener *listener, void *data) -{ - struct ds_subsurface *subsurface = data; - struct test_server *server; - - assert(subsurface); - - server = wl_container_of(listener, server, new_subsurface2); - server->cb_called = true; - wl_display_terminate(server->base.display); -} - -static void -cb_new_surface(struct wl_listener *listener, void *data) -{ - struct ds_surface *surface = data; - struct test_server *server; - - server = wl_container_of(listener, server, new_surface); - if (!server->new_subsurface1.notify) { - server->new_subsurface1.notify = cb_new_subsurface1; - ds_surface_add_new_subsurface_listener(surface, - &server->new_subsurface1); - } - else { - server->new_subsurface2.notify = cb_new_subsurface2; - ds_surface_add_new_subsurface_listener(surface, - &server->new_subsurface2); - } -} - -static void -run_client(const char *name) -{ - struct client client; - - test_client_init(&client, name); - - struct wl_surface *surface = - wl_compositor_create_surface(client.compositor); - - struct wl_surface *child_surface = - wl_compositor_create_surface(client.compositor); - - struct wl_subsurface *subsurface = - wl_subcompositor_get_subsurface(client.subcompositor, - child_surface, surface); - - wl_display_roundtrip(client.display); - - wl_subsurface_destroy(subsurface); - wl_surface_destroy(child_surface); - wl_surface_destroy(surface); - - test_client_finish(&client); -} - -static void -test_subsurface_create(void) -{ - struct test_server server = { - .new_subsurface1 = { .notify = NULL }, - .cb_called = false - }; - pid_t pid; - - const char *socket_name = test_server_init(&server.base); - - pid = fork(); - assert(pid != -1); - - if (pid == 0) { - run_client(socket_name); - exit(0); - } - - server.new_surface.notify = cb_new_surface; - ds_compositor_add_new_surface_listener(server.base.compositor, - &server.new_surface); - - wl_display_run(server.base.display); - - assert(server.cb_called); - - test_server_finish(&server.base); -} - -int -main(void) -{ - test_subsurface_create(); - return 0; -} diff --git a/tests/test-surface.c b/tests/test-surface.c deleted file mode 100644 index eab2b77..0000000 --- a/tests/test-surface.c +++ /dev/null @@ -1,162 +0,0 @@ -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -struct server_base -{ - struct wl_display *display; - struct ds_compositor *compositor; - const char *socket; -}; - -void -test_server_init(struct server_base *server) -{ - server->display = wl_display_create(); - assert(server->display); - server->compositor = ds_compositor_create(server->display); - assert(server->compositor); - server->socket = wl_display_add_socket_auto(server->display); - assert(server->socket); -} - -void -test_server_finish(struct server_base *server) -{ - wl_display_destroy(server->display); -} - -struct client -{ - struct wl_display *display; - struct wl_registry *registry; - struct wl_compositor *compositor; - struct wl_surface *surface; -}; - -static void -handle_global(void *data, struct wl_registry *registry, uint32_t id, - const char *interface, uint32_t version) -{ - struct client *client = data; - - if (strcmp(interface, "wl_compositor") == 0) { - client->compositor = - wl_registry_bind(registry, id, &wl_compositor_interface, version); - } -} - -static const struct wl_registry_listener registry_listener = { - .global = handle_global, -}; - -void -test_client_init(struct client *client, const char *name) -{ - client->display = wl_display_connect(name); - assert(client->display); - client->registry = wl_display_get_registry(client->display); - assert(client->registry); - - wl_registry_add_listener(client->registry, ®istry_listener, client); - - wl_display_roundtrip(client->display); - - assert(client->compositor); -} - -void -test_client_finish(struct client *client) -{ - wl_compositor_destroy(client->compositor); - wl_registry_destroy(client->registry); - wl_display_disconnect(client->display); -} - -struct test_server { - struct server_base base; - bool cb_called; - - struct wl_listener new_surface; - struct wl_listener surface_destroy; -}; - -static void -cb_surface_destroy(struct wl_listener *listener, void *data) -{ - struct test_server *server; - - server = wl_container_of(listener, server, surface_destroy); - server->cb_called = true; - wl_display_terminate(server->base.display); -} - -static void -cb_new_surface(struct wl_listener *listener, void *data) -{ - struct ds_surface *surface = data; - struct test_server *server; - - server = wl_container_of(listener, server, new_surface); - server->surface_destroy.notify = cb_surface_destroy; - ds_surface_add_destroy_listener(surface, &server->surface_destroy); -} - -static void -run_client(const char *name) -{ - struct client client; - - test_client_init(&client, name); - - struct wl_surface *surface = - wl_compositor_create_surface(client.compositor); - - wl_display_roundtrip(client.display); - - wl_surface_destroy(surface); - - test_client_finish(&client); -} - -static void -test_surface_create_and_destroy(void) -{ - struct test_server server = { .cb_called = false }; - pid_t pid; - - test_server_init(&server.base); - - pid = fork(); - assert(pid != -1); - - if (pid == 0) { - run_client(server.base.socket); - exit(0); - } - - server.new_surface.notify = cb_new_surface; - ds_compositor_add_new_surface_listener(server.base.compositor, - &server.new_surface); - - wl_display_run(server.base.display); - - assert(server.cb_called); - - test_server_finish(&server.base); -} - -int -main(void) -{ - test_surface_create_and_destroy(); - return 0; -} -- 2.7.4