From e51cefe13655e3eaadf49cbdefa4161efec1d748 Mon Sep 17 00:00:00 2001 From: Matt Scheirer Date: Fri, 24 Jul 2020 13:33:35 -0400 Subject: [PATCH] [libinput] Serialize QMatrix4x4 for KConfig --- src/backends/libinput/device.cpp | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/backends/libinput/device.cpp b/src/backends/libinput/device.cpp index ccf00e3d6a..038bcfedda 100644 --- a/src/backends/libinput/device.cpp +++ b/src/backends/libinput/device.cpp @@ -20,9 +20,11 @@ QDBusArgument &operator<<(QDBusArgument &argument, const QMatrix4x4 &matrix) { argument.beginArray(qMetaTypeId()); - for(quint8 row = 0; row < 4; ++row ) - for(quint8 col = 0; col < 4; ++col ) + for (quint8 row = 0; row < 4; ++row) { + for (quint8 col = 0; col < 4; ++col) { argument << matrix(row, col); + } + } argument.endArray(); return argument; } @@ -30,8 +32,8 @@ QDBusArgument &operator<<(QDBusArgument &argument, const QMatrix4x4 &matrix) const QDBusArgument &operator>>(const QDBusArgument &argument, QMatrix4x4 &matrix) { argument.beginArray(); - for(quint8 row = 0; row < 4; ++row ) { - for(quint8 col = 0; col < 4; ++col ) { + for (quint8 row = 0; row < 4; ++row) { + for (quint8 col = 0; col < 4; ++col) { double val; argument >> val; matrix(row, col) = val; @@ -413,8 +415,14 @@ void Device::loadConfiguration() if(it.value().qMatrix4x4Setter.setter != nullptr) { auto setter = it.value().qMatrix4x4Setter; - QMatrix4x4 def = setter.defaultValue ? (this->*(setter.defaultValue))() : QMatrix4x4(); - (this->*(setter.setter))(m_config.readEntry(key.constData(), QVariant(def)).value()); + QList list = m_config.readEntry(key.constData(), QList()); + QMatrix4x4 matrix; + if(list.size() == 16) { + matrix = QMatrix4x4(list.toVector().constData()); + } else if(setter.defaultValue) { + matrix = (this->*(setter.defaultValue))(); + } + (this->*(setter.setter))(matrix); } }; @@ -626,7 +634,13 @@ void Device::setCalibrationMatrix(QMatrix4x4 matrix) { } if(setOrientedCalibrationMatrix(m_device, matrix, m_orientation)) { - writeEntry(ConfigKey::Calibration, QVariant(matrix)); + QList list; + for (uchar row = 0; row < 4; ++row) { + for (uchar col = 0; col < 4; ++col) { + list << matrix(row,col); + } + } + writeEntry(ConfigKey::Calibration, list); m_calibrationMatrix = matrix; Q_EMIT calibrationMatrixChanged(); }