]> pilppa.org Git - familiar-h63xx-build.git/blob - org.handhelds.familiar/packages/qte/qte-2.3.10/mnci-touchscreen.patch
OE tree imported from monotone branch org.openembedded.oz354fam083 at revision 8b12e3...
[familiar-h63xx-build.git] / org.handhelds.familiar / packages / qte / qte-2.3.10 / mnci-touchscreen.patch
1
2 #
3 # Patch managed by http://www.holgerschurig.de/patcher.html
4 #
5
6 --- qt-2.3.10/src/kernel/qwsmouse_qws.cpp~ramses-touchscreen
7 +++ qt-2.3.10/src/kernel/qwsmouse_qws.cpp
8 @@ -1,5 +1,5 @@
9  /****************************************************************************
10 -** $Id: qt/src/kernel/qwsmouse_qws.cpp   2.3.10   edited 2005-01-24 $
11 +** $Id: qt/src/kernel/qwsmouse_qws.cpp   2.3.7   edited 2003-02-04 $
12  **
13  ** Implementation of Qt/Embedded mouse drivers
14  **
15 @@ -47,85 +47,32 @@
16  #include <stdlib.h>
17  #include <stdio.h>
18  #include <sys/ioctl.h>
19 -#include <sys/time.h>
20  #include <sys/types.h>
21  #include <sys/stat.h>
22  #include <fcntl.h>
23  #include <errno.h>
24  #include <termios.h>
25  
26 +
27  #include <qgfx_qws.h>
28  #if !defined(_OS_QNX6_)
29  
30 -#ifdef QT_QWS_CASSIOPEIA
31 -#include <linux/tpanel.h>
32 -#endif
33 -#ifdef QT_QWS_TSLIB
34 -#include <tslib.h>
35 -#endif
36 -
37 -
38 -//#define QT_QWS_K2
39 -
40 -#if defined(QT_QWS_IPAQ) || defined(QT_QWS_K2)
41 -#define QT_QWS_IPAQ_RAW
42 -typedef struct {
43 -        unsigned short pressure;
44 -        unsigned short x;
45 -        unsigned short y;
46 -        unsigned short pad;
47 -        struct timeval stamp;
48 -} TS_EVENT;
49 -#elif defined(QT_QWS_SL5XXX)
50 -#define QT_QWS_SL5XXX_RAW
51 -typedef struct {
52 -       long y;
53 -       long x;
54 -       long pressure;
55 -       long long millisecs;
56 -} TS_EVENT;
57 -#define QT_QWS_TP_SAMPLE_SIZE 10
58 -#define QT_QWS_TP_MINIMUM_SAMPLES 4
59 -#define QT_QWS_TP_PRESSURE_THRESHOLD 500
60 -#define QT_QWS_TP_MOVE_LIMIT 50
61 -#define QT_QWS_TP_JITTER_LIMIT 2
62 -#elif defined(QT_QWS_SLC700)
63 -#define QT_QWS_SLC700_RAW
64 -typedef struct {
65 -       unsigned short pressure;
66 -       unsigned short x;
67 -       unsigned short y;
68 -      unsigned short millisecs;
69 -} TS_EVENT;
70 -#define QT_QWS_TP_SAMPLE_SIZE 10
71 -#define QT_QWS_TP_MINIMUM_SAMPLES 4
72 -#define QT_QWS_TP_PRESSURE_THRESHOLD 500
73 -#define QT_QWS_TP_MOVE_LIMIT 50
74 -#define QT_QWS_TP_JITTER_LIMIT 2
75 -#endif
76 -
77 -#ifndef QT_QWS_TP_SAMPLE_SIZE
78 -#define QT_QWS_TP_SAMPLE_SIZE 5
79 -#endif
80 -
81 -#ifndef QT_QWS_TP_MINIMUM_SAMPLES
82 -#define QT_QWS_TP_MINIMUM_SAMPLES 5
83 +#ifndef QT_QWS_TP_PRESSURE_DOWN_THRESHOLD
84 +#define QT_QWS_TP_PRESSURE_DOWN_THRESHOLD 500
85  #endif
86  
87 -#ifndef QT_QWS_TP_PRESSURE_THRESHOLD
88 -#define QT_QWS_TP_PRESSURE_THRESHOLD 1
89 +#ifndef QT_QWS_TP_PRESSURE_UP_THRESHOLD
90 +#define QT_QWS_TP_PRESSURE_UP_THRESHOLD 450
91  #endif
92  
93 -#ifndef QT_QWS_TP_MOVE_LIMIT
94 -#define QT_QWS_TP_MOVE_LIMIT 100
95 +#ifndef QT_QWS_TP_TABLE_SIZE
96 +#define QT_QWS_TP_TABLE_SIZE 2
97  #endif
98  
99 -#ifndef QT_QWS_TP_JITTER_LIMIT
100 -#define QT_QWS_TP_JITTER_LIMIT 2
101 +#ifndef QT_QWS_TP_MOVE_MAX
102 +#define QT_QWS_TP_MOVE_MAX 100
103  #endif
104  
105 -//#define QWS_CUSTOMTOUCHPANEL
106 -
107  /*!
108    \class QWSMouseHandler qwsmouse_qws.h
109    \brief Mouse driver/handler for Qt/Embedded
110 @@ -168,8 +115,7 @@
111  enum MouseProtocol { Unknown = -1, Auto = 0,
112                      MouseMan, IntelliMouse, Microsoft,
113                      QVFBMouse, TPanel, BusMouse,
114 -                    FirstAuto = MouseMan,
115 -                    LastAuto = Microsoft };
116 +                  };
117  
118  static void limitToScreen( QPoint &pt )
119  {
120 @@ -186,810 +132,14 @@
121  } MouseConfig;
122  
123  static const MouseConfig mouseConfig[] = {
124 -#ifndef QT_NO_QWS_MOUSE_AUTO
125      { "Auto",          Auto },
126 -#endif
127 -#ifndef QT_NO_QWS_MOUSE_PC
128 -    { "MouseMan",      MouseMan },
129 -    { "IntelliMouse",  IntelliMouse },
130 -    { "USB",           IntelliMouse },
131 -    { "Microsoft",      Microsoft },
132 -#endif
133 -#ifndef QT_NO_QWS_VFB
134      { "QVFbMouse",      QVFBMouse },
135 -#endif
136      { "TPanel",         TPanel },
137 -    { "BusMouse",       BusMouse },
138      { 0,               Unknown }
139  };
140  
141 -#ifndef QT_NO_QWS_MOUSE_AUTO
142 -/*
143 - * Automatic-detection mouse driver
144 - */
145 -
146 -class QAutoMouseSubHandler {
147 -protected:
148 -    enum { max_buf=32 };
149 -
150 -    int fd;
151 -
152 -    uchar buffer[max_buf];
153 -    int nbuf;
154 -
155 -    QPoint motion;
156 -    int bstate;
157 -
158 -    int goodness;
159 -    int badness;
160 -
161 -    virtual int tryData()=0;
162 -
163 -public:
164 -    QAutoMouseSubHandler(int f) : fd(f)
165 -    {
166 -       nbuf = bstate = goodness = badness = 0;
167 -    }
168 -
169 -    int file() const { return fd; }
170 -
171 -    void closeIfNot(int& f)
172 -    {
173 -       if ( fd != f ) {
174 -           f = fd;
175 -           close(fd);
176 -       }
177 -    }
178 -
179 -    void worse(int by=1) { badness+=by; }
180 -    bool reliable() const { return goodness >= 5 && badness < 50; }
181 -    int buttonState() const { return bstate; }
182 -    bool motionPending() const { return motion!=QPoint(0,0); }
183 -    QPoint takeMotion() { QPoint r=motion; motion=QPoint(0,0); return r; }
184 -
185 -    void appendData(uchar* data, int length)
186 -    {
187 -       memcpy(buffer+nbuf, data, length);
188 -       nbuf += length;
189 -    }
190 -
191 -    enum UsageResult { Insufficient, Motion, Button };
192 -
193 -    UsageResult useData()
194 -    {
195 -       int pbstate = bstate;
196 -       int n = tryData();
197 -       if ( n > 0 ) {
198 -           if ( n<nbuf )
199 -               memmove( buffer, buffer+n, nbuf-n );
200 -           nbuf -= n;
201 -           return pbstate == bstate ? Motion : Button;
202 -       }
203 -       return Insufficient;
204 -    }
205 -};
206 -
207 -class QAutoMouseSubHandler_intellimouse : public QAutoMouseSubHandler {
208 -    int packetsize;
209 -public:
210 -    QAutoMouseSubHandler_intellimouse(int f) : QAutoMouseSubHandler(f)
211 -    {
212 -       init();
213 -    }
214 -
215 -    void init()
216 -    {
217 -       int n;
218 -       uchar reply[20];
219 -
220 -       tcflush(fd,TCIOFLUSH);
221 -       static const uchar initseq[] = { 243, 200, 243, 100, 243, 80 };
222 -       static const uchar query[] = { 0xf2 };
223 -       if (write(fd, initseq, sizeof(initseq))!=sizeof(initseq)) {
224 -           badness = 100;
225 -           return;
226 -       }
227 -       usleep(10000);
228 -       tcflush(fd,TCIOFLUSH);
229 -       if (write(fd, query, sizeof(query))!=sizeof(query)) {
230 -           badness = 100;
231 -           return;
232 -       }
233 -       usleep(10000);
234 -       n = read(fd, reply, 20);
235 -       if ( n > 0 ) {
236 -           goodness = 10;
237 -           switch ( reply[n-1] ) {
238 -             case 3:
239 -             case 4:
240 -               packetsize = 4;
241 -               break;
242 -            default:
243 -               packetsize = 3;
244 -           }
245 -       } else {
246 -           badness = 100;
247 -       }
248 -    }
249 -
250 -    int tryData()
251 -    {
252 -       if ( nbuf >= packetsize ) {
253 -           //int overflow = (buffer[0]>>6 )& 0x03;
254 -
255 -           if ( /*overflow ||*/ !(buffer[0] & 8) ) {
256 -               badness++;
257 -               return 1;
258 -           } else {
259 -               motion +=
260 -                   QPoint((buffer[0] & 0x10) ? buffer[1]-256 : buffer[1],
261 -                          (buffer[0] & 0x20) ? 256-buffer[2] : -buffer[2]);
262 -               int nbstate = buffer[0] & 0x7;
263 -               if ( motion.x() || motion.y() || bstate != nbstate ) {
264 -                   bstate = nbstate;
265 -                   goodness++;
266 -               } else {
267 -                   badness++;
268 -                   return 1;
269 -               }
270 -           }
271 -           return packetsize;
272 -       }
273 -       return 0;
274 -    }
275 -};
276 -
277 -class QAutoMouseSubHandler_serial : public QAutoMouseSubHandler {
278 -public:
279 -    QAutoMouseSubHandler_serial(int f) : QAutoMouseSubHandler(f)
280 -    {
281 -       initSerial();
282 -    }
283 -
284 -protected:
285 -    void setflags(int f)
286 -    {
287 -       termios tty;
288 -       tcgetattr(fd, &tty);
289 -       tty.c_iflag     = IGNBRK | IGNPAR;
290 -       tty.c_oflag     = 0;
291 -       tty.c_lflag     = 0;
292 -       tty.c_cflag     = f | CREAD | CLOCAL | HUPCL;
293 -#if !defined(_OS_FREEBSD_) && !defined(_OS_SOLARIS_)
294 -       tty.c_line      = 0;
295 -#endif
296 -       tty.c_cc[VTIME] = 0;
297 -       tty.c_cc[VMIN]  = 1;
298 -       tcsetattr(fd, TCSANOW, &tty);
299 -    }
300 -
301 -private:
302 -    void initSerial()
303 -    {
304 -       int speed[4] = { B9600, B4800, B2400, B1200 };
305 -
306 -        for (int n = 0; n < 4; n++) {
307 -           setflags(CSTOPB | speed[n]);
308 -           write(fd, "*q", 2);
309 -           usleep(10000);
310 -        }
311 -    }
312 -};
313 -
314 -class QAutoMouseSubHandler_mousesystems : public QAutoMouseSubHandler_serial {
315 -public:
316 -    // ##### This driver has not been tested
317 -
318 -    QAutoMouseSubHandler_mousesystems(int f) : QAutoMouseSubHandler_serial(f)
319 -    {
320 -       init();
321 -    }
322 -
323 -    void init()
324 -    {
325 -       setflags(B1200|CS8|CSTOPB);
326 -       // 60Hz
327 -       if (write(fd, "R", 1)!=1) {
328 -           badness = 100;
329 -           return;
330 -       }
331 -       tcflush(fd,TCIOFLUSH);
332 -    }
333 -
334 -    int tryData()
335 -    {
336 -       if ( nbuf >= 5 ) {
337 -           if ( (buffer[0] & 0xf8) != 0x80 ) {
338 -               badness++;
339 -               return 1;
340 -           }
341 -           motion +=
342 -               QPoint((signed char)buffer[1] + (signed char)buffer[3],
343 -                      -(signed char)buffer[2] + (signed char)buffer[4]);
344 -           int t = ~buffer[0];
345 -           int nbstate = ((t&3) << 1) | ((t&4) >> 2);
346 -           if ( motion.x() || motion.y() || bstate != nbstate ) {
347 -               bstate = nbstate;
348 -               goodness++;
349 -           } else {
350 -               badness++;
351 -               return 1;
352 -           }
353 -           return 5;
354 -       }
355 -       return 0;
356 -    }
357 -};
358 -
359 -class QAutoMouseSubHandler_ms : public QAutoMouseSubHandler_serial {
360 -    int mman;
361 -public:
362 -    QAutoMouseSubHandler_ms(int f) : QAutoMouseSubHandler_serial(f)
363 -    {
364 -       mman=0;
365 -       init();
366 -    }
367 -
368 -    void init()
369 -    {
370 -       setflags(B1200|CS7);
371 -       // 60Hz
372 -       if (write(fd, "R", 1)!=1) {
373 -           badness = 100;
374 -           return;
375 -       }
376 -       tcflush(fd,TCIOFLUSH);
377 -    }
378 -
379 -    int tryData()
380 -    {
381 -       if ( !(buffer[0] & 0x40) ) {
382 -           if ( buffer[0] == 0x20 && (bstate & Qt::MidButton) ) {
383 -               mman=1; // mouseman extension
384 -           }
385 -           return 1;
386 -       }
387 -       int extra = mman&&(bstate & Qt::MidButton);
388 -       if ( nbuf >= 3+extra ) {
389 -           int nbstate = 0;
390 -           if ( buffer[0] == 0x40 && !bstate && !buffer[1] && !buffer[2] ) {
391 -               nbstate = Qt::MidButton;
392 -           } else {
393 -               nbstate = ((buffer[0] & 0x20) >> 5)
394 -                       | ((buffer[0] & 0x10) >> 3);
395 -               if ( extra && buffer[3] == 0x20 )
396 -                   nbstate = Qt::MidButton;
397 -           }
398 -
399 -           if ( buffer[1] & 0x40 ) {
400 -               badness++;
401 -               return 1;
402 -           } else {
403 -               motion +=
404 -                   QPoint((signed char)((buffer[0]&0x3)<<6)
405 -                           |(signed char)(buffer[1]&0x3f),
406 -                          (signed char)((buffer[0]&0xc)<<4)
407 -                           |(signed char)(buffer[2]&0x3f));
408 -               if ( motion.x() || motion.y() || bstate != nbstate ) {
409 -                   bstate = nbstate;
410 -                   goodness++;
411 -               } else {
412 -                   badness++;
413 -                   return 1;
414 -               }
415 -               return 3+extra;
416 -           }
417 -       }
418 -       return 0;
419 -    }
420 -};
421 -
422 -/*
423 -QAutoMouseHandler::UsageResult QAutoMouseHandler::useDev(Dev& d)
424 -{
425 -    if ( d.nbuf >= mouseData[d.protocol].bytesPerPacket ) {
426 -       uchar *mb = d.buf;
427 -       int bstate = 0;
428 -       int dx = 0;
429 -       int dy = 0;
430 -
431 -       switch (mouseProtocol) {
432 -           case MouseMan:
433 -           case IntelliMouse:
434 -           {
435 -               bstate = mb[0] & 0x7; // assuming Qt::*Button order
436 -
437 -               int overflow = (mb[0]>>6 )& 0x03;
438 -               if (mouseProtocol == MouseMan && overflow) {
439 -                   //### wheel events signalled with overflow bit, ignore for now
440 -               }
441 -               else {
442 -                   bool xs = mb[0] & 0x10;
443 -                   bool ys = mb[0] & 0x20;
444 -                   dx = xs ? mb[1]-256 : mb[1];
445 -                   dy = ys ? mb[2]-256 : mb[2];
446 -               }
447 -               break;
448 -           }
449 -           case Microsoft:
450 -               if ( ((mb[0] & 0x20) >> 3) ) {
451 -                   bstate |= Qt::LeftButton;
452 -               }
453 -               if ( ((mb[0] & 0x10) >> 4) ) {
454 -                   bstate |= Qt::RightButton;
455 -               }
456 -
457 -               dx=(signed char)(((mb[0] & 0x03) << 6) | (mb[1] & 0x3f));
458 -               dy=-(signed char)(((mb[0] & 0x0c) << 4) | (mb[2] & 0x3f));
459 -
460 -               break;
461 -       }
462 -    }
463 -    }
464 -*/
465 -
466 -#endif
467 -
468 -class QAutoMouseHandler : public QWSMouseHandler {
469 -    Q_OBJECT
470 -
471 -public:
472 -    QAutoMouseHandler();
473 -    ~QAutoMouseHandler();
474 -
475 -#ifndef QT_NO_QWS_MOUSE_AUTO
476 -private:
477 -    enum { max_dev=32 };
478 -    QAutoMouseSubHandler *sub[max_dev];
479 -    QList<QSocketNotifier> notifiers;
480 -    int nsub;
481 -    int retries;
482 -#endif
483 -
484 -private slots:
485 -    void readMouseData(int);
486 -
487 -private:
488 -#ifndef QT_NO_QWS_MOUSE_AUTO
489 -    void openDevices();
490 -    void closeDevices();
491 -    void notify(int fd);
492 -    bool sendEvent(QAutoMouseSubHandler& h)
493 -    {
494 -       if ( h.reliable() ) {
495 -           mousePos += h.takeMotion();
496 -           limitToScreen( mousePos );
497 -/*
498 -qDebug("%d,%d %c%c%c",
499 -mousePos.x(),mousePos.y(),
500 -(h.buttonState()&Qt::LeftButton)?'L':'.',
501 -(h.buttonState()&Qt::MidButton)?'M':'.',
502 -(h.buttonState()&Qt::RightButton)?'R':'.');
503 -*/
504 -           emit mouseChanged(mousePos,h.buttonState());
505 -           return TRUE;
506 -       } else {
507 -           h.takeMotion();
508 -           if ( h.buttonState() & (Qt::RightButton|Qt::MidButton) ) {
509 -               // Strange for the user to press right or middle without
510 -               // a moving mouse!
511 -               h.worse();
512 -           }
513 -           return FALSE;
514 -       }
515 -    }
516 -#endif
517 -};
518 -
519 -QAutoMouseHandler::QAutoMouseHandler()
520 -{
521 -#ifndef QT_NO_QWS_MOUSE_AUTO
522 -    notifiers.setAutoDelete( TRUE );
523 -    retries = 0;
524 -    openDevices();
525 -#endif
526 -}
527 -
528 -QAutoMouseHandler::~QAutoMouseHandler()
529 -{
530 -#ifndef QT_NO_QWS_MOUSE_AUTO
531 -    closeDevices();
532 -#endif
533 -}
534 -
535 -#ifndef QT_NO_QWS_MOUSE_AUTO
536 -void QAutoMouseHandler::openDevices()
537 -{
538 -    nsub=0;
539 -    int fd;
540 -    fd = open( "/dev/psaux", O_RDWR | O_NDELAY );
541 -    if ( fd >= 0 ) {
542 -       sub[nsub++] = new QAutoMouseSubHandler_intellimouse(fd);
543 -       notify(fd);
544 -    }
545 -#if !defined(QT_QWS_IPAQ) && !defined(QT_QWS_SL5XXX) && !defined(QT_QWS_K2) && !defined(QT_QWS_SLC700)
546 -    char fn[] = "/dev/ttyS?";
547 -    for (int ch='0'; ch<='3'; ch++) {
548 -       fn[9] = ch;
549 -       fd = open( fn, O_RDWR | O_NDELAY );
550 -       if ( fd >= 0 ) {
551 -           //sub[nsub++] = new QAutoMouseSubHandler_intellimouse(fd);
552 -           sub[nsub++] = new QAutoMouseSubHandler_mousesystems(fd);
553 -           sub[nsub++] = new QAutoMouseSubHandler_ms(fd);
554 -           notify(fd);
555 -       }
556 -    }
557 -#endif
558 -    // ...
559 -}
560 -
561 -void QAutoMouseHandler::closeDevices()
562 -{
563 -    int pfd=-1;
564 -    for (int i=0; i<nsub; i++) {
565 -       sub[i]->closeIfNot(pfd);
566 -       delete sub[i];
567 -    }
568 -    notifiers.clear();
569 -}
570 -
571 -void QAutoMouseHandler::notify(int fd)
572 -{
573 -    QSocketNotifier *mouseNotifier
574 -       = new QSocketNotifier( fd, QSocketNotifier::Read, this );
575 -    connect(mouseNotifier, SIGNAL(activated(int)),this, SLOT(readMouseData(int)));
576 -    notifiers.append( mouseNotifier );
577 -}
578 -#endif
579 -
580 -void QAutoMouseHandler::readMouseData(int fd)
581 -{
582 -#ifndef QT_NO_QWS_MOUSE_AUTO
583 -    for (;;) {
584 -       uchar buf[8];
585 -       int n = read(fd, buf, 8);
586 -       if ( n<=0 )
587 -           break;
588 -       for (int i=0; i<nsub; i++) {
589 -           QAutoMouseSubHandler& h = *sub[i];
590 -           if ( h.file() == fd ) {
591 -               h.appendData(buf,n);
592 -               for (;;) {
593 -                   switch ( h.useData() ) {
594 -                     case QAutoMouseSubHandler::Button:
595 -                       sendEvent(h);
596 -                       break;
597 -                     case QAutoMouseSubHandler::Insufficient:
598 -                       goto breakbreak;
599 -                     case QAutoMouseSubHandler::Motion:
600 -                       break;
601 -                   }
602 -               }
603 -               breakbreak:
604 -                   ;
605 -           }
606 -       }
607 -    }
608 -    bool any_reliable=FALSE;
609 -    for (int i=0; i<nsub; i++) {
610 -       QAutoMouseSubHandler& h = *sub[i];
611 -       if ( h.motionPending() )
612 -           sendEvent(h);
613 -       any_reliable = any_reliable || h.reliable();
614 -    }
615 -    if ( any_reliable ) {
616 -       // ... get rid of all unreliable ones?  All bad ones?
617 -    } else if ( retries < 2 ) {
618 -       // Try again - maybe the mouse was being moved when we tried to init.
619 -       closeDevices();
620 -       openDevices();
621 -       retries++;
622 -    }
623 -#else
624 -    Q_UNUSED( fd );
625 -#endif
626 -}
627 -
628 -
629 -
630 -
631 -/*
632 - * Standard mouse driver
633 - */
634 -
635 -typedef struct {
636 -    int bytesPerPacket;
637 -} MouseData;
638 -
639 -static const MouseData mouseData[] = {
640 -    { 3 },  // dummy for auto protocal,  correction made by add by YYD
641 -    { 3 },  // MouseMan
642 -    { 4 },  // intelliMouse
643 -    { 3 },  // Microsoft
644 -    { 0 },  // QVFBMouse,
645 -    { 0 },  // TPanel,
646 -    { 3 },  // BusMouse,
647 -};
648 -
649 -
650 -class QWSMouseHandlerPrivate : public QWSMouseHandler {
651 -    Q_OBJECT
652 -public:
653 -    QWSMouseHandlerPrivate( MouseProtocol protocol, QString mouseDev );
654 -    ~QWSMouseHandlerPrivate();
655 -
656 -#ifndef QT_NO_QWS_MOUSE_PC
657 -private:
658 -    static const int mouseBufSize = 128;
659 -    int mouseFD;
660 -    int mouseIdx;
661 -    uchar mouseBuf[mouseBufSize];
662 -    MouseProtocol mouseProtocol;
663 -    void handleMouseData();
664 -#endif
665 -
666 -private slots:
667 -    void readMouseData();
668 -
669 -private:
670 -    int obstate;
671 -};
672 -
673 -
674 -void QWSMouseHandlerPrivate::readMouseData()
675 -{
676 -#ifndef QT_NO_QWS_MOUSE_PC
677 -    int n;
678 -    if ( BusMouse == mouseProtocol ) {
679 -       // a workaround of linux busmouse driver interface.
680 -       // It'll only read 3 bytes a time and return all other buffer zeroed, thus cause protocol errors
681 -       for (;;) {
682 -           if ( mouseBufSize - mouseIdx < 3 )
683 -               break;
684 -           n = read( mouseFD, mouseBuf+mouseIdx, 3 );
685 -           if ( n != 3 )
686 -               break;
687 -           mouseIdx += 3;
688 -       }
689 -    } else {
690 -       do {
691 -           n = read(mouseFD, mouseBuf+mouseIdx, mouseBufSize-mouseIdx );
692 -           if ( n > 0 )
693 -               mouseIdx += n;
694 -       } while ( n > 0 );
695 -    }
696 -    handleMouseData();
697 -#endif
698 -}
699 -
700 -
701 -#ifndef QT_NO_QWS_MOUSE_PC
702 -/*
703 -*/
704 -
705 -void QWSMouseHandlerPrivate::handleMouseData()
706 -{
707 -    static const int accel_limit = 5;
708 -    static const int accel = 2;
709 -
710 -    int idx = 0;
711 -    int bstate = 0;
712 -    int dx = 0, dy = 0;
713 -    bool sendEvent = false;
714 -    int tdx = 0, tdy = 0;
715 -
716 -    while ( mouseIdx-idx >= mouseData[mouseProtocol].bytesPerPacket ) {
717 -       //qDebug( "Got mouse data" );
718 -       uchar *mb = mouseBuf+idx;
719 -       bstate = 0;
720 -       dx = 0;
721 -       dy = 0;
722 -       sendEvent = false;
723 -       switch (mouseProtocol) {
724 -           case MouseMan:
725 -           case IntelliMouse:
726 -           {
727 -               if (mb[0] & 0x01)
728 -                   bstate |= Qt::LeftButton;
729 -               if (mb[0] & 0x02)
730 -                   bstate |= Qt::RightButton;
731 -               if (mb[0] & 0x04)
732 -                   bstate |= Qt::MidButton;
733 -
734 -               int overflow = (mb[0]>>6 )& 0x03;
735 -               if (mouseProtocol == MouseMan && overflow) {
736 -                   //### wheel events signalled with overflow bit, ignore for now
737 -               }
738 -               else {
739 -                   bool xs = mb[0] & 0x10;
740 -                   bool ys = mb[0] & 0x20;
741 -                   dx = xs ? mb[1]-256 : mb[1];
742 -                   dy = ys ? mb[2]-256 : mb[2];
743  
744 -                   sendEvent = true;
745 -               }
746 -#if 0 //debug
747 -               if (mouseProtocol == MouseMan)
748 -                   printf("(%2d) %02x %02x %02x ", idx, mb[0], mb[1], mb[2]);
749 -               else
750 -                   printf("(%2d) %02x %02x %02x %02x ",idx,mb[0],mb[1],mb[2],mb[3]);
751 -               const char *b1 = (mb[0] & 0x01) ? "b1":"  ";//left
752 -               const char *b2 = (mb[0] & 0x02) ? "b2":"  ";//right
753 -               const char *b3 = (mb[0] & 0x04) ? "b3":"  ";//mid
754  
755 -               if ( overflow )
756 -                   printf( "Overflow%d %s %s %s  (%4d,%4d)\n", overflow,
757 -                           b1, b2, b3, mousePos.x(), mousePos.y() );
758 -               else
759 -                   printf( "%s %s %s (%+3d,%+3d)  (%4d,%4d)\n",
760 -                           b1, b2, b3, dx, dy, mousePos.x(), mousePos.y() );
761 -#endif
762 -               break;
763 -           }
764 -           case Microsoft:
765 -               if ( (mb[0] & 0x20) )
766 -                   bstate |= Qt::LeftButton;
767 -               if ( (mb[0] & 0x10) )
768 -                   bstate |= Qt::RightButton;
769 -
770 -               dx=(signed char)(((mb[0] & 0x03) << 6) | (mb[1] & 0x3f));
771 -               dy=-(signed char)(((mb[0] & 0x0c) << 4) | (mb[2] & 0x3f));
772 -               sendEvent=true;
773 -
774 -               break;
775 -           case BusMouse:
776 -               if ( !(mb[0] & 0x04) )
777 -                   bstate |= Qt::LeftButton;
778 -               if ( !(mb[0] & 0x01) )
779 -                   bstate |= Qt::RightButton;
780 -
781 -               dx=(signed char)mb[1];
782 -               dy=(signed char)mb[2];
783 -               sendEvent=true;
784 -               break;
785 -
786 -           default:
787 -               qWarning( "Unknown mouse protocol in QWSMouseHandlerPrivate" );
788 -               break;
789 -       }
790 -       if (sendEvent) {
791 -           if ( QABS(dx) > accel_limit || QABS(dy) > accel_limit ) {
792 -               dx *= accel;
793 -               dy *= accel;
794 -           }
795 -           tdx += dx;
796 -           tdy += dy;
797 -           if ( bstate != obstate ) {
798 -               mousePos += QPoint(tdx,-tdy);
799 -               limitToScreen( mousePos );
800 -               emit mouseChanged(mousePos,bstate);
801 -               sendEvent = FALSE;
802 -               tdx = 0;
803 -               tdy = 0;
804 -               obstate = bstate;
805 -           }
806 -       }
807 -       idx += mouseData[mouseProtocol].bytesPerPacket;
808 -    }
809 -    if ( sendEvent ) {
810 -       mousePos += QPoint(tdx,-tdy);
811 -       limitToScreen( mousePos );
812 -       emit mouseChanged(mousePos,bstate);
813 -    }
814 -
815 -    int surplus = mouseIdx - idx;
816 -    for ( int i = 0; i < surplus; i++ )
817 -       mouseBuf[i] = mouseBuf[idx+i];
818 -    mouseIdx = surplus;
819 -}
820 -#endif
821 -
822 -
823 -QWSMouseHandlerPrivate::QWSMouseHandlerPrivate( MouseProtocol protocol,
824 -                                         QString mouseDev )
825 -{
826 -#ifndef QT_NO_QWS_MOUSE_PC
827 -    mouseProtocol = protocol;
828 -
829 -    if ( mouseDev.isEmpty() )
830 -       mouseDev = "/dev/mouse";
831 -    obstate = -1;
832 -    mouseFD = -1;
833 -    mouseFD = open( mouseDev.local8Bit().data(), O_RDWR | O_NDELAY);
834 -    if ( mouseFD < 0 ) {
835 -       mouseFD = open( mouseDev.local8Bit().data(), O_RDONLY | O_NDELAY);
836 -       if ( mouseFD < 0 )
837 -           qDebug( "Cannot open %s (%s)", mouseDev.ascii(),
838 -                   strerror(errno));
839 -    } else {
840 -       // Clear pending input
841 -       tcflush(mouseFD,TCIFLUSH);
842 -
843 -       bool ps2 = false;
844 -
845 -       switch (mouseProtocol) {
846 -           case MouseMan:
847 -               ps2 = true;
848 -               write(mouseFD,"",1);
849 -               usleep(50000);
850 -               write(mouseFD,"@EeI!",5);
851 -               break;
852 -
853 -           case IntelliMouse: {
854 -//                 ps2 = true;
855 -                   const unsigned char init1[] = { 243, 200, 243, 100, 243, 80 };
856 -                   const unsigned char init2[] = { 246, 230, 244, 243, 100, 232, 3 };
857 -                   write(mouseFD,init1,sizeof(init1));
858 -                   usleep(50000);
859 -                   write(mouseFD,init2,sizeof(init2));
860 -               }
861 -               break;
862 -
863 -           case Microsoft:
864 -               struct termios tty;
865 -
866 -               tcgetattr(mouseFD, &tty);
867 -
868 -               tty.c_iflag = IGNBRK | IGNPAR;
869 -               tty.c_oflag = 0;
870 -               tty.c_lflag = 0;
871 -#if !defined(_OS_FREEBSD_) && !defined(_OS_SOLARIS_)
872 -               tty.c_line = 0;
873 -#endif // _OS_FREEBSD_
874 -               tty.c_cc[VTIME] = 0;
875 -               tty.c_cc[VMIN] = 1;
876 -               tty.c_cflag = B1200 | CS7 | CREAD | CLOCAL | HUPCL;
877 -               tcsetattr(mouseFD, TCSAFLUSH, &tty); /* set parameters */
878 -               break;
879 -
880 -           case BusMouse:
881 -               usleep(50000);
882 -               break;
883 -
884 -           default:
885 -               qDebug("Unknown mouse protocol");
886 -               exit(1);
887 -       }
888 -
889 -       if (ps2) {
890 -           char buf[] = { 246, 244 };
891 -           write(mouseFD,buf,1);
892 -           write(mouseFD,buf+1,1);
893 -       }
894 -
895 -       usleep(50000);
896 -       tcflush(mouseFD,TCIFLUSH);          // ### doesn't seem to work.
897 -       usleep(50000);
898 -       tcflush(mouseFD,TCIFLUSH);          // ### doesn't seem to work.
899 -
900 -       char buf[100];                          // busmouse driver will not read if bufsize < 3,  YYD
901 -       while (read(mouseFD, buf, 100) > 0) { }  // eat unwanted replies
902 -
903 -       mouseIdx = 0;
904 -
905 -       QSocketNotifier *mouseNotifier;
906 -       mouseNotifier = new QSocketNotifier( mouseFD, QSocketNotifier::Read, this );
907 -       connect(mouseNotifier, SIGNAL(activated(int)),this, SLOT(readMouseData()));
908 -    }
909 -#else
910 -    Q_UNUSED(protocol);
911 -    Q_UNUSED(mouseDev);
912 -#endif
913 -}
914 -
915 -QWSMouseHandlerPrivate::~QWSMouseHandlerPrivate()
916 -{
917 -#ifndef QT_NO_QWS_MOUSE_PC
918 -    if (mouseFD >= 0) {
919 -       tcflush(mouseFD,TCIFLUSH);          // yyd.
920 -       close(mouseFD);
921 -    }
922 -#endif
923 -}
924 -
925 -/*
926 - *
927 - */
928  
929  QCalibratedMouseHandler::QCalibratedMouseHandler()
930      : samples(5), currSample(0), numSamples(0)
931 @@ -1030,7 +180,8 @@
932      if ( file.open( IO_WriteOnly ) ) {
933         QTextStream t( &file );
934         t << a << " " << b << " " << c << " ";
935 -       t << d << " " << e << " " << f << " " << s;
936 +       t << d << " " << e << " " << f << " " << s << endl;
937 +       file.close();
938      } else
939  #endif
940      {
941 @@ -1046,6 +197,7 @@
942      if ( file.open( IO_ReadOnly ) ) {
943         QTextStream t( &file );
944         t >> a >> b >> c >> d >> e >> f >> s;
945 +       file.close();
946      } else
947  #endif
948      {
949 @@ -1073,12 +225,24 @@
950      writeCalibration();
951  }
952  
953 +void QCalibratedMouseHandler::setCalibration(int aa, int bb, int cc, int dd, int ee, int ff, int ss)
954 +{
955 +    a = aa;
956 +    b = bb;
957 +    c = cc;
958 +    d = dd;
959 +    e = ee;
960 +    f = ff;
961 +    s = ss;
962 +}
963 +
964  QPoint QCalibratedMouseHandler::transform( const QPoint &p )
965  {
966      QPoint tp;
967  
968      tp.setX( (a * p.x() + b * p.y() + c) / s );
969      tp.setY( (d * p.x() + e * p.y() + f) / s );
970 +//qDebug("QCalibratedMouseHandler::transform(%d,%d) -> %d,%d)", p.x(), p.y(), tp.x(), tp.y() );
971  
972      return tp;
973  }
974 @@ -1143,814 +307,192 @@
975      return sent;
976  }
977  
978 -/*
979 - * Handler for /dev/tpanel Linux kernel driver
980 - */
981  
982 -class QVrTPanelHandlerPrivate : public QCalibratedMouseHandler {
983 -    Q_OBJECT
984 -public:
985 -    QVrTPanelHandlerPrivate(MouseProtocol, QString dev);
986 -    ~QVrTPanelHandlerPrivate();
987  
988 -private:
989 -    int mouseFD;
990 -    MouseProtocol mouseProtocol;
991 -private slots:
992 -    void sendRelease();
993 -    void readMouseData();
994 -private:
995 -    static const int mouseBufSize = 1280;
996 -    QTimer *rtimer;
997 -    int mouseIdx;
998 -    uchar mouseBuf[mouseBufSize];
999 -};
1000  
1001 -#ifndef QT_QWS_CASSIOPEIA
1002 -QVrTPanelHandlerPrivate::QVrTPanelHandlerPrivate( MouseProtocol, QString ) :
1003 -    QCalibratedMouseHandler()
1004 -{
1005 -}
1006 -#else
1007 -QVrTPanelHandlerPrivate::QVrTPanelHandlerPrivate( MouseProtocol, QString dev ) :
1008 -    QCalibratedMouseHandler()
1009 -{
1010 -    if ( dev.isEmpty() )
1011 -       dev = "/dev/tpanel";
1012 -
1013 -    if ((mouseFD = open( dev, O_RDONLY)) < 0) {
1014 -        qFatal( "Cannot open %s (%s)", dev.latin1(), strerror(errno));
1015 -    } else {
1016 -        sleep(1);
1017 -    }
1018 -
1019 -    struct scanparam s;
1020 -    s.interval = 20000;
1021 -    s.settletime = 480;
1022 -    if ( ioctl(mouseFD, TPSETSCANPARM, &s) < 0
1023 -      || fcntl(mouseFD, F_SETFL, O_NONBLOCK) < 0 )
1024 -       qWarning("Error initializing touch panel.");
1025 -
1026 -    QSocketNotifier *mouseNotifier;
1027 -    mouseNotifier = new QSocketNotifier( mouseFD, QSocketNotifier::Read,
1028 -                                        this );
1029 -    connect(mouseNotifier, SIGNAL(activated(int)),this, SLOT(readMouseData()));
1030 -
1031 -    rtimer = new QTimer( this );
1032 -    connect( rtimer, SIGNAL(timeout()), this, SLOT(sendRelease()));
1033 -    mouseIdx = 0;
1034 -    setFilterSize( 3 );
1035 -
1036 -    printf("\033[?25l"); fflush(stdout); // VT100 cursor off
1037 -}
1038 -#endif
1039 -
1040 -QVrTPanelHandlerPrivate::~QVrTPanelHandlerPrivate()
1041 -{
1042 -    if (mouseFD >= 0)
1043 -       close(mouseFD);
1044 -}
1045 -
1046 -void QVrTPanelHandlerPrivate::sendRelease()
1047 -{
1048 -    sendFiltered( mousePos, 0 );
1049 -}
1050  
1051 -void QVrTPanelHandlerPrivate::readMouseData()
1052 -{
1053 -#ifdef QT_QWS_CASSIOPEIA
1054 -    if(!qt_screen)
1055 -       return;
1056 -    static bool pressed = FALSE;
1057 -
1058 -    int n;
1059 -    do {
1060 -       n = read(mouseFD, mouseBuf+mouseIdx, mouseBufSize-mouseIdx );
1061 -       if ( n > 0 )
1062 -           mouseIdx += n;
1063 -    } while ( n > 0 && mouseIdx < mouseBufSize );
1064 -
1065 -    int idx = 0;
1066 -    while ( mouseIdx-idx >= (int)sizeof( short ) * 6 ) {
1067 -       uchar *mb = mouseBuf+idx;
1068 -       ushort *data = (ushort *) mb;
1069 -       if ( data[0] & 0x8000 ) {
1070 -           if ( data[5] > 750 ) {
1071 -               QPoint t(data[3]-data[4],data[2]-data[1]);
1072 -               if ( sendFiltered( t, Qt::LeftButton ) )
1073 -                   pressed = TRUE;
1074 -               if ( pressed )
1075 -                   rtimer->start( 200, TRUE ); // release unreliable
1076 -           }
1077 -       } else if ( pressed ) {
1078 -           rtimer->start( 50, TRUE );
1079 -           pressed = FALSE;
1080 -       }
1081 -       idx += sizeof( ushort ) * 6;
1082 -    }
1083 +struct input_event {
1084 +        struct timeval time;
1085 +        unsigned short type;
1086 +        unsigned short code;
1087 +        unsigned int value;
1088 +};
1089  
1090 -    int surplus = mouseIdx - idx;
1091 -    for ( int i = 0; i < surplus; i++ )
1092 -       mouseBuf[i] = mouseBuf[idx+i];
1093 -    mouseIdx = surplus;
1094  
1095 -#endif
1096 -}
1097 +#define EV_ABS                  0x03
1098 +#define ABS_X                   0x00
1099 +#define ABS_Y                   0x01
1100 +#define ABS_PRESSURE            0x18
1101  
1102  
1103 -class QTPanelHandlerPrivate : public QCalibratedMouseHandler
1104 +class QInputEventHandler : public QCalibratedMouseHandler
1105  {
1106       Q_OBJECT
1107  public:
1108 -    QTPanelHandlerPrivate(MouseProtocol, QString dev);
1109 -    ~QTPanelHandlerPrivate();
1110 +    QInputEventHandler(MouseProtocol, QString dev);
1111 +    ~QInputEventHandler();
1112 +
1113 +    virtual void calibrate( QWSPointerCalibrationData * );
1114 +    virtual void setCalibration(int aa, int bb, int cc, int dd, int ee, int ff, int ss);
1115  
1116  private:
1117 -    static const int mouseBufSize = 2048;
1118 +    void init();
1119 +    void fini();
1120 +
1121      int mouseFD;
1122 -    QPoint oldmouse;
1123 -    QPoint oldTotalMousePos;
1124 -    bool waspressed;
1125 -    QPointArray samples;
1126 -    unsigned int currSample;
1127 -    unsigned int lastSample;
1128 -    unsigned int numSamples;
1129 -    int skipCount;
1130 -    int mouseIdx;
1131 -    uchar mouseBuf[mouseBufSize];
1132 +    struct input_event sample;
1133 +    int myX, myY, myP, oldX, oldY, oldP;
1134 +    int xtable[QT_QWS_TP_TABLE_SIZE];
1135 +    int ytable[QT_QWS_TP_TABLE_SIZE];
1136 +    int ptr;
1137  
1138  private slots:
1139      void readMouseData();
1140  };
1141  
1142  
1143 -QTPanelHandlerPrivate::QTPanelHandlerPrivate( MouseProtocol, QString dev )
1144 -    : samples(QT_QWS_TP_SAMPLE_SIZE), currSample(0), lastSample(0),
1145 -    numSamples(0), skipCount(0)
1146 -{
1147 -    Q_UNUSED(dev);
1148 -#if defined(QT_QWS_IPAQ) || defined(QT_QWS_SL5XXX) || defined(QT_QWS_K2) || defined(QT_QWS_SLC700)
1149 -#if defined(QT_QWS_IPAQ)
1150 -# ifdef QT_QWS_IPAQ_RAW
1151 -    if ((mouseFD = open( "/dev/h3600_tsraw", O_RDONLY | O_NDELAY)) < 0) {
1152 -# else
1153 -    if ((mouseFD = open( "/dev/h3600_ts", O_RDONLY | O_NDELAY)) < 0) {
1154 -# endif
1155 -        qWarning( "Cannot open /dev/h3600_ts (%s)", strerror(errno));
1156 -       return;
1157 -    }
1158 -#elif defined(QT_QWS_SL5XXX) || defined(QT_QWS_K2) || defined(QT_QWS_SLC700)
1159 -//# ifdef QT_QWS_SL5XXX_TSRAW
1160 -# if 0
1161 -    if ((mouseFD = open( "/dev/tsraw", O_RDONLY | O_NDELAY)) < 0) {
1162 -        qWarning( "Cannot open /dev/tsraw (%s)", strerror(errno));
1163 -       return;
1164 -    }
1165 -# else
1166 -    if ((mouseFD = open( "/dev/ts", O_RDONLY | O_NDELAY)) < 0) {
1167 -        qWarning( "Cannot open /dev/ts (%s)", strerror(errno));
1168 -        return;
1169 -     }
1170 -# endif
1171 -#elif defined(QT_QWS_SIMPAD )
1172 -    if ((mouseFD = open( "/dev/touchscreen/ucb1x00", O_RDONLY | O_NONBLOCK )) < 0) {
1173 -         qWarning( "Cannot open /dev/touchscreen/ucb1x00 (%s)", strerror(errno));
1174 -         return;
1175 -    }
1176 -#endif
1177 -
1178 -    QSocketNotifier *mouseNotifier;
1179 -    mouseNotifier = new QSocketNotifier( mouseFD, QSocketNotifier::Read,
1180 -                                        this );
1181 -    connect(mouseNotifier, SIGNAL(activated(int)),this, SLOT(readMouseData()));
1182 -    waspressed=FALSE;
1183 -    mouseIdx = 0;
1184 -#endif
1185 -}
1186 -
1187 -QTPanelHandlerPrivate::~QTPanelHandlerPrivate()
1188 +QInputEventHandler::QInputEventHandler( MouseProtocol, QString )
1189 +       : myP(-1)
1190  {
1191 -#if defined(QT_QWS_IPAQ) || defined(QT_QWS_SL5XXX) || defined(QT_QWS_K2) || defined(QT_QWS_SLC700) || defined(QT_QWS_SIMPAD)
1192 -    if (mouseFD >= 0)
1193 -       close(mouseFD);
1194 -#endif
1195 +    init();
1196  }
1197  
1198 -void QTPanelHandlerPrivate::readMouseData()
1199 +QInputEventHandler::~QInputEventHandler()
1200  {
1201 -#if defined(QT_QWS_IPAQ) || defined(QT_QWS_SL5XXX) || defined(QT_QWS_K2) || defined(QT_QWS_SLC700) || defined(QT_QWS_SIMPAD)
1202 -    if(!qt_screen)
1203 -       return;
1204 -
1205 -    int n;
1206 -    do {
1207 -       n = read(mouseFD, mouseBuf+mouseIdx, mouseBufSize-mouseIdx );
1208 -       if ( n > 0 )
1209 -           mouseIdx += n;
1210 -    } while ( n > 0 && mouseIdx < mouseBufSize );
1211 -
1212 -    TS_EVENT *data;
1213 -    int idx = 0;
1214 -
1215 -    // perhaps we shouldn't be reading EVERY SAMPLE.
1216 -    while ( mouseIdx-idx >= (int)sizeof( TS_EVENT ) ) {
1217 -       uchar *mb = mouseBuf+idx;
1218 -       data = (TS_EVENT *) mb;
1219 -       if(data->pressure >= QT_QWS_TP_PRESSURE_THRESHOLD) {
1220 -#if defined(QT_QWS_SL5XXX) || defined(QT_QWS_SLC700)
1221 -           samples[currSample] = QPoint( 1000 - data->x, data->y );
1222 -#else
1223 -           samples[currSample] = QPoint( data->x, data->y );
1224 -#endif
1225 -
1226 -           numSamples++;
1227 -           if ( numSamples >= QT_QWS_TP_MINIMUM_SAMPLES ) {
1228 -               int sampleCount = QMIN(numSamples + 1,samples.count());
1229 -
1230 -               // average the rest
1231 -               mousePos = QPoint( 0, 0 );
1232 -               QPoint totalMousePos = oldTotalMousePos;
1233 -               totalMousePos += samples[currSample];
1234 -               if(numSamples >= samples.count())
1235 -                   totalMousePos -= samples[lastSample];
1236 -
1237 -               mousePos = totalMousePos / (sampleCount - 1);
1238 -
1239 -# if defined(QT_QWS_IPAQ_RAW) || defined(QT_QWS_SL5XXX_RAW)
1240 -               mousePos = transform( mousePos );
1241 -# endif
1242 -               if(!waspressed)
1243 -                   oldmouse = mousePos;
1244 -               QPoint dp = mousePos - oldmouse;
1245 -               int dxSqr = dp.x() * dp.x();
1246 -               int dySqr = dp.y() * dp.y();
1247 -               if ( dxSqr + dySqr < (QT_QWS_TP_MOVE_LIMIT * QT_QWS_TP_MOVE_LIMIT) ) {
1248 -                   if ( waspressed ) {
1249 -                       if ( (dxSqr + dySqr > (QT_QWS_TP_JITTER_LIMIT * QT_QWS_TP_JITTER_LIMIT) ) || skipCount > 2) {
1250 -                           emit mouseChanged(mousePos,Qt::LeftButton);
1251 -                           oldmouse = mousePos;
1252 -                           skipCount = 0;
1253 -                       } else {
1254 -                           skipCount++;
1255 -                       }
1256 -                   } else {
1257 -                       emit mouseChanged(mousePos,Qt::LeftButton);
1258 -                       oldmouse=mousePos;
1259 -                       waspressed=true;
1260 -                   }
1261 -
1262 -                   // save recuring information
1263 -                   currSample++;
1264 -                   if (numSamples >= samples.count())
1265 -                       lastSample++;
1266 -                   oldTotalMousePos = totalMousePos;
1267 -               } else {
1268 -                   numSamples--; // don't use this sample, it was bad.
1269 -               }
1270 -           } else {
1271 -               // build up the average
1272 -               oldTotalMousePos += samples[currSample];
1273 -               currSample++;
1274 -           }
1275 -           if ( currSample >= samples.count() )
1276 -               currSample = 0;
1277 -           if ( lastSample >= samples.count() )
1278 -               lastSample = 0;
1279 -       } else {
1280 -           currSample = 0;
1281 -           lastSample = 0;
1282 -           numSamples = 0;
1283 -           skipCount = 0;
1284 -           oldTotalMousePos = QPoint(0,0);
1285 -           if ( waspressed ) {
1286 -               emit mouseChanged(oldmouse,0);
1287 -               oldmouse = QPoint( -100, -100 );
1288 -               waspressed=false;
1289 -           }
1290 -       }
1291 -       idx += sizeof( TS_EVENT );
1292 -    }
1293 +    fini();
1294  
1295 -    int surplus = mouseIdx - idx;
1296 -    for ( int i = 0; i < surplus; i++ )
1297 -       mouseBuf[i] = mouseBuf[idx+i];
1298 -    mouseIdx = surplus;
1299 -#endif
1300  }
1301  
1302 -// YOPY touch panel support based on changes contributed by Ron Victorelli
1303 -// (victorrj at icubed.com) to Custom TP driver.
1304 -//
1305 -class QYopyTPanelHandlerPrivate : public QWSMouseHandler {
1306 -    Q_OBJECT
1307 -public:
1308 -    QYopyTPanelHandlerPrivate(MouseProtocol, QString dev);
1309 -    ~QYopyTPanelHandlerPrivate();
1310 -
1311 -private:
1312 -    int mouseFD;
1313 -    int prevstate;
1314 -private slots:
1315 -    void readMouseData();
1316 -
1317 -};
1318 -
1319 -QYopyTPanelHandlerPrivate::QYopyTPanelHandlerPrivate( MouseProtocol, QString )
1320 +void QInputEventHandler::setCalibration(int aa, int bb, int cc, int dd, int ee, int ff, int ss)
1321  {
1322 -#ifdef QT_QWS_YOPY
1323 -    if ((mouseFD = open( "/dev/ts", O_RDONLY)) < 0) {
1324 -        qWarning( "Cannot open /dev/ts (%s)", strerror(errno));
1325 -       return;
1326 -    } else {
1327 -        sleep(1);
1328 -    }
1329 -    prevstate=0;
1330 -    QSocketNotifier *mouseNotifier;
1331 -    mouseNotifier = new QSocketNotifier( mouseFD, QSocketNotifier::Read,
1332 -                                        this );
1333 -    connect(mouseNotifier, SIGNAL(activated(int)),this, SLOT(readMouseData()));
1334 -#endif
1335 -}
1336 +    QCalibratedMouseHandler::setCalibration(aa, bb, cc, dd, ee, ff, ss);
1337  
1338 -QYopyTPanelHandlerPrivate::~QYopyTPanelHandlerPrivate()
1339 -{
1340 -    if (mouseFD >= 0)
1341 -       close(mouseFD);
1342 +    writeCalibration();
1343 +    fini();
1344 +    init();
1345  }
1346  
1347 -#define YOPY_XPOS(d) (d[1]&0x3FF)
1348 -#define YOPY_YPOS(d) (d[2]&0x3FF)
1349 -#define YOPY_PRES(d) (d[0]&0xFF)
1350 -#define YOPY_STAT(d) (d[3]&0x01 )
1351 -
1352 -struct YopyTPdata {
1353 -
1354 -  unsigned char status;
1355 -  unsigned short xpos;
1356 -  unsigned short ypos;
1357 -
1358 -};
1359 -
1360 -void QYopyTPanelHandlerPrivate::readMouseData()
1361 +void QInputEventHandler::calibrate( QWSPointerCalibrationData *cd )
1362  {
1363 -#ifdef QT_QWS_YOPY
1364 -    if(!qt_screen)
1365 -       return;
1366 -    YopyTPdata data;
1367 -
1368 -    unsigned int yopDat[4];
1369 -
1370 -    int ret;
1371 -
1372 -    ret=read(mouseFD,&yopDat,sizeof(yopDat));
1373 +    QCalibratedMouseHandler::calibrate( cd );
1374  
1375 -    if(ret) {
1376 -        data.status= ( YOPY_PRES(yopDat) ) ? 1 : 0;
1377 -       data.xpos=YOPY_XPOS(yopDat);
1378 -       data.ypos=YOPY_YPOS(yopDat);
1379 -       QPoint q;
1380 -       q.setX(data.xpos);
1381 -       q.setY(data.ypos);
1382 -       mousePos=q;
1383 -       if(data.status && !prevstate) {
1384 -          emit mouseChanged(mousePos,Qt::LeftButton);
1385 -        } else if( !data.status && prevstate ) {
1386 -         emit mouseChanged(mousePos,0);
1387 -        }
1388 -        prevstate = data.status;
1389 -    }
1390 -    if(ret<0) {
1391 -       qDebug("Error %s",strerror(errno));
1392 -    }
1393 -#endif
1394 +    // write calibration data, and close and reopen
1395 +    // tslib, in order to ensure it uses the new values
1396 +    writeCalibration();
1397 +    fini();
1398 +    init();
1399  }
1400  
1401 -class QCustomTPanelHandlerPrivate : public QWSMouseHandler {
1402 -    Q_OBJECT
1403 -public:
1404 -    QCustomTPanelHandlerPrivate(MouseProtocol, QString dev);
1405 -    ~QCustomTPanelHandlerPrivate();
1406 -
1407 -private:
1408 -    int mouseFD;
1409 -private slots:
1410 -    void readMouseData();
1411 -
1412 -};
1413 -
1414 -QCustomTPanelHandlerPrivate::QCustomTPanelHandlerPrivate( MouseProtocol, QString )
1415 +void QInputEventHandler::init()
1416  {
1417 -#ifdef QWS_CUSTOMTOUCHPANEL
1418 -    if ((mouseFD = open( "/dev/ts", O_RDONLY)) < 0) {
1419 -        qWarning( "Cannot open /dev/ts (%s)", strerror(errno));
1420 +    if ((mouseFD = open( "/dev/input/event1", O_RDONLY)) < 0) {
1421 +        qWarning( "Cannot open /dev/input/event1 (%s)", strerror(errno));
1422         return;
1423 -    } else {
1424 -        sleep(1);
1425      }
1426  
1427      QSocketNotifier *mouseNotifier;
1428 -    mouseNotifier = new QSocketNotifier( mouseFD, QSocketNotifier::Read,
1429 -                                        this );
1430 +    mouseNotifier = new QSocketNotifier( mouseFD, QSocketNotifier::Read, this );
1431 +    setFilterSize(2);
1432      connect(mouseNotifier, SIGNAL(activated(int)),this, SLOT(readMouseData()));
1433 -#endif
1434  }
1435  
1436 -QCustomTPanelHandlerPrivate::~QCustomTPanelHandlerPrivate()
1437 +void QInputEventHandler::fini()
1438  {
1439      if (mouseFD >= 0)
1440         close(mouseFD);
1441  }
1442  
1443 -struct CustomTPdata {
1444 -
1445 -  unsigned char status;
1446 -  unsigned short xpos;
1447 -  unsigned short ypos;
1448 -
1449 -};
1450 -
1451 -void QCustomTPanelHandlerPrivate::readMouseData()
1452 +void QInputEventHandler::readMouseData()
1453  {
1454 -#ifdef QWS_CUSTOMTOUCHPANEL
1455 -    if(!qt_screen)
1456 -       return;
1457 -    CustomTPdata data;
1458 -
1459 -    unsigned char data2[5];
1460 -
1461 -    int ret;
1462 -
1463 -    ret=read(mouseFD,data2,5);
1464 +       if (!qt_screen)
1465 +               return;
1466  
1467 -    if(ret==5) {
1468 -       data.status=data2[0];
1469 -       data.xpos=(data2[1] << 8) | data2[2];
1470 -       data.ypos=(data2[3] << 8) | data2[4];
1471 -       QPoint q;
1472 -       q.setX(data.xpos);
1473 -       q.setY(data.ypos);
1474 -       mousePos=q;
1475 -       if(data.status & 0x40) {
1476 -          emit mouseChanged(mousePos,Qt::LeftButton);
1477 -       } else {
1478 -         emit mouseChanged(mousePos,0);
1479 +       unsigned int size = read(mouseFD, &sample, sizeof(sample));
1480 +       if (size < sizeof(sample)) {
1481 +               qDebug("no input");
1482 +               return;
1483 +       }
1484 +       //qDebug("type,code,val: %d,%d,%d", sample.type, sample.code, sample.value);
1485 +       if (sample.type == EV_ABS) {
1486 +               if (sample.code == ABS_Y) {
1487 +                       myY = sample.value;
1488 +                       return;
1489 +               } else
1490 +               if (sample.code == ABS_X) {
1491 +                       myX = sample.value;
1492 +                       return;
1493 +               } else
1494 +               if (sample.code == ABS_PRESSURE) {
1495 +                       myP = sample.value;
1496 +               }
1497         }
1498 -    }
1499 -    if(ret<0) {
1500 -       qDebug("Error %s",strerror(errno));
1501 -    }
1502 -#endif
1503 -}
1504 -
1505 -/*
1506 - * Virtual framebuffer mouse driver
1507 - */
1508 -
1509 -#ifndef QT_NO_QWS_VFB
1510 -#include "qvfbhdr.h"
1511 -extern int qws_display_id;
1512 -#endif
1513 -
1514 -class QVFbMouseHandlerPrivate : public QWSMouseHandler {
1515 -    Q_OBJECT
1516 -public:
1517 -    QVFbMouseHandlerPrivate(MouseProtocol, QString dev);
1518 -    ~QVFbMouseHandlerPrivate();
1519 -
1520 -#ifndef QT_NO_QWS_VFB
1521 -    bool isOpen() const { return mouseFD > 0; }
1522 -
1523 -private:
1524 -    static const int mouseBufSize = 128;
1525 -    int mouseFD;
1526 -    int mouseIdx;
1527 -    uchar mouseBuf[mouseBufSize];
1528 -#endif
1529 -
1530 -private slots:
1531 -    void readMouseData();
1532 -};
1533 -
1534 -QVFbMouseHandlerPrivate::QVFbMouseHandlerPrivate( MouseProtocol, QString mouseDev )
1535 -{
1536 -#ifndef QT_NO_QWS_VFB
1537 -    mouseFD = -1;
1538 -    if ( mouseDev.isEmpty() )
1539 -       mouseDev = QString(QT_VFB_MOUSE_PIPE).arg(qws_display_id);
1540 -
1541 -    if ((mouseFD = open( mouseDev.local8Bit().data(), O_RDWR | O_NDELAY)) < 0) {
1542 -       qDebug( "Cannot open %s (%s)", mouseDev.ascii(),
1543 -               strerror(errno));
1544 -    } else {
1545 -       // Clear pending input
1546 -       char buf[2];
1547 -       while (read(mouseFD, buf, 1) > 0) { }
1548 -
1549 -       mouseIdx = 0;
1550 -
1551 -       QSocketNotifier *mouseNotifier;
1552 -       mouseNotifier = new QSocketNotifier( mouseFD, QSocketNotifier::Read, this );
1553 -       connect(mouseNotifier, SIGNAL(activated(int)),this, SLOT(readMouseData()));
1554 -    }
1555 -#endif
1556 -}
1557 -
1558 -QVFbMouseHandlerPrivate::~QVFbMouseHandlerPrivate()
1559 -{
1560 -#ifndef QT_NO_QWS_VFB
1561 -    if (mouseFD >= 0)
1562 -       close(mouseFD);
1563 -#endif
1564 -}
1565 -
1566 -void QVFbMouseHandlerPrivate::readMouseData()
1567 -{
1568 -#ifndef QT_NO_QWS_VFB
1569 -    int n;
1570 -    do {
1571 -       n = read(mouseFD, mouseBuf+mouseIdx, mouseBufSize-mouseIdx );
1572 -       if ( n > 0 )
1573 -           mouseIdx += n;
1574 -    } while ( n > 0 );
1575 -
1576 -    int idx = 0;
1577 -    while ( mouseIdx-idx >= int(sizeof( QPoint ) + sizeof( int )) ) {
1578 -       uchar *mb = mouseBuf+idx;
1579 -       QPoint *p = (QPoint *) mb;
1580 -       mb += sizeof( QPoint );
1581 -       int *bstate = (int *)mb;
1582 -       mousePos = *p;
1583 -       limitToScreen( mousePos );
1584 -       emit mouseChanged(mousePos, *bstate);
1585 -       idx += sizeof( QPoint ) + sizeof( int );
1586 -    }
1587 -
1588 -    int surplus = mouseIdx - idx;
1589 -    for ( int i = 0; i < surplus; i++ )
1590 -       mouseBuf[i] = mouseBuf[idx+i];
1591 -    mouseIdx = surplus;
1592 -#endif
1593 -}
1594 -
1595 -/*
1596 -  mouse handler for tslib
1597 -  see http://cvs.arm.linux.org.uk/
1598 - */
1599 -/*
1600 -
1601 - Copyright (C) 2003, 2004, 2005 Texas Instruments, Inc.
1602 - Copyright (C)       2004, 2005 Holger Hans Peter Freyther
1603 - All rights reserved.
1604 -
1605 - Redistribution and use in source and binary forms, with or without
1606 - modification, are permitted provided that the following conditions are met:
1607 -
1608 -   Redistributions of source code must retain the above copyright notice,
1609 -   this list of conditions and the following disclaimer.
1610 -
1611 -   Redistributions in binary form must reproduce the above copyright
1612 -   notice, this list of conditions and the following disclaimer in the
1613 -   documentation and/or other materials provided with the distribution.
1614 -
1615 -   Neither the name Texas Instruments, Inc nor the names of its
1616 -   contributors may be used to endorse or promote products derived
1617 -   from this software without specific prior written permission.
1618 -
1619 - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1620 - "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1621 - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
1622 - FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
1623 - COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
1624 - INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
1625 - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
1626 - SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1627 - HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
1628 - STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
1629 - IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
1630 - POSSIBILITY OF SUCH DAMAGE.
1631 -
1632 -*/
1633 -class QTSLibHandlerPrivate : public QCalibratedMouseHandler
1634 -{
1635 -    Q_OBJECT
1636 -public:
1637 -    QTSLibHandlerPrivate();
1638 -   ~QTSLibHandlerPrivate();
1639 -
1640 -    virtual void clearCalibration();
1641 -    virtual void calibrate( QWSPointerCalibrationData * );
1642 -    static int sortByX( const void*, const void* );
1643 -    static int sortByY( const void*, const void* );
1644 -
1645 -private:
1646 -    bool m_raw : 1;
1647 -    QSocketNotifier *m_notify;
1648 -
1649 -#ifdef QT_QWS_TSLIB
1650 -    struct tsdev *m_ts;
1651 -#endif
1652 -    void openTs();
1653 -    void closeTs();
1654 -    void interpolateSample();
1655 -
1656 -private slots:
1657 -    void readMouseData();
1658 -
1659 -};
1660 -
1661 -QTSLibHandlerPrivate::QTSLibHandlerPrivate()
1662 -    : m_raw(false), m_notify(0 )
1663 -{
1664 -   openTs();
1665 -}
1666 -
1667 -QTSLibHandlerPrivate::~QTSLibHandlerPrivate()
1668 -{
1669 -    closeTs();
1670 -}
1671 -
1672 -void QTSLibHandlerPrivate::openTs()
1673 -{
1674 -#ifdef QT_QWS_TSLIB
1675 -   char *tsdevice;
1676 -   if((tsdevice = getenv("TSLIB_TSDEVICE")) != NULL) {
1677 -      m_ts = ts_open( tsdevice, 1 ); //1 = nonblocking, 0 = blocking mode
1678 -   } else {
1679 -      m_ts = ts_open( "/dev/ts", 1 );
1680 -   }
1681 -
1682 -   if (!m_ts) {
1683 -      qWarning( "Cannot open touchscreen (%s)", strerror( errno));
1684 -      return;
1685 -   }
1686 -
1687 -   if (ts_config( m_ts)) {
1688 -      qWarning( "Cannot configure touchscreen (%s)", strerror( errno));
1689 -      return;
1690 -   }
1691 -   m_notify = new QSocketNotifier( ts_fd(m_ts), QSocketNotifier::Read, this );
1692 -   connect( m_notify, SIGNAL(activated(int)),this, SLOT(readMouseData()));
1693 -#endif
1694 -}
1695 -
1696 -void QTSLibHandlerPrivate::closeTs()
1697 -{
1698 -#ifdef QT_QWS_TSLIB
1699 -    if (m_ts)
1700 -        ts_close(m_ts);
1701 -    m_ts = 0;
1702 -#endif
1703 -
1704 -    delete m_notify;
1705 -    m_notify = 0;
1706 -    m_raw = false;
1707 -}
1708 -
1709 -void QTSLibHandlerPrivate::clearCalibration()
1710 -{
1711 -    m_raw = true;
1712 -}
1713 -
1714 -void QTSLibHandlerPrivate::calibrate( QWSPointerCalibrationData * cd)
1715 -{
1716 -    QPoint dev_tl = cd->devPoints[ QWSPointerCalibrationData::TopLeft ];
1717 -    QPoint dev_br = cd->devPoints[ QWSPointerCalibrationData::BottomRight ];
1718 -    QPoint screen_tl = cd->screenPoints[ QWSPointerCalibrationData::TopLeft ];
1719 -    QPoint screen_br = cd->screenPoints[ QWSPointerCalibrationData::BottomRight ];
1720 -    int a, b, c, d, e, f, s;
1721 -
1722 -    s = 1 << 16;
1723  
1724 -    a = s * (screen_tl.x() - screen_br.x() ) / (dev_tl.x() - dev_br.x());
1725 -    b = 0;
1726 -    c = s * screen_tl.x() - a * dev_tl.x();
1727 +       // up->up
1728 +       if (oldP==0 && myP==0) {
1729 +               //qDebug("uu %d,%d,%d", myX,myY,myP);
1730 +               return;
1731 +       }
1732  
1733 -    d = 0;
1734 -    e = s * (screen_tl.y() - screen_br.y() ) / (dev_tl.y() - dev_br.y());
1735 -    f = s * screen_tl.y() - e * dev_tl.y();
1736 +       // up->down
1737 +       if (oldP==0 && myP>QT_QWS_TP_PRESSURE_DOWN_THRESHOLD) {
1738 +               //qDebug("ud %d,%d,%d", myX,myY,myP);
1739  
1740 -    QString calFile = "/etc/pointercal";
1741 -#ifndef QT_NO_TEXTSTREAM
1742 -    QFile file( calFile );
1743 -    if ( file.open( IO_WriteOnly ) ) {
1744 -        QTextStream t( &file );
1745 -        t << a << " " << b << " " << c << " ";
1746 -        t << d << " " << e << " " << f << " " << s;
1747 -       file.flush(); closeTs();
1748 -       openTs();
1749 -    } else
1750 -#endif
1751 -    {
1752 -        qDebug( "Could not save calibration: %s", calFile.latin1() );
1753 -    }
1754 -}
1755 +               xtable[0] = myX;
1756 +               ytable[0] = myY;
1757 +               ptr = 1;
1758 +               oldX = myX;
1759 +               oldY = myY;
1760 +               oldP = myP;
1761 +               return;
1762 +       }
1763  
1764 -void QTSLibHandlerPrivate::readMouseData()
1765 -{
1766 -#ifdef QT_QWS_TSLIB
1767 -    if(!qt_screen)
1768 -        return;
1769 +       // down->down
1770 +       if (oldP>QT_QWS_TP_PRESSURE_DOWN_THRESHOLD  && myP>QT_QWS_TP_PRESSURE_UP_THRESHOLD) {
1771 +               //qDebug("dd %d,%d,%d (%d,%d)", myX,myY,myP,  oldX,oldY);
1772  
1773 -    /*
1774 -     * After clear Calibration
1775 -     * we're in raw mode and do some easy median
1776 -     * search.
1777 -     */
1778 -    if ( m_raw )
1779 -        return interpolateSample();
1780 +               int dxSqr = myX-oldX; dxSqr *= dxSqr;
1781 +               int dySqr = myY-oldY; dySqr *= dySqr;
1782 +               oldX = myX;
1783 +               oldY = myY;
1784 +               if (dxSqr+dySqr > QT_QWS_TP_MOVE_MAX*QT_QWS_TP_MOVE_MAX) {
1785 +                       //qWarning("distance too wide %d", dxSqr+dySqr);
1786 +                       return;
1787 +               }
1788  
1789 -    static struct ts_sample sample;
1790 -    static int ret;
1791 +               if (ptr < QT_QWS_TP_TABLE_SIZE) {
1792 +                       xtable[ptr]   = myX;
1793 +                       ytable[ptr++] = myY;
1794 +               }
1795  
1796 -    /*
1797 -     * Ok. We need to see if we can read more than one event
1798 -     * We do this not to lose an update.
1799 -     */
1800 -    while ( true ) {
1801 -        if ((ret = ts_read(m_ts, &sample, 1)) != 1 )
1802 -            return;
1803 +               if (ptr == QT_QWS_TP_TABLE_SIZE) {
1804 +                       int i;
1805 +                       int mx = 0;
1806 +                       int my = 0;
1807 +                       for (i=0; i<QT_QWS_TP_TABLE_SIZE; i++) {
1808 +                               mx += xtable[i];
1809 +                               my += ytable[i];
1810 +                               if (i>0) {
1811 +                                       xtable[i-1] = xtable[i];
1812 +                                       ytable[i-1] = ytable[i];
1813 +                               }
1814 +                       }
1815 +                       ptr--;
1816 +                       mousePos = transform(QPoint(mx/QT_QWS_TP_TABLE_SIZE, my/QT_QWS_TP_TABLE_SIZE));
1817  
1818 +                       emit mouseChanged(mousePos, Qt::LeftButton);
1819 +               }
1820 +               return;
1821 +       }
1822  
1823 -        QPoint pos( sample.x, sample.y );
1824 -        mouseChanged( pos, sample.pressure != 0 ? 1 : 0 );
1825 -    }
1826 -#endif
1827 +       // down->up
1828 +       //qDebug("du %d,%d,%d", myX,myY,myP);
1829 +       emit mouseChanged(mousePos, 0);
1830 +       oldP = 0;
1831  }
1832  
1833 -/*
1834 - * Lets take all down events and then sort them
1835 - * and take the event in the middle.
1836 - *
1837 - * inspired by testutils.c
1838 - */
1839 -void QTSLibHandlerPrivate::interpolateSample() {
1840 -#ifdef QT_QWS_TSLIB
1841 -#define TSLIB_MAX_SAMPLES 25
1842 -    static struct ts_sample samples[TSLIB_MAX_SAMPLES];
1843 -    int index = 0;
1844 -    int read_samples = 0;
1845 -    int ret;
1846 -
1847 -    do {
1848 -        /* do not access negative arrays */
1849 -        if ( index < 0 )
1850 -            index = 0;
1851 -           
1852 -        /* we're opened non-blocking */
1853 -        if((ret= ts_read_raw(m_ts, &samples[index], 1 ) ) !=  1 )
1854 -            /* no event yet, so try again */
1855 -            if (ret==-1 )
1856 -                continue;
1857 -       
1858 -       read_samples++;
1859 -       index = (index+1)%TSLIB_MAX_SAMPLES;
1860 -    }while (samples[index == 0 ? (TSLIB_MAX_SAMPLES-1) : index-1].pressure != 0);
1861 -
1862 -    /*
1863 -     * If we've wrapped around each sample is used otherwise
1864 -     * we will use the index
1865 -     */
1866 -    index = read_samples >= TSLIB_MAX_SAMPLES ?
1867 -            (TSLIB_MAX_SAMPLES-1 ) : index;
1868 -    int x, y;
1869 -
1870 -    /*
1871 -     * now let us use the median value
1872 -     * even index does not have an item in the middle
1873 -     * so let us take the average of n/2 and (n/2)-1 as the middle
1874 -     */
1875 -    int m = index/2;
1876 -    ::qsort(samples, index, sizeof(ts_sample), QTSLibHandlerPrivate::sortByX);
1877 -    x = (index % 2 ) ? samples[m].x :
1878 -        ( samples[m-1].x + samples[m].x )/2;
1879 -
1880 -    ::qsort(samples, index, sizeof(ts_sample), QTSLibHandlerPrivate::sortByY);
1881 -    y = (index % 2 ) ? samples[m].y :
1882 -        ( samples[m-1].y + samples[m].y )/2;
1883  
1884 -    emit mouseChanged( QPoint(x, y), 1 );
1885 -    emit mouseChanged( QPoint(0, 0), 0 );
1886 -#endif
1887 -}
1888  
1889 -int QTSLibHandlerPrivate::sortByX( const void* one, const void* two) {
1890 -#ifdef QT_QWS_TSLIB
1891 -    return reinterpret_cast<const struct ts_sample*>(one)->x -
1892 -        reinterpret_cast<const struct ts_sample*>(two)->x;
1893 -#else
1894 -    return 0;
1895 -#endif
1896 -}
1897  
1898 -int QTSLibHandlerPrivate::sortByY( const void* one, const void* two) {
1899 -#ifdef QT_QWS_TSLIB
1900 -    return reinterpret_cast<const struct ts_sample*>(one)->y -
1901 -        reinterpret_cast<const struct ts_sample*>(two)->y;
1902 -#else
1903 -    return 0;
1904 -#endif
1905 -}
1906 -//////
1907  
1908  /*
1909   * return a QWSMouseHandler that supports /a spec.
1910 @@ -1977,7 +519,7 @@
1911  
1912      if ( mouseProto == "USB" && mouseDev.isEmpty() )
1913         mouseDev = "/dev/input/mice";
1914 -
1915 +    
1916      MouseProtocol mouseProtocol = Unknown;
1917  
1918      int idx = 0;
1919 @@ -1988,50 +530,7 @@
1920         idx++;
1921      }
1922  
1923 -
1924 -    QWSMouseHandler *handler = 0;
1925 -
1926 -    switch ( mouseProtocol ) {
1927 -#ifndef QT_NO_QWS_MOUSE_AUTO
1928 -       case Auto:
1929 -           handler = new QAutoMouseHandler();
1930 -           break;
1931 -#endif
1932 -
1933 -#ifndef QT_NO_QWS_MOUSE_PC
1934 -       case MouseMan:
1935 -       case IntelliMouse:
1936 -       case Microsoft:
1937 -       case BusMouse:
1938 -           handler = new QWSMouseHandlerPrivate( mouseProtocol, mouseDev );
1939 -           break;
1940 -#endif
1941 -
1942 -#ifndef QT_NO_QWS_VFB
1943 -       case QVFBMouse:
1944 -           handler = new QVFbMouseHandlerPrivate( mouseProtocol, mouseDev );
1945 -           break;
1946 -#endif
1947 -
1948 -       case TPanel:
1949 -#if defined(QWS_CUSTOMTOUCHPANEL)
1950 -           handler = new QCustomTPanelHandlerPrivate(mouseProtocol,mouseDev);
1951 -#elif defined(QT_QWS_TSLIB)
1952 -           handler = new QTSLibHandlerPrivate();
1953 -#elif defined(QT_QWS_YOPY)
1954 -           handler = new QYopyTPanelHandlerPrivate(mouseProtocol,mouseDev);
1955 -#elif defined(QT_QWS_IPAQ) || defined(QT_QWS_SL5XXX) || defined(QT_QWS_K2) || defined(QT_QWS_SLC700) || defined(QT_QWS_SIMPAD)
1956 -           handler = new QTPanelHandlerPrivate(mouseProtocol,mouseDev);
1957 -#elif defined(QT_QWS_CASSIOPEIA)
1958 -           handler = new QVrTPanelHandlerPrivate( mouseProtocol, mouseDev );
1959 -#endif
1960 -           break;
1961 -
1962 -       default:
1963 -           qDebug( "Mouse type %s unsupported", spec.latin1() );
1964 -    }
1965 -
1966 -    return handler;
1967 +    return new QInputEventHandler( mouseProtocol, mouseDev );
1968  }
1969  
1970  #include "qwsmouse_qws.moc"
1971 --- qt-2.3.10/src/kernel/qwsmouse_qws.h~ramses-touchscreen
1972 +++ qt-2.3.10/src/kernel/qwsmouse_qws.h
1973 @@ -1,5 +1,5 @@
1974  /****************************************************************************
1975 -** $Id: qt/src/kernel/qwsmouse_qws.h   2.3.10   edited 2005-01-24 $
1976 +** $Id: qt/src/kernel/qwsmouse_qws.h   2.3.7   edited 2001-10-03 $
1977  **
1978  ** Definition of Qt/FB central server classes
1979  **
1980 @@ -70,6 +70,7 @@
1981      virtual void clearCalibration();
1982      virtual void calibrate( QWSPointerCalibrationData * );
1983      virtual void getCalibration( QWSPointerCalibrationData * );
1984 +    virtual void setCalibration(int aa, int bb, int cc, int dd, int ee, int ff, int ss);
1985  
1986  protected:
1987      void readCalibration();