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>
|
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"
|
2018-02-12 21:29:23 +01:00
|
|
|
#include "util/signal.h"
|
2017-06-15 20:32:28 +02:00
|
|
|
|
2018-04-21 12:42:18 +02:00
|
|
|
struct wlr_tablet_tool *libinput_tablet_tool_create(
|
2017-08-13 00:50:09 +02:00
|
|
|
struct libinput_device *libinput_dev) {
|
|
|
|
assert(libinput_dev);
|
2017-08-14 16:03:05 +02:00
|
|
|
struct wlr_tablet_tool *wlr_tablet_tool = calloc(1, sizeof(struct wlr_tablet_tool));
|
|
|
|
if (!wlr_tablet_tool) {
|
|
|
|
wlr_log(L_ERROR, "Unable to allocate wlr_tablet_tool");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
wlr_tablet_tool_init(wlr_tablet_tool, NULL);
|
|
|
|
return wlr_tablet_tool;
|
2017-06-15 20:32:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void handle_tablet_tool_axis(struct libinput_event *event,
|
2017-08-13 00:50:09 +02:00
|
|
|
struct libinput_device *libinput_dev) {
|
|
|
|
struct wlr_input_device *wlr_dev =
|
|
|
|
get_appropriate_device(WLR_INPUT_DEVICE_TABLET_TOOL, libinput_dev);
|
|
|
|
if (!wlr_dev) {
|
2017-06-15 20:32:28 +02:00
|
|
|
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);
|
2017-08-11 18:38:27 +02:00
|
|
|
struct wlr_event_tablet_tool_axis wlr_event = { 0 };
|
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));
|
2017-06-15 20:32:28 +02:00
|
|
|
if (libinput_event_tablet_tool_x_has_changed(tevent)) {
|
2017-08-11 18:38:27 +02:00
|
|
|
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);
|
2017-06-15 20:32:28 +02:00
|
|
|
}
|
|
|
|
if (libinput_event_tablet_tool_y_has_changed(tevent)) {
|
2017-08-11 18:38:27 +02:00
|
|
|
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);
|
2017-06-15 20:32:28 +02:00
|
|
|
}
|
|
|
|
if (libinput_event_tablet_tool_pressure_has_changed(tevent)) {
|
2017-08-11 18:38:27 +02:00
|
|
|
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)) {
|
2017-08-11 18:38:27 +02:00
|
|
|
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)) {
|
2017-08-11 18:38:27 +02:00
|
|
|
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)) {
|
2017-08-11 18:38:27 +02:00
|
|
|
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)) {
|
2017-08-11 18:38:27 +02:00
|
|
|
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)) {
|
2017-08-11 18:38:27 +02:00
|
|
|
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)) {
|
2017-08-11 18:38:27 +02:00
|
|
|
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
|
|
|
}
|
2018-02-12 09:12:31 +01:00
|
|
|
wlr_signal_emit_safe(&wlr_dev->tablet_tool->events.axis, &wlr_event);
|
2017-06-15 20:32:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void handle_tablet_tool_proximity(struct libinput_event *event,
|
2017-08-13 00:50:09 +02:00
|
|
|
struct libinput_device *libinput_dev) {
|
|
|
|
struct wlr_input_device *wlr_dev =
|
|
|
|
get_appropriate_device(WLR_INPUT_DEVICE_TABLET_TOOL, libinput_dev);
|
|
|
|
if (!wlr_dev) {
|
2017-06-15 20:32:28 +02:00
|
|
|
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);
|
2017-08-11 18:38:27 +02:00
|
|
|
struct wlr_event_tablet_tool_proximity wlr_event = { 0 };
|
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));
|
2017-06-15 20:32:28 +02:00
|
|
|
switch (libinput_event_tablet_tool_get_proximity_state(tevent)) {
|
|
|
|
case LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT:
|
2017-08-11 18:38:27 +02:00
|
|
|
wlr_event.state = WLR_TABLET_TOOL_PROXIMITY_OUT;
|
2017-06-15 20:32:28 +02:00
|
|
|
break;
|
|
|
|
case LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN:
|
2017-08-11 18:38:27 +02:00
|
|
|
wlr_event.state = WLR_TABLET_TOOL_PROXIMITY_IN;
|
2017-08-13 00:50:09 +02:00
|
|
|
handle_tablet_tool_axis(event, libinput_dev);
|
2017-06-15 20:32:28 +02:00
|
|
|
break;
|
|
|
|
}
|
2018-02-12 09:12:31 +01:00
|
|
|
wlr_signal_emit_safe(&wlr_dev->tablet_tool->events.proximity, &wlr_event);
|
2017-06-15 20:32:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void handle_tablet_tool_tip(struct libinput_event *event,
|
2017-08-13 00:50:09 +02:00
|
|
|
struct libinput_device *libinput_dev) {
|
|
|
|
struct wlr_input_device *wlr_dev =
|
|
|
|
get_appropriate_device(WLR_INPUT_DEVICE_TABLET_TOOL, libinput_dev);
|
|
|
|
if (!wlr_dev) {
|
2017-06-15 20:32:28 +02:00
|
|
|
wlr_log(L_DEBUG, "Got a tablet tool event for a device with no tablet tools?");
|
|
|
|
return;
|
|
|
|
}
|
2017-08-13 00:50:09 +02:00
|
|
|
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);
|
2017-08-11 18:38:27 +02:00
|
|
|
struct wlr_event_tablet_tool_tip wlr_event = { 0 };
|
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));
|
2017-06-15 20:32:28 +02:00
|
|
|
switch (libinput_event_tablet_tool_get_tip_state(tevent)) {
|
|
|
|
case LIBINPUT_TABLET_TOOL_TIP_UP:
|
2017-08-11 18:38:27 +02:00
|
|
|
wlr_event.state = WLR_TABLET_TOOL_TIP_UP;
|
2017-06-15 20:32:28 +02:00
|
|
|
break;
|
|
|
|
case LIBINPUT_TABLET_TOOL_TIP_DOWN:
|
2017-08-11 18:38:27 +02:00
|
|
|
wlr_event.state = WLR_TABLET_TOOL_TIP_DOWN;
|
2017-06-15 20:32:28 +02:00
|
|
|
break;
|
|
|
|
}
|
2018-02-12 09:12:31 +01:00
|
|
|
wlr_signal_emit_safe(&wlr_dev->tablet_tool->events.tip, &wlr_event);
|
2017-06-15 20:32:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void handle_tablet_tool_button(struct libinput_event *event,
|
2017-08-13 00:50:09 +02:00
|
|
|
struct libinput_device *libinput_dev) {
|
|
|
|
struct wlr_input_device *wlr_dev =
|
|
|
|
get_appropriate_device(WLR_INPUT_DEVICE_TABLET_TOOL, libinput_dev);
|
|
|
|
if (!wlr_dev) {
|
2017-06-15 20:32:28 +02:00
|
|
|
wlr_log(L_DEBUG, "Got a tablet tool event for a device with no tablet tools?");
|
|
|
|
return;
|
|
|
|
}
|
2017-08-13 00:50:09 +02:00
|
|
|
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);
|
2017-08-11 18:38:27 +02:00
|
|
|
struct wlr_event_tablet_tool_button wlr_event = { 0 };
|
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));
|
2017-08-11 18:38:27 +02:00
|
|
|
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:
|
2017-08-11 18:38:27 +02:00
|
|
|
wlr_event.state = WLR_BUTTON_RELEASED;
|
2017-06-15 20:32:28 +02:00
|
|
|
break;
|
|
|
|
case LIBINPUT_BUTTON_STATE_PRESSED:
|
2017-08-11 18:38:27 +02:00
|
|
|
wlr_event.state = WLR_BUTTON_PRESSED;
|
2017-06-15 20:32:28 +02:00
|
|
|
break;
|
|
|
|
}
|
2018-02-12 09:12:31 +01:00
|
|
|
wlr_signal_emit_safe(&wlr_dev->tablet_tool->events.button, &wlr_event);
|
2017-06-15 20:32:28 +02:00
|
|
|
}
|