mirror of
https://invent.kde.org/plasma/plasma-desktop.git
synced 2026-11-03 22:59:45 -09:00
kcms/libkwindevices: Fix serializeMatrix serializing in the wrong order
We were switching which order the columns/rows were in accidentally, this should be fixed in lock-step with KWin because the same code exists there. I copied over the simple test from KWin too to verify this actually works as expected now.
This commit is contained in:
parent
5725fc35b5
commit
30edb4717d
6 changed files with 54 additions and 8 deletions
|
|
@ -23,3 +23,7 @@ target_link_libraries(kwindevices
|
||||||
Qt::DBus
|
Qt::DBus
|
||||||
Qt::Gui
|
Qt::Gui
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if(BUILD_TESTING)
|
||||||
|
add_subdirectory(tests)
|
||||||
|
endif()
|
||||||
|
|
|
||||||
|
|
@ -139,10 +139,12 @@ bool InputDevice::pressureCurveIsDefault() const
|
||||||
QString InputDevice::serializeMatrix(const QMatrix4x4 &matrix)
|
QString InputDevice::serializeMatrix(const QMatrix4x4 &matrix)
|
||||||
{
|
{
|
||||||
QString result;
|
QString result;
|
||||||
for (int i = 0; i < 16; i++) {
|
for (int i = 0; i < 4; ++i) {
|
||||||
result.append(QString::number(matrix.constData()[i]));
|
for (int j = 0; j < 4; ++j) {
|
||||||
if (i != 15) {
|
if (!result.isEmpty()) {
|
||||||
result.append(QLatin1Char(','));
|
result.append(QLatin1Char(','));
|
||||||
|
}
|
||||||
|
result.append(QString::number(matrix(i, j)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,8 @@
|
||||||
|
|
||||||
#include "kwindevices-logging.h"
|
#include "kwindevices-logging.h"
|
||||||
|
|
||||||
|
class InputDeviceTest;
|
||||||
|
|
||||||
namespace KWinDevices
|
namespace KWinDevices
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
@ -261,6 +263,12 @@ Q_SIGNALS:
|
||||||
void relativeChanged();
|
void relativeChanged();
|
||||||
void currentModesChanged();
|
void currentModesChanged();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
static QString serializeMatrix(const QMatrix4x4 &matrix);
|
||||||
|
static QMatrix4x4 deserializeMatrix(const QString &matrix);
|
||||||
|
|
||||||
|
friend class ::InputDeviceTest;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct Prop {
|
struct Prop {
|
||||||
|
|
@ -384,9 +392,6 @@ private:
|
||||||
mutable std::optional<T> m_value;
|
mutable std::optional<T> m_value;
|
||||||
};
|
};
|
||||||
|
|
||||||
static QString serializeMatrix(const QMatrix4x4 &matrix);
|
|
||||||
static QMatrix4x4 deserializeMatrix(const QString &matrix);
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// general
|
// general
|
||||||
Prop<QString> m_name = Prop<QString>(this, "name");
|
Prop<QString> m_name = Prop<QString>(this, "name");
|
||||||
|
|
|
||||||
4
kcms/libkwindevices/tests/CMakeLists.txt
Normal file
4
kcms/libkwindevices/tests/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
ecm_add_test(
|
||||||
|
TEST_NAME tst_inputdevice
|
||||||
|
tst_inputdevice.cpp tst_inputdevice.cpp)
|
||||||
|
target_link_libraries(tst_inputdevice PRIVATE Qt::Test kwindevices)
|
||||||
31
kcms/libkwindevices/tests/tst_inputdevice.cpp
Normal file
31
kcms/libkwindevices/tests/tst_inputdevice.cpp
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
/*
|
||||||
|
SPDX-FileCopyrightText: 2026 Joshua Goins <josh@redstrate.com>
|
||||||
|
|
||||||
|
SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <QTest>
|
||||||
|
|
||||||
|
#include "../inputdevice.h"
|
||||||
|
|
||||||
|
#include <QSignalSpy>
|
||||||
|
|
||||||
|
using namespace KWinDevices;
|
||||||
|
|
||||||
|
class InputDeviceTest : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
|
// Ensure we can actually do a round-trip serialization of matrices.
|
||||||
|
void testMatrix()
|
||||||
|
{
|
||||||
|
QMatrix4x4 matrix{-1.0f, 0.0f, 1.0f, 0.0f, 0.0f, -1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f};
|
||||||
|
|
||||||
|
QCOMPARE(InputDevice::deserializeMatrix(InputDevice::serializeMatrix(matrix)), matrix);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
QTEST_MAIN(InputDeviceTest)
|
||||||
|
|
||||||
|
#include "tst_inputdevice.moc"
|
||||||
|
|
@ -2,4 +2,4 @@ ecm_add_test(
|
||||||
TEST_NAME tst_calibrationtool
|
TEST_NAME tst_calibrationtool
|
||||||
tst_calibrationtool.cpp ../calibrationtool.cpp ${CMAKE_CURRENT_BINARY_DIR}/../logging.cpp)
|
tst_calibrationtool.cpp ../calibrationtool.cpp ${CMAKE_CURRENT_BINARY_DIR}/../logging.cpp)
|
||||||
target_link_libraries(tst_calibrationtool PRIVATE Qt::Test KF6::ConfigCore Canberra::Canberra kwindevices)
|
target_link_libraries(tst_calibrationtool PRIVATE Qt::Test KF6::ConfigCore Canberra::Canberra kwindevices)
|
||||||
target_include_directories(tst_calibrationtool PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/..) # ECM logging from the KCM
|
target_include_directories(tst_calibrationtool PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/..) # ECM logging from the KCM
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue