Kb::Kb(QObject *parent, const QString& path) : QThread(parent), devpath(path), cmdpath(path + "/cmd"), features("N/A"), firmware("N/A"), pollrate("N/A"), _currentProfile(0), _currentMode(0), _model(KeyMap::NO_MODEL), _layout(KeyMap::NO_LAYOUT), _hwProfile(0), prevProfile(0), prevMode(0), cmd(cmdpath), notifyNumber(1), _needsSave(false), hwLoading(true) { // Get the features, model, serial number, FW version (if available), and poll rate (if available) from /dev nodes QFile ftpath(path + "/features"), mpath(path + "/model"), spath(path + "/serial"), fwpath(path + "/fwversion"), ppath(path + "/pollrate"); if(ftpath.open(QIODevice::ReadOnly)){ features = ftpath.read(1000); features = features.trimmed(); ftpath.close(); // Read model from features (first word: vendor, second word: product) QStringList list = features.split(" "); if(list.length() < 2) return; _model = KeyMap::getModel(list[1]); if(_model == KeyMap::NO_MODEL) return; } else // Bail if features aren't readable return; if(mpath.open(QIODevice::ReadOnly)){ usbModel = mpath.read(100); usbModel = usbModel.remove("Corsair").remove("Gaming").remove("Keyboard").remove("Mouse").remove("Bootloader").trimmed(); mpath.close(); } if(usbModel == "") usbModel = "Keyboard"; if(spath.open(QIODevice::ReadOnly)){ usbSerial = spath.read(100); usbSerial = usbSerial.trimmed().toUpper(); spath.close(); } if(usbSerial == "") usbSerial = "Unknown-" + usbModel; if(features.contains("fwversion") && fwpath.open(QIODevice::ReadOnly)){ firmware = fwpath.read(100); firmware = QString::number(firmware.trimmed().toInt() / 100., 'f', 2); fwpath.close(); } if(features.contains("pollrate") && ppath.open(QIODevice::ReadOnly)){ pollrate = ppath.read(100); pollrate = pollrate.trimmed(); ppath.close(); } hwModeCount = (_model == KeyMap::K95) ? 3 : 1; // Open cmd in non-blocking mode so that it doesn't lock up if nothing is reading // (e.g. if the daemon crashed and didn't clean up the node) int fd = open(cmdpath.toLatin1().constData(), O_WRONLY | O_NONBLOCK); if(!cmd.open(fd, QIODevice::WriteOnly, QFileDevice::AutoCloseHandle)) return; // Find an available notification node (if none is found, take notify1) for(int i = 1; i < 10; i++){ QString notify = QString(path + "/notify%1").arg(i); if(!QFile::exists(notify)){ notifyNumber = i; notifyPath = notify; break; } } cmd.write(QString("notifyon %1\n").arg(notifyNumber).toLatin1()); cmd.flush(); cmd.write(QString("fps %1\n").arg(_frameRate).toLatin1()); cmd.write(QString("active\n@%1 get :hwprofileid").arg(notifyNumber).toLatin1()); for(int i = 0; i < hwModeCount; i++){ cmd.write(QString(" mode %1 get :hwid").arg(i + 1).toLatin1()); if(isMouse()) cmd.write(" :hwdpi :hwdpisel :hwlift :hwsnap"); } cmd.write("\n"); cmd.flush(); emit infoUpdated(); activeDevices.insert(this); // Start a separate thread to read from the notification node start(); }
bool MouseInputSource::hasMouseCursor() const noexcept { return isMouse(); }
bool MouseInputSource::canDoUnboundedMovement() const noexcept { return isMouse(); }
bool MouseInputSource::hasMouseWheel() const { return isMouse(); }
bool MouseInputSource::canHover() const { return isMouse(); }
bool MouseInputSource::isTouch() const { return ! isMouse(); }