2017-06-14 15:40:03 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <libinput.h>
|
2017-07-11 07:18:34 +00:00
|
|
|
#include <wlr/backend/session.h>
|
2017-06-21 14:27:45 +00:00
|
|
|
#include <wlr/types/wlr_input_device.h>
|
|
|
|
#include <wlr/interfaces/wlr_touch.h>
|
2017-06-21 16:10:07 +00:00
|
|
|
#include <wlr/util/log.h>
|
2017-06-14 15:40:03 +00:00
|
|
|
#include "backend/libinput.h"
|
|
|
|
|
|
|
|
struct wlr_touch *wlr_libinput_touch_create(
|
2017-08-12 22:50:09 +00:00
|
|
|
struct libinput_device *libinput_dev) {
|
|
|
|
assert(libinput_dev);
|
2017-08-14 14:07:00 +00:00
|
|
|
struct wlr_touch *wlr_touch = calloc(1, sizeof(struct wlr_touch));
|
|
|
|
if (!wlr_touch) {
|
|
|
|
wlr_log(L_ERROR, "Unable to allocate wlr_touch");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
wlr_touch_init(wlr_touch, NULL);
|
|
|
|
return wlr_touch;
|
2017-06-14 15:40:03 +00:00
|
|
|
}
|
2017-06-14 18:50:09 +00:00
|
|
|
|
|
|
|
void handle_touch_down(struct libinput_event *event,
|
2017-08-12 22:50:09 +00:00
|
|
|
struct libinput_device *libinput_dev) {
|
|
|
|
struct wlr_input_device *wlr_dev =
|
|
|
|
get_appropriate_device(WLR_INPUT_DEVICE_TOUCH, libinput_dev);
|
|
|
|
if (!wlr_dev) {
|
2017-06-14 18:50:09 +00:00
|
|
|
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);
|
2017-08-11 16:38:27 +00:00
|
|
|
struct wlr_event_touch_down wlr_event = { 0 };
|
2017-08-27 15:44:55 +00:00
|
|
|
wlr_event.device = wlr_dev;
|
2017-10-30 19:43:06 +00:00
|
|
|
wlr_event.time_msec =
|
|
|
|
usec_to_msec(libinput_event_touch_get_time_usec(tevent));
|
2017-08-11 16:38:27 +00:00
|
|
|
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);
|
2017-08-12 22:50:09 +00:00
|
|
|
libinput_device_get_size(libinput_dev, &wlr_event.width_mm, &wlr_event.height_mm);
|
|
|
|
wl_signal_emit(&wlr_dev->touch->events.down, &wlr_event);
|
2017-06-14 18:50:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void handle_touch_up(struct libinput_event *event,
|
2017-08-12 22:50:09 +00:00
|
|
|
struct libinput_device *libinput_dev) {
|
|
|
|
struct wlr_input_device *wlr_dev =
|
|
|
|
get_appropriate_device(WLR_INPUT_DEVICE_TOUCH, libinput_dev);
|
|
|
|
if (!wlr_dev) {
|
2017-06-14 18:50:09 +00:00
|
|
|
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);
|
2017-08-11 16:38:27 +00:00
|
|
|
struct wlr_event_touch_up wlr_event = { 0 };
|
2017-08-27 15:44:55 +00:00
|
|
|
wlr_event.device = wlr_dev;
|
2017-10-30 19:43:06 +00:00
|
|
|
wlr_event.time_msec =
|
|
|
|
usec_to_msec(libinput_event_touch_get_time_usec(tevent));
|
2017-08-11 16:38:27 +00:00
|
|
|
wlr_event.slot = libinput_event_touch_get_slot(tevent);
|
2017-08-12 22:50:09 +00:00
|
|
|
wl_signal_emit(&wlr_dev->touch->events.up, &wlr_event);
|
2017-06-14 18:50:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void handle_touch_motion(struct libinput_event *event,
|
2017-08-12 22:50:09 +00:00
|
|
|
struct libinput_device *libinput_dev) {
|
|
|
|
struct wlr_input_device *wlr_dev =
|
|
|
|
get_appropriate_device(WLR_INPUT_DEVICE_TOUCH, libinput_dev);
|
|
|
|
if (!wlr_dev) {
|
2017-06-14 18:50:09 +00:00
|
|
|
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);
|
2017-08-11 16:38:27 +00:00
|
|
|
struct wlr_event_touch_motion wlr_event = { 0 };
|
2017-08-27 15:44:55 +00:00
|
|
|
wlr_event.device = wlr_dev;
|
2017-10-30 19:43:06 +00:00
|
|
|
wlr_event.time_msec =
|
|
|
|
usec_to_msec(libinput_event_touch_get_time_usec(tevent));
|
2017-08-11 16:38:27 +00:00
|
|
|
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);
|
2017-08-12 22:50:09 +00:00
|
|
|
libinput_device_get_size(libinput_dev, &wlr_event.width_mm, &wlr_event.height_mm);
|
|
|
|
wl_signal_emit(&wlr_dev->touch->events.motion, &wlr_event);
|
2017-06-14 18:50:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void handle_touch_cancel(struct libinput_event *event,
|
2017-08-12 22:50:09 +00:00
|
|
|
struct libinput_device *libinput_dev) {
|
|
|
|
struct wlr_input_device *wlr_dev =
|
|
|
|
get_appropriate_device(WLR_INPUT_DEVICE_TOUCH, libinput_dev);
|
|
|
|
if (!wlr_dev) {
|
2017-06-14 18:50:09 +00:00
|
|
|
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);
|
2017-08-11 16:38:27 +00:00
|
|
|
struct wlr_event_touch_cancel wlr_event = { 0 };
|
2017-08-27 15:44:55 +00:00
|
|
|
wlr_event.device = wlr_dev;
|
2017-10-30 19:43:06 +00:00
|
|
|
wlr_event.time_msec =
|
|
|
|
usec_to_msec(libinput_event_touch_get_time_usec(tevent));
|
2017-08-11 16:38:27 +00:00
|
|
|
wlr_event.slot = libinput_event_touch_get_slot(tevent);
|
2017-08-12 22:50:09 +00:00
|
|
|
wl_signal_emit(&wlr_dev->touch->events.cancel, &wlr_event);
|
2017-06-14 18:50:09 +00:00
|
|
|
}
|