wlroots-hyprland/backend/libinput/tablet_tool.c

373 lines
12 KiB
C
Raw Normal View History

2018-04-23 08:55:49 +02:00
#ifndef _POSIX_C_SOURCE
#define _POSIX_C_SOURCE 200809L
#endif
#include <string.h>
2017-06-15 20:32:28 +02:00
#include <assert.h>
#include <libinput.h>
2018-02-12 21:29:23 +01:00
#include <stdlib.h>
#include <wayland-util.h>
2017-07-11 09:18:34 +02:00
#include <wlr/backend/session.h>
2017-06-21 16:27:45 +02:00
#include <wlr/interfaces/wlr_tablet_tool.h>
2018-02-12 21:29:23 +01:00
#include <wlr/types/wlr_input_device.h>
2017-06-21 18:10:07 +02:00
#include <wlr/util/log.h>
2017-06-15 20:32:28 +02:00
#include "backend/libinput.h"
#include "util/array.h"
2018-02-12 21:29:23 +01:00
#include "util/signal.h"
2017-06-15 20:32:28 +02:00
static const struct wlr_tablet_impl tablet_impl;
static bool tablet_is_libinput(struct wlr_tablet *tablet) {
return tablet->impl == &tablet_impl;
}
struct wlr_libinput_tablet_tool {
struct wlr_tablet_tool wlr_tool;
struct libinput_tablet_tool *libinput_tool;
bool unique;
// Refcount for destroy + release
size_t pad_refs;
};
struct wlr_libinput_tablet {
struct wlr_tablet wlr_tablet;
struct wl_array tools; // struct wlr_libinput_tablet_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);
free(tool);
}
static void destroy_tablet(struct wlr_tablet *wlr_tablet) {
assert(tablet_is_libinput(wlr_tablet));
struct wlr_libinput_tablet *tablet =
wl_container_of(wlr_tablet, tablet, wlr_tablet);
Fix invalid uses of wl_array_for_each [1] and [2] have introduced new wl_array usage in wlroots, but contains a mistake: wl_array_for_each iterates over pointers to the wl_array entries, not over entries themselves. Fix all wl_array_for_each call sites. Name the variables "ptr" to avoid confusion. Found via ASan: ==148752==ERROR: AddressSanitizer: attempting free on address which was not malloc()-ed: 0x602000214111 in thread T0 #0 0x7f6ff2235f19 in __interceptor_free /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cpp:127 #1 0x7f6ff1c04004 in wlr_tablet_destroy ../subprojects/wlroots/types/wlr_tablet_tool.c:24 #2 0x7f6ff1b8463c in wlr_input_device_destroy ../subprojects/wlroots/types/wlr_input_device.c:51 #3 0x7f6ff1ab9941 in backend_destroy ../subprojects/wlroots/backend/wayland/backend.c:306 #4 0x7f6ff1a68323 in wlr_backend_destroy ../subprojects/wlroots/backend/backend.c:57 #5 0x7f6ff1ab36b4 in multi_backend_destroy ../subprojects/wlroots/backend/multi/backend.c:57 #6 0x7f6ff1ab417c in handle_display_destroy ../subprojects/wlroots/backend/multi/backend.c:124 #7 0x7f6ff106184e in wl_display_destroy (/usr/lib/libwayland-server.so.0+0x884e) #8 0x55cd1a77c9e5 in server_fini ../sway/server.c:218 #9 0x55cd1a77893f in main ../sway/main.c:400 #10 0x7f6ff04bdb24 in __libc_start_main (/usr/lib/libc.so.6+0x27b24) #11 0x55cd1a73a7ad in _start (/home/simon/src/sway/build/sway/sway+0x33a7ad) 0x602000214111 is located 1 bytes inside of 16-byte region [0x602000214110,0x602000214120) freed by thread T0 here: #0 0x7f6ff2235f19 in __interceptor_free /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cpp:127 #1 0x7f6ff1c04004 in wlr_tablet_destroy ../subprojects/wlroots/types/wlr_tablet_tool.c:24 #2 0x7f6ff1b8463c in wlr_input_device_destroy ../subprojects/wlroots/types/wlr_input_device.c:51 #3 0x7f6ff1ab9941 in backend_destroy ../subprojects/wlroots/backend/wayland/backend.c:306 #4 0x7f6ff1a68323 in wlr_backend_destroy ../subprojects/wlroots/backend/backend.c:57 #5 0x7f6ff1ab36b4 in multi_backend_destroy ../subprojects/wlroots/backend/multi/backend.c:57 #6 0x7f6ff1ab417c in handle_display_destroy ../subprojects/wlroots/backend/multi/backend.c:124 #7 0x7f6ff106184e in wl_display_destroy (/usr/lib/libwayland-server.so.0+0x884e) previously allocated by thread T0 here: #0 0x7f6ff2236279 in __interceptor_malloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cpp:145 #1 0x7f6ff1066d03 in wl_array_add (/usr/lib/libwayland-server.so.0+0xdd03) [1]: https://github.com/swaywm/wlroots/pull/3002 [2]: https://github.com/swaywm/wlroots/pull/3004
2021-07-08 13:39:33 +02:00
struct wlr_libinput_tablet_tool **tool_ptr;
wl_array_for_each(tool_ptr, &tablet->tools) {
struct wlr_libinput_tablet_tool *tool = *tool_ptr;
if (--tool->pad_refs == 0) {
destroy_tool(tool);
}
}
wl_array_release(&tablet->tools);
free(tablet);
}
static const struct wlr_tablet_impl tablet_impl = {
.destroy = destroy_tablet,
};
struct wlr_tablet *create_libinput_tablet(
struct libinput_device *libinput_dev) {
assert(libinput_dev);
struct wlr_libinput_tablet *libinput_tablet =
2018-04-24 08:10:45 +02:00
calloc(1, sizeof(struct wlr_libinput_tablet));
if (!libinput_tablet) {
2018-07-09 23:49:54 +02:00
wlr_log(WLR_ERROR, "Unable to allocate wlr_tablet_tool");
2017-08-14 16:03:05 +02:00
return NULL;
}
2021-07-01 10:09:35 +02:00
struct wlr_tablet *wlr_tablet = &libinput_tablet->wlr_tablet;
const char *name = libinput_device_get_name(libinput_dev);
wlr_tablet_init(wlr_tablet, &tablet_impl, name);
wlr_tablet->base.vendor = libinput_device_get_id_vendor(libinput_dev);
wlr_tablet->base.product = libinput_device_get_id_product(libinput_dev);
2018-04-23 08:55:49 +02:00
struct udev_device *udev = libinput_device_get_udev_device(libinput_dev);
2021-07-01 10:09:35 +02:00
char **dst = wl_array_add(&wlr_tablet->paths, sizeof(char *));
*dst = strdup(udev_device_get_syspath(udev));
wlr_tablet->name = strdup(libinput_device_get_name(libinput_dev));
2021-07-01 10:09:35 +02:00
wl_array_init(&libinput_tablet->tools);
2018-04-23 08:55:49 +02:00
return wlr_tablet;
2017-06-15 20:32:28 +02:00
}
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;
case LIBINPUT_TABLET_TOOL_TYPE_TOTEM:
return WLR_TABLET_TOOL_TYPE_TOTEM;
}
abort(); // 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 *wlr_dev) {
assert(tablet_is_libinput(wlr_dev));
2018-09-17 21:53:03 +02:00
struct wlr_libinput_tablet *tablet =
wl_container_of(wlr_dev, tablet, wlr_tablet);
Fix invalid uses of wl_array_for_each [1] and [2] have introduced new wl_array usage in wlroots, but contains a mistake: wl_array_for_each iterates over pointers to the wl_array entries, not over entries themselves. Fix all wl_array_for_each call sites. Name the variables "ptr" to avoid confusion. Found via ASan: ==148752==ERROR: AddressSanitizer: attempting free on address which was not malloc()-ed: 0x602000214111 in thread T0 #0 0x7f6ff2235f19 in __interceptor_free /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cpp:127 #1 0x7f6ff1c04004 in wlr_tablet_destroy ../subprojects/wlroots/types/wlr_tablet_tool.c:24 #2 0x7f6ff1b8463c in wlr_input_device_destroy ../subprojects/wlroots/types/wlr_input_device.c:51 #3 0x7f6ff1ab9941 in backend_destroy ../subprojects/wlroots/backend/wayland/backend.c:306 #4 0x7f6ff1a68323 in wlr_backend_destroy ../subprojects/wlroots/backend/backend.c:57 #5 0x7f6ff1ab36b4 in multi_backend_destroy ../subprojects/wlroots/backend/multi/backend.c:57 #6 0x7f6ff1ab417c in handle_display_destroy ../subprojects/wlroots/backend/multi/backend.c:124 #7 0x7f6ff106184e in wl_display_destroy (/usr/lib/libwayland-server.so.0+0x884e) #8 0x55cd1a77c9e5 in server_fini ../sway/server.c:218 #9 0x55cd1a77893f in main ../sway/main.c:400 #10 0x7f6ff04bdb24 in __libc_start_main (/usr/lib/libc.so.6+0x27b24) #11 0x55cd1a73a7ad in _start (/home/simon/src/sway/build/sway/sway+0x33a7ad) 0x602000214111 is located 1 bytes inside of 16-byte region [0x602000214110,0x602000214120) freed by thread T0 here: #0 0x7f6ff2235f19 in __interceptor_free /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cpp:127 #1 0x7f6ff1c04004 in wlr_tablet_destroy ../subprojects/wlroots/types/wlr_tablet_tool.c:24 #2 0x7f6ff1b8463c in wlr_input_device_destroy ../subprojects/wlroots/types/wlr_input_device.c:51 #3 0x7f6ff1ab9941 in backend_destroy ../subprojects/wlroots/backend/wayland/backend.c:306 #4 0x7f6ff1a68323 in wlr_backend_destroy ../subprojects/wlroots/backend/backend.c:57 #5 0x7f6ff1ab36b4 in multi_backend_destroy ../subprojects/wlroots/backend/multi/backend.c:57 #6 0x7f6ff1ab417c in handle_display_destroy ../subprojects/wlroots/backend/multi/backend.c:124 #7 0x7f6ff106184e in wl_display_destroy (/usr/lib/libwayland-server.so.0+0x884e) previously allocated by thread T0 here: #0 0x7f6ff2236279 in __interceptor_malloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cpp:145 #1 0x7f6ff1066d03 in wl_array_add (/usr/lib/libwayland-server.so.0+0xdd03) [1]: https://github.com/swaywm/wlroots/pull/3002 [2]: https://github.com/swaywm/wlroots/pull/3004
2021-07-08 13:39:33 +02:00
struct wlr_libinput_tablet_tool **tool_ptr;
wl_array_for_each(tool_ptr, &tablet->tools) {
if (*tool_ptr == 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 wlr_libinput_tablet_tool **dst =
wl_array_add(&tablet->tools, sizeof(tool));
if (!dst) {
wlr_log(WLR_ERROR, "Failed to allocate memory for tracking tablet tool");
return;
}
*dst = tool;
++tool->pad_refs;
}
2017-06-15 20:32:28 +02:00
void handle_tablet_tool_axis(struct libinput_event *event,
struct libinput_device *libinput_dev) {
struct wlr_input_device *wlr_dev =
get_appropriate_device(WLR_INPUT_DEVICE_TABLET_TOOL, libinput_dev);
if (!wlr_dev) {
2018-09-17 21:53:03 +02:00
wlr_log(WLR_DEBUG,
"Got a tablet tool event for a device with no tablet tools?");
2017-06-15 20:32:28 +02:00
return;
}
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);
2017-08-28 14:42:39 +02:00
wlr_event.device = wlr_dev;
wlr_event.tool = &tool->wlr_tool;
2017-10-30 20:43:06 +01:00
wlr_event.time_msec =
usec_to_msec(libinput_event_tablet_tool_get_time_usec(tevent));
2017-06-15 20:32:28 +02:00
if (libinput_event_tablet_tool_x_has_changed(tevent)) {
wlr_event.updated_axes |= WLR_TABLET_TOOL_AXIS_X;
2018-03-28 17:40:35 +02:00
wlr_event.x = libinput_event_tablet_tool_get_x_transformed(tevent, 1);
2018-05-25 10:04:25 +02:00
wlr_event.dx = libinput_event_tablet_tool_get_dx(tevent);
2017-06-15 20:32:28 +02:00
}
if (libinput_event_tablet_tool_y_has_changed(tevent)) {
wlr_event.updated_axes |= WLR_TABLET_TOOL_AXIS_Y;
2018-03-28 17:40:35 +02:00
wlr_event.y = libinput_event_tablet_tool_get_y_transformed(tevent, 1);
2018-05-25 10:04:25 +02:00
wlr_event.dy = libinput_event_tablet_tool_get_dy(tevent);
2017-06-15 20:32:28 +02:00
}
if (libinput_event_tablet_tool_pressure_has_changed(tevent)) {
wlr_event.updated_axes |= WLR_TABLET_TOOL_AXIS_PRESSURE;
wlr_event.pressure = libinput_event_tablet_tool_get_pressure(tevent);
2017-06-15 20:32:28 +02:00
}
if (libinput_event_tablet_tool_distance_has_changed(tevent)) {
wlr_event.updated_axes |= WLR_TABLET_TOOL_AXIS_DISTANCE;
wlr_event.distance = libinput_event_tablet_tool_get_distance(tevent);
2017-06-15 20:32:28 +02:00
}
if (libinput_event_tablet_tool_tilt_x_has_changed(tevent)) {
wlr_event.updated_axes |= WLR_TABLET_TOOL_AXIS_TILT_X;
wlr_event.tilt_x = libinput_event_tablet_tool_get_tilt_x(tevent);
2017-06-15 20:32:28 +02:00
}
if (libinput_event_tablet_tool_tilt_y_has_changed(tevent)) {
wlr_event.updated_axes |= WLR_TABLET_TOOL_AXIS_TILT_Y;
wlr_event.tilt_y = libinput_event_tablet_tool_get_tilt_y(tevent);
2017-06-15 20:32:28 +02:00
}
if (libinput_event_tablet_tool_rotation_has_changed(tevent)) {
wlr_event.updated_axes |= WLR_TABLET_TOOL_AXIS_ROTATION;
wlr_event.rotation = libinput_event_tablet_tool_get_rotation(tevent);
2017-06-15 20:32:28 +02:00
}
if (libinput_event_tablet_tool_slider_has_changed(tevent)) {
wlr_event.updated_axes |= WLR_TABLET_TOOL_AXIS_SLIDER;
wlr_event.slider = libinput_event_tablet_tool_get_slider_position(tevent);
2017-06-15 20:32:28 +02:00
}
if (libinput_event_tablet_tool_wheel_has_changed(tevent)) {
wlr_event.updated_axes |= WLR_TABLET_TOOL_AXIS_WHEEL;
wlr_event.wheel_delta = libinput_event_tablet_tool_get_wheel_delta(tevent);
2017-06-15 20:32:28 +02:00
}
wlr_signal_emit_safe(&wlr_dev->tablet->events.axis, &wlr_event);
2017-06-15 20:32:28 +02:00
}
void handle_tablet_tool_proximity(struct libinput_event *event,
struct libinput_device *libinput_dev) {
struct wlr_input_device *wlr_dev =
get_appropriate_device(WLR_INPUT_DEVICE_TABLET_TOOL, libinput_dev);
if (!wlr_dev) {
2018-09-17 21:53:03 +02:00
wlr_log(WLR_DEBUG,
"Got a tablet tool event for a device with no tablet tools?");
2017-06-15 20:32:28 +02:00
return;
}
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);
wlr_event.tool = &tool->wlr_tool;
2017-08-28 14:42:39 +02:00
wlr_event.device = wlr_dev;
2017-10-30 20:43:06 +01:00
wlr_event.time_msec =
usec_to_msec(libinput_event_tablet_tool_get_time_usec(tevent));
wlr_event.x = libinput_event_tablet_tool_get_x_transformed(tevent, 1);
wlr_event.y = libinput_event_tablet_tool_get_y_transformed(tevent, 1);
2017-06-15 20:32:28 +02:00
switch (libinput_event_tablet_tool_get_proximity_state(tevent)) {
case LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT:
wlr_event.state = WLR_TABLET_TOOL_PROXIMITY_OUT;
2017-06-15 20:32:28 +02:00
break;
case LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN:
wlr_event.state = WLR_TABLET_TOOL_PROXIMITY_IN;
2017-06-15 20:32:28 +02:00
break;
}
wlr_signal_emit_safe(&wlr_dev->tablet->events.proximity, &wlr_event);
2018-09-17 21:53:03 +02:00
if (libinput_event_tablet_tool_get_proximity_state(tevent) ==
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN) {
2018-05-04 11:46:32 +02:00
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
2018-05-02 09:26:34 +02:00
if (!tool->unique &&
2018-09-17 21:53:03 +02:00
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_is_libinput(wlr_dev->tablet));
struct wlr_libinput_tablet *tablet =
wl_container_of(wlr_dev->tablet, tablet, wlr_tablet);
size_t i = 0;
struct wlr_libinput_tablet_tool **tool_ptr;
wl_array_for_each(tool_ptr, &tablet->tools) {
if (*tool_ptr == tool) {
array_remove_at(&tablet->tools, i * sizeof(tool), sizeof(tool));
break;
}
i++;
}
destroy_tool(tool);
}
2017-06-15 20:32:28 +02:00
}
void handle_tablet_tool_tip(struct libinput_event *event,
struct libinput_device *libinput_dev) {
struct wlr_input_device *wlr_dev =
get_appropriate_device(WLR_INPUT_DEVICE_TABLET_TOOL, libinput_dev);
if (!wlr_dev) {
2018-09-17 21:53:03 +02:00
wlr_log(WLR_DEBUG,
"Got a tablet tool event for a device with no tablet tools?");
2017-06-15 20:32:28 +02:00
return;
}
handle_tablet_tool_axis(event, libinput_dev);
2017-06-15 20:32:28 +02:00
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);
2017-08-28 14:42:39 +02:00
wlr_event.device = wlr_dev;
wlr_event.tool = &tool->wlr_tool;
2017-10-30 20:43:06 +01:00
wlr_event.time_msec =
usec_to_msec(libinput_event_tablet_tool_get_time_usec(tevent));
wlr_event.x = libinput_event_tablet_tool_get_x_transformed(tevent, 1);
wlr_event.y = libinput_event_tablet_tool_get_y_transformed(tevent, 1);
2017-06-15 20:32:28 +02:00
switch (libinput_event_tablet_tool_get_tip_state(tevent)) {
case LIBINPUT_TABLET_TOOL_TIP_UP:
wlr_event.state = WLR_TABLET_TOOL_TIP_UP;
2017-06-15 20:32:28 +02:00
break;
case LIBINPUT_TABLET_TOOL_TIP_DOWN:
wlr_event.state = WLR_TABLET_TOOL_TIP_DOWN;
2017-06-15 20:32:28 +02:00
break;
}
wlr_signal_emit_safe(&wlr_dev->tablet->events.tip, &wlr_event);
2017-06-15 20:32:28 +02:00
}
void handle_tablet_tool_button(struct libinput_event *event,
struct libinput_device *libinput_dev) {
struct wlr_input_device *wlr_dev =
get_appropriate_device(WLR_INPUT_DEVICE_TABLET_TOOL, libinput_dev);
if (!wlr_dev) {
2018-09-17 21:53:03 +02:00
wlr_log(WLR_DEBUG,
"Got a tablet tool event for a device with no tablet tools?");
2017-06-15 20:32:28 +02:00
return;
}
handle_tablet_tool_axis(event, libinput_dev);
2017-06-15 20:32:28 +02:00
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);
2017-08-28 14:42:39 +02:00
wlr_event.device = wlr_dev;
wlr_event.tool = &tool->wlr_tool;
2017-10-30 20:43:06 +01:00
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);
2017-06-15 20:32:28 +02:00
switch (libinput_event_tablet_tool_get_button_state(tevent)) {
case LIBINPUT_BUTTON_STATE_RELEASED:
wlr_event.state = WLR_BUTTON_RELEASED;
2017-06-15 20:32:28 +02:00
break;
case LIBINPUT_BUTTON_STATE_PRESSED:
wlr_event.state = WLR_BUTTON_PRESSED;
2017-06-15 20:32:28 +02:00
break;
}
wlr_signal_emit_safe(&wlr_dev->tablet->events.button, &wlr_event);
2017-06-15 20:32:28 +02:00
}