backend/libinput: rework pointer interface

The wlr_libinput_input_device now owns its wlr_pointer, instead of creating
a new wlr_libinput_input_device for it
This commit is contained in:
Simon Zeni 2022-02-28 11:57:35 -05:00 committed by Kirill Primak
parent 5eefda1ffe
commit d60cdad3ea
4 changed files with 104 additions and 169 deletions

View File

@ -243,6 +243,9 @@ struct libinput_device *wlr_libinput_get_device_handle(
case WLR_INPUT_DEVICE_KEYBOARD: case WLR_INPUT_DEVICE_KEYBOARD:
dev = device_from_keyboard(wlr_dev->keyboard); dev = device_from_keyboard(wlr_dev->keyboard);
break; break;
case WLR_INPUT_DEVICE_POINTER:
dev = device_from_pointer(wlr_dev->pointer);
break;
default: default:
dev = (struct wlr_libinput_input_device *)wlr_dev; dev = (struct wlr_libinput_input_device *)wlr_dev;
break; break;

View File

@ -40,6 +40,9 @@ void destroy_libinput_input_device(struct wlr_libinput_input_device *dev)
if (dev->keyboard.impl) { if (dev->keyboard.impl) {
wlr_keyboard_destroy(&dev->keyboard); wlr_keyboard_destroy(&dev->keyboard);
} }
if (dev->pointer.impl) {
wlr_pointer_destroy(&dev->pointer);
}
} }
libinput_device_unref(dev->handle); libinput_device_unref(dev->handle);
@ -127,6 +130,15 @@ static void handle_device_added(struct wlr_libinput_backend *backend,
dev_used = true; dev_used = true;
} }
if (libinput_device_has_capability(
libinput_dev, LIBINPUT_DEVICE_CAP_POINTER)) {
init_device_pointer(dev);
wlr_signal_emit_safe(&backend->backend.events.new_input,
&dev->pointer.base);
dev_used = true;
}
if (dev_used) { if (dev_used) {
wl_list_insert(&backend->devices, &dev->link); wl_list_insert(&backend->devices, &dev->link);
@ -143,20 +155,6 @@ static void handle_device_added(struct wlr_libinput_backend *backend,
} }
wl_list_init(wlr_devices); wl_list_init(wlr_devices);
if (libinput_device_has_capability(
libinput_dev, LIBINPUT_DEVICE_CAP_POINTER)) {
struct wlr_input_device *wlr_dev = allocate_device(backend,
libinput_dev, wlr_devices, WLR_INPUT_DEVICE_POINTER);
if (!wlr_dev) {
goto fail;
}
wlr_dev->pointer = create_libinput_pointer(libinput_dev);
if (!wlr_dev->pointer) {
free(wlr_dev);
goto fail;
}
wlr_signal_emit_safe(&backend->backend.events.new_input, wlr_dev);
}
if (libinput_device_has_capability( if (libinput_device_has_capability(
libinput_dev, LIBINPUT_DEVICE_CAP_TOUCH)) { libinput_dev, LIBINPUT_DEVICE_CAP_TOUCH)) {
struct wlr_input_device *wlr_dev = allocate_device(backend, struct wlr_input_device *wlr_dev = allocate_device(backend,
@ -297,16 +295,16 @@ void handle_libinput_event(struct wlr_libinput_backend *backend,
handle_keyboard_key(event, &dev->keyboard); handle_keyboard_key(event, &dev->keyboard);
break; break;
case LIBINPUT_EVENT_POINTER_MOTION: case LIBINPUT_EVENT_POINTER_MOTION:
handle_pointer_motion(event, libinput_dev); handle_pointer_motion(event, &dev->pointer);
break; break;
case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE: case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE:
handle_pointer_motion_abs(event, libinput_dev); handle_pointer_motion_abs(event, &dev->pointer);
break; break;
case LIBINPUT_EVENT_POINTER_BUTTON: case LIBINPUT_EVENT_POINTER_BUTTON:
handle_pointer_button(event, libinput_dev); handle_pointer_button(event, &dev->pointer);
break; break;
case LIBINPUT_EVENT_POINTER_AXIS: case LIBINPUT_EVENT_POINTER_AXIS:
handle_pointer_axis(event, libinput_dev); handle_pointer_axis(event, &dev->pointer);
break; break;
case LIBINPUT_EVENT_TOUCH_DOWN: case LIBINPUT_EVENT_TOUCH_DOWN:
handle_touch_down(event, libinput_dev); handle_touch_down(event, libinput_dev);
@ -348,29 +346,29 @@ void handle_libinput_event(struct wlr_libinput_backend *backend,
handle_switch_toggle(event, libinput_dev); handle_switch_toggle(event, libinput_dev);
break; break;
case LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN: case LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN:
handle_pointer_swipe_begin(event, libinput_dev); handle_pointer_swipe_begin(event, &dev->pointer);
break; break;
case LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE: case LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE:
handle_pointer_swipe_update(event, libinput_dev); handle_pointer_swipe_update(event, &dev->pointer);
break; break;
case LIBINPUT_EVENT_GESTURE_SWIPE_END: case LIBINPUT_EVENT_GESTURE_SWIPE_END:
handle_pointer_swipe_end(event, libinput_dev); handle_pointer_swipe_end(event, &dev->pointer);
break; break;
case LIBINPUT_EVENT_GESTURE_PINCH_BEGIN: case LIBINPUT_EVENT_GESTURE_PINCH_BEGIN:
handle_pointer_pinch_begin(event, libinput_dev); handle_pointer_pinch_begin(event, &dev->pointer);
break; break;
case LIBINPUT_EVENT_GESTURE_PINCH_UPDATE: case LIBINPUT_EVENT_GESTURE_PINCH_UPDATE:
handle_pointer_pinch_update(event, libinput_dev); handle_pointer_pinch_update(event, &dev->pointer);
break; break;
case LIBINPUT_EVENT_GESTURE_PINCH_END: case LIBINPUT_EVENT_GESTURE_PINCH_END:
handle_pointer_pinch_end(event, libinput_dev); handle_pointer_pinch_end(event, &dev->pointer);
break; break;
#if LIBINPUT_HAS_HOLD_GESTURES #if LIBINPUT_HAS_HOLD_GESTURES
case LIBINPUT_EVENT_GESTURE_HOLD_BEGIN: case LIBINPUT_EVENT_GESTURE_HOLD_BEGIN:
handle_pointer_hold_begin(event, libinput_dev); handle_pointer_hold_begin(event, &dev->pointer);
break; break;
case LIBINPUT_EVENT_GESTURE_HOLD_END: case LIBINPUT_EVENT_GESTURE_HOLD_END:
handle_pointer_hold_end(event, libinput_dev); handle_pointer_hold_end(event, &dev->pointer);
break; break;
#endif #endif
default: default:

View File

@ -1,83 +1,70 @@
#include <assert.h> #include <assert.h>
#include <libinput.h> #include <libinput.h>
#include <stdlib.h> #include <wlr/interfaces/wlr_pointer.h>
#include <wlr/backend/session.h>
#include <wlr/types/wlr_input_device.h>
#include <wlr/util/log.h>
#include "backend/libinput.h" #include "backend/libinput.h"
#include "util/signal.h" #include "util/signal.h"
const struct wlr_pointer_impl libinput_pointer_impl = {0}; static void pointer_destroy(struct wlr_pointer *pointer) {
/* wlr_pointer belongs to the wlr_libinput_input_device */
}
struct wlr_pointer *create_libinput_pointer( const struct wlr_pointer_impl libinput_pointer_impl = {
struct libinput_device *libinput_dev) { .destroy = pointer_destroy,
assert(libinput_dev); };
struct wlr_pointer *wlr_pointer = calloc(1, sizeof(struct wlr_pointer));
if (!wlr_pointer) { void init_device_pointer(struct wlr_libinput_input_device *dev) {
wlr_log(WLR_ERROR, "Unable to allocate wlr_pointer"); const char *name = libinput_device_get_name(dev->handle);
return NULL; struct wlr_pointer *wlr_pointer = &dev->pointer;
}
const char *name = libinput_device_get_name(libinput_dev);
wlr_pointer_init(wlr_pointer, &libinput_pointer_impl, name); wlr_pointer_init(wlr_pointer, &libinput_pointer_impl, name);
wlr_pointer->base.vendor = libinput_device_get_id_vendor(libinput_dev); wlr_pointer->base.vendor = libinput_device_get_id_vendor(dev->handle);
wlr_pointer->base.product = libinput_device_get_id_product(libinput_dev); wlr_pointer->base.product = libinput_device_get_id_product(dev->handle);
return wlr_pointer; }
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;
} }
void handle_pointer_motion(struct libinput_event *event, void handle_pointer_motion(struct libinput_event *event,
struct libinput_device *libinput_dev) { struct wlr_pointer *pointer) {
struct wlr_input_device *wlr_dev =
get_appropriate_device(WLR_INPUT_DEVICE_POINTER, libinput_dev);
if (!wlr_dev) {
wlr_log(WLR_DEBUG, "Got a pointer event for a device with no pointers?");
return;
}
struct libinput_event_pointer *pevent = struct libinput_event_pointer *pevent =
libinput_event_get_pointer_event(event); libinput_event_get_pointer_event(event);
struct wlr_event_pointer_motion wlr_event = { 0 }; struct wlr_event_pointer_motion wlr_event = { 0 };
wlr_event.device = wlr_dev; wlr_event.device = &pointer->base;
wlr_event.time_msec = wlr_event.time_msec =
usec_to_msec(libinput_event_pointer_get_time_usec(pevent)); usec_to_msec(libinput_event_pointer_get_time_usec(pevent));
wlr_event.delta_x = libinput_event_pointer_get_dx(pevent); wlr_event.delta_x = libinput_event_pointer_get_dx(pevent);
wlr_event.delta_y = libinput_event_pointer_get_dy(pevent); wlr_event.delta_y = libinput_event_pointer_get_dy(pevent);
wlr_event.unaccel_dx = libinput_event_pointer_get_dx_unaccelerated(pevent); wlr_event.unaccel_dx = libinput_event_pointer_get_dx_unaccelerated(pevent);
wlr_event.unaccel_dy = libinput_event_pointer_get_dy_unaccelerated(pevent); wlr_event.unaccel_dy = libinput_event_pointer_get_dy_unaccelerated(pevent);
wlr_signal_emit_safe(&wlr_dev->pointer->events.motion, &wlr_event); wlr_signal_emit_safe(&pointer->events.motion, &wlr_event);
wlr_signal_emit_safe(&wlr_dev->pointer->events.frame, wlr_dev->pointer); wlr_signal_emit_safe(&pointer->events.frame, pointer);
} }
void handle_pointer_motion_abs(struct libinput_event *event, void handle_pointer_motion_abs(struct libinput_event *event,
struct libinput_device *libinput_dev) { struct wlr_pointer *pointer) {
struct wlr_input_device *wlr_dev =
get_appropriate_device(WLR_INPUT_DEVICE_POINTER, libinput_dev);
if (!wlr_dev) {
wlr_log(WLR_DEBUG, "Got a pointer event for a device with no pointers?");
return;
}
struct libinput_event_pointer *pevent = struct libinput_event_pointer *pevent =
libinput_event_get_pointer_event(event); libinput_event_get_pointer_event(event);
struct wlr_event_pointer_motion_absolute wlr_event = { 0 }; struct wlr_event_pointer_motion_absolute wlr_event = { 0 };
wlr_event.device = wlr_dev; wlr_event.device = &pointer->base;
wlr_event.time_msec = wlr_event.time_msec =
usec_to_msec(libinput_event_pointer_get_time_usec(pevent)); usec_to_msec(libinput_event_pointer_get_time_usec(pevent));
wlr_event.x = libinput_event_pointer_get_absolute_x_transformed(pevent, 1); wlr_event.x = libinput_event_pointer_get_absolute_x_transformed(pevent, 1);
wlr_event.y = libinput_event_pointer_get_absolute_y_transformed(pevent, 1); wlr_event.y = libinput_event_pointer_get_absolute_y_transformed(pevent, 1);
wlr_signal_emit_safe(&wlr_dev->pointer->events.motion_absolute, &wlr_event); wlr_signal_emit_safe(&pointer->events.motion_absolute, &wlr_event);
wlr_signal_emit_safe(&wlr_dev->pointer->events.frame, wlr_dev->pointer); wlr_signal_emit_safe(&pointer->events.frame, pointer);
} }
void handle_pointer_button(struct libinput_event *event, void handle_pointer_button(struct libinput_event *event,
struct libinput_device *libinput_dev) { struct wlr_pointer *pointer) {
struct wlr_input_device *wlr_dev =
get_appropriate_device(WLR_INPUT_DEVICE_POINTER, libinput_dev);
if (!wlr_dev) {
wlr_log(WLR_DEBUG, "Got a pointer event for a device with no pointers?");
return;
}
struct libinput_event_pointer *pevent = struct libinput_event_pointer *pevent =
libinput_event_get_pointer_event(event); libinput_event_get_pointer_event(event);
struct wlr_event_pointer_button wlr_event = { 0 }; struct wlr_event_pointer_button wlr_event = { 0 };
wlr_event.device = wlr_dev; wlr_event.device = &pointer->base;
wlr_event.time_msec = wlr_event.time_msec =
usec_to_msec(libinput_event_pointer_get_time_usec(pevent)); usec_to_msec(libinput_event_pointer_get_time_usec(pevent));
wlr_event.button = libinput_event_pointer_get_button(pevent); wlr_event.button = libinput_event_pointer_get_button(pevent);
@ -89,22 +76,16 @@ void handle_pointer_button(struct libinput_event *event,
wlr_event.state = WLR_BUTTON_RELEASED; wlr_event.state = WLR_BUTTON_RELEASED;
break; break;
} }
wlr_signal_emit_safe(&wlr_dev->pointer->events.button, &wlr_event); wlr_signal_emit_safe(&pointer->events.button, &wlr_event);
wlr_signal_emit_safe(&wlr_dev->pointer->events.frame, wlr_dev->pointer); wlr_signal_emit_safe(&pointer->events.frame, pointer);
} }
void handle_pointer_axis(struct libinput_event *event, void handle_pointer_axis(struct libinput_event *event,
struct libinput_device *libinput_dev) { struct wlr_pointer *pointer) {
struct wlr_input_device *wlr_dev =
get_appropriate_device(WLR_INPUT_DEVICE_POINTER, libinput_dev);
if (!wlr_dev) {
wlr_log(WLR_DEBUG, "Got a pointer event for a device with no pointers?");
return;
}
struct libinput_event_pointer *pevent = struct libinput_event_pointer *pevent =
libinput_event_get_pointer_event(event); libinput_event_get_pointer_event(event);
struct wlr_event_pointer_axis wlr_event = { 0 }; struct wlr_event_pointer_axis wlr_event = { 0 };
wlr_event.device = wlr_dev; wlr_event.device = &pointer->base;
wlr_event.time_msec = wlr_event.time_msec =
usec_to_msec(libinput_event_pointer_get_time_usec(pevent)); usec_to_msec(libinput_event_pointer_get_time_usec(pevent));
switch (libinput_event_pointer_get_axis_source(pevent)) { switch (libinput_event_pointer_get_axis_source(pevent)) {
@ -139,102 +120,72 @@ void handle_pointer_axis(struct libinput_event *event,
libinput_event_pointer_get_axis_value(pevent, axes[i]); libinput_event_pointer_get_axis_value(pevent, axes[i]);
wlr_event.delta_discrete = wlr_event.delta_discrete =
libinput_event_pointer_get_axis_value_discrete(pevent, axes[i]); libinput_event_pointer_get_axis_value_discrete(pevent, axes[i]);
wlr_signal_emit_safe(&wlr_dev->pointer->events.axis, &wlr_event); wlr_signal_emit_safe(&pointer->events.axis, &wlr_event);
} }
} }
wlr_signal_emit_safe(&wlr_dev->pointer->events.frame, wlr_dev->pointer); wlr_signal_emit_safe(&pointer->events.frame, pointer);
} }
void handle_pointer_swipe_begin(struct libinput_event *event, void handle_pointer_swipe_begin(struct libinput_event *event,
struct libinput_device *libinput_dev) { struct wlr_pointer *pointer) {
struct wlr_input_device *wlr_dev =
get_appropriate_device(WLR_INPUT_DEVICE_POINTER, libinput_dev);
if (!wlr_dev) {
wlr_log(WLR_DEBUG, "Got a pointer gesture event for a device with no pointers?");
return;
}
struct libinput_event_gesture *gevent = struct libinput_event_gesture *gevent =
libinput_event_get_gesture_event(event); libinput_event_get_gesture_event(event);
struct wlr_event_pointer_swipe_begin wlr_event = { struct wlr_event_pointer_swipe_begin wlr_event = {
.device = wlr_dev, .device = &pointer->base,
.time_msec = .time_msec =
usec_to_msec(libinput_event_gesture_get_time_usec(gevent)), usec_to_msec(libinput_event_gesture_get_time_usec(gevent)),
.fingers = libinput_event_gesture_get_finger_count(gevent), .fingers = libinput_event_gesture_get_finger_count(gevent),
}; };
wlr_signal_emit_safe(&wlr_dev->pointer->events.swipe_begin, &wlr_event); wlr_signal_emit_safe(&pointer->events.swipe_begin, &wlr_event);
} }
void handle_pointer_swipe_update(struct libinput_event *event, void handle_pointer_swipe_update(struct libinput_event *event,
struct libinput_device *libinput_dev) { struct wlr_pointer *pointer) {
struct wlr_input_device *wlr_dev =
get_appropriate_device(WLR_INPUT_DEVICE_POINTER, libinput_dev);
if (!wlr_dev) {
wlr_log(WLR_DEBUG, "Got a pointer gesture event for a device with no pointers?");
return;
}
struct libinput_event_gesture *gevent = struct libinput_event_gesture *gevent =
libinput_event_get_gesture_event(event); libinput_event_get_gesture_event(event);
struct wlr_event_pointer_swipe_update wlr_event = { struct wlr_event_pointer_swipe_update wlr_event = {
.device = wlr_dev, .device = &pointer->base,
.time_msec = .time_msec =
usec_to_msec(libinput_event_gesture_get_time_usec(gevent)), usec_to_msec(libinput_event_gesture_get_time_usec(gevent)),
.fingers = libinput_event_gesture_get_finger_count(gevent), .fingers = libinput_event_gesture_get_finger_count(gevent),
.dx = libinput_event_gesture_get_dx(gevent), .dx = libinput_event_gesture_get_dx(gevent),
.dy = libinput_event_gesture_get_dy(gevent), .dy = libinput_event_gesture_get_dy(gevent),
}; };
wlr_signal_emit_safe(&wlr_dev->pointer->events.swipe_update, &wlr_event); wlr_signal_emit_safe(&pointer->events.swipe_update, &wlr_event);
} }
void handle_pointer_swipe_end(struct libinput_event *event, void handle_pointer_swipe_end(struct libinput_event *event,
struct libinput_device *libinput_dev) { struct wlr_pointer *pointer) {
struct wlr_input_device *wlr_dev =
get_appropriate_device(WLR_INPUT_DEVICE_POINTER, libinput_dev);
if (!wlr_dev) {
wlr_log(WLR_DEBUG, "Got a pointer gesture event for a device with no pointers?");
return;
}
struct libinput_event_gesture *gevent = struct libinput_event_gesture *gevent =
libinput_event_get_gesture_event(event); libinput_event_get_gesture_event(event);
struct wlr_event_pointer_swipe_end wlr_event = { struct wlr_event_pointer_swipe_end wlr_event = {
.device = wlr_dev, .device = &pointer->base,
.time_msec = .time_msec =
usec_to_msec(libinput_event_gesture_get_time_usec(gevent)), usec_to_msec(libinput_event_gesture_get_time_usec(gevent)),
.cancelled = libinput_event_gesture_get_cancelled(gevent), .cancelled = libinput_event_gesture_get_cancelled(gevent),
}; };
wlr_signal_emit_safe(&wlr_dev->pointer->events.swipe_end, &wlr_event); wlr_signal_emit_safe(&pointer->events.swipe_end, &wlr_event);
} }
void handle_pointer_pinch_begin(struct libinput_event *event, void handle_pointer_pinch_begin(struct libinput_event *event,
struct libinput_device *libinput_dev) { struct wlr_pointer *pointer) {
struct wlr_input_device *wlr_dev =
get_appropriate_device(WLR_INPUT_DEVICE_POINTER, libinput_dev);
if (!wlr_dev) {
wlr_log(WLR_DEBUG, "Got a pointer gesture event for a device with no pointers?");
return;
}
struct libinput_event_gesture *gevent = struct libinput_event_gesture *gevent =
libinput_event_get_gesture_event(event); libinput_event_get_gesture_event(event);
struct wlr_event_pointer_pinch_begin wlr_event = { struct wlr_event_pointer_pinch_begin wlr_event = {
.device = wlr_dev, .device = &pointer->base,
.time_msec = .time_msec =
usec_to_msec(libinput_event_gesture_get_time_usec(gevent)), usec_to_msec(libinput_event_gesture_get_time_usec(gevent)),
.fingers = libinput_event_gesture_get_finger_count(gevent), .fingers = libinput_event_gesture_get_finger_count(gevent),
}; };
wlr_signal_emit_safe(&wlr_dev->pointer->events.pinch_begin, &wlr_event); wlr_signal_emit_safe(&pointer->events.pinch_begin, &wlr_event);
} }
void handle_pointer_pinch_update(struct libinput_event *event, void handle_pointer_pinch_update(struct libinput_event *event,
struct libinput_device *libinput_dev) { struct wlr_pointer *pointer) {
struct wlr_input_device *wlr_dev =
get_appropriate_device(WLR_INPUT_DEVICE_POINTER, libinput_dev);
if (!wlr_dev) {
wlr_log(WLR_DEBUG, "Got a pointer gesture event for a device with no pointers?");
return;
}
struct libinput_event_gesture *gevent = struct libinput_event_gesture *gevent =
libinput_event_get_gesture_event(event); libinput_event_get_gesture_event(event);
struct wlr_event_pointer_pinch_update wlr_event = { struct wlr_event_pointer_pinch_update wlr_event = {
.device = wlr_dev, .device = &pointer->base,
.time_msec = .time_msec =
usec_to_msec(libinput_event_gesture_get_time_usec(gevent)), usec_to_msec(libinput_event_gesture_get_time_usec(gevent)),
.fingers = libinput_event_gesture_get_finger_count(gevent), .fingers = libinput_event_gesture_get_finger_count(gevent),
@ -243,62 +194,44 @@ void handle_pointer_pinch_update(struct libinput_event *event,
.scale = libinput_event_gesture_get_scale(gevent), .scale = libinput_event_gesture_get_scale(gevent),
.rotation = libinput_event_gesture_get_angle_delta(gevent), .rotation = libinput_event_gesture_get_angle_delta(gevent),
}; };
wlr_signal_emit_safe(&wlr_dev->pointer->events.pinch_update, &wlr_event); wlr_signal_emit_safe(&pointer->events.pinch_update, &wlr_event);
} }
void handle_pointer_pinch_end(struct libinput_event *event, void handle_pointer_pinch_end(struct libinput_event *event,
struct libinput_device *libinput_dev) { struct wlr_pointer *pointer) {
struct wlr_input_device *wlr_dev =
get_appropriate_device(WLR_INPUT_DEVICE_POINTER, libinput_dev);
if (!wlr_dev) {
wlr_log(WLR_DEBUG, "Got a pointer gesture event for a device with no pointers?");
return;
}
struct libinput_event_gesture *gevent = struct libinput_event_gesture *gevent =
libinput_event_get_gesture_event(event); libinput_event_get_gesture_event(event);
struct wlr_event_pointer_pinch_end wlr_event = { struct wlr_event_pointer_pinch_end wlr_event = {
.device = wlr_dev, .device = &pointer->base,
.time_msec = .time_msec =
usec_to_msec(libinput_event_gesture_get_time_usec(gevent)), usec_to_msec(libinput_event_gesture_get_time_usec(gevent)),
.cancelled = libinput_event_gesture_get_cancelled(gevent), .cancelled = libinput_event_gesture_get_cancelled(gevent),
}; };
wlr_signal_emit_safe(&wlr_dev->pointer->events.pinch_end, &wlr_event); wlr_signal_emit_safe(&pointer->events.pinch_end, &wlr_event);
} }
void handle_pointer_hold_begin(struct libinput_event *event, void handle_pointer_hold_begin(struct libinput_event *event,
struct libinput_device *libinput_dev) { struct wlr_pointer *pointer) {
struct wlr_input_device *wlr_dev =
get_appropriate_device(WLR_INPUT_DEVICE_POINTER, libinput_dev);
if (!wlr_dev) {
wlr_log(WLR_DEBUG, "Got a pointer gesture event for a device with no pointers?");
return;
}
struct libinput_event_gesture *gevent = struct libinput_event_gesture *gevent =
libinput_event_get_gesture_event(event); libinput_event_get_gesture_event(event);
struct wlr_event_pointer_hold_begin wlr_event = { struct wlr_event_pointer_hold_begin wlr_event = {
.device = wlr_dev, .device = &pointer->base,
.time_msec = .time_msec =
usec_to_msec(libinput_event_gesture_get_time_usec(gevent)), usec_to_msec(libinput_event_gesture_get_time_usec(gevent)),
.fingers = libinput_event_gesture_get_finger_count(gevent), .fingers = libinput_event_gesture_get_finger_count(gevent),
}; };
wlr_signal_emit_safe(&wlr_dev->pointer->events.hold_begin, &wlr_event); wlr_signal_emit_safe(&pointer->events.hold_begin, &wlr_event);
} }
void handle_pointer_hold_end(struct libinput_event *event, void handle_pointer_hold_end(struct libinput_event *event,
struct libinput_device *libinput_dev) { struct wlr_pointer *pointer) {
struct wlr_input_device *wlr_dev =
get_appropriate_device(WLR_INPUT_DEVICE_POINTER, libinput_dev);
if (!wlr_dev) {
wlr_log(WLR_DEBUG, "Got a pointer gesture event for a device with no pointers?");
return;
}
struct libinput_event_gesture *gevent = struct libinput_event_gesture *gevent =
libinput_event_get_gesture_event(event); libinput_event_get_gesture_event(event);
struct wlr_event_pointer_hold_end wlr_event = { struct wlr_event_pointer_hold_end wlr_event = {
.device = wlr_dev, .device = &pointer->base,
.time_msec = .time_msec =
usec_to_msec(libinput_event_gesture_get_time_usec(gevent)), usec_to_msec(libinput_event_gesture_get_time_usec(gevent)),
.cancelled = libinput_event_gesture_get_cancelled(gevent), .cancelled = libinput_event_gesture_get_cancelled(gevent),
}; };
wlr_signal_emit_safe(&wlr_dev->pointer->events.hold_end, &wlr_event); wlr_signal_emit_safe(&pointer->events.hold_end, &wlr_event);
} }

View File

@ -35,6 +35,7 @@ struct wlr_libinput_input_device {
struct libinput_device *handle; struct libinput_device *handle;
struct wlr_keyboard keyboard; struct wlr_keyboard keyboard;
struct wlr_pointer pointer;
struct wl_list link; struct wl_list link;
}; };
@ -61,32 +62,32 @@ void init_device_keyboard(struct wlr_libinput_input_device *dev);
struct wlr_libinput_input_device *device_from_keyboard(struct wlr_keyboard *kb); struct wlr_libinput_input_device *device_from_keyboard(struct wlr_keyboard *kb);
void handle_keyboard_key(struct libinput_event *event, struct wlr_keyboard *kb); void handle_keyboard_key(struct libinput_event *event, struct wlr_keyboard *kb);
struct wlr_pointer *create_libinput_pointer( void init_device_pointer(struct wlr_libinput_input_device *dev);
struct libinput_device *device); struct wlr_libinput_input_device *device_from_pointer(struct wlr_pointer *kb);
void handle_pointer_motion(struct libinput_event *event, void handle_pointer_motion(struct libinput_event *event,
struct libinput_device *device); struct wlr_pointer *pointer);
void handle_pointer_motion_abs(struct libinput_event *event, void handle_pointer_motion_abs(struct libinput_event *event,
struct libinput_device *device); struct wlr_pointer *pointer);
void handle_pointer_button(struct libinput_event *event, void handle_pointer_button(struct libinput_event *event,
struct libinput_device *device); struct wlr_pointer *pointer);
void handle_pointer_axis(struct libinput_event *event, void handle_pointer_axis(struct libinput_event *event,
struct libinput_device *device); struct wlr_pointer *pointer);
void handle_pointer_swipe_begin(struct libinput_event *event, void handle_pointer_swipe_begin(struct libinput_event *event,
struct libinput_device *device); struct wlr_pointer *pointer);
void handle_pointer_swipe_update(struct libinput_event *event, void handle_pointer_swipe_update(struct libinput_event *event,
struct libinput_device *device); struct wlr_pointer *pointer);
void handle_pointer_swipe_end(struct libinput_event *event, void handle_pointer_swipe_end(struct libinput_event *event,
struct libinput_device *device); struct wlr_pointer *pointer);
void handle_pointer_pinch_begin(struct libinput_event *event, void handle_pointer_pinch_begin(struct libinput_event *event,
struct libinput_device *device); struct wlr_pointer *pointer);
void handle_pointer_pinch_update(struct libinput_event *event, void handle_pointer_pinch_update(struct libinput_event *event,
struct libinput_device *device); struct wlr_pointer *pointer);
void handle_pointer_pinch_end(struct libinput_event *event, void handle_pointer_pinch_end(struct libinput_event *event,
struct libinput_device *device); struct wlr_pointer *pointer);
void handle_pointer_hold_begin(struct libinput_event *event, void handle_pointer_hold_begin(struct libinput_event *event,
struct libinput_device *device); struct wlr_pointer *pointer);
void handle_pointer_hold_end(struct libinput_event *event, void handle_pointer_hold_end(struct libinput_event *event,
struct libinput_device *device); struct wlr_pointer *pointer);
struct wlr_switch *create_libinput_switch( struct wlr_switch *create_libinput_switch(
struct libinput_device *device); struct libinput_device *device);