aboutsummaryrefslogtreecommitdiff
path: root/backend/libinput/touch.c
diff options
context:
space:
mode:
authorSimon Zeni <simon@bl4ckb0ne.ca>2022-02-23 14:06:02 -0500
committerKirill Primak <vyivel@eclair.cafe>2022-03-02 18:18:05 +0000
commit4f4dd9522378f4d62a47ee9b1472378c9960b2f2 (patch)
treecc69e9030642d3bef7f37cccee209b5a17806994 /backend/libinput/touch.c
parentd750c5ac676850d93ba7abf0a08476c4535ff1b6 (diff)
backend/libinput: rework touch interface
The wlr_libinput_input_device now owns its wlr_touch, instead of creating a new wlr_libinput_input_device for it.
Diffstat (limited to 'backend/libinput/touch.c')
-rw-r--r--backend/libinput/touch.c96
1 files changed, 35 insertions, 61 deletions
diff --git a/backend/libinput/touch.c b/backend/libinput/touch.c
index 2e22a97a..5b4dcbd6 100644
--- a/backend/libinput/touch.c
+++ b/backend/libinput/touch.c
@@ -1,113 +1,87 @@
#include <assert.h>
#include <libinput.h>
-#include <stdlib.h>
-#include <wlr/backend/session.h>
#include <wlr/interfaces/wlr_touch.h>
-#include <wlr/types/wlr_input_device.h>
-#include <wlr/util/log.h>
#include "backend/libinput.h"
#include "util/signal.h"
-const struct wlr_touch_impl libinput_touch_impl;
+static void touch_destroy(struct wlr_touch *touch) {
+ /* wlr_touch belongs to the wlr_libinput_input_device */
+}
+
+const struct wlr_touch_impl libinput_touch_impl = {
+ .destroy = touch_destroy,
+};
-struct wlr_touch *create_libinput_touch(
- struct libinput_device *libinput_dev) {
- assert(libinput_dev);
- struct wlr_touch *wlr_touch = calloc(1, sizeof(struct wlr_touch));
- if (!wlr_touch) {
- wlr_log(WLR_ERROR, "Unable to allocate wlr_touch");
- return NULL;
- }
- const char *name = libinput_device_get_name(libinput_dev);
+void init_device_touch(struct wlr_libinput_input_device *dev) {
+ const char *name = libinput_device_get_name(dev->handle);
+ struct wlr_touch *wlr_touch = &dev->touch;
wlr_touch_init(wlr_touch, &libinput_touch_impl, name);
- wlr_touch->base.vendor = libinput_device_get_id_vendor(libinput_dev);
- wlr_touch->base.product = libinput_device_get_id_product(libinput_dev);
- return wlr_touch;
+ wlr_touch->base.vendor = libinput_device_get_id_vendor(dev->handle);
+ wlr_touch->base.product = libinput_device_get_id_product(dev->handle);
+}
+
+struct wlr_libinput_input_device *device_from_touch(
+ struct wlr_touch *wlr_touch) {
+ assert(wlr_touch->impl == &libinput_touch_impl);
+
+ struct wlr_libinput_input_device *dev =
+ wl_container_of(wlr_touch, dev, touch);
+ return dev;
}
void handle_touch_down(struct libinput_event *event,
- struct libinput_device *libinput_dev) {
- struct wlr_input_device *wlr_dev =
- get_appropriate_device(WLR_INPUT_DEVICE_TOUCH, libinput_dev);
- if (!wlr_dev) {
- wlr_log(WLR_DEBUG, "Got a touch event for a device with no touch?");
- return;
- }
+ struct wlr_touch *touch) {
struct libinput_event_touch *tevent =
libinput_event_get_touch_event(event);
struct wlr_event_touch_down wlr_event = { 0 };
- wlr_event.device = wlr_dev;
+ wlr_event.device = &touch->base;
wlr_event.time_msec =
usec_to_msec(libinput_event_touch_get_time_usec(tevent));
wlr_event.touch_id = libinput_event_touch_get_seat_slot(tevent);
wlr_event.x = libinput_event_touch_get_x_transformed(tevent, 1);
wlr_event.y = libinput_event_touch_get_y_transformed(tevent, 1);
- wlr_signal_emit_safe(&wlr_dev->touch->events.down, &wlr_event);
+ wlr_signal_emit_safe(&touch->events.down, &wlr_event);
}
void handle_touch_up(struct libinput_event *event,
- struct libinput_device *libinput_dev) {
- struct wlr_input_device *wlr_dev =
- get_appropriate_device(WLR_INPUT_DEVICE_TOUCH, libinput_dev);
- if (!wlr_dev) {
- wlr_log(WLR_DEBUG, "Got a touch event for a device with no touch?");
- return;
- }
+ struct wlr_touch *touch) {
struct libinput_event_touch *tevent =
libinput_event_get_touch_event(event);
struct wlr_event_touch_up wlr_event = { 0 };
- wlr_event.device = wlr_dev;
+ wlr_event.device = &touch->base;
wlr_event.time_msec =
usec_to_msec(libinput_event_touch_get_time_usec(tevent));
wlr_event.touch_id = libinput_event_touch_get_seat_slot(tevent);
- wlr_signal_emit_safe(&wlr_dev->touch->events.up, &wlr_event);
+ wlr_signal_emit_safe(&touch->events.up, &wlr_event);
}
void handle_touch_motion(struct libinput_event *event,
- struct libinput_device *libinput_dev) {
- struct wlr_input_device *wlr_dev =
- get_appropriate_device(WLR_INPUT_DEVICE_TOUCH, libinput_dev);
- if (!wlr_dev) {
- wlr_log(WLR_DEBUG, "Got a touch event for a device with no touch?");
- return;
- }
+ struct wlr_touch *touch) {
struct libinput_event_touch *tevent =
libinput_event_get_touch_event(event);
struct wlr_event_touch_motion wlr_event = { 0 };
- wlr_event.device = wlr_dev;
+ wlr_event.device = &touch->base;
wlr_event.time_msec =
usec_to_msec(libinput_event_touch_get_time_usec(tevent));
wlr_event.touch_id = libinput_event_touch_get_seat_slot(tevent);
wlr_event.x = libinput_event_touch_get_x_transformed(tevent, 1);
wlr_event.y = libinput_event_touch_get_y_transformed(tevent, 1);
- wlr_signal_emit_safe(&wlr_dev->touch->events.motion, &wlr_event);
+ wlr_signal_emit_safe(&touch->events.motion, &wlr_event);
}
void handle_touch_cancel(struct libinput_event *event,
- struct libinput_device *libinput_dev) {
- struct wlr_input_device *wlr_dev =
- get_appropriate_device(WLR_INPUT_DEVICE_TOUCH, libinput_dev);
- if (!wlr_dev) {
- wlr_log(WLR_DEBUG, "Got a touch event for a device with no touch?");
- return;
- }
+ struct wlr_touch *touch) {
struct libinput_event_touch *tevent =
libinput_event_get_touch_event(event);
struct wlr_event_touch_cancel wlr_event = { 0 };
- wlr_event.device = wlr_dev;
+ wlr_event.device = &touch->base;
wlr_event.time_msec =
usec_to_msec(libinput_event_touch_get_time_usec(tevent));
wlr_event.touch_id = libinput_event_touch_get_seat_slot(tevent);
- wlr_signal_emit_safe(&wlr_dev->touch->events.cancel, &wlr_event);
+ wlr_signal_emit_safe(&touch->events.cancel, &wlr_event);
}
void handle_touch_frame(struct libinput_event *event,
- struct libinput_device *libinput_dev) {
- struct wlr_input_device *wlr_dev =
- get_appropriate_device(WLR_INPUT_DEVICE_TOUCH, libinput_dev);
- if (!wlr_dev) {
- wlr_log(WLR_DEBUG, "Got a touch event for a device with no touch?");
- return;
- }
- wlr_signal_emit_safe(&wlr_dev->touch->events.frame, NULL);
+ struct wlr_touch *touch) {
+ wlr_signal_emit_safe(&touch->events.frame, NULL);
}