Warning, file /plasma/wacomtablet/src/kded/procsystemadaptor.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 * This file is part of the KDE wacomtablet project. For copyright 0003 * information and license terms see the AUTHORS and COPYING files 0004 * in the top-level directory of this distribution. 0005 * 0006 * This program is free software; you can redistribute it and/or 0007 * modify it under the terms of the GNU General Public License as 0008 * published by the Free Software Foundation; either version 2 of 0009 * the License, or (at your option) any later version. 0010 * 0011 * This program is distributed in the hope that it will be useful, 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0014 * GNU General Public License for more details. 0015 * 0016 * You should have received a copy of the GNU General Public License 0017 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0018 */ 0019 0020 #include "procsystemadaptor.h" 0021 0022 #include "logging.h" 0023 #include "procsystemproperty.h" 0024 0025 #include <QProcess> 0026 0027 using namespace Wacom; 0028 0029 namespace Wacom 0030 { 0031 class ProcSystemAdaptorPrivate 0032 { 0033 public: 0034 QString deviceName; 0035 }; // CLASS 0036 } // NAMESPACE 0037 0038 ProcSystemAdaptor::ProcSystemAdaptor(const QString &deviceName) 0039 : PropertyAdaptor(nullptr) 0040 , d_ptr(new ProcSystemAdaptorPrivate) 0041 { 0042 Q_D(ProcSystemAdaptor); 0043 d->deviceName = deviceName; 0044 } 0045 0046 ProcSystemAdaptor::~ProcSystemAdaptor() 0047 { 0048 delete this->d_ptr; 0049 } 0050 0051 const QList<Property> ProcSystemAdaptor::getProperties() const 0052 { 0053 return ProcSystemProperty::ids(); 0054 } 0055 0056 const QString ProcSystemAdaptor::getProperty(const Property &property) const 0057 { 0058 Q_D(const ProcSystemAdaptor); 0059 0060 qCWarning(KDED) << QString::fromLatin1("Can not get unsupported property '%1' from device '%2' using proc system!").arg(property.key()).arg(d->deviceName); 0061 0062 return QString(); 0063 } 0064 0065 bool ProcSystemAdaptor::setProperty(const Property &property, const QString &value) 0066 { 0067 qCDebug(KDED) << QString::fromLatin1("Setting property '%1' to '%2'.").arg(property.key()).arg(value); 0068 0069 // https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-driver-wacom 0070 /* /sys/bus/hid/devices/<bus>:<vid>:<pid>.<n>/wacom_led/status0_luminance 0071 <obsoleted by the LED class API now exported by the driver> 0072 Writing to this file sets the status LED luminance (1..127) 0073 when the stylus does not touch the tablet surface, and no 0074 button is pressed on the stylus. This luminance level is 0075 normally lower than the level when a button is pressed. 0076 */ 0077 /* /sys/bus/hid/devices/<bus>:<vid>:<pid>.<n>/wacom_led/status1_luminance 0078 <obsoleted by the LED class API now exported by the driver> 0079 Writing to this file sets the status LED luminance (1..127) 0080 when the stylus touches the tablet surface, or any button is 0081 pressed on the stylus. 0082 */ 0083 // https://www.kernel.org/doc/Documentation/leds/leds-class.txt 0084 0085 QString cmd; 0086 if (property == Property::StatusLEDs) { 0087 int statusLed = value.toInt(); 0088 if (statusLed < 4 && statusLed >= 0) { 0089 cmd = QString::fromLatin1("bash -c \"echo %1 > /sys/bus/hid/devices/*/wacom_led/status_led0_select\"").arg(statusLed); 0090 } else if (statusLed < 8 && statusLed >= 4) { 0091 statusLed -= 4; 0092 cmd = QString::fromLatin1("bash -c \"echo %1 > /sys/bus/hid/devices/*/wacom_led/status_led1_select\"").arg(statusLed); 0093 } else { 0094 return false; 0095 } 0096 } else if (property == Property::StatusLEDsBrightness) { 0097 int statusLedBrightness = value.toInt(); 0098 if (statusLedBrightness < 128 && statusLedBrightness >= 0) { 0099 cmd = QString::fromLatin1("bash -c \"echo %1 > /sys/bus/hid/devices/*/wacom_led/status0_luminance\"").arg(statusLedBrightness); 0100 } else if (statusLedBrightness < 256 && statusLedBrightness >= 128) { 0101 statusLedBrightness -= 128; 0102 cmd = QString::fromLatin1("bash -c \"echo %1 > /sys/bus/hid/devices/*/wacom_led/status1_luminance\"").arg(statusLedBrightness); 0103 } else { 0104 return false; 0105 } 0106 } else { 0107 qCWarning(KDED) << "Unknown Property: " << property.key(); 0108 } 0109 0110 return QProcess::execute(cmd, {}) == 0; 0111 } 0112 0113 bool ProcSystemAdaptor::supportsProperty(const Property &property) const 0114 { 0115 return (ProcSystemProperty::map(property)); 0116 }