#include <qtextstream.h>
#include <X11/Xutil.h>
#include <X11/extensions/XTest.h>
#include <X11/extensions/XInput.h>
#include <QDebug>

int getDeviceID()

{
    int n, i=0;
    QString devName;
    XDeviceInfo *devList, *curDev;

    Display *dpy = XOpenDisplay(0); // Connecting to XServer
    devList = XListInputDevices(dpy, &n); // Getting Input Device list
    if (!devList) // Checking for more then 0 devices
    qDebug() << "No Input devices to List";

    while(i < n)
     {
            curDev = devList + i;
            std::string s = curDev->name;
            devName = QString::fromLocal8Bit(s.c_str());
            if (devName.contains("TouchPad", Qt::CaseInsensitive)) {
                qDebug() << "Device ID is " << curDev->id;
                return curDev->id;
            }
             i++;
     }
    return 0;
}
