From 77bac448ccac9827abfa2ab10e798295f07f3980 Mon Sep 17 00:00:00 2001 From: Markus Ongyerth Date: Mon, 23 Apr 2018 08:55:49 +0200 Subject: storage commit #2 --- backend/libinput/tablet_pad.c | 71 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) (limited to 'backend/libinput/tablet_pad.c') diff --git a/backend/libinput/tablet_pad.c b/backend/libinput/tablet_pad.c index 626c2219..ed5374c6 100644 --- a/backend/libinput/tablet_pad.c +++ b/backend/libinput/tablet_pad.c @@ -8,7 +8,60 @@ #include "backend/libinput.h" #include "util/signal.h" -struct wlr_tablet_pad *create_libinput_tablet_pad( +static void add_pad_group_from_libinput(struct wlr_tablet_pad *pad, + struct libinput_device *device, unsigned int index) { + struct libinput_tablet_pad_mode_group *li_group = + libinput_device_tablet_pad_get_mode_group(device, index); + struct wlr_tablet_pad_group_v2 *group = + calloc(1, sizeof(struct wlr_tablet_pad_group_v2)); + if (!group) { + return; + } + + for (size_t i = 0; i < pad->ring_count; ++i) { + if (libinput_tablet_pad_mode_group_has_ring(li_group, i)) { + ++group->ring_count; + } + } + group->rings = calloc(sizeof(int), group->ring_count); + size_t ring = 0; + for (size_t i = 0; i < pad->ring_count; ++i) { + if (libinput_tablet_pad_mode_group_has_ring(li_group, i)) { + group->rings[ring++] = i; + } + } + + for (size_t i = 0; i < pad->strip_count; ++i) { + if (libinput_tablet_pad_mode_group_has_strip(li_group, i)) { + ++group->strip_count; + } + } + group->strips = calloc(sizeof(int), group->strip_count); + size_t strip = 0; + for (size_t i = 0; i < pad->strip_count; ++i) { + if (libinput_tablet_pad_mode_group_has_strip(li_group, i)) { + group->strips[strip++] = i; + } + } + + for (size_t i = 0; i < pad->button_count; ++i) { + if (libinput_tablet_pad_mode_group_has_button(li_group, i)) { + ++group->button_count; + } + } + group->buttons = calloc(sizeof(int), group->button_count); + size_t button = 0; + for (size_t i = 0; i < pad->button_count; ++i) { + if (libinput_tablet_pad_mode_group_has_button(li_group, i)) { + group->buttons[button++] = i; + } + } + + group->mode_count = libinput_tablet_pad_mode_group_get_num_modes(li_group); + wl_list_insert(&pad->groups, &group->link); +} + +struct wlr_tablet_pad *libinput_tablet_pad_create( struct libinput_device *libinput_dev) { assert(libinput_dev); struct wlr_tablet_pad *wlr_tablet_pad = calloc(1, sizeof(struct wlr_tablet_pad)); @@ -16,6 +69,22 @@ struct wlr_tablet_pad *create_libinput_tablet_pad( wlr_log(WLR_ERROR, "Unable to allocate wlr_tablet_pad"); return NULL; } + + wlr_tablet_pad->button_count = + libinput_device_tablet_pad_get_num_buttons(libinput_dev); + wlr_tablet_pad->ring_count = + libinput_device_tablet_pad_get_num_rings(libinput_dev); + wlr_tablet_pad->strip_count = + libinput_device_tablet_pad_get_num_strips(libinput_dev); + + //struct udev_device *udev = libinput_device_get_udev_device(libinput_dev); + //add_tablet_path(&pad->paths, udev_device_get_syspath(udev)); + + int groups = libinput_device_tablet_pad_get_num_mode_groups(libinput_dev); + for (int i = 0; i < groups; ++i) { + add_pad_group_from_libinput(wlr_tablet_pad, libinput_dev, i); + } + wlr_tablet_pad_init(wlr_tablet_pad, NULL); return wlr_tablet_pad; } -- cgit v1.2.3 From e235f7d33621b5879a5f9a8a1d89d4a8515857c3 Mon Sep 17 00:00:00 2001 From: Markus Ongyerth Date: Tue, 24 Apr 2018 08:10:45 +0200 Subject: Basic tablet_v2 object lifetime --- backend/libinput/tablet_pad.c | 28 +- backend/libinput/tablet_tool.c | 12 +- include/rootston/cursor.h | 1 + include/rootston/desktop.h | 1 + include/wlr/types/wlr_tablet_pad.h | 2 +- include/wlr/types/wlr_tablet_tool.h | 2 +- include/wlr/types/wlr_tablet_v2.h | 62 ++++ rootston/desktop.c | 4 + rootston/seat.c | 26 ++ types/wlr_tablet_v2.c | 673 ++++++++++++++++++++++++++++++++++-- 10 files changed, 763 insertions(+), 48 deletions(-) create mode 100644 include/wlr/types/wlr_tablet_v2.h (limited to 'backend/libinput/tablet_pad.c') diff --git a/backend/libinput/tablet_pad.c b/backend/libinput/tablet_pad.c index ed5374c6..2558d09c 100644 --- a/backend/libinput/tablet_pad.c +++ b/backend/libinput/tablet_pad.c @@ -1,4 +1,8 @@ +#ifndef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 200809L +#endif #include +#include #include #include #include @@ -8,12 +12,26 @@ #include "backend/libinput.h" #include "util/signal.h" +//TODO: Move out +static void add_tablet_path(struct wl_list *list, const char *path) { + struct wlr_tablet_path *tablet_path = calloc(1, sizeof(struct wlr_tablet_path)); + + if (!tablet_path) { + return; + } + + tablet_path->path = strdup(path); + assert(tablet_path->path); + wl_list_insert(list, &tablet_path->link); +} + +// FIXME: Decide on how to alloc/count here static void add_pad_group_from_libinput(struct wlr_tablet_pad *pad, struct libinput_device *device, unsigned int index) { struct libinput_tablet_pad_mode_group *li_group = libinput_device_tablet_pad_get_mode_group(device, index); - struct wlr_tablet_pad_group_v2 *group = - calloc(1, sizeof(struct wlr_tablet_pad_group_v2)); + struct wlr_tablet_pad_group *group = + calloc(1, sizeof(struct wlr_tablet_pad_group)); if (!group) { return; } @@ -77,9 +95,11 @@ struct wlr_tablet_pad *libinput_tablet_pad_create( wlr_tablet_pad->strip_count = libinput_device_tablet_pad_get_num_strips(libinput_dev); - //struct udev_device *udev = libinput_device_get_udev_device(libinput_dev); - //add_tablet_path(&pad->paths, udev_device_get_syspath(udev)); + wl_list_init(&wlr_tablet_pad->paths); + struct udev_device *udev = libinput_device_get_udev_device(libinput_dev); + add_tablet_path(&wlr_tablet_pad->paths, udev_device_get_syspath(udev)); + wl_list_init(&wlr_tablet_pad->groups); int groups = libinput_device_tablet_pad_get_num_mode_groups(libinput_dev); for (int i = 0; i < groups; ++i) { add_pad_group_from_libinput(wlr_tablet_pad, libinput_dev, i); diff --git a/backend/libinput/tablet_tool.c b/backend/libinput/tablet_tool.c index 6c48dcf0..f69e41f8 100644 --- a/backend/libinput/tablet_tool.c +++ b/backend/libinput/tablet_tool.c @@ -64,30 +64,32 @@ void wlr_libinput_tablet_tool_destroy(struct wlr_input_device *wlr_dev) { struct tablet_tool_list_elem *pos; struct tablet_tool_list_elem *tmp; wl_list_for_each_safe(pos, tmp, &tablet->tools, link) { - wl_list_remove(&pos->link); struct wlr_libinput_tablet_tool *tool = pos->tool; + wl_list_remove(&pos->link); + free(pos); if (--tool->pad_refs == 0) { destroy_tool_tool(tool); } - - free(pos); } } struct wlr_tablet_tool *libinput_tablet_tool_create( struct libinput_device *libinput_dev) { assert(libinput_dev); - struct wlr_tablet_tool *wlr_tablet_tool = calloc(1, sizeof(struct wlr_tablet_tool)); + struct wlr_libinput_tablet *libinput_tablet_tool = + calloc(1, sizeof(struct wlr_libinput_tablet)); + struct wlr_tablet_tool *wlr_tablet_tool = &libinput_tablet_tool->wlr_tool; if (!wlr_tablet_tool) { wlr_log(WLR_ERROR, "Unable to allocate wlr_tablet_tool"); return NULL; } + wl_list_init(&wlr_tablet_tool->paths); struct udev_device *udev = libinput_device_get_udev_device(libinput_dev); add_tablet_path(&wlr_tablet_tool->paths, udev_device_get_syspath(udev)); wlr_tablet_tool->name = strdup(libinput_device_get_name(libinput_dev)); - + wl_list_init(&libinput_tablet_tool->tools); wlr_tablet_tool_init(wlr_tablet_tool, NULL); return wlr_tablet_tool; diff --git a/include/rootston/cursor.h b/include/rootston/cursor.h index a1a466c2..0478c3ca 100644 --- a/include/rootston/cursor.h +++ b/include/rootston/cursor.h @@ -40,6 +40,7 @@ struct roots_cursor { struct wl_listener tool_axis; struct wl_listener tool_tip; + struct wl_listener tool_proximity; struct wl_listener request_set_cursor; }; diff --git a/include/rootston/desktop.h b/include/rootston/desktop.h index 88c5ca90..d9add26a 100644 --- a/include/rootston/desktop.h +++ b/include/rootston/desktop.h @@ -56,6 +56,7 @@ struct roots_desktop { struct wlr_layer_shell *layer_shell; struct wlr_virtual_keyboard_manager_v1 *virtual_keyboard; struct wlr_screencopy_manager_v1 *screencopy; + struct wlr_tablet_manager_v2 *tablet_v2; struct wl_listener new_output; struct wl_listener layout_change; diff --git a/include/wlr/types/wlr_tablet_pad.h b/include/wlr/types/wlr_tablet_pad.h index b633f439..b71f5b9a 100644 --- a/include/wlr/types/wlr_tablet_pad.h +++ b/include/wlr/types/wlr_tablet_pad.h @@ -32,7 +32,7 @@ struct wlr_tablet_pad { void *data; }; -struct wlr_tablet_pad_group_v2 { +struct wlr_tablet_pad_group { struct wl_list link; size_t button_count; diff --git a/include/wlr/types/wlr_tablet_tool.h b/include/wlr/types/wlr_tablet_tool.h index 884b486a..114ce98a 100644 --- a/include/wlr/types/wlr_tablet_tool.h +++ b/include/wlr/types/wlr_tablet_tool.h @@ -17,7 +17,7 @@ enum wlr_tablet_tool_type { Wacom Inking Pen */ WLR_TABLET_TOOL_TYPE_AIRBRUSH, /**< An airbrush-like tool */ WLR_TABLET_TOOL_TYPE_MOUSE, /**< A mouse bound to the tablet */ - WLR_TABLET_TOOL_TYPE_LENS, /**< A mouse tool with a lens */ + WLR_TABLET_TOOL_TYPE_LENS, /**< A mouse tool with a lens */ }; struct wlr_tablet_tool_tool { diff --git a/include/wlr/types/wlr_tablet_v2.h b/include/wlr/types/wlr_tablet_v2.h new file mode 100644 index 00000000..358f0719 --- /dev/null +++ b/include/wlr/types/wlr_tablet_v2.h @@ -0,0 +1,62 @@ +#ifndef WLR_TYPES_WLR_TABLET_V2_H +#define WLR_TYPES_WLR_TABLET_V2_H + +#include +#include +#include + +struct wlr_tablet_manager_v2 { + struct wl_global *wl_global; + struct wl_list clients; // wlr_tablet_manager_client_v2::link + struct wl_list seats; // wlr_tablet_seat_v2::link + + struct wl_listener display_destroy; + + void *data; +}; + +struct wlr_tablet_v2_tablet { + struct wl_list link; // wlr_tablet_seat_v2::tablets + struct wlr_tablet_tool *wlr_tool; + struct wlr_input_device *wlr_device; + struct wl_list clients; // wlr_tablet_client_v2::tablet_link + + struct wl_listener tool_destroy; +}; + +struct wlr_tablet_v2_tablet_tool { + struct wl_list link; // wlr_tablet_seat_v2::tablets + struct wlr_tablet_tool_tool *wlr_tool; + struct wl_list clients; // wlr_tablet_tool_client_v2::tablet_link + + struct wl_listener tool_destroy; +}; + +struct wlr_tablet_v2_tablet_pad { + struct wl_list link; // wlr_tablet_seat_v2::pads + struct wlr_tablet_pad *wlr_pad; + struct wlr_input_device *wlr_device; + struct wl_list clients; // wlr_tablet_pad_client_v2::tablet_link + + struct wl_listener pad_destroy; +}; + +struct wlr_tablet_v2_tablet *wlr_make_tablet( + struct wlr_tablet_manager_v2 *manager, + struct wlr_seat *wlr_seat, + struct wlr_input_device *wlr_device); + +struct wlr_tablet_v2_tablet_pad *wlr_make_tablet_pad( + struct wlr_tablet_manager_v2 *manager, + struct wlr_seat *wlr_seat, + struct wlr_input_device *wlr_device); + +struct wlr_tablet_v2_tablet_tool *wlr_make_tablet_tool( + struct wlr_tablet_manager_v2 *manager, + struct wlr_seat *wlr_seat, + struct wlr_tablet_tool_tool *wlr_tool); + +struct wlr_tablet_manager_v2 *wlr_tablet_v2_create(struct wl_display *display); +void wlr_tablet_v2_destroy(struct wlr_tablet_manager_v2 *manager); + +#endif /* WLR_TYPES_WLR_TABLET_V2_H */ diff --git a/rootston/desktop.c b/rootston/desktop.c index 563c5938..3f9faf24 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -22,6 +22,8 @@ #include #include #include +#include +#include #include #include "rootston/layers.h" #include "rootston/seat.h" @@ -801,6 +803,8 @@ struct roots_desktop *desktop_create(struct roots_server *server, &desktop->layer_shell_surface); desktop->layer_shell_surface.notify = handle_layer_shell_surface; + desktop->tablet_v2 = wlr_tablet_v2_create(server->wl_display); + #ifdef WLR_HAS_XWAYLAND const char *cursor_theme = NULL; const char *cursor_default = ROOTS_XCURSOR_DEFAULT; diff --git a/rootston/seat.c b/rootston/seat.c index 544cfb90..455e9b00 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include "rootston/cursor.h" #include "rootston/input.h" @@ -115,6 +116,19 @@ static void handle_tool_tip(struct wl_listener *listener, void *data) { roots_cursor_handle_tool_tip(cursor, event); } +static void handle_tool_proximity(struct wl_listener *listener, void *data) { + struct roots_cursor *cursor = + wl_container_of(listener, cursor, tool_proximity); + struct roots_desktop *desktop = cursor->seat->input->server->desktop; + wlr_idle_notify_activity(desktop->idle, cursor->seat->seat); + struct wlr_event_tablet_tool_proximity *event = data; + + struct wlr_tablet_tool_tool *tool = event->tool; + if (!tool->data) { + tool->data = wlr_make_tablet_tool(desktop->tablet_v2, cursor->seat->seat, tool); + } +} + static void handle_request_set_cursor(struct wl_listener *listener, void *data) { struct roots_cursor *cursor = @@ -251,6 +265,9 @@ static void roots_seat_init_cursor(struct roots_seat *seat) { wl_signal_add(&wlr_cursor->events.tablet_tool_tip, &seat->cursor->tool_tip); seat->cursor->tool_tip.notify = handle_tool_tip; + wl_signal_add(&wlr_cursor->events.tablet_tool_proximity, &seat->cursor->tool_proximity); + seat->cursor->tool_proximity.notify = handle_tool_proximity; + wl_signal_add(&seat->seat->events.request_set_cursor, &seat->cursor->request_set_cursor); seat->cursor->request_set_cursor.notify = handle_request_set_cursor; @@ -532,6 +549,10 @@ static void seat_add_touch(struct roots_seat *seat, static void seat_add_tablet_pad(struct roots_seat *seat, struct wlr_input_device *device) { // TODO + // FIXME: This needs to be stored on the roots_tablet_tool + struct roots_desktop *desktop = seat->input->server->desktop; + (void)wlr_make_tablet_pad(desktop->tablet_v2, seat->seat, device); + } static void handle_tablet_tool_destroy(struct wl_listener *listener, @@ -568,6 +589,11 @@ static void seat_add_tablet_tool(struct roots_seat *seat, wlr_cursor_attach_input_device(seat->cursor->cursor, device); roots_seat_configure_cursor(seat); + + struct roots_desktop *desktop = seat->input->server->desktop; + + // FIXME: This needs to be stored on the roots_tablet_tool + (void)wlr_make_tablet(desktop->tablet_v2, seat->seat, device); } void roots_seat_add_device(struct roots_seat *seat, diff --git a/types/wlr_tablet_v2.c b/types/wlr_tablet_v2.c index 56f4d567..db08c184 100644 --- a/types/wlr_tablet_v2.c +++ b/types/wlr_tablet_v2.c @@ -2,6 +2,9 @@ #define _POSIX_C_SOURCE 200809L #endif +#include + +#include #include #include #include @@ -9,17 +12,22 @@ #include #include #include +#include #include "tablet-unstable-v2-protocol.h" +struct wlr_tablet_seat_v2 { + struct wl_list link; + struct wlr_seat *wlr_seat; + struct wlr_tablet_manager_v2 *manager; -struct wlr_tablet_manager_v2 { - struct wl_global *wl_global; - struct wl_list clients; // wlr_tablet_manager_client_v2::link + struct wl_list tablets; // wlr_tablet_v2_tablet::link + struct wl_list tools; + struct wl_list pads; - struct wl_listener display_destroy; + struct wl_list clients; //wlr_tablet_seat_v2_client::link; - void *data; + struct wl_listener seat_destroy; }; struct wlr_tablet_manager_client_v2 { @@ -29,19 +37,19 @@ struct wlr_tablet_manager_client_v2 { struct wlr_tablet_manager_v2 *manager; - struct wl_list tablet_seats; // wlr_tablet_seat_v2::link + struct wl_list tablet_seats; // wlr_tablet_seat_client_v2::link }; -struct wlr_tablet_seat_v2 { - struct wl_list link; +struct wlr_tablet_seat_client_v2 { + struct wl_list seat_link; + struct wl_list client_link; struct wl_client *wl_client; struct wl_resource *resource; struct wlr_tablet_manager_client_v2 *client; struct wlr_seat_client *seat; - struct wl_listener seat_destroy; - struct wl_listener client_destroy; + struct wl_listener seat_client_destroy; struct wl_list tools; struct wl_list tablets; @@ -49,16 +57,17 @@ struct wlr_tablet_seat_v2 { }; struct wlr_tablet_client_v2 { - struct wl_list link; + struct wl_list seat_link; // wlr_tablet_seat_client_v2::tablet + struct wl_list tablet_link; // wlr_tablet_v2_tablet::clients struct wl_client *client; struct wl_resource *resource; struct wl_listener device_destroy; - struct wl_listener client_destroy; }; struct wlr_tablet_tool_client_v2 { - struct wl_list link; + struct wl_list seat_link; + struct wl_list tool_link; struct wl_client *client; struct wl_resource *resource; @@ -66,26 +75,587 @@ struct wlr_tablet_tool_client_v2 { struct wl_listener cursor_destroy; struct wl_listener tool_destroy; - struct wl_listener client_destroy; }; struct wlr_tablet_pad_client_v2 { - struct wl_list link; + struct wl_list seat_link; + struct wl_list pad_link; struct wl_client *client; struct wl_resource *resource; size_t button_count; - size_t ring_cout; + size_t group_count; + struct wl_resource **groups; + + size_t ring_count; struct wl_resource **rings; - size_t strip_cout; + size_t strip_count; struct wl_resource **strips; struct wl_listener device_destroy; - struct wl_listener client_destroy; }; +static struct zwp_tablet_v2_interface tablet_impl; + +static struct wlr_tablet_client_v2 *tablet_client_from_resource(struct wl_resource *resource) { + assert(wl_resource_instance_of(resource, &zwp_tablet_v2_interface, + &tablet_impl)); + return wl_resource_get_user_data(resource); +} + +static void destroy_tablet_v2(struct wl_resource *resource) { + struct wlr_tablet_client_v2 *tablet = tablet_client_from_resource(resource); + + wl_list_remove(&tablet->seat_link); + wl_list_remove(&tablet->tablet_link); + + //wl_list_remove(tablet->device_destroy.link); + //wl_list_remove(tablet->client_destroy.link); +} + +static void handle_tablet_v2_destroy(struct wl_client *client, + struct wl_resource *resource) { + wl_resource_destroy(resource); +} + +static struct zwp_tablet_v2_interface tablet_impl = { + .destroy = handle_tablet_v2_destroy, +}; + +static struct wlr_tablet_seat_v2 *make_tablet_seat( + struct wlr_tablet_manager_v2 *manager, + struct wlr_seat *wlr_seat) { + struct wlr_tablet_seat_v2 *tablet_seat = + calloc(1, sizeof(struct wlr_tablet_seat_v2)); + if (!tablet_seat) { + return NULL; + } + + tablet_seat->manager = manager; + tablet_seat->wlr_seat = wlr_seat; + + wl_list_init(&tablet_seat->clients); + + wl_list_init(&tablet_seat->tablets); + wl_list_init(&tablet_seat->tools); + wl_list_init(&tablet_seat->pads); + + wl_list_insert(&manager->seats, &tablet_seat->link); + return tablet_seat; +} + +static struct wlr_tablet_seat_v2 *get_or_make_tablet_seat( + struct wlr_tablet_manager_v2 *manager, + struct wlr_seat *wlr_seat) { + struct wlr_tablet_seat_v2 *pos; + wl_list_for_each(pos, &manager->seats, link) { + if (pos->wlr_seat == wlr_seat) { + return pos; + } + } + + return make_tablet_seat(manager, wlr_seat); +} + +static void add_tablet_client(struct wlr_tablet_seat_client_v2 *seat, + struct wlr_tablet_v2_tablet *tablet) { + struct wlr_tablet_client_v2 *client = + calloc(1, sizeof(struct wlr_tablet_client_v2)); + if (!client) { + return; + } + + client->resource = + wl_resource_create(seat->wl_client, &zwp_tablet_v2_interface, 1, 0); + if (!client->resource) { + free(client); + return; + } + wl_resource_set_implementation(client->resource, &tablet_impl, + client, destroy_tablet_v2); + zwp_tablet_seat_v2_send_tablet_added(seat->resource, client->resource); + + // Send the expected events + if (tablet->wlr_tool->name) { + zwp_tablet_v2_send_name(client->resource, tablet->wlr_tool->name); + } + zwp_tablet_v2_send_id(client->resource, + tablet->wlr_device->vendor, tablet->wlr_device->product); + struct wlr_tablet_path *path; + wl_list_for_each(path, &tablet->wlr_tool->paths, link) { + zwp_tablet_v2_send_path(client->resource, path->path); + } + zwp_tablet_v2_send_done(client->resource); + + client->client = seat->wl_client; + wl_list_insert(&seat->tablets, &client->seat_link); + wl_list_insert(&tablet->clients, &client->tablet_link); +} + +static void handle_wlr_tablet_destroy(struct wl_listener *listener, void *data) { + struct wlr_tablet_v2_tablet *tablet = + wl_container_of(listener, tablet, tool_destroy); + + struct wlr_tablet_client_v2 *pos; + struct wlr_tablet_client_v2 *tmp; + wl_list_for_each_safe(pos, tmp, &tablet->clients, tablet_link) { + // XXX: Add a timer/flag to destroy if client is slow? + zwp_tablet_v2_send_removed(pos->resource); + } + + wl_list_remove(&tablet->clients); + wl_list_remove(&tablet->link); + wl_list_remove(&tablet->tool_destroy.link); + free(tablet); +} + +static void handle_tablet_tool_v2_destroy(struct wl_client *client, + struct wl_resource *resource) { + wl_resource_destroy(resource); +} +static struct zwp_tablet_tool_v2_interface tablet_tool_impl = { + .set_cursor = NULL, + .destroy = handle_tablet_tool_v2_destroy, +}; + +static enum zwp_tablet_tool_v2_type tablet_type_from_wlr_type( + enum wlr_tablet_tool_type wlr_type) { + switch(wlr_type) { + case WLR_TABLET_TOOL_TYPE_PEN: + return ZWP_TABLET_TOOL_V2_TYPE_PEN; + case WLR_TABLET_TOOL_TYPE_ERASER: + return ZWP_TABLET_TOOL_V2_TYPE_ERASER; + case WLR_TABLET_TOOL_TYPE_BRUSH: + return ZWP_TABLET_TOOL_V2_TYPE_BRUSH; + case WLR_TABLET_TOOL_TYPE_PENCIL: + return ZWP_TABLET_TOOL_V2_TYPE_PENCIL; + case WLR_TABLET_TOOL_TYPE_AIRBRUSH: + return ZWP_TABLET_TOOL_V2_TYPE_AIRBRUSH; + case WLR_TABLET_TOOL_TYPE_MOUSE: + return ZWP_TABLET_TOOL_V2_TYPE_MOUSE; + case WLR_TABLET_TOOL_TYPE_LENS: + return ZWP_TABLET_TOOL_V2_TYPE_LENS; + } + + assert(false && "Unreachable"); +} + +static void add_tablet_tool_client(struct wlr_tablet_seat_client_v2 *seat, + struct wlr_tablet_v2_tablet_tool *tool) { + struct wlr_tablet_tool_client_v2 *client = + calloc(1, sizeof(struct wlr_tablet_tool_client_v2)); + if (!client) { + return; + } + + client->resource = + wl_resource_create(seat->wl_client, &zwp_tablet_tool_v2_interface, 1, 0); + if (!client->resource) { + free(client); + return; + } + wl_resource_set_implementation(client->resource, &tablet_tool_impl, + client, NULL); + zwp_tablet_seat_v2_send_tool_added(seat->resource, client->resource); + + // Send the expected events + if (tool->wlr_tool->hardware_serial) { + zwp_tablet_tool_v2_send_hardware_serial( + client->resource, + tool->wlr_tool->hardware_serial >> 32, + tool->wlr_tool->hardware_serial & 0xFFFFFFFF); + } + if (tool->wlr_tool->hardware_wacom) { + zwp_tablet_tool_v2_send_hardware_id_wacom( + client->resource, + tool->wlr_tool->hardware_wacom >> 32, + tool->wlr_tool->hardware_wacom & 0xFFFFFFFF); + } + zwp_tablet_tool_v2_send_type(client->resource, + tablet_type_from_wlr_type(tool->wlr_tool->type)); + + if (tool->wlr_tool->tilt) { + zwp_tablet_tool_v2_send_capability(client->resource, + ZWP_TABLET_TOOL_V2_CAPABILITY_TILT); + } + + if (tool->wlr_tool->pressure) { + zwp_tablet_tool_v2_send_capability(client->resource, + ZWP_TABLET_TOOL_V2_CAPABILITY_PRESSURE); + } + + if (tool->wlr_tool->distance) { + zwp_tablet_tool_v2_send_capability(client->resource, + ZWP_TABLET_TOOL_V2_CAPABILITY_DISTANCE); + } + + if (tool->wlr_tool->rotation) { + zwp_tablet_tool_v2_send_capability(client->resource, + ZWP_TABLET_TOOL_V2_CAPABILITY_ROTATION); + } + + if (tool->wlr_tool->slider) { + zwp_tablet_tool_v2_send_capability(client->resource, + ZWP_TABLET_TOOL_V2_CAPABILITY_SLIDER); + } + + if (tool->wlr_tool->wheel) { + zwp_tablet_tool_v2_send_capability(client->resource, + ZWP_TABLET_TOOL_V2_CAPABILITY_WHEEL); + } + + zwp_tablet_tool_v2_send_done(client->resource); + + client->client = seat->wl_client; + wl_list_insert(&seat->tools, &client->seat_link); + wl_list_insert(&tool->clients, &client->tool_link); +} + +struct wlr_tablet_v2_tablet *wlr_make_tablet( + struct wlr_tablet_manager_v2 *manager, + struct wlr_seat *wlr_seat, + struct wlr_input_device *wlr_device) { + assert(wlr_device->type == WLR_INPUT_DEVICE_TABLET_TOOL); + struct wlr_tablet_seat_v2 *seat = get_or_make_tablet_seat(manager, wlr_seat); + if (!seat) { + return NULL; + } + struct wlr_tablet_tool *tool = wlr_device->tablet_tool; + struct wlr_tablet_v2_tablet *tablet = calloc(1, sizeof(struct wlr_tablet_v2_tablet)); + if (!tablet) { + return NULL; + } + + tablet->wlr_tool = tool; + tablet->wlr_device = wlr_device; + wl_list_init(&tablet->clients); + + + tablet->tool_destroy.notify = handle_wlr_tablet_destroy; + wl_signal_add(&wlr_device->events.destroy, &tablet->tool_destroy); + wl_list_insert(&seat->tablets, &tablet->link); + + // We need to create a tablet client for all clients on the seat + struct wlr_tablet_seat_client_v2 *pos; + wl_list_for_each(pos, &seat->clients, seat_link) { + // Tell the clients about the new tool + add_tablet_client(pos, tablet); + } + + return tablet; +} + +static void handle_wlr_tablet_tool_destroy(struct wl_listener *listener, void *data) { + struct wlr_tablet_v2_tablet_tool *tool = + wl_container_of(listener, tool, tool_destroy); + + struct wlr_tablet_tool_client_v2 *pos; + struct wlr_tablet_tool_client_v2 *tmp; + wl_list_for_each_safe(pos, tmp, &tool->clients, tool_link) { + // XXX: Add a timer/flag to destroy if client is slow? + zwp_tablet_tool_v2_send_removed(pos->resource); + } + + wl_list_remove(&tool->clients); + wl_list_remove(&tool->link); + wl_list_remove(&tool->tool_destroy.link); + free(tool); +} + +struct wlr_tablet_v2_tablet_tool *wlr_make_tablet_tool( + struct wlr_tablet_manager_v2 *manager, + struct wlr_seat *wlr_seat, + struct wlr_tablet_tool_tool *wlr_tool) { + struct wlr_tablet_seat_v2 *seat = get_or_make_tablet_seat(manager, wlr_seat); + if (!seat) { + return NULL; + } + struct wlr_tablet_v2_tablet_tool *tool = + calloc(1, sizeof(struct wlr_tablet_v2_tablet_tool)); + if (!tool) { + return NULL; + } + + tool->wlr_tool = wlr_tool; + wl_list_init(&tool->clients); + + + tool->tool_destroy.notify = handle_wlr_tablet_tool_destroy; + wl_signal_add(&wlr_tool->events.destroy, &tool->tool_destroy); + wl_list_insert(&seat->tools, &tool->link); + + // We need to create a tablet client for all clients on the seat + struct wlr_tablet_seat_client_v2 *pos; + wl_list_for_each(pos, &seat->clients, seat_link) { + // Tell the clients about the new tool + add_tablet_tool_client(pos, tool); + } + + return tool; +} + +static struct zwp_tablet_pad_v2_interface tablet_pad_impl; + +static struct wlr_tablet_pad_client_v2 *tablet_pad_client_from_resource(struct wl_resource *resource) { + assert(wl_resource_instance_of(resource, &zwp_tablet_pad_v2_interface, + &tablet_pad_impl)); + return wl_resource_get_user_data(resource); +} + + +static void destroy_tablet_pad_v2(struct wl_resource *resource) { + struct wlr_tablet_pad_client_v2 *pad = + tablet_pad_client_from_resource(resource); + + wl_list_remove(&pad->seat_link); + wl_list_remove(&pad->pad_link); + + //wl_list_remove(tablet->device_destroy.link); + //wl_list_remove(tablet->client_destroy.link); +} + +static void handle_tablet_pad_v2_destroy(struct wl_client *client, + struct wl_resource *resource) { + wl_resource_destroy(resource); +} + +static void destroy_tablet_pad_ring_v2(struct wl_resource *resource) { + struct wlr_tablet_pad_client_v2 *client = wl_resource_get_user_data(resource); + + for (size_t i = 0; i < client->ring_count; ++i) { + if (client->rings[i] == resource) { + client->rings[i] = NULL; + return; + } + } +} + +static void handle_tablet_pad_ring_v2_destroy(struct wl_client *client, + struct wl_resource *resource) { + wl_resource_destroy(resource); +} + +static struct zwp_tablet_pad_ring_v2_interface tablet_pad_ring_impl = { + .set_feedback = NULL, + .destroy = handle_tablet_pad_ring_v2_destroy, +}; + +static void destroy_tablet_pad_strip_v2(struct wl_resource *resource) { + struct wlr_tablet_pad_client_v2 *client = wl_resource_get_user_data(resource); + + for (size_t i = 0; i < client->strip_count; ++i) { + if (client->strips[i] == resource) { + client->strips[i] = NULL; + return; + } + } +} + +static void handle_tablet_pad_strip_v2_destroy(struct wl_client *client, + struct wl_resource *resource) { + wl_resource_destroy(resource); +} + +static struct zwp_tablet_pad_strip_v2_interface tablet_pad_strip_impl = { + .set_feedback = NULL, + .destroy = handle_tablet_pad_strip_v2_destroy, +}; + +static struct zwp_tablet_pad_v2_interface tablet_pad_impl = { + .set_feedback = NULL, + .destroy = handle_tablet_pad_v2_destroy, +}; + +static void destroy_tablet_pad_group_v2(struct wl_resource *resource) { + struct wlr_tablet_pad_client_v2 *client = wl_resource_get_user_data(resource); + + for (size_t i = 0; i < client->group_count; ++i) { + if (client->groups[i] == resource) { + client->groups[i] = NULL; + return; + } + } +} + +static void handle_tablet_pad_group_v2_destroy(struct wl_client *client, + struct wl_resource *resource) { + wl_resource_destroy(resource); +} + +static struct zwp_tablet_pad_group_v2_interface tablet_pad_group_impl = { + .destroy = handle_tablet_pad_group_v2_destroy, +}; + +static void add_tablet_pad_group(struct wlr_tablet_v2_tablet_pad *pad, + struct wlr_tablet_pad_client_v2 *client, + struct wlr_tablet_pad_group *group, size_t index) { + client->groups[index] = + wl_resource_create(client->client, &zwp_tablet_pad_group_v2_interface, 1, 0); + if (!client->groups[index]) { + wl_client_post_no_memory(client->client); + return; + } + wl_resource_set_implementation(client->groups[index], &tablet_pad_group_impl, + client, destroy_tablet_pad_group_v2); + + zwp_tablet_pad_v2_send_group(client->resource, client->groups[index]); + zwp_tablet_pad_group_v2_send_modes(client->groups[index], group->mode_count); + + struct wl_array button_array; + wl_array_init(&button_array); + wl_array_add(&button_array, group->button_count * sizeof(int)); + memcpy(button_array.data, group->buttons, group->button_count * sizeof(int)); + zwp_tablet_pad_group_v2_send_buttons(client->groups[index], &button_array); + + client->strip_count = group->strip_count; + for (size_t i = 0; i < group->strip_count; ++i) { + size_t strip = group->strips[i]; + client->strips[strip] = + wl_resource_create(client->client, &zwp_tablet_pad_strip_v2_interface, 1, 0); + wl_resource_set_implementation(client->strips[strip], + &tablet_pad_strip_impl, + client, destroy_tablet_pad_strip_v2); + zwp_tablet_pad_group_v2_send_strip(client->groups[index], client->strips[strip]); + } + + client->ring_count = group->ring_count; + for (size_t i = 0; i < group->ring_count; ++i) { + size_t ring = group->rings[i]; + client->rings[ring] = + wl_resource_create(client->client, &zwp_tablet_pad_ring_v2_interface, 1, 0); + wl_resource_set_implementation(client->rings[ring], + &tablet_pad_ring_impl, + client, destroy_tablet_pad_ring_v2); + zwp_tablet_pad_group_v2_send_ring(client->groups[index], client->rings[ring]); + } + + zwp_tablet_pad_group_v2_send_done(client->groups[index]); +} + +static void add_tablet_pad_client(struct wlr_tablet_seat_client_v2 *seat, + struct wlr_tablet_v2_tablet_pad *pad) { + struct wlr_tablet_pad_client_v2 *client = + calloc(1, sizeof(struct wlr_tablet_pad_client_v2)); + if (!client) { + wl_client_post_no_memory(seat->wl_client); + return; + } + + client->groups = calloc(sizeof(int), wl_list_length(&pad->wlr_pad->groups)); + if (!client->groups) { + wl_client_post_no_memory(seat->wl_client); + free(client); + return; + } + + client->rings = calloc(sizeof(struct wl_resource*), pad->wlr_pad->ring_count); + if (!client->rings) { + wl_client_post_no_memory(seat->wl_client); + free(client->groups); + free(client); + return; + } + + client->strips = calloc(sizeof(struct wl_resource*), pad->wlr_pad->strip_count); + if (!client->strips) { + wl_client_post_no_memory(seat->wl_client); + free(client->groups); + free(client->rings); + free(client); + return; + } + + client->resource = + wl_resource_create(seat->wl_client, &zwp_tablet_pad_v2_interface, 1, 0); + if (!client->resource) { + wl_client_post_no_memory(seat->wl_client); + free(client->groups); + free(client->rings); + free(client->strips); + free(client); + return; + } + wl_resource_set_implementation(client->resource, &tablet_pad_impl, + client, destroy_tablet_pad_v2); + zwp_tablet_seat_v2_send_pad_added(seat->resource, client->resource); + client->client = seat->wl_client; + + // Send the expected events + if (pad->wlr_pad->button_count) { + zwp_tablet_pad_v2_send_buttons(client->resource, pad->wlr_pad->button_count); + } + struct wlr_tablet_path *path; + wl_list_for_each(path, &pad->wlr_pad->paths, link) { + zwp_tablet_pad_v2_send_path(client->resource, path->path); + } + size_t i = 0; + struct wlr_tablet_pad_group *group; + wl_list_for_each(group, &pad->wlr_pad->groups, link) { + add_tablet_pad_group(pad, client, group, i++); + } + zwp_tablet_pad_v2_send_done(client->resource); + + wl_list_insert(&seat->pads, &client->seat_link); + wl_list_insert(&pad->clients, &client->pad_link); +} + +static void handle_wlr_tablet_pad_destroy(struct wl_listener *listener, void *data) { + struct wlr_tablet_v2_tablet_pad *pad = + wl_container_of(listener, pad, pad_destroy); + + struct wlr_tablet_pad_client_v2 *pos; + struct wlr_tablet_pad_client_v2 *tmp; + wl_list_for_each_safe(pos, tmp, &pad->clients, pad_link) { + // XXX: Add a timer/flag to destroy if client is slow? + zwp_tablet_pad_v2_send_removed(pos->resource); + } + + wl_list_remove(&pad->clients); + wl_list_remove(&pad->link); + wl_list_remove(&pad->pad_destroy.link); + free(pad); +} + +struct wlr_tablet_v2_tablet_pad *wlr_make_tablet_pad( + struct wlr_tablet_manager_v2 *manager, + struct wlr_seat *wlr_seat, + struct wlr_input_device *wlr_device) { + assert(wlr_device->type == WLR_INPUT_DEVICE_TABLET_PAD); + struct wlr_tablet_seat_v2 *seat = get_or_make_tablet_seat(manager, wlr_seat); + if (!seat) { + return NULL; + } + struct wlr_tablet_pad *wlr_pad = wlr_device->tablet_pad; + struct wlr_tablet_v2_tablet_pad *pad = calloc(1, sizeof(struct wlr_tablet_v2_tablet_pad)); + if (!pad) { + return NULL; + } + + pad->wlr_pad = wlr_pad; + wl_list_init(&pad->clients); + + pad->pad_destroy.notify = handle_wlr_tablet_pad_destroy; + wl_signal_add(&wlr_device->events.destroy, &pad->pad_destroy); + wl_list_insert(&seat->pads, &pad->link); + + // We need to create a tablet client for all clients on the seat + struct wlr_tablet_seat_client_v2 *pos; + wl_list_for_each(pos, &seat->clients, seat_link) { + // Tell the clients about the new tool + add_tablet_pad_client(pos, pad); + } + + wlr_log(L_DEBUG, "Created tablet v2 pad:"); + struct wlr_tablet_path *path; + wl_list_for_each(path, &wlr_pad->paths, link) { + wlr_log(L_DEBUG, "%s", path->path); + } + + return pad; +} + void wlr_tablet_v2_destroy(struct wlr_tablet_manager_v2 *manager); static struct wlr_tablet_manager_client_v2 *tablet_manager_client_from_resource(struct wl_resource *resource); @@ -98,15 +668,15 @@ static struct zwp_tablet_seat_v2_interface seat_impl = { .destroy = tablet_seat_destroy, }; -static struct wlr_tablet_seat_v2 *tablet_seat_from_resource ( +static struct wlr_tablet_seat_client_v2 *tablet_seat_from_resource ( struct wl_resource *resource) { assert(wl_resource_instance_of(resource, &zwp_tablet_seat_v2_interface, &seat_impl)); return wl_resource_get_user_data(resource); } -static void wlr_tablet_seat_v2_destroy(struct wl_resource *resource) { - struct wlr_tablet_seat_v2 *seat = tablet_seat_from_resource(resource); +static void wlr_tablet_seat_client_v2_destroy(struct wl_resource *resource) { + struct wlr_tablet_seat_client_v2 *seat = tablet_seat_from_resource(resource); seat->resource = NULL; /* We can't just destroy the struct, because we may need to iterate it @@ -116,15 +686,15 @@ static void wlr_tablet_seat_v2_destroy(struct wl_resource *resource) { } static void handle_seat_destroy(struct wl_listener *listener, void *data) { - struct wlr_tablet_seat_v2 *seat = - wl_container_of(listener, seat, seat_destroy); + struct wlr_tablet_seat_client_v2 *seat = + wl_container_of(listener, seat, seat_client_destroy); seat->seat = NULL; - wl_list_remove(&seat->seat_destroy.link); + wl_list_remove(&seat->seat_client_destroy.link); /* Remove leaves it in a defunct state, we will remove again in the * actual destroy sequence */ - wl_list_init(&seat->seat_destroy.link); + wl_list_init(&seat->seat_client_destroy.link); } static void tablet_manager_destroy(struct wl_client *client, @@ -137,32 +707,60 @@ static void get_tablet_seat(struct wl_client *wl_client, struct wl_resource *res { struct wlr_tablet_manager_client_v2 *manager = tablet_manager_client_from_resource(resource); struct wlr_seat_client *seat = wlr_seat_client_from_resource(seat_resource); - struct wlr_tablet_seat_v2 *tablet_seat = - calloc(1, sizeof(struct wlr_tablet_seat_v2)); + get_or_make_tablet_seat(manager->manager, seat->seat); + + if (!tablet_seat) {// This can only happen when we ran out of memory + wl_client_post_no_memory(wl_client); + return; + } + + struct wlr_tablet_seat_client_v2 *seat_client = + calloc(1, sizeof(struct wlr_tablet_seat_client_v2)); if (tablet_seat == NULL) { wl_client_post_no_memory(wl_client); return; } - tablet_seat->resource = + seat_client->resource = wl_resource_create(wl_client, &zwp_tablet_seat_v2_interface, 1, id); - if (tablet_seat->resource == NULL) { - free(tablet_seat); + if (seat_client->resource == NULL) { + free(seat_client); wl_client_post_no_memory(wl_client); return; } + wl_resource_set_implementation(seat_client->resource, &seat_impl, seat_client, + wlr_tablet_seat_client_v2_destroy); + + seat_client->seat = seat; + seat_client->client = manager; + seat_client->wl_client = wl_client; + wl_list_init(&seat_client->tools); + wl_list_init(&seat_client->tablets); + wl_list_init(&seat_client->pads); - tablet_seat->seat = seat; - tablet_seat->client = manager; + seat_client->seat_client_destroy.notify = handle_seat_destroy; + wl_signal_add(&seat->events.destroy, &seat_client->seat_client_destroy); - tablet_seat->seat_destroy.notify = handle_seat_destroy; - wl_signal_add(&seat->events.destroy, &tablet_seat->seat_destroy); + wl_list_insert(&manager->tablet_seats, &seat_client->client_link); + wl_list_insert(&tablet_seat->clients, &seat_client->seat_link); + + // We need to emmit the devices allready on the seat + struct wlr_tablet_v2_tablet *tablet_pos; + wl_list_for_each(tablet_pos, &tablet_seat->tablets, link) { + add_tablet_client(seat_client, tablet_pos); + } - wl_resource_set_implementation(tablet_seat->resource, &seat_impl, tablet_seat, - wlr_tablet_seat_v2_destroy); - wl_list_insert(&manager->tablet_seats, &tablet_seat->link); + struct wlr_tablet_v2_tablet_pad *pad_pos; + wl_list_for_each(pad_pos, &tablet_seat->pads, link) { + add_tablet_pad_client(seat_client, pad_pos); + } + + struct wlr_tablet_v2_tablet_tool *tool_pos; + wl_list_for_each(tool_pos, &tablet_seat->tools, link) { + add_tablet_tool_client(seat_client, tool_pos); + } } static struct zwp_tablet_manager_v2_interface manager_impl = { @@ -242,6 +840,7 @@ struct wlr_tablet_manager_v2 *wlr_tablet_v2_create(struct wl_display *display) { } wl_list_init(&tablet->clients); + wl_list_init(&tablet->seats); tablet->display_destroy.notify = handle_display_destroy; wl_display_add_destroy_listener(display, &tablet->display_destroy); -- cgit v1.2.3 From f375246657e23926d98cc21ae66a5dae352ea50a Mon Sep 17 00:00:00 2001 From: Markus Ongyerth Date: Thu, 26 Apr 2018 12:31:25 +0200 Subject: Implement basic tablet_pad handling (bound to keyboard focus) --- backend/libinput/tablet_pad.c | 2 + include/rootston/seat.h | 23 ++++ include/wlr/types/wlr_tablet_pad.h | 2 + include/wlr/types/wlr_tablet_v2.h | 42 ++++++ rootston/seat.c | 177 ++++++++++++++++++++++++- types/wlr_tablet_pad.c | 1 + types/wlr_tablet_v2.c | 263 +++++++++++++++++++++++++++++++++++++ 7 files changed, 505 insertions(+), 5 deletions(-) (limited to 'backend/libinput/tablet_pad.c') diff --git a/backend/libinput/tablet_pad.c b/backend/libinput/tablet_pad.c index 2558d09c..7c196bf1 100644 --- a/backend/libinput/tablet_pad.c +++ b/backend/libinput/tablet_pad.c @@ -124,6 +124,8 @@ void handle_tablet_pad_button(struct libinput_event *event, usec_to_msec(libinput_event_tablet_pad_get_time_usec(pevent)); wlr_event.button = libinput_event_tablet_pad_get_button_number(pevent); wlr_event.mode = libinput_event_tablet_pad_get_mode(pevent); + wlr_event.group = libinput_tablet_pad_mode_group_get_index( + libinput_event_tablet_pad_get_mode_group(pevent)); switch (libinput_event_tablet_pad_get_button_state(pevent)) { case LIBINPUT_BUTTON_STATE_PRESSED: wlr_event.state = WLR_BUTTON_PRESSED; diff --git a/include/rootston/seat.h b/include/rootston/seat.h index 0e3043dd..31ddd6fa 100644 --- a/include/rootston/seat.h +++ b/include/rootston/seat.h @@ -31,6 +31,7 @@ struct roots_seat { struct wl_list pointers; struct wl_list touch; struct wl_list tablet_tools; + struct wl_list tablet_pads; struct wl_listener new_drag_icon; struct wl_listener destroy; @@ -80,12 +81,34 @@ struct roots_touch { struct roots_tablet_tool { struct roots_seat *seat; struct wlr_input_device *device; + struct wlr_tablet_v2_tablet *tablet_v2; + struct wl_listener device_destroy; struct wl_listener axis; struct wl_listener proximity; struct wl_listener tip; struct wl_listener button; struct wl_list link; + + struct wl_list pads; // struct roots_tablet_pad::tablet_link +}; + +struct roots_tablet_pad { + struct wl_list link; + struct wl_list tablet_link; + struct wlr_tablet_v2_tablet_pad *tablet_v2_pad; + + struct roots_seat *seat; + struct wlr_input_device *device; + + struct wl_listener device_destroy; + struct wl_listener attach; + struct wl_listener button; + struct wl_listener ring; + struct wl_listener strip; + + struct roots_tablet_tool *tablet; + struct wl_listener tablet_destroy; }; struct roots_seat *roots_seat_create(struct roots_input *input, char *name); diff --git a/include/wlr/types/wlr_tablet_pad.h b/include/wlr/types/wlr_tablet_pad.h index b71f5b9a..ec291c75 100644 --- a/include/wlr/types/wlr_tablet_pad.h +++ b/include/wlr/types/wlr_tablet_pad.h @@ -20,6 +20,7 @@ struct wlr_tablet_pad { struct wl_signal button; struct wl_signal ring; struct wl_signal strip; + struct wl_signal attach_tablet; //struct wlr_tablet_tool } events; size_t button_count; @@ -52,6 +53,7 @@ struct wlr_event_tablet_pad_button { uint32_t button; enum wlr_button_state state; unsigned int mode; + unsigned int group; }; enum wlr_tablet_pad_ring_source { diff --git a/include/wlr/types/wlr_tablet_v2.h b/include/wlr/types/wlr_tablet_v2.h index 358f0719..4b2fffe4 100644 --- a/include/wlr/types/wlr_tablet_v2.h +++ b/include/wlr/types/wlr_tablet_v2.h @@ -5,6 +5,11 @@ #include #include +#include "tablet-unstable-v2-protocol.h" + +struct wlr_tablet_tool_client_v2; +struct wlr_tablet_pad_client_v2; + struct wlr_tablet_manager_v2 { struct wl_global *wl_global; struct wl_list clients; // wlr_tablet_manager_client_v2::link @@ -30,6 +35,8 @@ struct wlr_tablet_v2_tablet_tool { struct wl_list clients; // wlr_tablet_tool_client_v2::tablet_link struct wl_listener tool_destroy; + + struct wlr_tablet_tool_client_v2 *current_client; }; struct wlr_tablet_v2_tablet_pad { @@ -38,7 +45,12 @@ struct wlr_tablet_v2_tablet_pad { struct wlr_input_device *wlr_device; struct wl_list clients; // wlr_tablet_pad_client_v2::tablet_link + size_t group_count; + uint32_t *groups; + struct wl_listener pad_destroy; + + struct wlr_tablet_pad_client_v2 *current_client; }; struct wlr_tablet_v2_tablet *wlr_make_tablet( @@ -59,4 +71,34 @@ struct wlr_tablet_v2_tablet_tool *wlr_make_tablet_tool( struct wlr_tablet_manager_v2 *wlr_tablet_v2_create(struct wl_display *display); void wlr_tablet_v2_destroy(struct wlr_tablet_manager_v2 *manager); +uint32_t wlr_send_tablet_v2_tablet_tool_proximity_in( + struct wlr_tablet_v2_tablet_tool *tool, + struct wlr_tablet_v2_tablet *tablet, + struct wlr_surface *surface); + +void wlr_send_tablet_v2_tablet_tool_motion( + struct wlr_tablet_v2_tablet_tool *tool, double x, double y); + +void wlr_send_tablet_v2_tablet_tool_proximity_out( + struct wlr_tablet_v2_tablet_tool *tool); + +uint32_t wlr_send_tablet_v2_tablet_pad_enter( + struct wlr_tablet_v2_tablet_pad *pad, + struct wlr_tablet_v2_tablet *tablet, + struct wlr_surface *surface); + +void wlr_send_tablet_v2_tablet_pad_button( + struct wlr_tablet_v2_tablet_pad *pad, size_t button, + uint32_t time, enum zwp_tablet_pad_v2_button_state state); + +void wlr_send_tablet_v2_tablet_pad_strip( struct wlr_tablet_v2_tablet_pad *pad, + uint32_t strip, double position, bool finger, uint32_t time); +void wlr_send_tablet_v2_tablet_pad_ring(struct wlr_tablet_v2_tablet_pad *pad, + uint32_t ring, double position, bool finger, uint32_t time); + +uint32_t wlr_send_tablet_v2_tablet_pad_leave(struct wlr_tablet_v2_tablet_pad *pad, + struct wlr_surface *surface); + +uint32_t wlr_send_tablet_v2_tablet_pad_mode(struct wlr_tablet_v2_tablet_pad *pad, + size_t group, uint32_t mode, uint32_t time); #endif /* WLR_TYPES_WLR_TABLET_V2_H */ diff --git a/rootston/seat.c b/rootston/seat.c index 455e9b00..8f84fc4b 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -16,6 +17,8 @@ #include "rootston/seat.h" #include "rootston/xcursor.h" +#include + static void handle_keyboard_key(struct wl_listener *listener, void *data) { struct roots_keyboard *keyboard = wl_container_of(listener, keyboard, keyboard_key); @@ -393,6 +396,7 @@ struct roots_seat *roots_seat_create(struct roots_input *input, char *name) { wl_list_init(&seat->pointers); wl_list_init(&seat->touch); wl_list_init(&seat->tablet_tools); + wl_list_init(&seat->tablet_pads); wl_list_init(&seat->views); wl_list_init(&seat->drag_icons); @@ -546,13 +550,152 @@ static void seat_add_touch(struct roots_seat *seat, roots_seat_configure_cursor(seat); } +static void handle_tablet_pad_destroy(struct wl_listener *listener, + void *data) { + struct roots_tablet_pad *tablet_pad = + wl_container_of(listener, tablet_pad, device_destroy); + struct roots_seat *seat = tablet_pad->seat; + + wl_list_remove(&tablet_pad->device_destroy.link); + wl_list_remove(&tablet_pad->tablet_destroy.link); + wl_list_remove(&tablet_pad->attach.link); + wl_list_remove(&tablet_pad->link); + wl_list_remove(&tablet_pad->tablet_link); + + wl_list_remove(&tablet_pad->button.link); + wl_list_remove(&tablet_pad->strip.link); + wl_list_remove(&tablet_pad->ring.link); + free(tablet_pad); + + seat_update_capabilities(seat); +} + +static void handle_pad_tool_destroy(struct wl_listener *listener, void *data) { + struct roots_tablet_pad *pad = + wl_container_of(listener, pad, tablet_destroy); + + pad->tablet = NULL; + wl_list_remove(&pad->tablet_link); + wl_list_init(&pad->tablet_link); + + wl_list_remove(&pad->tablet_destroy.link); + wl_list_init(&pad->tablet_destroy.link); +} + +static void attach_tablet_pad(struct roots_tablet_pad *pad, + struct roots_tablet_tool *tool) { + wlr_log(L_DEBUG, "Attaching tablet pad \"%s\" to tablet tool \"%s\"", + pad->device->name, tool->device->name); + + pad->tablet = tool; + wl_list_remove(&pad->tablet_link); + wl_list_insert(&tool->pads, &pad->tablet_link); + + wl_signal_add(&tool->device->events.destroy, + &pad->tablet_destroy); +} + +static void handle_tablet_pad_attach(struct wl_listener *listener, void *data) { + struct roots_tablet_pad *pad = + wl_container_of(listener, pad, attach); + struct wlr_tablet_tool *wlr_tool = data; + struct roots_tablet_tool *tool = wlr_tool->data; + + attach_tablet_pad(pad, tool); +} + +static void handle_tablet_pad_ring(struct wl_listener *listener, void *data) { + struct roots_tablet_pad *pad = + wl_container_of(listener, pad, ring); + struct wlr_event_tablet_pad_ring *event = data; + + wlr_send_tablet_v2_tablet_pad_ring(pad->tablet_v2_pad, + event->ring, event->position, + event->source == WLR_TABLET_PAD_RING_SOURCE_FINGER, + event->time_msec); +} + +static void handle_tablet_pad_strip(struct wl_listener *listener, void *data) { + struct roots_tablet_pad *pad = + wl_container_of(listener, pad, strip); + struct wlr_event_tablet_pad_strip *event = data; + + wlr_send_tablet_v2_tablet_pad_strip(pad->tablet_v2_pad, + event->strip, event->position, + event->source == WLR_TABLET_PAD_STRIP_SOURCE_FINGER, + event->time_msec); +} + +static void handle_tablet_pad_button(struct wl_listener *listener, void *data) { + struct roots_tablet_pad *pad = + wl_container_of(listener, pad, button); + struct wlr_event_tablet_pad_button *event = data; + + wlr_send_tablet_v2_tablet_pad_mode(pad->tablet_v2_pad, + event->group, event->mode, event->time_msec); + + wlr_send_tablet_v2_tablet_pad_button(pad->tablet_v2_pad, + event->button, event->time_msec, event->state); +} + static void seat_add_tablet_pad(struct roots_seat *seat, struct wlr_input_device *device) { - // TODO - // FIXME: This needs to be stored on the roots_tablet_tool + struct roots_tablet_pad *tablet_pad = + calloc(sizeof(struct roots_tablet_pad), 1); + if (!tablet_pad) { + wlr_log(L_ERROR, "could not allocate tablet_pad for seat"); + return; + } + + device->data = tablet_pad; + tablet_pad->device = device; + tablet_pad->seat = seat; + wl_list_init(&tablet_pad->tablet_link); + wl_list_insert(&seat->tablet_pads, &tablet_pad->link); + + tablet_pad->device_destroy.notify = handle_tablet_pad_destroy; + wl_signal_add(&tablet_pad->device->events.destroy, + &tablet_pad->device_destroy); + + tablet_pad->tablet_destroy.notify = handle_pad_tool_destroy; + + tablet_pad->attach.notify = handle_tablet_pad_attach; + wl_signal_add(&tablet_pad->device->tablet_pad->events.attach_tablet, &tablet_pad->attach); + + tablet_pad->button.notify = handle_tablet_pad_button; + wl_signal_add(&tablet_pad->device->tablet_pad->events.button, &tablet_pad->button); + + tablet_pad->strip.notify = handle_tablet_pad_strip; + wl_signal_add(&tablet_pad->device->tablet_pad->events.strip, &tablet_pad->strip); + + tablet_pad->ring.notify = handle_tablet_pad_ring; + wl_signal_add(&tablet_pad->device->tablet_pad->events.ring, &tablet_pad->ring); + struct roots_desktop *desktop = seat->input->server->desktop; - (void)wlr_make_tablet_pad(desktop->tablet_v2, seat->seat, device); + tablet_pad->tablet_v2_pad = + wlr_make_tablet_pad(desktop->tablet_v2, seat->seat, device); + + /* Search for a sibling tablet */ + if (!wlr_input_device_is_libinput(device)) { + /* We can only do this on libinput devices */ + return; + } + struct libinput_device_group *group = + libinput_device_get_device_group(wlr_libinput_get_device_handle(device)); + struct roots_tablet_tool *tool; + wl_list_for_each(tool, &seat->tablet_tools, link) { + if (!wlr_input_device_is_libinput(tool->device)) { + continue; + } + + struct libinput_device *li_dev = + wlr_libinput_get_device_handle(tool->device); + if (libinput_device_get_device_group(li_dev) == group) { + attach_tablet_pad(tablet_pad, tool); + break; + } + } } static void handle_tablet_tool_destroy(struct wl_listener *listener, @@ -564,6 +707,7 @@ static void handle_tablet_tool_destroy(struct wl_listener *listener, wlr_cursor_detach_input_device(seat->cursor->cursor, tablet_tool->device); wl_list_remove(&tablet_tool->device_destroy.link); wl_list_remove(&tablet_tool->link); + wl_list_remove(&tablet_tool->pads); free(tablet_tool); seat_update_capabilities(seat); @@ -581,6 +725,7 @@ static void seat_add_tablet_tool(struct roots_seat *seat, device->data = tablet_tool; tablet_tool->device = device; tablet_tool->seat = seat; + wl_list_init(&tablet_tool->pads); wl_list_insert(&seat->tablet_tools, &tablet_tool->link); tablet_tool->device_destroy.notify = handle_tablet_tool_destroy; @@ -592,8 +737,23 @@ static void seat_add_tablet_tool(struct roots_seat *seat, struct roots_desktop *desktop = seat->input->server->desktop; - // FIXME: This needs to be stored on the roots_tablet_tool - (void)wlr_make_tablet(desktop->tablet_v2, seat->seat, device); + tablet_tool->tablet_v2 = + wlr_make_tablet(desktop->tablet_v2, seat->seat, device); + + struct libinput_device_group *group = + libinput_device_get_device_group(wlr_libinput_get_device_handle(device)); + struct roots_tablet_pad *pad; + wl_list_for_each(pad, &seat->tablet_pads, link) { + if (!wlr_input_device_is_libinput(pad->device)) { + continue; + } + + struct libinput_device *li_dev = + wlr_libinput_get_device_handle(pad->device); + if (libinput_device_get_device_group(li_dev) == group) { + attach_tablet_pad(pad, tablet_tool); + } + } } void roots_seat_add_device(struct roots_seat *seat, @@ -859,6 +1019,13 @@ void roots_seat_set_focus(struct roots_seat *seat, struct roots_view *view) { wlr_seat_keyboard_notify_enter(seat->seat, view->wlr_surface, keyboard->keycodes, keyboard->num_keycodes, &keyboard->modifiers); + /* FIXME: Move this to a better place */ + struct roots_tablet_pad *pad; + wl_list_for_each(pad, &seat->tablet_pads, link) { + if (pad->tablet) { + wlr_send_tablet_v2_tablet_pad_enter(pad->tablet_v2_pad, pad->tablet->tablet_v2, view->wlr_surface); + } + } } else { wlr_seat_keyboard_notify_enter(seat->seat, view->wlr_surface, NULL, 0, NULL); diff --git a/types/wlr_tablet_pad.c b/types/wlr_tablet_pad.c index 3d25d685..f7d6c436 100644 --- a/types/wlr_tablet_pad.c +++ b/types/wlr_tablet_pad.c @@ -10,6 +10,7 @@ void wlr_tablet_pad_init(struct wlr_tablet_pad *pad, wl_signal_init(&pad->events.button); wl_signal_init(&pad->events.ring); wl_signal_init(&pad->events.strip); + wl_signal_init(&pad->events.attach_tablet); } void wlr_tablet_pad_destroy(struct wlr_tablet_pad *pad) { diff --git a/types/wlr_tablet_v2.c b/types/wlr_tablet_v2.c index 3e4eaafc..f980aa0d 100644 --- a/types/wlr_tablet_v2.c +++ b/types/wlr_tablet_v2.c @@ -68,6 +68,10 @@ struct wlr_tablet_tool_client_v2 { struct wl_list tool_link; struct wl_client *client; struct wl_resource *resource; + + uint32_t proximity_serial; + + struct wl_event_source *frame_source; }; struct wlr_tablet_pad_client_v2 { @@ -76,6 +80,10 @@ struct wlr_tablet_pad_client_v2 { struct wl_client *client; struct wl_resource *resource; + uint32_t enter_serial; + uint32_t mode_serial; + uint32_t leave_serial; + size_t button_count; size_t group_count; @@ -284,6 +292,10 @@ static void destroy_tablet_tool(struct wl_resource *resource) { struct wlr_tablet_tool_client_v2 *client = wl_resource_get_user_data(resource); + if (client->frame_source) { + wl_event_source_remove(client->frame_source); + } + wl_list_remove(&client->seat_link); wl_list_remove(&client->tool_link); free(client); @@ -706,6 +718,13 @@ struct wlr_tablet_v2_tablet_pad *wlr_make_tablet_pad( return NULL; } + pad->group_count = wl_list_length(&wlr_pad->groups); + pad->groups = calloc(pad->group_count, sizeof(int)); + if (!pad->groups) { + free(pad); + return NULL; + } + pad->wlr_pad = wlr_pad; wl_list_init(&pad->clients); @@ -920,3 +939,247 @@ struct wlr_tablet_manager_v2 *wlr_tablet_v2_create(struct wl_display *display) { return tablet; } + +/* Actual protocol foo */ + +static void send_tool_frame(void *data) { + struct wlr_tablet_tool_client_v2 *tool = data; + + zwp_tablet_tool_v2_send_frame(tool->resource, 0); + tool->frame_source = NULL; +} + +static void queue_tool_frame(struct wlr_tablet_tool_client_v2 *tool) { + if (!tool->frame_source) { + tool->frame_source = wl_event_loop_add_idle(NULL, send_tool_frame, tool); + } +} + +uint32_t wlr_send_tablet_v2_tablet_tool_proximity_in( + struct wlr_tablet_v2_tablet_tool *tool, + struct wlr_tablet_v2_tablet *tablet, + struct wlr_surface *surface) { + struct wl_client *client = wl_resource_get_client(surface->resource); + + struct wlr_tablet_client_v2 *tablet_tmp; + struct wlr_tablet_client_v2 *tablet_client = NULL; + wl_list_for_each(tablet_tmp, &tablet->clients, tablet_link) { + if (tablet_tmp->client == client) { + tablet_client = tablet_tmp; + break; + } + } + + // Couldn't find the client binding for the surface's client. Either + // the client didn't bind tablet_v2 at all, or not for the relevant + // seat + if (!tablet_client) { + return 0; + } + + struct wlr_tablet_tool_client_v2 *tool_tmp; + struct wlr_tablet_tool_client_v2 *tool_client; + wl_list_for_each(tool_tmp, &tool->clients, tool_link) { + if (tool_tmp->client == client) { + tool_client = tool_tmp; + break; + } + } + + // Couldn't find the client binding for the surface's client. Either + // the client didn't bind tablet_v2 at all, or not for the relevant + // seat + if (!tool_client) { + return 0; + } + + tool->current_client = tool_client; + + /* Pre-increment keeps 0 clean. wraparound would be after 2^32 + * proximity_in. Someone wants to do the math how long that would take? + */ + uint32_t serial = ++tool_client->proximity_serial; + + zwp_tablet_tool_v2_send_proximity_in(tool_client->resource, serial, + tablet_client->resource, surface->resource); + queue_tool_frame(tool_client); + + return serial; +} + +void wlr_send_tablet_v2_tablet_tool_motion( + struct wlr_tablet_v2_tablet_tool *tool, double x, double y) { + if (!tool->current_client) { + return; + } + + zwp_tablet_tool_v2_send_motion(tool->current_client->resource, + wl_fixed_from_double(x), wl_fixed_from_double(y)); + + queue_tool_frame(tool->current_client); +} + +void wlr_send_tablet_v2_tablet_tool_proximity_out( + struct wlr_tablet_v2_tablet_tool *tool) { + if (tool->current_client) { + zwp_tablet_tool_v2_send_proximity_out(tool->current_client->resource); + // XXX: Get the time for the frame + if (tool->current_client->frame_source) { + wl_event_source_remove(tool->current_client->frame_source); + send_tool_frame(tool->current_client); + } + } +} + + +uint32_t wlr_send_tablet_v2_tablet_pad_enter( + struct wlr_tablet_v2_tablet_pad *pad, + struct wlr_tablet_v2_tablet *tablet, + struct wlr_surface *surface) { + struct wl_client *client = wl_resource_get_client(surface->resource); + + struct wlr_tablet_client_v2 *tablet_tmp; + struct wlr_tablet_client_v2 *tablet_client = NULL; + wl_list_for_each(tablet_tmp, &tablet->clients, tablet_link) { + if (tablet_tmp->client == client) { + tablet_client = tablet_tmp; + break; + } + } + + // Couldn't find the client binding for the surface's client. Either + // the client didn't bind tablet_v2 at all, or not for the relevant + // seat + if (!tablet_client) { + return 0; + } + + struct wlr_tablet_pad_client_v2 *pad_tmp; + struct wlr_tablet_pad_client_v2 *pad_client; + wl_list_for_each(pad_tmp, &pad->clients, pad_link) { + if (pad_tmp->client == client) { + pad_client = pad_tmp; + break; + } + } + + // Couldn't find the client binding for the surface's client. Either + // the client didn't bind tablet_v2 at all, or not for the relevant + // seat + if (!pad_client) { + return 0; + } + + pad->current_client = pad_client; + + /* Pre-increment keeps 0 clean. wraparound would be after 2^32 + * proximity_in. Someone wants to do the math how long that would take? + */ + uint32_t serial = ++pad_client->enter_serial; + + zwp_tablet_pad_v2_send_enter(pad_client->resource, serial, + tablet_client->resource, surface->resource); + + struct timespec now; + clock_gettime(CLOCK_MONOTONIC, &now); + uint32_t time = now.tv_nsec / 1000; + + for (size_t i = 0; i < pad->group_count; ++i) { + zwp_tablet_pad_group_v2_send_mode_switch( + pad_client->groups[i], time, serial, pad->groups[i]); + } + + return serial; +} + +void wlr_send_tablet_v2_tablet_pad_button( + struct wlr_tablet_v2_tablet_pad *pad, size_t button, + uint32_t time, enum zwp_tablet_pad_v2_button_state state) { + + if (pad->current_client) { + zwp_tablet_pad_v2_send_button(pad->current_client->resource, + time, button, state); + } +} + +void wlr_send_tablet_v2_tablet_pad_strip(struct wlr_tablet_v2_tablet_pad *pad, + uint32_t strip, double position, bool finger, uint32_t time) { + if (!pad->current_client && + pad->current_client->strips && + pad->current_client->strips[strip]) { + return; + } + struct wl_resource *resource = pad->current_client->strips[strip]; + + if (finger) { + zwp_tablet_pad_strip_v2_send_source(resource, ZWP_TABLET_PAD_STRIP_V2_SOURCE_FINGER); + } + + if (position < 0) { + zwp_tablet_pad_strip_v2_send_stop(resource); + } else { + zwp_tablet_pad_strip_v2_send_position(resource, position * 65535); + } + zwp_tablet_pad_strip_v2_send_frame(resource, time); +} + +void wlr_send_tablet_v2_tablet_pad_ring(struct wlr_tablet_v2_tablet_pad *pad, + uint32_t ring, double position, bool finger, uint32_t time) { + if (!pad->current_client || + !pad->current_client->rings || + !pad->current_client->rings[ring]) { + return; + } + struct wl_resource *resource = pad->current_client->rings[ring]; + + if (finger) { + zwp_tablet_pad_ring_v2_send_source(resource, ZWP_TABLET_PAD_RING_V2_SOURCE_FINGER); + } + + if (position < 0) { + zwp_tablet_pad_ring_v2_send_stop(resource); + } else { + zwp_tablet_pad_ring_v2_send_angle(resource, position); + } + zwp_tablet_pad_ring_v2_send_frame(resource, time); +} + +uint32_t wlr_send_tablet_v2_tablet_pad_leave(struct wlr_tablet_v2_tablet_pad *pad, + struct wlr_surface *surface) { + if (!pad->current_client || + wl_resource_get_client(surface->resource) != pad->current_client->client) { + return 0; + } + + /* Pre-increment keeps 0 clean. wraparound would be after 2^32 + * proximity_in. Someone wants to do the math how long that would take? + */ + uint32_t serial = ++pad->current_client->leave_serial; + + zwp_tablet_pad_v2_send_leave(pad->current_client->resource, serial, surface->resource); + return serial; +} + +uint32_t wlr_send_tablet_v2_tablet_pad_mode(struct wlr_tablet_v2_tablet_pad *pad, + size_t group, uint32_t mode, uint32_t time) { + if (!pad->current_client || + !pad->current_client->groups || + !pad->current_client->groups[group] ) { + return 0; + } + + if (pad->groups[group] == mode) { + return 0; + } + + pad->groups[group] = mode; + + /* Pre-increment keeps 0 clean. wraparound would be after 2^32 + * proximity_in. Someone wants to do the math how long that would take? + */ + uint32_t serial = ++pad->current_client->mode_serial; + + zwp_tablet_pad_group_v2_send_mode_switch( + pad->current_client->groups[group], time, serial, mode); + return serial; +} -- cgit v1.2.3 From 599f84f736ef617374660c82acf52bff0e95c566 Mon Sep 17 00:00:00 2001 From: Markus Ongyerth Date: Fri, 4 May 2018 16:40:41 +0200 Subject: Fix borked rebase --- backend/libinput/tablet_pad.c | 2 +- backend/libinput/tablet_tool.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'backend/libinput/tablet_pad.c') diff --git a/backend/libinput/tablet_pad.c b/backend/libinput/tablet_pad.c index 7c196bf1..bb65adf6 100644 --- a/backend/libinput/tablet_pad.c +++ b/backend/libinput/tablet_pad.c @@ -79,7 +79,7 @@ static void add_pad_group_from_libinput(struct wlr_tablet_pad *pad, wl_list_insert(&pad->groups, &group->link); } -struct wlr_tablet_pad *libinput_tablet_pad_create( +struct wlr_tablet_pad *create_libinput_tablet_pad( struct libinput_device *libinput_dev) { assert(libinput_dev); struct wlr_tablet_pad *wlr_tablet_pad = calloc(1, sizeof(struct wlr_tablet_pad)); diff --git a/backend/libinput/tablet_tool.c b/backend/libinput/tablet_tool.c index 3a39f5dc..a20637c1 100644 --- a/backend/libinput/tablet_tool.c +++ b/backend/libinput/tablet_tool.c @@ -74,7 +74,7 @@ void wlr_libinput_tablet_tool_destroy(struct wlr_input_device *wlr_dev) { } } -struct wlr_tablet_tool *libinput_tablet_tool_create( +struct wlr_tablet_tool *create_libinput_tablet_tool( struct libinput_device *libinput_dev) { assert(libinput_dev); struct wlr_libinput_tablet *libinput_tablet_tool = -- cgit v1.2.3 From 31cec36b741d3c645c18c4e7e8dedbd6c6e3ece5 Mon Sep 17 00:00:00 2001 From: Markus Ongyerth Date: Tue, 15 May 2018 15:41:32 +0200 Subject: 1st feedback pass Rename make_ functions to _create Implement set_cursor and set_feedback --- backend/libinput/tablet_pad.c | 6 +- backend/libinput/tablet_tool.c | 4 +- include/wlr/types/wlr_tablet_v2.h | 29 ++++++- rootston/seat.c | 13 ++-- types/wlr_tablet_v2.c | 154 +++++++++++++++++++++++++++++++------- 5 files changed, 166 insertions(+), 40 deletions(-) (limited to 'backend/libinput/tablet_pad.c') diff --git a/backend/libinput/tablet_pad.c b/backend/libinput/tablet_pad.c index bb65adf6..f1fb6d7a 100644 --- a/backend/libinput/tablet_pad.c +++ b/backend/libinput/tablet_pad.c @@ -21,7 +21,11 @@ static void add_tablet_path(struct wl_list *list, const char *path) { } tablet_path->path = strdup(path); - assert(tablet_path->path); + if (!tablet_path->path) { + free(tablet_path); + return; + } + wl_list_insert(list, &tablet_path->link); } diff --git a/backend/libinput/tablet_tool.c b/backend/libinput/tablet_tool.c index a20637c1..f02e045a 100644 --- a/backend/libinput/tablet_tool.c +++ b/backend/libinput/tablet_tool.c @@ -79,11 +79,11 @@ struct wlr_tablet_tool *create_libinput_tablet_tool( assert(libinput_dev); struct wlr_libinput_tablet *libinput_tablet_tool = calloc(1, sizeof(struct wlr_libinput_tablet)); - struct wlr_tablet_tool *wlr_tablet_tool = &libinput_tablet_tool->wlr_tool; - if (!wlr_tablet_tool) { + if (!libinput_tablet_tool) { wlr_log(WLR_ERROR, "Unable to allocate wlr_tablet_tool"); return NULL; } + struct wlr_tablet_tool *wlr_tablet_tool = &libinput_tablet_tool->wlr_tool; wl_list_init(&wlr_tablet_tool->paths); struct udev_device *udev = libinput_device_get_udev_device(libinput_dev); diff --git a/include/wlr/types/wlr_tablet_v2.h b/include/wlr/types/wlr_tablet_v2.h index 12995308..0be672cb 100644 --- a/include/wlr/types/wlr_tablet_v2.h +++ b/include/wlr/types/wlr_tablet_v2.h @@ -50,6 +50,10 @@ struct wlr_tablet_v2_tablet_tool { uint32_t button_serial; size_t num_buttons; uint32_t pressed_buttons[WLR_TABLEt_V2_TOOL_BUTTONS_CAP]; + + struct { + struct wl_signal set_cursor; // struct wlr_tablet_v2_event_cursor + } events; }; struct wlr_tablet_v2_tablet_pad { @@ -64,19 +68,38 @@ struct wlr_tablet_v2_tablet_pad { struct wl_listener pad_destroy; struct wlr_tablet_pad_client_v2 *current_client; + + struct { + struct wl_signal button_feedback; // struct wlr_tablet_v2_event_feedback + struct wl_signal strip_feedback; // struct wlr_tablet_v2_event_feedback + struct wl_signal ring_feedback; // struct wlr_tablet_v2_event_feedback + } events; +}; + +struct wlr_tablet_v2_event_cursor { + struct wlr_surface *surface; + uint32_t serial; + int32_t hotspot_x; + int32_t hotspot_y; +}; + +struct wlr_tablet_v2_event_feedback { + const char *description; + size_t index; + uint32_t serial; }; -struct wlr_tablet_v2_tablet *wlr_make_tablet( +struct wlr_tablet_v2_tablet *wlr_tablet_create( struct wlr_tablet_manager_v2 *manager, struct wlr_seat *wlr_seat, struct wlr_input_device *wlr_device); -struct wlr_tablet_v2_tablet_pad *wlr_make_tablet_pad( +struct wlr_tablet_v2_tablet_pad *wlr_tablet_pad_create( struct wlr_tablet_manager_v2 *manager, struct wlr_seat *wlr_seat, struct wlr_input_device *wlr_device); -struct wlr_tablet_v2_tablet_tool *wlr_make_tablet_tool( +struct wlr_tablet_v2_tablet_tool *wlr_tablet_tool_create( struct wlr_tablet_manager_v2 *manager, struct wlr_seat *wlr_seat, struct wlr_tablet_tool_tool *wlr_tool); diff --git a/rootston/seat.c b/rootston/seat.c index b7bf28fc..6b12f682 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -148,7 +148,7 @@ static void handle_tool_axis(struct wl_listener *listener, void *data) { struct roots_tablet_tool_tool *roots_tool = event->tool->data; if (!roots_tool) { // Should this be an assert? - wlr_log(L_DEBUG, "Tool Axis, before proximity"); + wlr_log(WLR_DEBUG, "Tool Axis, before proximity"); return; } @@ -217,7 +217,8 @@ static void handle_tool_proximity(struct wl_listener *listener, void *data) { roots_tool->seat = cursor->seat; tool->data = roots_tool; roots_tool->tablet_v2_tool = - wlr_make_tablet_tool(desktop->tablet_v2, cursor->seat->seat, tool); + wlr_tablet_tool_create(desktop->tablet_v2, + cursor->seat->seat, tool); roots_tool->tool_destroy.notify = handle_tablet_tool_tool_destroy; wl_signal_add(&tool->events.destroy, &roots_tool->tool_destroy); wl_list_init(&roots_tool->link); @@ -683,7 +684,7 @@ static void handle_pad_tool_destroy(struct wl_listener *listener, void *data) { static void attach_tablet_pad(struct roots_tablet_pad *pad, struct roots_tablet_tool *tool) { - wlr_log(L_DEBUG, "Attaching tablet pad \"%s\" to tablet tool \"%s\"", + wlr_log(WLR_DEBUG, "Attaching tablet pad \"%s\" to tablet tool \"%s\"", pad->device->name, tool->device->name); pad->tablet = tool; @@ -742,7 +743,7 @@ static void seat_add_tablet_pad(struct roots_seat *seat, struct roots_tablet_pad *tablet_pad = calloc(sizeof(struct roots_tablet_pad), 1); if (!tablet_pad) { - wlr_log(L_ERROR, "could not allocate tablet_pad for seat"); + wlr_log(WLR_ERROR, "could not allocate tablet_pad for seat"); return; } @@ -772,7 +773,7 @@ static void seat_add_tablet_pad(struct roots_seat *seat, struct roots_desktop *desktop = seat->input->server->desktop; tablet_pad->tablet_v2_pad = - wlr_make_tablet_pad(desktop->tablet_v2, seat->seat, device); + wlr_tablet_pad_create(desktop->tablet_v2, seat->seat, device); /* Search for a sibling tablet */ if (!wlr_input_device_is_libinput(device)) { @@ -837,7 +838,7 @@ static void seat_add_tablet_tool(struct roots_seat *seat, struct roots_desktop *desktop = seat->input->server->desktop; tablet_tool->tablet_v2 = - wlr_make_tablet(desktop->tablet_v2, seat->seat, device); + wlr_tablet_create(desktop->tablet_v2, seat->seat, device); struct libinput_device_group *group = libinput_device_get_device_group(wlr_libinput_get_device_handle(device)); diff --git a/types/wlr_tablet_v2.c b/types/wlr_tablet_v2.c index 104de65f..e05e85f3 100644 --- a/types/wlr_tablet_v2.c +++ b/types/wlr_tablet_v2.c @@ -2,18 +2,16 @@ #define _POSIX_C_SOURCE 200809L #endif -#include - -#include #include #include -#include #include +#include #include #include #include #include - +#include +#include #include "tablet-unstable-v2-protocol.h" struct wlr_tablet_seat_v2 { @@ -68,6 +66,7 @@ struct wlr_tablet_tool_client_v2 { struct wl_list tool_link; struct wl_client *client; struct wl_resource *resource; + struct wlr_tablet_v2_tablet_tool *tool; uint32_t proximity_serial; @@ -79,6 +78,7 @@ struct wlr_tablet_pad_client_v2 { struct wl_list pad_link; struct wl_client *client; struct wl_resource *resource; + struct wlr_tablet_v2_tablet_pad *pad; uint32_t enter_serial; uint32_t mode_serial; @@ -96,6 +96,11 @@ struct wlr_tablet_pad_client_v2 { struct wl_resource **strips; }; +struct tablet_pad_auxiliary_user_data { + struct wlr_tablet_pad_client_v2 *pad; + size_t index; +}; + static struct zwp_tablet_v2_interface tablet_impl; static struct wlr_tablet_client_v2 *tablet_client_from_resource(struct wl_resource *resource) { @@ -257,12 +262,35 @@ static void handle_wlr_tablet_destroy(struct wl_listener *listener, void *data) free(tablet); } +static void handle_tablet_tool_v2_set_cursor(struct wl_client *client, + struct wl_resource *resource, + uint32_t serial, + struct wl_resource *surface_resource, + int32_t hotspot_x, + int32_t hotspot_y) { + struct wlr_tablet_tool_client_v2 *tool = wl_resource_get_user_data(resource); + if (!tool) { + return; + } + + struct wlr_surface *surface = wlr_surface_from_resource(surface_resource); + + struct wlr_tablet_v2_event_cursor evt = { + .surface = surface, + .serial = serial, + .hotspot_x = hotspot_x, + .hotspot_y = hotspot_y, + }; + + wl_signal_emit(&tool->tool->events.set_cursor, &evt); +} + static void handle_tablet_tool_v2_destroy(struct wl_client *client, struct wl_resource *resource) { wl_resource_destroy(resource); } static struct zwp_tablet_tool_v2_interface tablet_tool_impl = { - .set_cursor = NULL, + .set_cursor = handle_tablet_tool_v2_set_cursor, .destroy = handle_tablet_tool_v2_destroy, }; @@ -308,6 +336,7 @@ static void add_tablet_tool_client(struct wlr_tablet_seat_client_v2 *seat, if (!client) { return; } + client->tool = tool; client->resource = wl_resource_create(seat->wl_client, &zwp_tablet_tool_v2_interface, 1, 0); @@ -372,7 +401,7 @@ static void add_tablet_tool_client(struct wlr_tablet_seat_client_v2 *seat, wl_list_insert(&tool->clients, &client->tool_link); } -struct wlr_tablet_v2_tablet *wlr_make_tablet( +struct wlr_tablet_v2_tablet *wlr_tablet_create( struct wlr_tablet_manager_v2 *manager, struct wlr_seat *wlr_seat, struct wlr_input_device *wlr_device) { @@ -420,10 +449,11 @@ static void handle_wlr_tablet_tool_destroy(struct wl_listener *listener, void *d wl_list_remove(&tool->clients); wl_list_remove(&tool->link); wl_list_remove(&tool->tool_destroy.link); + wl_list_remove(&tool->events.set_cursor.listener_list); free(tool); } -struct wlr_tablet_v2_tablet_tool *wlr_make_tablet_tool( +struct wlr_tablet_v2_tablet_tool *wlr_tablet_tool_create( struct wlr_tablet_manager_v2 *manager, struct wlr_seat *wlr_seat, struct wlr_tablet_tool_tool *wlr_tool) { @@ -452,6 +482,8 @@ struct wlr_tablet_v2_tablet_tool *wlr_make_tablet_tool( add_tablet_tool_client(pos, tool); } + wl_signal_init(&tool->events.set_cursor); + return tool; } @@ -506,14 +538,30 @@ static void handle_tablet_pad_v2_destroy(struct wl_client *client, } static void destroy_tablet_pad_ring_v2(struct wl_resource *resource) { - struct wlr_tablet_pad_client_v2 *client = wl_resource_get_user_data(resource); + struct tablet_pad_auxiliary_user_data *aux = wl_resource_get_user_data(resource); - for (size_t i = 0; i < client->ring_count; ++i) { - if (client->rings[i] == resource) { - client->rings[i] = NULL; - return; - } + if (!aux) { + return; } + + aux->pad->rings[aux->index] = NULL; + free(aux); +} +static void handle_tablet_pad_ring_v2_set_feedback(struct wl_client *client, + struct wl_resource *resource, const char *description, + uint32_t serial) { + struct tablet_pad_auxiliary_user_data *aux = wl_resource_get_user_data(resource); + if (!aux) { + return; + } + + struct wlr_tablet_v2_event_feedback evt = { + .serial = serial, + .description = description, + .index = aux->index + }; + + wl_signal_emit(&aux->pad->pad->events.ring_feedback, &evt); } static void handle_tablet_pad_ring_v2_destroy(struct wl_client *client, @@ -522,19 +570,35 @@ static void handle_tablet_pad_ring_v2_destroy(struct wl_client *client, } static struct zwp_tablet_pad_ring_v2_interface tablet_pad_ring_impl = { - .set_feedback = NULL, + .set_feedback = handle_tablet_pad_ring_v2_set_feedback, .destroy = handle_tablet_pad_ring_v2_destroy, }; static void destroy_tablet_pad_strip_v2(struct wl_resource *resource) { - struct wlr_tablet_pad_client_v2 *client = wl_resource_get_user_data(resource); + struct tablet_pad_auxiliary_user_data *aux = wl_resource_get_user_data(resource); + if (!aux) { + return; + } - for (size_t i = 0; i < client->strip_count; ++i) { - if (client->strips[i] == resource) { - client->strips[i] = NULL; - return; - } + aux->pad->strips[aux->index] = NULL; + free(aux); +} + +static void handle_tablet_pad_strip_v2_set_feedback(struct wl_client *client, + struct wl_resource *resource, const char *description, + uint32_t serial) { + struct tablet_pad_auxiliary_user_data *aux = wl_resource_get_user_data(resource); + if (!aux) { + return; } + + struct wlr_tablet_v2_event_feedback evt = { + .serial = serial, + .description = description, + .index = aux->index + }; + + wl_signal_emit(&aux->pad->pad->events.strip_feedback, &evt); } static void handle_tablet_pad_strip_v2_destroy(struct wl_client *client, @@ -543,12 +607,26 @@ static void handle_tablet_pad_strip_v2_destroy(struct wl_client *client, } static struct zwp_tablet_pad_strip_v2_interface tablet_pad_strip_impl = { - .set_feedback = NULL, + .set_feedback = handle_tablet_pad_strip_v2_set_feedback, .destroy = handle_tablet_pad_strip_v2_destroy, }; +static void handle_tablet_pad_v2_set_feedback( struct wl_client *client, + struct wl_resource *resource, uint32_t button, + const char *description, uint32_t serial) { + struct wlr_tablet_v2_tablet_pad *pad = wl_resource_get_user_data(resource); + + struct wlr_tablet_v2_event_feedback evt = { + .serial = serial, + .index = button, + .description = description, + }; + + wl_signal_emit(&pad->events.button_feedback, &evt); +} + static struct zwp_tablet_pad_v2_interface tablet_pad_impl = { - .set_feedback = NULL, + .set_feedback = handle_tablet_pad_v2_set_feedback, .destroy = handle_tablet_pad_v2_destroy, }; @@ -597,22 +675,34 @@ static void add_tablet_pad_group(struct wlr_tablet_v2_tablet_pad *pad, client->strip_count = group->strip_count; for (size_t i = 0; i < group->strip_count; ++i) { size_t strip = group->strips[i]; + struct tablet_pad_auxiliary_user_data *user_data = + calloc(1, sizeof(struct tablet_pad_auxiliary_user_data)); + if (!user_data) { + continue; + } + user_data->pad = client; + user_data->index = strip; client->strips[strip] = wl_resource_create(client->client, &zwp_tablet_pad_strip_v2_interface, 1, 0); wl_resource_set_implementation(client->strips[strip], - &tablet_pad_strip_impl, - client, destroy_tablet_pad_strip_v2); + &tablet_pad_strip_impl, user_data, destroy_tablet_pad_strip_v2); zwp_tablet_pad_group_v2_send_strip(client->groups[index], client->strips[strip]); } client->ring_count = group->ring_count; for (size_t i = 0; i < group->ring_count; ++i) { size_t ring = group->rings[i]; + struct tablet_pad_auxiliary_user_data *user_data = + calloc(1, sizeof(struct tablet_pad_auxiliary_user_data)); + if (!user_data) { + continue; + } + user_data->pad = client; + user_data->index = ring; client->rings[ring] = wl_resource_create(client->client, &zwp_tablet_pad_ring_v2_interface, 1, 0); wl_resource_set_implementation(client->rings[ring], - &tablet_pad_ring_impl, - client, destroy_tablet_pad_ring_v2); + &tablet_pad_ring_impl, user_data, destroy_tablet_pad_ring_v2); zwp_tablet_pad_group_v2_send_ring(client->groups[index], client->rings[ring]); } @@ -627,6 +717,7 @@ static void add_tablet_pad_client(struct wlr_tablet_seat_client_v2 *seat, wl_client_post_no_memory(seat->wl_client); return; } + client->pad = pad; client->groups = calloc(sizeof(int), wl_list_length(&pad->wlr_pad->groups)); if (!client->groups) { @@ -700,10 +791,13 @@ static void handle_wlr_tablet_pad_destroy(struct wl_listener *listener, void *da wl_list_remove(&pad->clients); wl_list_remove(&pad->link); wl_list_remove(&pad->pad_destroy.link); + wl_list_remove(&pad->events.button_feedback.listener_list); + wl_list_remove(&pad->events.strip_feedback.listener_list); + wl_list_remove(&pad->events.ring_feedback.listener_list); free(pad); } -struct wlr_tablet_v2_tablet_pad *wlr_make_tablet_pad( +struct wlr_tablet_v2_tablet_pad *wlr_tablet_pad_create( struct wlr_tablet_manager_v2 *manager, struct wlr_seat *wlr_seat, struct wlr_input_device *wlr_device) { @@ -739,6 +833,10 @@ struct wlr_tablet_v2_tablet_pad *wlr_make_tablet_pad( add_tablet_pad_client(pos, pad); } + wl_signal_init(&pad->events.button_feedback); + wl_signal_init(&pad->events.strip_feedback); + wl_signal_init(&pad->events.ring_feedback); + return pad; } -- cgit v1.2.3 From 0c9a26828a764ec2648fa1f72178d5df4dd7b36b Mon Sep 17 00:00:00 2001 From: Markus Ongyerth Date: Tue, 15 May 2018 16:16:19 +0200 Subject: Use wlr_list for paths, and improve inert resource handling --- backend/libinput/tablet_pad.c | 21 ++-------------- backend/libinput/tablet_tool.c | 16 ++----------- include/wlr/types/wlr_tablet_pad.h | 3 ++- include/wlr/types/wlr_tablet_tool.h | 8 ++----- types/wlr_tablet_pad.c | 9 ++++++- types/wlr_tablet_tool.c | 4 ++++ types/wlr_tablet_v2.c | 48 +++++++++++++++++++++++++++---------- 7 files changed, 55 insertions(+), 54 deletions(-) (limited to 'backend/libinput/tablet_pad.c') diff --git a/backend/libinput/tablet_pad.c b/backend/libinput/tablet_pad.c index f1fb6d7a..579a11cf 100644 --- a/backend/libinput/tablet_pad.c +++ b/backend/libinput/tablet_pad.c @@ -12,23 +12,6 @@ #include "backend/libinput.h" #include "util/signal.h" -//TODO: Move out -static void add_tablet_path(struct wl_list *list, const char *path) { - struct wlr_tablet_path *tablet_path = calloc(1, sizeof(struct wlr_tablet_path)); - - if (!tablet_path) { - return; - } - - tablet_path->path = strdup(path); - if (!tablet_path->path) { - free(tablet_path); - return; - } - - wl_list_insert(list, &tablet_path->link); -} - // FIXME: Decide on how to alloc/count here static void add_pad_group_from_libinput(struct wlr_tablet_pad *pad, struct libinput_device *device, unsigned int index) { @@ -99,9 +82,9 @@ struct wlr_tablet_pad *create_libinput_tablet_pad( wlr_tablet_pad->strip_count = libinput_device_tablet_pad_get_num_strips(libinput_dev); - wl_list_init(&wlr_tablet_pad->paths); + wlr_list_init(&wlr_tablet_pad->paths); struct udev_device *udev = libinput_device_get_udev_device(libinput_dev); - add_tablet_path(&wlr_tablet_pad->paths, udev_device_get_syspath(udev)); + wlr_list_push(&wlr_tablet_pad->paths, strdup(udev_device_get_syspath(udev))); wl_list_init(&wlr_tablet_pad->groups); int groups = libinput_device_tablet_pad_get_num_mode_groups(libinput_dev); diff --git a/backend/libinput/tablet_tool.c b/backend/libinput/tablet_tool.c index 7cecb091..5dc0584c 100644 --- a/backend/libinput/tablet_tool.c +++ b/backend/libinput/tablet_tool.c @@ -13,18 +13,6 @@ #include "backend/libinput.h" #include "util/signal.h" -//TODO: Move out -static void add_tablet_path(struct wl_list *list, const char *path) { - struct wlr_tablet_path *tablet_path = calloc(1, sizeof(struct wlr_tablet_path)); - - if (!tablet_path) { - return; - } - - tablet_path->path = strdup(path); - wl_list_insert(list, &tablet_path->link); -} - struct wlr_libinput_tablet_tool { struct wlr_tablet_tool_tool wlr_tool; @@ -91,9 +79,9 @@ struct wlr_tablet_tool *create_libinput_tablet_tool( } struct wlr_tablet_tool *wlr_tablet_tool = &libinput_tablet_tool->wlr_tool; - wl_list_init(&wlr_tablet_tool->paths); + wlr_list_init(&wlr_tablet_tool->paths); struct udev_device *udev = libinput_device_get_udev_device(libinput_dev); - add_tablet_path(&wlr_tablet_tool->paths, udev_device_get_syspath(udev)); + wlr_list_push(&wlr_tablet_tool->paths, strdup(udev_device_get_syspath(udev))); wlr_tablet_tool->name = strdup(libinput_device_get_name(libinput_dev)); wl_list_init(&libinput_tablet_tool->tools); diff --git a/include/wlr/types/wlr_tablet_pad.h b/include/wlr/types/wlr_tablet_pad.h index ec291c75..23ac464d 100644 --- a/include/wlr/types/wlr_tablet_pad.h +++ b/include/wlr/types/wlr_tablet_pad.h @@ -4,6 +4,7 @@ #include #include #include +#include /* * NOTE: the wlr tablet pad implementation does not currently support tablets @@ -28,7 +29,7 @@ struct wlr_tablet_pad { size_t strip_count; struct wl_list groups; // wlr_tablet_pad_group::link - struct wl_list paths; // wlr_tablet_path::link + struct wlr_list paths; // char * void *data; }; diff --git a/include/wlr/types/wlr_tablet_tool.h b/include/wlr/types/wlr_tablet_tool.h index 114ce98a..71fa0f82 100644 --- a/include/wlr/types/wlr_tablet_tool.h +++ b/include/wlr/types/wlr_tablet_tool.h @@ -4,6 +4,7 @@ #include #include #include +#include /* * Copy+Paste from libinput, but this should neither use libinput, nor @@ -42,11 +43,6 @@ struct wlr_tablet_tool_tool { struct wlr_tablet_tool_impl; -struct wlr_tablet_path { - struct wl_list link; - char *path; -}; - struct wlr_tablet_tool { struct wlr_tablet_tool_impl *impl; @@ -58,7 +54,7 @@ struct wlr_tablet_tool { } events; const char *name; - struct wl_list paths; // wlr_table_path::link + struct wlr_list paths; // char * void *data; }; diff --git a/types/wlr_tablet_pad.c b/types/wlr_tablet_pad.c index f7d6c436..804d6910 100644 --- a/types/wlr_tablet_pad.c +++ b/types/wlr_tablet_pad.c @@ -14,7 +14,14 @@ void wlr_tablet_pad_init(struct wlr_tablet_pad *pad, } void wlr_tablet_pad_destroy(struct wlr_tablet_pad *pad) { - if (pad && pad->impl && pad->impl->destroy) { + if (!pad) { + return; + } + + wlr_list_for_each(&pad->paths, free); + wlr_list_finish(&pad->paths); + + if (pad->impl && pad->impl->destroy) { pad->impl->destroy(pad); } else { free(pad); diff --git a/types/wlr_tablet_tool.c b/types/wlr_tablet_tool.c index f46a5434..85a13832 100644 --- a/types/wlr_tablet_tool.c +++ b/types/wlr_tablet_tool.c @@ -17,6 +17,10 @@ void wlr_tablet_tool_destroy(struct wlr_tablet_tool *tool) { if (!tool) { return; } + + wlr_list_for_each(&tool->paths, free); + wlr_list_finish(&tool->paths); + if (tool->impl && tool->impl->destroy) { tool->impl->destroy(tool); } else { diff --git a/types/wlr_tablet_v2.c b/types/wlr_tablet_v2.c index e05e85f3..52089c47 100644 --- a/types/wlr_tablet_v2.c +++ b/types/wlr_tablet_v2.c @@ -234,9 +234,9 @@ static void add_tablet_client(struct wlr_tablet_seat_client_v2 *seat, } zwp_tablet_v2_send_id(client->resource, tablet->wlr_device->vendor, tablet->wlr_device->product); - struct wlr_tablet_path *path; - wl_list_for_each(path, &tablet->wlr_tool->paths, link) { - zwp_tablet_v2_send_path(client->resource, path->path); + for (size_t i = 0; i < tablet->wlr_tool->paths.length; ++i) { + zwp_tablet_v2_send_path(client->resource, + tablet->wlr_tool->paths.items[i]); } zwp_tablet_v2_send_done(client->resource); @@ -546,6 +546,7 @@ static void destroy_tablet_pad_ring_v2(struct wl_resource *resource) { aux->pad->rings[aux->index] = NULL; free(aux); + wl_resource_set_user_data(resource, NULL); } static void handle_tablet_pad_ring_v2_set_feedback(struct wl_client *client, struct wl_resource *resource, const char *description, @@ -582,6 +583,7 @@ static void destroy_tablet_pad_strip_v2(struct wl_resource *resource) { aux->pad->strips[aux->index] = NULL; free(aux); + wl_resource_set_user_data(resource, NULL); } static void handle_tablet_pad_strip_v2_set_feedback(struct wl_client *client, @@ -631,14 +633,15 @@ static struct zwp_tablet_pad_v2_interface tablet_pad_impl = { }; static void destroy_tablet_pad_group_v2(struct wl_resource *resource) { - struct wlr_tablet_pad_client_v2 *client = wl_resource_get_user_data(resource); + struct tablet_pad_auxiliary_user_data *aux = wl_resource_get_user_data(resource); - for (size_t i = 0; i < client->group_count; ++i) { - if (client->groups[i] == resource) { - client->groups[i] = NULL; - return; - } + if (!aux) { + return; } + + aux->pad->groups[aux->index] = NULL; + free(aux); + wl_resource_set_user_data(resource, NULL); } static void handle_tablet_pad_group_v2_destroy(struct wl_client *client, @@ -659,8 +662,15 @@ static void add_tablet_pad_group(struct wlr_tablet_v2_tablet_pad *pad, wl_client_post_no_memory(client->client); return; } + struct tablet_pad_auxiliary_user_data *user_data = + calloc(1, sizeof(struct tablet_pad_auxiliary_user_data)); + if (!user_data) { + return; + } + user_data->pad = client; + user_data->index = index; wl_resource_set_implementation(client->groups[index], &tablet_pad_group_impl, - client, destroy_tablet_pad_group_v2); + user_data, destroy_tablet_pad_group_v2); zwp_tablet_pad_v2_send_group(client->resource, client->groups[index]); zwp_tablet_pad_group_v2_send_modes(client->groups[index], group->mode_count); @@ -762,9 +772,9 @@ static void add_tablet_pad_client(struct wlr_tablet_seat_client_v2 *seat, if (pad->wlr_pad->button_count) { zwp_tablet_pad_v2_send_buttons(client->resource, pad->wlr_pad->button_count); } - struct wlr_tablet_path *path; - wl_list_for_each(path, &pad->wlr_pad->paths, link) { - zwp_tablet_pad_v2_send_path(client->resource, path->path); + for (size_t i = 0; i < pad->wlr_pad->paths.length; ++i) { + zwp_tablet_pad_v2_send_path(client->resource, + pad->wlr_pad->paths.items[i]); } size_t i = 0; struct wlr_tablet_pad_group *group; @@ -786,6 +796,18 @@ static void handle_wlr_tablet_pad_destroy(struct wl_listener *listener, void *da wl_list_for_each_safe(pos, tmp, &pad->clients, pad_link) { // XXX: Add a timer/flag to destroy if client is slow? zwp_tablet_pad_v2_send_removed(pos->resource); + + for (size_t i = 0; i < pos->group_count; ++i) { + destroy_tablet_pad_group_v2(pos->groups[i]); + } + + for (size_t i = 0; i < pos->strip_count; ++i) { + destroy_tablet_pad_strip_v2(pos->strips[i]); + } + + for (size_t i = 0; i < pos->ring_count; ++i) { + destroy_tablet_pad_ring_v2(pos->rings[i]); + } } wl_list_remove(&pad->clients); -- cgit v1.2.3