diff options
author | Drew DeVault <sir@cmpwn.com> | 2017-06-15 14:32:28 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2017-06-15 14:32:53 -0400 |
commit | 4a9966b1a47d497ccc9473a24ba56b3d0eef72d2 (patch) | |
tree | cc1f747603e729873453d875315037ae9c4a8644 /backend/libinput | |
parent | e65f83d7f2f29f54b0cae27807e3b6a9b2299a10 (diff) |
Implement wlr_tablet_tool
Diffstat (limited to 'backend/libinput')
-rw-r--r-- | backend/libinput/events.c | 17 | ||||
-rw-r--r-- | backend/libinput/tablet_tool.c | 154 |
2 files changed, 170 insertions, 1 deletions
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); +} |