From bf8751d632c32d5d564bd8cae163199b4db54869 Mon Sep 17 00:00:00 2001 From: Markus Ongyerth Date: Wed, 11 Apr 2018 16:17:28 +0200 Subject: Start tablet protocol --- protocol/meson.build | 1 + types/meson.build | 1 + types/wlr_tablet_v2.c | 218 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 220 insertions(+) create mode 100644 types/wlr_tablet_v2.c diff --git a/protocol/meson.build b/protocol/meson.build index 5ab82d84..b7a6e80a 100644 --- a/protocol/meson.build +++ b/protocol/meson.build @@ -33,6 +33,7 @@ protocols = [ [wl_protocol_dir, 'unstable/linux-dmabuf/linux-dmabuf-unstable-v1.xml'], [wl_protocol_dir, 'unstable/xdg-shell/xdg-shell-unstable-v6.xml'], [wl_protocol_dir, 'unstable/xdg-output/xdg-output-unstable-v1.xml'], + [wl_protocol_dir, 'unstable/tablet/tablet-unstable-v2.xml'], 'gamma-control.xml', 'gtk-primary-selection.xml', 'idle.xml', diff --git a/types/meson.build b/types/meson.build index 49f87bf8..a571dffd 100644 --- a/types/meson.build +++ b/types/meson.build @@ -43,6 +43,7 @@ lib_wlr_types = static_library( 'wlr_screenshooter.c', 'wlr_server_decoration.c', 'wlr_surface.c', + 'wlr_tablet_v2.c', 'wlr_tablet_pad.c', 'wlr_tablet_tool.c', 'wlr_touch.c', diff --git a/types/wlr_tablet_v2.c b/types/wlr_tablet_v2.c new file mode 100644 index 00000000..09e0ef35 --- /dev/null +++ b/types/wlr_tablet_v2.c @@ -0,0 +1,218 @@ +#ifndef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 200809L +#endif + +#include +#include +#include +#include +#include + +#include "tablet-unstable-v2-protocol.h" + + +struct wlr_tablet_manager_v2 { + struct wl_global *wl_global; + struct wl_list clients; // wlr_tablet_client_v2::link + + struct wl_listener display_destroy; + + void *data; +}; + +struct wlr_tablet_client_v2 { + struct wl_list link; + struct wl_client *client; + struct wl_resource *resource; + + struct wlr_tablet_manager_v2 *manager; + + struct wl_list tablet_seats; // wlr_tablet_seat_v2::link +}; + +struct wlr_tablet_seat_v2 { + struct wl_list link; + struct wl_resource *resource; + + struct wlr_tablet_client_v2 *client; + struct wlr_seat_client *seat; + + struct wl_listener seat_destroy; + + struct wl_list tools; +}; + +struct wlr_tablet_v2 { + struct wl_list link; + struct wl_resource *resource; +}; + +void wlr_tablet_v2_destroy(struct wlr_tablet_manager_v2 *manager); +static struct wlr_tablet_client_v2 *tablet_client_from_resource(struct wl_resource *resource); + +static void tablet_seat_destroy(struct wl_client *client, + struct wl_resource *resource) { + wl_resource_destroy(resource); +} + +static struct zwp_tablet_seat_v2_interface seat_impl = { + .destroy = tablet_seat_destroy, +}; + +static struct wlr_tablet_seat_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); + + seat->resource = NULL; + /* We can't just destroy the struct, because we may need to iterate it + * on display->destroy/manager_destroy + */ + // TODO: Implement the free() check +} + +static void handle_seat_destroy(struct wl_listener *listener, void *data) { + struct wlr_tablet_seat_v2 *seat = + wl_container_of(listener, seat, seat_destroy); + + seat->seat = NULL; + wl_list_remove(&seat->seat_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); +} + +static void tablet_manager_destroy(struct wl_client *client, + struct wl_resource *resource) { + wl_resource_destroy(resource); +} + +static void get_tablet_seat(struct wl_client *wl_client, struct wl_resource *resource, + uint32_t id, struct wl_resource *seat_resource) +{ + struct wlr_tablet_client_v2 *manager = tablet_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)); + if (tablet_seat == NULL) { + wl_client_post_no_memory(wl_client); + return; + } + + tablet_seat->resource = + wl_resource_create(wl_client, &zwp_tablet_seat_v2_interface, 1, id); + if (tablet_seat->resource == NULL) { + free(tablet_seat); + wl_client_post_no_memory(wl_client); + return; + } + + + tablet_seat->seat = seat; + tablet_seat->client = manager; + + tablet_seat->seat_destroy.notify = handle_seat_destroy; + wl_signal_add(&seat->events.destroy, &tablet_seat->seat_destroy); + + 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); +} + +static struct zwp_tablet_manager_v2_interface manager_impl = { + .get_tablet_seat = get_tablet_seat, + .destroy = tablet_manager_destroy, +}; + +static struct wlr_tablet_client_v2 *tablet_client_from_resource ( + struct wl_resource *resource) { + assert(wl_resource_instance_of(resource, &zwp_tablet_manager_v2_interface, + &manager_impl)); + return wl_resource_get_user_data(resource); +} + +static void wlr_tablet_manager_v2_destroy(struct wl_resource *resource) { + struct wlr_tablet_client_v2 *client = tablet_client_from_resource(resource); + + client->resource = NULL; + /* We can't just destroy the struct, because we may need to iterate it + * on display->destroy/manager_destroy + */ + // TODO: Implement the free() check +} + +static void tablet_v2_bind(struct wl_client *wl_client, void *data, + uint32_t version, uint32_t id) { + struct wlr_tablet_manager_v2 *manager = data; + assert(wl_client && manager); + + struct wlr_tablet_client_v2 *client = + calloc(1, sizeof(struct wlr_tablet_client_v2)); + if (client == NULL) { + wl_client_post_no_memory(wl_client); + return; + } + + wl_list_init(&client->tablet_seats); + + client->resource = + wl_resource_create(wl_client, &zwp_tablet_manager_v2_interface, version, id); + if (client->resource == NULL) { + free(client); + wl_client_post_no_memory(wl_client); + return; + } + client->client = wl_client; + client->manager = manager; + + wl_resource_set_implementation(client->resource, &manager_impl, client, + wlr_tablet_manager_v2_destroy); + wl_list_insert(&manager->clients, &client->link); +} + +static void handle_display_destroy(struct wl_listener *listener, void *data) { + struct wlr_tablet_manager_v2 *tablet = + wl_container_of(listener, tablet, display_destroy); + wlr_tablet_v2_destroy(tablet); +} + +void wlr_tablet_v2_destroy(struct wlr_tablet_manager_v2 *manager) { + struct wlr_tablet_client_v2 *tmp; + struct wlr_tablet_client_v2 *pos; + + wl_list_for_each_safe(pos, tmp, &manager->clients, link) { + wl_resource_destroy(pos->resource); + } + + wl_global_destroy(manager->wl_global); + free(manager); +} + +struct wlr_tablet_manager_v2 *wlr_tablet_v2_create(struct wl_display *display) { + struct wlr_tablet_manager_v2 *tablet = + calloc(1, sizeof(struct wlr_tablet_manager_v2)); + if (!tablet) { + return NULL; + } + + wl_list_init(&tablet->clients); + + tablet->display_destroy.notify = handle_display_destroy; + wl_display_add_destroy_listener(display, &tablet->display_destroy); + + tablet->wl_global = wl_global_create(display, + &zwp_tablet_manager_v2_interface, 1, tablet, tablet_v2_bind); + if (tablet->wl_global == NULL) { + free(tablet); + return NULL; + } + + return tablet; +} -- cgit v1.2.3 From 000b305eccb8d732aa2bde5f4b2f126c23e574cf Mon Sep 17 00:00:00 2001 From: Markus Ongyerth Date: Tue, 17 Apr 2018 19:09:42 +0200 Subject: backend/libinput: Manage tablet tool livetimes This adds the management code to manage tablet tools lifetimes from libinput. It follows the suggestion made in the tablet-unstable-v2.xml to destroy tablet_tools once all tablets that it got into contact with were removed from the system. This is implemented via a refcount. If a tool is *not* unique, it will be destroyed on proximity out. This is libinput specific and mentioned in libinput docs that tools will not be found again, so we shouldn't keep a reference to them. Also they can't be on other tablets as well, because they cannot be tracked. The naming in this commit is a bit off (to not break things). The wlr names stay the same, tablet_tool is the libinput_device with capaiblity LIBINPUT_DEVICE_CAP_TABLET_TOOL which is more akin to "tablet" in the tablet-unstable-v2 protocol. The struct that corresponds to the tablet_tool in tablet-unstable-v2 is called tablet_tool_tool, a rename should be done at some point in the future. --- backend/libinput/events.c | 3 + backend/libinput/tablet_tool.c | 179 +++++++++++++++++++++++++++++++++++- include/backend/libinput.h | 1 + include/wlr/types/wlr_tablet_tool.h | 40 ++++++++ 4 files changed, 222 insertions(+), 1 deletion(-) diff --git a/backend/libinput/events.c b/backend/libinput/events.c index 93664af2..d15de6bb 100644 --- a/backend/libinput/events.c +++ b/backend/libinput/events.c @@ -186,6 +186,9 @@ static void handle_device_removed(struct wlr_libinput_backend *backend, } struct wlr_input_device *dev, *tmp_dev; wl_list_for_each_safe(dev, tmp_dev, wlr_devices, link) { + if (dev->type == WLR_INPUT_DEVICE_TABLET_TOOL) { + wlr_libinput_tablet_tool_destroy(dev); + } wlr_input_device_destroy(dev); } for (size_t i = 0; i < backend->wlr_device_lists.length; i++) { diff --git a/backend/libinput/tablet_tool.c b/backend/libinput/tablet_tool.c index e9308b65..bae7780f 100644 --- a/backend/libinput/tablet_tool.c +++ b/backend/libinput/tablet_tool.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -8,7 +9,57 @@ #include "backend/libinput.h" #include "util/signal.h" -struct wlr_tablet_tool *create_libinput_tablet_tool( +struct wlr_libinput_tablet_tool { + struct wlr_tablet_tool_tool wlr_tool; + + struct libinput_tablet_tool *libinput_tool; + + bool unique; + // Refcount for destroy + release + size_t pad_refs; +}; + +// TODO: Maybe this should be a wlr_list? Do we keep it, or want to get rid of +// it? +struct tablet_tool_list_elem { + struct wl_list link; + + struct wlr_libinput_tablet_tool *tool; +}; + +struct wlr_libinput_tablet { + struct wlr_tablet_tool wlr_tool; + + struct wl_list tools; // tablet_tool_list_elem::link +}; + +static void destroy_tool_tool(struct wlr_libinput_tablet_tool *tool) { + wlr_signal_emit_safe(&tool->wlr_tool.events.destroy, &tool->wlr_tool); + libinput_tablet_tool_ref(tool->libinput_tool); + libinput_tablet_tool_set_user_data(tool->libinput_tool, NULL); + free(tool); +} + + +void wlr_libinput_tablet_tool_destroy(struct wlr_input_device *wlr_dev) { + struct wlr_libinput_tablet *tablet = + wl_container_of(wlr_dev->tablet_tool, tablet, wlr_tool); + + 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; + + if (--tool->pad_refs == 0) { + destroy_tool_tool(tool); + } + + free(pos); + } +} + +struct wlr_tablet_tool *wlr_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)); @@ -20,6 +71,91 @@ struct wlr_tablet_tool *create_libinput_tablet_tool( return wlr_tablet_tool; } +static enum wlr_tablet_tool_type wlr_type_from_libinput_type( + enum libinput_tablet_tool_type value) { + switch (value) { + case LIBINPUT_TABLET_TOOL_TYPE_PEN: + return WLR_TABLET_TOOL_TYPE_PEN; + case LIBINPUT_TABLET_TOOL_TYPE_ERASER: + return WLR_TABLET_TOOL_TYPE_ERASER; + case LIBINPUT_TABLET_TOOL_TYPE_BRUSH: + return WLR_TABLET_TOOL_TYPE_BRUSH; + case LIBINPUT_TABLET_TOOL_TYPE_PENCIL: + return WLR_TABLET_TOOL_TYPE_PENCIL; + case LIBINPUT_TABLET_TOOL_TYPE_AIRBRUSH: + return WLR_TABLET_TOOL_TYPE_AIRBRUSH; + case LIBINPUT_TABLET_TOOL_TYPE_MOUSE: + return WLR_TABLET_TOOL_TYPE_MOUSE; + case LIBINPUT_TABLET_TOOL_TYPE_LENS: + return WLR_TABLET_TOOL_TYPE_LENS; + } + + assert(false && "UNREACHABLE"); +} + +static struct wlr_libinput_tablet_tool *get_wlr_tablet_tool( + struct libinput_tablet_tool *tool) { + struct wlr_libinput_tablet_tool *ret = + libinput_tablet_tool_get_user_data(tool); + + if (ret) { + return ret; + } + + ret = calloc(1, sizeof(struct wlr_libinput_tablet_tool)); + if (!ret) { + return NULL; + } + + ret->libinput_tool = libinput_tablet_tool_ref(tool); + ret->wlr_tool.pressure = libinput_tablet_tool_has_pressure(tool); + ret->wlr_tool.distance = libinput_tablet_tool_has_distance(tool); + ret->wlr_tool.tilt = libinput_tablet_tool_has_tilt(tool); + ret->wlr_tool.rotation = libinput_tablet_tool_has_rotation(tool); + ret->wlr_tool.slider = libinput_tablet_tool_has_slider(tool); + ret->wlr_tool.wheel = libinput_tablet_tool_has_wheel(tool); + + ret->wlr_tool.hardware_serial = libinput_tablet_tool_get_serial(tool); + ret->wlr_tool.hardware_wacom = libinput_tablet_tool_get_tool_id(tool); + ret->wlr_tool.type = wlr_type_from_libinput_type( + libinput_tablet_tool_get_type(tool)); + + ret->unique = libinput_tablet_tool_is_unique(tool); + + wl_signal_init(&ret->wlr_tool.events.destroy); + + libinput_tablet_tool_set_user_data(tool, ret); + return ret; +} + +static void ensure_tool_reference(struct wlr_libinput_tablet_tool *tool, + struct wlr_tablet_tool *wlr_dev) { + struct tablet_tool_list_elem *pos; + struct wlr_libinput_tablet *tablet = wl_container_of(wlr_dev, tablet, wlr_tool); + + wl_list_for_each(pos, &tablet->tools, link) { + if (pos->tool == tool) { // We already have a ref + // XXX: We *could* optimize the tool to the front of + // the list here, since we will probably get the next + // couple of events from the same tool. + // BUT the list should always be rather short (probably + // single digit amount of tools) so it might be more + // work than it saves + return; + } + } + + struct tablet_tool_list_elem *new = + calloc(1, sizeof(struct tablet_tool_list_elem)); + if (!new) {// TODO: Should we at least log? + return; + } + + new->tool = tool; + wl_list_insert(&tablet->tools, &new->link); + ++tool->pad_refs; +} + void handle_tablet_tool_axis(struct libinput_event *event, struct libinput_device *libinput_dev) { struct wlr_input_device *wlr_dev = @@ -31,7 +167,12 @@ void handle_tablet_tool_axis(struct libinput_event *event, struct libinput_event_tablet_tool *tevent = libinput_event_get_tablet_tool_event(event); struct wlr_event_tablet_tool_axis wlr_event = { 0 }; + struct wlr_libinput_tablet_tool *tool = get_wlr_tablet_tool( + libinput_event_tablet_tool_get_tool(tevent)); + ensure_tool_reference(tool, wlr_dev->tablet_tool); + wlr_event.device = wlr_dev; + wlr_event.tool = &tool->wlr_tool; wlr_event.time_msec = usec_to_msec(libinput_event_tablet_tool_get_time_usec(tevent)); if (libinput_event_tablet_tool_x_has_changed(tevent)) { @@ -84,6 +225,11 @@ void handle_tablet_tool_proximity(struct libinput_event *event, struct libinput_event_tablet_tool *tevent = libinput_event_get_tablet_tool_event(event); struct wlr_event_tablet_tool_proximity wlr_event = { 0 }; + struct wlr_libinput_tablet_tool *tool = get_wlr_tablet_tool( + libinput_event_tablet_tool_get_tool(tevent)); + ensure_tool_reference(tool, wlr_dev->tablet_tool); + + wlr_event.tool = &tool->wlr_tool; wlr_event.device = wlr_dev; wlr_event.time_msec = usec_to_msec(libinput_event_tablet_tool_get_time_usec(tevent)); @@ -97,6 +243,27 @@ void handle_tablet_tool_proximity(struct libinput_event *event, break; } wlr_signal_emit_safe(&wlr_dev->tablet_tool->events.proximity, &wlr_event); + + // If the tool is not unique, libinput will not find it again after the + // proximity out, so we should destroy it + if (!tool->unique) { + // The tool isn't unique, it can't be on multiple tablets + assert(tool->pad_refs == 1); + struct wlr_libinput_tablet *tablet = + wl_container_of(wlr_dev->tablet_tool, tablet, wlr_tool); + struct tablet_tool_list_elem *pos; + struct tablet_tool_list_elem *tmp; + + wl_list_for_each_safe(pos, tmp, &tablet->tools, link) { + if (pos->tool == tool) { + wl_list_remove(&pos->link); + free(pos); + break; + } + } + + destroy_tool_tool(tool); + } } void handle_tablet_tool_tip(struct libinput_event *event, @@ -111,7 +278,12 @@ void handle_tablet_tool_tip(struct libinput_event *event, struct libinput_event_tablet_tool *tevent = libinput_event_get_tablet_tool_event(event); struct wlr_event_tablet_tool_tip wlr_event = { 0 }; + struct wlr_libinput_tablet_tool *tool = get_wlr_tablet_tool( + libinput_event_tablet_tool_get_tool(tevent)); + ensure_tool_reference(tool, wlr_dev->tablet_tool); + wlr_event.device = wlr_dev; + wlr_event.tool = &tool->wlr_tool; wlr_event.time_msec = usec_to_msec(libinput_event_tablet_tool_get_time_usec(tevent)); switch (libinput_event_tablet_tool_get_tip_state(tevent)) { @@ -137,7 +309,12 @@ void handle_tablet_tool_button(struct libinput_event *event, struct libinput_event_tablet_tool *tevent = libinput_event_get_tablet_tool_event(event); struct wlr_event_tablet_tool_button wlr_event = { 0 }; + struct wlr_libinput_tablet_tool *tool = get_wlr_tablet_tool( + libinput_event_tablet_tool_get_tool(tevent)); + ensure_tool_reference(tool, wlr_dev->tablet_tool); + wlr_event.device = wlr_dev; + wlr_event.tool = &tool->wlr_tool; wlr_event.time_msec = usec_to_msec(libinput_event_tablet_tool_get_time_usec(tevent)); wlr_event.button = libinput_event_tablet_tool_get_button(tevent); diff --git a/include/backend/libinput.h b/include/backend/libinput.h index f0928133..6ecdf44f 100644 --- a/include/backend/libinput.h +++ b/include/backend/libinput.h @@ -67,6 +67,7 @@ void handle_touch_cancel(struct libinput_event *event, struct wlr_tablet_tool *create_libinput_tablet_tool( struct libinput_device *device); +void wlr_libinput_tablet_tool_destroy(struct wlr_input_device *device); void handle_tablet_tool_axis(struct libinput_event *event, struct libinput_device *device); void handle_tablet_tool_proximity(struct libinput_event *event, diff --git a/include/wlr/types/wlr_tablet_tool.h b/include/wlr/types/wlr_tablet_tool.h index 22bf2649..08d37f68 100644 --- a/include/wlr/types/wlr_tablet_tool.h +++ b/include/wlr/types/wlr_tablet_tool.h @@ -5,6 +5,41 @@ #include #include +/* + * Copy+Paste from libinput, but this should neither use libinput, nor + * tablet-unstable-v2 headers, so we can't include them + */ +enum wlr_tablet_tool_type { + WLR_TABLET_TOOL_TYPE_PEN = 1, /**< A generic pen */ + WLR_TABLET_TOOL_TYPE_ERASER, /**< Eraser */ + WLR_TABLET_TOOL_TYPE_BRUSH, /**< A paintbrush-like tool */ + WLR_TABLET_TOOL_TYPE_PENCIL, /**< Physical drawing tool, e.g. + 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 */ +}; + +struct wlr_tablet_tool_tool { + enum wlr_tablet_tool_type type; + uint64_t hardware_serial; + uint64_t hardware_wacom; + + // Capabilities + bool tilt; + bool pressure; + bool distance; + bool rotation; + bool slider; + bool wheel; + + struct { + struct wl_signal destroy; + } events; + + void *data; +}; + struct wlr_tablet_tool_impl; struct wlr_tablet_tool { @@ -34,6 +69,8 @@ enum wlr_tablet_tool_axes { struct wlr_event_tablet_tool_axis { struct wlr_input_device *device; + struct wlr_tablet_tool_tool *tool; + uint32_t time_msec; uint32_t updated_axes; // From 0..1 @@ -53,6 +90,7 @@ enum wlr_tablet_tool_proximity_state { struct wlr_event_tablet_tool_proximity { struct wlr_input_device *device; + struct wlr_tablet_tool_tool *tool; uint32_t time_msec; // From 0..1 double x, y; @@ -66,6 +104,7 @@ enum wlr_tablet_tool_tip_state { struct wlr_event_tablet_tool_tip { struct wlr_input_device *device; + struct wlr_tablet_tool_tool *tool; uint32_t time_msec; // From 0..1 double x, y; @@ -74,6 +113,7 @@ struct wlr_event_tablet_tool_tip { struct wlr_event_tablet_tool_button { struct wlr_input_device *device; + struct wlr_tablet_tool_tool *tool; uint32_t time_msec; uint32_t button; enum wlr_button_state state; -- cgit v1.2.3 From 4947295c8f6d9b6f2f77928eda164ad44fb3ecf8 Mon Sep 17 00:00:00 2001 From: Markus Ongyerth Date: Wed, 18 Apr 2018 10:00:29 +0200 Subject: convoluted tablet code --- types/meson.build | 1 + types/wlr_tablet_tool_tool.c | 16 +++ types/wlr_tablet_v2.c | 232 +++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 238 insertions(+), 11 deletions(-) create mode 100644 types/wlr_tablet_tool_tool.c diff --git a/types/meson.build b/types/meson.build index a571dffd..5570d0c5 100644 --- a/types/meson.build +++ b/types/meson.build @@ -46,6 +46,7 @@ lib_wlr_types = static_library( 'wlr_tablet_v2.c', 'wlr_tablet_pad.c', 'wlr_tablet_tool.c', + 'wlr_tablet_tool_tool.c', 'wlr_touch.c', 'wlr_virtual_keyboard_v1.c', 'wlr_wl_shell.c', diff --git a/types/wlr_tablet_tool_tool.c b/types/wlr_tablet_tool_tool.c new file mode 100644 index 00000000..fcd38f56 --- /dev/null +++ b/types/wlr_tablet_tool_tool.c @@ -0,0 +1,16 @@ +#include +#include +#include +#include +#include + +void wlr_tablet_tool_tool_init(struct wlr_tablet_tool_tool *tool) { + // Intentionaly empty (for now) +} + +void wlr_tablet_tool_tool_destroy(struct wlr_tablet_tool_tool *tool) { + if (!tool) { + return; + } + free(tool); +} diff --git a/types/wlr_tablet_v2.c b/types/wlr_tablet_v2.c index 09e0ef35..076975c4 100644 --- a/types/wlr_tablet_v2.c +++ b/types/wlr_tablet_v2.c @@ -3,6 +3,8 @@ #endif #include +#include +#include #include #include #include @@ -13,14 +15,16 @@ struct wlr_tablet_manager_v2 { struct wl_global *wl_global; - struct wl_list clients; // wlr_tablet_client_v2::link + struct wl_list tablets; // wlr_tablet_v2::link + struct wl_list pads; // wlr_tablet_pad_v2::link + struct wl_list clients; // wlr_tablet_manager_client_v2::link struct wl_listener display_destroy; void *data; }; -struct wlr_tablet_client_v2 { +struct wlr_tablet_manager_client_v2 { struct wl_list link; struct wl_client *client; struct wl_resource *resource; @@ -34,21 +38,227 @@ struct wlr_tablet_seat_v2 { struct wl_list link; struct wl_resource *resource; - struct wlr_tablet_client_v2 *client; + struct wlr_tablet_manager_client_v2 *client; struct wlr_seat_client *seat; struct wl_listener seat_destroy; struct wl_list tools; + struct wl_list tablets; + struct wl_list pads; //wlr_tablet_pad_client_v2::link }; struct wlr_tablet_v2 { + struct wl_list link; + struct wl_list resources; + + char *name; + struct wl_list paths; // wlr_tablet_path::link + // USB vendor/product id + unsigned int vid; + unsigned int pid; +}; + +struct wlr_tablet_pad_v2 { + struct wl_list link; + struct wl_list resources; + + struct wlr_tablet_v2 *tablet; + + struct wl_list groups; // wlr_tablet_pad_group::link + struct wl_list paths; // wlr_tablet_path::link + size_t button_count; + size_t ring_count; + size_t strip_count; +}; + +struct wlr_tablet_tool_v2 { + struct wl_list link; + + enum zwp_tablet_tool_v2_type type; + uint64_t hardware_serial; + uint64_t hardware_wacom; + + // Capabilities + bool tilt; + bool pressure; + bool distance; + bool rotation; + bool slider; + bool wheel; +}; + +struct wlr_tablet_tool_client_v2 { struct wl_list link; struct wl_resource *resource; + + struct wlr_surface *cursor; + struct wl_listener cursor_destroy; }; +struct wlr_tablet_pad_client_v2 { + struct wl_list link; + struct wlr_tablet_pad_v2 *pad; + struct wl_resource *resource; + + size_t button_count; + + size_t ring_cout; + struct wl_resource **rings; + + size_t strip_cout; + struct wl_resource **strips; +}; + +struct wlr_tablet_pad_group_v2 { + struct wl_list link; + struct wl_list resources; + + struct wlr_tablet_pad_v2 *pad; + + size_t button_count; + unsigned int *buttons; + size_t strip_count; + unsigned int *strips; + size_t ring_count; + unsigned int *rings; + + unsigned int mode_count; +}; + +struct wlr_tablet_path { + struct wl_list link; + char *path; +}; + +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); +} + +void wlr_tablet_destroy(struct wlr_tablet_v2 *tablet) { + wl_list_remove(&tablet->link); + free(tablet->name); + + struct wlr_tablet_path *tmp; + struct wlr_tablet_path *pos; + wl_list_for_each_safe(pos, tmp, &tablet->paths, link) { + free(pos->path); + wl_list_remove(&pos->link); + free(pos); + } + + free(tablet); +} + +static void add_pad_group_from_libinput(struct wlr_tablet_pad_v2 *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_v2 *tablet_pad_from_libinput(struct wlr_tablet_manager_v2 *manager, + struct libinput_device *device) { + struct wlr_tablet_pad_v2 *pad = calloc(1, sizeof(struct wlr_tablet_pad_v2)); + if (!pad) { + return NULL; + } + + pad->button_count = libinput_device_tablet_pad_get_num_buttons(device); + pad->ring_count = libinput_device_tablet_pad_get_num_rings(device); + pad->strip_count = libinput_device_tablet_pad_get_num_strips(device); + + struct udev_device *udev = libinput_device_get_udev_device(device); + add_tablet_path(&pad->paths, udev_device_get_syspath(udev)); + + int groups = libinput_device_tablet_pad_get_num_mode_groups(device); + for (int i = 0; i < groups; ++i) { + add_pad_group_from_libinput(pad, device, i); + } + + wl_list_insert(&manager->pads, &pad->link); + return pad; +} + +struct wlr_tablet_v2 *tablet_from_libinput(struct wlr_tablet_manager_v2 *manager, + struct libinput_device *device) { + struct wlr_tablet_v2 *tablet = calloc(1, sizeof(struct wlr_tablet_v2)); + if (!tablet) { + return NULL; + } + + wl_list_init(&tablet->resources); + + tablet->vid = libinput_device_get_id_vendor(device); + tablet->pid = libinput_device_get_id_product(device); + tablet->name = strdup(libinput_device_get_name(device)); + if (!tablet->name) { + free(tablet); + return NULL; + } + + struct udev_device *udev = libinput_device_get_udev_device(device); + add_tablet_path(&tablet->paths, udev_device_get_syspath(udev)); + + wl_list_insert(&manager->tablets, &tablet->link); + return tablet; +} + void wlr_tablet_v2_destroy(struct wlr_tablet_manager_v2 *manager); -static struct wlr_tablet_client_v2 *tablet_client_from_resource(struct wl_resource *resource); +static struct wlr_tablet_manager_client_v2 *tablet_manager_client_from_resource(struct wl_resource *resource); static void tablet_seat_destroy(struct wl_client *client, struct wl_resource *resource) { @@ -96,7 +306,7 @@ static void tablet_manager_destroy(struct wl_client *client, static void get_tablet_seat(struct wl_client *wl_client, struct wl_resource *resource, uint32_t id, struct wl_resource *seat_resource) { - struct wlr_tablet_client_v2 *manager = tablet_client_from_resource(resource); + 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 = @@ -131,7 +341,7 @@ static struct zwp_tablet_manager_v2_interface manager_impl = { .destroy = tablet_manager_destroy, }; -static struct wlr_tablet_client_v2 *tablet_client_from_resource ( +static struct wlr_tablet_manager_client_v2 *tablet_manager_client_from_resource ( struct wl_resource *resource) { assert(wl_resource_instance_of(resource, &zwp_tablet_manager_v2_interface, &manager_impl)); @@ -139,7 +349,7 @@ static struct wlr_tablet_client_v2 *tablet_client_from_resource ( } static void wlr_tablet_manager_v2_destroy(struct wl_resource *resource) { - struct wlr_tablet_client_v2 *client = tablet_client_from_resource(resource); + struct wlr_tablet_manager_client_v2 *client = tablet_manager_client_from_resource(resource); client->resource = NULL; /* We can't just destroy the struct, because we may need to iterate it @@ -153,8 +363,8 @@ static void tablet_v2_bind(struct wl_client *wl_client, void *data, struct wlr_tablet_manager_v2 *manager = data; assert(wl_client && manager); - struct wlr_tablet_client_v2 *client = - calloc(1, sizeof(struct wlr_tablet_client_v2)); + struct wlr_tablet_manager_client_v2 *client = + calloc(1, sizeof(struct wlr_tablet_manager_client_v2)); if (client == NULL) { wl_client_post_no_memory(wl_client); return; @@ -184,8 +394,8 @@ static void handle_display_destroy(struct wl_listener *listener, void *data) { } void wlr_tablet_v2_destroy(struct wlr_tablet_manager_v2 *manager) { - struct wlr_tablet_client_v2 *tmp; - struct wlr_tablet_client_v2 *pos; + struct wlr_tablet_manager_client_v2 *tmp; + struct wlr_tablet_manager_client_v2 *pos; wl_list_for_each_safe(pos, tmp, &manager->clients, link) { wl_resource_destroy(pos->resource); -- cgit v1.2.3 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 ++++++++++++- backend/libinput/tablet_tool.c | 24 ++++- include/wlr/types/wlr_tablet_pad.h | 22 ++++ include/wlr/types/wlr_tablet_tool.h | 8 ++ types/wlr_tablet_v2.c | 199 +++--------------------------------- 5 files changed, 137 insertions(+), 187 deletions(-) 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; } diff --git a/backend/libinput/tablet_tool.c b/backend/libinput/tablet_tool.c index bae7780f..6c48dcf0 100644 --- a/backend/libinput/tablet_tool.c +++ b/backend/libinput/tablet_tool.c @@ -1,3 +1,7 @@ +#ifndef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 200809L +#endif +#include #include #include #include @@ -9,6 +13,18 @@ #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; @@ -59,7 +75,7 @@ void wlr_libinput_tablet_tool_destroy(struct wlr_input_device *wlr_dev) { } } -struct wlr_tablet_tool *wlr_libinput_tablet_tool_create( +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)); @@ -67,6 +83,12 @@ struct wlr_tablet_tool *wlr_libinput_tablet_tool_create( wlr_log(WLR_ERROR, "Unable to allocate wlr_tablet_tool"); return NULL; } + + 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)); + + wlr_tablet_tool_init(wlr_tablet_tool, NULL); return wlr_tablet_tool; } diff --git a/include/wlr/types/wlr_tablet_pad.h b/include/wlr/types/wlr_tablet_pad.h index 73082c56..b633f439 100644 --- a/include/wlr/types/wlr_tablet_pad.h +++ b/include/wlr/types/wlr_tablet_pad.h @@ -22,9 +22,31 @@ struct wlr_tablet_pad { struct wl_signal strip; } events; + size_t button_count; + size_t ring_count; + size_t strip_count; + + struct wl_list groups; // wlr_tablet_pad_group::link + struct wl_list paths; // wlr_tablet_path::link + void *data; }; +struct wlr_tablet_pad_group_v2 { + struct wl_list link; + + size_t button_count; + unsigned int *buttons; + + size_t strip_count; + unsigned int *strips; + + size_t ring_count; + unsigned int *rings; + + unsigned int mode_count; +}; + struct wlr_event_tablet_pad_button { uint32_t time_msec; uint32_t button; diff --git a/include/wlr/types/wlr_tablet_tool.h b/include/wlr/types/wlr_tablet_tool.h index 08d37f68..884b486a 100644 --- a/include/wlr/types/wlr_tablet_tool.h +++ b/include/wlr/types/wlr_tablet_tool.h @@ -42,6 +42,11 @@ 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; @@ -52,6 +57,9 @@ struct wlr_tablet_tool { struct wl_signal button; } events; + const char *name; + struct wl_list paths; // wlr_table_path::link + void *data; }; diff --git a/types/wlr_tablet_v2.c b/types/wlr_tablet_v2.c index 076975c4..56f4d567 100644 --- a/types/wlr_tablet_v2.c +++ b/types/wlr_tablet_v2.c @@ -15,8 +15,6 @@ struct wlr_tablet_manager_v2 { struct wl_global *wl_global; - struct wl_list tablets; // wlr_tablet_v2::link - struct wl_list pads; // wlr_tablet_pad_v2::link struct wl_list clients; // wlr_tablet_manager_client_v2::link struct wl_listener display_destroy; @@ -36,69 +34,44 @@ struct wlr_tablet_manager_client_v2 { struct wlr_tablet_seat_v2 { struct wl_list 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_list tools; struct wl_list tablets; struct wl_list pads; //wlr_tablet_pad_client_v2::link }; -struct wlr_tablet_v2 { - struct wl_list link; - struct wl_list resources; - - char *name; - struct wl_list paths; // wlr_tablet_path::link - // USB vendor/product id - unsigned int vid; - unsigned int pid; -}; - -struct wlr_tablet_pad_v2 { - struct wl_list link; - struct wl_list resources; - - struct wlr_tablet_v2 *tablet; - - struct wl_list groups; // wlr_tablet_pad_group::link - struct wl_list paths; // wlr_tablet_path::link - size_t button_count; - size_t ring_count; - size_t strip_count; -}; - -struct wlr_tablet_tool_v2 { +struct wlr_tablet_client_v2 { struct wl_list link; + struct wl_client *client; + struct wl_resource *resource; - enum zwp_tablet_tool_v2_type type; - uint64_t hardware_serial; - uint64_t hardware_wacom; - - // Capabilities - bool tilt; - bool pressure; - bool distance; - bool rotation; - bool slider; - bool wheel; + struct wl_listener device_destroy; + struct wl_listener client_destroy; }; struct wlr_tablet_tool_client_v2 { struct wl_list link; + struct wl_client *client; struct wl_resource *resource; struct wlr_surface *cursor; 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 wlr_tablet_pad_v2 *pad; + struct wl_client *client; struct wl_resource *resource; size_t button_count; @@ -108,155 +81,11 @@ struct wlr_tablet_pad_client_v2 { size_t strip_cout; struct wl_resource **strips; -}; - -struct wlr_tablet_pad_group_v2 { - struct wl_list link; - struct wl_list resources; - struct wlr_tablet_pad_v2 *pad; - - size_t button_count; - unsigned int *buttons; - size_t strip_count; - unsigned int *strips; - size_t ring_count; - unsigned int *rings; - - unsigned int mode_count; + struct wl_listener device_destroy; + struct wl_listener client_destroy; }; -struct wlr_tablet_path { - struct wl_list link; - char *path; -}; - -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); -} - -void wlr_tablet_destroy(struct wlr_tablet_v2 *tablet) { - wl_list_remove(&tablet->link); - free(tablet->name); - - struct wlr_tablet_path *tmp; - struct wlr_tablet_path *pos; - wl_list_for_each_safe(pos, tmp, &tablet->paths, link) { - free(pos->path); - wl_list_remove(&pos->link); - free(pos); - } - - free(tablet); -} - -static void add_pad_group_from_libinput(struct wlr_tablet_pad_v2 *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_v2 *tablet_pad_from_libinput(struct wlr_tablet_manager_v2 *manager, - struct libinput_device *device) { - struct wlr_tablet_pad_v2 *pad = calloc(1, sizeof(struct wlr_tablet_pad_v2)); - if (!pad) { - return NULL; - } - - pad->button_count = libinput_device_tablet_pad_get_num_buttons(device); - pad->ring_count = libinput_device_tablet_pad_get_num_rings(device); - pad->strip_count = libinput_device_tablet_pad_get_num_strips(device); - - struct udev_device *udev = libinput_device_get_udev_device(device); - add_tablet_path(&pad->paths, udev_device_get_syspath(udev)); - - int groups = libinput_device_tablet_pad_get_num_mode_groups(device); - for (int i = 0; i < groups; ++i) { - add_pad_group_from_libinput(pad, device, i); - } - - wl_list_insert(&manager->pads, &pad->link); - return pad; -} - -struct wlr_tablet_v2 *tablet_from_libinput(struct wlr_tablet_manager_v2 *manager, - struct libinput_device *device) { - struct wlr_tablet_v2 *tablet = calloc(1, sizeof(struct wlr_tablet_v2)); - if (!tablet) { - return NULL; - } - - wl_list_init(&tablet->resources); - - tablet->vid = libinput_device_get_id_vendor(device); - tablet->pid = libinput_device_get_id_product(device); - tablet->name = strdup(libinput_device_get_name(device)); - if (!tablet->name) { - free(tablet); - return NULL; - } - - struct udev_device *udev = libinput_device_get_udev_device(device); - add_tablet_path(&tablet->paths, udev_device_get_syspath(udev)); - - wl_list_insert(&manager->tablets, &tablet->link); - return tablet; -} - 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); -- 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 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 f696e980f1790621bdeb0b56482fc2590cf3226c Mon Sep 17 00:00:00 2001 From: Markus Ongyerth Date: Tue, 24 Apr 2018 15:47:41 +0200 Subject: stabilise tablet_v2 code (prevent bunch of crashes) --- types/wlr_tablet_v2.c | 154 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 110 insertions(+), 44 deletions(-) diff --git a/types/wlr_tablet_v2.c b/types/wlr_tablet_v2.c index db08c184..3e4eaafc 100644 --- a/types/wlr_tablet_v2.c +++ b/types/wlr_tablet_v2.c @@ -34,9 +34,9 @@ struct wlr_tablet_manager_client_v2 { struct wl_list link; struct wl_client *client; struct wl_resource *resource; - struct wlr_tablet_manager_v2 *manager; + struct wl_listener client_destroy; struct wl_list tablet_seats; // wlr_tablet_seat_client_v2::link }; @@ -51,9 +51,9 @@ struct wlr_tablet_seat_client_v2 { struct wl_listener seat_client_destroy; - struct wl_list tools; - struct wl_list tablets; - struct wl_list pads; //wlr_tablet_pad_client_v2::link + struct wl_list tools; //wlr_tablet_tool_client_v2::link + struct wl_list tablets; //wlr_tablet_client_v2::link + struct wl_list pads; //wlr_tablet_pad_client_v2::link }; struct wlr_tablet_client_v2 { @@ -61,8 +61,6 @@ struct wlr_tablet_client_v2 { struct wl_list tablet_link; // wlr_tablet_v2_tablet::clients struct wl_client *client; struct wl_resource *resource; - - struct wl_listener device_destroy; }; struct wlr_tablet_tool_client_v2 { @@ -70,11 +68,6 @@ struct wlr_tablet_tool_client_v2 { struct wl_list tool_link; struct wl_client *client; struct wl_resource *resource; - - struct wlr_surface *cursor; - struct wl_listener cursor_destroy; - - struct wl_listener tool_destroy; }; struct wlr_tablet_pad_client_v2 { @@ -93,8 +86,6 @@ struct wlr_tablet_pad_client_v2 { size_t strip_count; struct wl_resource **strips; - - struct wl_listener device_destroy; }; static struct zwp_tablet_v2_interface tablet_impl; @@ -110,9 +101,7 @@ static void destroy_tablet_v2(struct wl_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); + free(tablet); } static void handle_tablet_v2_destroy(struct wl_client *client, @@ -124,6 +113,52 @@ static struct zwp_tablet_v2_interface tablet_impl = { .destroy = handle_tablet_v2_destroy, }; +static void destroy_tablet_seat_client(struct wlr_tablet_seat_client_v2 *client) { + /* This is only called when the seat or client gets destroyed. + * The client is liable to make a request on a deleted resource either + * way, so we don't do the removed->destroy process, but just remove + * all structs immediatly. + */ + struct wlr_tablet_client_v2 *tablet; + struct wlr_tablet_client_v2 *tmp_tablet; + wl_list_for_each_safe(tablet, tmp_tablet, &client->tablets, seat_link) { + wl_resource_destroy(tablet->resource); + } + + struct wlr_tablet_pad_client_v2 *pad; + struct wlr_tablet_pad_client_v2 *tmp_pad; + wl_list_for_each_safe(pad, tmp_pad, &client->pads, seat_link) { + wl_resource_destroy(pad->resource); + } + + struct wlr_tablet_tool_client_v2 *tool; + struct wlr_tablet_tool_client_v2 *tmp_tool; + wl_list_for_each_safe(tool, tmp_tool, &client->tools, seat_link) { + wl_resource_destroy(tool->resource); + } + + wl_resource_destroy(client->resource); +} + +static void handle_wlr_seat_destroy(struct wl_listener *listener, void *data) { + struct wlr_tablet_seat_v2 *seat = + wl_container_of(listener, seat, seat_destroy); + + wl_list_remove(&seat->link); + wl_list_remove(&seat->seat_destroy.link); + + struct wlr_tablet_seat_client_v2 *client; + struct wlr_tablet_seat_client_v2 *tmp; + + /* wl_seat doesn't have a removed event/destroy request, so we can just + * destroy all attached tablet_seat_clients -> tablet_v2 resources. + * The client can call requests on gone resources either way + */ + wl_list_for_each_safe(client, tmp, &seat->clients, seat_link) { + destroy_tablet_seat_client(client); + } +} + static struct wlr_tablet_seat_v2 *make_tablet_seat( struct wlr_tablet_manager_v2 *manager, struct wlr_seat *wlr_seat) { @@ -142,6 +177,9 @@ static struct wlr_tablet_seat_v2 *make_tablet_seat( wl_list_init(&tablet_seat->tools); wl_list_init(&tablet_seat->pads); + tablet_seat->seat_destroy.notify = handle_wlr_seat_destroy; + wl_signal_add(&wlr_seat->events.destroy, &tablet_seat->seat_destroy); + wl_list_insert(&manager->seats, &tablet_seat->link); return tablet_seat; } @@ -242,6 +280,15 @@ static enum zwp_tablet_tool_v2_type tablet_type_from_wlr_type( assert(false && "Unreachable"); } +static void destroy_tablet_tool(struct wl_resource *resource) { + struct wlr_tablet_tool_client_v2 *client = + wl_resource_get_user_data(resource); + + wl_list_remove(&client->seat_link); + wl_list_remove(&client->tool_link); + free(client); +} + 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 = @@ -257,7 +304,7 @@ static void add_tablet_tool_client(struct wlr_tablet_seat_client_v2 *seat, return; } wl_resource_set_implementation(client->resource, &tablet_tool_impl, - client, NULL); + client, destroy_tablet_tool); zwp_tablet_seat_v2_send_tool_added(seat->resource, client->resource); // Send the expected events @@ -412,8 +459,33 @@ static void destroy_tablet_pad_v2(struct wl_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); + /* This isn't optimal, if the client destroys the resources in another + * order, it will be disconnected. + * But this makes things *way* easier for us, and (untested) I doubt + * clients will destroy it in another order. + */ + for (size_t i = 0; i < pad->group_count; ++i) { + if (pad->groups[i]) { + wl_resource_destroy(pad->groups[i]); + } + } + free(pad->groups); + + for (size_t i = 0; i < pad->ring_count; ++i) { + if (pad->rings[i]) { + wl_resource_destroy(pad->rings[i]); + } + } + free(pad->rings); + + for (size_t i = 0; i < pad->strip_count; ++i) { + if (pad->strips[i]) { + wl_resource_destroy(pad->strips[i]); + } + } + free(pad->strips); + + free(pad); } static void handle_tablet_pad_v2_destroy(struct wl_client *client, @@ -508,6 +580,7 @@ static void add_tablet_pad_group(struct wlr_tablet_v2_tablet_pad *pad, 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); + wl_array_release(&button_array); client->strip_count = group->strip_count; for (size_t i = 0; i < group->strip_count; ++i) { @@ -647,12 +720,6 @@ struct wlr_tablet_v2_tablet_pad *wlr_make_tablet_pad( 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; } @@ -678,23 +745,21 @@ static struct wlr_tablet_seat_client_v2 *tablet_seat_from_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 - * on display->destroy/manager_destroy - */ - // TODO: Implement the free() check + /* XXX: Evaluate whether we should have a way to access structs */ + wl_list_remove(&seat->tools); + wl_list_remove(&seat->tablets); + wl_list_remove(&seat->pads); + + wl_list_remove(&seat->seat_link); + wl_list_remove(&seat->client_link); + + free(seat); } -static void handle_seat_destroy(struct wl_listener *listener, void *data) { +static void handle_seat_client_destroy(struct wl_listener *listener, void *data) { struct wlr_tablet_seat_client_v2 *seat = wl_container_of(listener, seat, seat_client_destroy); - - seat->seat = NULL; - 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_client_destroy.link); + destroy_tablet_seat_client(seat); } static void tablet_manager_destroy(struct wl_client *client, @@ -740,7 +805,7 @@ static void get_tablet_seat(struct wl_client *wl_client, struct wl_resource *res wl_list_init(&seat_client->tablets); wl_list_init(&seat_client->pads); - seat_client->seat_client_destroy.notify = handle_seat_destroy; + seat_client->seat_client_destroy.notify = handle_seat_client_destroy; wl_signal_add(&seat->events.destroy, &seat_client->seat_client_destroy); wl_list_insert(&manager->tablet_seats, &seat_client->client_link); @@ -778,11 +843,12 @@ static struct wlr_tablet_manager_client_v2 *tablet_manager_client_from_resource static void wlr_tablet_manager_v2_destroy(struct wl_resource *resource) { struct wlr_tablet_manager_client_v2 *client = tablet_manager_client_from_resource(resource); - client->resource = NULL; - /* We can't just destroy the struct, because we may need to iterate it - * on display->destroy/manager_destroy - */ - // TODO: Implement the free() check + // TODO: Evaluate whether we may need to iterate structs + wl_list_remove(&client->link); + wl_list_remove(&client->tablet_seats); + //wl_list_remove(&client->client_destroy.link); + + free(client); } static void tablet_v2_bind(struct wl_client *wl_client, void *data, -- 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(-) 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 391eef6ea9acfd12856970548cb75dbef83dc702 Mon Sep 17 00:00:00 2001 From: Markus Ongyerth Date: Wed, 2 May 2018 09:26:34 +0200 Subject: Propagate most axis events to clients --- backend/libinput/tablet_tool.c | 3 +- include/rootston/seat.h | 13 ++++++ include/wlr/types/wlr_tablet_v2.h | 15 +++++++ rootston/seat.c | 93 +++++++++++++++++++++++++++++++++++++-- types/wlr_tablet_v2.c | 51 ++++++++++++++++++++- 5 files changed, 170 insertions(+), 5 deletions(-) diff --git a/backend/libinput/tablet_tool.c b/backend/libinput/tablet_tool.c index f69e41f8..36b64836 100644 --- a/backend/libinput/tablet_tool.c +++ b/backend/libinput/tablet_tool.c @@ -270,7 +270,8 @@ void handle_tablet_tool_proximity(struct libinput_event *event, // If the tool is not unique, libinput will not find it again after the // proximity out, so we should destroy it - if (!tool->unique) { + if (!tool->unique && + libinput_event_tablet_tool_get_proximity_state(tevent) == LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT) { // The tool isn't unique, it can't be on multiple tablets assert(tool->pad_refs == 1); struct wlr_libinput_tablet *tablet = diff --git a/include/rootston/seat.h b/include/rootston/seat.h index 31ddd6fa..1a0b889a 100644 --- a/include/rootston/seat.h +++ b/include/rootston/seat.h @@ -111,6 +111,19 @@ struct roots_tablet_pad { struct wl_listener tablet_destroy; }; +struct roots_tablet_tool_tool { + struct wl_list link; + struct wl_list tool_link; + struct wlr_tablet_v2_tablet_tool *tablet_v2_tool; + + struct roots_seat *seat; + + struct wl_listener tool_destroy; + + struct roots_tablet_tool *current_tablet; + struct wl_listener tablet_destroy; +}; + struct roots_seat *roots_seat_create(struct roots_input *input, char *name); void roots_seat_destroy(struct roots_seat *seat); diff --git a/include/wlr/types/wlr_tablet_v2.h b/include/wlr/types/wlr_tablet_v2.h index 4b2fffe4..a07a0177 100644 --- a/include/wlr/types/wlr_tablet_v2.h +++ b/include/wlr/types/wlr_tablet_v2.h @@ -7,6 +7,7 @@ #include "tablet-unstable-v2-protocol.h" +struct wlr_tablet_client_v2; struct wlr_tablet_tool_client_v2; struct wlr_tablet_pad_client_v2; @@ -27,6 +28,8 @@ struct wlr_tablet_v2_tablet { struct wl_list clients; // wlr_tablet_client_v2::tablet_link struct wl_listener tool_destroy; + + struct wlr_tablet_client_v2 *current_client; }; struct wlr_tablet_v2_tablet_tool { @@ -37,6 +40,9 @@ struct wlr_tablet_v2_tablet_tool { struct wl_listener tool_destroy; struct wlr_tablet_tool_client_v2 *current_client; + struct wlr_surface *focused_surface; + struct wl_listener surface_destroy; + struct wl_listener client_destroy; }; struct wlr_tablet_v2_tablet_pad { @@ -79,6 +85,12 @@ uint32_t wlr_send_tablet_v2_tablet_tool_proximity_in( 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_distance( + struct wlr_tablet_v2_tablet_tool *tool, uint32_t distance); + +void wlr_send_tablet_v2_tablet_tool_wheel( + struct wlr_tablet_v2_tablet_tool *tool, double delta, int32_t clicks); + void wlr_send_tablet_v2_tablet_tool_proximity_out( struct wlr_tablet_v2_tablet_tool *tool); @@ -101,4 +113,7 @@ uint32_t wlr_send_tablet_v2_tablet_pad_leave(struct wlr_tablet_v2_tablet_pad *pa 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); + +bool wlr_surface_accepts_tablet_v2(struct wlr_tablet_v2_tablet *tablet, + struct wlr_surface *surface); #endif /* WLR_TYPES_WLR_TABLET_V2_H */ diff --git a/rootston/seat.c b/rootston/seat.c index 8f84fc4b..eb909e78 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -101,13 +101,75 @@ static void handle_touch_motion(struct wl_listener *listener, void *data) { roots_cursor_handle_touch_motion(cursor, event); } +static void handle_tablet_tool_position(struct roots_cursor *cursor, + struct roots_tablet_tool *tool, + struct wlr_tablet_tool_tool *tool_tool, + bool change_x, bool change_y, double x, double y, + uint32_t time) { + if (!change_x && !change_y) { + return; + } + + wlr_cursor_warp_absolute(cursor->cursor, tool->device, + change_x ? x : -1 , change_y ? y : -1); + + double sx, sy; + struct roots_view *view = NULL; + struct roots_seat *seat = cursor->seat; + struct roots_desktop *desktop = seat->input->server->desktop; + struct wlr_surface *surface = desktop_surface_at(desktop, + cursor->cursor->x, cursor->cursor->y, &sx, &sy, &view); + struct roots_tablet_tool_tool *roots_tool = tool_tool->data; + + if (!surface) { + wlr_send_tablet_v2_tablet_tool_proximity_out(roots_tool->tablet_v2_tool); + /* XXX: TODO: Fallback pointer semantics */ + return; + } + + if (!wlr_surface_accepts_tablet_v2(tool->tablet_v2, surface)) { + wlr_send_tablet_v2_tablet_tool_proximity_out(roots_tool->tablet_v2_tool); + /* XXX: TODO: Fallback pointer semantics */ + return; + } + + wlr_send_tablet_v2_tablet_tool_proximity_in(roots_tool->tablet_v2_tool, + tool->tablet_v2, surface); + + wlr_send_tablet_v2_tablet_tool_motion(roots_tool->tablet_v2_tool, sx, sy); +} + static void handle_tool_axis(struct wl_listener *listener, void *data) { + wlr_log(L_DEBUG, "Tool Axis"); struct roots_cursor *cursor = wl_container_of(listener, cursor, tool_axis); struct roots_desktop *desktop = cursor->seat->input->server->desktop; wlr_idle_notify_activity(desktop->idle, cursor->seat->seat); struct wlr_event_tablet_tool_axis *event = data; - roots_cursor_handle_tool_axis(cursor, event); + struct roots_tablet_tool_tool *roots_tool = event->tool->data; + + if (!roots_tool) { + wlr_log(L_DEBUG, "Tool Axis, before proximity"); + return; + } + + /** + * We need to handle them ourselves, not pass it into the cursor + * without any consideration + */ + handle_tablet_tool_position(cursor, event->device->data, event->tool, + event->updated_axes & WLR_TABLET_TOOL_AXIS_X, + event->updated_axes & WLR_TABLET_TOOL_AXIS_Y, + event->x, event->y, event->time_msec); + + if (event->updated_axes & WLR_TABLET_TOOL_AXIS_DISTANCE) { + wlr_send_tablet_v2_tablet_tool_distance(roots_tool->tablet_v2_tool, event->distance); + } + + if (event->updated_axes & WLR_TABLET_TOOL_AXIS_WHEEL) { + wlr_send_tablet_v2_tablet_tool_wheel(roots_tool->tablet_v2_tool, event->wheel_delta, 0); + } + //roots_cursor_handle_tool_axis(cursor, event); } static void handle_tool_tip(struct wl_listener *listener, void *data) { @@ -119,7 +181,22 @@ static void handle_tool_tip(struct wl_listener *listener, void *data) { roots_cursor_handle_tool_tip(cursor, event); } +static void handle_tablet_tool_tool_destroy(struct wl_listener *listener, void *data) { + wlr_log(L_DEBUG, "Tool destroy"); + struct roots_tablet_tool_tool *tool = + wl_container_of(listener, tool, tool_destroy); + + wl_list_remove(&tool->link); + wl_list_remove(&tool->tool_link); + + wl_list_remove(&tool->tool_destroy.link); + wl_list_remove(&tool->tablet_destroy.link); + + free(tool); +} + static void handle_tool_proximity(struct wl_listener *listener, void *data) { + wlr_log(L_DEBUG, "Tool Proximity"); struct roots_cursor *cursor = wl_container_of(listener, cursor, tool_proximity); struct roots_desktop *desktop = cursor->seat->input->server->desktop; @@ -128,8 +205,18 @@ static void handle_tool_proximity(struct wl_listener *listener, void *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); - } + struct roots_tablet_tool_tool *roots_tool = + calloc(1, sizeof(struct roots_tablet_tool_tool)); + 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); + roots_tool->tool_destroy.notify = handle_tablet_tool_tool_destroy; + wl_signal_add(&tool->events.destroy, &roots_tool->tool_destroy); + } + + handle_tablet_tool_position(cursor, event->device->data, event->tool, + true, true, event->x, event->y, event->time_msec); } static void handle_request_set_cursor(struct wl_listener *listener, diff --git a/types/wlr_tablet_v2.c b/types/wlr_tablet_v2.c index f980aa0d..042713b7 100644 --- a/types/wlr_tablet_v2.c +++ b/types/wlr_tablet_v2.c @@ -950,8 +950,11 @@ static void send_tool_frame(void *data) { } static void queue_tool_frame(struct wlr_tablet_tool_client_v2 *tool) { + struct wl_display *display = wl_client_get_display(tool->client); + struct wl_event_loop *loop = wl_display_get_event_loop(display); if (!tool->frame_source) { - tool->frame_source = wl_event_loop_add_idle(NULL, send_tool_frame, tool); + tool->frame_source = + wl_event_loop_add_idle(loop, send_tool_frame, tool); } } @@ -961,6 +964,10 @@ uint32_t wlr_send_tablet_v2_tablet_tool_proximity_in( struct wlr_surface *surface) { struct wl_client *client = wl_resource_get_client(surface->resource); + if (tool->focused_surface == surface) { + return 0; + } + 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) { @@ -1004,6 +1011,7 @@ uint32_t wlr_send_tablet_v2_tablet_tool_proximity_in( tablet_client->resource, surface->resource); queue_tool_frame(tool_client); + tool->focused_surface = surface; return serial; } @@ -1028,9 +1036,31 @@ void wlr_send_tablet_v2_tablet_tool_proximity_out( wl_event_source_remove(tool->current_client->frame_source); send_tool_frame(tool->current_client); } + tool->current_client = NULL; + } +} + +void wlr_send_tablet_v2_tablet_tool_distance( + struct wlr_tablet_v2_tablet_tool *tool, uint32_t distance) { + if (tool->current_client) { + zwp_tablet_tool_v2_send_distance(tool->current_client->resource, + distance); + + queue_tool_frame(tool->current_client); } } +void wlr_send_tablet_v2_tablet_tool_wheel( + struct wlr_tablet_v2_tablet_tool *tool, double delta, int32_t clicks) { + if (tool->current_client) { + zwp_tablet_tool_v2_send_wheel(tool->current_client->resource, + clicks, delta); + + queue_tool_frame(tool->current_client); + } + +} + uint32_t wlr_send_tablet_v2_tablet_pad_enter( struct wlr_tablet_v2_tablet_pad *pad, @@ -1183,3 +1213,22 @@ uint32_t wlr_send_tablet_v2_tablet_pad_mode(struct wlr_tablet_v2_tablet_pad *pad pad->current_client->groups[group], time, serial, mode); return serial; } + +bool wlr_surface_accepts_tablet_v2(struct wlr_tablet_v2_tablet *tablet, + struct wlr_surface *surface) { + struct wl_client *client = wl_resource_get_client(surface->resource); + + if (tablet->current_client && + tablet->current_client->client == client) { + return true; + } + + struct wlr_tablet_client_v2 *tablet_tmp; + wl_list_for_each(tablet_tmp, &tablet->clients, tablet_link) { + if (tablet_tmp->client == client) { + return true; + } + } + + return false; +} -- cgit v1.2.3 From 5c7a37f30922d973e176b0eec29bb5fddf241eee Mon Sep 17 00:00:00 2001 From: Markus Ongyerth Date: Fri, 4 May 2018 11:46:32 +0200 Subject: Add tool buttons --- backend/libinput/tablet_tool.c | 5 +++- include/rootston/cursor.h | 1 + include/wlr/types/wlr_tablet_v2.h | 11 +++++++ rootston/seat.c | 19 +++++++++--- types/wlr_tablet_v2.c | 63 +++++++++++++++++++++++++++++++++++++-- 5 files changed, 91 insertions(+), 8 deletions(-) diff --git a/backend/libinput/tablet_tool.c b/backend/libinput/tablet_tool.c index 36b64836..3a39f5dc 100644 --- a/backend/libinput/tablet_tool.c +++ b/backend/libinput/tablet_tool.c @@ -263,11 +263,14 @@ void handle_tablet_tool_proximity(struct libinput_event *event, break; case LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN: wlr_event.state = WLR_TABLET_TOOL_PROXIMITY_IN; - handle_tablet_tool_axis(event, libinput_dev); break; } wlr_signal_emit_safe(&wlr_dev->tablet_tool->events.proximity, &wlr_event); + if (libinput_event_tablet_tool_get_proximity_state(tevent) == LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN) { + handle_tablet_tool_axis(event, libinput_dev); + } + // If the tool is not unique, libinput will not find it again after the // proximity out, so we should destroy it if (!tool->unique && diff --git a/include/rootston/cursor.h b/include/rootston/cursor.h index 0478c3ca..f7410dec 100644 --- a/include/rootston/cursor.h +++ b/include/rootston/cursor.h @@ -41,6 +41,7 @@ struct roots_cursor { struct wl_listener tool_axis; struct wl_listener tool_tip; struct wl_listener tool_proximity; + struct wl_listener tool_button; struct wl_listener request_set_cursor; }; diff --git a/include/wlr/types/wlr_tablet_v2.h b/include/wlr/types/wlr_tablet_v2.h index a07a0177..12995308 100644 --- a/include/wlr/types/wlr_tablet_v2.h +++ b/include/wlr/types/wlr_tablet_v2.h @@ -7,6 +7,9 @@ #include "tablet-unstable-v2-protocol.h" +/* This can probably be even lower,the tools don't have a lot of buttons */ +#define WLR_TABLEt_V2_TOOL_BUTTONS_CAP 16 + struct wlr_tablet_client_v2; struct wlr_tablet_tool_client_v2; struct wlr_tablet_pad_client_v2; @@ -43,6 +46,10 @@ struct wlr_tablet_v2_tablet_tool { struct wlr_surface *focused_surface; struct wl_listener surface_destroy; struct wl_listener client_destroy; + + uint32_t button_serial; + size_t num_buttons; + uint32_t pressed_buttons[WLR_TABLEt_V2_TOOL_BUTTONS_CAP]; }; struct wlr_tablet_v2_tablet_pad { @@ -94,6 +101,10 @@ void wlr_send_tablet_v2_tablet_tool_wheel( void wlr_send_tablet_v2_tablet_tool_proximity_out( struct wlr_tablet_v2_tablet_tool *tool); +uint32_t wlr_send_tablet_v2_tablet_tool_button( + struct wlr_tablet_v2_tablet_tool *tool, uint32_t button, + enum zwp_tablet_pad_v2_button_state state); + uint32_t wlr_send_tablet_v2_tablet_pad_enter( struct wlr_tablet_v2_tablet_pad *pad, struct wlr_tablet_v2_tablet *tablet, diff --git a/rootston/seat.c b/rootston/seat.c index eb909e78..eb1e7e0b 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -140,7 +140,6 @@ static void handle_tablet_tool_position(struct roots_cursor *cursor, } static void handle_tool_axis(struct wl_listener *listener, void *data) { - wlr_log(L_DEBUG, "Tool Axis"); struct roots_cursor *cursor = wl_container_of(listener, cursor, tool_axis); struct roots_desktop *desktop = cursor->seat->input->server->desktop; @@ -148,7 +147,7 @@ static void handle_tool_axis(struct wl_listener *listener, void *data) { struct wlr_event_tablet_tool_axis *event = data; struct roots_tablet_tool_tool *roots_tool = event->tool->data; - if (!roots_tool) { + if (!roots_tool) { // Should this be an assert? wlr_log(L_DEBUG, "Tool Axis, before proximity"); return; } @@ -182,7 +181,6 @@ static void handle_tool_tip(struct wl_listener *listener, void *data) { } static void handle_tablet_tool_tool_destroy(struct wl_listener *listener, void *data) { - wlr_log(L_DEBUG, "Tool destroy"); struct roots_tablet_tool_tool *tool = wl_container_of(listener, tool, tool_destroy); @@ -195,8 +193,18 @@ static void handle_tablet_tool_tool_destroy(struct wl_listener *listener, void * free(tool); } +static void handle_tool_button(struct wl_listener *listener, void *data) { + struct roots_cursor *cursor = + wl_container_of(listener, cursor, tool_button); + struct roots_desktop *desktop = cursor->seat->input->server->desktop; + wlr_idle_notify_activity(desktop->idle, cursor->seat->seat); + struct wlr_event_tablet_tool_button *event = data; + struct roots_tablet_tool_tool *roots_tool = event->tool->data; + + wlr_send_tablet_v2_tablet_tool_button(roots_tool->tablet_v2_tool, event->button, event->state); +} + static void handle_tool_proximity(struct wl_listener *listener, void *data) { - wlr_log(L_DEBUG, "Tool Proximity"); struct roots_cursor *cursor = wl_container_of(listener, cursor, tool_proximity); struct roots_desktop *desktop = cursor->seat->input->server->desktop; @@ -358,6 +366,9 @@ static void roots_seat_init_cursor(struct roots_seat *seat) { wl_signal_add(&wlr_cursor->events.tablet_tool_proximity, &seat->cursor->tool_proximity); seat->cursor->tool_proximity.notify = handle_tool_proximity; + wl_signal_add(&wlr_cursor->events.tablet_tool_button, &seat->cursor->tool_button); + seat->cursor->tool_button.notify = handle_tool_button; + wl_signal_add(&seat->seat->events.request_set_cursor, &seat->cursor->request_set_cursor); seat->cursor->request_set_cursor.notify = handle_request_set_cursor; diff --git a/types/wlr_tablet_v2.c b/types/wlr_tablet_v2.c index 042713b7..104de65f 100644 --- a/types/wlr_tablet_v2.c +++ b/types/wlr_tablet_v2.c @@ -941,6 +941,47 @@ struct wlr_tablet_manager_v2 *wlr_tablet_v2_create(struct wl_display *display) { } /* Actual protocol foo */ +// https://www.geeksforgeeks.org/move-zeroes-end-array/ +static size_t push_zeroes_to_end(uint32_t arr[], size_t n) { + size_t count = 0; + + for (size_t i = 0; i < n; i++) { + if (arr[i] != 0) { + arr[count++] = arr[i]; + } + } + + size_t ret = count; + + while (count < n) { + arr[count++] = 0; + } + + return ret; +} + +static void tablet_tool_button_update(struct wlr_tablet_v2_tablet_tool *tool, + uint32_t button, enum zwp_tablet_pad_v2_button_state state) { + bool found = false; + size_t i = 0; + for (; i < tool->num_buttons; ++i) { + if (tool->pressed_buttons[i] == button) { + found = true; + break; + } + } + + if (button == ZWP_TABLET_PAD_V2_BUTTON_STATE_PRESSED && !found && + tool->num_buttons < WLR_TABLEt_V2_TOOL_BUTTONS_CAP) { + tool->pressed_buttons[tool->num_buttons++] = button; + } + if (button == ZWP_TABLET_PAD_V2_BUTTON_STATE_RELEASED && found) { + tool->pressed_buttons[i] = 0; + tool->num_buttons = push_zeroes_to_end(tool->pressed_buttons, WLR_TABLEt_V2_TOOL_BUTTONS_CAP); + } + + assert(tool->num_buttons <= WLR_TABLEt_V2_TOOL_BUTTONS_CAP); +} static void send_tool_frame(void *data) { struct wlr_tablet_tool_client_v2 *tool = data; @@ -1041,7 +1082,7 @@ void wlr_send_tablet_v2_tablet_tool_proximity_out( } void wlr_send_tablet_v2_tablet_tool_distance( - struct wlr_tablet_v2_tablet_tool *tool, uint32_t distance) { + struct wlr_tablet_v2_tablet_tool *tool, uint32_t distance) { if (tool->current_client) { zwp_tablet_tool_v2_send_distance(tool->current_client->resource, distance); @@ -1050,6 +1091,24 @@ void wlr_send_tablet_v2_tablet_tool_distance( } } +uint32_t wlr_send_tablet_v2_tablet_tool_button( + struct wlr_tablet_v2_tablet_tool *tool, uint32_t button, + enum zwp_tablet_pad_v2_button_state state) { + tablet_tool_button_update(tool, button, state); + + if (tool->current_client) { + uint32_t serial = ++tool->button_serial; + + zwp_tablet_tool_v2_send_button(tool->current_client->resource, + serial, button, state); + queue_tool_frame(tool->current_client); + + return serial; + } + + return 0; +} + void wlr_send_tablet_v2_tablet_tool_wheel( struct wlr_tablet_v2_tablet_tool *tool, double delta, int32_t clicks) { if (tool->current_client) { @@ -1058,10 +1117,8 @@ void wlr_send_tablet_v2_tablet_tool_wheel( queue_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, -- 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(-) 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 15870ceb4b0277cc83cdd824bd521de95a77d983 Mon Sep 17 00:00:00 2001 From: Markus Ongyerth Date: Fri, 4 May 2018 19:10:30 +0200 Subject: Fix segfaultiness --- rootston/seat.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/rootston/seat.c b/rootston/seat.c index eb1e7e0b..b7bf28fc 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -111,7 +111,7 @@ static void handle_tablet_tool_position(struct roots_cursor *cursor, } wlr_cursor_warp_absolute(cursor->cursor, tool->device, - change_x ? x : -1 , change_y ? y : -1); + change_x ? x : NAN, change_y ? y : NAN); double sx, sy; struct roots_view *view = NULL; @@ -188,7 +188,6 @@ static void handle_tablet_tool_tool_destroy(struct wl_listener *listener, void * wl_list_remove(&tool->tool_link); wl_list_remove(&tool->tool_destroy.link); - wl_list_remove(&tool->tablet_destroy.link); free(tool); } @@ -221,6 +220,8 @@ static void handle_tool_proximity(struct wl_listener *listener, void *data) { wlr_make_tablet_tool(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); + wl_list_init(&roots_tool->tool_link); } handle_tablet_tool_position(cursor, event->device->data, event->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(-) 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 adba68a3c1fb51771342512f570c552a7404cc93 Mon Sep 17 00:00:00 2001 From: Markus Ongyerth Date: Tue, 15 May 2018 15:49:55 +0200 Subject: Use tablet_tool impl in libinput backend --- backend/libinput/events.c | 3 --- backend/libinput/tablet_tool.c | 12 +++++++++--- include/backend/libinput.h | 1 - 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/backend/libinput/events.c b/backend/libinput/events.c index d15de6bb..93664af2 100644 --- a/backend/libinput/events.c +++ b/backend/libinput/events.c @@ -186,9 +186,6 @@ static void handle_device_removed(struct wlr_libinput_backend *backend, } struct wlr_input_device *dev, *tmp_dev; wl_list_for_each_safe(dev, tmp_dev, wlr_devices, link) { - if (dev->type == WLR_INPUT_DEVICE_TABLET_TOOL) { - wlr_libinput_tablet_tool_destroy(dev); - } wlr_input_device_destroy(dev); } for (size_t i = 0; i < backend->wlr_device_lists.length; i++) { diff --git a/backend/libinput/tablet_tool.c b/backend/libinput/tablet_tool.c index f02e045a..7cecb091 100644 --- a/backend/libinput/tablet_tool.c +++ b/backend/libinput/tablet_tool.c @@ -57,9 +57,9 @@ static void destroy_tool_tool(struct wlr_libinput_tablet_tool *tool) { } -void wlr_libinput_tablet_tool_destroy(struct wlr_input_device *wlr_dev) { +static void libinput_tablet_tool_destroy(struct wlr_tablet_tool *tool) { struct wlr_libinput_tablet *tablet = - wl_container_of(wlr_dev->tablet_tool, tablet, wlr_tool); + wl_container_of(tool, tablet, wlr_tool); struct tablet_tool_list_elem *pos; struct tablet_tool_list_elem *tmp; @@ -72,8 +72,14 @@ void wlr_libinput_tablet_tool_destroy(struct wlr_input_device *wlr_dev) { destroy_tool_tool(tool); } } + + free(tablet); } +static struct wlr_tablet_tool_impl tool_impl = { + .destroy = libinput_tablet_tool_destroy, +}; + struct wlr_tablet_tool *create_libinput_tablet_tool( struct libinput_device *libinput_dev) { assert(libinput_dev); @@ -91,7 +97,7 @@ struct wlr_tablet_tool *create_libinput_tablet_tool( 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); + wlr_tablet_tool_init(wlr_tablet_tool, &tool_impl); return wlr_tablet_tool; } diff --git a/include/backend/libinput.h b/include/backend/libinput.h index 6ecdf44f..f0928133 100644 --- a/include/backend/libinput.h +++ b/include/backend/libinput.h @@ -67,7 +67,6 @@ void handle_touch_cancel(struct libinput_event *event, struct wlr_tablet_tool *create_libinput_tablet_tool( struct libinput_device *device); -void wlr_libinput_tablet_tool_destroy(struct wlr_input_device *device); void handle_tablet_tool_axis(struct libinput_event *event, struct libinput_device *device); void handle_tablet_tool_proximity(struct libinput_event *event, -- 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(-) 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 From b79d11395c9f8f26287e17e80066fd9034f05266 Mon Sep 17 00:00:00 2001 From: Markus Ongyerth Date: Thu, 17 May 2018 09:59:37 +0200 Subject: Hook up set_cursor in rootston --- include/rootston/seat.h | 1 + include/wlr/types/wlr_tablet_v2.h | 1 + rootston/seat.c | 22 ++++++++++++++++++++++ types/wlr_tablet_v2.c | 27 ++++++++++++++++++++++----- 4 files changed, 46 insertions(+), 5 deletions(-) diff --git a/include/rootston/seat.h b/include/rootston/seat.h index 1a0b889a..258c8840 100644 --- a/include/rootston/seat.h +++ b/include/rootston/seat.h @@ -118,6 +118,7 @@ struct roots_tablet_tool_tool { struct roots_seat *seat; + struct wl_listener set_cursor; struct wl_listener tool_destroy; struct roots_tablet_tool *current_tablet; diff --git a/include/wlr/types/wlr_tablet_v2.h b/include/wlr/types/wlr_tablet_v2.h index 0be672cb..5de12ec8 100644 --- a/include/wlr/types/wlr_tablet_v2.h +++ b/include/wlr/types/wlr_tablet_v2.h @@ -81,6 +81,7 @@ struct wlr_tablet_v2_event_cursor { uint32_t serial; int32_t hotspot_x; int32_t hotspot_y; + struct wlr_seat_client *seat_client; }; struct wlr_tablet_v2_event_feedback { diff --git a/rootston/seat.c b/rootston/seat.c index 6b12f682..3ca1404e 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -188,6 +188,7 @@ static void handle_tablet_tool_tool_destroy(struct wl_listener *listener, void * wl_list_remove(&tool->tool_link); wl_list_remove(&tool->tool_destroy.link); + wl_list_remove(&tool->set_cursor.link); free(tool); } @@ -203,6 +204,23 @@ static void handle_tool_button(struct wl_listener *listener, void *data) { wlr_send_tablet_v2_tablet_tool_button(roots_tool->tablet_v2_tool, event->button, event->state); } +static void handle_tablet_tool_set_cursor(struct wl_listener *listener, void *data) { + struct roots_tablet_tool_tool *tool = + wl_container_of(listener, tool, set_cursor); + struct wlr_tablet_v2_event_cursor *evt = data; + + + struct wlr_seat_pointer_request_set_cursor_event event = { + .surface = evt->surface, + .hotspot_x = evt->hotspot_x, + .hotspot_y = evt->hotspot_y, + .serial = evt->serial, + .seat_client = evt->seat_client, + }; + + roots_cursor_handle_request_set_cursor(tool->seat->cursor, &event); +} + static void handle_tool_proximity(struct wl_listener *listener, void *data) { struct roots_cursor *cursor = wl_container_of(listener, cursor, tool_proximity); @@ -221,6 +239,10 @@ static void handle_tool_proximity(struct wl_listener *listener, void *data) { cursor->seat->seat, tool); roots_tool->tool_destroy.notify = handle_tablet_tool_tool_destroy; wl_signal_add(&tool->events.destroy, &roots_tool->tool_destroy); + + roots_tool->set_cursor.notify = handle_tablet_tool_set_cursor; + wl_signal_add(&roots_tool->tablet_v2_tool->events.set_cursor, &roots_tool->set_cursor); + wl_list_init(&roots_tool->link); wl_list_init(&roots_tool->tool_link); } diff --git a/types/wlr_tablet_v2.c b/types/wlr_tablet_v2.c index 52089c47..5dec1c5d 100644 --- a/types/wlr_tablet_v2.c +++ b/types/wlr_tablet_v2.c @@ -67,6 +67,7 @@ struct wlr_tablet_tool_client_v2 { struct wl_client *client; struct wl_resource *resource; struct wlr_tablet_v2_tablet_tool *tool; + struct wlr_tablet_seat_client_v2 *seat; uint32_t proximity_serial; @@ -262,24 +263,34 @@ static void handle_wlr_tablet_destroy(struct wl_listener *listener, void *data) free(tablet); } +static const struct wlr_surface_role pointer_cursor_surface_role = { + .name = "wl_pointer-cursor", +}; + static void handle_tablet_tool_v2_set_cursor(struct wl_client *client, - struct wl_resource *resource, - uint32_t serial, + struct wl_resource *resource, uint32_t serial, struct wl_resource *surface_resource, - int32_t hotspot_x, - int32_t hotspot_y) { + 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_surface *surface; + if (surface_resource != NULL) { + surface = wlr_surface_from_resource(surface_resource); + if (!wlr_surface_set_role(surface, &pointer_cursor_surface_role, NULL, + surface_resource, WL_POINTER_ERROR_ROLE)) { + return; + } + } struct wlr_tablet_v2_event_cursor evt = { .surface = surface, .serial = serial, .hotspot_x = hotspot_x, .hotspot_y = hotspot_y, + .seat_client = tool->seat->seat, }; wl_signal_emit(&tool->tool->events.set_cursor, &evt); @@ -324,6 +335,10 @@ static void destroy_tablet_tool(struct wl_resource *resource) { wl_event_source_remove(client->frame_source); } + if (client->tool && client->tool->current_client == client) { + client->tool->current_client = NULL; + } + wl_list_remove(&client->seat_link); wl_list_remove(&client->tool_link); free(client); @@ -337,6 +352,7 @@ static void add_tablet_tool_client(struct wlr_tablet_seat_client_v2 *seat, return; } client->tool = tool; + client->seat = seat; client->resource = wl_resource_create(seat->wl_client, &zwp_tablet_tool_v2_interface, 1, 0); @@ -444,6 +460,7 @@ static void handle_wlr_tablet_tool_destroy(struct wl_listener *listener, void *d 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); + pos->tool = NULL; } wl_list_remove(&tool->clients); -- cgit v1.2.3 From 2155c976f61aa569f5da94bd2e933f5b40534ceb Mon Sep 17 00:00:00 2001 From: Markus Ongyerth Date: Thu, 17 May 2018 11:10:31 +0200 Subject: Improve inert resource handling --- include/types/wlr_tablet_v2.h | 20 ++++++++ types/wlr_tablet_v2.c | 114 +++++++++++++++++++++++------------------- 2 files changed, 83 insertions(+), 51 deletions(-) create mode 100644 include/types/wlr_tablet_v2.h diff --git a/include/types/wlr_tablet_v2.h b/include/types/wlr_tablet_v2.h new file mode 100644 index 00000000..21e2d962 --- /dev/null +++ b/include/types/wlr_tablet_v2.h @@ -0,0 +1,20 @@ +#ifndef TYPES_WLR_TABLET_V2_H +#define TYPES_WLR_TABLET_V2_H + +#include "tablet-unstable-v2-protocol.h" +#include +#include + + +struct wlr_tablet_client_v2 *tablet_client_from_resource(struct wl_resource *resource); +void destroy_tablet_v2(struct wl_resource *resource); + +void destroy_tablet_pad_v2(struct wl_resource *resource); +struct wlr_tablet_pad_client_v2 *tablet_pad_client_from_resource(struct wl_resource *resource); + +void destroy_tablet_tool_v2(struct wl_resource *resource); +struct wlr_tablet_tool_client_v2 *tablet_tool_client_from_resource(struct wl_resource *resource); + +struct wlr_tablet_seat_client_v2 *tablet_seat_client_from_resource(struct wl_resource *resource); +static void wlr_tablet_seat_client_v2_destroy(struct wl_resource *resource); +#endif /* TYPES_WLR_TABLET_V2_H */ diff --git a/types/wlr_tablet_v2.c b/types/wlr_tablet_v2.c index 5dec1c5d..781e52f9 100644 --- a/types/wlr_tablet_v2.c +++ b/types/wlr_tablet_v2.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -104,18 +105,23 @@ struct tablet_pad_auxiliary_user_data { static struct zwp_tablet_v2_interface tablet_impl; -static struct wlr_tablet_client_v2 *tablet_client_from_resource(struct wl_resource *resource) { +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) { +void destroy_tablet_v2(struct wl_resource *resource) { struct wlr_tablet_client_v2 *tablet = tablet_client_from_resource(resource); + if (!tablet) { + return; + } + wl_list_remove(&tablet->seat_link); wl_list_remove(&tablet->tablet_link); free(tablet); + wl_resource_set_user_data(resource, NULL); } static void handle_tablet_v2_destroy(struct wl_client *client, @@ -127,33 +133,6 @@ static struct zwp_tablet_v2_interface tablet_impl = { .destroy = handle_tablet_v2_destroy, }; -static void destroy_tablet_seat_client(struct wlr_tablet_seat_client_v2 *client) { - /* This is only called when the seat or client gets destroyed. - * The client is liable to make a request on a deleted resource either - * way, so we don't do the removed->destroy process, but just remove - * all structs immediatly. - */ - struct wlr_tablet_client_v2 *tablet; - struct wlr_tablet_client_v2 *tmp_tablet; - wl_list_for_each_safe(tablet, tmp_tablet, &client->tablets, seat_link) { - wl_resource_destroy(tablet->resource); - } - - struct wlr_tablet_pad_client_v2 *pad; - struct wlr_tablet_pad_client_v2 *tmp_pad; - wl_list_for_each_safe(pad, tmp_pad, &client->pads, seat_link) { - wl_resource_destroy(pad->resource); - } - - struct wlr_tablet_tool_client_v2 *tool; - struct wlr_tablet_tool_client_v2 *tmp_tool; - wl_list_for_each_safe(tool, tmp_tool, &client->tools, seat_link) { - wl_resource_destroy(tool->resource); - } - - wl_resource_destroy(client->resource); -} - static void handle_wlr_seat_destroy(struct wl_listener *listener, void *data) { struct wlr_tablet_seat_v2 *seat = wl_container_of(listener, seat, seat_destroy); @@ -163,13 +142,8 @@ static void handle_wlr_seat_destroy(struct wl_listener *listener, void *data) { struct wlr_tablet_seat_client_v2 *client; struct wlr_tablet_seat_client_v2 *tmp; - - /* wl_seat doesn't have a removed event/destroy request, so we can just - * destroy all attached tablet_seat_clients -> tablet_v2 resources. - * The client can call requests on gone resources either way - */ wl_list_for_each_safe(client, tmp, &seat->clients, seat_link) { - destroy_tablet_seat_client(client); + wlr_tablet_seat_client_v2_destroy(client->resource); } } @@ -271,7 +245,7 @@ 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); + struct wlr_tablet_tool_client_v2 *tool = tablet_tool_client_from_resource(resource); if (!tool) { return; } @@ -327,9 +301,13 @@ static enum zwp_tablet_tool_v2_type tablet_type_from_wlr_type( assert(false && "Unreachable"); } -static void destroy_tablet_tool(struct wl_resource *resource) { +void destroy_tablet_tool_v2(struct wl_resource *resource) { struct wlr_tablet_tool_client_v2 *client = - wl_resource_get_user_data(resource); + tablet_tool_client_from_resource(resource); + + if (!client) { + return; + } if (client->frame_source) { wl_event_source_remove(client->frame_source); @@ -342,6 +320,8 @@ static void destroy_tablet_tool(struct wl_resource *resource) { wl_list_remove(&client->seat_link); wl_list_remove(&client->tool_link); free(client); + + wl_resource_set_user_data(resource, NULL); } static void add_tablet_tool_client(struct wlr_tablet_seat_client_v2 *seat, @@ -361,7 +341,7 @@ static void add_tablet_tool_client(struct wlr_tablet_seat_client_v2 *seat, return; } wl_resource_set_implementation(client->resource, &tablet_tool_impl, - client, destroy_tablet_tool); + client, destroy_tablet_tool_v2); zwp_tablet_seat_v2_send_tool_added(seat->resource, client->resource); // Send the expected events @@ -506,17 +486,21 @@ struct wlr_tablet_v2_tablet_tool *wlr_tablet_tool_create( 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) { +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) { +void destroy_tablet_pad_v2(struct wl_resource *resource) { struct wlr_tablet_pad_client_v2 *pad = tablet_pad_client_from_resource(resource); + if (!pad) { + return; + } + wl_list_remove(&pad->seat_link); wl_list_remove(&pad->pad_link); @@ -547,6 +531,7 @@ static void destroy_tablet_pad_v2(struct wl_resource *resource) { free(pad->strips); free(pad); + wl_resource_set_user_data(resource, NULL); } static void handle_tablet_pad_v2_destroy(struct wl_client *client, @@ -633,7 +618,10 @@ static struct zwp_tablet_pad_strip_v2_interface tablet_pad_strip_impl = { 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_pad_client_v2 *pad = tablet_pad_client_from_resource(resource); + if (!pad) { + return; + } struct wlr_tablet_v2_event_feedback evt = { .serial = serial, @@ -641,7 +629,7 @@ static void handle_tablet_pad_v2_set_feedback( struct wl_client *client, .description = description, }; - wl_signal_emit(&pad->events.button_feedback, &evt); + wl_signal_emit(&pad->pad->events.button_feedback, &evt); } static struct zwp_tablet_pad_v2_interface tablet_pad_impl = { @@ -891,31 +879,49 @@ static struct zwp_tablet_seat_v2_interface seat_impl = { .destroy = tablet_seat_destroy, }; -static struct wlr_tablet_seat_client_v2 *tablet_seat_from_resource ( +struct wlr_tablet_seat_client_v2 *tablet_seat_client_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_client_v2_destroy(struct wl_resource *resource) { - struct wlr_tablet_seat_client_v2 *seat = tablet_seat_from_resource(resource); +void wlr_tablet_seat_client_v2_destroy(struct wl_resource *resource) { + struct wlr_tablet_seat_client_v2 *seat = tablet_seat_client_from_resource(resource); + if (!seat) { + return; + } - /* XXX: Evaluate whether we should have a way to access structs */ - wl_list_remove(&seat->tools); - wl_list_remove(&seat->tablets); - wl_list_remove(&seat->pads); + struct wlr_tablet_client_v2 *tablet; + struct wlr_tablet_client_v2 *tmp_tablet; + wl_list_for_each_safe(tablet, tmp_tablet, &seat->tablets, seat_link) { + destroy_tablet_v2(tablet->resource); + } + + struct wlr_tablet_pad_client_v2 *pad; + struct wlr_tablet_pad_client_v2 *tmp_pad; + wl_list_for_each_safe(pad, tmp_pad, &seat->pads, seat_link) { + destroy_tablet_pad_v2(pad->resource); + } + + struct wlr_tablet_tool_client_v2 *tool; + struct wlr_tablet_tool_client_v2 *tmp_tool; + wl_list_for_each_safe(tool, tmp_tool, &seat->tools, seat_link) { + destroy_tablet_tool_v2(tool->resource); + } wl_list_remove(&seat->seat_link); wl_list_remove(&seat->client_link); + wl_list_remove(&seat->seat_client_destroy.link); free(seat); + wl_resource_set_user_data(resource, NULL); } static void handle_seat_client_destroy(struct wl_listener *listener, void *data) { struct wlr_tablet_seat_client_v2 *seat = wl_container_of(listener, seat, seat_client_destroy); - destroy_tablet_seat_client(seat); + wlr_tablet_seat_client_v2_destroy(seat->resource); } static void tablet_manager_destroy(struct wl_client *client, @@ -1426,3 +1432,9 @@ bool wlr_surface_accepts_tablet_v2(struct wlr_tablet_v2_tablet *tablet, return false; } + +struct wlr_tablet_tool_client_v2 *tablet_tool_client_from_resource(struct wl_resource *resource) { + assert(wl_resource_instance_of(resource, &zwp_tablet_tool_v2_interface, + &tablet_tool_impl)); + return wl_resource_get_user_data(resource); +} -- cgit v1.2.3 From 6a40561e4cddae0f6c3325afd96c7f38e8f649d1 Mon Sep 17 00:00:00 2001 From: Markus Ongyerth Date: Thu, 17 May 2018 11:15:07 +0200 Subject: Fix clang build errors --- rootston/seat.c | 7 +++++-- types/wlr_tablet_v2.c | 10 +++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/rootston/seat.c b/rootston/seat.c index 3ca1404e..d49d71cc 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -201,7 +201,9 @@ static void handle_tool_button(struct wl_listener *listener, void *data) { struct wlr_event_tablet_tool_button *event = data; struct roots_tablet_tool_tool *roots_tool = event->tool->data; - wlr_send_tablet_v2_tablet_tool_button(roots_tool->tablet_v2_tool, event->button, event->state); + wlr_send_tablet_v2_tablet_tool_button(roots_tool->tablet_v2_tool, + (enum zwp_tablet_pad_v2_button_state)event->button, + (enum zwp_tablet_pad_v2_button_state)event->state); } static void handle_tablet_tool_set_cursor(struct wl_listener *listener, void *data) { @@ -757,7 +759,8 @@ static void handle_tablet_pad_button(struct wl_listener *listener, void *data) { 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); + event->button, event->time_msec, + (enum zwp_tablet_pad_v2_button_state)event->state); } static void seat_add_tablet_pad(struct roots_seat *seat, diff --git a/types/wlr_tablet_v2.c b/types/wlr_tablet_v2.c index 781e52f9..74327c9c 100644 --- a/types/wlr_tablet_v2.c +++ b/types/wlr_tablet_v2.c @@ -250,7 +250,7 @@ static void handle_tablet_tool_v2_set_cursor(struct wl_client *client, return; } - struct wlr_surface *surface; + struct wlr_surface *surface = NULL; if (surface_resource != NULL) { surface = wlr_surface_from_resource(surface_resource); if (!wlr_surface_set_role(surface, &pointer_cursor_surface_role, NULL, @@ -1168,8 +1168,8 @@ uint32_t wlr_send_tablet_v2_tablet_tool_proximity_in( return 0; } - struct wlr_tablet_tool_client_v2 *tool_tmp; - struct wlr_tablet_tool_client_v2 *tool_client; + struct wlr_tablet_tool_client_v2 *tool_tmp = NULL; + struct wlr_tablet_tool_client_v2 *tool_client = NULL; wl_list_for_each(tool_tmp, &tool->clients, tool_link) { if (tool_tmp->client == client) { tool_client = tool_tmp; @@ -1284,8 +1284,8 @@ uint32_t wlr_send_tablet_v2_tablet_pad_enter( return 0; } - struct wlr_tablet_pad_client_v2 *pad_tmp; - struct wlr_tablet_pad_client_v2 *pad_client; + struct wlr_tablet_pad_client_v2 *pad_tmp = NULL; + struct wlr_tablet_pad_client_v2 *pad_client = NULL; wl_list_for_each(pad_tmp, &pad->clients, pad_link) { if (pad_tmp->client == client) { pad_client = pad_tmp; -- cgit v1.2.3 From 2c120114723aaaf270e3a44df958faeda91b3f5a Mon Sep 17 00:00:00 2001 From: Markus Ongyerth Date: Thu, 17 May 2018 12:22:15 +0200 Subject: Send all tablet tool axis events --- include/wlr/types/wlr_tablet_v2.h | 17 +++++++++ rootston/seat.c | 25 ++++++++++++- types/wlr_tablet_v2.c | 77 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 117 insertions(+), 2 deletions(-) diff --git a/include/wlr/types/wlr_tablet_v2.h b/include/wlr/types/wlr_tablet_v2.h index 5de12ec8..3268c0b5 100644 --- a/include/wlr/types/wlr_tablet_v2.h +++ b/include/wlr/types/wlr_tablet_v2.h @@ -47,6 +47,8 @@ struct wlr_tablet_v2_tablet_tool { struct wl_listener surface_destroy; struct wl_listener client_destroy; + uint32_t down_serial; + bool is_down; uint32_t button_serial; size_t num_buttons; uint32_t pressed_buttons[WLR_TABLEt_V2_TOOL_BUTTONS_CAP]; @@ -113,12 +115,27 @@ uint32_t wlr_send_tablet_v2_tablet_tool_proximity_in( struct wlr_tablet_v2_tablet *tablet, struct wlr_surface *surface); +uint32_t wlr_send_tablet_v2_tablet_tool_down(struct wlr_tablet_v2_tablet_tool *tool); +void wlr_send_tablet_v2_tablet_tool_up(struct wlr_tablet_v2_tablet_tool *tool); + 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_pressure( + struct wlr_tablet_v2_tablet_tool *tool, uint32_t pressure); + void wlr_send_tablet_v2_tablet_tool_distance( struct wlr_tablet_v2_tablet_tool *tool, uint32_t distance); +void wlr_send_tablet_v2_tablet_tool_tilt( + struct wlr_tablet_v2_tablet_tool *tool, double x, double y); + +void wlr_send_tablet_v2_tablet_tool_rotation( + struct wlr_tablet_v2_tablet_tool *tool, double degrees); + +void wlr_send_tablet_v2_tablet_tool_slider( + struct wlr_tablet_v2_tablet_tool *tool, int32_t position); + void wlr_send_tablet_v2_tablet_tool_wheel( struct wlr_tablet_v2_tablet_tool *tool, double delta, int32_t clicks); diff --git a/rootston/seat.c b/rootston/seat.c index d49d71cc..56b9c50e 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -161,14 +161,29 @@ static void handle_tool_axis(struct wl_listener *listener, void *data) { event->updated_axes & WLR_TABLET_TOOL_AXIS_Y, event->x, event->y, event->time_msec); + if (event->updated_axes & WLR_TABLET_TOOL_AXIS_PRESSURE) { + wlr_send_tablet_v2_tablet_tool_pressure(roots_tool->tablet_v2_tool, event->pressure); + } + if (event->updated_axes & WLR_TABLET_TOOL_AXIS_DISTANCE) { wlr_send_tablet_v2_tablet_tool_distance(roots_tool->tablet_v2_tool, event->distance); } + if (event->updated_axes & (WLR_TABLET_TOOL_AXIS_TILT_X | WLR_TABLET_TOOL_AXIS_TILT_Y)) { + wlr_send_tablet_v2_tablet_tool_tilt(roots_tool->tablet_v2_tool, event->tilt_x, event->tilt_y); + } + + if (event->updated_axes & WLR_TABLET_TOOL_AXIS_ROTATION) { + wlr_send_tablet_v2_tablet_tool_rotation(roots_tool->tablet_v2_tool, event->rotation); + } + + if (event->updated_axes & WLR_TABLET_TOOL_AXIS_SLIDER) { + wlr_send_tablet_v2_tablet_tool_slider(roots_tool->tablet_v2_tool, event->slider); + } + if (event->updated_axes & WLR_TABLET_TOOL_AXIS_WHEEL) { wlr_send_tablet_v2_tablet_tool_wheel(roots_tool->tablet_v2_tool, event->wheel_delta, 0); } - //roots_cursor_handle_tool_axis(cursor, event); } static void handle_tool_tip(struct wl_listener *listener, void *data) { @@ -177,7 +192,13 @@ static void handle_tool_tip(struct wl_listener *listener, void *data) { struct roots_desktop *desktop = cursor->seat->input->server->desktop; wlr_idle_notify_activity(desktop->idle, cursor->seat->seat); struct wlr_event_tablet_tool_tip *event = data; - roots_cursor_handle_tool_tip(cursor, event); + struct roots_tablet_tool_tool *roots_tool = event->tool->data; + + if (event->state == WLR_TABLET_TOOL_TIP_DOWN) { + wlr_send_tablet_v2_tablet_tool_down(roots_tool->tablet_v2_tool); + } else { + wlr_send_tablet_v2_tablet_tool_up(roots_tool->tablet_v2_tool); + } } static void handle_tablet_tool_tool_destroy(struct wl_listener *listener, void *data) { diff --git a/types/wlr_tablet_v2.c b/types/wlr_tablet_v2.c index 74327c9c..48de6b68 100644 --- a/types/wlr_tablet_v2.c +++ b/types/wlr_tablet_v2.c @@ -1224,6 +1224,16 @@ void wlr_send_tablet_v2_tablet_tool_proximity_out( } } +void wlr_send_tablet_v2_tablet_tool_pressure( + struct wlr_tablet_v2_tablet_tool *tool, uint32_t pressure) { + if (tool->current_client) { + zwp_tablet_tool_v2_send_pressure(tool->current_client->resource, + pressure); + + queue_tool_frame(tool->current_client); + } +} + void wlr_send_tablet_v2_tablet_tool_distance( struct wlr_tablet_v2_tablet_tool *tool, uint32_t distance) { if (tool->current_client) { @@ -1234,6 +1244,42 @@ void wlr_send_tablet_v2_tablet_tool_distance( } } +void wlr_send_tablet_v2_tablet_tool_tilt( + struct wlr_tablet_v2_tablet_tool *tool, double x, double y) { + if (!tool->current_client) { + return; + } + + zwp_tablet_tool_v2_send_tilt(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_rotation( + struct wlr_tablet_v2_tablet_tool *tool, double degrees) { + if (!tool->current_client) { + return; + } + + zwp_tablet_tool_v2_send_rotation(tool->current_client->resource, + wl_fixed_from_double(degrees)); + + queue_tool_frame(tool->current_client); +} + +void wlr_send_tablet_v2_tablet_tool_slider( + struct wlr_tablet_v2_tablet_tool *tool, int32_t position) { + if (!tool->current_client) { + return; + } + + zwp_tablet_tool_v2_send_slider(tool->current_client->resource, + position); + + queue_tool_frame(tool->current_client); +} + uint32_t wlr_send_tablet_v2_tablet_tool_button( struct wlr_tablet_v2_tablet_tool *tool, uint32_t button, enum zwp_tablet_pad_v2_button_state state) { @@ -1262,6 +1308,37 @@ void wlr_send_tablet_v2_tablet_tool_wheel( } } +uint32_t wlr_send_tablet_v2_tablet_tool_down(struct wlr_tablet_v2_tablet_tool *tool) { + if (tool->is_down) { + return 0; + } + + tool->is_down = true; + if (tool->current_client) { + uint32_t serial = ++tool->down_serial; + + zwp_tablet_tool_v2_send_down(tool->current_client->resource, + serial); + queue_tool_frame(tool->current_client); + + return serial; + } + + return 0; +} + +void wlr_send_tablet_v2_tablet_tool_up(struct wlr_tablet_v2_tablet_tool *tool) { + if (!tool->is_down) { + return; + } + tool->is_down = false; + + if (tool->current_client) { + zwp_tablet_tool_v2_send_up(tool->current_client->resource); + queue_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, -- cgit v1.2.3 From fa39fd178dd276316c37b9a98e2bfd5e337d4da0 Mon Sep 17 00:00:00 2001 From: Markus Ongyerth Date: Thu, 17 May 2018 13:45:06 +0200 Subject: Split tablet_v2 implementation for easier maintainance --- include/types/wlr_tablet_v2.h | 87 ++++- types/meson.build | 5 +- types/tablet_v2/wlr_tablet_v2.c | 307 ++++++++++++++++++ types/tablet_v2/wlr_tablet_v2_pad.c | 565 +++++++++++++++++++++++++++++++++ types/tablet_v2/wlr_tablet_v2_tablet.c | 128 ++++++++ types/tablet_v2/wlr_tablet_v2_tool.c | 489 ++++++++++++++++++++++++++++ 6 files changed, 1579 insertions(+), 2 deletions(-) create mode 100644 types/tablet_v2/wlr_tablet_v2.c create mode 100644 types/tablet_v2/wlr_tablet_v2_pad.c create mode 100644 types/tablet_v2/wlr_tablet_v2_tablet.c create mode 100644 types/tablet_v2/wlr_tablet_v2_tool.c diff --git a/include/types/wlr_tablet_v2.h b/include/types/wlr_tablet_v2.h index 21e2d962..ca776734 100644 --- a/include/types/wlr_tablet_v2.h +++ b/include/types/wlr_tablet_v2.h @@ -5,16 +5,101 @@ #include #include +struct wlr_tablet_seat_v2 { + struct wl_list link; + struct wlr_seat *wlr_seat; + struct wlr_tablet_manager_v2 *manager; + + struct wl_list tablets; // wlr_tablet_v2_tablet::link + struct wl_list tools; + struct wl_list pads; + + struct wl_list clients; //wlr_tablet_seat_v2_client::link; + + struct wl_listener seat_destroy; +}; + +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_client_destroy; + + struct wl_list tools; //wlr_tablet_tool_client_v2::link + struct wl_list tablets; //wlr_tablet_client_v2::link + struct wl_list pads; //wlr_tablet_pad_client_v2::link +}; + +struct wlr_tablet_client_v2 { + 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 wlr_tablet_pad_client_v2 { + struct wl_list seat_link; + 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; + uint32_t leave_serial; + + size_t button_count; + + size_t group_count; + struct wl_resource **groups; + + size_t ring_count; + struct wl_resource **rings; + + size_t strip_count; + struct wl_resource **strips; +}; + +struct wlr_tablet_tool_client_v2 { + struct wl_list seat_link; + struct wl_list tool_link; + struct wl_client *client; + struct wl_resource *resource; + struct wlr_tablet_v2_tablet_tool *tool; + struct wlr_tablet_seat_client_v2 *seat; + + uint32_t proximity_serial; + + struct wl_event_source *frame_source; +}; + +struct tablet_pad_auxiliary_user_data { + struct wlr_tablet_pad_client_v2 *pad; + size_t index; +}; + struct wlr_tablet_client_v2 *tablet_client_from_resource(struct wl_resource *resource); void destroy_tablet_v2(struct wl_resource *resource); +void add_tablet_client(struct wlr_tablet_seat_client_v2 *seat, struct wlr_tablet_v2_tablet *tablet); void destroy_tablet_pad_v2(struct wl_resource *resource); struct wlr_tablet_pad_client_v2 *tablet_pad_client_from_resource(struct wl_resource *resource); +void add_tablet_pad_client(struct wlr_tablet_seat_client_v2 *seat, struct wlr_tablet_v2_tablet_pad *pad); void destroy_tablet_tool_v2(struct wl_resource *resource); struct wlr_tablet_tool_client_v2 *tablet_tool_client_from_resource(struct wl_resource *resource); +void add_tablet_tool_client(struct wlr_tablet_seat_client_v2 *seat, struct wlr_tablet_v2_tablet_tool *tool); struct wlr_tablet_seat_client_v2 *tablet_seat_client_from_resource(struct wl_resource *resource); -static void wlr_tablet_seat_client_v2_destroy(struct wl_resource *resource); +void wlr_tablet_seat_client_v2_destroy(struct wl_resource *resource); +struct wlr_tablet_seat_v2 *get_or_create_tablet_seat( + struct wlr_tablet_manager_v2 *manager, + struct wlr_seat *wlr_seat); + #endif /* TYPES_WLR_TABLET_V2_H */ diff --git a/types/meson.build b/types/meson.build index 5570d0c5..03f678a1 100644 --- a/types/meson.build +++ b/types/meson.build @@ -43,7 +43,10 @@ lib_wlr_types = static_library( 'wlr_screenshooter.c', 'wlr_server_decoration.c', 'wlr_surface.c', - 'wlr_tablet_v2.c', + 'tablet_v2/wlr_tablet_v2.c', + 'tablet_v2/wlr_tablet_v2_pad.c', + 'tablet_v2/wlr_tablet_v2_tablet.c', + 'tablet_v2/wlr_tablet_v2_tool.c', 'wlr_tablet_pad.c', 'wlr_tablet_tool.c', 'wlr_tablet_tool_tool.c', diff --git a/types/tablet_v2/wlr_tablet_v2.c b/types/tablet_v2/wlr_tablet_v2.c new file mode 100644 index 00000000..45f1dd99 --- /dev/null +++ b/types/tablet_v2/wlr_tablet_v2.c @@ -0,0 +1,307 @@ +#ifndef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 200809L +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "tablet-unstable-v2-protocol.h" + +struct wlr_tablet_manager_client_v2 { + struct wl_list link; + struct wl_client *client; + struct wl_resource *resource; + struct wlr_tablet_manager_v2 *manager; + + struct wl_listener client_destroy; + struct wl_list tablet_seats; // wlr_tablet_seat_client_v2::link +}; + +static void handle_wlr_seat_destroy(struct wl_listener *listener, void *data) { + struct wlr_tablet_seat_v2 *seat = + wl_container_of(listener, seat, seat_destroy); + + wl_list_remove(&seat->link); + wl_list_remove(&seat->seat_destroy.link); + + struct wlr_tablet_seat_client_v2 *client; + struct wlr_tablet_seat_client_v2 *tmp; + wl_list_for_each_safe(client, tmp, &seat->clients, seat_link) { + wlr_tablet_seat_client_v2_destroy(client->resource); + } +} + +static struct wlr_tablet_seat_v2 *create_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); + + tablet_seat->seat_destroy.notify = handle_wlr_seat_destroy; + wl_signal_add(&wlr_seat->events.destroy, &tablet_seat->seat_destroy); + + wl_list_insert(&manager->seats, &tablet_seat->link); + return tablet_seat; +} + +struct wlr_tablet_seat_v2 *get_or_create_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 create_tablet_seat(manager, wlr_seat); +} + +static struct wlr_tablet_manager_client_v2 *tablet_manager_client_from_resource(struct wl_resource *resource); + +static void tablet_seat_destroy(struct wl_client *client, + struct wl_resource *resource) { + wl_resource_destroy(resource); +} + +static struct zwp_tablet_seat_v2_interface seat_impl = { + .destroy = tablet_seat_destroy, +}; + +struct wlr_tablet_seat_client_v2 *tablet_seat_client_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); +} + +void wlr_tablet_seat_client_v2_destroy(struct wl_resource *resource) { + struct wlr_tablet_seat_client_v2 *seat = tablet_seat_client_from_resource(resource); + if (!seat) { + return; + } + + struct wlr_tablet_client_v2 *tablet; + struct wlr_tablet_client_v2 *tmp_tablet; + wl_list_for_each_safe(tablet, tmp_tablet, &seat->tablets, seat_link) { + destroy_tablet_v2(tablet->resource); + } + + struct wlr_tablet_pad_client_v2 *pad; + struct wlr_tablet_pad_client_v2 *tmp_pad; + wl_list_for_each_safe(pad, tmp_pad, &seat->pads, seat_link) { + destroy_tablet_pad_v2(pad->resource); + } + + struct wlr_tablet_tool_client_v2 *tool; + struct wlr_tablet_tool_client_v2 *tmp_tool; + wl_list_for_each_safe(tool, tmp_tool, &seat->tools, seat_link) { + destroy_tablet_tool_v2(tool->resource); + } + + wl_list_remove(&seat->seat_client_destroy.link); + + free(seat); + wl_resource_set_user_data(resource, NULL); +} + +static void handle_seat_client_destroy(struct wl_listener *listener, void *data) { + struct wlr_tablet_seat_client_v2 *seat = + wl_container_of(listener, seat, seat_client_destroy); + wlr_tablet_seat_client_v2_destroy(seat->resource); +} + +static void tablet_manager_destroy(struct wl_client *client, + struct wl_resource *resource) { + wl_resource_destroy(resource); +} + +static void get_tablet_seat(struct wl_client *wl_client, struct wl_resource *resource, + uint32_t id, struct wl_resource *seat_resource) +{ + struct wlr_tablet_manager_client_v2 *manager = tablet_manager_client_from_resource(resource); + if (!manager) { + /* Inert manager, just set up the resource for later + * destruction, without allocations or advertising things + */ + wl_resource_set_implementation(seat_resource, &seat_impl, NULL, + wlr_tablet_seat_client_v2_destroy); + return; + } + struct wlr_seat_client *seat = wlr_seat_client_from_resource(seat_resource); + struct wlr_tablet_seat_v2 *tablet_seat = + get_or_create_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; + } + + seat_client->resource = + wl_resource_create(wl_client, &zwp_tablet_seat_v2_interface, 1, id); + 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); + + seat_client->seat_client_destroy.notify = handle_seat_client_destroy; + wl_signal_add(&seat->events.destroy, &seat_client->seat_client_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); + } + + 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 = { + .get_tablet_seat = get_tablet_seat, + .destroy = tablet_manager_destroy, +}; + +static struct wlr_tablet_manager_client_v2 *tablet_manager_client_from_resource ( + struct wl_resource *resource) { + assert(wl_resource_instance_of(resource, &zwp_tablet_manager_v2_interface, + &manager_impl)); + return wl_resource_get_user_data(resource); +} + +static void wlr_tablet_manager_v2_destroy(struct wl_resource *resource) { + struct wlr_tablet_manager_client_v2 *client = tablet_manager_client_from_resource(resource); + if (!client) { + return; + } + + struct wlr_tablet_seat_client_v2 *pos; + struct wlr_tablet_seat_client_v2 *tmp; + wl_list_for_each_safe(pos, tmp, &client->tablet_seats, client_link) { + wlr_tablet_seat_client_v2_destroy(pos->resource); + } + + wl_list_remove(&client->link); + //wl_list_remove(&client->client_destroy.link); + + free(client); + wl_resource_set_user_data(resource, NULL); +} + +static void tablet_v2_bind(struct wl_client *wl_client, void *data, + uint32_t version, uint32_t id) { + struct wlr_tablet_manager_v2 *manager = data; + assert(wl_client && manager); + + struct wlr_tablet_manager_client_v2 *client = + calloc(1, sizeof(struct wlr_tablet_manager_client_v2)); + if (client == NULL) { + wl_client_post_no_memory(wl_client); + return; + } + + wl_list_init(&client->tablet_seats); + + client->resource = + wl_resource_create(wl_client, &zwp_tablet_manager_v2_interface, version, id); + if (client->resource == NULL) { + free(client); + wl_client_post_no_memory(wl_client); + return; + } + client->client = wl_client; + client->manager = manager; + + wl_resource_set_implementation(client->resource, &manager_impl, client, + wlr_tablet_manager_v2_destroy); + wl_list_insert(&manager->clients, &client->link); +} + +static void handle_display_destroy(struct wl_listener *listener, void *data) { + struct wlr_tablet_manager_v2 *tablet = + wl_container_of(listener, tablet, display_destroy); + wlr_tablet_v2_destroy(tablet); +} + +void wlr_tablet_v2_destroy(struct wlr_tablet_manager_v2 *manager) { + struct wlr_tablet_manager_client_v2 *tmp; + struct wlr_tablet_manager_client_v2 *pos; + + wl_list_for_each_safe(pos, tmp, &manager->clients, link) { + wlr_tablet_manager_v2_destroy(pos->resource); + } + + wl_global_destroy(manager->wl_global); + free(manager); +} + +struct wlr_tablet_manager_v2 *wlr_tablet_v2_create(struct wl_display *display) { + struct wlr_tablet_manager_v2 *tablet = + calloc(1, sizeof(struct wlr_tablet_manager_v2)); + if (!tablet) { + return NULL; + } + + 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); + + tablet->wl_global = wl_global_create(display, + &zwp_tablet_manager_v2_interface, 1, tablet, tablet_v2_bind); + if (tablet->wl_global == NULL) { + free(tablet); + return NULL; + } + + return tablet; +} diff --git a/types/tablet_v2/wlr_tablet_v2_pad.c b/types/tablet_v2/wlr_tablet_v2_pad.c new file mode 100644 index 00000000..c3627ef6 --- /dev/null +++ b/types/tablet_v2/wlr_tablet_v2_pad.c @@ -0,0 +1,565 @@ +#ifndef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 200809L +#endif + +#include "tablet-unstable-v2-protocol.h" +#include +#include +#include +#include +#include +#include +#include + +void destroy_tablet_pad_v2(struct wl_resource *resource) { + struct wlr_tablet_pad_client_v2 *pad = + tablet_pad_client_from_resource(resource); + + if (!pad) { + return; + } + + wl_list_remove(&pad->seat_link); + wl_list_remove(&pad->pad_link); + + /* This isn't optimal, if the client destroys the resources in another + * order, it will be disconnected. + * But this makes things *way* easier for us, and (untested) I doubt + * clients will destroy it in another order. + */ + for (size_t i = 0; i < pad->group_count; ++i) { + if (pad->groups[i]) { + wl_resource_destroy(pad->groups[i]); + } + } + free(pad->groups); + + for (size_t i = 0; i < pad->ring_count; ++i) { + if (pad->rings[i]) { + wl_resource_destroy(pad->rings[i]); + } + } + free(pad->rings); + + for (size_t i = 0; i < pad->strip_count; ++i) { + if (pad->strips[i]) { + wl_resource_destroy(pad->strips[i]); + } + } + free(pad->strips); + + free(pad); + wl_resource_set_user_data(resource, NULL); +} + +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 tablet_pad_auxiliary_user_data *aux = wl_resource_get_user_data(resource); + + if (!aux) { + return; + } + + 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, + 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, + struct wl_resource *resource) { + wl_resource_destroy(resource); +} + +static struct zwp_tablet_pad_ring_v2_interface tablet_pad_ring_impl = { + .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 tablet_pad_auxiliary_user_data *aux = wl_resource_get_user_data(resource); + if (!aux) { + return; + } + + 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, + 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, + struct wl_resource *resource) { + wl_resource_destroy(resource); +} + +static struct zwp_tablet_pad_strip_v2_interface tablet_pad_strip_impl = { + .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_pad_client_v2 *pad = tablet_pad_client_from_resource(resource); + if (!pad) { + return; + } + + struct wlr_tablet_v2_event_feedback evt = { + .serial = serial, + .index = button, + .description = description, + }; + + wl_signal_emit(&pad->pad->events.button_feedback, &evt); +} + +static struct zwp_tablet_pad_v2_interface tablet_pad_impl = { + .set_feedback = handle_tablet_pad_v2_set_feedback, + .destroy = handle_tablet_pad_v2_destroy, +}; + +static void destroy_tablet_pad_group_v2(struct wl_resource *resource) { + struct tablet_pad_auxiliary_user_data *aux = wl_resource_get_user_data(resource); + + 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, + 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; + } + 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, + 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); + + 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); + wl_array_release(&button_array); + + 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, 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, user_data, 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]); +} + +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->pad = pad; + + 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); + } + 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; + 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); + + 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); + 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_tablet_pad_create( + 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_create_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->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); + + 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); + } + + wl_signal_init(&pad->events.button_feedback); + wl_signal_init(&pad->events.strip_feedback); + wl_signal_init(&pad->events.ring_feedback); + + return pad; +} + +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); +} + +/* Actual protocol foo */ +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 = NULL; + struct wlr_tablet_pad_client_v2 *pad_client = NULL; + 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; +} + +bool wlr_surface_accepts_tablet_v2(struct wlr_tablet_v2_tablet *tablet, + struct wlr_surface *surface) { + struct wl_client *client = wl_resource_get_client(surface->resource); + + if (tablet->current_client && + tablet->current_client->client == client) { + return true; + } + + struct wlr_tablet_client_v2 *tablet_tmp; + wl_list_for_each(tablet_tmp, &tablet->clients, tablet_link) { + if (tablet_tmp->client == client) { + return true; + } + } + + return false; +} diff --git a/types/tablet_v2/wlr_tablet_v2_tablet.c b/types/tablet_v2/wlr_tablet_v2_tablet.c new file mode 100644 index 00000000..1bca6e34 --- /dev/null +++ b/types/tablet_v2/wlr_tablet_v2_tablet.c @@ -0,0 +1,128 @@ +#ifndef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 200809L +#endif + +#include "tablet-unstable-v2-protocol.h" +#include +#include +#include +#include +#include +#include +#include + +void destroy_tablet_v2(struct wl_resource *resource) { + struct wlr_tablet_client_v2 *tablet = tablet_client_from_resource(resource); + + if (!tablet) { + return; + } + + wl_list_remove(&tablet->seat_link); + wl_list_remove(&tablet->tablet_link); + free(tablet); + wl_resource_set_user_data(resource, NULL); +} + +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 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); +} + +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) { + assert(wlr_device->type == WLR_INPUT_DEVICE_TABLET_TOOL); + struct wlr_tablet_seat_v2 *seat = get_or_create_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; +} + + +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); + 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); + + client->client = seat->wl_client; + wl_list_insert(&seat->tablets, &client->seat_link); + wl_list_insert(&tablet->clients, &client->tablet_link); +} + + +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); +} diff --git a/types/tablet_v2/wlr_tablet_v2_tool.c b/types/tablet_v2/wlr_tablet_v2_tool.c new file mode 100644 index 00000000..1f39f12a --- /dev/null +++ b/types/tablet_v2/wlr_tablet_v2_tool.c @@ -0,0 +1,489 @@ +#ifndef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 200809L +#endif + +#include "tablet-unstable-v2-protocol.h" +#include +#include +#include +#include +#include +#include +#include + +static const struct wlr_surface_role pointer_cursor_surface_role = { + .name = "wl_pointer-cursor", +}; + +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 = tablet_tool_client_from_resource(resource); + if (!tool) { + return; + } + + struct wlr_surface *surface = NULL; + if (surface_resource != NULL) { + surface = wlr_surface_from_resource(surface_resource); + if (!wlr_surface_set_role(surface, &pointer_cursor_surface_role, NULL, + surface_resource, WL_POINTER_ERROR_ROLE)) { + return; + } + } + + struct wlr_tablet_v2_event_cursor evt = { + .surface = surface, + .serial = serial, + .hotspot_x = hotspot_x, + .hotspot_y = hotspot_y, + .seat_client = tool->seat->seat, + }; + + 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 = handle_tablet_tool_v2_set_cursor, + .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"); +} + +void destroy_tablet_tool_v2(struct wl_resource *resource) { + struct wlr_tablet_tool_client_v2 *client = + tablet_tool_client_from_resource(resource); + + if (!client) { + return; + } + + if (client->frame_source) { + wl_event_source_remove(client->frame_source); + } + + if (client->tool && client->tool->current_client == client) { + client->tool->current_client = NULL; + } + + wl_list_remove(&client->seat_link); + wl_list_remove(&client->tool_link); + free(client); + + wl_resource_set_user_data(resource, NULL); +} + +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->tool = tool; + client->seat = seat; + + 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, destroy_tablet_tool_v2); + 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); +} + +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); + pos->tool = NULL; + } + + 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_tablet_tool_create( + 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_create_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); + } + + wl_signal_init(&tool->events.set_cursor); + + return tool; +} + +struct wlr_tablet_tool_client_v2 *tablet_tool_client_from_resource(struct wl_resource *resource) { + assert(wl_resource_instance_of(resource, &zwp_tablet_tool_v2_interface, + &tablet_tool_impl)); + return wl_resource_get_user_data(resource); +} + + +/* Actual protocol foo */ +// https://www.geeksforgeeks.org/move-zeroes-end-array/ +static size_t push_zeroes_to_end(uint32_t arr[], size_t n) { + size_t count = 0; + + for (size_t i = 0; i < n; i++) { + if (arr[i] != 0) { + arr[count++] = arr[i]; + } + } + + size_t ret = count; + + while (count < n) { + arr[count++] = 0; + } + + return ret; +} + +static void tablet_tool_button_update(struct wlr_tablet_v2_tablet_tool *tool, + uint32_t button, enum zwp_tablet_pad_v2_button_state state) { + bool found = false; + size_t i = 0; + for (; i < tool->num_buttons; ++i) { + if (tool->pressed_buttons[i] == button) { + found = true; + break; + } + } + + if (button == ZWP_TABLET_PAD_V2_BUTTON_STATE_PRESSED && !found && + tool->num_buttons < WLR_TABLEt_V2_TOOL_BUTTONS_CAP) { + tool->pressed_buttons[tool->num_buttons++] = button; + } + if (button == ZWP_TABLET_PAD_V2_BUTTON_STATE_RELEASED && found) { + tool->pressed_buttons[i] = 0; + tool->num_buttons = push_zeroes_to_end(tool->pressed_buttons, WLR_TABLEt_V2_TOOL_BUTTONS_CAP); + } + + assert(tool->num_buttons <= WLR_TABLEt_V2_TOOL_BUTTONS_CAP); +} + +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) { + struct wl_display *display = wl_client_get_display(tool->client); + struct wl_event_loop *loop = wl_display_get_event_loop(display); + if (!tool->frame_source) { + tool->frame_source = + wl_event_loop_add_idle(loop, 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); + + if (tool->focused_surface == surface) { + return 0; + } + + 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 = NULL; + struct wlr_tablet_tool_client_v2 *tool_client = NULL; + 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); + + tool->focused_surface = surface; + 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); + } + tool->current_client = NULL; + } +} + +void wlr_send_tablet_v2_tablet_tool_pressure( + struct wlr_tablet_v2_tablet_tool *tool, uint32_t pressure) { + if (tool->current_client) { + zwp_tablet_tool_v2_send_pressure(tool->current_client->resource, + pressure); + + queue_tool_frame(tool->current_client); + } +} + +void wlr_send_tablet_v2_tablet_tool_distance( + struct wlr_tablet_v2_tablet_tool *tool, uint32_t distance) { + if (tool->current_client) { + zwp_tablet_tool_v2_send_distance(tool->current_client->resource, + distance); + + queue_tool_frame(tool->current_client); + } +} + +void wlr_send_tablet_v2_tablet_tool_tilt( + struct wlr_tablet_v2_tablet_tool *tool, double x, double y) { + if (!tool->current_client) { + return; + } + + zwp_tablet_tool_v2_send_tilt(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_rotation( + struct wlr_tablet_v2_tablet_tool *tool, double degrees) { + if (!tool->current_client) { + return; + } + + zwp_tablet_tool_v2_send_rotation(tool->current_client->resource, + wl_fixed_from_double(degrees)); + + queue_tool_frame(tool->current_client); +} + +void wlr_send_tablet_v2_tablet_tool_slider( + struct wlr_tablet_v2_tablet_tool *tool, int32_t position) { + if (!tool->current_client) { + return; + } + + zwp_tablet_tool_v2_send_slider(tool->current_client->resource, + position); + + queue_tool_frame(tool->current_client); +} + +uint32_t wlr_send_tablet_v2_tablet_tool_button( + struct wlr_tablet_v2_tablet_tool *tool, uint32_t button, + enum zwp_tablet_pad_v2_button_state state) { + tablet_tool_button_update(tool, button, state); + + if (tool->current_client) { + uint32_t serial = ++tool->button_serial; + + zwp_tablet_tool_v2_send_button(tool->current_client->resource, + serial, button, state); + queue_tool_frame(tool->current_client); + + return serial; + } + + return 0; +} + +void wlr_send_tablet_v2_tablet_tool_wheel( + struct wlr_tablet_v2_tablet_tool *tool, double delta, int32_t clicks) { + if (tool->current_client) { + zwp_tablet_tool_v2_send_wheel(tool->current_client->resource, + clicks, delta); + + queue_tool_frame(tool->current_client); + } +} + +uint32_t wlr_send_tablet_v2_tablet_tool_down(struct wlr_tablet_v2_tablet_tool *tool) { + if (tool->is_down) { + return 0; + } + + tool->is_down = true; + if (tool->current_client) { + uint32_t serial = ++tool->down_serial; + + zwp_tablet_tool_v2_send_down(tool->current_client->resource, + serial); + queue_tool_frame(tool->current_client); + + return serial; + } + + return 0; +} + +void wlr_send_tablet_v2_tablet_tool_up(struct wlr_tablet_v2_tablet_tool *tool) { + if (!tool->is_down) { + return; + } + tool->is_down = false; + + if (tool->current_client) { + zwp_tablet_tool_v2_send_up(tool->current_client->resource); + queue_tool_frame(tool->current_client); + } +} + -- cgit v1.2.3 From 88a4b908d1e798a5276817c3f18d29d61298b7ba Mon Sep 17 00:00:00 2001 From: Markus Ongyerth Date: Thu, 17 May 2018 13:46:45 +0200 Subject: Hide pad auxiliary data in .c file --- include/types/wlr_tablet_v2.h | 6 ------ types/tablet_v2/wlr_tablet_v2_pad.c | 5 +++++ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/include/types/wlr_tablet_v2.h b/include/types/wlr_tablet_v2.h index ca776734..a59c014f 100644 --- a/include/types/wlr_tablet_v2.h +++ b/include/types/wlr_tablet_v2.h @@ -78,12 +78,6 @@ struct wlr_tablet_tool_client_v2 { struct wl_event_source *frame_source; }; -struct tablet_pad_auxiliary_user_data { - struct wlr_tablet_pad_client_v2 *pad; - size_t index; -}; - - struct wlr_tablet_client_v2 *tablet_client_from_resource(struct wl_resource *resource); void destroy_tablet_v2(struct wl_resource *resource); void add_tablet_client(struct wlr_tablet_seat_client_v2 *seat, struct wlr_tablet_v2_tablet *tablet); diff --git a/types/tablet_v2/wlr_tablet_v2_pad.c b/types/tablet_v2/wlr_tablet_v2_pad.c index c3627ef6..4dc408d8 100644 --- a/types/tablet_v2/wlr_tablet_v2_pad.c +++ b/types/tablet_v2/wlr_tablet_v2_pad.c @@ -11,6 +11,11 @@ #include #include +struct tablet_pad_auxiliary_user_data { + struct wlr_tablet_pad_client_v2 *pad; + size_t index; +}; + void destroy_tablet_pad_v2(struct wl_resource *resource) { struct wlr_tablet_pad_client_v2 *pad = tablet_pad_client_from_resource(resource); -- cgit v1.2.3 From 25c28081531979141cff41fd689cb52ff269d712 Mon Sep 17 00:00:00 2001 From: Markus Ongyerth Date: Thu, 17 May 2018 14:23:17 +0200 Subject: Clean up serial handling --- include/types/wlr_tablet_v2.h | 6 --- include/wlr/types/wlr_tablet_v2.h | 59 +++++++++++++------------- types/tablet_v2/wlr_tablet_v2.c | 4 +- types/tablet_v2/wlr_tablet_v2_pad.c | 18 +++----- types/tablet_v2/wlr_tablet_v2_tablet.c | 1 - types/tablet_v2/wlr_tablet_v2_tool.c | 75 +++++++++++++++++++++------------- 6 files changed, 84 insertions(+), 79 deletions(-) diff --git a/include/types/wlr_tablet_v2.h b/include/types/wlr_tablet_v2.h index a59c014f..f2d9b8e4 100644 --- a/include/types/wlr_tablet_v2.h +++ b/include/types/wlr_tablet_v2.h @@ -49,10 +49,6 @@ struct wlr_tablet_pad_client_v2 { struct wl_resource *resource; struct wlr_tablet_v2_tablet_pad *pad; - uint32_t enter_serial; - uint32_t mode_serial; - uint32_t leave_serial; - size_t button_count; size_t group_count; @@ -73,8 +69,6 @@ struct wlr_tablet_tool_client_v2 { struct wlr_tablet_v2_tablet_tool *tool; struct wlr_tablet_seat_client_v2 *seat; - uint32_t proximity_serial; - struct wl_event_source *frame_source; }; diff --git a/include/wlr/types/wlr_tablet_v2.h b/include/wlr/types/wlr_tablet_v2.h index 3268c0b5..18fafcc3 100644 --- a/include/wlr/types/wlr_tablet_v2.h +++ b/include/wlr/types/wlr_tablet_v2.h @@ -47,11 +47,12 @@ struct wlr_tablet_v2_tablet_tool { struct wl_listener surface_destroy; struct wl_listener client_destroy; - uint32_t down_serial; + uint32_t proximity_serial; bool is_down; - uint32_t button_serial; + uint32_t down_serial; size_t num_buttons; uint32_t pressed_buttons[WLR_TABLEt_V2_TOOL_BUTTONS_CAP]; + uint32_t pressed_serials[WLR_TABLEt_V2_TOOL_BUTTONS_CAP]; struct { struct wl_signal set_cursor; // struct wlr_tablet_v2_event_cursor @@ -93,42 +94,42 @@ struct wlr_tablet_v2_event_feedback { }; 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_manager_v2 *manager, + struct wlr_seat *wlr_seat, + struct wlr_input_device *wlr_device); 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_manager_v2 *manager, + struct wlr_seat *wlr_seat, + struct wlr_input_device *wlr_device); 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); + 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); -uint32_t wlr_send_tablet_v2_tablet_tool_proximity_in( +void 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); -uint32_t wlr_send_tablet_v2_tablet_tool_down(struct wlr_tablet_v2_tablet_tool *tool); +void wlr_send_tablet_v2_tablet_tool_down(struct wlr_tablet_v2_tablet_tool *tool); void wlr_send_tablet_v2_tablet_tool_up(struct wlr_tablet_v2_tablet_tool *tool); void wlr_send_tablet_v2_tablet_tool_motion( - struct wlr_tablet_v2_tablet_tool *tool, double x, double y); + struct wlr_tablet_v2_tablet_tool *tool, double x, double y); void wlr_send_tablet_v2_tablet_tool_pressure( - struct wlr_tablet_v2_tablet_tool *tool, uint32_t pressure); + struct wlr_tablet_v2_tablet_tool *tool, uint32_t pressure); void wlr_send_tablet_v2_tablet_tool_distance( struct wlr_tablet_v2_tablet_tool *tool, uint32_t distance); void wlr_send_tablet_v2_tablet_tool_tilt( - struct wlr_tablet_v2_tablet_tool *tool, double x, double y); + struct wlr_tablet_v2_tablet_tool *tool, double x, double y); void wlr_send_tablet_v2_tablet_tool_rotation( struct wlr_tablet_v2_tablet_tool *tool, double degrees); @@ -142,30 +143,30 @@ void wlr_send_tablet_v2_tablet_tool_wheel( void wlr_send_tablet_v2_tablet_tool_proximity_out( struct wlr_tablet_v2_tablet_tool *tool); -uint32_t wlr_send_tablet_v2_tablet_tool_button( - struct wlr_tablet_v2_tablet_tool *tool, uint32_t button, - enum zwp_tablet_pad_v2_button_state state); +void wlr_send_tablet_v2_tablet_tool_button( + struct wlr_tablet_v2_tablet_tool *tool, uint32_t button, + enum zwp_tablet_pad_v2_button_state state); 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 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); + 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); + 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 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); + 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); + size_t group, uint32_t mode, uint32_t time); bool wlr_surface_accepts_tablet_v2(struct wlr_tablet_v2_tablet *tablet, - struct wlr_surface *surface); + struct wlr_surface *surface); #endif /* WLR_TYPES_WLR_TABLET_V2_H */ diff --git a/types/tablet_v2/wlr_tablet_v2.c b/types/tablet_v2/wlr_tablet_v2.c index 45f1dd99..1ac60e17 100644 --- a/types/tablet_v2/wlr_tablet_v2.c +++ b/types/tablet_v2/wlr_tablet_v2.c @@ -77,8 +77,6 @@ struct wlr_tablet_seat_v2 *get_or_create_tablet_seat( return create_tablet_seat(manager, wlr_seat); } -static struct wlr_tablet_manager_client_v2 *tablet_manager_client_from_resource(struct wl_resource *resource); - static void tablet_seat_destroy(struct wl_client *client, struct wl_resource *resource) { wl_resource_destroy(resource); @@ -136,6 +134,8 @@ static void tablet_manager_destroy(struct wl_client *client, wl_resource_destroy(resource); } +static struct wlr_tablet_manager_client_v2 *tablet_manager_client_from_resource(struct wl_resource *resource); + static void get_tablet_seat(struct wl_client *wl_client, struct wl_resource *resource, uint32_t id, struct wl_resource *seat_resource) { diff --git a/types/tablet_v2/wlr_tablet_v2_pad.c b/types/tablet_v2/wlr_tablet_v2_pad.c index 4dc408d8..f86dd77e 100644 --- a/types/tablet_v2/wlr_tablet_v2_pad.c +++ b/types/tablet_v2/wlr_tablet_v2_pad.c @@ -323,7 +323,6 @@ static void handle_wlr_tablet_pad_destroy(struct wl_listener *listener, void *da 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); for (size_t i = 0; i < pos->group_count; ++i) { @@ -441,7 +440,7 @@ uint32_t wlr_send_tablet_v2_tablet_pad_enter( /* 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; + uint32_t serial = wl_display_next_serial(wl_client_get_display(client)); zwp_tablet_pad_v2_send_enter(pad_client->resource, serial, tablet_client->resource, surface->resource); @@ -512,15 +511,12 @@ void wlr_send_tablet_v2_tablet_pad_ring(struct wlr_tablet_v2_tablet_pad *pad, 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) { + struct wl_client *client = wl_resource_get_client(surface->resource); + if (!pad->current_client || client != 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; + uint32_t serial = wl_display_next_serial(wl_client_get_display(client)); zwp_tablet_pad_v2_send_leave(pad->current_client->resource, serial, surface->resource); return serial; @@ -540,10 +536,8 @@ uint32_t wlr_send_tablet_v2_tablet_pad_mode(struct wlr_tablet_v2_tablet_pad *pad 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; + struct wl_client *client = wl_resource_get_client(pad->current_client->resource); + uint32_t serial = wl_display_next_serial(wl_client_get_display(client)); zwp_tablet_pad_group_v2_send_mode_switch( pad->current_client->groups[group], time, serial, mode); diff --git a/types/tablet_v2/wlr_tablet_v2_tablet.c b/types/tablet_v2/wlr_tablet_v2_tablet.c index 1bca6e34..5ddbcbf6 100644 --- a/types/tablet_v2/wlr_tablet_v2_tablet.c +++ b/types/tablet_v2/wlr_tablet_v2_tablet.c @@ -40,7 +40,6 @@ static void handle_wlr_tablet_destroy(struct wl_listener *listener, void *data) 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); } diff --git a/types/tablet_v2/wlr_tablet_v2_tool.c b/types/tablet_v2/wlr_tablet_v2_tool.c index 1f39f12a..0532134d 100644 --- a/types/tablet_v2/wlr_tablet_v2_tool.c +++ b/types/tablet_v2/wlr_tablet_v2_tool.c @@ -178,7 +178,6 @@ static void handle_wlr_tablet_tool_destroy(struct wl_listener *listener, void *d 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); pos->tool = NULL; } @@ -251,7 +250,7 @@ static size_t push_zeroes_to_end(uint32_t arr[], size_t n) { return ret; } -static void tablet_tool_button_update(struct wlr_tablet_v2_tablet_tool *tool, +static ssize_t tablet_tool_button_update(struct wlr_tablet_v2_tablet_tool *tool, uint32_t button, enum zwp_tablet_pad_v2_button_state state) { bool found = false; size_t i = 0; @@ -264,20 +263,31 @@ static void tablet_tool_button_update(struct wlr_tablet_v2_tablet_tool *tool, if (button == ZWP_TABLET_PAD_V2_BUTTON_STATE_PRESSED && !found && tool->num_buttons < WLR_TABLEt_V2_TOOL_BUTTONS_CAP) { - tool->pressed_buttons[tool->num_buttons++] = button; + i = tool->num_buttons++; + tool->pressed_buttons[i] = button; } if (button == ZWP_TABLET_PAD_V2_BUTTON_STATE_RELEASED && found) { tool->pressed_buttons[i] = 0; + tool->pressed_serials[i] = 0; tool->num_buttons = push_zeroes_to_end(tool->pressed_buttons, WLR_TABLEt_V2_TOOL_BUTTONS_CAP); + tool->num_buttons = push_zeroes_to_end(tool->pressed_serials, WLR_TABLEt_V2_TOOL_BUTTONS_CAP); + i = -1; } assert(tool->num_buttons <= WLR_TABLEt_V2_TOOL_BUTTONS_CAP); + return i; +} + +static inline int64_t timespec_to_msec(const struct timespec *a) { + return (int64_t)a->tv_sec * 1000 + a->tv_nsec / 1000000; } static void send_tool_frame(void *data) { struct wlr_tablet_tool_client_v2 *tool = data; - zwp_tablet_tool_v2_send_frame(tool->resource, 0); + struct timespec now; + clock_gettime(CLOCK_MONOTONIC, &now); + zwp_tablet_tool_v2_send_frame(tool->resource, timespec_to_msec(&now)); tool->frame_source = NULL; } @@ -290,14 +300,14 @@ static void queue_tool_frame(struct wlr_tablet_tool_client_v2 *tool) { } } -uint32_t wlr_send_tablet_v2_tablet_tool_proximity_in( +void 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); if (tool->focused_surface == surface) { - return 0; + return; } struct wlr_tablet_client_v2 *tablet_tmp; @@ -313,7 +323,7 @@ uint32_t wlr_send_tablet_v2_tablet_tool_proximity_in( // the client didn't bind tablet_v2 at all, or not for the relevant // seat if (!tablet_client) { - return 0; + return; } struct wlr_tablet_tool_client_v2 *tool_tmp = NULL; @@ -329,22 +339,28 @@ uint32_t wlr_send_tablet_v2_tablet_tool_proximity_in( // the client didn't bind tablet_v2 at all, or not for the relevant // seat if (!tool_client) { - return 0; + return; } 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; + uint32_t serial = wl_display_next_serial(wl_client_get_display(client)); + tool->focused_surface = surface; + tool->proximity_serial = serial; zwp_tablet_tool_v2_send_proximity_in(tool_client->resource, serial, tablet_client->resource, surface->resource); - queue_tool_frame(tool_client); + /* Send all the pressed buttons */ + for (size_t i = 0; i < tool->num_buttons; ++i) { + wlr_send_tablet_v2_tablet_tool_button(tool, + tool->pressed_buttons[i], + ZWP_TABLET_PAD_V2_BUTTON_STATE_PRESSED); + } + if (tool->is_down) { + wlr_send_tablet_v2_tablet_tool_down(tool); + } - tool->focused_surface = surface; - return serial; + queue_tool_frame(tool_client); } void wlr_send_tablet_v2_tablet_tool_motion( @@ -363,7 +379,6 @@ 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); @@ -428,22 +443,23 @@ void wlr_send_tablet_v2_tablet_tool_slider( queue_tool_frame(tool->current_client); } -uint32_t wlr_send_tablet_v2_tablet_tool_button( +void wlr_send_tablet_v2_tablet_tool_button( struct wlr_tablet_v2_tablet_tool *tool, uint32_t button, enum zwp_tablet_pad_v2_button_state state) { - tablet_tool_button_update(tool, button, state); + ssize_t index = tablet_tool_button_update(tool, button, state); if (tool->current_client) { - uint32_t serial = ++tool->button_serial; + struct wl_client *client = + wl_resource_get_client(tool->current_client->resource); + uint32_t serial = wl_display_next_serial(wl_client_get_display(client)); + if (index >= 0) { + tool->pressed_serials[index] = serial; + } zwp_tablet_tool_v2_send_button(tool->current_client->resource, serial, button, state); queue_tool_frame(tool->current_client); - - return serial; } - - return 0; } void wlr_send_tablet_v2_tablet_tool_wheel( @@ -456,23 +472,23 @@ void wlr_send_tablet_v2_tablet_tool_wheel( } } -uint32_t wlr_send_tablet_v2_tablet_tool_down(struct wlr_tablet_v2_tablet_tool *tool) { +void wlr_send_tablet_v2_tablet_tool_down(struct wlr_tablet_v2_tablet_tool *tool) { if (tool->is_down) { - return 0; + return; } tool->is_down = true; if (tool->current_client) { - uint32_t serial = ++tool->down_serial; + struct wl_client *client = + wl_resource_get_client(tool->current_client->resource); + uint32_t serial = wl_display_next_serial(wl_client_get_display(client)); zwp_tablet_tool_v2_send_down(tool->current_client->resource, serial); queue_tool_frame(tool->current_client); - return serial; + tool->down_serial = serial; } - - return 0; } void wlr_send_tablet_v2_tablet_tool_up(struct wlr_tablet_v2_tablet_tool *tool) { @@ -480,6 +496,7 @@ void wlr_send_tablet_v2_tablet_tool_up(struct wlr_tablet_v2_tablet_tool *tool) { return; } tool->is_down = false; + tool->down_serial = 0; if (tool->current_client) { zwp_tablet_tool_v2_send_up(tool->current_client->resource); -- cgit v1.2.3 From dc525a9c5f65c30d67de21a5cfb0315c0997f756 Mon Sep 17 00:00:00 2001 From: Markus Ongyerth Date: Thu, 17 May 2018 15:21:20 +0200 Subject: Clean up serial handling and automate proximity acompaning events --- include/wlr/types/wlr_tablet_v2.h | 6 +++--- types/tablet_v2/wlr_tablet_v2.c | 2 ++ types/tablet_v2/wlr_tablet_v2_tool.c | 29 +++++++++++++++++++++-------- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/include/wlr/types/wlr_tablet_v2.h b/include/wlr/types/wlr_tablet_v2.h index 18fafcc3..09f7454a 100644 --- a/include/wlr/types/wlr_tablet_v2.h +++ b/include/wlr/types/wlr_tablet_v2.h @@ -8,7 +8,7 @@ #include "tablet-unstable-v2-protocol.h" /* This can probably be even lower,the tools don't have a lot of buttons */ -#define WLR_TABLEt_V2_TOOL_BUTTONS_CAP 16 +#define WLR_TABLET_V2_TOOL_BUTTONS_CAP 16 struct wlr_tablet_client_v2; struct wlr_tablet_tool_client_v2; @@ -51,8 +51,8 @@ struct wlr_tablet_v2_tablet_tool { bool is_down; uint32_t down_serial; size_t num_buttons; - uint32_t pressed_buttons[WLR_TABLEt_V2_TOOL_BUTTONS_CAP]; - uint32_t pressed_serials[WLR_TABLEt_V2_TOOL_BUTTONS_CAP]; + uint32_t pressed_buttons[WLR_TABLET_V2_TOOL_BUTTONS_CAP]; + uint32_t pressed_serials[WLR_TABLET_V2_TOOL_BUTTONS_CAP]; struct { struct wl_signal set_cursor; // struct wlr_tablet_v2_event_cursor diff --git a/types/tablet_v2/wlr_tablet_v2.c b/types/tablet_v2/wlr_tablet_v2.c index 1ac60e17..58945765 100644 --- a/types/tablet_v2/wlr_tablet_v2.c +++ b/types/tablet_v2/wlr_tablet_v2.c @@ -117,6 +117,8 @@ void wlr_tablet_seat_client_v2_destroy(struct wl_resource *resource) { destroy_tablet_tool_v2(tool->resource); } + wl_list_remove(&seat->seat_link); + wl_list_remove(&seat->client_link); wl_list_remove(&seat->seat_client_destroy.link); free(seat); diff --git a/types/tablet_v2/wlr_tablet_v2_tool.c b/types/tablet_v2/wlr_tablet_v2_tool.c index 0532134d..954c98c9 100644 --- a/types/tablet_v2/wlr_tablet_v2_tool.c +++ b/types/tablet_v2/wlr_tablet_v2_tool.c @@ -261,20 +261,22 @@ static ssize_t tablet_tool_button_update(struct wlr_tablet_v2_tablet_tool *tool, } } - if (button == ZWP_TABLET_PAD_V2_BUTTON_STATE_PRESSED && !found && - tool->num_buttons < WLR_TABLEt_V2_TOOL_BUTTONS_CAP) { + if (state == ZWP_TABLET_PAD_V2_BUTTON_STATE_PRESSED && !found && + tool->num_buttons < WLR_TABLET_V2_TOOL_BUTTONS_CAP) { i = tool->num_buttons++; tool->pressed_buttons[i] = button; + tool->pressed_serials[i] = -1; + } else { + i = -1; } - if (button == ZWP_TABLET_PAD_V2_BUTTON_STATE_RELEASED && found) { + if (state == ZWP_TABLET_PAD_V2_BUTTON_STATE_RELEASED && found) { tool->pressed_buttons[i] = 0; tool->pressed_serials[i] = 0; - tool->num_buttons = push_zeroes_to_end(tool->pressed_buttons, WLR_TABLEt_V2_TOOL_BUTTONS_CAP); - tool->num_buttons = push_zeroes_to_end(tool->pressed_serials, WLR_TABLEt_V2_TOOL_BUTTONS_CAP); - i = -1; + tool->num_buttons = push_zeroes_to_end(tool->pressed_buttons, WLR_TABLET_V2_TOOL_BUTTONS_CAP); + tool->num_buttons = push_zeroes_to_end(tool->pressed_serials, WLR_TABLET_V2_TOOL_BUTTONS_CAP); } - assert(tool->num_buttons <= WLR_TABLEt_V2_TOOL_BUTTONS_CAP); + assert(tool->num_buttons <= WLR_TABLET_V2_TOOL_BUTTONS_CAP); return i; } @@ -352,7 +354,7 @@ void wlr_send_tablet_v2_tablet_tool_proximity_in( tablet_client->resource, surface->resource); /* Send all the pressed buttons */ for (size_t i = 0; i < tool->num_buttons; ++i) { - wlr_send_tablet_v2_tablet_tool_button(tool, + wlr_send_tablet_v2_tablet_tool_button(tool, tool->pressed_buttons[i], ZWP_TABLET_PAD_V2_BUTTON_STATE_PRESSED); } @@ -378,12 +380,23 @@ void wlr_send_tablet_v2_tablet_tool_motion( void wlr_send_tablet_v2_tablet_tool_proximity_out( struct wlr_tablet_v2_tablet_tool *tool) { if (tool->current_client) { + for (size_t i = 0; i < tool->num_buttons; ++i) { + zwp_tablet_tool_v2_send_button(tool->current_client->resource, + tool->pressed_serials[i], + tool->pressed_buttons[i], + ZWP_TABLET_PAD_V2_BUTTON_STATE_RELEASED); + } + if (tool->is_down) { + zwp_tablet_tool_v2_send_up(tool->current_client->resource); + } zwp_tablet_tool_v2_send_proximity_out(tool->current_client->resource); if (tool->current_client->frame_source) { wl_event_source_remove(tool->current_client->frame_source); send_tool_frame(tool->current_client); } + tool->current_client = NULL; + tool->focused_surface = NULL; } } -- cgit v1.2.3 From 2bc09d91c3f9c0afe093e77491521da8ed85b4cf Mon Sep 17 00:00:00 2001 From: Markus Ongyerth Date: Sat, 19 May 2018 12:16:11 +0200 Subject: Silent conversion from double to int should be illegal --- include/wlr/types/wlr_tablet_v2.h | 6 +++--- types/tablet_v2/wlr_tablet_v2_tool.c | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/include/wlr/types/wlr_tablet_v2.h b/include/wlr/types/wlr_tablet_v2.h index 09f7454a..85233813 100644 --- a/include/wlr/types/wlr_tablet_v2.h +++ b/include/wlr/types/wlr_tablet_v2.h @@ -123,10 +123,10 @@ 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_pressure( - struct wlr_tablet_v2_tablet_tool *tool, uint32_t pressure); + struct wlr_tablet_v2_tablet_tool *tool, double pressure); void wlr_send_tablet_v2_tablet_tool_distance( - struct wlr_tablet_v2_tablet_tool *tool, uint32_t distance); + struct wlr_tablet_v2_tablet_tool *tool, double distance); void wlr_send_tablet_v2_tablet_tool_tilt( struct wlr_tablet_v2_tablet_tool *tool, double x, double y); @@ -135,7 +135,7 @@ void wlr_send_tablet_v2_tablet_tool_rotation( struct wlr_tablet_v2_tablet_tool *tool, double degrees); void wlr_send_tablet_v2_tablet_tool_slider( - struct wlr_tablet_v2_tablet_tool *tool, int32_t position); + struct wlr_tablet_v2_tablet_tool *tool, double position); void wlr_send_tablet_v2_tablet_tool_wheel( struct wlr_tablet_v2_tablet_tool *tool, double delta, int32_t clicks); diff --git a/types/tablet_v2/wlr_tablet_v2_tool.c b/types/tablet_v2/wlr_tablet_v2_tool.c index 954c98c9..9eefaad7 100644 --- a/types/tablet_v2/wlr_tablet_v2_tool.c +++ b/types/tablet_v2/wlr_tablet_v2_tool.c @@ -401,20 +401,20 @@ void wlr_send_tablet_v2_tablet_tool_proximity_out( } void wlr_send_tablet_v2_tablet_tool_pressure( - struct wlr_tablet_v2_tablet_tool *tool, uint32_t pressure) { + struct wlr_tablet_v2_tablet_tool *tool, double pressure) { if (tool->current_client) { zwp_tablet_tool_v2_send_pressure(tool->current_client->resource, - pressure); + pressure * 65535); queue_tool_frame(tool->current_client); } } void wlr_send_tablet_v2_tablet_tool_distance( - struct wlr_tablet_v2_tablet_tool *tool, uint32_t distance) { + struct wlr_tablet_v2_tablet_tool *tool, double distance) { if (tool->current_client) { zwp_tablet_tool_v2_send_distance(tool->current_client->resource, - distance); + distance * 65535); queue_tool_frame(tool->current_client); } @@ -445,13 +445,13 @@ void wlr_send_tablet_v2_tablet_tool_rotation( } void wlr_send_tablet_v2_tablet_tool_slider( - struct wlr_tablet_v2_tablet_tool *tool, int32_t position) { + struct wlr_tablet_v2_tablet_tool *tool, double position) { if (!tool->current_client) { return; } zwp_tablet_tool_v2_send_slider(tool->current_client->resource, - position); + position * 65535); queue_tool_frame(tool->current_client); } -- cgit v1.2.3 From 3be916f9b8dd697d5876e017b544e3d42c11397e Mon Sep 17 00:00:00 2001 From: Markus Ongyerth Date: Sat, 19 May 2018 14:35:02 +0200 Subject: Add asserts and rename destroy function in libinput backend --- backend/libinput/tablet_tool.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/backend/libinput/tablet_tool.c b/backend/libinput/tablet_tool.c index 5dc0584c..d780330a 100644 --- a/backend/libinput/tablet_tool.c +++ b/backend/libinput/tablet_tool.c @@ -13,6 +13,12 @@ #include "backend/libinput.h" #include "util/signal.h" +static struct wlr_tablet_tool_impl tool_impl; + +static bool tablet_tool_is_libinput(struct wlr_tablet_tool *tool) { + return tool->impl == &tool_impl; +} + struct wlr_libinput_tablet_tool { struct wlr_tablet_tool_tool wlr_tool; @@ -45,7 +51,8 @@ static void destroy_tool_tool(struct wlr_libinput_tablet_tool *tool) { } -static void libinput_tablet_tool_destroy(struct wlr_tablet_tool *tool) { +static void destroy_tablet_tool(struct wlr_tablet_tool *tool) { + assert(tablet_tool_is_libinput(tool)); struct wlr_libinput_tablet *tablet = wl_container_of(tool, tablet, wlr_tool); @@ -65,7 +72,7 @@ static void libinput_tablet_tool_destroy(struct wlr_tablet_tool *tool) { } static struct wlr_tablet_tool_impl tool_impl = { - .destroy = libinput_tablet_tool_destroy, + .destroy = destroy_tablet_tool, }; struct wlr_tablet_tool *create_libinput_tablet_tool( @@ -148,6 +155,7 @@ static struct wlr_libinput_tablet_tool *get_wlr_tablet_tool( static void ensure_tool_reference(struct wlr_libinput_tablet_tool *tool, struct wlr_tablet_tool *wlr_dev) { + assert(tablet_tool_is_libinput(wlr_dev)); struct tablet_tool_list_elem *pos; struct wlr_libinput_tablet *tablet = wl_container_of(wlr_dev, tablet, wlr_tool); @@ -271,6 +279,7 @@ void handle_tablet_tool_proximity(struct libinput_event *event, libinput_event_tablet_tool_get_proximity_state(tevent) == LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT) { // The tool isn't unique, it can't be on multiple tablets assert(tool->pad_refs == 1); + assert(tablet_tool_is_libinput(wlr_dev->tablet_tool)); struct wlr_libinput_tablet *tablet = wl_container_of(wlr_dev->tablet_tool, tablet, wlr_tool); struct tablet_tool_list_elem *pos; -- cgit v1.2.3 From 5cbdd13df838c70e66e511598eb061534392c804 Mon Sep 17 00:00:00 2001 From: Markus Ongyerth Date: Sat, 19 May 2018 14:35:51 +0200 Subject: remove unused wl_listener --- include/wlr/types/wlr_tablet_v2.h | 1 - 1 file changed, 1 deletion(-) diff --git a/include/wlr/types/wlr_tablet_v2.h b/include/wlr/types/wlr_tablet_v2.h index 85233813..872bb425 100644 --- a/include/wlr/types/wlr_tablet_v2.h +++ b/include/wlr/types/wlr_tablet_v2.h @@ -45,7 +45,6 @@ struct wlr_tablet_v2_tablet_tool { struct wlr_tablet_tool_client_v2 *current_client; struct wlr_surface *focused_surface; struct wl_listener surface_destroy; - struct wl_listener client_destroy; uint32_t proximity_serial; bool is_down; -- cgit v1.2.3 From 503f9d6e52c3d78db10e06c00499d8935cc957f5 Mon Sep 17 00:00:00 2001 From: Markus Ongyerth Date: Fri, 25 May 2018 08:33:15 +0200 Subject: emersion feedback Introduce TABLET_MANAGER_VERSION and remove the wlr_tablet_tool_tool.c --- types/meson.build | 1 - types/tablet_v2/wlr_tablet_v2.c | 13 +++++++------ types/wlr_tablet_tool_tool.c | 16 ---------------- 3 files changed, 7 insertions(+), 23 deletions(-) delete mode 100644 types/wlr_tablet_tool_tool.c diff --git a/types/meson.build b/types/meson.build index 03f678a1..0b8584f8 100644 --- a/types/meson.build +++ b/types/meson.build @@ -49,7 +49,6 @@ lib_wlr_types = static_library( 'tablet_v2/wlr_tablet_v2_tool.c', 'wlr_tablet_pad.c', 'wlr_tablet_tool.c', - 'wlr_tablet_tool_tool.c', 'wlr_touch.c', 'wlr_virtual_keyboard_v1.c', 'wlr_wl_shell.c', diff --git a/types/tablet_v2/wlr_tablet_v2.c b/types/tablet_v2/wlr_tablet_v2.c index 58945765..802de77f 100644 --- a/types/tablet_v2/wlr_tablet_v2.c +++ b/types/tablet_v2/wlr_tablet_v2.c @@ -15,13 +15,14 @@ #include #include "tablet-unstable-v2-protocol.h" +#define TABLET_MANAGER_VERSION 1 + struct wlr_tablet_manager_client_v2 { struct wl_list link; struct wl_client *client; struct wl_resource *resource; struct wlr_tablet_manager_v2 *manager; - struct wl_listener client_destroy; struct wl_list tablet_seats; // wlr_tablet_seat_client_v2::link }; @@ -154,7 +155,7 @@ static void get_tablet_seat(struct wl_client *wl_client, struct wl_resource *res struct wlr_tablet_seat_v2 *tablet_seat = get_or_create_tablet_seat(manager->manager, seat->seat); - if (!tablet_seat) {// This can only happen when we ran out of memory + if (!tablet_seat) { // This can only happen when we ran out of memory wl_client_post_no_memory(wl_client); return; } @@ -167,7 +168,7 @@ static void get_tablet_seat(struct wl_client *wl_client, struct wl_resource *res } seat_client->resource = - wl_resource_create(wl_client, &zwp_tablet_seat_v2_interface, 1, id); + wl_resource_create(wl_client, &zwp_tablet_seat_v2_interface, TABLET_MANAGER_VERSION, id); if (seat_client->resource == NULL) { free(seat_client); wl_client_post_no_memory(wl_client); @@ -190,7 +191,7 @@ static void get_tablet_seat(struct wl_client *wl_client, struct wl_resource *res 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 + // We need to emit 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); @@ -232,7 +233,6 @@ static void wlr_tablet_manager_v2_destroy(struct wl_resource *resource) { } wl_list_remove(&client->link); - //wl_list_remove(&client->client_destroy.link); free(client); wl_resource_set_user_data(resource, NULL); @@ -299,7 +299,8 @@ struct wlr_tablet_manager_v2 *wlr_tablet_v2_create(struct wl_display *display) { wl_display_add_destroy_listener(display, &tablet->display_destroy); tablet->wl_global = wl_global_create(display, - &zwp_tablet_manager_v2_interface, 1, tablet, tablet_v2_bind); + &zwp_tablet_manager_v2_interface, TABLET_MANAGER_VERSION, + tablet, tablet_v2_bind); if (tablet->wl_global == NULL) { free(tablet); return NULL; diff --git a/types/wlr_tablet_tool_tool.c b/types/wlr_tablet_tool_tool.c deleted file mode 100644 index fcd38f56..00000000 --- a/types/wlr_tablet_tool_tool.c +++ /dev/null @@ -1,16 +0,0 @@ -#include -#include -#include -#include -#include - -void wlr_tablet_tool_tool_init(struct wlr_tablet_tool_tool *tool) { - // Intentionaly empty (for now) -} - -void wlr_tablet_tool_tool_destroy(struct wlr_tablet_tool_tool *tool) { - if (!tool) { - return; - } - free(tool); -} -- cgit v1.2.3 From 48e2cba9b6d94b549dbd3edcb94183a66e904224 Mon Sep 17 00:00:00 2001 From: Markus Ongyerth Date: Fri, 25 May 2018 10:04:25 +0200 Subject: Handle relative motion for mouse tools --- backend/libinput/tablet_tool.c | 2 ++ include/wlr/types/wlr_tablet_tool.h | 2 ++ rootston/seat.c | 19 +++++++++++++------ 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/backend/libinput/tablet_tool.c b/backend/libinput/tablet_tool.c index d780330a..0dab6795 100644 --- a/backend/libinput/tablet_tool.c +++ b/backend/libinput/tablet_tool.c @@ -204,10 +204,12 @@ void handle_tablet_tool_axis(struct libinput_event *event, if (libinput_event_tablet_tool_x_has_changed(tevent)) { wlr_event.updated_axes |= WLR_TABLET_TOOL_AXIS_X; wlr_event.x = libinput_event_tablet_tool_get_x_transformed(tevent, 1); + wlr_event.dx = libinput_event_tablet_tool_get_dx(tevent); } if (libinput_event_tablet_tool_y_has_changed(tevent)) { wlr_event.updated_axes |= WLR_TABLET_TOOL_AXIS_Y; wlr_event.y = libinput_event_tablet_tool_get_y_transformed(tevent, 1); + wlr_event.dy = libinput_event_tablet_tool_get_dy(tevent); } if (libinput_event_tablet_tool_pressure_has_changed(tevent)) { wlr_event.updated_axes |= WLR_TABLET_TOOL_AXIS_PRESSURE; diff --git a/include/wlr/types/wlr_tablet_tool.h b/include/wlr/types/wlr_tablet_tool.h index 71fa0f82..0a92ffe2 100644 --- a/include/wlr/types/wlr_tablet_tool.h +++ b/include/wlr/types/wlr_tablet_tool.h @@ -79,6 +79,8 @@ struct wlr_event_tablet_tool_axis { uint32_t updated_axes; // From 0..1 double x, y; + // Relative to last event + double dx, dy; double pressure; double distance; double tilt_x, tilt_y; diff --git a/rootston/seat.c b/rootston/seat.c index 56b9c50e..e9bfbdf7 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -104,14 +104,21 @@ static void handle_touch_motion(struct wl_listener *listener, void *data) { static void handle_tablet_tool_position(struct roots_cursor *cursor, struct roots_tablet_tool *tool, struct wlr_tablet_tool_tool *tool_tool, - bool change_x, bool change_y, double x, double y, - uint32_t time) { + bool change_x, bool change_y, + double x, double y, double dx, double dy) { if (!change_x && !change_y) { return; } - wlr_cursor_warp_absolute(cursor->cursor, tool->device, - change_x ? x : NAN, change_y ? y : NAN); + switch (tool_tool->type) { + case WLR_TABLET_TOOL_TYPE_MOUSE: + // They are 0 either way when they weren't modified + wlr_cursor_move(cursor->cursor, tool->device, dx, dy); + break; + default: + wlr_cursor_warp_absolute(cursor->cursor, tool->device, + change_x ? x : NAN, change_y ? y : NAN); + } double sx, sy; struct roots_view *view = NULL; @@ -159,7 +166,7 @@ static void handle_tool_axis(struct wl_listener *listener, void *data) { handle_tablet_tool_position(cursor, event->device->data, event->tool, event->updated_axes & WLR_TABLET_TOOL_AXIS_X, event->updated_axes & WLR_TABLET_TOOL_AXIS_Y, - event->x, event->y, event->time_msec); + event->x, event->y, event->dx, event->dy); if (event->updated_axes & WLR_TABLET_TOOL_AXIS_PRESSURE) { wlr_send_tablet_v2_tablet_tool_pressure(roots_tool->tablet_v2_tool, event->pressure); @@ -271,7 +278,7 @@ static void handle_tool_proximity(struct wl_listener *listener, void *data) { } handle_tablet_tool_position(cursor, event->device->data, event->tool, - true, true, event->x, event->y, event->time_msec); + true, true, event->x, event->y, 0, 0); } static void handle_request_set_cursor(struct wl_listener *listener, -- cgit v1.2.3 From 6b51f3b57a211c5a1ae326596aa82f5a4d0eec9d Mon Sep 17 00:00:00 2001 From: Markus Ongyerth Date: Fri, 1 Jun 2018 12:33:19 +0200 Subject: use previous resource versions and destroy pads --- include/wlr/types/wlr_tablet_v2.h | 4 ++-- types/tablet_v2/wlr_tablet_v2_pad.c | 19 ++++++++++++++----- types/tablet_v2/wlr_tablet_v2_tablet.c | 8 ++++++-- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/include/wlr/types/wlr_tablet_v2.h b/include/wlr/types/wlr_tablet_v2.h index 872bb425..3818132c 100644 --- a/include/wlr/types/wlr_tablet_v2.h +++ b/include/wlr/types/wlr_tablet_v2.h @@ -38,7 +38,7 @@ struct wlr_tablet_v2_tablet { 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_list clients; // wlr_tablet_tool_client_v2::tool_link struct wl_listener tool_destroy; @@ -62,7 +62,7 @@ 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_list clients; // wlr_tablet_pad_client_v2::pad_link size_t group_count; uint32_t *groups; diff --git a/types/tablet_v2/wlr_tablet_v2_pad.c b/types/tablet_v2/wlr_tablet_v2_pad.c index f86dd77e..154e6434 100644 --- a/types/tablet_v2/wlr_tablet_v2_pad.c +++ b/types/tablet_v2/wlr_tablet_v2_pad.c @@ -86,7 +86,7 @@ static void handle_tablet_pad_ring_v2_set_feedback(struct wl_client *client, .serial = serial, .description = description, .index = aux->index - }; + }; wl_signal_emit(&aux->pad->pad->events.ring_feedback, &evt); } @@ -185,8 +185,11 @@ static struct zwp_tablet_pad_group_v2_interface tablet_pad_group_impl = { 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) { + + int version = wl_resource_get_version(client->resource); client->groups[index] = - wl_resource_create(client->client, &zwp_tablet_pad_group_v2_interface, 1, 0); + wl_resource_create(client->client, &zwp_tablet_pad_group_v2_interface, + version, 0); if (!client->groups[index]) { wl_client_post_no_memory(client->client); return; @@ -194,6 +197,7 @@ static void add_tablet_pad_group(struct wlr_tablet_v2_tablet_pad *pad, struct tablet_pad_auxiliary_user_data *user_data = calloc(1, sizeof(struct tablet_pad_auxiliary_user_data)); if (!user_data) { + wl_client_post_no_memory(client->client); return; } user_data->pad = client; @@ -338,6 +342,14 @@ static void handle_wlr_tablet_pad_destroy(struct wl_listener *listener, void *da } } + struct wlr_tablet_pad_client_v2 *client; + struct wlr_tablet_pad_client_v2 *tmp_client; + wl_list_for_each_safe(client, tmp_client, &pad->clients, pad_link) { + zwp_tablet_pad_v2_send_removed(client->resource); + destroy_tablet_pad_v2(client->resource); + + } + wl_list_remove(&pad->clients); wl_list_remove(&pad->link); wl_list_remove(&pad->pad_destroy.link); @@ -437,9 +449,6 @@ uint32_t wlr_send_tablet_v2_tablet_pad_enter( 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 = wl_display_next_serial(wl_client_get_display(client)); zwp_tablet_pad_v2_send_enter(pad_client->resource, serial, diff --git a/types/tablet_v2/wlr_tablet_v2_tablet.c b/types/tablet_v2/wlr_tablet_v2_tablet.c index 5ddbcbf6..3fc6f8b2 100644 --- a/types/tablet_v2/wlr_tablet_v2_tablet.c +++ b/types/tablet_v2/wlr_tablet_v2_tablet.c @@ -2,7 +2,6 @@ #define _POSIX_C_SOURCE 200809L #endif -#include "tablet-unstable-v2-protocol.h" #include #include #include @@ -11,6 +10,8 @@ #include #include +#include "tablet-unstable-v2-protocol.h" + void destroy_tablet_v2(struct wl_resource *resource) { struct wlr_tablet_client_v2 *tablet = tablet_client_from_resource(resource); @@ -92,9 +93,12 @@ void add_tablet_client(struct wlr_tablet_seat_client_v2 *seat, return; } + int version = wl_resource_get_version(seat->resource); client->resource = - wl_resource_create(seat->wl_client, &zwp_tablet_v2_interface, 1, 0); + wl_resource_create(seat->wl_client, &zwp_tablet_v2_interface, + version, 0); if (!client->resource) { + wl_resource_post_no_memory(seat->resource); free(client); return; } -- cgit v1.2.3 From 101080a3828881ebc4e536c13d129220ea41428b Mon Sep 17 00:00:00 2001 From: Markus Ongyerth Date: Wed, 13 Jun 2018 08:11:33 +0200 Subject: Another feedback pass --- rootston/seat.c | 43 +++++++++++++++++++--------------- types/tablet_v2/wlr_tablet_v2_tablet.c | 2 +- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/rootston/seat.c b/rootston/seat.c index e9bfbdf7..e95fa7f4 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -1,15 +1,16 @@ #define _POSIX_C_SOURCE 199309L #include +#include #include #include #include #include -#include #include +#include #include #include -#include #include +#include #include #include "rootston/cursor.h" #include "rootston/input.h" @@ -17,7 +18,6 @@ #include "rootston/seat.h" #include "rootston/xcursor.h" -#include static void handle_keyboard_key(struct wl_listener *listener, void *data) { struct roots_keyboard *keyboard = @@ -169,27 +169,33 @@ static void handle_tool_axis(struct wl_listener *listener, void *data) { event->x, event->y, event->dx, event->dy); if (event->updated_axes & WLR_TABLET_TOOL_AXIS_PRESSURE) { - wlr_send_tablet_v2_tablet_tool_pressure(roots_tool->tablet_v2_tool, event->pressure); + wlr_send_tablet_v2_tablet_tool_pressure( + roots_tool->tablet_v2_tool, event->pressure); } if (event->updated_axes & WLR_TABLET_TOOL_AXIS_DISTANCE) { - wlr_send_tablet_v2_tablet_tool_distance(roots_tool->tablet_v2_tool, event->distance); + wlr_send_tablet_v2_tablet_tool_distance( + roots_tool->tablet_v2_tool, event->distance); } if (event->updated_axes & (WLR_TABLET_TOOL_AXIS_TILT_X | WLR_TABLET_TOOL_AXIS_TILT_Y)) { - wlr_send_tablet_v2_tablet_tool_tilt(roots_tool->tablet_v2_tool, event->tilt_x, event->tilt_y); + wlr_send_tablet_v2_tablet_tool_tilt( + roots_tool->tablet_v2_tool, event->tilt_x, event->tilt_y); } if (event->updated_axes & WLR_TABLET_TOOL_AXIS_ROTATION) { - wlr_send_tablet_v2_tablet_tool_rotation(roots_tool->tablet_v2_tool, event->rotation); + wlr_send_tablet_v2_tablet_tool_rotation( + roots_tool->tablet_v2_tool, event->rotation); } if (event->updated_axes & WLR_TABLET_TOOL_AXIS_SLIDER) { - wlr_send_tablet_v2_tablet_tool_slider(roots_tool->tablet_v2_tool, event->slider); + wlr_send_tablet_v2_tablet_tool_slider( + roots_tool->tablet_v2_tool, event->slider); } if (event->updated_axes & WLR_TABLET_TOOL_AXIS_WHEEL) { - wlr_send_tablet_v2_tablet_tool_wheel(roots_tool->tablet_v2_tool, event->wheel_delta, 0); + wlr_send_tablet_v2_tablet_tool_wheel( + roots_tool->tablet_v2_tool, event->wheel_delta, 0); } } @@ -246,7 +252,7 @@ static void handle_tablet_tool_set_cursor(struct wl_listener *listener, void *da .hotspot_y = evt->hotspot_y, .serial = evt->serial, .seat_client = evt->seat_client, - }; + }; roots_cursor_handle_request_set_cursor(tool->seat->cursor, &event); } @@ -271,7 +277,8 @@ static void handle_tool_proximity(struct wl_listener *listener, void *data) { wl_signal_add(&tool->events.destroy, &roots_tool->tool_destroy); roots_tool->set_cursor.notify = handle_tablet_tool_set_cursor; - wl_signal_add(&roots_tool->tablet_v2_tool->events.set_cursor, &roots_tool->set_cursor); + wl_signal_add(&roots_tool->tablet_v2_tool->events.set_cursor, + &roots_tool->set_cursor); wl_list_init(&roots_tool->link); wl_list_init(&roots_tool->tool_link); @@ -651,7 +658,7 @@ static void handle_pointer_destroy(struct wl_listener *listener, void *data) { static void seat_add_pointer(struct roots_seat *seat, struct wlr_input_device *device) { - struct roots_pointer *pointer = calloc(sizeof(struct roots_pointer), 1); + struct roots_pointer *pointer = calloc(1, sizeof(struct roots_pointer)); if (!pointer) { wlr_log(WLR_ERROR, "could not allocate pointer for seat"); return; @@ -684,7 +691,7 @@ static void handle_touch_destroy(struct wl_listener *listener, void *data) { static void seat_add_touch(struct roots_seat *seat, struct wlr_input_device *device) { - struct roots_touch *touch = calloc(sizeof(struct roots_touch), 1); + struct roots_touch *touch = calloc(1, sizeof(struct roots_touch)); if (!touch) { wlr_log(WLR_ERROR, "could not allocate touch for seat"); return; @@ -743,8 +750,8 @@ static void attach_tablet_pad(struct roots_tablet_pad *pad, wl_list_remove(&pad->tablet_link); wl_list_insert(&tool->pads, &pad->tablet_link); - wl_signal_add(&tool->device->events.destroy, - &pad->tablet_destroy); + pad->tablet_destroy.notify = handle_pad_tool_destroy; + wl_signal_add(&tool->device->events.destroy, &pad->tablet_destroy); } static void handle_tablet_pad_attach(struct wl_listener *listener, void *data) { @@ -794,7 +801,7 @@ static void handle_tablet_pad_button(struct wl_listener *listener, void *data) { static void seat_add_tablet_pad(struct roots_seat *seat, struct wlr_input_device *device) { struct roots_tablet_pad *tablet_pad = - calloc(sizeof(struct roots_tablet_pad), 1); + calloc(1, sizeof(struct roots_tablet_pad)); if (!tablet_pad) { wlr_log(WLR_ERROR, "could not allocate tablet_pad for seat"); return; @@ -810,8 +817,6 @@ static void seat_add_tablet_pad(struct roots_seat *seat, 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); @@ -869,7 +874,7 @@ static void handle_tablet_tool_destroy(struct wl_listener *listener, static void seat_add_tablet_tool(struct roots_seat *seat, struct wlr_input_device *device) { struct roots_tablet_tool *tablet_tool = - calloc(sizeof(struct roots_tablet_tool), 1); + calloc(1, sizeof(struct roots_tablet_tool)); if (!tablet_tool) { wlr_log(WLR_ERROR, "could not allocate tablet_tool for seat"); return; diff --git a/types/tablet_v2/wlr_tablet_v2_tablet.c b/types/tablet_v2/wlr_tablet_v2_tablet.c index 3fc6f8b2..d3ef4de0 100644 --- a/types/tablet_v2/wlr_tablet_v2_tablet.c +++ b/types/tablet_v2/wlr_tablet_v2_tablet.c @@ -93,7 +93,7 @@ void add_tablet_client(struct wlr_tablet_seat_client_v2 *seat, return; } - int version = wl_resource_get_version(seat->resource); + uint32_t version = wl_resource_get_version(seat->resource); client->resource = wl_resource_create(seat->wl_client, &zwp_tablet_v2_interface, version, 0); -- cgit v1.2.3 From b84288af16f56295a66d58bdb41b7ba7c4dd54f3 Mon Sep 17 00:00:00 2001 From: Markus Ongyerth Date: Thu, 14 Jun 2018 11:56:14 +0200 Subject: Remove unused tablet_pad list from tools --- include/rootston/seat.h | 3 --- rootston/seat.c | 8 -------- 2 files changed, 11 deletions(-) diff --git a/include/rootston/seat.h b/include/rootston/seat.h index 258c8840..071103cf 100644 --- a/include/rootston/seat.h +++ b/include/rootston/seat.h @@ -89,13 +89,10 @@ struct roots_tablet_tool { 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; diff --git a/rootston/seat.c b/rootston/seat.c index e95fa7f4..5bd6e752 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -719,7 +719,6 @@ static void handle_tablet_pad_destroy(struct wl_listener *listener, 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); @@ -734,8 +733,6 @@ static void handle_pad_tool_destroy(struct wl_listener *listener, void *data) { 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); @@ -747,8 +744,6 @@ static void attach_tablet_pad(struct roots_tablet_pad *pad, pad->device->name, tool->device->name); pad->tablet = tool; - wl_list_remove(&pad->tablet_link); - wl_list_insert(&tool->pads, &pad->tablet_link); pad->tablet_destroy.notify = handle_pad_tool_destroy; wl_signal_add(&tool->device->events.destroy, &pad->tablet_destroy); @@ -810,7 +805,6 @@ static void seat_add_tablet_pad(struct roots_seat *seat, 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; @@ -865,7 +859,6 @@ 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); @@ -883,7 +876,6 @@ 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; -- cgit v1.2.3 From d9e978e1b379c811c47f4b3b75f1ec186a640ff7 Mon Sep 17 00:00:00 2001 From: Markus Ongyerth Date: Sat, 16 Jun 2018 11:19:48 +0200 Subject: rename wlr_tablet_tool to wlr_tablet The previous naming was based on the input-device capability names from libinput. With code that uses the libinput_tablet_tool and mapping into tablet-v2, this is confusing, so the name is changed to follow the names used in the protocol. --- backend/headless/input_device.c | 8 ++-- backend/libinput/events.c | 4 +- backend/libinput/tablet_tool.c | 71 ++++++++++++++++---------------- examples/tablet.c | 6 +-- include/backend/libinput.h | 2 +- include/wlr/interfaces/wlr_tablet_tool.h | 10 ++--- include/wlr/types/wlr_input_device.h | 2 +- include/wlr/types/wlr_tablet_tool.h | 18 ++++---- include/wlr/types/wlr_tablet_v2.h | 6 +-- rootston/seat.c | 4 +- types/tablet_v2/wlr_tablet_v2_tablet.c | 13 +++--- types/tablet_v2/wlr_tablet_v2_tool.c | 2 +- types/wlr_cursor.c | 8 ++-- types/wlr_input_device.c | 2 +- types/wlr_tablet_tool.c | 28 ++++++------- 15 files changed, 93 insertions(+), 91 deletions(-) diff --git a/backend/headless/input_device.c b/backend/headless/input_device.c index e0411c27..a2474aeb 100644 --- a/backend/headless/input_device.c +++ b/backend/headless/input_device.c @@ -60,12 +60,12 @@ struct wlr_input_device *wlr_headless_add_input_device( wlr_touch_init(wlr_device->touch, NULL); break; case WLR_INPUT_DEVICE_TABLET_TOOL: - wlr_device->tablet_tool = calloc(1, sizeof(struct wlr_tablet_tool)); - if (wlr_device->tablet_tool == NULL) { - wlr_log(WLR_ERROR, "Unable to allocate wlr_tablet_tool"); + wlr_device->tablet = calloc(1, sizeof(struct wlr_tablet)); + if (wlr_device->tablet == NULL) { + wlr_log(WLR_ERROR, "Unable to allocate wlr_tablet"); goto error; } - wlr_tablet_tool_init(wlr_device->tablet_tool, NULL); + wlr_tablet_init(wlr_device->tablet, NULL); break; case WLR_INPUT_DEVICE_TABLET_PAD: wlr_device->tablet_pad = calloc(1, sizeof(struct wlr_tablet_pad)); diff --git a/backend/libinput/events.c b/backend/libinput/events.c index 93664af2..0548e502 100644 --- a/backend/libinput/events.c +++ b/backend/libinput/events.c @@ -130,8 +130,8 @@ static void handle_device_added(struct wlr_libinput_backend *backend, if (!wlr_dev) { goto fail; } - wlr_dev->tablet_tool = create_libinput_tablet_tool(libinput_dev); - if (!wlr_dev->tablet_tool) { + wlr_dev->tablet = create_libinput_tablet(libinput_dev); + if (!wlr_dev->tablet) { free(wlr_dev); goto fail; } diff --git a/backend/libinput/tablet_tool.c b/backend/libinput/tablet_tool.c index 0dab6795..563338b8 100644 --- a/backend/libinput/tablet_tool.c +++ b/backend/libinput/tablet_tool.c @@ -13,14 +13,14 @@ #include "backend/libinput.h" #include "util/signal.h" -static struct wlr_tablet_tool_impl tool_impl; +static struct wlr_tablet_impl tablet_impl; -static bool tablet_tool_is_libinput(struct wlr_tablet_tool *tool) { - return tool->impl == &tool_impl; +static bool tablet_is_libinput(struct wlr_tablet *tablet) { + return tablet->impl == &tablet_impl; } struct wlr_libinput_tablet_tool { - struct wlr_tablet_tool_tool wlr_tool; + struct wlr_tablet_tool wlr_tool; struct libinput_tablet_tool *libinput_tool; @@ -38,7 +38,7 @@ struct tablet_tool_list_elem { }; struct wlr_libinput_tablet { - struct wlr_tablet_tool wlr_tool; + struct wlr_tablet wlr_tablet; struct wl_list tools; // tablet_tool_list_elem::link }; @@ -51,10 +51,10 @@ static void destroy_tool_tool(struct wlr_libinput_tablet_tool *tool) { } -static void destroy_tablet_tool(struct wlr_tablet_tool *tool) { - assert(tablet_tool_is_libinput(tool)); +static void destroy_tablet(struct wlr_tablet *wlr_tablet) { + assert(tablet_is_libinput(wlr_tablet)); struct wlr_libinput_tablet *tablet = - wl_container_of(tool, tablet, wlr_tool); + wl_container_of(wlr_tablet, tablet, wlr_tablet); struct tablet_tool_list_elem *pos; struct tablet_tool_list_elem *tmp; @@ -71,29 +71,29 @@ static void destroy_tablet_tool(struct wlr_tablet_tool *tool) { free(tablet); } -static struct wlr_tablet_tool_impl tool_impl = { - .destroy = destroy_tablet_tool, +static struct wlr_tablet_impl tablet_impl = { + .destroy = destroy_tablet, }; -struct wlr_tablet_tool *create_libinput_tablet_tool( +struct wlr_tablet *create_libinput_tablet( struct libinput_device *libinput_dev) { assert(libinput_dev); - struct wlr_libinput_tablet *libinput_tablet_tool = + struct wlr_libinput_tablet *libinput_tablet = calloc(1, sizeof(struct wlr_libinput_tablet)); - if (!libinput_tablet_tool) { + if (!libinput_tablet) { wlr_log(WLR_ERROR, "Unable to allocate wlr_tablet_tool"); return NULL; } - struct wlr_tablet_tool *wlr_tablet_tool = &libinput_tablet_tool->wlr_tool; + struct wlr_tablet *wlr_tablet = &libinput_tablet->wlr_tablet; - wlr_list_init(&wlr_tablet_tool->paths); + wlr_list_init(&wlr_tablet->paths); struct udev_device *udev = libinput_device_get_udev_device(libinput_dev); - 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); + wlr_list_push(&wlr_tablet->paths, strdup(udev_device_get_syspath(udev))); + wlr_tablet->name = strdup(libinput_device_get_name(libinput_dev)); + wl_list_init(&libinput_tablet->tools); - wlr_tablet_tool_init(wlr_tablet_tool, &tool_impl); - return wlr_tablet_tool; + wlr_tablet_init(wlr_tablet, &tablet_impl); + return wlr_tablet; } static enum wlr_tablet_tool_type wlr_type_from_libinput_type( @@ -154,11 +154,11 @@ static struct wlr_libinput_tablet_tool *get_wlr_tablet_tool( } static void ensure_tool_reference(struct wlr_libinput_tablet_tool *tool, - struct wlr_tablet_tool *wlr_dev) { - assert(tablet_tool_is_libinput(wlr_dev)); - struct tablet_tool_list_elem *pos; - struct wlr_libinput_tablet *tablet = wl_container_of(wlr_dev, tablet, wlr_tool); + struct wlr_tablet *wlr_dev) { + assert(tablet_is_libinput(wlr_dev)); + struct wlr_libinput_tablet *tablet = wl_container_of(wlr_dev, tablet, wlr_tablet); + struct tablet_tool_list_elem *pos; wl_list_for_each(pos, &tablet->tools, link) { if (pos->tool == tool) { // We already have a ref // XXX: We *could* optimize the tool to the front of @@ -173,7 +173,8 @@ static void ensure_tool_reference(struct wlr_libinput_tablet_tool *tool, struct tablet_tool_list_elem *new = calloc(1, sizeof(struct tablet_tool_list_elem)); - if (!new) {// TODO: Should we at least log? + if (!new) { + wlr_log(WLR_ERROR, "Failed to allocate memory for tracking tablet tool"); return; } @@ -195,7 +196,7 @@ void handle_tablet_tool_axis(struct libinput_event *event, struct wlr_event_tablet_tool_axis wlr_event = { 0 }; struct wlr_libinput_tablet_tool *tool = get_wlr_tablet_tool( libinput_event_tablet_tool_get_tool(tevent)); - ensure_tool_reference(tool, wlr_dev->tablet_tool); + ensure_tool_reference(tool, wlr_dev->tablet); wlr_event.device = wlr_dev; wlr_event.tool = &tool->wlr_tool; @@ -239,7 +240,7 @@ void handle_tablet_tool_axis(struct libinput_event *event, wlr_event.updated_axes |= WLR_TABLET_TOOL_AXIS_WHEEL; wlr_event.wheel_delta = libinput_event_tablet_tool_get_wheel_delta(tevent); } - wlr_signal_emit_safe(&wlr_dev->tablet_tool->events.axis, &wlr_event); + wlr_signal_emit_safe(&wlr_dev->tablet->events.axis, &wlr_event); } void handle_tablet_tool_proximity(struct libinput_event *event, @@ -255,7 +256,7 @@ void handle_tablet_tool_proximity(struct libinput_event *event, struct wlr_event_tablet_tool_proximity wlr_event = { 0 }; struct wlr_libinput_tablet_tool *tool = get_wlr_tablet_tool( libinput_event_tablet_tool_get_tool(tevent)); - ensure_tool_reference(tool, wlr_dev->tablet_tool); + ensure_tool_reference(tool, wlr_dev->tablet); wlr_event.tool = &tool->wlr_tool; wlr_event.device = wlr_dev; @@ -269,7 +270,7 @@ void handle_tablet_tool_proximity(struct libinput_event *event, wlr_event.state = WLR_TABLET_TOOL_PROXIMITY_IN; break; } - wlr_signal_emit_safe(&wlr_dev->tablet_tool->events.proximity, &wlr_event); + wlr_signal_emit_safe(&wlr_dev->tablet->events.proximity, &wlr_event); if (libinput_event_tablet_tool_get_proximity_state(tevent) == LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN) { handle_tablet_tool_axis(event, libinput_dev); @@ -281,9 +282,9 @@ void handle_tablet_tool_proximity(struct libinput_event *event, libinput_event_tablet_tool_get_proximity_state(tevent) == LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT) { // The tool isn't unique, it can't be on multiple tablets assert(tool->pad_refs == 1); - assert(tablet_tool_is_libinput(wlr_dev->tablet_tool)); + assert(tablet_is_libinput(wlr_dev->tablet)); struct wlr_libinput_tablet *tablet = - wl_container_of(wlr_dev->tablet_tool, tablet, wlr_tool); + wl_container_of(wlr_dev->tablet, tablet, wlr_tablet); struct tablet_tool_list_elem *pos; struct tablet_tool_list_elem *tmp; @@ -313,7 +314,7 @@ void handle_tablet_tool_tip(struct libinput_event *event, struct wlr_event_tablet_tool_tip wlr_event = { 0 }; struct wlr_libinput_tablet_tool *tool = get_wlr_tablet_tool( libinput_event_tablet_tool_get_tool(tevent)); - ensure_tool_reference(tool, wlr_dev->tablet_tool); + ensure_tool_reference(tool, wlr_dev->tablet); wlr_event.device = wlr_dev; wlr_event.tool = &tool->wlr_tool; @@ -327,7 +328,7 @@ void handle_tablet_tool_tip(struct libinput_event *event, wlr_event.state = WLR_TABLET_TOOL_TIP_DOWN; break; } - wlr_signal_emit_safe(&wlr_dev->tablet_tool->events.tip, &wlr_event); + wlr_signal_emit_safe(&wlr_dev->tablet->events.tip, &wlr_event); } void handle_tablet_tool_button(struct libinput_event *event, @@ -344,7 +345,7 @@ void handle_tablet_tool_button(struct libinput_event *event, struct wlr_event_tablet_tool_button wlr_event = { 0 }; struct wlr_libinput_tablet_tool *tool = get_wlr_tablet_tool( libinput_event_tablet_tool_get_tool(tevent)); - ensure_tool_reference(tool, wlr_dev->tablet_tool); + ensure_tool_reference(tool, wlr_dev->tablet); wlr_event.device = wlr_dev; wlr_event.tool = &tool->wlr_tool; @@ -359,5 +360,5 @@ void handle_tablet_tool_button(struct libinput_event *event, wlr_event.state = WLR_BUTTON_PRESSED; break; } - wlr_signal_emit_safe(&wlr_dev->tablet_tool->events.button, &wlr_event); + wlr_signal_emit_safe(&wlr_dev->tablet->events.button, &wlr_event); } diff --git a/examples/tablet.c b/examples/tablet.c index 7332afe0..4a27d0e1 100644 --- a/examples/tablet.c +++ b/examples/tablet.c @@ -326,11 +326,11 @@ void new_input_notify(struct wl_listener *listener, void *data) { tstate->destroy.notify = tablet_tool_destroy_notify; wl_signal_add(&device->events.destroy, &tstate->destroy); tstate->axis.notify = tablet_tool_axis_notify; - wl_signal_add(&device->tablet_tool->events.axis, &tstate->axis); + wl_signal_add(&device->tablet->events.axis, &tstate->axis); tstate->proximity.notify = tablet_tool_proximity_notify; - wl_signal_add(&device->tablet_tool->events.proximity, &tstate->proximity); + wl_signal_add(&device->tablet->events.proximity, &tstate->proximity); tstate->button.notify = tablet_tool_button_notify; - wl_signal_add(&device->tablet_tool->events.button, &tstate->button); + wl_signal_add(&device->tablet->events.button, &tstate->button); wl_list_insert(&sample->tablet_tools, &tstate->link); break; default: diff --git a/include/backend/libinput.h b/include/backend/libinput.h index f0928133..d1fb3a44 100644 --- a/include/backend/libinput.h +++ b/include/backend/libinput.h @@ -65,7 +65,7 @@ void handle_touch_motion(struct libinput_event *event, void handle_touch_cancel(struct libinput_event *event, struct libinput_device *device); -struct wlr_tablet_tool *create_libinput_tablet_tool( +struct wlr_tablet *create_libinput_tablet( struct libinput_device *device); void handle_tablet_tool_axis(struct libinput_event *event, struct libinput_device *device); diff --git a/include/wlr/interfaces/wlr_tablet_tool.h b/include/wlr/interfaces/wlr_tablet_tool.h index 347a0003..12b2e32e 100644 --- a/include/wlr/interfaces/wlr_tablet_tool.h +++ b/include/wlr/interfaces/wlr_tablet_tool.h @@ -3,12 +3,12 @@ #include -struct wlr_tablet_tool_impl { - void (*destroy)(struct wlr_tablet_tool *tool); +struct wlr_tablet_impl { + void (*destroy)(struct wlr_tablet *tablet); }; -void wlr_tablet_tool_init(struct wlr_tablet_tool *tool, - struct wlr_tablet_tool_impl *impl); -void wlr_tablet_tool_destroy(struct wlr_tablet_tool *tool); +void wlr_tablet_init(struct wlr_tablet *tablet, + struct wlr_tablet_impl *impl); +void wlr_tablet_destroy(struct wlr_tablet *tablet); #endif diff --git a/include/wlr/types/wlr_input_device.h b/include/wlr/types/wlr_input_device.h index 5cf26b65..cce15d90 100644 --- a/include/wlr/types/wlr_input_device.h +++ b/include/wlr/types/wlr_input_device.h @@ -39,7 +39,7 @@ struct wlr_input_device { struct wlr_keyboard *keyboard; struct wlr_pointer *pointer; struct wlr_touch *touch; - struct wlr_tablet_tool *tablet_tool; + struct wlr_tablet *tablet; struct wlr_tablet_pad *tablet_pad; }; diff --git a/include/wlr/types/wlr_tablet_tool.h b/include/wlr/types/wlr_tablet_tool.h index 0a92ffe2..bfa2e1f7 100644 --- a/include/wlr/types/wlr_tablet_tool.h +++ b/include/wlr/types/wlr_tablet_tool.h @@ -15,13 +15,13 @@ enum wlr_tablet_tool_type { WLR_TABLET_TOOL_TYPE_ERASER, /**< Eraser */ WLR_TABLET_TOOL_TYPE_BRUSH, /**< A paintbrush-like tool */ WLR_TABLET_TOOL_TYPE_PENCIL, /**< Physical drawing tool, e.g. - Wacom Inking Pen */ + 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 */ }; -struct wlr_tablet_tool_tool { +struct wlr_tablet_tool { enum wlr_tablet_tool_type type; uint64_t hardware_serial; uint64_t hardware_wacom; @@ -41,10 +41,10 @@ struct wlr_tablet_tool_tool { void *data; }; -struct wlr_tablet_tool_impl; +struct wlr_tablet_impl; -struct wlr_tablet_tool { - struct wlr_tablet_tool_impl *impl; +struct wlr_tablet { + struct wlr_tablet_impl *impl; struct { struct wl_signal axis; @@ -73,7 +73,7 @@ enum wlr_tablet_tool_axes { struct wlr_event_tablet_tool_axis { struct wlr_input_device *device; - struct wlr_tablet_tool_tool *tool; + struct wlr_tablet_tool *tool; uint32_t time_msec; uint32_t updated_axes; @@ -96,7 +96,7 @@ enum wlr_tablet_tool_proximity_state { struct wlr_event_tablet_tool_proximity { struct wlr_input_device *device; - struct wlr_tablet_tool_tool *tool; + struct wlr_tablet_tool *tool; uint32_t time_msec; // From 0..1 double x, y; @@ -110,7 +110,7 @@ enum wlr_tablet_tool_tip_state { struct wlr_event_tablet_tool_tip { struct wlr_input_device *device; - struct wlr_tablet_tool_tool *tool; + struct wlr_tablet_tool *tool; uint32_t time_msec; // From 0..1 double x, y; @@ -119,7 +119,7 @@ struct wlr_event_tablet_tool_tip { struct wlr_event_tablet_tool_button { struct wlr_input_device *device; - struct wlr_tablet_tool_tool *tool; + struct wlr_tablet_tool *tool; uint32_t time_msec; uint32_t button; enum wlr_button_state state; diff --git a/include/wlr/types/wlr_tablet_v2.h b/include/wlr/types/wlr_tablet_v2.h index 3818132c..bebf8a19 100644 --- a/include/wlr/types/wlr_tablet_v2.h +++ b/include/wlr/types/wlr_tablet_v2.h @@ -26,7 +26,7 @@ struct wlr_tablet_manager_v2 { struct wlr_tablet_v2_tablet { struct wl_list link; // wlr_tablet_seat_v2::tablets - struct wlr_tablet_tool *wlr_tool; + struct wlr_tablet *wlr_tablet; struct wlr_input_device *wlr_device; struct wl_list clients; // wlr_tablet_client_v2::tablet_link @@ -37,7 +37,7 @@ struct wlr_tablet_v2_tablet { struct wlr_tablet_v2_tablet_tool { struct wl_list link; // wlr_tablet_seat_v2::tablets - struct wlr_tablet_tool_tool *wlr_tool; + struct wlr_tablet_tool *wlr_tool; struct wl_list clients; // wlr_tablet_tool_client_v2::tool_link struct wl_listener tool_destroy; @@ -105,7 +105,7 @@ struct wlr_tablet_v2_tablet_pad *wlr_tablet_pad_create( 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); + struct wlr_tablet_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); diff --git a/rootston/seat.c b/rootston/seat.c index 5bd6e752..89a32fa9 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -103,7 +103,7 @@ static void handle_touch_motion(struct wl_listener *listener, void *data) { static void handle_tablet_tool_position(struct roots_cursor *cursor, struct roots_tablet_tool *tool, - struct wlr_tablet_tool_tool *tool_tool, + struct wlr_tablet_tool *tool_tool, bool change_x, bool change_y, double x, double y, double dx, double dy) { if (!change_x && !change_y) { @@ -264,7 +264,7 @@ static void handle_tool_proximity(struct wl_listener *listener, void *data) { 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; + struct wlr_tablet_tool *tool = event->tool; if (!tool->data) { struct roots_tablet_tool_tool *roots_tool = calloc(1, sizeof(struct roots_tablet_tool_tool)); diff --git a/types/tablet_v2/wlr_tablet_v2_tablet.c b/types/tablet_v2/wlr_tablet_v2_tablet.c index d3ef4de0..0d1b5aa3 100644 --- a/types/tablet_v2/wlr_tablet_v2_tablet.c +++ b/types/tablet_v2/wlr_tablet_v2_tablet.c @@ -59,13 +59,13 @@ struct wlr_tablet_v2_tablet *wlr_tablet_create( if (!seat) { return NULL; } - struct wlr_tablet_tool *tool = wlr_device->tablet_tool; + struct wlr_tablet *wlr_tablet = wlr_device->tablet; struct wlr_tablet_v2_tablet *tablet = calloc(1, sizeof(struct wlr_tablet_v2_tablet)); if (!tablet) { return NULL; } - tablet->wlr_tool = tool; + tablet->wlr_tablet = wlr_tablet; tablet->wlr_device = wlr_device; wl_list_init(&tablet->clients); @@ -107,14 +107,15 @@ void add_tablet_client(struct wlr_tablet_seat_client_v2 *seat, 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); + if (tablet->wlr_tablet->name) { + zwp_tablet_v2_send_name(client->resource, + tablet->wlr_tablet->name); } zwp_tablet_v2_send_id(client->resource, tablet->wlr_device->vendor, tablet->wlr_device->product); - for (size_t i = 0; i < tablet->wlr_tool->paths.length; ++i) { + for (size_t i = 0; i < tablet->wlr_tablet->paths.length; ++i) { zwp_tablet_v2_send_path(client->resource, - tablet->wlr_tool->paths.items[i]); + tablet->wlr_tablet->paths.items[i]); } zwp_tablet_v2_send_done(client->resource); diff --git a/types/tablet_v2/wlr_tablet_v2_tool.c b/types/tablet_v2/wlr_tablet_v2_tool.c index 9eefaad7..d254f21a 100644 --- a/types/tablet_v2/wlr_tablet_v2_tool.c +++ b/types/tablet_v2/wlr_tablet_v2_tool.c @@ -192,7 +192,7 @@ static void handle_wlr_tablet_tool_destroy(struct wl_listener *listener, void *d 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) { + struct wlr_tablet_tool *wlr_tool) { struct wlr_tablet_seat_v2 *seat = get_or_create_tablet_seat(manager, wlr_seat); if (!seat) { return NULL; diff --git a/types/wlr_cursor.c b/types/wlr_cursor.c index 4a30215f..82ad1a4a 100644 --- a/types/wlr_cursor.c +++ b/types/wlr_cursor.c @@ -551,19 +551,19 @@ static struct wlr_cursor_device *cursor_device_create( wl_signal_add(&device->touch->events.cancel, &c_device->touch_cancel); c_device->touch_cancel.notify = handle_touch_cancel; } else if (device->type == WLR_INPUT_DEVICE_TABLET_TOOL) { - wl_signal_add(&device->tablet_tool->events.tip, + wl_signal_add(&device->tablet->events.tip, &c_device->tablet_tool_tip); c_device->tablet_tool_tip.notify = handle_tablet_tool_tip; - wl_signal_add(&device->tablet_tool->events.proximity, + wl_signal_add(&device->tablet->events.proximity, &c_device->tablet_tool_proximity); c_device->tablet_tool_proximity.notify = handle_tablet_tool_proximity; - wl_signal_add(&device->tablet_tool->events.axis, + wl_signal_add(&device->tablet->events.axis, &c_device->tablet_tool_axis); c_device->tablet_tool_axis.notify = handle_tablet_tool_axis; - wl_signal_add(&device->tablet_tool->events.button, + wl_signal_add(&device->tablet->events.button, &c_device->tablet_tool_button); c_device->tablet_tool_button.notify = handle_tablet_tool_button; } diff --git a/types/wlr_input_device.c b/types/wlr_input_device.c index 3a8fc582..89ca13cb 100644 --- a/types/wlr_input_device.c +++ b/types/wlr_input_device.c @@ -44,7 +44,7 @@ void wlr_input_device_destroy(struct wlr_input_device *dev) { wlr_touch_destroy(dev->touch); break; case WLR_INPUT_DEVICE_TABLET_TOOL: - wlr_tablet_tool_destroy(dev->tablet_tool); + wlr_tablet_destroy(dev->tablet); break; case WLR_INPUT_DEVICE_TABLET_PAD: wlr_tablet_pad_destroy(dev->tablet_pad); diff --git a/types/wlr_tablet_tool.c b/types/wlr_tablet_tool.c index 85a13832..ca92d4e2 100644 --- a/types/wlr_tablet_tool.c +++ b/types/wlr_tablet_tool.c @@ -4,26 +4,26 @@ #include #include -void wlr_tablet_tool_init(struct wlr_tablet_tool *tool, - struct wlr_tablet_tool_impl *impl) { - tool->impl = impl; - wl_signal_init(&tool->events.axis); - wl_signal_init(&tool->events.proximity); - wl_signal_init(&tool->events.tip); - wl_signal_init(&tool->events.button); +void wlr_tablet_init(struct wlr_tablet *tablet, + struct wlr_tablet_impl *impl) { + tablet->impl = impl; + wl_signal_init(&tablet->events.axis); + wl_signal_init(&tablet->events.proximity); + wl_signal_init(&tablet->events.tip); + wl_signal_init(&tablet->events.button); } -void wlr_tablet_tool_destroy(struct wlr_tablet_tool *tool) { - if (!tool) { +void wlr_tablet_destroy(struct wlr_tablet *tablet) { + if (!tablet) { return; } - wlr_list_for_each(&tool->paths, free); - wlr_list_finish(&tool->paths); + wlr_list_for_each(&tablet->paths, free); + wlr_list_finish(&tablet->paths); - if (tool->impl && tool->impl->destroy) { - tool->impl->destroy(tool); + if (tablet->impl && tablet->impl->destroy) { + tablet->impl->destroy(tablet); } else { - free(tool); + free(tablet); } } -- cgit v1.2.3 From 36955204cf87f723de1deb32da4b774d56bed478 Mon Sep 17 00:00:00 2001 From: Markus Ongyerth Date: Mon, 18 Jun 2018 09:30:24 +0200 Subject: Remove last remnant of tool_tool in libinput --- backend/libinput/tablet_tool.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/libinput/tablet_tool.c b/backend/libinput/tablet_tool.c index 563338b8..adfc6221 100644 --- a/backend/libinput/tablet_tool.c +++ b/backend/libinput/tablet_tool.c @@ -43,7 +43,7 @@ struct wlr_libinput_tablet { struct wl_list tools; // tablet_tool_list_elem::link }; -static void destroy_tool_tool(struct wlr_libinput_tablet_tool *tool) { +static void destroy_tool(struct wlr_libinput_tablet_tool *tool) { wlr_signal_emit_safe(&tool->wlr_tool.events.destroy, &tool->wlr_tool); libinput_tablet_tool_ref(tool->libinput_tool); libinput_tablet_tool_set_user_data(tool->libinput_tool, NULL); @@ -64,7 +64,7 @@ static void destroy_tablet(struct wlr_tablet *wlr_tablet) { free(pos); if (--tool->pad_refs == 0) { - destroy_tool_tool(tool); + destroy_tool(tool); } } @@ -296,7 +296,7 @@ void handle_tablet_tool_proximity(struct libinput_event *event, } } - destroy_tool_tool(tool); + destroy_tool(tool); } } -- cgit v1.2.3 From 9313ac1068105286a9541e540bd93cd2b2d5e5e9 Mon Sep 17 00:00:00 2001 From: Markus Ongyerth Date: Mon, 18 Jun 2018 09:30:32 +0200 Subject: propagate rename to rootston code --- include/rootston/seat.h | 10 ++--- rootston/seat.c | 98 ++++++++++++++++++++++++------------------------- 2 files changed, 54 insertions(+), 54 deletions(-) diff --git a/include/rootston/seat.h b/include/rootston/seat.h index 071103cf..3ddb97c5 100644 --- a/include/rootston/seat.h +++ b/include/rootston/seat.h @@ -30,7 +30,7 @@ struct roots_seat { struct wl_list keyboards; struct wl_list pointers; struct wl_list touch; - struct wl_list tablet_tools; + struct wl_list tablets; struct wl_list tablet_pads; struct wl_listener new_drag_icon; @@ -78,7 +78,7 @@ struct roots_touch { struct wl_list link; }; -struct roots_tablet_tool { +struct roots_tablet { struct roots_seat *seat; struct wlr_input_device *device; struct wlr_tablet_v2_tablet *tablet_v2; @@ -104,11 +104,11 @@ struct roots_tablet_pad { struct wl_listener ring; struct wl_listener strip; - struct roots_tablet_tool *tablet; + struct roots_tablet *tablet; struct wl_listener tablet_destroy; }; -struct roots_tablet_tool_tool { +struct roots_tablet_tool { struct wl_list link; struct wl_list tool_link; struct wlr_tablet_v2_tablet_tool *tablet_v2_tool; @@ -118,7 +118,7 @@ struct roots_tablet_tool_tool { struct wl_listener set_cursor; struct wl_listener tool_destroy; - struct roots_tablet_tool *current_tablet; + struct roots_tablet *current_tablet; struct wl_listener tablet_destroy; }; diff --git a/rootston/seat.c b/rootston/seat.c index 89a32fa9..892faaa0 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -102,21 +102,21 @@ static void handle_touch_motion(struct wl_listener *listener, void *data) { } static void handle_tablet_tool_position(struct roots_cursor *cursor, - struct roots_tablet_tool *tool, - struct wlr_tablet_tool *tool_tool, + struct roots_tablet *tablet, + struct wlr_tablet_tool *tool, bool change_x, bool change_y, double x, double y, double dx, double dy) { if (!change_x && !change_y) { return; } - switch (tool_tool->type) { + switch (tool->type) { case WLR_TABLET_TOOL_TYPE_MOUSE: // They are 0 either way when they weren't modified - wlr_cursor_move(cursor->cursor, tool->device, dx, dy); + wlr_cursor_move(cursor->cursor, tablet->device, dx, dy); break; default: - wlr_cursor_warp_absolute(cursor->cursor, tool->device, + wlr_cursor_warp_absolute(cursor->cursor, tablet->device, change_x ? x : NAN, change_y ? y : NAN); } @@ -126,7 +126,7 @@ static void handle_tablet_tool_position(struct roots_cursor *cursor, struct roots_desktop *desktop = seat->input->server->desktop; struct wlr_surface *surface = desktop_surface_at(desktop, cursor->cursor->x, cursor->cursor->y, &sx, &sy, &view); - struct roots_tablet_tool_tool *roots_tool = tool_tool->data; + struct roots_tablet_tool *roots_tool = tool->data; if (!surface) { wlr_send_tablet_v2_tablet_tool_proximity_out(roots_tool->tablet_v2_tool); @@ -134,14 +134,14 @@ static void handle_tablet_tool_position(struct roots_cursor *cursor, return; } - if (!wlr_surface_accepts_tablet_v2(tool->tablet_v2, surface)) { + if (!wlr_surface_accepts_tablet_v2(tablet->tablet_v2, surface)) { wlr_send_tablet_v2_tablet_tool_proximity_out(roots_tool->tablet_v2_tool); /* XXX: TODO: Fallback pointer semantics */ return; } wlr_send_tablet_v2_tablet_tool_proximity_in(roots_tool->tablet_v2_tool, - tool->tablet_v2, surface); + tablet->tablet_v2, surface); wlr_send_tablet_v2_tablet_tool_motion(roots_tool->tablet_v2_tool, sx, sy); } @@ -152,7 +152,7 @@ static void handle_tool_axis(struct wl_listener *listener, void *data) { struct roots_desktop *desktop = cursor->seat->input->server->desktop; wlr_idle_notify_activity(desktop->idle, cursor->seat->seat); struct wlr_event_tablet_tool_axis *event = data; - struct roots_tablet_tool_tool *roots_tool = event->tool->data; + struct roots_tablet_tool *roots_tool = event->tool->data; if (!roots_tool) { // Should this be an assert? wlr_log(WLR_DEBUG, "Tool Axis, before proximity"); @@ -205,7 +205,7 @@ static void handle_tool_tip(struct wl_listener *listener, void *data) { struct roots_desktop *desktop = cursor->seat->input->server->desktop; wlr_idle_notify_activity(desktop->idle, cursor->seat->seat); struct wlr_event_tablet_tool_tip *event = data; - struct roots_tablet_tool_tool *roots_tool = event->tool->data; + struct roots_tablet_tool *roots_tool = event->tool->data; if (event->state == WLR_TABLET_TOOL_TIP_DOWN) { wlr_send_tablet_v2_tablet_tool_down(roots_tool->tablet_v2_tool); @@ -214,8 +214,8 @@ static void handle_tool_tip(struct wl_listener *listener, void *data) { } } -static void handle_tablet_tool_tool_destroy(struct wl_listener *listener, void *data) { - struct roots_tablet_tool_tool *tool = +static void handle_tablet_tool_destroy(struct wl_listener *listener, void *data) { + struct roots_tablet_tool *tool = wl_container_of(listener, tool, tool_destroy); wl_list_remove(&tool->link); @@ -233,7 +233,7 @@ static void handle_tool_button(struct wl_listener *listener, void *data) { struct roots_desktop *desktop = cursor->seat->input->server->desktop; wlr_idle_notify_activity(desktop->idle, cursor->seat->seat); struct wlr_event_tablet_tool_button *event = data; - struct roots_tablet_tool_tool *roots_tool = event->tool->data; + struct roots_tablet_tool *roots_tool = event->tool->data; wlr_send_tablet_v2_tablet_tool_button(roots_tool->tablet_v2_tool, (enum zwp_tablet_pad_v2_button_state)event->button, @@ -241,7 +241,7 @@ static void handle_tool_button(struct wl_listener *listener, void *data) { } static void handle_tablet_tool_set_cursor(struct wl_listener *listener, void *data) { - struct roots_tablet_tool_tool *tool = + struct roots_tablet_tool *tool = wl_container_of(listener, tool, set_cursor); struct wlr_tablet_v2_event_cursor *evt = data; @@ -266,14 +266,14 @@ static void handle_tool_proximity(struct wl_listener *listener, void *data) { struct wlr_tablet_tool *tool = event->tool; if (!tool->data) { - struct roots_tablet_tool_tool *roots_tool = - calloc(1, sizeof(struct roots_tablet_tool_tool)); + struct roots_tablet_tool *roots_tool = + calloc(1, sizeof(struct roots_tablet_tool)); roots_tool->seat = cursor->seat; tool->data = roots_tool; roots_tool->tablet_v2_tool = wlr_tablet_tool_create(desktop->tablet_v2, cursor->seat->seat, tool); - roots_tool->tool_destroy.notify = handle_tablet_tool_tool_destroy; + roots_tool->tool_destroy.notify = handle_tablet_tool_destroy; wl_signal_add(&tool->events.destroy, &roots_tool->tool_destroy); roots_tool->set_cursor.notify = handle_tablet_tool_set_cursor; @@ -337,7 +337,7 @@ void roots_seat_configure_cursor(struct roots_seat *seat) { struct roots_pointer *pointer; struct roots_touch *touch; - struct roots_tablet_tool *tablet_tool; + struct roots_tablet *tablet; struct roots_output *output; // reset mappings @@ -348,8 +348,8 @@ void roots_seat_configure_cursor(struct roots_seat *seat) { wl_list_for_each(touch, &seat->touch, link) { seat_reset_device_mappings(seat, touch->device); } - wl_list_for_each(tablet_tool, &seat->tablet_tools, link) { - seat_reset_device_mappings(seat, tablet_tool->device); + wl_list_for_each(tablet, &seat->tablets, link) { + seat_reset_device_mappings(seat, tablet->device); } // configure device to output mappings @@ -369,8 +369,8 @@ void roots_seat_configure_cursor(struct roots_seat *seat) { seat_set_device_output_mappings(seat, pointer->device, output->wlr_output); } - wl_list_for_each(tablet_tool, &seat->tablet_tools, link) { - seat_set_device_output_mappings(seat, tablet_tool->device, + wl_list_for_each(tablet, &seat->tablets, link) { + seat_set_device_output_mappings(seat, tablet->device, output->wlr_output); } wl_list_for_each(touch, &seat->touch, link) { @@ -554,7 +554,7 @@ struct roots_seat *roots_seat_create(struct roots_input *input, char *name) { wl_list_init(&seat->keyboards); wl_list_init(&seat->pointers); wl_list_init(&seat->touch); - wl_list_init(&seat->tablet_tools); + wl_list_init(&seat->tablets); wl_list_init(&seat->tablet_pads); wl_list_init(&seat->views); wl_list_init(&seat->drag_icons); @@ -589,7 +589,7 @@ static void seat_update_capabilities(struct roots_seat *seat) { if (!wl_list_empty(&seat->keyboards)) { caps |= WL_SEAT_CAPABILITY_KEYBOARD; } - if (!wl_list_empty(&seat->pointers) || !wl_list_empty(&seat->tablet_tools)) { + if (!wl_list_empty(&seat->pointers) || !wl_list_empty(&seat->tablets)) { caps |= WL_SEAT_CAPABILITY_POINTER; } if (!wl_list_empty(&seat->touch)) { @@ -739,7 +739,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) { + struct roots_tablet *tool) { wlr_log(WLR_DEBUG, "Attaching tablet pad \"%s\" to tablet tool \"%s\"", pad->device->name, tool->device->name); @@ -753,7 +753,7 @@ 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; + struct roots_tablet *tool = wlr_tool->data; attach_tablet_pad(pad, tool); } @@ -835,8 +835,8 @@ static void seat_add_tablet_pad(struct roots_seat *seat, 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) { + struct roots_tablet *tool; + wl_list_for_each(tool, &seat->tablets, link) { if (!wlr_input_device_is_libinput(tool->device)) { continue; } @@ -850,44 +850,44 @@ static void seat_add_tablet_pad(struct roots_seat *seat, } } -static void handle_tablet_tool_destroy(struct wl_listener *listener, +static void handle_tablet_destroy(struct wl_listener *listener, void *data) { - struct roots_tablet_tool *tablet_tool = - wl_container_of(listener, tablet_tool, device_destroy); - struct roots_seat *seat = tablet_tool->seat; + struct roots_tablet *tablet = + wl_container_of(listener, tablet, device_destroy); + struct roots_seat *seat = tablet->seat; - 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); - free(tablet_tool); + wlr_cursor_detach_input_device(seat->cursor->cursor, tablet->device); + wl_list_remove(&tablet->device_destroy.link); + wl_list_remove(&tablet->link); + free(tablet); seat_update_capabilities(seat); } static void seat_add_tablet_tool(struct roots_seat *seat, struct wlr_input_device *device) { - struct roots_tablet_tool *tablet_tool = - calloc(1, sizeof(struct roots_tablet_tool)); - if (!tablet_tool) { - wlr_log(WLR_ERROR, "could not allocate tablet_tool for seat"); + struct roots_tablet *tablet = + calloc(1, sizeof(struct roots_tablet)); + if (!tablet) { + wlr_log(WLR_ERROR, "could not allocate tablet for seat"); return; } - device->data = tablet_tool; - tablet_tool->device = device; - tablet_tool->seat = seat; - wl_list_insert(&seat->tablet_tools, &tablet_tool->link); + device->data = tablet; + tablet->device = device; + tablet->seat = seat; + wl_list_insert(&seat->tablets, &tablet->link); - tablet_tool->device_destroy.notify = handle_tablet_tool_destroy; - wl_signal_add(&tablet_tool->device->events.destroy, - &tablet_tool->device_destroy); + tablet->device_destroy.notify = handle_tablet_destroy; + wl_signal_add(&tablet->device->events.destroy, + &tablet->device_destroy); wlr_cursor_attach_input_device(seat->cursor->cursor, device); roots_seat_configure_cursor(seat); struct roots_desktop *desktop = seat->input->server->desktop; - tablet_tool->tablet_v2 = + tablet->tablet_v2 = wlr_tablet_create(desktop->tablet_v2, seat->seat, device); struct libinput_device_group *group = @@ -901,7 +901,7 @@ static void seat_add_tablet_tool(struct roots_seat *seat, 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); + attach_tablet_pad(pad, tablet); } } } -- cgit v1.2.3 From 43b20bfea2070df78ba7cb12a78a5f7a42dd21f5 Mon Sep 17 00:00:00 2001 From: Markus Ongyerth Date: Sun, 24 Jun 2018 20:56:39 +0200 Subject: First feedback pass from acrisci --- include/types/wlr_tablet_v2.h | 4 ++-- include/wlr/types/wlr_tablet_v2.h | 2 +- types/tablet_v2/wlr_tablet_v2.c | 14 +++++++------- types/tablet_v2/wlr_tablet_v2_pad.c | 22 ++++++++++++++++------ types/tablet_v2/wlr_tablet_v2_tool.c | 8 ++++---- 5 files changed, 30 insertions(+), 20 deletions(-) diff --git a/include/types/wlr_tablet_v2.h b/include/types/wlr_tablet_v2.h index f2d9b8e4..4b9e727d 100644 --- a/include/types/wlr_tablet_v2.h +++ b/include/types/wlr_tablet_v2.h @@ -26,7 +26,7 @@ struct wlr_tablet_seat_client_v2 { struct wl_resource *resource; struct wlr_tablet_manager_client_v2 *client; - struct wlr_seat_client *seat; + struct wlr_seat_client *seat_client; struct wl_listener seat_client_destroy; @@ -85,7 +85,7 @@ struct wlr_tablet_tool_client_v2 *tablet_tool_client_from_resource(struct wl_res void add_tablet_tool_client(struct wlr_tablet_seat_client_v2 *seat, struct wlr_tablet_v2_tablet_tool *tool); struct wlr_tablet_seat_client_v2 *tablet_seat_client_from_resource(struct wl_resource *resource); -void wlr_tablet_seat_client_v2_destroy(struct wl_resource *resource); +void tablet_seat_client_v2_destroy(struct wl_resource *resource); struct wlr_tablet_seat_v2 *get_or_create_tablet_seat( struct wlr_tablet_manager_v2 *manager, struct wlr_seat *wlr_seat); diff --git a/include/wlr/types/wlr_tablet_v2.h b/include/wlr/types/wlr_tablet_v2.h index bebf8a19..afa74d05 100644 --- a/include/wlr/types/wlr_tablet_v2.h +++ b/include/wlr/types/wlr_tablet_v2.h @@ -137,7 +137,7 @@ void wlr_send_tablet_v2_tablet_tool_slider( struct wlr_tablet_v2_tablet_tool *tool, double position); void wlr_send_tablet_v2_tablet_tool_wheel( - struct wlr_tablet_v2_tablet_tool *tool, double delta, int32_t clicks); + struct wlr_tablet_v2_tablet_tool *tool, double degrees, int32_t clicks); void wlr_send_tablet_v2_tablet_tool_proximity_out( struct wlr_tablet_v2_tablet_tool *tool); diff --git a/types/tablet_v2/wlr_tablet_v2.c b/types/tablet_v2/wlr_tablet_v2.c index 802de77f..fa058e79 100644 --- a/types/tablet_v2/wlr_tablet_v2.c +++ b/types/tablet_v2/wlr_tablet_v2.c @@ -36,7 +36,7 @@ static void handle_wlr_seat_destroy(struct wl_listener *listener, void *data) { struct wlr_tablet_seat_client_v2 *client; struct wlr_tablet_seat_client_v2 *tmp; wl_list_for_each_safe(client, tmp, &seat->clients, seat_link) { - wlr_tablet_seat_client_v2_destroy(client->resource); + tablet_seat_client_v2_destroy(client->resource); } } @@ -94,7 +94,7 @@ struct wlr_tablet_seat_client_v2 *tablet_seat_client_from_resource( return wl_resource_get_user_data(resource); } -void wlr_tablet_seat_client_v2_destroy(struct wl_resource *resource) { +void tablet_seat_client_v2_destroy(struct wl_resource *resource) { struct wlr_tablet_seat_client_v2 *seat = tablet_seat_client_from_resource(resource); if (!seat) { return; @@ -129,7 +129,7 @@ void wlr_tablet_seat_client_v2_destroy(struct wl_resource *resource) { static void handle_seat_client_destroy(struct wl_listener *listener, void *data) { struct wlr_tablet_seat_client_v2 *seat = wl_container_of(listener, seat, seat_client_destroy); - wlr_tablet_seat_client_v2_destroy(seat->resource); + tablet_seat_client_v2_destroy(seat->resource); } static void tablet_manager_destroy(struct wl_client *client, @@ -148,7 +148,7 @@ static void get_tablet_seat(struct wl_client *wl_client, struct wl_resource *res * destruction, without allocations or advertising things */ wl_resource_set_implementation(seat_resource, &seat_impl, NULL, - wlr_tablet_seat_client_v2_destroy); + tablet_seat_client_v2_destroy); return; } struct wlr_seat_client *seat = wlr_seat_client_from_resource(seat_resource); @@ -175,10 +175,10 @@ static void get_tablet_seat(struct wl_client *wl_client, struct wl_resource *res return; } wl_resource_set_implementation(seat_client->resource, &seat_impl, seat_client, - wlr_tablet_seat_client_v2_destroy); + tablet_seat_client_v2_destroy); - seat_client->seat = seat; + seat_client->seat_client = seat; seat_client->client = manager; seat_client->wl_client = wl_client; wl_list_init(&seat_client->tools); @@ -229,7 +229,7 @@ static void wlr_tablet_manager_v2_destroy(struct wl_resource *resource) { struct wlr_tablet_seat_client_v2 *pos; struct wlr_tablet_seat_client_v2 *tmp; wl_list_for_each_safe(pos, tmp, &client->tablet_seats, client_link) { - wlr_tablet_seat_client_v2_destroy(pos->resource); + tablet_seat_client_v2_destroy(pos->resource); } wl_list_remove(&client->link); diff --git a/types/tablet_v2/wlr_tablet_v2_pad.c b/types/tablet_v2/wlr_tablet_v2_pad.c index 154e6434..899f60cd 100644 --- a/types/tablet_v2/wlr_tablet_v2_pad.c +++ b/types/tablet_v2/wlr_tablet_v2_pad.c @@ -86,7 +86,7 @@ static void handle_tablet_pad_ring_v2_set_feedback(struct wl_client *client, .serial = serial, .description = description, .index = aux->index - }; + }; wl_signal_emit(&aux->pad->pad->events.ring_feedback, &evt); } @@ -221,12 +221,17 @@ static void add_tablet_pad_group(struct wlr_tablet_v2_tablet_pad *pad, struct tablet_pad_auxiliary_user_data *user_data = calloc(1, sizeof(struct tablet_pad_auxiliary_user_data)); if (!user_data) { - continue; + wl_client_post_no_memory(client->client); + return; } user_data->pad = client; user_data->index = strip; client->strips[strip] = wl_resource_create(client->client, &zwp_tablet_pad_strip_v2_interface, 1, 0); + if (!client->strips[strip]) { + wl_client_post_no_memory(client->client); + return; + } wl_resource_set_implementation(client->strips[strip], &tablet_pad_strip_impl, user_data, destroy_tablet_pad_strip_v2); zwp_tablet_pad_group_v2_send_strip(client->groups[index], client->strips[strip]); @@ -238,12 +243,17 @@ static void add_tablet_pad_group(struct wlr_tablet_v2_tablet_pad *pad, struct tablet_pad_auxiliary_user_data *user_data = calloc(1, sizeof(struct tablet_pad_auxiliary_user_data)); if (!user_data) { - continue; + wl_client_post_no_memory(client->client); + return; } user_data->pad = client; user_data->index = ring; client->rings[ring] = wl_resource_create(client->client, &zwp_tablet_pad_ring_v2_interface, 1, 0); + if (!client->rings[ring]) { + wl_client_post_no_memory(client->client); + return; + } wl_resource_set_implementation(client->rings[ring], &tablet_pad_ring_impl, user_data, destroy_tablet_pad_ring_v2); zwp_tablet_pad_group_v2_send_ring(client->groups[index], client->rings[ring]); @@ -262,14 +272,14 @@ void add_tablet_pad_client(struct wlr_tablet_seat_client_v2 *seat, } client->pad = pad; - client->groups = calloc(sizeof(int), wl_list_length(&pad->wlr_pad->groups)); + client->groups = calloc(wl_list_length(&pad->wlr_pad->groups), sizeof(struct wl_resource*)); 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); + client->rings = calloc(pad->wlr_pad->ring_count, sizeof(struct wl_resource*)); if (!client->rings) { wl_client_post_no_memory(seat->wl_client); free(client->groups); @@ -277,7 +287,7 @@ void add_tablet_pad_client(struct wlr_tablet_seat_client_v2 *seat, return; } - client->strips = calloc(sizeof(struct wl_resource*), pad->wlr_pad->strip_count); + client->strips = calloc(pad->wlr_pad->strip_count, sizeof(struct wl_resource*)); if (!client->strips) { wl_client_post_no_memory(seat->wl_client); free(client->groups); diff --git a/types/tablet_v2/wlr_tablet_v2_tool.c b/types/tablet_v2/wlr_tablet_v2_tool.c index d254f21a..f476c2db 100644 --- a/types/tablet_v2/wlr_tablet_v2_tool.c +++ b/types/tablet_v2/wlr_tablet_v2_tool.c @@ -28,7 +28,7 @@ static void handle_tablet_tool_v2_set_cursor(struct wl_client *client, if (surface_resource != NULL) { surface = wlr_surface_from_resource(surface_resource); if (!wlr_surface_set_role(surface, &pointer_cursor_surface_role, NULL, - surface_resource, WL_POINTER_ERROR_ROLE)) { + surface_resource, ZWP_TABLET_TOOL_V2_ERROR_ROLE)) { return; } } @@ -38,7 +38,7 @@ static void handle_tablet_tool_v2_set_cursor(struct wl_client *client, .serial = serial, .hotspot_x = hotspot_x, .hotspot_y = hotspot_y, - .seat_client = tool->seat->seat, + .seat_client = tool->seat->seat_client, }; wl_signal_emit(&tool->tool->events.set_cursor, &evt); @@ -476,10 +476,10 @@ void wlr_send_tablet_v2_tablet_tool_button( } void wlr_send_tablet_v2_tablet_tool_wheel( - struct wlr_tablet_v2_tablet_tool *tool, double delta, int32_t clicks) { + struct wlr_tablet_v2_tablet_tool *tool, double degrees, int32_t clicks) { if (tool->current_client) { zwp_tablet_tool_v2_send_wheel(tool->current_client->resource, - clicks, delta); + clicks, degrees); queue_tool_frame(tool->current_client); } -- cgit v1.2.3 From 74ca2f8fcf10f5b00b4a3eeb121e418e1b5212e0 Mon Sep 17 00:00:00 2001 From: Markus Ongyerth Date: Sat, 7 Jul 2018 17:56:37 +0200 Subject: Another round of feedback from acrisci --- include/util/array.h | 9 +++++++++ types/tablet_v2/wlr_tablet_v2_tool.c | 35 ++++++++++++----------------------- types/wlr_keyboard.c | 20 +------------------- util/array.c | 21 +++++++++++++++++++++ util/meson.build | 1 + 5 files changed, 44 insertions(+), 42 deletions(-) create mode 100644 include/util/array.h create mode 100644 util/array.c diff --git a/include/util/array.h b/include/util/array.h new file mode 100644 index 00000000..1c046e1d --- /dev/null +++ b/include/util/array.h @@ -0,0 +1,9 @@ +#ifndef UTIL_ARRAY_H +#define UTIL_ARRAY_H + +#include +#include + +size_t push_zeroes_to_end(uint32_t arr[], size_t n); + +#endif diff --git a/types/tablet_v2/wlr_tablet_v2_tool.c b/types/tablet_v2/wlr_tablet_v2_tool.c index f476c2db..c7a1fa54 100644 --- a/types/tablet_v2/wlr_tablet_v2_tool.c +++ b/types/tablet_v2/wlr_tablet_v2_tool.c @@ -3,6 +3,7 @@ #endif #include "tablet-unstable-v2-protocol.h" +#include "util/array.h" #include #include #include @@ -231,25 +232,8 @@ struct wlr_tablet_tool_client_v2 *tablet_tool_client_from_resource(struct wl_res /* Actual protocol foo */ -// https://www.geeksforgeeks.org/move-zeroes-end-array/ -static size_t push_zeroes_to_end(uint32_t arr[], size_t n) { - size_t count = 0; - - for (size_t i = 0; i < n; i++) { - if (arr[i] != 0) { - arr[count++] = arr[i]; - } - } - - size_t ret = count; - - while (count < n) { - arr[count++] = 0; - } - - return ret; -} +// Button 0 is KEY_RESERVED in input-event-codes on linux (and freebsd) static ssize_t tablet_tool_button_update(struct wlr_tablet_v2_tablet_tool *tool, uint32_t button, enum zwp_tablet_pad_v2_button_state state) { bool found = false; @@ -261,11 +245,16 @@ static ssize_t tablet_tool_button_update(struct wlr_tablet_v2_tablet_tool *tool, } } - if (state == ZWP_TABLET_PAD_V2_BUTTON_STATE_PRESSED && !found && - tool->num_buttons < WLR_TABLET_V2_TOOL_BUTTONS_CAP) { - i = tool->num_buttons++; - tool->pressed_buttons[i] = button; - tool->pressed_serials[i] = -1; + if (state == ZWP_TABLET_PAD_V2_BUTTON_STATE_PRESSED && !found) { + if (tool->num_buttons < WLR_TABLET_V2_TOOL_BUTTONS_CAP) { + i = tool->num_buttons++; + tool->pressed_buttons[i] = button; + tool->pressed_serials[i] = -1; + } else { + i = -1; + wlr_log(WLR_ERROR, "You pressed more than %d tablet tool buttons. This is currently not supporte by wlroots. Please report this with a description of your tablet, since this is either a bug, or fancy hardware", + WLR_TABLET_V2_TOOL_BUTTONS_CAP); + } } else { i = -1; } diff --git a/types/wlr_keyboard.c b/types/wlr_keyboard.c index e941e8d1..3a4f5f67 100644 --- a/types/wlr_keyboard.c +++ b/types/wlr_keyboard.c @@ -1,3 +1,4 @@ +#include "util/array.h" #include #include #include @@ -58,25 +59,6 @@ static bool keyboard_modifier_update(struct wlr_keyboard *keyboard) { return true; } -// https://www.geeksforgeeks.org/move-zeroes-end-array/ -static size_t push_zeroes_to_end(uint32_t arr[], size_t n) { - size_t count = 0; - - for (size_t i = 0; i < n; i++) { - if (arr[i] != 0) { - arr[count++] = arr[i]; - } - } - - size_t ret = count; - - while (count < n) { - arr[count++] = 0; - } - - return ret; -} - static void keyboard_key_update(struct wlr_keyboard *keyboard, struct wlr_event_keyboard_key *event) { bool found = false; diff --git a/util/array.c b/util/array.c new file mode 100644 index 00000000..9ee39d33 --- /dev/null +++ b/util/array.c @@ -0,0 +1,21 @@ +#include +#include + +// https://www.geeksforgeeks.org/move-zeroes-end-array/ +size_t push_zeroes_to_end(uint32_t arr[], size_t n) { + size_t count = 0; + + for (size_t i = 0; i < n; i++) { + if (arr[i] != 0) { + arr[count++] = arr[i]; + } + } + + size_t ret = count; + + while (count < n) { + arr[count++] = 0; + } + + return ret; +} diff --git a/util/meson.build b/util/meson.build index adc52a53..f9d1997d 100644 --- a/util/meson.build +++ b/util/meson.build @@ -1,6 +1,7 @@ lib_wlr_util = static_library( 'wlr_util', files( + 'array.c', 'log.c', 'os-compatibility.c', 'region.c', -- cgit v1.2.3 From 9a6f77fc2ceb59f4b5bcd1e1f8c00aa974b5192b Mon Sep 17 00:00:00 2001 From: Markus Ongyerth Date: Sat, 14 Jul 2018 10:29:22 +0200 Subject: tablet-v2: fix merge commits and test again There were a few issues after rebase, that the merge algorithm didn't throw at my face: wlr_output did a check on the actual role, not a string anymore, so that had to go to allow tablet-v2 to set cursor surfaces. A few L_DEBUG/L_ERRORs were still around There was a user-after-free in tablet-group free()ing, probably after insufficient testing from a previous feedback pass --- include/wlr/types/wlr_seat.h | 2 - types/seat/wlr_seat_pointer.c | 4 -- types/tablet_v2/wlr_tablet_v2_pad.c | 103 +++++++++++++++-------------------- types/tablet_v2/wlr_tablet_v2_tool.c | 16 ++++-- types/wlr_output.c | 5 -- 5 files changed, 54 insertions(+), 76 deletions(-) diff --git a/include/wlr/types/wlr_seat.h b/include/wlr/types/wlr_seat.h index 1c7a1472..92d0a233 100644 --- a/include/wlr/types/wlr_seat.h +++ b/include/wlr/types/wlr_seat.h @@ -540,6 +540,4 @@ bool wlr_seat_validate_grab_serial(struct wlr_seat *seat, uint32_t serial); struct wlr_seat_client *wlr_seat_client_from_resource( struct wl_resource *resource); -bool wlr_surface_is_pointer_cursor(struct wlr_surface *surface); - #endif diff --git a/types/seat/wlr_seat_pointer.c b/types/seat/wlr_seat_pointer.c index e54b79bf..899fb64f 100644 --- a/types/seat/wlr_seat_pointer.c +++ b/types/seat/wlr_seat_pointer.c @@ -355,7 +355,3 @@ void seat_client_destroy_pointer(struct wl_resource *resource) { } wl_resource_set_user_data(resource, NULL); } - -bool wlr_surface_is_pointer_cursor(struct wlr_surface *surface) { - return surface->role == &pointer_cursor_surface_role; -} diff --git a/types/tablet_v2/wlr_tablet_v2_pad.c b/types/tablet_v2/wlr_tablet_v2_pad.c index 899f60cd..1fcfa38e 100644 --- a/types/tablet_v2/wlr_tablet_v2_pad.c +++ b/types/tablet_v2/wlr_tablet_v2_pad.c @@ -16,47 +16,6 @@ struct tablet_pad_auxiliary_user_data { size_t index; }; -void destroy_tablet_pad_v2(struct wl_resource *resource) { - struct wlr_tablet_pad_client_v2 *pad = - tablet_pad_client_from_resource(resource); - - if (!pad) { - return; - } - - wl_list_remove(&pad->seat_link); - wl_list_remove(&pad->pad_link); - - /* This isn't optimal, if the client destroys the resources in another - * order, it will be disconnected. - * But this makes things *way* easier for us, and (untested) I doubt - * clients will destroy it in another order. - */ - for (size_t i = 0; i < pad->group_count; ++i) { - if (pad->groups[i]) { - wl_resource_destroy(pad->groups[i]); - } - } - free(pad->groups); - - for (size_t i = 0; i < pad->ring_count; ++i) { - if (pad->rings[i]) { - wl_resource_destroy(pad->rings[i]); - } - } - free(pad->rings); - - for (size_t i = 0; i < pad->strip_count; ++i) { - if (pad->strips[i]) { - wl_resource_destroy(pad->strips[i]); - } - } - free(pad->strips); - - free(pad); - wl_resource_set_user_data(resource, NULL); -} - static void handle_tablet_pad_v2_destroy(struct wl_client *client, struct wl_resource *resource) { wl_resource_destroy(resource); @@ -173,6 +132,47 @@ static void destroy_tablet_pad_group_v2(struct wl_resource *resource) { wl_resource_set_user_data(resource, NULL); } +void destroy_tablet_pad_v2(struct wl_resource *resource) { + struct wlr_tablet_pad_client_v2 *pad = + tablet_pad_client_from_resource(resource); + + if (!pad) { + return; + } + + wl_list_remove(&pad->seat_link); + wl_list_remove(&pad->pad_link); + + /* This isn't optimal, if the client destroys the resources in another + * order, it will be disconnected. + * But this makes things *way* easier for us, and (untested) I doubt + * clients will destroy it in another order. + */ + for (size_t i = 0; i < pad->group_count; ++i) { + if (pad->groups[i]) { + destroy_tablet_pad_group_v2(pad->groups[i]); + } + } + free(pad->groups); + + for (size_t i = 0; i < pad->ring_count; ++i) { + if (pad->rings[i]) { + destroy_tablet_pad_ring_v2(pad->rings[i]); + } + } + free(pad->rings); + + for (size_t i = 0; i < pad->strip_count; ++i) { + if (pad->strips[i]) { + destroy_tablet_pad_strip_v2(pad->strips[i]); + } + } + free(pad->strips); + + free(pad); + wl_resource_set_user_data(resource, NULL); +} + static void handle_tablet_pad_group_v2_destroy(struct wl_client *client, struct wl_resource *resource) { wl_resource_destroy(resource); @@ -321,9 +321,11 @@ void add_tablet_pad_client(struct wlr_tablet_seat_client_v2 *seat, } size_t i = 0; struct wlr_tablet_pad_group *group; + client->group_count = pad->group_count; 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); @@ -334,30 +336,11 @@ static void handle_wlr_tablet_pad_destroy(struct wl_listener *listener, void *da 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) { - 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]); - } - } - struct wlr_tablet_pad_client_v2 *client; struct wlr_tablet_pad_client_v2 *tmp_client; wl_list_for_each_safe(client, tmp_client, &pad->clients, pad_link) { zwp_tablet_pad_v2_send_removed(client->resource); destroy_tablet_pad_v2(client->resource); - } wl_list_remove(&pad->clients); diff --git a/types/tablet_v2/wlr_tablet_v2_tool.c b/types/tablet_v2/wlr_tablet_v2_tool.c index c7a1fa54..62c00a37 100644 --- a/types/tablet_v2/wlr_tablet_v2_tool.c +++ b/types/tablet_v2/wlr_tablet_v2_tool.c @@ -12,8 +12,8 @@ #include #include -static const struct wlr_surface_role pointer_cursor_surface_role = { - .name = "wl_pointer-cursor", +static const struct wlr_surface_role tablet_tool_cursor_surface_role = { + .name = "wp_tablet_tool-cursor", }; static void handle_tablet_tool_v2_set_cursor(struct wl_client *client, @@ -28,7 +28,7 @@ static void handle_tablet_tool_v2_set_cursor(struct wl_client *client, struct wlr_surface *surface = NULL; if (surface_resource != NULL) { surface = wlr_surface_from_resource(surface_resource); - if (!wlr_surface_set_role(surface, &pointer_cursor_surface_role, NULL, + if (!wlr_surface_set_role(surface, &tablet_tool_cursor_surface_role, NULL, surface_resource, ZWP_TABLET_TOOL_V2_ERROR_ROLE)) { return; } @@ -241,10 +241,17 @@ static ssize_t tablet_tool_button_update(struct wlr_tablet_v2_tablet_tool *tool, for (; i < tool->num_buttons; ++i) { if (tool->pressed_buttons[i] == button) { found = true; + wlr_log(WLR_DEBUG, "Found the button \\o/: %u", button); break; + } } + if (state == ZWP_TABLET_PAD_V2_BUTTON_STATE_PRESSED && found) { + /* Already have the button saved, durr */ + return -1; + } + if (state == ZWP_TABLET_PAD_V2_BUTTON_STATE_PRESSED && !found) { if (tool->num_buttons < WLR_TABLET_V2_TOOL_BUTTONS_CAP) { i = tool->num_buttons++; @@ -255,10 +262,9 @@ static ssize_t tablet_tool_button_update(struct wlr_tablet_v2_tablet_tool *tool, wlr_log(WLR_ERROR, "You pressed more than %d tablet tool buttons. This is currently not supporte by wlroots. Please report this with a description of your tablet, since this is either a bug, or fancy hardware", WLR_TABLET_V2_TOOL_BUTTONS_CAP); } - } else { - i = -1; } if (state == ZWP_TABLET_PAD_V2_BUTTON_STATE_RELEASED && found) { + wlr_log(WLR_DEBUG, "Removed the button \\o/: %u", button); tool->pressed_buttons[i] = 0; tool->pressed_serials[i] = 0; tool->num_buttons = push_zeroes_to_end(tool->pressed_buttons, WLR_TABLET_V2_TOOL_BUTTONS_CAP); diff --git a/types/wlr_output.c b/types/wlr_output.c index 35b8c416..a1d00c0c 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -817,11 +817,6 @@ static void output_cursor_handle_destroy(struct wl_listener *listener, void wlr_output_cursor_set_surface(struct wlr_output_cursor *cursor, struct wlr_surface *surface, int32_t hotspot_x, int32_t hotspot_y) { - if (surface && !wlr_surface_is_pointer_cursor(surface)) { - wlr_log(WLR_ERROR, "Tried to set a cursor surface with invalid role"); - return; - } - hotspot_x *= cursor->output->scale; hotspot_y *= cursor->output->scale; -- cgit v1.2.3