2017-06-13 14:27:15 +00:00
|
|
|
#include <assert.h>
|
|
|
|
#include <libinput.h>
|
2022-02-28 16:57:35 +00:00
|
|
|
#include <wlr/interfaces/wlr_pointer.h>
|
2017-06-13 14:27:15 +00:00
|
|
|
#include "backend/libinput.h"
|
|
|
|
|
2022-02-28 16:57:35 +00:00
|
|
|
const struct wlr_pointer_impl libinput_pointer_impl = {
|
2022-03-02 18:57:28 +00:00
|
|
|
.name = "libinput-pointer",
|
2022-02-28 16:57:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void init_device_pointer(struct wlr_libinput_input_device *dev) {
|
2024-02-29 11:08:02 +00:00
|
|
|
const char *name = get_libinput_device_name(dev->handle);
|
2022-02-28 16:57:35 +00:00
|
|
|
struct wlr_pointer *wlr_pointer = &dev->pointer;
|
2022-02-09 21:03:12 +00:00
|
|
|
wlr_pointer_init(wlr_pointer, &libinput_pointer_impl, name);
|
2022-02-28 16:57:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct wlr_libinput_input_device *device_from_pointer(
|
|
|
|
struct wlr_pointer *wlr_pointer) {
|
|
|
|
assert(wlr_pointer->impl == &libinput_pointer_impl);
|
|
|
|
|
|
|
|
struct wlr_libinput_input_device *dev =
|
|
|
|
wl_container_of(wlr_pointer, dev, pointer);
|
|
|
|
return dev;
|
2017-06-13 14:27:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void handle_pointer_motion(struct libinput_event *event,
|
2022-02-28 16:57:35 +00:00
|
|
|
struct wlr_pointer *pointer) {
|
2017-06-13 14:27:15 +00:00
|
|
|
struct libinput_event_pointer *pevent =
|
|
|
|
libinput_event_get_pointer_event(event);
|
2023-06-08 15:21:07 +00:00
|
|
|
struct wlr_pointer_motion_event wlr_event = {
|
|
|
|
.pointer = pointer,
|
|
|
|
.time_msec = usec_to_msec(libinput_event_pointer_get_time_usec(pevent)),
|
|
|
|
.delta_x = libinput_event_pointer_get_dx(pevent),
|
|
|
|
.delta_y = libinput_event_pointer_get_dy(pevent),
|
|
|
|
.unaccel_dx = libinput_event_pointer_get_dx_unaccelerated(pevent),
|
|
|
|
.unaccel_dy = libinput_event_pointer_get_dy_unaccelerated(pevent),
|
|
|
|
};
|
2022-08-18 11:16:16 +00:00
|
|
|
wl_signal_emit_mutable(&pointer->events.motion, &wlr_event);
|
|
|
|
wl_signal_emit_mutable(&pointer->events.frame, pointer);
|
2017-06-13 14:27:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void handle_pointer_motion_abs(struct libinput_event *event,
|
2022-02-28 16:57:35 +00:00
|
|
|
struct wlr_pointer *pointer) {
|
2017-06-13 14:27:15 +00:00
|
|
|
struct libinput_event_pointer *pevent =
|
|
|
|
libinput_event_get_pointer_event(event);
|
2023-06-08 15:21:07 +00:00
|
|
|
struct wlr_pointer_motion_absolute_event wlr_event = {
|
|
|
|
.pointer = pointer,
|
|
|
|
.time_msec = usec_to_msec(libinput_event_pointer_get_time_usec(pevent)),
|
|
|
|
.x = libinput_event_pointer_get_absolute_x_transformed(pevent, 1),
|
|
|
|
.y = libinput_event_pointer_get_absolute_y_transformed(pevent, 1),
|
|
|
|
};
|
2022-08-18 11:16:16 +00:00
|
|
|
wl_signal_emit_mutable(&pointer->events.motion_absolute, &wlr_event);
|
|
|
|
wl_signal_emit_mutable(&pointer->events.frame, pointer);
|
2017-06-13 14:27:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void handle_pointer_button(struct libinput_event *event,
|
2022-02-28 16:57:35 +00:00
|
|
|
struct wlr_pointer *pointer) {
|
2017-06-13 14:27:15 +00:00
|
|
|
struct libinput_event_pointer *pevent =
|
|
|
|
libinput_event_get_pointer_event(event);
|
2023-06-08 15:21:07 +00:00
|
|
|
struct wlr_pointer_button_event wlr_event = {
|
|
|
|
.pointer = pointer,
|
|
|
|
.time_msec = usec_to_msec(libinput_event_pointer_get_time_usec(pevent)),
|
|
|
|
.button = libinput_event_pointer_get_button(pevent),
|
|
|
|
};
|
2017-06-13 14:27:15 +00:00
|
|
|
switch (libinput_event_pointer_get_button_state(pevent)) {
|
|
|
|
case LIBINPUT_BUTTON_STATE_PRESSED:
|
2024-02-28 09:26:38 +00:00
|
|
|
wlr_event.state = WL_POINTER_BUTTON_STATE_PRESSED;
|
2017-06-13 14:27:15 +00:00
|
|
|
break;
|
|
|
|
case LIBINPUT_BUTTON_STATE_RELEASED:
|
2024-02-28 09:26:38 +00:00
|
|
|
wlr_event.state = WL_POINTER_BUTTON_STATE_RELEASED;
|
2017-06-13 14:27:15 +00:00
|
|
|
break;
|
|
|
|
}
|
2022-08-18 11:16:16 +00:00
|
|
|
wl_signal_emit_mutable(&pointer->events.button, &wlr_event);
|
|
|
|
wl_signal_emit_mutable(&pointer->events.frame, pointer);
|
2017-06-13 14:27:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void handle_pointer_axis(struct libinput_event *event,
|
2022-02-28 16:57:35 +00:00
|
|
|
struct wlr_pointer *pointer) {
|
2017-06-13 14:27:15 +00:00
|
|
|
struct libinput_event_pointer *pevent =
|
|
|
|
libinput_event_get_pointer_event(event);
|
2023-06-08 15:21:07 +00:00
|
|
|
struct wlr_pointer_axis_event wlr_event = {
|
|
|
|
.pointer = pointer,
|
|
|
|
.time_msec = usec_to_msec(libinput_event_pointer_get_time_usec(pevent)),
|
|
|
|
};
|
2017-06-13 14:27:15 +00:00
|
|
|
switch (libinput_event_pointer_get_axis_source(pevent)) {
|
|
|
|
case LIBINPUT_POINTER_AXIS_SOURCE_WHEEL:
|
2024-02-28 09:15:13 +00:00
|
|
|
wlr_event.source = WL_POINTER_AXIS_SOURCE_WHEEL;
|
2017-06-13 14:27:15 +00:00
|
|
|
break;
|
|
|
|
case LIBINPUT_POINTER_AXIS_SOURCE_FINGER:
|
2024-02-28 09:15:13 +00:00
|
|
|
wlr_event.source = WL_POINTER_AXIS_SOURCE_FINGER;
|
2017-06-13 14:27:15 +00:00
|
|
|
break;
|
|
|
|
case LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS:
|
2024-02-28 09:15:13 +00:00
|
|
|
wlr_event.source = WL_POINTER_AXIS_SOURCE_CONTINUOUS;
|
2017-06-13 14:27:15 +00:00
|
|
|
break;
|
|
|
|
case LIBINPUT_POINTER_AXIS_SOURCE_WHEEL_TILT:
|
2024-02-28 09:15:13 +00:00
|
|
|
wlr_event.source = WL_POINTER_AXIS_SOURCE_WHEEL_TILT;
|
2017-06-13 14:27:15 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-01-26 10:04:05 +00:00
|
|
|
const enum libinput_pointer_axis axes[] = {
|
2017-06-13 14:27:15 +00:00
|
|
|
LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL,
|
|
|
|
LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL,
|
|
|
|
};
|
2019-01-26 10:04:05 +00:00
|
|
|
for (size_t i = 0; i < sizeof(axes) / sizeof(axes[0]); ++i) {
|
2022-02-25 16:30:51 +00:00
|
|
|
if (!libinput_event_pointer_has_axis(pevent, axes[i])) {
|
|
|
|
continue;
|
2017-06-13 14:27:15 +00:00
|
|
|
}
|
2022-02-25 16:30:51 +00:00
|
|
|
|
|
|
|
switch (axes[i]) {
|
|
|
|
case LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL:
|
2024-02-28 09:33:39 +00:00
|
|
|
wlr_event.orientation = WL_POINTER_AXIS_VERTICAL_SCROLL;
|
2022-02-25 16:30:51 +00:00
|
|
|
break;
|
|
|
|
case LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL:
|
2024-02-28 09:33:39 +00:00
|
|
|
wlr_event.orientation = WL_POINTER_AXIS_HORIZONTAL_SCROLL;
|
2022-02-25 16:30:51 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
wlr_event.delta =
|
|
|
|
libinput_event_pointer_get_axis_value(pevent, axes[i]);
|
|
|
|
wlr_event.delta_discrete =
|
|
|
|
libinput_event_pointer_get_axis_value_discrete(pevent, axes[i]);
|
|
|
|
wlr_event.delta_discrete *= WLR_POINTER_AXIS_DISCRETE_STEP;
|
2024-02-28 09:31:03 +00:00
|
|
|
wlr_event.relative_direction = WL_POINTER_AXIS_RELATIVE_DIRECTION_IDENTICAL;
|
2023-02-11 12:34:12 +00:00
|
|
|
if (libinput_device_config_scroll_get_natural_scroll_enabled(libinput_event_get_device(event))) {
|
2024-02-28 09:31:03 +00:00
|
|
|
wlr_event.relative_direction = WL_POINTER_AXIS_RELATIVE_DIRECTION_INVERTED;
|
2023-02-11 12:34:12 +00:00
|
|
|
}
|
2022-08-18 11:16:16 +00:00
|
|
|
wl_signal_emit_mutable(&pointer->events.axis, &wlr_event);
|
2017-06-13 14:27:15 +00:00
|
|
|
}
|
2022-08-18 11:16:16 +00:00
|
|
|
wl_signal_emit_mutable(&pointer->events.frame, pointer);
|
2017-06-13 14:27:15 +00:00
|
|
|
}
|
2019-01-25 22:51:38 +00:00
|
|
|
|
2022-02-25 16:30:42 +00:00
|
|
|
void handle_pointer_axis_value120(struct libinput_event *event,
|
2024-02-28 09:15:13 +00:00
|
|
|
struct wlr_pointer *pointer, enum wl_pointer_axis_source source) {
|
2022-02-25 16:30:42 +00:00
|
|
|
struct libinput_event_pointer *pevent =
|
|
|
|
libinput_event_get_pointer_event(event);
|
2023-06-08 15:21:07 +00:00
|
|
|
struct wlr_pointer_axis_event wlr_event = {
|
|
|
|
.pointer = pointer,
|
|
|
|
.time_msec = usec_to_msec(libinput_event_pointer_get_time_usec(pevent)),
|
|
|
|
.source = source,
|
|
|
|
};
|
2022-02-25 16:30:42 +00:00
|
|
|
|
|
|
|
const enum libinput_pointer_axis axes[] = {
|
|
|
|
LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL,
|
|
|
|
LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL,
|
|
|
|
};
|
|
|
|
for (size_t i = 0; i < sizeof(axes) / sizeof(axes[0]); ++i) {
|
|
|
|
if (!libinput_event_pointer_has_axis(pevent, axes[i])) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
switch (axes[i]) {
|
|
|
|
case LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL:
|
2024-02-28 09:33:39 +00:00
|
|
|
wlr_event.orientation = WL_POINTER_AXIS_VERTICAL_SCROLL;
|
2022-02-25 16:30:42 +00:00
|
|
|
break;
|
|
|
|
case LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL:
|
2024-02-28 09:33:39 +00:00
|
|
|
wlr_event.orientation = WL_POINTER_AXIS_HORIZONTAL_SCROLL;
|
2022-02-25 16:30:42 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
wlr_event.delta =
|
|
|
|
libinput_event_pointer_get_scroll_value(pevent, axes[i]);
|
2024-02-28 09:15:13 +00:00
|
|
|
if (source == WL_POINTER_AXIS_SOURCE_WHEEL) {
|
2022-02-25 16:30:42 +00:00
|
|
|
wlr_event.delta_discrete =
|
|
|
|
libinput_event_pointer_get_scroll_value_v120(pevent, axes[i]);
|
|
|
|
}
|
2022-08-18 11:16:16 +00:00
|
|
|
wl_signal_emit_mutable(&pointer->events.axis, &wlr_event);
|
2022-02-25 16:30:42 +00:00
|
|
|
}
|
2022-08-18 11:16:16 +00:00
|
|
|
wl_signal_emit_mutable(&pointer->events.frame, pointer);
|
2022-02-25 16:30:42 +00:00
|
|
|
}
|
|
|
|
|
2019-01-25 22:51:38 +00:00
|
|
|
void handle_pointer_swipe_begin(struct libinput_event *event,
|
2022-02-28 16:57:35 +00:00
|
|
|
struct wlr_pointer *pointer) {
|
2019-01-25 22:51:38 +00:00
|
|
|
struct libinput_event_gesture *gevent =
|
|
|
|
libinput_event_get_gesture_event(event);
|
2022-03-09 19:52:27 +00:00
|
|
|
struct wlr_pointer_swipe_begin_event wlr_event = {
|
|
|
|
.pointer = pointer,
|
2019-01-25 22:51:38 +00:00
|
|
|
.time_msec =
|
|
|
|
usec_to_msec(libinput_event_gesture_get_time_usec(gevent)),
|
|
|
|
.fingers = libinput_event_gesture_get_finger_count(gevent),
|
|
|
|
};
|
2022-08-18 11:16:16 +00:00
|
|
|
wl_signal_emit_mutable(&pointer->events.swipe_begin, &wlr_event);
|
2019-01-25 22:51:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void handle_pointer_swipe_update(struct libinput_event *event,
|
2022-02-28 16:57:35 +00:00
|
|
|
struct wlr_pointer *pointer) {
|
2019-01-25 22:51:38 +00:00
|
|
|
struct libinput_event_gesture *gevent =
|
|
|
|
libinput_event_get_gesture_event(event);
|
2022-03-09 19:52:27 +00:00
|
|
|
struct wlr_pointer_swipe_update_event wlr_event = {
|
|
|
|
.pointer = pointer,
|
2019-01-25 22:51:38 +00:00
|
|
|
.time_msec =
|
|
|
|
usec_to_msec(libinput_event_gesture_get_time_usec(gevent)),
|
|
|
|
.fingers = libinput_event_gesture_get_finger_count(gevent),
|
|
|
|
.dx = libinput_event_gesture_get_dx(gevent),
|
|
|
|
.dy = libinput_event_gesture_get_dy(gevent),
|
|
|
|
};
|
2022-08-18 11:16:16 +00:00
|
|
|
wl_signal_emit_mutable(&pointer->events.swipe_update, &wlr_event);
|
2019-01-25 22:51:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void handle_pointer_swipe_end(struct libinput_event *event,
|
2022-02-28 16:57:35 +00:00
|
|
|
struct wlr_pointer *pointer) {
|
2019-01-25 22:51:38 +00:00
|
|
|
struct libinput_event_gesture *gevent =
|
|
|
|
libinput_event_get_gesture_event(event);
|
2022-03-09 19:52:27 +00:00
|
|
|
struct wlr_pointer_swipe_end_event wlr_event = {
|
|
|
|
.pointer = pointer,
|
2019-01-25 22:51:38 +00:00
|
|
|
.time_msec =
|
|
|
|
usec_to_msec(libinput_event_gesture_get_time_usec(gevent)),
|
|
|
|
.cancelled = libinput_event_gesture_get_cancelled(gevent),
|
|
|
|
};
|
2022-08-18 11:16:16 +00:00
|
|
|
wl_signal_emit_mutable(&pointer->events.swipe_end, &wlr_event);
|
2019-01-25 22:51:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void handle_pointer_pinch_begin(struct libinput_event *event,
|
2022-02-28 16:57:35 +00:00
|
|
|
struct wlr_pointer *pointer) {
|
2019-01-25 22:51:38 +00:00
|
|
|
struct libinput_event_gesture *gevent =
|
|
|
|
libinput_event_get_gesture_event(event);
|
2022-03-09 19:52:27 +00:00
|
|
|
struct wlr_pointer_pinch_begin_event wlr_event = {
|
|
|
|
.pointer = pointer,
|
2019-01-25 22:51:38 +00:00
|
|
|
.time_msec =
|
|
|
|
usec_to_msec(libinput_event_gesture_get_time_usec(gevent)),
|
|
|
|
.fingers = libinput_event_gesture_get_finger_count(gevent),
|
|
|
|
};
|
2022-08-18 11:16:16 +00:00
|
|
|
wl_signal_emit_mutable(&pointer->events.pinch_begin, &wlr_event);
|
2019-01-25 22:51:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void handle_pointer_pinch_update(struct libinput_event *event,
|
2022-02-28 16:57:35 +00:00
|
|
|
struct wlr_pointer *pointer) {
|
2019-01-25 22:51:38 +00:00
|
|
|
struct libinput_event_gesture *gevent =
|
|
|
|
libinput_event_get_gesture_event(event);
|
2022-03-09 19:52:27 +00:00
|
|
|
struct wlr_pointer_pinch_update_event wlr_event = {
|
|
|
|
.pointer = pointer,
|
2019-01-25 22:51:38 +00:00
|
|
|
.time_msec =
|
|
|
|
usec_to_msec(libinput_event_gesture_get_time_usec(gevent)),
|
|
|
|
.fingers = libinput_event_gesture_get_finger_count(gevent),
|
|
|
|
.dx = libinput_event_gesture_get_dx(gevent),
|
|
|
|
.dy = libinput_event_gesture_get_dy(gevent),
|
|
|
|
.scale = libinput_event_gesture_get_scale(gevent),
|
|
|
|
.rotation = libinput_event_gesture_get_angle_delta(gevent),
|
|
|
|
};
|
2022-08-18 11:16:16 +00:00
|
|
|
wl_signal_emit_mutable(&pointer->events.pinch_update, &wlr_event);
|
2019-01-25 22:51:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void handle_pointer_pinch_end(struct libinput_event *event,
|
2022-02-28 16:57:35 +00:00
|
|
|
struct wlr_pointer *pointer) {
|
2019-01-25 22:51:38 +00:00
|
|
|
struct libinput_event_gesture *gevent =
|
|
|
|
libinput_event_get_gesture_event(event);
|
2022-03-09 19:52:27 +00:00
|
|
|
struct wlr_pointer_pinch_end_event wlr_event = {
|
|
|
|
.pointer = pointer,
|
2019-01-25 22:51:38 +00:00
|
|
|
.time_msec =
|
|
|
|
usec_to_msec(libinput_event_gesture_get_time_usec(gevent)),
|
|
|
|
.cancelled = libinput_event_gesture_get_cancelled(gevent),
|
|
|
|
};
|
2022-08-18 11:16:16 +00:00
|
|
|
wl_signal_emit_mutable(&pointer->events.pinch_end, &wlr_event);
|
2019-01-25 22:51:38 +00:00
|
|
|
}
|
2021-07-12 17:50:44 +00:00
|
|
|
|
|
|
|
void handle_pointer_hold_begin(struct libinput_event *event,
|
2022-02-28 16:57:35 +00:00
|
|
|
struct wlr_pointer *pointer) {
|
2021-07-12 17:50:44 +00:00
|
|
|
struct libinput_event_gesture *gevent =
|
|
|
|
libinput_event_get_gesture_event(event);
|
2022-03-09 19:52:27 +00:00
|
|
|
struct wlr_pointer_hold_begin_event wlr_event = {
|
|
|
|
.pointer = pointer,
|
2021-07-12 17:50:44 +00:00
|
|
|
.time_msec =
|
|
|
|
usec_to_msec(libinput_event_gesture_get_time_usec(gevent)),
|
|
|
|
.fingers = libinput_event_gesture_get_finger_count(gevent),
|
|
|
|
};
|
2022-08-18 11:16:16 +00:00
|
|
|
wl_signal_emit_mutable(&pointer->events.hold_begin, &wlr_event);
|
2021-07-12 17:50:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void handle_pointer_hold_end(struct libinput_event *event,
|
2022-02-28 16:57:35 +00:00
|
|
|
struct wlr_pointer *pointer) {
|
2021-07-12 17:50:44 +00:00
|
|
|
struct libinput_event_gesture *gevent =
|
|
|
|
libinput_event_get_gesture_event(event);
|
2022-03-09 19:52:27 +00:00
|
|
|
struct wlr_pointer_hold_end_event wlr_event = {
|
|
|
|
.pointer = pointer,
|
2021-07-12 17:50:44 +00:00
|
|
|
.time_msec =
|
|
|
|
usec_to_msec(libinput_event_gesture_get_time_usec(gevent)),
|
|
|
|
.cancelled = libinput_event_gesture_get_cancelled(gevent),
|
|
|
|
};
|
2022-08-18 11:16:16 +00:00
|
|
|
wl_signal_emit_mutable(&pointer->events.hold_end, &wlr_event);
|
2021-07-12 17:50:44 +00:00
|
|
|
}
|