From 449da861f39b5cc9f2f181aa7e68d27dbad6c04e Mon Sep 17 00:00:00 2001 From: Matt Scheirer Date: Wed, 9 Sep 2020 19:03:36 -0400 Subject: [PATCH] Grammar and syntax changes suggested by @vladz --- src/backends/libinput/connection.cpp | 1 + src/backends/libinput/device.cpp | 90 +++++++++++++--------------- src/backends/libinput/device.h | 18 +++--- 3 files changed, 53 insertions(+), 56 deletions(-) diff --git a/src/backends/libinput/connection.cpp b/src/backends/libinput/connection.cpp index aacea06f54..eb96cf4a69 100644 --- a/src/backends/libinput/connection.cpp +++ b/src/backends/libinput/connection.cpp @@ -600,6 +600,7 @@ void Connection::applyScreenToDevice(Device *device) } } } + device->setOutput(deviceOutput); // TODO: this is currently non-functional even on DRM. Needs orientation() override there. diff --git a/src/backends/libinput/device.cpp b/src/backends/libinput/device.cpp index 40c42ea7c3..fa5bd82249 100644 --- a/src/backends/libinput/device.cpp +++ b/src/backends/libinput/device.cpp @@ -131,11 +131,16 @@ struct ConfigData { explicit ConfigData(QByteArray _key, void (Device::*_setter)(Qt::ScreenOrientation), Qt::ScreenOrientation (Device::*_defaultValue)() const = nullptr) : key(_key) - { screenOrientationSetter.setter = _setter; screenOrientationSetter.defaultValue = _defaultValue; } + { + screenOrientationSetter.setter = _setter; + screenOrientationSetter.defaultValue = _defaultValue; + } - explicit ConfigData(QByteArray _key, void (Device::*_setter)(QMatrix4x4), QMatrix4x4 (Device::*_defaultValue)() const = nullptr) + explicit ConfigData(QByteArray _key, void (Device::*_setter)(const QMatrix4x4 &), QMatrix4x4 (Device::*_defaultValue)() const = nullptr) : key(_key) - { qMatrix4x4Setter.setter = _setter, qMatrix4x4Setter.defaultValue = _defaultValue; } + { + qMatrix4x4Setter.setter = _setter, qMatrix4x4Setter.defaultValue = _defaultValue; + } QByteArray key; @@ -160,7 +165,7 @@ struct ConfigData { Qt::ScreenOrientation (Device::*defaultValue)() const; } screenOrientationSetter; struct { - void (Device::*setter)(QMatrix4x4) = nullptr; + void (Device::*setter)(const QMatrix4x4 &) = nullptr; QMatrix4x4 (Device::*defaultValue)() const; } qMatrix4x4Setter; }; @@ -183,14 +188,14 @@ static const QMap s_configData { {ConfigKey::ScrollFactor, ConfigData(QByteArrayLiteral("ScrollFactor"), &Device::setScrollFactor, &Device::scrollFactorDefault)}, {ConfigKey::Orientation, ConfigData(QByteArrayLiteral("Orientation"), &Device::setOrientation, &Device::defaultOrientation)}, {ConfigKey::Calibration, ConfigData(QByteArrayLiteral("CalibrationMatrix"), &Device::setCalibrationMatrix, &Device::defaultCalibrationMatrix)}, - {ConfigKey::Screen, ConfigData(QByteArrayLiteral("Screen"), &Device::setScreenSlug, &Device::defaultScreenSlug)} + {ConfigKey::Screen, ConfigData(QByteArrayLiteral("Screen"), &Device::setScreen, &Device::defaultScreen)} }; namespace { -QMatrix4x4 getMatrix(libinput_device *device, std::function getter) +QMatrix4x4 getMatrix(libinput_device *device, std::function getter) { float matrix[6]; - if(!getter(device, matrix)) { + if (!getter(device, matrix)) { return {}; } return QMatrix4x4 { @@ -199,9 +204,11 @@ QMatrix4x4 getMatrix(libinput_device *device, std::function*(setter.defaultValue))() : Qt::PrimaryOrientation; int orientation = m_config.readEntry(key.constData(), def); (this->*(setter.setter))(static_cast(orientation)); } - if(it.value().qMatrix4x4Setter.setter != nullptr) { + if (it.value().qMatrix4x4Setter.setter != nullptr) { auto setter = it.value().qMatrix4x4Setter; QList list = m_config.readEntry(key.constData(), QList()); QMatrix4x4 matrix; - if(list.size() == 16) { + if (list.size() == 16) { matrix = QMatrix4x4(list.toVector().constData()); - } else if(setter.defaultValue) { + } else if (setter.defaultValue) { matrix = (this->*(setter.defaultValue))(); } (this->*(setter.setter))(matrix); @@ -619,17 +628,18 @@ void Device::setScrollFactor(qreal factor) } } -void Device::setCalibrationMatrix(QMatrix4x4 matrix) { +void Device::setCalibrationMatrix(const QMatrix4x4 &matrix) +{ if (!m_supportsCalibrationMatrix || m_calibrationMatrix == matrix) { return; } - if(setOrientedCalibrationMatrix(m_device, matrix, m_orientation)) { + if (setOrientedCalibrationMatrix(m_device, matrix, m_orientation)) { QList list; list.reserve(16); for (uchar row = 0; row < 4; ++row) { for (uchar col = 0; col < 4; ++col) { - list << matrix(row,col); + list << matrix(row, col); } } writeEntry(ConfigKey::Calibration, list); @@ -651,35 +661,20 @@ void Device::setOrientation(Qt::ScreenOrientation orientation) } } -void Device::setScreenSlug(QString slug) { +void Device::setScreen(QString name) +{ #ifndef KWIN_BUILD_TESTING - if(slug.isEmpty()) { - return; - } - - auto parts = slug.split(';'); - if(parts.size() != 4) { - qCWarning(KWIN_LIBINPUT) << "Malformed display slug in config:" << slug << "for device:" << m_name; - return; - } - - const auto outputs = kwinApp()->platform()->enabledOutputs(); - AbstractOutput *match = nullptr; - for(auto output : outputs) { - if(output->manufacturer() == parts[1] && - output->model() == parts[2]) { - match = output; - // If neither serial (preferred) or name match we may not have the right screen and have to keep iterating. - if((!parts[3].isEmpty() && output->serialNumber() == parts[3]) || output->name() == parts[0]) { - break; - } + auto outputs = kwinApp()->platform()->enabledOutputs(); + for(int i = 0; i < outputs.count(); ++i) { + if (outputs[i]->name() == name) { + setOutput(outputs[i]); + writeEntry(ConfigKey::Screen, outputs[i]->uuid().toString()); + Q_EMIT screenChanged(); + break; } } - if(match) { - setOutput(match); - } #else - Q_UNUSED(slug) + Q_UNUSED(name) #endif } @@ -691,9 +686,6 @@ AbstractOutput *Device::output() const void Device::setOutput(AbstractOutput *output) { m_output = output; - - QString slug = output->name() + ';' + output->manufacturer() + ';' + output->model() + ';' + output->serialNumber(); - writeEntry(ConfigKey::Screen, slug); } static libinput_led toLibinputLEDS(LEDs leds) diff --git a/src/backends/libinput/device.h b/src/backends/libinput/device.h index bd04374670..c5543cdde9 100644 --- a/src/backends/libinput/device.h +++ b/src/backends/libinput/device.h @@ -349,18 +349,22 @@ public: */ void setLeftHanded(bool set); - QMatrix4x4 defaultCalibrationMatrix() const { + QMatrix4x4 defaultCalibrationMatrix() const + { return m_defaultCalibrationMatrix; } - QMatrix4x4 calibrationMatrix() const { + QMatrix4x4 calibrationMatrix() const + { return m_calibrationMatrix; } - void setCalibrationMatrix(QMatrix4x4 matrix); + void setCalibrationMatrix(const QMatrix4x4 &matrix); - Qt::ScreenOrientation defaultOrientation() const { + Qt::ScreenOrientation defaultOrientation() const + { return Qt::PrimaryOrientation; } - Qt::ScreenOrientation orientation() const { + Qt::ScreenOrientation orientation() const + { return m_orientation; } void setOrientation(Qt::ScreenOrientation orientation); @@ -464,8 +468,8 @@ public: /** * Used to deserialize monitor data from KConfig when initializing a device */ - void setScreenSlug(QString slug); - QString defaultScreenSlug() const { return {}; } + void setScreen(QString uuid); + QString defaultScreen() const { return {}; } /** * Loads the configuration and applies it to the Device