From 5809a0a894193811a8668a4499059bfcc4ab4a2b Mon Sep 17 00:00:00 2001 From: dyamy-lee Date: Fri, 12 Nov 2021 14:16:23 +0900 Subject: [PATCH] input : add get capabilities by env and event listeners about pointer, touch for integration doctor function Change-Id: Iff8de4ced6c08f1cd61f86f9687eb49a993c08b1 (cherry picked from commit 3cc9b489271abc1093835cb925c4b3299ee84e6b) --- src/input/input.c | 175 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 167 insertions(+), 8 deletions(-) diff --git a/src/input/input.c b/src/input/input.c index 6d32d3b..ac70aa3 100644 --- a/src/input/input.c +++ b/src/input/input.c @@ -34,6 +34,8 @@ typedef struct pepper_seat_t *seat; pepper_evdev_t *evdev; pepper_keyboard_t *keyboard; + pepper_pointer_t *pointer; + pepper_touch_t *touch; pepper_input_device_t *default_device; pepper_inotify_t *inotify; @@ -46,6 +48,10 @@ typedef struct pepper_event_listener_t *listener_seat_keyboard_key; pepper_event_listener_t *listener_seat_keyboard_add; + pepper_event_listener_t *listener_seat_pointer_event; + pepper_event_listener_t *listener_seat_pointer_add; + pepper_event_listener_t *listener_seat_touch_event; + pepper_event_listener_t *listener_seat_touch_add; pepper_event_listener_t *listener_seat_add; pepper_event_listener_t *listener_input_device_add; @@ -57,6 +63,82 @@ const static int KEY_INPUT = 0xdeadbeaf; static void headless_input_init_event_listeners(headless_input_t *hi); static void headless_input_deinit_event_listeners(headless_input_t *hi); +/* pointer event handler */ +static void +_handle_pointer_event(pepper_event_listener_t *listener, pepper_object_t *object, uint32_t id, void *info, void *data) +{ + pepper_input_event_t *event; + + PEPPER_CHECK((id >= PEPPER_EVENT_POINTER_MOTION && id <= PEPPER_EVENT_POINTER_AXIS), return, "unknown event %d !\n", id); + PEPPER_CHECK(info, return, "Invalid event !\n"); + PEPPER_CHECK(data, return, "Invalid data !\n"); + + event = (pepper_input_event_t *)info; + + /* TODO: */ + (void) event; + + switch (id) + { + case PEPPER_EVENT_POINTER_MOTION: + /* TODO: */ + PEPPER_TRACE("[%s] PEPPER_EVENT_POINTER_MOTION\n", __FUNCTION__); + break; + case PEPPER_EVENT_POINTER_MOTION_ABSOLUTE: + /* TODO: */ + PEPPER_TRACE("[%s] PEPPER_EVENT_POINTER_MOTION_ABSOLUTE\n", __FUNCTION__); + break; + case PEPPER_EVENT_POINTER_BUTTON: + /* TODO: */ + PEPPER_TRACE("[%s] PEPPER_EVENT_POINTER_BUTTON\n", __FUNCTION__); + break; + case PEPPER_EVENT_POINTER_AXIS: + /* TODO: */ + PEPPER_TRACE("[%s] PEPPER_EVENT_POINTER_AXIS\n", __FUNCTION__); + break; + } +} + +/* touch event handler */ +static void +_handle_touch_event(pepper_event_listener_t *listener, pepper_object_t *object, uint32_t id, void *info, void *data) +{ + pepper_input_event_t *event; + + PEPPER_CHECK((id >= PEPPER_EVENT_TOUCH_DOWN && id <= PEPPER_EVENT_TOUCH_CANCEL), return, "unknown event %d !\n", id); + PEPPER_CHECK(info, return, "Invalid event !\n"); + PEPPER_CHECK(data, return, "Invalid data !\n"); + + event = (pepper_input_event_t *)info; + + /* TODO: */ + (void) event; + + switch (id) + { + case PEPPER_EVENT_TOUCH_DOWN: + /* TODO: */ + PEPPER_TRACE("[%s] PEPPER_EVENT_TOUCH_DOWN\n", __FUNCTION__); + break; + case PEPPER_EVENT_TOUCH_UP: + /* TODO: */ + PEPPER_TRACE("[%s] PEPPER_EVENT_TOUCH_UP\n", __FUNCTION__); + break; + case PEPPER_EVENT_TOUCH_MOTION: + /* TODO: */ + PEPPER_TRACE("[%s] PEPPER_EVENT_TOUCH_MOTION\n", __FUNCTION__); + break; + case PEPPER_EVENT_TOUCH_FRAME: + /* TODO: */ + PEPPER_TRACE("[%s] PEPPER_EVENT_TOUCH_FRAME\n", __FUNCTION__); + break; + case PEPPER_EVENT_TOUCH_CANCEL: + /* TODO: */ + PEPPER_TRACE("[%s] PEPPER_EVENT_TOUCH_CANCEL\n", __FUNCTION__); + break; + } +} + /* seat keyboard add event handler */ static void _cb_handle_seat_keyboard_add(pepper_event_listener_t *listener, pepper_object_t *object, uint32_t id, void *info, void *data) @@ -84,6 +166,57 @@ end: headless_input_deinit_event_listeners(hi); } +static void +_cb_handle_seat_pointer_add(pepper_event_listener_t *listener, pepper_object_t *object, uint32_t id, void *info, void *data) +{ + pepper_event_listener_t *h = NULL; + pepper_pointer_t *pointer = (pepper_pointer_t *)info; + headless_input_t *hi = (headless_input_t *)data; + + PEPPER_TRACE("[%s] pointer added\n", __FUNCTION__); + + h = pepper_object_add_event_listener((pepper_object_t *)pointer, + PEPPER_EVENT_POINTER_MOTION + | PEPPER_EVENT_POINTER_MOTION_ABSOLUTE + | PEPPER_EVENT_POINTER_BUTTON + | PEPPER_EVENT_POINTER_AXIS, + 0, _handle_pointer_event, hi->compositor); + PEPPER_CHECK(h, goto end, "Failed to add pointer listener.\n"); + hi->listener_seat_pointer_event = h; + hi->pointer = pointer; + + return; + +end: + headless_input_deinit_event_listeners(hi); +} + +static void +_cb_handle_seat_touch_add(pepper_event_listener_t *listener, pepper_object_t *object, uint32_t id, void *info, void *data) +{ + pepper_event_listener_t *h = NULL; + pepper_touch_t *touch = (pepper_touch_t *)info; + headless_input_t *hi = (headless_input_t *)data; + + PEPPER_TRACE("[%s] touch added\n", __FUNCTION__); + + h = pepper_object_add_event_listener((pepper_object_t *)touch, + PEPPER_EVENT_TOUCH_DOWN + | PEPPER_EVENT_TOUCH_UP + | PEPPER_EVENT_TOUCH_MOTION + | PEPPER_EVENT_TOUCH_FRAME + | PEPPER_EVENT_TOUCH_CANCEL, + 0, _handle_touch_event, hi->compositor); + PEPPER_CHECK(h, goto end, "Failed to add touch listener.\n"); + hi->listener_seat_touch_event = h; + hi->touch = touch; + + return; + +end: + headless_input_deinit_event_listeners(hi); +} + /* compositor input device add event handler */ static void _cb_handle_input_device_add(pepper_event_listener_t *listener, pepper_object_t *object, uint32_t id, void *info, void *data) @@ -101,16 +234,29 @@ _cb_handle_input_device_add(pepper_event_listener_t *listener, pepper_object_t * static void _cb_handle_seat_add(pepper_event_listener_t *listener, pepper_object_t *object, uint32_t id, void *info, void *data) { - pepper_event_listener_t *h = NULL; + pepper_event_listener_t *key = NULL; + pepper_event_listener_t *pointer = NULL; + pepper_event_listener_t *touch = NULL; pepper_seat_t *seat = (pepper_seat_t *)info; headless_input_t *hi = (headless_input_t *)data; PEPPER_TRACE("[%s] seat added. name:%s\n", __FUNCTION__, pepper_seat_get_name(seat)); - h = pepper_object_add_event_listener((pepper_object_t *)seat, PEPPER_EVENT_SEAT_KEYBOARD_ADD, + key = pepper_object_add_event_listener((pepper_object_t *)seat, PEPPER_EVENT_SEAT_KEYBOARD_ADD, 0, _cb_handle_seat_keyboard_add, hi); - PEPPER_CHECK(h, goto end, "Failed to add seat keyboard add listener.\n"); - hi->listener_seat_keyboard_add = h; + + PEPPER_CHECK(key, goto end, "Failed to add seat keyboard add listener.\n"); + hi->listener_seat_keyboard_add = key; + + pointer = pepper_object_add_event_listener((pepper_object_t *)seat, PEPPER_EVENT_SEAT_POINTER_ADD, + 0, _cb_handle_seat_pointer_add, hi); + PEPPER_CHECK(pointer, goto end, "Failed to add seat pointer add listener.\n"); + hi->listener_seat_pointer_add = pointer; + + touch = pepper_object_add_event_listener((pepper_object_t *)seat, PEPPER_EVENT_SEAT_TOUCH_ADD, + 0, _cb_handle_seat_touch_add, hi); + PEPPER_CHECK(touch, goto end, "Failed to add seat touch add listener.\n"); + hi->listener_seat_touch_add = touch; return; @@ -226,8 +372,12 @@ end: static void headless_input_deinit_event_listeners(headless_input_t *hi) { - pepper_event_listener_remove(hi->listener_seat_keyboard_key); - pepper_event_listener_remove(hi->listener_seat_keyboard_add); + if(hi->listener_seat_keyboard_key) pepper_event_listener_remove(hi->listener_seat_keyboard_key); + if(hi->listener_seat_keyboard_add) pepper_event_listener_remove(hi->listener_seat_keyboard_add); + if(hi->listener_seat_pointer_add) pepper_event_listener_remove(hi->listener_seat_pointer_add); + if(hi->listener_seat_pointer_event) pepper_event_listener_remove(hi->listener_seat_pointer_event); + if(hi->listener_seat_touch_add) pepper_event_listener_remove(hi->listener_seat_touch_add); + if(hi->listener_seat_touch_event) pepper_event_listener_remove(hi->listener_seat_touch_event); pepper_event_listener_remove(hi->listener_seat_add); pepper_event_listener_remove(hi->listener_input_device_add); @@ -287,10 +437,19 @@ headless_input_init_input(headless_input_t *hi) hi->evdev = evdev; - /* probe evdev keyboard device(s) */ - caps |= WL_SEAT_CAPABILITY_KEYBOARD; + /* get capabilities for a default pepper input device*/ + if (getenv("WAYLAND_INPUT_KEYBOARD")) + caps |= WL_SEAT_CAPABILITY_KEYBOARD; + if (getenv("WAYLAND_INPUT_POINTER")) + caps |= WL_SEAT_CAPABILITY_POINTER; + if (getenv("WAYLAND_INPUT_TOUCH")) + caps |= WL_SEAT_CAPABILITY_TOUCH; + + if(!caps) + caps |= WL_SEAT_CAPABILITY_KEYBOARD; probed = pepper_evdev_device_probe(evdev, caps); + if (!probed) { PEPPER_TRACE("No evdev device has been probed. A default key device will be created.\n"); -- 2.7.4