aboutsummaryrefslogtreecommitdiff
path: root/backend/libinput/touch.c
blob: d79b2a97ad4f5cfef64d80845a02cf2d1482e587 (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
86
87
88
89
90
91
92
93
94
95
96
97
#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"

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(L_ERROR, "Unable to allocate wlr_touch");
		return NULL;
	}
	wlr_touch_init(wlr_touch, NULL);
	return wlr_touch;
}

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(L_DEBUG, "Got a touch event for a device with no touch?");
		return;
	}
	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.time_msec =
		usec_to_msec(libinput_event_touch_get_time_usec(tevent));
	wlr_event.touch_id = libinput_event_touch_get_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);
}

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(L_DEBUG, "Got a touch event for a device with no touch?");
		return;
	}
	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.time_msec =
		usec_to_msec(libinput_event_touch_get_time_usec(tevent));
	wlr_event.touch_id = libinput_event_touch_get_slot(tevent);
	wlr_signal_emit_safe(&wlr_dev->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(L_DEBUG, "Got a touch event for a device with no touch?");
		return;
	}
	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.time_msec =
		usec_to_msec(libinput_event_touch_get_time_usec(tevent));
	wlr_event.touch_id = libinput_event_touch_get_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);
}

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(L_DEBUG, "Got a touch event for a device with no touch?");
		return;
	}
	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.time_msec =
		usec_to_msec(libinput_event_touch_get_time_usec(tevent));
	wlr_event.touch_id = libinput_event_touch_get_slot(tevent);
	wlr_signal_emit_safe(&wlr_dev->touch->events.cancel, &wlr_event);
}