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 <div>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:</div>
<div><br></div><div><div>diff --git a/hw/kdrive/linux/evdev.c b/hw/kdrive/linux/evdev.c</div><div>index 096a2dd..0e3c69e 100644</div><div>--- a/hw/kdrive/linux/evdev.c</div><div>+++ b/hw/kdrive/linux/evdev.c</div><div>@@ -60,6 +60,15 @@ typedef struct _kevdev {</div>
<div> int fd;</div><div> } Kevdev;</div><div> </div><div>+struct ts_sample {</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span>int<span class="Apple-tab-span" style="white-space:pre">                </span>x;</div>
<div>+<span class="Apple-tab-span" style="white-space:pre">        </span>int<span class="Apple-tab-span" style="white-space:pre">                </span>y;</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span>int <span class="Apple-tab-span" style="white-space:pre">        </span>lastx;</div>
<div>+<span class="Apple-tab-span" style="white-space:pre">        </span>int<span class="Apple-tab-span" style="white-space:pre">                </span>lasty;</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span>unsigned int<span class="Apple-tab-span" style="white-space:pre">        </span>pressure;</div>
<div>+<span class="Apple-tab-span" style="white-space:pre">        </span>struct timeval<span class="Apple-tab-span" style="white-space:pre">        </span>tv;</div><div>+};</div><div>+</div><div> static void</div><div> EvdevPtrBtn (KdPointerInfo *pi, struct input_event *ev)</div>
<div> {</div><div>@@ -161,6 +170,10 @@ EvdevPtrRead (int evdevPort, void *closure)</div><div> int i;</div><div> struct input_event events[NUM_EVENTS];</div><div> int n;</div>
<div>+ long x = 0, y = 0;</div><div>+ unsigned long flags;</div><div>+ int a[7]={37, -8961, 33606232, 12473, 252, -3803356, 65536};</div><div>+ struct ts_sample ts_event;</div><div> </div><div> n = read (evdevPort, &events, NUM_EVENTS * sizeof (struct input_event));</div>
<div> if (n <= 0) {</div><div>@@ -172,22 +185,60 @@ EvdevPtrRead (int evdevPort, void *closure)</div><div> n /= sizeof (struct input_event);</div><div> for (i = 0; i < n; i++)</div><div> {</div><div>
- switch (events[i].type) {</div><div>- case EV_SYN:</div><div>- break;</div><div>- case EV_KEY:</div><div>- EvdevPtrBtn (pi, &events[i]);</div><div>- break;</div>
<div>- case EV_REL:</div><div>- ke->rel[events[i].code] += events[i].value;</div><div>- EvdevPtrMotion (pi, &events[i]);</div><div>- break;</div><div>- case EV_ABS:</div>
<div>- ke->abs[events[i].code] = events[i].value;</div><div>- EvdevPtrMotion (pi, &events[i]);</div><div>- break;</div><div>- }</div><div>- }</div><div>+ <span class="Apple-tab-span" style="white-space:pre">        </span>switch (events[i].type) {</div>
<div>+ <span class="Apple-tab-span" style="white-space:pre">                                </span>case EV_KEY:</div><div>+ <span class="Apple-tab-span" style="white-space:pre">                                        </span>switch (events[i].code) {</div><div>+ <span class="Apple-tab-span" style="white-space:pre">                                        </span>case BTN_TOUCH:</div>
<div>+ <span class="Apple-tab-span" style="white-space:pre">                                                </span>if (events[i].value == 0) {</div><div>+ <span class="Apple-tab-span" style="white-space:pre">                                                        </span>/* pen up */</div><div>+ <span class="Apple-tab-span" style="white-space:pre">                                                        </span>ts_event.x = 0;</div>
<div>+ <span class="Apple-tab-span" style="white-space:pre">                                                        </span>ts_event.y = 0;</div><div>+ <span class="Apple-tab-span" style="white-space:pre">                                                        </span>ts_event.pressure = 0;</div><div>+ <span class="Apple-tab-span" style="white-space:pre">                                                        </span><a href="http://ts_event.tv">ts_event.tv</a> = events[i].time;</div>
<div>+ <span class="Apple-tab-span" style="white-space:pre">                                                </span>}</div><div>+ <span class="Apple-tab-span" style="white-space:pre">                                                </span>break;</div><div>+ <span class="Apple-tab-span" style="white-space:pre">                                        </span>}</div>
<div>+ <span class="Apple-tab-span" style="white-space:pre">                                        </span>break;</div><div>+ <span class="Apple-tab-span" style="white-space:pre">                                </span>case EV_SYN: /* Fill out a new complete event */</div><div>+</div>
<div>+ <span class="Apple-tab-span" style="white-space:pre">                                        </span>if (ts_event.pressure) {</div><div>+</div><div>+ <span class="Apple-tab-span" style="white-space:pre">                                                </span>flags = KD_BUTTON_1;</div><div>
+</div><div>+ <span class="Apple-tab-span" style="white-space:pre">                                        </span>x = ( a[2] + a[0]*ts_event.x + a[1]*ts_event.y ) / a[6];</div><div>+ <span class="Apple-tab-span" style="white-space:pre">                                        </span>y = ( a[5] + a[3]*ts_event.x + a[4]*ts_event.y ) / a[6];</div>
<div>+</div><div>+ <span class="Apple-tab-span" style="white-space:pre">                                                </span>KdEnqueuePointerEvent (pi, flags, x, y, ts_event.pressure);</div><div>+</div><div>+ <span class="Apple-tab-span" style="white-space:pre">                                                </span>ts_event.lastx = x;</div>
<div>+ <span class="Apple-tab-span" style="white-space:pre">                                                </span>ts_event.lasty = y;</div><div>+</div><div>+ <span class="Apple-tab-span" style="white-space:pre">                                        </span>}</div><div>+ <span class="Apple-tab-span" style="white-space:pre">                                        </span>else {</div>
<div>+</div><div>+ <span class="Apple-tab-span" style="white-space:pre">                                                </span>flags = 0;</div><div>+<span class="Apple-tab-span" style="white-space:pre">                                                        </span>x = ts_event.lastx;</div><div>+<span class="Apple-tab-span" style="white-space:pre">                                                        </span>y = ts_event.lasty;</div>
<div>+</div><div>+ <span class="Apple-tab-span" style="white-space:pre">                                                </span>KdEnqueuePointerEvent (pi, flags, x, y, ts_event.pressure);</div><div>+ <span class="Apple-tab-span" style="white-space:pre">                                        </span>}</div>
<div>+</div><div>+ <span class="Apple-tab-span" style="white-space:pre">                                        </span>break;</div><div>+ <span class="Apple-tab-span" style="white-space:pre">                                </span>case EV_ABS:</div><div>+ <span class="Apple-tab-span" style="white-space:pre">                                        </span>switch (events[i].code) {</div>
<div>+ <span class="Apple-tab-span" style="white-space:pre">                                        </span>case ABS_X:</div><div>+ <span class="Apple-tab-span" style="white-space:pre">                                                </span>ts_event.x = events[i].value;</div><div>+ <span class="Apple-tab-span" style="white-space:pre">                                                </span>break;</div>
<div>+ <span class="Apple-tab-span" style="white-space:pre">                                        </span>case ABS_Y:</div><div>+ <span class="Apple-tab-span" style="white-space:pre">                                                </span>ts_event.y = events[i].value;</div><div>+ <span class="Apple-tab-span" style="white-space:pre">                                                </span>break;</div>
<div>+ <span class="Apple-tab-span" style="white-space:pre">                                        </span>case ABS_PRESSURE:</div><div>+ <span class="Apple-tab-span" style="white-space:pre">                                                </span>ts_event.pressure = events[i].value;</div><div>
+ <span class="Apple-tab-span" style="white-space:pre">                                                </span>break;</div><div>+ <span class="Apple-tab-span" style="white-space:pre">                                        </span>}</div><div>+ <span class="Apple-tab-span" style="white-space:pre">                                        </span>break;</div>
<div>+ <span class="Apple-tab-span" style="white-space:pre">                                </span>}</div><div>+ <span class="Apple-tab-span" style="white-space:pre">                        </span>}</div><div> }</div><div> </div><div> char *kdefaultEvdev[] = {</div>
</div><div><br></div><div>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: </div>
<div><br></div><div> MotionNotify event, serial 26, synthetic NO, window 0x600001,</div><div> root 0x43, subw 0x0, time 2495627686, (101,63), root:(559,336),</div><div> state 0x0, is_hint 0, same_screen YES</div><div>
<br></div><div>ButtonPress event, serial 26, synthetic NO, window 0x600001,</div><div> root 0x43, subw 0x0, time 2495627686, (101,63), root:(559,336),</div><div> state 0x0, button 1, same_screen YES</div><div><br></div>
<div>MotionNotify event, serial 26, synthetic NO, window 0x600001,</div><div> root 0x43, subw 0x0, time 2495627697, (104,65), root:(562,338),</div><div> state 0x100, is_hint 0, same_screen YES</div><div><br></div><div>
LeaveNotify event, serial 26, synthetic NO, window 0x600001,</div><div> root 0x43, subw 0x0, time 2495627705, (181,206), root:(639,479),</div><div> mode NotifyNormal, detail NotifyNonlinear, same_screen YES,</div><div>
focus YES, state 256</div><div><br></div><div><div>MotionNotify event, serial 26, synthetic NO, window 0x600001,</div><div> root 0x43, subw 0x0, time 2495627705, (181,206), root:(639,479),</div><div> state 0x100, is_hint 0, same_screen YES</div>
<div><br></div><div>ButtonRelease event, serial 26, synthetic NO, window 0x600001,</div><div> root 0x43, subw 0x0, time 2495627705, (181,206), root:(639,479),</div></div><div><br></div><div><br></div><div>Or:</div><div>
<br></div><div><br></div><div><div>MotionNotify event, serial 26, synthetic NO, window 0x600001,</div><div> root 0x43, subw 0x0, time 2495640336, (110,66), root:(568,339),</div><div> state 0x0, is_hint 0, same_screen YES</div>
<div><br></div><div>ButtonPress event, serial 26, synthetic NO, window 0x600001,</div><div> root 0x43, subw 0x0, time 2495640337, (110,66), root:(568,339),</div><div> state 0x0, button 1, same_screen YES</div><div><br>
</div><div>MotionNotify event, serial 26, synthetic NO, window 0x600001,</div><div> root 0x43, subw 0x0, time 2495640347, (113,64), root:(571,337),</div><div> state 0x100, is_hint 0, same_screen YES</div><div><br></div>
<div>LeaveNotify event, serial 26, synthetic NO, window 0x600001,</div><div> root 0x43, subw 0x0, time 2495640356, (101,-273), root:(559,0),</div><div> mode NotifyNormal, detail NotifyAncestor, same_screen YES,</div>
<div> focus YES, state 256</div><div><br></div><div>MotionNotify event, serial 26, synthetic NO, window 0x600001,</div><div> root 0x43, subw 0x0, time 2495640356, (101,-273), root:(559,0),</div><div> state 0x100, is_hint 0, same_screen YES</div>
</div><div><br></div><div><br></div><div>What could be the cause of this?</div>