Commit 2ac542b729b58bf44bbefdec31abcc45ef67e8b5
- Diff rendering mode:
- inline
- side by side
daemon/synaptiksdaemon.cpp
(95 / 14)
|   | |||
| 130 | 130 | "found.</warning>")); | |
| 131 | 131 | } | |
| 132 | 132 | } else { | |
| 133 | // setup global action | ||
| 134 | d->globalActions = new KActionCollection(this, d->applicationData); | ||
| 135 | KAction *touchpadOn = new KToggleAction( | ||
| 136 | i18nc("@action:button hidden action", "Touchpad on"), | ||
| 137 | d->globalActions); | ||
| 138 | d->globalActions->addAction("touchpadOn", touchpadOn); | ||
| 139 | touchpadOn->setGlobalShortcut( | ||
| 140 | KShortcut(i18nc("touchpadOn shortcut", "Ctrl+Alt+T"))); | ||
| 141 | this->connect(touchpadOn, SIGNAL(triggered(bool)), | ||
| 142 | SLOT(touchpadOnTriggered(bool))); | ||
| 143 | |||
| 133 | // create the touchpad manager | ||
| 144 | 134 | d->touchpadManager = new TouchpadManager(touchpad, monitor, this); | |
| 145 | 135 | this->connect(d->touchpadManager, | |
| 146 | 136 | SIGNAL(touchpadSwitched(bool, const QString&, | |
| … | … | ||
| 141 | 141 | SIGNAL(touchpadError(const QString&)), | |
| 142 | 142 | SLOT(notifyError(const QString&))); | |
| 143 | 143 | ||
| 144 | |||
| 145 | // dump settings from touchpad driver to configuration and write the | ||
| 146 | // settings to a file to make them available to the kcmodule | ||
| 147 | this->dumpTouchpadToConfiguration(); | ||
| 148 | d->config->setSharedConfig(KSharedConfig::openConfig( | ||
| 149 | "synaptiksrc-defaults")); | ||
| 150 | d->config->writeConfig(); | ||
| 151 | // update all defaults in the configuration scheme ... | ||
| 152 | foreach (KConfigSkeletonItem *item, d->config->items()) { | ||
| 153 | item->swapDefault(); | ||
| 154 | } | ||
| 155 | // ... and finally read the actual configuration | ||
| 156 | d->config->setSharedConfig( | ||
| 157 | KSharedConfig::openConfig("synaptiksrc")); | ||
| 158 | d->config->readConfig(); | ||
| 159 | |||
| 160 | // action to switch the touchpad with global shortcut | ||
| 161 | d->globalActions = new KActionCollection(this, d->applicationData); | ||
| 162 | KAction *touchpadOn = new KToggleAction( | ||
| 163 | i18nc("@action:button hidden action", "Touchpad on"), | ||
| 164 | d->globalActions); | ||
| 165 | d->globalActions->addAction("touchpadOn", touchpadOn); | ||
| 166 | touchpadOn->setGlobalShortcut( | ||
| 167 | KShortcut(i18nc("touchpadOn shortcut", "Ctrl+Alt+T"))); | ||
| 168 | this->connect(touchpadOn, SIGNAL(triggered(bool)), | ||
| 169 | SLOT(touchpadOnTriggered(bool))); | ||
| 170 | |||
| 144 | 171 | // initial touchpad state | |
| 145 | 172 | int state = d->config->touchpadStateAtStartup(); | |
| 146 | 173 | if (state != SynaptiksConfiguration::UnchangedState) { | |
| … | … | ||
| 176 | 176 | // and the rest of the configuration | |
| 177 | 177 | this->reparseConfiguration(); | |
| 178 | 178 | ||
| 179 | // register on session bus | ||
| 179 | 180 | QDBusConnection::sessionBus().registerObject("/Touchpad", touchpad); | |
| 180 | |||
| 181 | 181 | QDBusConnection::sessionBus().registerObject( | |
| 182 | 182 | "/TouchpadManager", d->touchpadManager, | |
| 183 | 183 | QDBusConnection::ExportScriptableContents); | |
| … | … | ||
| 263 | 263 | << "HorizontalTwoFingerScrolling" << "VerticalTwoFingerScrolling" | |
| 264 | 264 | << "HorizontalEdgeScrolling" << "VerticalEdgeScrolling" | |
| 265 | 265 | << "HorizontalScrollingDistance" << "VerticalScrollingDistance" | |
| 266 | << "CornerCoasting" | ||
| 266 | 267 | // tapping configuration | |
| 267 | 268 | << "FastTaps" << "TapAndDragGesture" << "LockedDrags"; | |
| 268 | 269 | foreach (const QString &name, names) { | |
| … | … | ||
| 277 | 277 | // ... and finally the more complicated stuff | |
| 278 | 278 | if (d->config->coasting()) { | |
| 279 | 279 | this->setTouchpadProperty( | |
| 280 | "cornerCoasting", d->config->cornerCoasting()); | ||
| 281 | this->setTouchpadProperty( | ||
| 282 | 280 | "coastingSpeed", d->config->coastingSpeed()); | |
| 283 | 281 | } else { | |
| 284 | 282 | // 0.0 for coasting speed disables coasting | |
| … | … | ||
| 301 | 301 | this->setTouchpadProperty("fingerButtons", buttons); | |
| 302 | 302 | } | |
| 303 | 303 | ||
| 304 | void SynaptiksDaemon::dumpTouchpadToConfiguration() { | ||
| 305 | Q_D(SynaptiksDaemon); | ||
| 306 | // First all items, that directly map to touchpad properties ... | ||
| 307 | QList<QString> names; | ||
| 308 | names | ||
| 309 | // general configuration | ||
| 310 | << "CircularTouchpad" | ||
| 311 | // motion configuration | ||
| 312 | << "MinimumSpeed" << "MaximumSpeed" << "AccelerationFactor" | ||
| 313 | << "EdgeMotionAlways" | ||
| 314 | // scrolling configuration | ||
| 315 | << "CircularScrolling" << "CircularScrollingTrigger" | ||
| 316 | << "HorizontalTwoFingerScrolling" << "VerticalTwoFingerScrolling" | ||
| 317 | << "HorizontalEdgeScrolling" << "VerticalEdgeScrolling" | ||
| 318 | << "HorizontalScrollingDistance" << "VerticalScrollingDistance" | ||
| 319 | << "CornerCoasting" << "CoastingSpeed" | ||
| 320 | // tapping configuration | ||
| 321 | << "FastTaps" << "TapAndDragGesture" << "LockedDrags"; | ||
| 322 | foreach (const QString &name, names) { | ||
| 323 | KConfigSkeletonItem *item = d->config->findItem(name); | ||
| 324 | Q_ASSERT(item); | ||
| 325 | QString property = name; | ||
| 326 | property[0] = property.at(0).toLower(); | ||
| 327 | QVariant value = this->touchpadProperty(property.toAscii()); | ||
| 328 | if (value.userType() == QMetaType::Float) { | ||
| 329 | value = round(value.toFloat()*100)/100.0; | ||
| 330 | kDebug() << "rounding" << name << "to" << value; | ||
| 331 | } | ||
| 332 | kDebug() << "setting" << name << "to" << value; | ||
| 333 | item->setProperty(value); | ||
| 334 | } | ||
| 335 | |||
| 336 | // ... and the more complicated stuff | ||
| 337 | float coastingSpeed = this->touchpadProperty("coastingSpeed").toFloat(); | ||
| 338 | d->config->setCoasting(coastingSpeed != 0.0); | ||
| 339 | // convert to degrees | ||
| 340 | float circScrollDistance = | ||
| 341 | this->touchpadProperty("circularScrollingDistance").toFloat(); | ||
| 342 | d->config->setCircularScrollingDistance( | ||
| 343 | round(circScrollDistance*180/M_PI)); | ||
| 344 | // lockedDragsTimeout scaled to seconds | ||
| 345 | int lockedDragsTimeout = | ||
| 346 | this->touchpadProperty("lockedDragsTimeout").toInt(); | ||
| 347 | d->config->setLockedDragsTimeout(lockedDragsTimeout / 1000.0); | ||
| 348 | // corner and finger buttons | ||
| 349 | QByteArray buttons; | ||
| 350 | buttons = this->touchpadProperty("cornerButtons").toByteArray(); | ||
| 351 | for (int i=0; i < 4; i++) { | ||
| 352 | d->config->setCornerButton(i, buttons.at(i)); | ||
| 353 | } | ||
| 354 | buttons = this->touchpadProperty("fingerButtons").toByteArray(); | ||
| 355 | for (int i=0; i < 3; i++) { | ||
| 356 | d->config->setFingerButton(i, buttons.at(i)); | ||
| 357 | } | ||
| 358 | } | ||
| 359 | |||
| 304 | 360 | bool SynaptiksDaemon::isTouchpadAvailable() const { | |
| 305 | 361 | Q_D(const SynaptiksDaemon); | |
| 306 | 362 | // if touchpad manager is a null pointer, no touchpad is available. | |
| … | … | ||
| 392 | 392 | d->touchpadManager->touchpad()->setProperty(name, value); | |
| 393 | 393 | } catch (const QXDeviceError &error) { | |
| 394 | 394 | this->notifyError(error.toString()); | |
| 395 | } | ||
| 396 | } | ||
| 397 | |||
| 398 | QVariant SynaptiksDaemon::touchpadProperty(const char *name) const { | ||
| 399 | Q_D(const SynaptiksDaemon); | ||
| 400 | try { | ||
| 401 | return d->touchpadManager->touchpad()->property(name); | ||
| 402 | } catch (const QXDeviceError &error) { | ||
| 403 | return QVariant(); | ||
| 395 | 404 | } | |
| 396 | 405 | } | |
| 397 | 406 |
daemon/synaptiksdaemon.h
(26 / 0)
|   | |||
| 149 | 149 | Q_DECLARE_PRIVATE(SynaptiksDaemon) | |
| 150 | 150 | ||
| 151 | 151 | /** | |
| 152 | * @brief Dump the touchpad state to the configuration object. | ||
| 153 | * | ||
| 154 | * This function reads all configurable properties from the | ||
| 155 | * touchpad, and writes them to the configuration. | ||
| 156 | * | ||
| 157 | * This is used to initialize the configuration with defaults from | ||
| 158 | * the touchpad driver. | ||
| 159 | */ | ||
| 160 | void dumpTouchpadToConfiguration(); | ||
| 161 | |||
| 162 | /** | ||
| 152 | 163 | * @brief Set the given touchpad @p property to the given @p value. | |
| 153 | 164 | * | |
| 154 | 165 | * This function does not propagate any exceptions from | |
| … | … | ||
| 171 | 171 | */ | |
| 172 | 172 | void setTouchpadProperty(const char *property, | |
| 173 | 173 | const QVariant &value); | |
| 174 | |||
| 175 | /** | ||
| 176 | * @brief Get the given touchpad @p property. | ||
| 177 | * | ||
| 178 | * This function does not propagate any exceptions from | ||
| 179 | * synaptiks::Touchpad, but catches and silently ignores them. In | ||
| 180 | * this case, an invalid QVariant is returned. | ||
| 181 | * | ||
| 182 | * Do @e always use this function, if you access touchpad properties | ||
| 183 | * from slots or DBus calls! | ||
| 184 | * | ||
| 185 | * @return the property value, or an invalid QVariant in case of | ||
| 186 | * exception | ||
| 187 | */ | ||
| 188 | QVariant touchpadProperty(const char *property) const; | ||
| 174 | 189 | ||
| 175 | 190 | SynaptiksDaemonPrivate *const d_ptr; | |
| 176 | 191 | }; |
kcmodule/synaptikskcm.cpp
(12 / 0)
|   | |||
| 94 | 94 | // daemon is running and has a touchpad, so load configuration and | |
| 95 | 95 | // setup user interface | |
| 96 | 96 | this->config = new SynaptiksConfiguration(); | |
| 97 | // read the defaults provided by the daemon ... | ||
| 98 | this->config->setSharedConfig( | ||
| 99 | KSharedConfig::openConfig("synaptiksrc-defaults")); | ||
| 100 | this->config->readConfig(); | ||
| 101 | // ... update all defaults in the configuration scheme ... | ||
| 102 | foreach (KConfigSkeletonItem *item, this->config->items()) { | ||
| 103 | item->swapDefault(); | ||
| 104 | } | ||
| 105 | // ... and finally read the actual configuration | ||
| 106 | this->config->setSharedConfig( | ||
| 107 | KSharedConfig::openConfig("synaptiksrc")); | ||
| 108 | this->config->readConfig(); | ||
| 97 | 109 | this->setupUi(); | |
| 98 | 110 | } | |
| 99 | 111 | } |
synaptiksconfiguration.kcfgc
(0 / 2)
|   | |||
| 5 | 5 | ClassName=SynaptiksConfiguration | |
| 6 | 6 | # generate mutator functions | |
| 7 | 7 | Mutators=true | |
| 8 | # use the enum as return and argument type (instead of int) | ||
| 9 | UseEnumTypes=true |

