From 19fc9e8bfa4b7a7dc2f7a5f5eccd8fb4e7e58221 Mon Sep 17 00:00:00 2001 From: Seunghun Lee Date: Thu, 21 Apr 2022 14:05:11 +0900 Subject: [PATCH] examples/tinyds: Handle ds_pointer This adds listeners of ds_pointer and prints logs. Change-Id: I10372862b9111e2cf01f88753e16a5036ffe8406 --- src/examples/tinyds.c | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) diff --git a/src/examples/tinyds.c b/src/examples/tinyds.c index 77ede91..735fc30 100644 --- a/src/examples/tinyds.c +++ b/src/examples/tinyds.c @@ -20,6 +20,7 @@ #include #include #include +#include #define TINYDS_UNUSED __attribute__((unused)) @@ -28,6 +29,18 @@ struct tinyds_server; +struct tinyds_pointer +{ + struct ds_input_device *dev; + struct tinyds_server *server; + + struct wl_listener destroy; + struct wl_listener motion; + struct wl_listener motion_absolute; + struct wl_listener button; + struct wl_listener frame; +}; + struct tinyds_keyboard { struct ds_input_device *dev; @@ -303,6 +316,103 @@ server_add_touch(struct tinyds_server *server, struct ds_input_device *dev) } static void +pointer_handle_device_destroy(struct wl_listener *listener, void *data) +{ + struct tinyds_pointer *pointer; + + pointer = wl_container_of(listener, pointer, destroy); + + ds_inf("Pointer(%p) destroyed", pointer); + + wl_list_remove(&pointer->destroy.link); + wl_list_remove(&pointer->motion.link); + wl_list_remove(&pointer->motion_absolute.link); + wl_list_remove(&pointer->button.link); + wl_list_remove(&pointer->frame.link); + + free(pointer); +} + +static void +pointer_handle_motion(struct wl_listener *listener, void *data) +{ + struct tinyds_pointer *pointer; + + pointer = wl_container_of(listener, pointer, motion); + + ds_inf("Pointer(%p) motion", pointer); +} + +static void +pointer_handle_motion_absolute(struct wl_listener *listener, void *data) +{ + struct tinyds_pointer *pointer; + struct ds_event_pointer_motion_absolute *event = data; + + pointer = wl_container_of(listener, pointer, motion_absolute); + + ds_inf("Pointer(%p) motion absolute: (x %f y %f) time(%d)", + pointer, event->x, event->y, event->time_msec); +} + +static void +pointer_handle_button(struct wl_listener *listener, void *data) +{ + struct tinyds_pointer *pointer; + struct ds_event_pointer_button *event = data; + + pointer = wl_container_of(listener, pointer, button); + + ds_inf("Pointer(%p) button(%d): state(%s) time(%d)", + pointer, event->button, + (event->state == DS_BUTTON_PRESSED) ? "Pressed" : "Released", + event->time_msec); +} + +static void +pointer_handle_frame(struct wl_listener *listener, void *data) +{ + struct tinyds_pointer *pointer; + + pointer = wl_container_of(listener, pointer, motion); + + ds_inf("Pointer(%p) frame", pointer); +} + +static void +server_add_pointer(struct tinyds_server *server, struct ds_input_device *dev) +{ + struct tinyds_pointer *pointer; + + pointer = calloc(1, sizeof *pointer); + assert(pointer); + + pointer->dev = dev; + pointer->server = server; + + pointer->destroy.notify = pointer_handle_device_destroy; + ds_input_device_add_destroy_listener(dev, &pointer->destroy); + + pointer->motion.notify = pointer_handle_motion; + ds_pointer_add_motion_listener(ds_input_device_get_pointer(dev), + &pointer->motion); + + pointer->motion_absolute.notify = pointer_handle_motion_absolute; + ds_pointer_add_motion_absolute_listener(ds_input_device_get_pointer(dev), + &pointer->motion_absolute); + + pointer->button.notify = pointer_handle_button; + ds_pointer_add_button_listener(ds_input_device_get_pointer(dev), + &pointer->button); + + pointer->frame.notify = pointer_handle_frame; + ds_pointer_add_frame_listener(ds_input_device_get_pointer(dev), + &pointer->frame); + + ds_inf("Pointer(%p) added", pointer); +} + +static void server_handle_new_input(struct wl_listener *listener, void *data) { struct tinyds_server *server; @@ -319,6 +429,9 @@ server_handle_new_input(struct wl_listener *listener, void *data) case DS_INPUT_DEVICE_TOUCH: server_add_touch(server, dev); break; + case DS_INPUT_DEVICE_POINTER: + server_add_pointer(server, dev); + break; default: ds_err("Unknown type(%d) of ds_input_device", dev_type); break; -- 2.7.4