aboutsummaryrefslogtreecommitdiff
path: root/backend/libinput/touch.c
blob: 3316754ef4e4af42d0381776fd164e1dd9db2f49 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <assert.h>
#include <libinput.h>
#include <wlr/interfaces/wlr_touch.h>
#include "backend/libinput.h"

const struct wlr_touch_impl libinput_touch_impl = {
	.name = "libinput-touch",
};

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(dev->handle);
	wlr_touch->base.product = libinput_device_get_id_product(dev->handle);

	libinput_device_get_size(dev->handle, &wlr_touch->width_mm,
		&wlr_touch->height_mm);
}

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 wlr_touch *touch) {
	struct libinput_event_touch *tevent =
		libinput_event_get_touch_event(event);
	struct wlr_touch_down_event wlr_event = { 0 };
	wlr_event.touch = touch;
	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);
	wl_signal_emit_mutable(&touch->events.down, &wlr_event);
}

void handle_touch_up(struct libinput_event *event,
		struct wlr_touch *touch) {
	struct libinput_event_touch *tevent =
		libinput_event_get_touch_event(event);
	struct wlr_touch_up_event wlr_event = { 0 };
	wlr_event.touch = touch;
	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);
	wl_signal_emit_mutable(&touch->events.up, &wlr_event);
}

void handle_touch_motion(struct libinput_event *event,
		struct wlr_touch *touch) {
	struct libinput_event_touch *tevent =
		libinput_event_get_touch_event(event);
	struct wlr_touch_motion_event wlr_event = { 0 };
	wlr_event.touch = touch;
	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);
	wl_signal_emit_mutable(&touch->events.motion, &wlr_event);
}

void handle_touch_cancel(struct libinput_event *event,
		struct wlr_touch *touch) {
	struct libinput_event_touch *tevent =
		libinput_event_get_touch_event(event);
	struct wlr_touch_cancel_event wlr_event = { 0 };
	wlr_event.touch = touch;
	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);
	wl_signal_emit_mutable(&touch->events.cancel, &wlr_event);
}

void handle_touch_frame(struct libinput_event *event,
		struct wlr_touch *touch) {
	wl_signal_emit_mutable(&touch->events.frame, NULL);
}