From 6ccbc890b60742e6fec9eb543291e1e9a22139d6 Mon Sep 17 00:00:00 2001 From: Andrey Borzenkov <arvidjaar@mail.ru> Date: Sat, 13 Feb 2010 22:11:16 +0300 Subject: [PATCH 5/5] Implement SmartMode as interface to ksyndaemon Reenable SmartMode again and make it call ksyndaemon to start and stop touchpad activity monitor. Currently zero error checking is done. It is not quite clear what we can do in case of error except logging it. --- kcmtouchpad.cpp | 51 +++++++++++++++++++++++++++++++++++++------------ kcmtouchpad.h | 4 ++- kcmtouchpadwidget.ui | 2 +- 3 files changed, 42 insertions(+), 15 deletions(-) diff --git a/kcmtouchpad.cpp b/kcmtouchpad.cpp index bb03321..f281366 100644 --- a/kcmtouchpad.cpp +++ b/kcmtouchpad.cpp @@ -49,7 +49,8 @@ K_PLUGIN_FACTORY(TouchpadConfigFactory, registerPlugin<TouchpadConfig>("touchpad K_EXPORT_PLUGIN(TouchpadConfigFactory("kcmtouchpad")) TouchpadConfig::TouchpadConfig(QWidget *parent, const QVariantList &) - : KCModule(TouchpadConfigFactory::componentData(), parent), setup_failed(false) + : KCModule(TouchpadConfigFactory::componentData(), parent), + setup_failed(false) { // Load translations KGlobal::locale()->insertCatalog("kcm_touchpad"); @@ -79,8 +80,8 @@ TouchpadConfig::TouchpadConfig(QWidget *parent, const QVariantList &) // "Touchpad Allow Moving" check box connect(ui->TouchpadOffWOMoveCB, SIGNAL(toggled(bool)), this, SLOT(touchpadAllowedMoving(bool))); - //connect(ui->SmartModeEnableCB, SIGNAL(toggled(bool)), this, SLOT(smartModeEnabled(bool))); - //connect(ui->SmartModeDelayS, SIGNAL(valueChanged(int)), this, SLOT(smartModeDelayChanged(int))); + connect(ui->SmartModeEnableCB, SIGNAL(toggled(bool)), this, SLOT(smartModeEnabled(bool))); + connect(ui->SmartModeDelayS, SIGNAL(valueChanged(int)), this, SLOT(smartModeDelayChanged(int))); // "Touch Sensitivity" slider connect(ui->SensitivityValueS, SIGNAL(valueChanged(int)), this, SLOT(sensitivityValueChanged(int))); @@ -199,8 +200,8 @@ void TouchpadConfig::load() ui->TouchpadOffWOMoveCB->setCheckState(config.readEntry("TouchpadOff", (int)*(char*)Touchpad::get_parameter("TouchpadOff")) == 2 ? Qt::Checked : Qt::Unchecked); } - //ui->SmartModeEnableCB->setCheckState(config.readEntry("SmartModeEnabled", false) ? Qt::Checked : Qt::Unchecked); - //ui->SmartModeDelayS->setValue(config.readEntry("SmartModeDelay", 1000)); + ui->SmartModeEnableCB->setCheckState(config.readEntry("SmartModeEnabled", false) ? Qt::Checked : Qt::Unchecked); + ui->SmartModeDelayS->setValue(config.readEntry("SmartModeDelay", 1000)); if (this->propertiesList.contains(SYNAPTICS_PROP_FINGER)) { ui->SensitivityValueS->setValue(config.readEntry("FingerLow", *(int*)Touchpad::get_parameter("FingerLow") / 10)); @@ -280,8 +281,8 @@ void TouchpadConfig::save() config.writeEntry("TouchpadOff", 0); } - //config.writeEntry("SmartModeEnabled", ui->SmartModeEnableCB->isChecked()); - //config.writeEntry("SmartModeDelay", ui->SmartModeDelayS->value()); + config.writeEntry("SmartModeEnabled", ui->SmartModeEnableCB->isChecked()); + config.writeEntry("SmartModeDelay", ui->SmartModeDelayS->value()); if (this->propertiesList.contains(SYNAPTICS_PROP_FINGER)) { config.writeEntry("FingerLow", ui->SensitivityValueS->value()); @@ -361,6 +362,30 @@ QString TouchpadConfig::quickHelp() const } /* + * Call ksyndaemon to start or stop touchpad activity monitoring. + * FIXME could do with some error handling + */ +void TouchpadConfig::setSmartMode(bool enable, unsigned interval) +{ + QDBusInterface interface("org.kde.ksyndaemon", + "/Syndaemon", + "org.kde.KSyndaemon", + QDBusConnection::sessionBus()); + + // FIXME currently subsecond resolution is not supported + interval /= 1000; + if (interval == 0) + interval = 1; + + if (enable) { + interface.call("setInterval", interval); + interface.call("startMonitoring"); + } else { + interface.call("stopMonitoring"); + } +} + +/* * This function applies sensitivity setting to driver. * It is a bit tricky because driver (hardware?) will refuse to apply * out of order values (i.e. you cannot set upper limit less than current @@ -401,7 +426,7 @@ bool TouchpadConfig::apply() Touchpad::set_parameter("TouchpadOff", 0); } - //Touchpad::setSmartModeEnabled(ui->SmartModeEnableCB->isChecked(), ui->SmartModeDelayS->value() / 1000); + setSmartMode(ui->SmartModeEnableCB->isChecked(), ui->SmartModeDelayS->value()); if (this->propertiesList.contains(SYNAPTICS_PROP_FINGER)) { applySensitivity(ui->SensitivityValueS->value()); @@ -476,16 +501,16 @@ void TouchpadConfig::touchpadAllowedMoving(bool toggle) { } void TouchpadConfig::smartModeEnabled(bool toggle) { - /*emit this->changed(); + emit this->changed(); ui->SmartModeDelayL->setEnabled(toggle); ui->SmartModeDelayS->setEnabled(toggle); ui->SmartModeDelayValueL->setEnabled(toggle); - ui->SmartModeDelayMilisecondsL->setEnabled(toggle);*/ + ui->SmartModeDelayMilisecondsL->setEnabled(toggle); } void TouchpadConfig::smartModeDelayChanged(int value) { -// emit this->changed(); + emit this->changed(); } void TouchpadConfig::sensitivityValueChanged(int value) { @@ -656,8 +681,8 @@ void TouchpadConfig::init_touchpad() Touchpad::set_parameter("TouchpadOff", config.readEntry("TouchpadOff", -1)); } -// Touchpad::setSmartModeEnabled(config.readEntry("SmartModeEnabled", Touchpad::isSmartModeEnabled()), -// config.readEntry("SmartModeDelay", 1000)); + setSmartMode(config.readEntry("SmartModeEnabled", false), + config.readEntry("SmartModeDelay", 1000)); if (propertiesList.contains(SYNAPTICS_PROP_FINGER)) { int value; diff --git a/kcmtouchpad.h b/kcmtouchpad.h index 86f4acf..5415e4c 100644 --- a/kcmtouchpad.h +++ b/kcmtouchpad.h @@ -28,6 +28,7 @@ #include <QSet> #include <QString> +#include <QtDBus/QtDBus> #include <KApplication> #include <KCModule> @@ -55,6 +56,7 @@ public: private: bool apply(); static void applySensitivity(int val); + static void setSmartMode(bool enable, unsigned interval); void enableProperties(); Ui_TouchpadConfigWidget* ui; @@ -65,7 +67,7 @@ private: QSet<const char*> propertiesList; bool setup_failed; - + private slots: void changed(); diff --git a/kcmtouchpadwidget.ui b/kcmtouchpadwidget.ui index 3eabd99..b8e7799 100644 --- a/kcmtouchpadwidget.ui +++ b/kcmtouchpadwidget.ui @@ -152,7 +152,7 @@ <item row="0" column="0" colspan="3"> <widget class="QCheckBox" name="SmartModeEnableCB"> <property name="enabled"> - <bool>false</bool> + <bool>true</bool> </property> <property name="text"> <string>Disable touchpad when typing</string> -- 1.6.6.2