diff options
author | nyorain <nyorain@gmail.com> | 2017-06-19 17:49:26 +0200 |
---|---|---|
committer | nyorain <nyorain@gmail.com> | 2017-06-19 17:49:26 +0200 |
commit | 41a477375cf5fc2cfafc97fb6d98e4e3457dfa62 (patch) | |
tree | 93e318287fb70b21dd0f5d7f90551810fa85a7dd /backend/libinput/touch.c | |
parent | 904739c40596cb4e9e9d48c89b1d864051237441 (diff) | |
parent | 7e038a6110501a51e7f3d3366e8bc54a02766f22 (diff) |
Merge branch 'libinput' into wayland-backend
Diffstat (limited to 'backend/libinput/touch.c')
-rw-r--r-- | backend/libinput/touch.c | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/backend/libinput/touch.c b/backend/libinput/touch.c new file mode 100644 index 00000000..02c9cfef --- /dev/null +++ b/backend/libinput/touch.c @@ -0,0 +1,93 @@ +#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_touch *wlr_libinput_touch_create( + struct libinput_device *device) { + assert(device); + return wlr_touch_create(NULL, NULL); +} + +void handle_touch_down(struct libinput_event *event, + struct libinput_device *device) { + struct wlr_input_device *dev = + get_appropriate_device(WLR_INPUT_DEVICE_TOUCH, device); + if (!dev) { + wlr_log(L_DEBUG, "Got a touch event for a device with no touch?"); + return; + } + struct libinput_event_touch *tevent = + libinput_event_get_touch_event(event); + struct wlr_touch_down *wlr_event = + calloc(1, sizeof(struct wlr_touch_down)); + wlr_event->time_sec = libinput_event_touch_get_time(tevent); + wlr_event->time_usec = libinput_event_touch_get_time_usec(tevent); + wlr_event->slot = libinput_event_touch_get_slot(tevent); + wlr_event->x_mm = libinput_event_touch_get_x(tevent); + wlr_event->y_mm = libinput_event_touch_get_y(tevent); + libinput_device_get_size(device, &wlr_event->width_mm, &wlr_event->height_mm); + wl_signal_emit(&dev->touch->events.down, wlr_event); +} + +void handle_touch_up(struct libinput_event *event, + struct libinput_device *device) { + struct wlr_input_device *dev = + get_appropriate_device(WLR_INPUT_DEVICE_TOUCH, device); + if (!dev) { + wlr_log(L_DEBUG, "Got a touch event for a device with no touch?"); + return; + } + struct libinput_event_touch *tevent = + libinput_event_get_touch_event(event); + struct wlr_touch_up *wlr_event = + calloc(1, sizeof(struct wlr_touch_up)); + wlr_event->time_sec = libinput_event_touch_get_time(tevent); + wlr_event->time_usec = libinput_event_touch_get_time_usec(tevent); + wlr_event->slot = libinput_event_touch_get_slot(tevent); + wl_signal_emit(&dev->touch->events.up, wlr_event); +} + +void handle_touch_motion(struct libinput_event *event, + struct libinput_device *device) { + struct wlr_input_device *dev = + get_appropriate_device(WLR_INPUT_DEVICE_TOUCH, device); + if (!dev) { + wlr_log(L_DEBUG, "Got a touch event for a device with no touch?"); + return; + } + struct libinput_event_touch *tevent = + libinput_event_get_touch_event(event); + struct wlr_touch_motion *wlr_event = + calloc(1, sizeof(struct wlr_touch_motion)); + wlr_event->time_sec = libinput_event_touch_get_time(tevent); + wlr_event->time_usec = libinput_event_touch_get_time_usec(tevent); + wlr_event->slot = libinput_event_touch_get_slot(tevent); + wlr_event->x_mm = libinput_event_touch_get_x(tevent); + wlr_event->y_mm = libinput_event_touch_get_y(tevent); + libinput_device_get_size(device, &wlr_event->width_mm, &wlr_event->height_mm); + wl_signal_emit(&dev->touch->events.motion, wlr_event); +} + +void handle_touch_cancel(struct libinput_event *event, + struct libinput_device *device) { + struct wlr_input_device *dev = + get_appropriate_device(WLR_INPUT_DEVICE_TOUCH, device); + if (!dev) { + wlr_log(L_DEBUG, "Got a touch event for a device with no touch?"); + return; + } + struct libinput_event_touch *tevent = + libinput_event_get_touch_event(event); + struct wlr_touch_cancel *wlr_event = + calloc(1, sizeof(struct wlr_touch_cancel)); + wlr_event->time_sec = libinput_event_touch_get_time(tevent); + wlr_event->time_usec = libinput_event_touch_get_time_usec(tevent); + wlr_event->slot = libinput_event_touch_get_slot(tevent); + wl_signal_emit(&dev->touch->events.cancel, wlr_event); +} |