-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtouch-event.c
94 lines (81 loc) · 1.67 KB
/
touch-event.c
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
/*
* SPDX-License-Identifier: ISC
*
* Copyright (c) 2022 Codethink
*/
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include "msg/msg.h"
#include "msg/queue.h"
#include "msg/private.h"
#include "util/log.h"
#define PRINT_FMT_TOUCH_EVENT_START__ID_X_Y \
"{" \
"\"id\":%i," \
"\"method\":\"Input.dispatchTouchEvent\"," \
"\"params\":{" \
"\"type\":\"touchStart\"," \
"\"touchPoints\":[" \
"{\"x\":%i,\"y\":%i}" \
"]" \
"}" \
"}"
#define PRINT_FMT_TOUCH_EVENT_MOVE__ID_X_Y \
"{" \
"\"id\":%i," \
"\"method\":\"Input.dispatchTouchEvent\"," \
"\"params\":{" \
"\"type\":\"touchMove\"," \
"\"touchPoints\":[" \
"{\"x\":%i,\"y\":%i}" \
"]" \
"}" \
"}"
#define PRINT_FMT_TOUCH_EVENT_END__ID \
"{" \
"\"id\":%i," \
"\"method\":\"Input.dispatchTouchEvent\"," \
"\"params\":{" \
"\"type\":\"touchEnd\"," \
"\"touchPoints\":[]" \
"}" \
"}"
char *msg_str_touch_event(const struct msg *msg, int id)
{
struct msg_container *m;
switch (msg->type) {
case MSG_TYPE_TOUCH_EVENT_END:
if (!msg_create(&m,
PRINT_FMT_TOUCH_EVENT_END__ID,
id)) {
return NULL;
}
break;
case MSG_TYPE_TOUCH_EVENT_MOVE:
if (!msg_create(&m,
PRINT_FMT_TOUCH_EVENT_MOVE__ID_X_Y,
id,
msg->data.touch_event.x,
msg->data.touch_event.y)) {
return NULL;
}
break;
case MSG_TYPE_TOUCH_EVENT_START:
if (!msg_create(&m,
PRINT_FMT_TOUCH_EVENT_START__ID_X_Y,
id,
msg->data.touch_event.x,
msg->data.touch_event.y)) {
return NULL;
}
break;
default:
cdt_log(CDT_LOG_ERROR, "%s: Unhandled message type: %i",
__func__, msg->type);
return NULL;
}
m->type = msg->type;
m->id = id;
return m->str;
}