Trying to add kdrive evdev touchscreen support, ran into some problems.

Marko Katić dromede at gmail.com
Thu Oct 27 06:59:06 PDT 2011


As the title suggests, i'm trying to add basic kdrive touchscreen support
through evdev. I'm doing this because i'm trying to get rid of tslib. Tslib
uses evdev internally
so my idea was to eliminate the need for tslib by using parts of it to
enhance kdrive's evdev pointer driver. Here's the experimental patch:

diff --git a/hw/kdrive/linux/evdev.c b/hw/kdrive/linux/evdev.c
index 096a2dd..0e3c69e 100644
--- a/hw/kdrive/linux/evdev.c
+++ b/hw/kdrive/linux/evdev.c
@@ -60,6 +60,15 @@ typedef struct _kevdev {
     int                     fd;
 } Kevdev;

+struct ts_sample {
+ int x;
+ int y;
+ int lastx;
+ int lasty;
+ unsigned int pressure;
+ struct timeval tv;
+};
+
 static void
 EvdevPtrBtn (KdPointerInfo    *pi, struct input_event *ev)
 {
@@ -161,6 +170,10 @@ EvdevPtrRead (int evdevPort, void *closure)
     int                        i;
     struct input_event        events[NUM_EVENTS];
     int                        n;
+    long x = 0, y = 0;
+    unsigned long flags;
+    int a[7]={37, -8961, 33606232, 12473, 252, -3803356, 65536};
+    struct ts_sample ts_event;

     n = read (evdevPort, &events, NUM_EVENTS * sizeof (struct
input_event));
     if (n <= 0) {
@@ -172,22 +185,60 @@ EvdevPtrRead (int evdevPort, void *closure)
     n /= sizeof (struct input_event);
     for (i = 0; i < n; i++)
     {
-        switch (events[i].type) {
-        case EV_SYN:
-            break;
-        case EV_KEY:
-            EvdevPtrBtn (pi, &events[i]);
-            break;
-        case EV_REL:
-            ke->rel[events[i].code] += events[i].value;
-            EvdevPtrMotion (pi, &events[i]);
-            break;
-        case EV_ABS:
-            ke->abs[events[i].code] = events[i].value;
-            EvdevPtrMotion (pi, &events[i]);
-            break;
-        }
-    }
+     switch (events[i].type) {
+     case EV_KEY:
+     switch (events[i].code) {
+     case BTN_TOUCH:
+     if (events[i].value == 0) {
+     /* pen up */
+     ts_event.x = 0;
+     ts_event.y = 0;
+     ts_event.pressure = 0;
+     ts_event.tv = events[i].time;
+     }
+     break;
+     }
+     break;
+     case EV_SYN: /* Fill out a new complete event */
+
+     if (ts_event.pressure) {
+
+     flags = KD_BUTTON_1;
+
+         x = ( a[2] + a[0]*ts_event.x + a[1]*ts_event.y ) / a[6];
+         y = ( a[5] + a[3]*ts_event.x + a[4]*ts_event.y ) / a[6];
+
+     KdEnqueuePointerEvent (pi, flags, x, y, ts_event.pressure);
+
+     ts_event.lastx = x;
+     ts_event.lasty = y;
+
+     }
+     else {
+
+     flags = 0;
+ x = ts_event.lastx;
+ y = ts_event.lasty;
+
+     KdEnqueuePointerEvent (pi, flags, x, y, ts_event.pressure);
+     }
+
+     break;
+     case EV_ABS:
+     switch (events[i].code) {
+     case ABS_X:
+     ts_event.x = events[i].value;
+     break;
+     case ABS_Y:
+     ts_event.y = events[i].value;
+     break;
+     case ABS_PRESSURE:
+     ts_event.pressure = events[i].value;
+     break;
+     }
+     break;
+     }
+     }
 }

 char *kdefaultEvdev[] =  {

This patch was tested on a Sharp Zaurus C-1000 running kdrive 1.7.99.2.
Kdrive was built with the Yocto build system. Tests were made with mrxvt,
icewm, and xev. Everything seems to work just fine, coordinate scaling
works, left mouse button works. But i have extremely erratic pointer
movement when touching buttons, scrollbars or when moving windows. For
instance, if i touch the root window or mrxvt window, the pointer behaves as
expected. If i try to use the scrollbar or any of the buttons on mrxvt, move
windows,  the pointer goes crazy and most often jumps to the edges of the
screen (size 640x480). This is clearly visible in Xev output, for instance:

 MotionNotify event, serial 26, synthetic NO, window 0x600001,
    root 0x43, subw 0x0, time 2495627686, (101,63), root:(559,336),
    state 0x0, is_hint 0, same_screen YES

ButtonPress event, serial 26, synthetic NO, window 0x600001,
    root 0x43, subw 0x0, time 2495627686, (101,63), root:(559,336),
    state 0x0, button 1, same_screen YES

MotionNotify event, serial 26, synthetic NO, window 0x600001,
    root 0x43, subw 0x0, time 2495627697, (104,65), root:(562,338),
    state 0x100, is_hint 0, same_screen YES

LeaveNotify event, serial 26, synthetic NO, window 0x600001,
    root 0x43, subw 0x0, time 2495627705, (181,206), root:(639,479),
    mode NotifyNormal, detail NotifyNonlinear, same_screen YES,
    focus YES, state 256

MotionNotify event, serial 26, synthetic NO, window 0x600001,
    root 0x43, subw 0x0, time 2495627705, (181,206), root:(639,479),
    state 0x100, is_hint 0, same_screen YES

ButtonRelease event, serial 26, synthetic NO, window 0x600001,
    root 0x43, subw 0x0, time 2495627705, (181,206), root:(639,479),


Or:


MotionNotify event, serial 26, synthetic NO, window 0x600001,
    root 0x43, subw 0x0, time 2495640336, (110,66), root:(568,339),
    state 0x0, is_hint 0, same_screen YES

ButtonPress event, serial 26, synthetic NO, window 0x600001,
    root 0x43, subw 0x0, time 2495640337, (110,66), root:(568,339),
    state 0x0, button 1, same_screen YES

MotionNotify event, serial 26, synthetic NO, window 0x600001,
    root 0x43, subw 0x0, time 2495640347, (113,64), root:(571,337),
    state 0x100, is_hint 0, same_screen YES

LeaveNotify event, serial 26, synthetic NO, window 0x600001,
    root 0x43, subw 0x0, time 2495640356, (101,-273), root:(559,0),
    mode NotifyNormal, detail NotifyAncestor, same_screen YES,
    focus YES, state 256

MotionNotify event, serial 26, synthetic NO, window 0x600001,
    root 0x43, subw 0x0, time 2495640356, (101,-273), root:(559,0),
    state 0x100, is_hint 0, same_screen YES


What could be the cause of this?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.x.org/archives/xorg-devel/attachments/20111027/665d0a07/attachment.htm>


More information about the xorg-devel mailing list