1From daecf59cc8b294265666482a4766aaa3148c308b Mon Sep 17 00:00:00 2001
2From: Khem Raj <raj.khem@gmail.com>
3Date: Sat, 30 Nov 2019 11:43:32 -0800
4Subject: [PATCH] Fix build on 32bit arches with 64bit time_t
5
6time element is deprecated on new input_event structure in kernel's
7input.h [1]
8
9[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit?id=152194fe9c3f
10
11[Retrieved from:
12https://github.com/LibVNC/x11vnc/commit/daecf59cc8b294265666482a4766aaa3148c308b]
13Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
14---
15 src/uinput.c | 25 +++++++++++++++++++++----
16 1 file changed, 21 insertions(+), 4 deletions(-)
17
18diff --git a/src/uinput.c b/src/uinput.c
19index 28fbad3..d71bcde 100644
20--- a/src/uinput.c
21+++ b/src/uinput.c
22@@ -54,6 +54,11 @@ so, delete this exception statement from your version.
23 #include <linux/input.h>
24 #include <linux/uinput.h>
25
26+#ifndef input_event_sec
27+#define input_event_sec time.tv_sec
28+#define input_event_usec time.tv_usec
29+#endif
30+
31 #if !defined(EV_SYN) || !defined(SYN_REPORT)
32 #undef UINPUT_OK
33 #endif
34@@ -710,6 +715,7 @@ void parse_uinput_str(char *in) {
35 static void ptr_move(int dx, int dy) {
36 #ifdef UINPUT_OK
37 	struct input_event ev;
38+	struct timeval tval;
39 	int d = direct_rel_fd < 0 ? fd : direct_rel_fd;
40
41 	if (injectable && strchr(injectable, 'M') == NULL) {
42@@ -720,7 +726,9 @@ static void ptr_move(int dx, int dy) {
43
44 	if (db) fprintf(stderr, "ptr_move(%d, %d) fd=%d\n", dx, dy, d);
45
46-	gettimeofday(&ev.time, NULL);
47+	gettimeofday(&tval, NULL);
48+	ev.input_event_sec = tval.tv_sec;
49+	ev.input_event_usec = tval.tv_usec;
50 	ev.type = EV_REL;
51 	ev.code = REL_Y;
52 	ev.value = dy;
53@@ -755,6 +763,7 @@ static void apply_tslib(int *x, int *y) {
54 static void ptr_abs(int x, int y, int p) {
55 #ifdef UINPUT_OK
56 	struct input_event ev;
57+	struct timeval tval;
58 	int x0, y0;
59 	int d = direct_abs_fd < 0 ? fd : direct_abs_fd;
60
61@@ -773,7 +782,9 @@ static void ptr_abs(int x, int y, int p) {
62
63 	if (db) fprintf(stderr, "ptr_abs(%d, %d => %d %d, p=%d) fd=%d\n", x0, y0, x, y, p, d);
64
65-	gettimeofday(&ev.time, NULL);
66+	gettimeofday(&tval, NULL);
67+	ev.input_event_sec = tval.tv_sec;
68+	ev.input_event_usec = tval.tv_usec;
69 	ev.type = EV_ABS;
70 	ev.code = ABS_Y;
71 	ev.value = y;
72@@ -950,6 +961,7 @@ if (0) {usleep(100*1000) ;}
73 static void button_click(int down, int btn) {
74 #ifdef UINPUT_OK
75 	struct input_event ev;
76+	struct timeval tval;
77 	int d = direct_btn_fd < 0 ? fd : direct_btn_fd;
78
79 	if (injectable && strchr(injectable, 'B') == NULL) {
80@@ -959,7 +971,9 @@ static void button_click(int down, int btn) {
81 	if (db) fprintf(stderr, "button_click: btn %d %s fd=%d\n", btn, down ? "down" : "up", d);
82
83 	memset(&ev, 0, sizeof(ev));
84-	gettimeofday(&ev.time, NULL);
85+	gettimeofday(&tval, NULL);
86+	ev.input_event_sec = tval.tv_sec;
87+	ev.input_event_usec = tval.tv_usec;
88 	ev.type = EV_KEY;
89 	ev.value = down;
90
91@@ -1230,6 +1244,7 @@ void uinput_pointer_command(int mask, int x, int y, rfbClientPtr client) {
92 void uinput_key_command(int down, int keysym, rfbClientPtr client) {
93 #ifdef UINPUT_OK
94 	struct input_event ev;
95+	struct timeval tval;
96 	int scancode;
97 	allowed_input_t input;
98 	int d = direct_key_fd < 0 ? fd : direct_key_fd;
99@@ -1253,7 +1268,9 @@ void uinput_key_command(int down, int keysym, rfbClientPtr client) {
100 	if (db) fprintf(stderr, "uinput_key_command: %d -> %d %s fd=%d\n", keysym, scancode, down ? "down" : "up", d);
101
102 	memset(&ev, 0, sizeof(ev));
103-	gettimeofday(&ev.time, NULL);
104+	gettimeofday(&tval, NULL);
105+	ev.input_event_sec = tval.tv_sec;
106+	ev.input_event_usec = tval.tv_usec;
107 	ev.type = EV_KEY;
108 	ev.code = (unsigned char) scancode;
109 	ev.value = down;
110