2017-06-13 16:27:15 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <libinput.h>
|
2017-07-11 09:18:34 +02:00
|
|
|
#include <wlr/backend/session.h>
|
2017-06-21 16:27:45 +02:00
|
|
|
#include <wlr/types/wlr_input_device.h>
|
|
|
|
#include <wlr/interfaces/wlr_pointer.h>
|
2017-06-21 18:10:07 +02:00
|
|
|
#include <wlr/util/log.h>
|
2018-02-12 19:45:58 +01:00
|
|
|
#include "util/signal.h"
|
2017-06-13 16:27:15 +02:00
|
|
|
#include "backend/libinput.h"
|
|
|
|
|
|
|
|
struct wlr_pointer *wlr_libinput_pointer_create(
|
2017-08-13 00:50:09 +02:00
|
|
|
struct libinput_device *libinput_dev) {
|
|
|
|
assert(libinput_dev);
|
2017-08-14 15:55:48 +02:00
|
|
|
struct wlr_pointer *wlr_pointer = calloc(1, sizeof(struct wlr_pointer));
|
|
|
|
if (!wlr_pointer) {
|
|
|
|
wlr_log(L_ERROR, "Unable to allocate wlr_pointer");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
wlr_pointer_init(wlr_pointer, NULL);
|
|
|
|
return wlr_pointer;
|
2017-06-13 16:27:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void handle_pointer_motion(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_POINTER, libinput_dev);
|
|
|
|
if (!wlr_dev) {
|
2017-06-13 16:27:15 +02:00
|
|
|
wlr_log(L_DEBUG, "Got a pointer event for a device with no pointers?");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
struct libinput_event_pointer *pevent =
|
|
|
|
libinput_event_get_pointer_event(event);
|
2017-08-11 18:38:27 +02:00
|
|
|
struct wlr_event_pointer_motion wlr_event = { 0 };
|
2017-08-24 20:35:55 +02:00
|
|
|
wlr_event.device = wlr_dev;
|
2017-10-30 20:43:06 +01:00
|
|
|
wlr_event.time_msec =
|
|
|
|
usec_to_msec(libinput_event_pointer_get_time_usec(pevent));
|
2017-08-11 18:38:27 +02:00
|
|
|
wlr_event.delta_x = libinput_event_pointer_get_dx(pevent);
|
|
|
|
wlr_event.delta_y = libinput_event_pointer_get_dy(pevent);
|
2018-02-12 09:12:31 +01:00
|
|
|
wlr_signal_emit_safe(&wlr_dev->pointer->events.motion, &wlr_event);
|
2017-06-13 16:27:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void handle_pointer_motion_abs(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_POINTER, libinput_dev);
|
|
|
|
if (!wlr_dev) {
|
2017-06-13 16:27:15 +02:00
|
|
|
wlr_log(L_DEBUG, "Got a pointer event for a device with no pointers?");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
struct libinput_event_pointer *pevent =
|
|
|
|
libinput_event_get_pointer_event(event);
|
2017-08-11 18:38:27 +02:00
|
|
|
struct wlr_event_pointer_motion_absolute wlr_event = { 0 };
|
2017-08-24 20:35:55 +02:00
|
|
|
wlr_event.device = wlr_dev;
|
2017-10-30 20:43:06 +01:00
|
|
|
wlr_event.time_msec =
|
|
|
|
usec_to_msec(libinput_event_pointer_get_time_usec(pevent));
|
2017-08-11 18:38:27 +02:00
|
|
|
wlr_event.x_mm = libinput_event_pointer_get_absolute_x(pevent);
|
|
|
|
wlr_event.y_mm = libinput_event_pointer_get_absolute_y(pevent);
|
2017-08-13 00:50:09 +02:00
|
|
|
libinput_device_get_size(libinput_dev, &wlr_event.width_mm, &wlr_event.height_mm);
|
2018-02-12 09:12:31 +01:00
|
|
|
wlr_signal_emit_safe(&wlr_dev->pointer->events.motion_absolute, &wlr_event);
|
2017-06-13 16:27:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void handle_pointer_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_POINTER, libinput_dev);
|
|
|
|
if (!wlr_dev) {
|
2017-06-13 16:27:15 +02:00
|
|
|
wlr_log(L_DEBUG, "Got a pointer event for a device with no pointers?");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
struct libinput_event_pointer *pevent =
|
|
|
|
libinput_event_get_pointer_event(event);
|
2017-08-11 18:38:27 +02:00
|
|
|
struct wlr_event_pointer_button wlr_event = { 0 };
|
2017-08-24 20:35:55 +02:00
|
|
|
wlr_event.device = wlr_dev;
|
2017-10-30 20:43:06 +01:00
|
|
|
wlr_event.time_msec =
|
|
|
|
usec_to_msec(libinput_event_pointer_get_time_usec(pevent));
|
2017-08-11 18:38:27 +02:00
|
|
|
wlr_event.button = libinput_event_pointer_get_button(pevent);
|
2017-06-13 16:27:15 +02:00
|
|
|
switch (libinput_event_pointer_get_button_state(pevent)) {
|
|
|
|
case LIBINPUT_BUTTON_STATE_PRESSED:
|
2017-08-11 18:38:27 +02:00
|
|
|
wlr_event.state = WLR_BUTTON_PRESSED;
|
2017-06-13 16:27:15 +02:00
|
|
|
break;
|
|
|
|
case LIBINPUT_BUTTON_STATE_RELEASED:
|
2017-08-11 18:38:27 +02:00
|
|
|
wlr_event.state = WLR_BUTTON_RELEASED;
|
2017-06-13 16:27:15 +02:00
|
|
|
break;
|
|
|
|
}
|
2018-02-12 09:12:31 +01:00
|
|
|
wlr_signal_emit_safe(&wlr_dev->pointer->events.button, &wlr_event);
|
2017-06-13 16:27:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void handle_pointer_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_POINTER, libinput_dev);
|
|
|
|
if (!wlr_dev) {
|
2017-06-13 16:27:15 +02:00
|
|
|
wlr_log(L_DEBUG, "Got a pointer event for a device with no pointers?");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
struct libinput_event_pointer *pevent =
|
|
|
|
libinput_event_get_pointer_event(event);
|
2017-08-11 18:38:27 +02:00
|
|
|
struct wlr_event_pointer_axis wlr_event = { 0 };
|
2017-08-24 20:35:55 +02:00
|
|
|
wlr_event.device = wlr_dev;
|
2017-10-30 20:43:06 +01:00
|
|
|
wlr_event.time_msec =
|
|
|
|
usec_to_msec(libinput_event_pointer_get_time_usec(pevent));
|
2017-06-13 16:27:15 +02:00
|
|
|
switch (libinput_event_pointer_get_axis_source(pevent)) {
|
|
|
|
case LIBINPUT_POINTER_AXIS_SOURCE_WHEEL:
|
2017-08-11 18:38:27 +02:00
|
|
|
wlr_event.source = WLR_AXIS_SOURCE_WHEEL;
|
2017-06-13 16:27:15 +02:00
|
|
|
break;
|
|
|
|
case LIBINPUT_POINTER_AXIS_SOURCE_FINGER:
|
2017-08-11 18:38:27 +02:00
|
|
|
wlr_event.source = WLR_AXIS_SOURCE_FINGER;
|
2017-06-13 16:27:15 +02:00
|
|
|
break;
|
|
|
|
case LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS:
|
2017-08-11 18:38:27 +02:00
|
|
|
wlr_event.source = WLR_AXIS_SOURCE_CONTINUOUS;
|
2017-06-13 16:27:15 +02:00
|
|
|
break;
|
|
|
|
case LIBINPUT_POINTER_AXIS_SOURCE_WHEEL_TILT:
|
2017-08-11 18:38:27 +02:00
|
|
|
wlr_event.source = WLR_AXIS_SOURCE_WHEEL_TILT;
|
2017-06-13 16:27:15 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
enum libinput_pointer_axis axies[] = {
|
|
|
|
LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL,
|
|
|
|
LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL,
|
|
|
|
};
|
|
|
|
for (size_t i = 0; i < sizeof(axies) / sizeof(axies[0]); ++i) {
|
|
|
|
if (libinput_event_pointer_has_axis(pevent, axies[i])) {
|
|
|
|
switch (axies[i]) {
|
|
|
|
case LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL:
|
2017-08-11 18:38:27 +02:00
|
|
|
wlr_event.orientation = WLR_AXIS_ORIENTATION_VERTICAL;
|
2017-06-13 16:27:15 +02:00
|
|
|
break;
|
|
|
|
case LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL:
|
2017-08-11 18:38:27 +02:00
|
|
|
wlr_event.orientation = WLR_AXIS_ORIENTATION_HORIZONTAL;
|
2017-06-13 16:27:15 +02:00
|
|
|
break;
|
|
|
|
}
|
2017-08-11 18:38:27 +02:00
|
|
|
wlr_event.delta = libinput_event_pointer_get_axis_value(
|
2017-06-13 16:27:15 +02:00
|
|
|
pevent, axies[i]);
|
2018-02-12 09:12:31 +01:00
|
|
|
wlr_signal_emit_safe(&wlr_dev->pointer->events.axis, &wlr_event);
|
2017-06-13 16:27:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|