add packages_10.03.2 in preparation for the 10.03.2 interim release
[10.03/packages.git] / Xorg / lib / tslib / patches / tslib-input_raw-grab_events.patch
1 This patch adds support for "EVIOCGRAB" on the input device, which
2 tells the kernel _not_ to deliver events of the touchscreen to
3 /dev/input/mice.  
4
5 This is probably what most people want, since unprocessed raw touchscreen
6 events should not be converted to emulated PS/2 mouse movements.
7
8 Signed-off-by: Harald Welte <laforge@openmoko.org>
9
10 Index: a/plugins/input-raw.c
11 ===================================================================
12 --- a/plugins/input-raw.c       (revision 49)
13 +++ b/plugins/input-raw.c       (working copy)
14 @@ -18,6 +18,7 @@
15  
16  #include <errno.h>
17  #include <stdio.h>
18 +#include <limits.h>
19  
20  #include <stdlib.h>
21  #ifdef HAVE_UNISTD_H
22 @@ -33,6 +34,9 @@
23  
24  #include "tslib-private.h"
25  
26 +#define GRAB_EVENTS_WANTED     1
27 +#define GRAB_EVENTS_ACTIVE     2
28 +
29  struct tslib_input {
30         struct tslib_module_info module;
31  
32 @@ -42,6 +46,7 @@
33  
34         int     sane_fd;
35         int     using_syn;
36 +       int     grab_events;
37  };
38  
39  static int check_fd(struct tslib_input *i)
40 @@ -64,6 +69,14 @@
41  
42         if (bit & (1 << EV_SYN))
43                 i->using_syn = 1;
44 +       
45 +       if (i->grab_events == GRAB_EVENTS_WANTED) {
46 +               if (ioctl(ts->fd, EVIOCGRAB, (void *)1)) {
47 +                       fprintf(stderr, "Unable to grab selected input device\n");
48 +                       return -1;
49 +               }
50 +               i->grab_events = GRAB_EVENTS_ACTIVE;
51 +       }
52  
53         return 0;
54  }
55 @@ -222,6 +235,15 @@
56  
57  static int ts_input_fini(struct tslib_module_info *inf)
58  {
59 +       struct tslib_input *i = (struct tslib_input *)inf;
60 +       struct tsdev *ts = inf->dev;
61 +
62 +       if (i->grab_events == GRAB_EVENTS_ACTIVE) {
63 +               if (ioctl(ts->fd, EVIOCGRAB, (void *)0)) {
64 +                       fprintf(stderr, "Unable to un-grab selected input device\n");
65 +               }
66 +       }
67 +
68         free(inf);
69         return 0;
70  }
71 @@ -231,6 +253,36 @@
72         .fini   = ts_input_fini,
73  };
74  
75 +static int parse_raw_grab(struct tslib_module_info *inf, char *str, void *data)
76 +{
77 +       struct tslib_input *i = (struct tslib_input *)inf;
78 +       unsigned long v;
79 +       int err = errno;
80 +
81 +       v = strtoul(str, NULL, 0);
82 +
83 +       if (v == ULONG_MAX && errno == ERANGE)
84 +               return -1;
85 +       
86 +       errno = err;
87 +       switch ((int)data) {
88 +       case 1:
89 +               if (v)
90 +                       i->grab_events = GRAB_EVENTS_WANTED;
91 +               break;
92 +       default:
93 +               return -1;
94 +       }
95 +       return 0;
96 +}
97 +
98 +static const struct tslib_vars raw_vars[] =
99 +{
100 +       { "grab_events", (void *)1, parse_raw_grab },
101 +};
102 +
103 +#define NR_VARS (sizeof(raw_vars) / sizeof(raw_vars[0]))
104 +
105  TSAPI struct tslib_module_info *mod_init(struct tsdev *dev, const char *params)
106  {
107         struct tslib_input *i;
108 @@ -245,5 +297,12 @@
109         i->current_p = 0;
110         i->sane_fd = 0;
111         i->using_syn = 0;
112 +       i->grab_events = 0;
113 +
114 +       if (tslib_parse_vars(&i->module, raw_vars, NR_VARS, params)) {
115 +               free(i);
116 +               return NULL;
117 +       }
118 +
119         return &(i->module);
120  }