[Interest] gesture on qt4.8.3 not sensitive

Steve (YiLiang) Zhou szhou at telecomsys.com
Thu Sep 25 08:38:45 CEST 2014


Dear all,

Qt4.8.3 not support multitouch naturally  ,so we add some codes to
support it.  The guesture example can work and recognize the guestures
,but it's not sensitive and sometimes it can't recognize them.

About the modified codes ,see bellow, and about the touchpoint's center
algorithm ,I don't know whether it's ok.

If you have some advices or you met this before, please help me!

 

bool QApplicationPrivate::readRX71MultiTouchEvents(int deviceNumber)

{

    RX71TouchPointState &touchPointState =
allRX71TouchPoints[deviceNumber];

    QSocketNotifier *socketNotifier = touchPointState.socketNotifier;

    int fd = socketNotifier->socket();

 

    QTouchEvent::TouchPoint &touchPoint = touchPointState.touchPoint;

 

    bool down = touchPoint.state() != Qt::TouchPointReleased;

    if (down)

        touchPoint.setState(Qt::TouchPointStationary);

 

    bool changed = false;

    for (;;) {

        struct input_event inputEvent;

        int bytesRead = read(fd, &inputEvent, sizeof(inputEvent));

        if (bytesRead <= 0)

            break;

        if (bytesRead != sizeof(inputEvent)) {

            qWarning("Qt: INTERNAL ERROR: short read in
readRX71MultiTouchEvents()");

            return false;

        }

                                

        processMultiTouchEvent(&inputEvent);

....

 

 

bool QApplicationPrivate::processMultiTouchEvent(struct input_event
*eventData)

{

    bool ret = false;

    

    if(eventData->type == EV_ABS)

    {

        if(eventData->code == ABS_MT_SLOT)

        {

            mCurrentSlot = eventData->value;

            qDebug("ABS_MT_SLOT:%d\n", eventData->value);

        }

        if(eventData->code == ABS_MT_TOUCH_MAJOR)

        {

            mCurrContact.maj = eventData->value;

            if (eventData->value == 0) mCurrContact.state =
Qt::TouchPointReleased;

            if (mTypeB) mContacts[mCurrentSlot].maj = mCurrContact.maj;

            qDebug("ABS_MT_TOUCH_MAJOR:%d\n", mCurrContact.maj);

        }

        if(eventData->code == ABS_MT_TOUCH_MINOR)

        {

            qDebug("Code:ABS_MT_TOUCH_MINOR, value:%d\n",
eventData->value); 

        }

        if(eventData->code == ABS_MT_ORIENTATION)

        {

            qDebug("Code:ABS_MT_ORIENTATION, value:%d\n",
eventData->value);

        }

        if(eventData->code == ABS_MT_POSITION_X)

        {

            mCurrContact.x = qBound(hw_range_x_min, eventData->value,
hw_range_x_max);

            //mCurrContact.x = eventData->value;

            if (mTypeB) mContacts[mCurrentSlot].x = mCurrContact.x;

            qDebug("ABS_MT_POSITION_X:%d\n", mCurrContact.x);

       }

        if(eventData->code == ABS_MT_POSITION_Y)

        {

            mCurrContact.y = qBound(hw_range_y_min, eventData->value,
hw_range_y_max);

            //mCurrContact.y = eventData->value;

            if (mTypeB) mContacts[mCurrentSlot].y = mCurrContact.y;

            qDebug("ABS_MT_POSITION_Y:%d\n", mCurrContact.y);

        }

        if(eventData->code == ABS_MT_TRACKING_ID)

        {

            mCurrContact.trackingId = eventData->value;

            if (mTypeB) 

            {

                if (mCurrContact.trackingId == -1)

                    mContacts[mCurrentSlot].state =
Qt::TouchPointReleased;

                else

                {

                    mContacts[mCurrentSlot].trackingId =
mCurrContact.trackingId;

                    if(mLastEventType == ABS_MT_SLOT)

                    {

                        mContacts[mCurrentSlot].state =
Qt::TouchPointPressed;

                    }

                }

            }

            qDebug("ABS_MT_TRACKING_ID:%d\n", mCurrContact.trackingId);

        }

        if(eventData->code == ABS_TOOL_WIDTH)

        {

            qDebug("Code:BS_TOOL_WIDTH, value:%d\n", eventData->value);

        }

        if(eventData->code == ABS_VOLUME)

        {

            qDebug("Code:ABS_VOLUME, value:%d\n", eventData->value);

        }

        if(eventData->code == ABS_PRESSURE)

        {

            mCurrContact.pressure = qBound(hw_pressure_min,
eventData->value, hw_pressure_max);

            //mCurrContact.pressure = eventData->value;

            if (mTypeB) mContacts[mCurrentSlot].pressure =
mCurrContact.pressure;

            qDebug("ABS_PRESSURE:%d\n", mCurrContact.pressure);

        }

    }

    else if (eventData->type == EV_SYN && eventData->code ==
SYN_MT_REPORT && mLastEventType != EV_SYN) 

    {

        int key = mCurrContact.trackingId;

        if (key == -1) key = mContacts.count();

         

        mContacts.insert(key, mCurrContact);

        mCurrContact.trackingId = -1;

        mCurrContact.x = 0;

        mCurrContact.y = 0;

        mCurrContact.maj = -1;

        mCurrContact.pressure = 0;

        mCurrContact.state = Qt::TouchPointPressed;

        //mCurrContact.flags = 0;

    }

    else if (eventData->type == EV_SYN && eventData->code == SYN_REPORT)

    {

        mTouchPoints.clear();

        Qt::TouchPointStates combinedStates;

        QMutableHashIterator<int, struct Contact> it(mContacts);

        

        while (it.hasNext()) 

        {

            it.next();

            QTouchEvent::TouchPoint tp;

            struct Contact contact = it.value();

            tp.setId(contact.trackingId);

            //tp.flags = contact.flags;

            int key = mTypeB ? it.key() : contact.trackingId;

            if (mLastContacts.contains(key)) 

            {

                const Contact &prev(mLastContacts.value(key));

                if (contact.state == Qt::TouchPointReleased) 

                {

                    // Copy over the previous values for released
points, just in case.

                    contact.x = prev.x;

                    contact.y = prev.y;

                    contact.maj = prev.maj;

                } 

                else 

                {

                    contact.state = (prev.x == contact.x && prev.y ==
contact.y) ? Qt::TouchPointStationary : Qt::TouchPointMoved;

                  

                }

            }

            // Avoid reporting a contact in released state more than
once.

            if (contact.state == Qt::TouchPointReleased &&
!mLastContacts.contains(key)) 

            {

                it.remove();

                continue;

            }

            

            tp.setState(contact.state);

            combinedStates |= tp.state();

 

            QRectF screenRect;

            QRect screenGeometry =
QApplication::desktop()->screenGeometry();

            QPointF screenPos((contact.x - hw_range_x_min) /
qreal(hw_range_x_max - hw_range_x_min) * screenGeometry.width(),

                              (contact.y - hw_range_y_min) /
qreal(hw_range_y_max - hw_range_y_min) * screenGeometry.height());

            screenRect.setSize(QSizeF(0.0, 0.0));

            screenRect.moveCenter(screenPos);

            tp.setScreenRect(screenRect);

            tp.setNormalizedPos(QPointF(screenPos.x() /
screenGeometry.width(),

                                            screenPos.y() /
screenGeometry.height()));

            tp.setPressure(contact.pressure);

            mTouchPoints.append(tp);

            //qDebug("Add point\n");

            if (contact.state == Qt::TouchPointReleased)

                it.remove();

        }

        

        mLastContacts = mContacts;

        if (!mTypeB)

            mContacts.clear();

        if (!mTouchPoints.isEmpty() && combinedStates !=
Qt::TouchPointStationary)

        {

translateRawTouchEvent(0, QTouchEvent::TouchScreen, mTouchPoints);

            reportPoints();

            ret = true;

        }

    }

    else

    {

        qWarning("unknow type:%d\n", eventData->type);

    }

 

    mLastEventType = eventData->code;

    return ret;

}

 

 

Thanks and Best Regards

Steve Zhou

 


CONFIDENTIALITY NOTICE: The information contained in this message may be privileged and/or confidential. If you are not the intended recipient, or responsible for delivering this message to the intended recipient, any review, forwarding, dissemination, distribution or copying of this communication or any attachment(s) is strictly prohibited. If you have received this message in error, please notify the sender immediately, and delete it and all attachments from your computer and network.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20140925/4cb5bef1/attachment.html>


More information about the Interest mailing list