Logo Search packages:      
Sourcecode: kcm-tablet version File versions  Download package

bool DeviceHandler::findXInputDevice (  )  [private]

Checks xinput --list to find the names of the pad/stylus/eraser/cursor

Returns:
true if xinput found some devices false if no input device could be found

Definition at line 226 of file devicehandler.cpp.

References deviceName().

Referenced by detectTablet().

{
    Q_D(DeviceHandler);

    d->deviceList.clear();

    // read xinput --list
    QProcess xinput;
    xinput.start("xinput --list");
    xinput.waitForStarted();
    xinput.waitForFinished();


    //@TODO find better parsing rules
    QRegExp rxWacom("\"((.*wacom.*)|(.*waltop.*)|(stylus|pad|eraser|cursor|touch))\"", Qt::CaseInsensitive);
    // this is a rather bad hack to identify some devices that are a stylus/eraser and so on but named differently
    // got the xinput --list results that showed "Type is Wacom stylus" and so on in the line after the device name
    // this line does not show up in my xinput list ... thus this might only work for one person at all
    QRegExp rxTypeCheck("Type is Wacom (stylus|pad|eraser|cursor|touch)", Qt::CaseInsensitive);
    QRegExp rxTypeCheckLastName("\"(.*)\"", Qt::CaseInsensitive);
    QString curLine;
    QString lastLine;

    // parse xinput
    while (!xinput.atEnd()) {
        lastLine = curLine;
        curLine = xinput.readLine();

        int pos = rxWacom.indexIn(curLine);
        if (pos > -1) {
            QString deviceName = rxWacom.cap(1);

            //add device name to the list of known devices
            d->deviceList.append(deviceName);

            //figure out what device we just found and save it as reference

            if (deviceName.contains("pad")) {
                d->internalPadName = deviceName;
            } else if (deviceName.contains("eraser")) {
                d->internalEraserName = deviceName;
            } else if (deviceName.contains("cursor")) {
                d->internalCursorName = deviceName;
            } else if (deviceName.contains("touch")) {
                d->internalTouchName = deviceName;
            } else if (deviceName.contains("stylus")) {
                d->internalStylusName = deviceName;
            } else {
                d->internalStylusName = deviceName; //assume stylus if no information is given, this is how Kubuntu HAL config handles it (my stylus is called "Wacom Bamboo")
            }
        }
        // if we can't find the device name normally,check if the next line contains "Type is Wacom xxx"
        // this is more of a hack than a good solution ...
        else {
            int posAlternate = rxTypeCheck.indexIn(curLine);

            if (posAlternate > -1) {
                QString deviceType = rxTypeCheck.cap(1);

                // next line fits what we need, so lets get the name in the quotes from the line before
                int posAlternateName = rxTypeCheckLastName.indexIn(lastLine);

                if (posAlternateName > -1) {
                    QString deviceName = rxTypeCheckLastName.cap(1);

                    //add device name to the list of known devices
                    d->deviceList.append(deviceName);

                    //check what type we found (with Type is Wacom xxx) and save internal reference)
                    if (deviceType.contains("pad", Qt::CaseInsensitive)) {
                        d->internalPadName = deviceName;
                    } else if (deviceType.contains("eraser", Qt::CaseInsensitive)) {
                        d->internalEraserName = deviceName;
                    } else if (deviceType.contains("cursor", Qt::CaseInsensitive)) {
                        d->internalCursorName = deviceName;
                    } else if (deviceType.contains("touch",  Qt::CaseInsensitive)) {
                        d->internalTouchName = deviceName;
                    } else if (deviceType.contains("stylus", Qt::CaseInsensitive)) {
                        d->internalStylusName = deviceName;
                    }
                }
            }
        }
    }

    // Regexp could not find any device named stylus/pad/eraser/cursor/touch or with wacom in the name
    if (d->deviceList.isEmpty()) {
        return false;
    }

    // This happens because we deal with two different output results of xinput --list
    // happens that both fit ... really time to let solid handle this
    d->deviceList.removeDuplicates();

    // if we just have no pad name only a name for a stylus...copy that, this is how the touchpc devices seem to work
    if (d->internalPadName.isEmpty()) {
        d->internalPadName = d->internalStylusName;
    }

    // seems we found something useful
    return true;
}


Generated by  Doxygen 1.6.0   Back to index