aboutsummaryrefslogtreecommitdiffstats
path: root/recipes/xorg-driver/xf86-input-evtouch/04_server-1.7-ftbfs.diff
blob: 726297cff666f4cf8e2623f254c889be0c6a1d26 (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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
commit f88ce643a4d343cc27ef6ef7e0bf148f885043ab
Author: Mattia Dongili <malattia@linux.it>
Date:   Sun Jan 24 15:45:51 2010 +0900

    04
    
    Build with 1.7. Also add some more probing taken from evdev.
    
    Signed-off-by: Mattia Dongili <malattia@linux.it>

Index: xserver-xorg-input-evtouch/evtouch.c
===================================================================
--- xserver-xorg-input-evtouch.orig/evtouch.c	2010-02-14 14:08:33.000000000 +0900
+++ xserver-xorg-input-evtouch/evtouch.c	2010-02-14 14:13:51.000000000 +0900
@@ -57,6 +57,7 @@
 #define NEED_EVENTS
 #include <X11/X.h>
 #include <X11/Xproto.h>
+#include <xserver-properties.h>
 
 #include "xf86.h"
 
@@ -129,7 +130,6 @@
         0
 };
 
-#ifdef XFree86LOADER
 static XF86ModuleVersionInfo VersionRec =
 {
         "evtouch",
@@ -164,9 +164,7 @@
 }
 
 
-XF86ModuleData evtouchModuleData = {&VersionRec, Plug, Unplug };
-
-#endif /* XFree86LOADER */
+_X_EXPORT XF86ModuleData evtouchModuleData = {&VersionRec, Plug, Unplug };
 
 
 static const char *default_options[] =
@@ -239,7 +237,7 @@
 
         priv->emulate3_timer_expired = TRUE;
         xf86UnblockSIGIO(sigstate);
-             
+
         return 0;
 }
 
@@ -339,7 +337,7 @@
 						     priv->cur_x, 
 						     priv->cur_y);
 			}
-		}			
+		}
 	}
 }
 
@@ -372,7 +370,7 @@
                     0, 0, 0, 0,
                     &priv->cur_x, &priv->cur_y);
 #endif
-	
+
         libtouchSetPos(priv->libtouch, priv->cur_x, priv->cur_y);
 }
 
@@ -394,7 +392,7 @@
                                                         priv->emulate3_timeout,
                                                         emulate3Timer,
                                                         local);
-                
+
                 if ( (ev->value == 1) && (ev->code == BTN_LEFT) ) {
                         priv->touch_flags |= LB_STAT;
                 }
@@ -419,7 +417,7 @@
                         DBGOUT(2, "EVTouch: Right Release\n");
                         priv->touch_flags &= ~RB_STAT;
                         SetBtnAction(priv, 3, BTN_RELEASE);
-                }                                
+                }
         } else {
                 if (ev->code == BTN_LEFT) {
                         SetBtnAction(priv, 1, ev->value);
@@ -478,26 +476,98 @@
         return;
 }
 
-
-
+#define TestBit(bit, array) ((array[(bit) / LONG_BITS]) & (1L << ((bit) % LONG_BITS)))
+#define ArrayLength(a) (sizeof(a) / (sizeof((a)[0])))
 
 static Bool
 QueryHardware (LocalDevicePtr local)
 {
-        DBGOUT(2, "EVTouch: %s\n", __FUNCTION__);
-
-        return Success;
+    EVTouchPrivatePtr priv = (EVTouchPrivatePtr) (local->private);
+    size_t len;
+    int i, num_buttons;
+
+    DBGOUT(2, "EVTouch: %s\n", __FUNCTION__);
+
+    if (ioctl(local->fd, EVIOCGNAME(sizeof(priv->name) - 1), priv->name) < 0) {
+	    xf86Msg(X_ERROR, "ioctl EVIOCGNAME failed: %s\n", strerror(errno));
+	    goto error;
+    }
+
+    len = ioctl(local->fd, EVIOCGBIT(0, sizeof(priv->bitmask)), priv->bitmask);
+    if (len < 0) {
+	    xf86Msg(X_ERROR, "%s: ioctl EVIOCGBIT failed: %s\n",
+			    local->name, strerror(errno));
+	    goto error;
+    }
+
+    len = ioctl(local->fd, EVIOCGBIT(EV_REL, sizeof(priv->rel_bitmask)), priv->rel_bitmask);
+    if (len < 0) {
+	    xf86Msg(X_ERROR, "%s: ioctl EVIOCGBIT failed: %s\n",
+			    local->name, strerror(errno));
+	    goto error;
+    }
+
+    len = ioctl(local->fd, EVIOCGBIT(EV_ABS, sizeof(priv->abs_bitmask)), priv->abs_bitmask);
+    if (len < 0) {
+	    xf86Msg(X_ERROR, "%s: ioctl EVIOCGBIT failed: %s\n",
+			    local->name, strerror(errno));
+	    goto error;
+    }
+
+    len = ioctl(local->fd, EVIOCGBIT(EV_KEY, sizeof(priv->key_bitmask)), priv->key_bitmask);
+    if (len < 0) {
+	    xf86Msg(X_ERROR, "%s: ioctl EVIOCGBIT failed: %s\n",
+			    local->name, strerror(errno));
+	    goto error;
+    }
+
+    num_buttons = 0;
+
+    /* count all buttons */
+    for (i = BTN_MISC; i < BTN_JOYSTICK; i++)
+    {
+        if (TestBit(i, priv->key_bitmask))
+        {
+            if (i > num_buttons)
+                num_buttons = i;
+        }
+    }
+    if (num_buttons)
+    {
+        priv->flags |= EVTOUCH_BUTTON_EVENTS;
+        priv->num_buttons = num_buttons;
+        xf86Msg(X_INFO, "%s: Found %d mouse buttons\n", local->name,
+                num_buttons);
+    }
+
+    for (i = 0; i < REL_MAX; i++) {
+        if (TestBit(i, priv->rel_bitmask)) {
+            xf86Msg(X_INFO, "%s: Found relative axes\n", local->name);
+            priv->flags |= EVTOUCH_RELATIVE_EVENTS;
+            break;
+        }
+    }
+
+    for (i = 0; i < ABS_MAX; i++) {
+        if (TestBit(i, priv->abs_bitmask)) {
+            xf86Msg(X_INFO, "%s: Found absolute axes\n", local->name);
+            priv->flags |= EVTOUCH_ABSOLUTE_EVENTS;
+            break;
+        }
+    }
+
+    return Success;
+error:
+    return (!Success);
 }
 
 
-
-
 static Bool
 DeviceOn (DeviceIntPtr dev)
 {
         LocalDevicePtr local = (LocalDevicePtr) dev->public.devicePrivate;
         EVTouchPrivatePtr priv = (EVTouchPrivatePtr) (local->private);
-        
+
         local->fd = xf86OpenSerial(local->options);
 
         DBGOUT(2, "EVTouch: %s\n", __FUNCTION__ );
@@ -512,8 +582,7 @@
 
         DBG (9, XisbTrace (priv->buffer, 1));
 
-
-        if (!priv->buffer) 
+        if (!priv->buffer)
         {
                 xf86CloseSerial(local->fd);
                 local->fd = -1;
@@ -531,7 +600,6 @@
         if (ioctl(local->fd, EVIOCGRAB, (void *)1))
                 xf86Msg(X_ERROR, "%s: Unable to grab device (%s).\n", local->name, strerror(errno));
 
-
 #ifndef XFREE86_V4
         xf86AddEnabledDevice(local);
 #else
@@ -544,8 +612,6 @@
 }
 
 
-
-
 static Bool
 DeviceOff (DeviceIntPtr dev)
 {
@@ -555,7 +621,7 @@
         DBGOUT(2, "EVTouch: %s\n", __FUNCTION__ );
 
         if (local->fd != -1)
-        { 
+        {
                 ioctl(local->fd, EVIOCGRAB, (void *)0);
                 xf86RemoveEnabledDevice (local);
                 if (priv->buffer)
@@ -577,6 +643,73 @@
 }
 
 
+static Atom *EvtouchInitButtonLabels(void)
+{
+#ifdef HAVE_LABELS
+    Atom *labels = xalloc(EV_MAX_BUTTONS * sizeof(Atom));
+
+    /* initialize the 5 button labels used by this driver */
+    labels[0] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_LEFT);
+    labels[1] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_MIDDLE);
+    labels[2] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_RIGHT);
+    labels[3] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_WHEEL_UP);
+    labels[4] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_WHEEL_DOWN);
+
+    return labels;
+#endif
+}
+
+static char* abs_labels[] = {
+    AXIS_LABEL_PROP_ABS_X,
+    AXIS_LABEL_PROP_ABS_Y,
+    AXIS_LABEL_PROP_ABS_Z,
+    AXIS_LABEL_PROP_ABS_WHEEL
+};
+static char* rel_labels[] = {
+    AXIS_LABEL_PROP_REL_X,
+    AXIS_LABEL_PROP_REL_Y,
+    AXIS_LABEL_PROP_REL_Z,
+    AXIS_LABEL_PROP_REL_WHEEL
+};
+
+static void
+EvtouchInitAxesLabels(EVTouchPrivatePtr pEVTouch, int natoms, Atom *atoms)
+{
+#ifdef HAVE_LABELS
+    Atom atom;
+    int axis;
+    char **labels;
+    int labels_len = 0;
+    char *misc_label;
+
+    if (pEVTouch->flags & EVTOUCH_ABSOLUTE_EVENTS)
+    {
+        labels     = abs_labels;
+        labels_len = ArrayLength(abs_labels);
+        misc_label = AXIS_LABEL_PROP_ABS_MISC;
+    } else if ((pEVTouch->flags & EVTOUCH_RELATIVE_EVENTS))
+    {
+        labels     = rel_labels;
+        labels_len = ArrayLength(rel_labels);
+        misc_label = AXIS_LABEL_PROP_REL_MISC;
+    }
+
+    memset(atoms, 0, natoms * sizeof(Atom));
+
+    /* Now fill the ones we know */
+    for (axis = 0; axis < labels_len; axis++)
+    {
+        if (pEVTouch->axis_map[axis] == -1)
+            continue;
+
+        atom = XIGetKnownProperty(labels[axis]);
+        if (!atom) /* Should not happen */
+            continue;
+
+        atoms[pEVTouch->axis_map[axis]] = atom;
+    }
+#endif
+}
 
 
 static Bool
@@ -585,6 +718,7 @@
         DBGOUT(2, "EVTouch: %s\n", __FUNCTION__);
         LocalDevicePtr local = (LocalDevicePtr) dev->public.devicePrivate;
         EVTouchPrivatePtr priv = (EVTouchPrivatePtr) (local->private);
+	Atom *labels, *atoms;
         unsigned char map[EV_MAX_BUTTONS];
         int i;
 
@@ -593,7 +727,7 @@
 
         priv->btn_count = EV_MAX_BUTTONS;
 
-        /* 
+        /*
          * these have to be here instead of in the SetupProc, because when the
          * SetupProc is run at server startup, screenInfo is not setup yet
          */
@@ -603,9 +737,9 @@
         priv->screen_height = pScrn->virtualY;
         priv->pViewPort_X0  = &(pScrn->frameX0);   /* initialize the pointers to the viewport coords */
         if ( (priv->screen_width != priv->phys_width) ||
-             (priv->screen_height != priv->phys_height) ) 
+             (priv->screen_height != priv->phys_height) )
               priv->virtual = 1;
-        else  
+        else
                 priv->virtual = 0;
 
         priv->pViewPort_Y0  = &(pScrn->frameY0);
@@ -620,24 +754,29 @@
         DBGOUT(2, "EVTouch: MaxValue H,V: %d %d\n", pScrn->maxHValue, pScrn->maxVValue);
 
         priv->screen_width = screenInfo.screens[priv->screen_num]->width;
-        priv->screen_height = screenInfo.screens[priv->screen_num]->height;        
+        priv->screen_height = screenInfo.screens[priv->screen_num]->height;
 
-        /* 
+        /*
          * Device reports button press for 5 buttons.
          */
-        if (InitButtonClassDeviceStruct (dev, EV_MAX_BUTTONS, map) == FALSE)
+	labels = EvtouchInitButtonLabels();
+        if (InitButtonClassDeviceStruct (dev, EV_MAX_BUTTONS,
+#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
+				labels,
+#endif
+				map) == FALSE)
         {
                 ErrorF("Unable to allocate EVTouch touchscreen ButtonClassDeviceStruct\n");
                 return BadAlloc;
-        } 
+        }
 
-        DBGOUT(2, "EVTouch: %s btn_count=%d\n", __FUNCTION__, 
+        DBGOUT(2, "EVTouch: %s btn_count=%d\n", __FUNCTION__,
                priv->btn_count);
         priv->btn_actions = xcalloc(priv->btn_count, sizeof(BtnAction));
-        memset(priv->btn_actions, 0, 
+        memset(priv->btn_actions, 0,
                priv->btn_count * sizeof(BtnAction));
-        
-        DBGOUT(2, "EVTouch: %s btn_count=%d\n", __FUNCTION__, 
+
+        DBGOUT(2, "EVTouch: %s btn_count=%d\n", __FUNCTION__,
                priv->btn_count);
 
         if (InitFocusClassDeviceStruct(dev) == FALSE) {
@@ -645,13 +784,18 @@
                 return !Success;
         }
 
-        /* 
+        /*
          * Device reports motions on 2 axes in absolute coordinates.
          * Axes min and max values are reported in raw coordinates.
          */
+	atoms = xalloc(2 * sizeof(Atom));
+	EvtouchInitAxesLabels(priv, 2, atoms);
+
         if (InitValuatorClassDeviceStruct(dev, 2,
 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) == 0
                                           xf86GetMotionEvents,
+#elif GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
+					  atoms,
 #endif
                                           local->history_size, Absolute) == FALSE)
         {
@@ -660,12 +804,20 @@
         }
 
 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 2
-        xf86InitValuatorAxisStruct(dev, 0, 0, priv->screen_width,
+        xf86InitValuatorAxisStruct(dev, 0,
+#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
+			           atoms[0],
+#endif
+			           0, priv->screen_width,
                                    1024,
                                    EV_AXIS_MIN_RES /* min_res */ ,
                                    EV_AXIS_MAX_RES /* max_res */ );
         xf86InitValuatorDefaults(dev, 0);
-        xf86InitValuatorAxisStruct(dev, 1, 0, priv->screen_height,
+        xf86InitValuatorAxisStruct(dev, 1,
+#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
+			           atoms[1],
+#endif
+                                   0, priv->screen_height,
                                    1024,
                                    EV_AXIS_MIN_RES /* min_res */ ,
                                    EV_AXIS_MAX_RES /* max_res */ );
@@ -682,7 +834,6 @@
 	priv->raw_y=priv->cur_y;
         libtouchSetPos(priv->libtouch, priv->cur_x, priv->cur_y);
 
-        
         if (InitProximityClassDeviceStruct (dev) == FALSE)
         {
                 ErrorF ("Unable to allocate EVTouch touchscreen ProximityClassDeviceStruct\n");
@@ -695,7 +846,7 @@
                 return !Success;
         }
 
-        /* 
+        /*
          * Allocate the motion events buffer.
          */
         xf86MotionHistoryAllocate (local);
@@ -765,7 +916,7 @@
                 if (sizeof(priv->ev) == count) {
                         count = 0;
                         EVTouchDumpPacketToLog(priv);
-                        
+
                         return Success;
                 }
         }
Index: xserver-xorg-input-evtouch/evtouch.h
===================================================================
--- xserver-xorg-input-evtouch.orig/evtouch.h	2010-02-14 14:01:43.000000000 +0900
+++ xserver-xorg-input-evtouch/evtouch.h	2010-02-14 14:08:34.000000000 +0900
@@ -35,6 +35,22 @@
 #define DBGOUT(lvl, ...)
 #endif
 
+#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 3
+#define HAVE_PROPERTIES 1
+
+/* 1.6 has properties, but no labels */
+#ifdef AXIS_LABEL_PROP
+#define HAVE_LABELS
+#else
+#undef HAVE_LABELS
+#endif
+
+#endif
+
+#define LONG_BITS (sizeof(long) * 8)
+/* Number of longs needed to hold the given number of bits */
+#define NLONGS(x) (((x) + LONG_BITS - 1) / LONG_BITS)
+
 /******************************************************************************
  *  Definitions
  *  structs, typedefs, #defines, enums
@@ -52,6 +68,10 @@
 
 #define EV_MAX_BUTTONS        5
 
+#define EVTOUCH_BUTTON_EVENTS		0x01
+#define EVTOUCH_RELATIVE_EVENTS		0x02
+#define EVTOUCH_ABSOLUTE_EVENTS		0x04
+
 #define TOUCHED 0x01
 #define X_COORD 0x02
 #define Y_COORD 0x04
@@ -80,6 +100,8 @@
         int min_rel_y;  /* Minimum y reported by calibration        */
         int max_rel_y;  /* Maximum y                    */
 
+	int axis_map[max(ABS_CNT, REL_CNT)]; /* Map evtouch <axis> to index */
+
         int drag_timer;
         Bool emulate3;
         int emulate3_timeout;
@@ -129,10 +151,10 @@
         int screen_num;    /* Screen associated with the device */
         int screen_width;   /* Width of the associated X screen  */
         int screen_height;   /* Height of the screen              */
-        
+
         XISBuffer *buffer;
         struct input_event ev; /* packet being/just read */
-        
+
         int packeti;    /* index into packet */
         Bool cs7flag;
         Bool binary_pkt;   /* indicates packet was a binary touch */
@@ -141,6 +163,16 @@
 
         LibTouchRecPtr libtouch;
         LocalDevicePtr local;
+
+	/* Cached info from device. */
+	int flags;
+	int num_buttons;
+	char name[1024];
+	unsigned long bitmask[NLONGS(EV_CNT)];
+	unsigned long key_bitmask[NLONGS(KEY_CNT)];
+	unsigned long rel_bitmask[NLONGS(REL_CNT)];
+	unsigned long abs_bitmask[NLONGS(ABS_CNT)];
+
 } EVTouchPrivateRec, *EVTouchPrivatePtr;