aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--backend/CMakeLists.txt1
-rw-r--r--backend/libinput/events.c17
-rw-r--r--backend/libinput/tablet_tool.c154
-rw-r--r--include/backend/libinput.h11
-rw-r--r--include/types.h8
-rw-r--r--include/wlr/types.h80
-rw-r--r--types/CMakeLists.txt3
-rw-r--r--types/wlr_tablet_tool.c26
8 files changed, 295 insertions, 5 deletions
diff --git a/backend/CMakeLists.txt b/backend/CMakeLists.txt
index 8272e039..6ffa2042 100644
--- a/backend/CMakeLists.txt
+++ b/backend/CMakeLists.txt
@@ -19,6 +19,7 @@ add_library(wlr-backend
libinput/keyboard.c
libinput/pointer.c
libinput/touch.c
+ libinput/tablet_tool.c
multi/backend.c
backend.c
diff --git a/backend/libinput/events.c b/backend/libinput/events.c
index f8413dae..8ebec63b 100644
--- a/backend/libinput/events.c
+++ b/backend/libinput/events.c
@@ -85,7 +85,10 @@ static void handle_device_added(struct wlr_backend_state *state,
wl_signal_emit(&state->backend->events.input_add, wlr_device);
}
if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_TABLET_TOOL)) {
- // TODO
+ struct wlr_input_device *wlr_device = allocate_device(state,
+ device, devices, WLR_INPUT_DEVICE_TABLET_TOOL);
+ wlr_device->tablet_tool = wlr_libinput_tablet_tool_create(device);
+ wl_signal_emit(&state->backend->events.input_add, wlr_device);
}
if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_TABLET_PAD)) {
// TODO
@@ -154,6 +157,18 @@ void wlr_libinput_event(struct wlr_backend_state *state,
case LIBINPUT_EVENT_TOUCH_FRAME:
// no-op (at least for now)
break;
+ case LIBINPUT_EVENT_TABLET_TOOL_AXIS:
+ handle_tablet_tool_axis(event, device);
+ break;
+ case LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY:
+ handle_tablet_tool_proximity(event, device);
+ break;
+ case LIBINPUT_EVENT_TABLET_TOOL_TIP:
+ handle_tablet_tool_tip(event, device);
+ break;
+ case LIBINPUT_EVENT_TABLET_TOOL_BUTTON:
+ handle_tablet_tool_button(event, device);
+ break;
default:
wlr_log(L_DEBUG, "Unknown libinput event %d", event_type);
break;
diff --git a/backend/libinput/tablet_tool.c b/backend/libinput/tablet_tool.c
new file mode 100644
index 00000000..276c263c
--- /dev/null
+++ b/backend/libinput/tablet_tool.c
@@ -0,0 +1,154 @@
+#include <stdlib.h>
+#include <assert.h>
+#include <libinput.h>
+#include <wlr/session.h>
+#include <wlr/types.h>
+#include <wlr/common/list.h>
+#include "backend/libinput.h"
+#include "common/log.h"
+#include "types.h"
+
+struct wlr_tablet_tool *wlr_libinput_tablet_tool_create(
+ struct libinput_device *device) {
+ assert(device);
+ return wlr_tablet_tool_create(NULL, NULL);
+}
+
+void handle_tablet_tool_axis(struct libinput_event *event,
+ struct libinput_device *device) {
+ struct wlr_input_device *dev =
+ get_appropriate_device(WLR_INPUT_DEVICE_TABLET_TOOL, device);
+ if (!dev) {
+ wlr_log(L_DEBUG, "Got a tablet tool event for a device with no tablet tools?");
+ return;
+ }
+ struct libinput_event_tablet_tool *tevent =
+ libinput_event_get_tablet_tool_event(event);
+ struct wlr_tablet_tool_axis *wlr_event =
+ calloc(1, sizeof(struct wlr_tablet_tool_axis));
+ wlr_event->time_sec = libinput_event_tablet_tool_get_time(tevent);
+ wlr_event->time_usec = libinput_event_tablet_tool_get_time_usec(tevent);
+ libinput_device_get_size(device, &wlr_event->width_mm, &wlr_event->height_mm);
+ if (libinput_event_tablet_tool_x_has_changed(tevent)) {
+ wlr_event->updated_axes |= WLR_TABLET_TOOL_AXIS_X;
+ wlr_event->x_mm = libinput_event_tablet_tool_get_x(tevent);
+ }
+ if (libinput_event_tablet_tool_y_has_changed(tevent)) {
+ wlr_event->updated_axes |= WLR_TABLET_TOOL_AXIS_Y;
+ wlr_event->y_mm = libinput_event_tablet_tool_get_y(tevent);
+ }
+ 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);
+ }
+ 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);
+ }
+ 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);
+ }
+ 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);
+ }
+ 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);
+ }
+ 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);
+ }
+ 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);
+ }
+ wl_signal_emit(&dev->tablet_tool->events.axis, wlr_event);
+}
+
+void handle_tablet_tool_proximity(struct libinput_event *event,
+ struct libinput_device *device) {
+ struct wlr_input_device *dev =
+ get_appropriate_device(WLR_INPUT_DEVICE_TABLET_TOOL, device);
+ if (!dev) {
+ wlr_log(L_DEBUG, "Got a tablet tool event for a device with no tablet tools?");
+ return;
+ }
+ // Proximity events contain axis information. We update this information
+ // before we send the proximity event
+ handle_tablet_tool_axis(event, device);
+ struct libinput_event_tablet_tool *tevent =
+ libinput_event_get_tablet_tool_event(event);
+ struct wlr_tablet_tool_proximity *wlr_event =
+ calloc(1, sizeof(struct wlr_tablet_tool_proximity));
+ wlr_event->time_sec = libinput_event_tablet_tool_get_time(tevent);
+ wlr_event->time_usec = libinput_event_tablet_tool_get_time_usec(tevent);
+ switch (libinput_event_tablet_tool_get_proximity_state(tevent)) {
+ case LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT:
+ wlr_event->state = WLR_TABLET_TOOL_PROXIMITY_OUT;
+ break;
+ case LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN:
+ wlr_event->state = WLR_TABLET_TOOL_PROXIMITY_IN;
+ break;
+ }
+ wl_signal_emit(&dev->tablet_tool->events.proximity, wlr_event);
+}
+
+void handle_tablet_tool_tip(struct libinput_event *event,
+ struct libinput_device *device) {
+ struct wlr_input_device *dev =
+ get_appropriate_device(WLR_INPUT_DEVICE_TABLET_TOOL, device);
+ if (!dev) {
+ wlr_log(L_DEBUG, "Got a tablet tool event for a device with no tablet tools?");
+ return;
+ }
+ // Tip events contain axis information. We update this information
+ // before we send the proximity event
+ handle_tablet_tool_axis(event, device);
+ struct libinput_event_tablet_tool *tevent =
+ libinput_event_get_tablet_tool_event(event);
+ struct wlr_tablet_tool_tip *wlr_event =
+ calloc(1, sizeof(struct wlr_tablet_tool_tip));
+ wlr_event->time_sec = libinput_event_tablet_tool_get_time(tevent);
+ wlr_event->time_usec = libinput_event_tablet_tool_get_time_usec(tevent);
+ switch (libinput_event_tablet_tool_get_tip_state(tevent)) {
+ case LIBINPUT_TABLET_TOOL_TIP_UP:
+ wlr_event->state = WLR_TABLET_TOOL_TIP_UP;
+ break;
+ case LIBINPUT_TABLET_TOOL_TIP_DOWN:
+ wlr_event->state = WLR_TABLET_TOOL_TIP_DOWN;
+ break;
+ }
+ wl_signal_emit(&dev->tablet_tool->events.tip, wlr_event);
+}
+
+void handle_tablet_tool_button(struct libinput_event *event,
+ struct libinput_device *device) {
+ struct wlr_input_device *dev =
+ get_appropriate_device(WLR_INPUT_DEVICE_TABLET_TOOL, device);
+ if (!dev) {
+ wlr_log(L_DEBUG, "Got a tablet tool event for a device with no tablet tools?");
+ return;
+ }
+ // Tip events contain axis information. We update this information
+ // before we send the proximity event
+ handle_tablet_tool_axis(event, device);
+ struct libinput_event_tablet_tool *tevent =
+ libinput_event_get_tablet_tool_event(event);
+ struct wlr_tablet_tool_button *wlr_event =
+ calloc(1, sizeof(struct wlr_tablet_tool_button));
+ wlr_event->time_sec = libinput_event_tablet_tool_get_time(tevent);
+ wlr_event->time_usec = libinput_event_tablet_tool_get_time_usec(tevent);
+ wlr_event->button = libinput_event_tablet_tool_get_button(tevent);
+ switch (libinput_event_tablet_tool_get_button_state(tevent)) {
+ case LIBINPUT_BUTTON_STATE_RELEASED:
+ wlr_event->state = WLR_BUTTON_RELEASED;
+ break;
+ case LIBINPUT_BUTTON_STATE_PRESSED:
+ wlr_event->state = WLR_BUTTON_PRESSED;
+ break;
+ }
+ wl_signal_emit(&dev->tablet_tool->events.button, wlr_event);
+}
diff --git a/include/backend/libinput.h b/include/backend/libinput.h
index 2427ae5c..80f57177 100644
--- a/include/backend/libinput.h
+++ b/include/backend/libinput.h
@@ -57,4 +57,15 @@ void handle_touch_motion(struct libinput_event *event,
void handle_touch_cancel(struct libinput_event *event,
struct libinput_device *device);
+struct wlr_tablet_tool *wlr_libinput_tablet_tool_create(
+ struct libinput_device *device);
+void handle_tablet_tool_axis(struct libinput_event *event,
+ struct libinput_device *device);
+void handle_tablet_tool_proximity(struct libinput_event *event,
+ struct libinput_device *device);
+void handle_tablet_tool_tip(struct libinput_event *event,
+ struct libinput_device *device);
+void handle_tablet_tool_button(struct libinput_event *event,
+ struct libinput_device *device);
+
#endif
diff --git a/include/types.h b/include/types.h
index 5b20e2ed..efead03c 100644
--- a/include/types.h
+++ b/include/types.h
@@ -42,6 +42,14 @@ struct wlr_touch *wlr_touch_create(struct wlr_touch_impl *impl,
struct wlr_touch_state *state);
void wlr_touch_destroy(struct wlr_touch *touch);
+struct wlr_tablet_tool_impl {
+ void (*destroy)(struct wlr_tablet_tool_state *tool);
+};
+
+struct wlr_tablet_tool *wlr_tablet_tool_create(struct wlr_tablet_tool_impl *impl,
+ struct wlr_tablet_tool_state *state);
+void wlr_tablet_tool_destroy(struct wlr_tablet_tool *tool);
+
struct wlr_input_device_impl {
void (*destroy)(struct wlr_input_device_state *state);
};
diff --git a/include/wlr/types.h b/include/wlr/types.h
index 4763013a..aae76f06 100644
--- a/include/wlr/types.h
+++ b/include/wlr/types.h
@@ -177,15 +177,88 @@ struct wlr_touch_cancel {
int32_t slot;
};
-// TODO: tablet & tablet tool
-// TODO: gestures
+struct wlr_tablet_tool_impl;
+struct wlr_tablet_tool_state;
+
+struct wlr_tablet_tool {
+ struct wlr_tablet_tool_impl *impl;
+ struct wlr_tablet_tool_state *state;
+
+ struct {
+ struct wl_signal axis;
+ struct wl_signal proximity;
+ struct wl_signal tip;
+ struct wl_signal button;
+ } events;
+};
+
+enum wlr_tablet_tool_axes {
+ WLR_TABLET_TOOL_AXIS_X = 1,
+ WLR_TABLET_TOOL_AXIS_Y = 2,
+ WLR_TABLET_TOOL_AXIS_DISTANCE = 4,
+ WLR_TABLET_TOOL_AXIS_PRESSURE = 8,
+ WLR_TABLET_TOOL_AXIS_TILT_X = 16,
+ WLR_TABLET_TOOL_AXIS_TILT_Y = 32,
+ WLR_TABLET_TOOL_AXIS_ROTATION = 64,
+ WLR_TABLET_TOOL_AXIS_SLIDER = 128,
+ WLR_TABLET_TOOL_AXIS_WHEEL = 256,
+};
+
+struct wlr_tablet_tool_axis {
+ uint32_t time_sec;
+ uint64_t time_usec;
+ uint32_t updated_axes;
+ double x_mm, y_mm;
+ double width_mm, height_mm;
+ double pressure;
+ double distance;
+ double tilt_x, tilt_y;
+ double rotation;
+ double slider;
+ double wheel_delta;
+};
+
+enum wlr_tablet_tool_proximity_state {
+ WLR_TABLET_TOOL_PROXIMITY_OUT,
+ WLR_TABLET_TOOL_PROXIMITY_IN,
+};
+
+struct wlr_tablet_tool_proximity {
+ uint32_t time_sec;
+ uint64_t time_usec;
+ double x, y;
+ double width_mm, height_mm;
+ enum wlr_tablet_tool_proximity_state state;
+};
+
+enum wlr_tablet_tool_tip_state {
+ WLR_TABLET_TOOL_TIP_UP,
+ WLR_TABLET_TOOL_TIP_DOWN,
+};
+
+struct wlr_tablet_tool_tip {
+ uint32_t time_sec;
+ uint64_t time_usec;
+ double x, y;
+ double width_mm, height_mm;
+ enum wlr_tablet_tool_tip_state state;
+};
+
+struct wlr_tablet_tool_button {
+ uint32_t time_sec;
+ uint64_t time_usec;
+ uint32_t button;
+ enum wlr_button_state state;
+};
+
+// TODO: tablet pad
// TODO: switch
enum wlr_input_device_type {
WLR_INPUT_DEVICE_KEYBOARD,
WLR_INPUT_DEVICE_POINTER,
WLR_INPUT_DEVICE_TOUCH,
- WLR_INPUT_DEVICE_TABLET_PEN,
+ WLR_INPUT_DEVICE_TABLET_TOOL,
WLR_INPUT_DEVICE_TABLET_PAD,
WLR_INPUT_DEVICE_GESTURE,
WLR_INPUT_DEVICE_SWITCH,
@@ -207,6 +280,7 @@ struct wlr_input_device {
struct wlr_keyboard *keyboard;
struct wlr_pointer *pointer;
struct wlr_touch *touch;
+ struct wlr_tablet_tool *tablet_tool;
};
};
diff --git a/types/CMakeLists.txt b/types/CMakeLists.txt
index b158db39..b10966ec 100644
--- a/types/CMakeLists.txt
+++ b/types/CMakeLists.txt
@@ -5,10 +5,11 @@ include_directories(
add_library(wlr-types
wlr_output.c
+ wlr_input_device.c
wlr_keyboard.c
wlr_pointer.c
wlr_touch.c
- wlr_input_device.c
+ wlr_tablet_tool.c
)
target_link_libraries(wlr-types
diff --git a/types/wlr_tablet_tool.c b/types/wlr_tablet_tool.c
new file mode 100644
index 00000000..1c1d21ee
--- /dev/null
+++ b/types/wlr_tablet_tool.c
@@ -0,0 +1,26 @@
+#include <stdlib.h>
+#include <string.h>
+#include <wayland-server.h>
+#include <wlr/types.h>
+#include <wlr/common/list.h>
+#include "types.h"
+
+struct wlr_tablet_tool *wlr_tablet_tool_create(struct wlr_tablet_tool_impl *impl,
+ struct wlr_tablet_tool_state *state) {
+ struct wlr_tablet_tool *tool = calloc(1, sizeof(struct wlr_tablet_tool));
+ tool->impl = impl;
+ tool->state = state;
+ wl_signal_init(&tool->events.axis);
+ wl_signal_init(&tool->events.proximity);
+ wl_signal_init(&tool->events.tip);
+ wl_signal_init(&tool->events.button);
+ return tool;
+}
+
+void wlr_tablet_tool_destroy(struct wlr_tablet_tool *tool) {
+ if (!tool) return;
+ if (tool->impl) {
+ tool->impl->destroy(tool->state);
+ }
+ free(tool);
+}