[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [kde-workspace] /: Remember if we were enabled or not on load
From: Albert Astals Cid <tsdgeos () terra ! es>
Date: 2012-11-03 15:54:40
Message-ID: 20121103155440.23BBFA6104 () git ! kde ! org
[Download RAW message or body]
Git commit 28c06c28b393b032267955514298a2abfe110235 by Albert Astals Cid.
Committed on 30/04/2012 at 22:21.
Pushed by nalvarez into branch 'master'.
Remember if we were enabled or not on load
M +2 -0 CMakeLists.txt
A +12 -0 ktouchpadenabler.kcfg
M +49 -17 ktouchpadenabler_daemon.cpp
A +5 -0 settings.kcfgc
http://commits.kde.org/kde-workspace/28c06c28b393b032267955514298a2abfe110235
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f73b5cc..472eec4 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -11,6 +11,8 @@ set(kded_ktouchpadenabler_SRCS
ktouchpadenabler_daemon.cpp
)
+kde4_add_kcfg_files(kded_ktouchpadenabler_SRCS settings.kcfgc )
+
kde4_add_plugin(kded_ktouchpadenabler
${kded_ktouchpadenabler_SRCS}
)
diff --git a/ktouchpadenabler.kcfg b/ktouchpadenabler.kcfg
new file mode 100644
index 0000000..dc69bfc
--- /dev/null
+++ b/ktouchpadenabler.kcfg
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
+ http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
+ <kcfgfile name="ktouchpadenablerrc"/>
+ <group name="general" >
+ <entry key="touchpadEnabled" type="Bool">
+ <default>true</default>
+ </entry>
+ </group>
+</kcfg>
diff --git a/ktouchpadenabler_daemon.cpp b/ktouchpadenabler_daemon.cpp
index 559cc83..af270f9 100644
--- a/ktouchpadenabler_daemon.cpp
+++ b/ktouchpadenabler_daemon.cpp
@@ -1,5 +1,5 @@
/***************************************************************************
- * Copyright (C) 2011 Albert Astals Cid <aacid@kde.org> *
+ * Copyright (C) 2011, 2012 Albert Astals Cid <aacid@kde.org> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
@@ -19,6 +19,8 @@
#include "ktouchpadenabler_daemon.h"
+#include "settings.h"
+
#include <KApplication>
#include <KDebug>
#include <KLocalizedString>
@@ -45,6 +47,9 @@ class TouchpadEnablerDaemonPrivate : public QWidget
enum TouchpadKey { ToggleKey = 0, OnKey, OffKey };
static const int nKeys = OffKey + 1;
+ bool getEnabled(bool *currentValue) const;
+ void setEnabled(bool enabled) const;
+
Display *m_display;
KeyCode m_keyCode[nKeys];
int m_deviceId;
@@ -106,6 +111,14 @@ TouchpadEnablerDaemonPrivate::TouchpadEnablerDaemonPrivate()
if (grabResult == BadAccess || grabResult == BadValue || \
grabResult == BadWindow) { kDebug() << "Could not grab ktouchpadenabler key index" \
<< i <<". You probably have some other program grabbig it, if you are sure you don't \
have any, please report a bug against ktouchpadenabler in http://bugs.kde.org"; \
m_keyCode[i] = 0; + } else {
+ bool currentlyEnabled;
+ if (getEnabled(¤tlyEnabled)) {
+ const bool newValue = \
ktouchpadenabler::Settings::self()->touchpadEnabled(); + \
if (newValue != currentlyEnabled) { + \
setEnabled(newValue); + }
+ }
}
} else {
kWarning() << "Could not match ktouchpadenabler key index" << i \
<< "to a Keycode. This should never happen. Please report a bug against \
ktouchpadenabler in http://bugs.kde.org"; @@ -134,26 +147,23 @@ bool \
TouchpadEnablerDaemonPrivate::x11Event(XEvent *event) if (event->type == KeyPress) {
for (int i = 0; i < nKeys; ++i) {
if (event->xkey.keycode == m_keyCode[i]) {
- unsigned char newValue;
-
- Atom realtype;
- int realformat;
- unsigned long nitems, bytes_after;
- unsigned char *currentValue;
- if ((XIGetProperty (m_display, m_deviceId, m_enabledProperty, 0, 1, \
False, XA_INTEGER, &realtype, &realformat, &nitems, &bytes_after, ¤tValue) == \
Success) && (realtype != None)) { + bool currentlyEnabled;
+ if (getEnabled(¤tlyEnabled)) {
+ bool newValue;
switch (i) {
- case ToggleKey: newValue = (*currentValue == 0) ? 1 : 0; \
break;
- case OnKey: newValue = 1; break;
- case OffKey: newValue = 0; break;
+ case ToggleKey: newValue = !currentlyEnabled; break;
+ case OnKey: newValue = true; break;
+ case OffKey: newValue = false; break;
}
- if (newValue != *currentValue) {
- XIChangeProperty (m_display, m_deviceId, m_enabledProperty, \
XA_INTEGER, 8, PropModeReplace, &newValue, 1);
- XFlush(m_display);
-
- KNotification *notification = \
KNotification::event(KNotification::Notification, i18n("Touchpad status"), newValue \
== 1 ? i18n("Touchpad enabled") : i18n("Touchpad disabled")); + if \
(newValue != currentlyEnabled) { + setEnabled(newValue);
+
+ KNotification *notification = \
KNotification::event(KNotification::Notification, i18n("Touchpad status"), newValue ? \
i18n("Touchpad enabled") : i18n("Touchpad disabled")); notification->sendEvent();
+
+ \
ktouchpadenabler::Settings::self()->setTouchpadEnabled(newValue); + \
ktouchpadenabler::Settings::self()->writeConfig(); }
- XFree (currentValue);
return true;
}
}
@@ -162,6 +172,28 @@ bool TouchpadEnablerDaemonPrivate::x11Event(XEvent *event)
return false;
}
+bool TouchpadEnablerDaemonPrivate::getEnabled(bool *enabled) const
+{
+ Atom realtype;
+ int realformat;
+ unsigned long nitems, bytes_after;
+ unsigned char *value;
+ if ((XIGetProperty(m_display, m_deviceId, m_enabledProperty, 0, 1, False, \
XA_INTEGER, &realtype, &realformat, &nitems, &bytes_after, &value) == Success) && \
(realtype != None)) { + *enabled = (*value == 1);
+ XFree(value);
+ return true;
+ } else {
+ return false;
+ }
+}
+
+void TouchpadEnablerDaemonPrivate::setEnabled(bool enabled) const
+{
+ unsigned char newValue = enabled ? 1 : 0;
+ XIChangeProperty(m_display, m_deviceId, m_enabledProperty, XA_INTEGER, 8, \
PropModeReplace, &newValue, 1); + XFlush(m_display);
+}
+
TouchpadEnablerDaemon::TouchpadEnablerDaemon(QObject *parent, const \
QList<QVariant>&) : KDEDModule(parent)
{
diff --git a/settings.kcfgc b/settings.kcfgc
new file mode 100644
index 0000000..9e49060
--- /dev/null
+++ b/settings.kcfgc
@@ -0,0 +1,5 @@
+ClassName=Settings
+Namespace=ktouchpadenabler
+File=ktouchpadenabler.kcfg
+Mutators=true
+Singleton=true
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic