1 /*
2 * Copyright © 2019 Red Hat, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 */
23
24 #pragma once
25
26 #include "config.h"
27
28 #include "util-time.h"
29 #include <linux/input.h>
30
31 static inline struct input_event
input_event_init(uint64_t time,unsigned int type,unsigned int code,int value)32 input_event_init(uint64_t time,
33 unsigned int type,
34 unsigned int code,
35 int value)
36 {
37 struct input_event ev;
38 struct timeval tval = us2tv(time);
39
40 ev.input_event_sec = tval.tv_sec;
41 ev.input_event_usec = tval.tv_usec;
42 ev.type = type;
43 ev.code = code;
44 ev.value = value;
45
46 return ev;
47 }
48
49 static inline uint64_t
input_event_time(const struct input_event * e)50 input_event_time(const struct input_event *e)
51 {
52 struct timeval tval;
53
54 tval.tv_sec = e->input_event_sec;
55 tval.tv_usec = e->input_event_usec;
56
57 return tv2us(&tval);
58 }
59
60
61 static inline void
input_event_set_time(struct input_event * e,uint64_t time)62 input_event_set_time(struct input_event *e,
63 uint64_t time)
64 {
65 struct timeval tval = us2tv(time);
66
67 e->input_event_sec = tval.tv_sec;
68 e->input_event_usec = tval.tv_usec;
69 }
70