summaryrefslogtreecommitdiff
path: root/packages/tslib/tslib-1.0/tslib-input_raw-grab_events.patch
blob: 4bd0a05531155b780dc37a564ec1e8ed02e1b419 (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
This patch adds support for "EVIOCGRAB" on the input device, which
tells the kernel _not_ to deliver events of the touchscreen to
/dev/input/mice.  

This is probably what most people want, since unprocessed raw touchscreen
events should not be converted to emulated PS/2 mouse movements.

Signed-off-by: Harald Welte <laforge@openmoko.org>

Index: a/plugins/input-raw.c
===================================================================
--- a/plugins/input-raw.c	(revision 49)
+++ b/plugins/input-raw.c	(working copy)
@@ -18,6 +18,7 @@
 
 #include <errno.h>
 #include <stdio.h>
+#include <limits.h>
 
 #include <stdlib.h>
 #ifdef HAVE_UNISTD_H
@@ -33,6 +34,9 @@
 
 #include "tslib-private.h"
 
+#define GRAB_EVENTS_WANTED	1
+#define GRAB_EVENTS_ACTIVE	2
+
 struct tslib_input {
 	struct tslib_module_info module;
 
@@ -42,6 +46,7 @@
 
 	int	sane_fd;
 	int	using_syn;
+	int	grab_events;
 };
 
 static int check_fd(struct tslib_input *i)
@@ -64,6 +69,14 @@
 
 	if (bit & (1 << EV_SYN))
 		i->using_syn = 1;
+	
+	if (i->grab_events == GRAB_EVENTS_WANTED) {
+		if (ioctl(ts->fd, EVIOCGRAB, (void *)1)) {
+			fprintf(stderr, "Unable to grab selected input device\n");
+			return -1;
+		}
+		i->grab_events = GRAB_EVENTS_ACTIVE;
+	}
 
 	return 0;
 }
@@ -222,6 +235,15 @@
 
 static int ts_input_fini(struct tslib_module_info *inf)
 {
+	struct tslib_input *i = (struct tslib_input *)inf;
+	struct tsdev *ts = inf->dev;
+
+	if (i->grab_events == GRAB_EVENTS_ACTIVE) {
+		if (ioctl(ts->fd, EVIOCGRAB, (void *)0)) {
+			fprintf(stderr, "Unable to un-grab selected input device\n");
+		}
+	}
+
 	free(inf);
 	return 0;
 }
@@ -231,6 +253,36 @@
 	.fini	= ts_input_fini,
 };
 
+static int parse_raw_grab(struct tslib_module_info *inf, char *str, void *data)
+{
+	struct tslib_input *i = (struct tslib_input *)inf;
+	unsigned long v;
+	int err = errno;
+
+	v = strtoul(str, NULL, 0);
+
+	if (v == ULONG_MAX && errno == ERANGE)
+		return -1;
+	
+	errno = err;
+	switch ((int)data) {
+	case 1:
+		if (v)
+			i->grab_events = GRAB_EVENTS_WANTED;
+		break;
+	default:
+		return -1;
+	}
+	return 0;
+}
+
+static const struct tslib_vars raw_vars[] =
+{
+	{ "grab_events", (void *)1, parse_raw_grab },
+};
+
+#define NR_VARS (sizeof(raw_vars) / sizeof(raw_vars[0]))
+
 TSAPI struct tslib_module_info *mod_init(struct tsdev *dev, const char *params)
 {
 	struct tslib_input *i;
@@ -245,5 +297,12 @@
 	i->current_p = 0;
 	i->sane_fd = 0;
 	i->using_syn = 0;
+	i->grab_events = 0;
+
+	if (tslib_parse_vars(&i->module, raw_vars, NR_VARS, params)) {
+		free(i);
+		return NULL;
+	}
+
 	return &(i->module);
 }