File indexing completed on 2024-05-12 05:35:47
0001 /* 0002 SPDX-FileCopyrightText: 2021 Aleix Pol Gonzalez <aleixpol@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "inputdevice.h" 0008 0009 #include <QDBusError> 0010 #include <QDBusInterface> 0011 #include <QList> 0012 0013 #include "logging.h" 0014 0015 template<typename T> 0016 bool InputDevice::Prop<T>::save() 0017 { 0018 if (!isSupported() || !m_value || m_prop.isConstant()) { 0019 qCDebug(LIBKWINDEVICES) << "skipping" << this << m_value.has_value() << isSupported() << m_prop.name(); 0020 return false; 0021 } 0022 0023 auto iface = m_device->m_iface.get(); 0024 const bool ret = m_prop.write(iface, *m_value); 0025 if (ret) { 0026 m_configValue = *m_value; 0027 } 0028 return ret; 0029 } 0030 0031 template<typename T> 0032 void InputDevice::Prop<T>::set(T newVal) 0033 { 0034 if (!m_value) { 0035 value(); 0036 } 0037 0038 Q_ASSERT(isSupported()); 0039 if (m_value != newVal) { 0040 m_value = newVal; 0041 if (m_changedSignalFunction) { 0042 (m_device->*m_changedSignalFunction)(); 0043 } 0044 } 0045 } 0046 0047 template<typename T> 0048 bool InputDevice::Prop<T>::changed() const 0049 { 0050 return m_value.has_value() && m_value.value() != m_configValue; 0051 } 0052 0053 InputDevice::InputDevice(const QString &dbusName, QObject *parent) 0054 : QObject(parent) 0055 { 0056 m_iface = std::make_unique<OrgKdeKWinInputDeviceInterface>(QStringLiteral("org.kde.KWin"), 0057 QStringLiteral("/org/kde/KWin/InputDevice/") + dbusName, 0058 QDBusConnection::sessionBus(), 0059 this); 0060 connect(this, &InputDevice::leftHandedChanged, this, &InputDevice::needsSaveChanged); 0061 connect(this, &InputDevice::orientationChanged, this, &InputDevice::needsSaveChanged); 0062 connect(this, &InputDevice::outputNameChanged, this, &InputDevice::needsSaveChanged); 0063 connect(this, &InputDevice::outputAreaChanged, this, &InputDevice::needsSaveChanged); 0064 connect(this, &InputDevice::enabledChanged, this, &InputDevice::needsSaveChanged); 0065 } 0066 0067 void InputDevice::save() 0068 { 0069 m_orientation.save(); 0070 m_outputName.save(); 0071 m_leftHanded.save(); 0072 m_outputArea.save(); 0073 m_enabled.save(); 0074 } 0075 0076 bool InputDevice::isSaveNeeded() const 0077 { 0078 return m_leftHanded.changed() || m_orientation.changed() || m_outputName.changed() || m_outputArea.changed() || m_enabled.changed();; 0079 } 0080 0081 void InputDevice::defaults() 0082 { 0083 m_leftHanded.resetFromDefaults(); 0084 m_orientation.resetFromDefaults(); 0085 m_outputName.resetFromDefaults(); 0086 m_outputArea.resetFromDefaults(); 0087 m_enabled.resetFromDefaults(); 0088 } 0089 0090 bool InputDevice::isDefaults() const 0091 { 0092 return m_leftHanded.isDefaults() && m_orientation.isDefaults() && m_outputName.isDefaults() && m_outputArea.isDefaults() && m_enabled.isDefaults(); 0093 } 0094 0095 void InputDevice::load() 0096 { 0097 m_orientation.resetFromSaved(); 0098 m_leftHanded.resetFromSaved(); 0099 m_outputName.resetFromSaved(); 0100 m_outputArea.resetFromSaved(); 0101 m_enabled.resetFromSaved(); 0102 } 0103 0104 void InputDevice::setOrientation(int ori) 0105 { 0106 m_orientation.set(ori); 0107 } 0108 0109 void InputDevice::setOutputName(const QString &outputName) 0110 { 0111 m_outputName.set(outputName); 0112 } 0113 0114 void InputDevice::setLeftHanded(bool set) 0115 { 0116 m_leftHanded.set(set); 0117 } 0118 0119 void InputDevice::setOutputArea(const QRectF &outputArea) 0120 { 0121 m_outputArea.set(outputArea); 0122 } 0123 0124 void InputDevice::setEnabled(bool enabled) 0125 { 0126 m_enabled.set(enabled); 0127 }