Grammar and syntax changes suggested by @vladz

This commit is contained in:
Matt Scheirer 2020-09-09 19:03:36 -04:00 committed by Aleix Pol Gonzalez
parent 6287ab16f4
commit 449da861f3
3 changed files with 53 additions and 56 deletions

View file

@ -600,6 +600,7 @@ void Connection::applyScreenToDevice(Device *device)
} }
} }
} }
device->setOutput(deviceOutput); device->setOutput(deviceOutput);
// TODO: this is currently non-functional even on DRM. Needs orientation() override there. // TODO: this is currently non-functional even on DRM. Needs orientation() override there.

View file

@ -131,11 +131,16 @@ struct ConfigData {
explicit ConfigData(QByteArray _key, void (Device::*_setter)(Qt::ScreenOrientation), Qt::ScreenOrientation (Device::*_defaultValue)() const = nullptr) explicit ConfigData(QByteArray _key, void (Device::*_setter)(Qt::ScreenOrientation), Qt::ScreenOrientation (Device::*_defaultValue)() const = nullptr)
: key(_key) : 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) : key(_key)
{ qMatrix4x4Setter.setter = _setter, qMatrix4x4Setter.defaultValue = _defaultValue; } {
qMatrix4x4Setter.setter = _setter, qMatrix4x4Setter.defaultValue = _defaultValue;
}
QByteArray key; QByteArray key;
@ -160,7 +165,7 @@ struct ConfigData {
Qt::ScreenOrientation (Device::*defaultValue)() const; Qt::ScreenOrientation (Device::*defaultValue)() const;
} screenOrientationSetter; } screenOrientationSetter;
struct { struct {
void (Device::*setter)(QMatrix4x4) = nullptr; void (Device::*setter)(const QMatrix4x4 &) = nullptr;
QMatrix4x4 (Device::*defaultValue)() const; QMatrix4x4 (Device::*defaultValue)() const;
} qMatrix4x4Setter; } qMatrix4x4Setter;
}; };
@ -183,14 +188,14 @@ static const QMap<ConfigKey, ConfigData> s_configData {
{ConfigKey::ScrollFactor, ConfigData(QByteArrayLiteral("ScrollFactor"), &Device::setScrollFactor, &Device::scrollFactorDefault)}, {ConfigKey::ScrollFactor, ConfigData(QByteArrayLiteral("ScrollFactor"), &Device::setScrollFactor, &Device::scrollFactorDefault)},
{ConfigKey::Orientation, ConfigData(QByteArrayLiteral("Orientation"), &Device::setOrientation, &Device::defaultOrientation)}, {ConfigKey::Orientation, ConfigData(QByteArrayLiteral("Orientation"), &Device::setOrientation, &Device::defaultOrientation)},
{ConfigKey::Calibration, ConfigData(QByteArrayLiteral("CalibrationMatrix"), &Device::setCalibrationMatrix, &Device::defaultCalibrationMatrix)}, {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 { namespace {
QMatrix4x4 getMatrix(libinput_device *device, std::function<int(libinput_device*, float[6])> getter) QMatrix4x4 getMatrix(libinput_device *device, std::function<int(libinput_device *, float[6])> getter)
{ {
float matrix[6]; float matrix[6];
if(!getter(device, matrix)) { if (!getter(device, matrix)) {
return {}; return {};
} }
return QMatrix4x4 { return QMatrix4x4 {
@ -199,9 +204,11 @@ QMatrix4x4 getMatrix(libinput_device *device, std::function<int(libinput_device*
0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f 0.0f, 0.0f, 0.0f, 1.0f
}; };
} }
bool setOrientedCalibrationMatrix(libinput_device *device, QMatrix4x4 matrix, Qt::ScreenOrientation orientation) { bool setOrientedCalibrationMatrix(libinput_device *device, QMatrix4x4 matrix, Qt::ScreenOrientation orientation)
{
// 90 deg cw // 90 deg cw
static const QMatrix4x4 portraitMatrix { static const QMatrix4x4 portraitMatrix {
0.0f, -1.0f, 1.0f, 0.0f, 0.0f, -1.0f, 1.0f, 0.0f,
@ -240,8 +247,7 @@ bool setOrientedCalibrationMatrix(libinput_device *device, QMatrix4x4 matrix, Qt
break; break;
} }
float data[6] { matrix(0,0), matrix(0,1), matrix(0,2), float data[6]{matrix(0, 0), matrix(0, 1), matrix(0, 2), matrix(1, 0), matrix(1, 1), matrix(1, 2)};
matrix(1,0), matrix(1,1), matrix(1,2) };
return libinput_device_config_calibration_set_matrix(device, data) == LIBINPUT_CONFIG_STATUS_SUCCESS; return libinput_device_config_calibration_set_matrix(device, data) == LIBINPUT_CONFIG_STATUS_SUCCESS;
} }
} }
@ -344,10 +350,13 @@ Device::Device(libinput_device *device, QObject *parent)
m_alphaNumericKeyboard = checkAlphaNumericKeyboard(m_device); m_alphaNumericKeyboard = checkAlphaNumericKeyboard(m_device);
} }
if (m_supportsCalibrationMatrix && if (m_supportsCalibrationMatrix && m_calibrationMatrix != m_defaultCalibrationMatrix) {
m_calibrationMatrix != m_defaultCalibrationMatrix) { float matrix[]{m_defaultCalibrationMatrix(0, 0),
float matrix[] {m_defaultCalibrationMatrix(0,0), m_defaultCalibrationMatrix(0,1), m_defaultCalibrationMatrix(0,2), m_defaultCalibrationMatrix(0, 1),
m_defaultCalibrationMatrix(1,0), m_defaultCalibrationMatrix(1,1), m_defaultCalibrationMatrix(1,2)}; m_defaultCalibrationMatrix(0, 2),
m_defaultCalibrationMatrix(1, 0),
m_defaultCalibrationMatrix(1, 1),
m_defaultCalibrationMatrix(1, 2)};
libinput_device_config_calibration_set_matrix(m_device, matrix); libinput_device_config_calibration_set_matrix(m_device, matrix);
m_calibrationMatrix = m_defaultCalibrationMatrix; m_calibrationMatrix = m_defaultCalibrationMatrix;
} }
@ -410,20 +419,20 @@ void Device::loadConfiguration()
readEntry(key, it.value().stringSetter, ""); readEntry(key, it.value().stringSetter, "");
readEntry(key, it.value().qrealSetter, 1.0); readEntry(key, it.value().qrealSetter, 1.0);
if(it.value().screenOrientationSetter.setter != nullptr) { if (it.value().screenOrientationSetter.setter != nullptr) {
auto setter = it.value().screenOrientationSetter; auto setter = it.value().screenOrientationSetter;
int def = setter.defaultValue ? (this->*(setter.defaultValue))() : Qt::PrimaryOrientation; int def = setter.defaultValue ? (this->*(setter.defaultValue))() : Qt::PrimaryOrientation;
int orientation = m_config.readEntry(key.constData(), def); int orientation = m_config.readEntry(key.constData(), def);
(this->*(setter.setter))(static_cast<Qt::ScreenOrientation>(orientation)); (this->*(setter.setter))(static_cast<Qt::ScreenOrientation>(orientation));
} }
if(it.value().qMatrix4x4Setter.setter != nullptr) { if (it.value().qMatrix4x4Setter.setter != nullptr) {
auto setter = it.value().qMatrix4x4Setter; auto setter = it.value().qMatrix4x4Setter;
QList<float> list = m_config.readEntry(key.constData(), QList<float>()); QList<float> list = m_config.readEntry(key.constData(), QList<float>());
QMatrix4x4 matrix; QMatrix4x4 matrix;
if(list.size() == 16) { if (list.size() == 16) {
matrix = QMatrix4x4(list.toVector().constData()); matrix = QMatrix4x4(list.toVector().constData());
} else if(setter.defaultValue) { } else if (setter.defaultValue) {
matrix = (this->*(setter.defaultValue))(); matrix = (this->*(setter.defaultValue))();
} }
(this->*(setter.setter))(matrix); (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) { if (!m_supportsCalibrationMatrix || m_calibrationMatrix == matrix) {
return; return;
} }
if(setOrientedCalibrationMatrix(m_device, matrix, m_orientation)) { if (setOrientedCalibrationMatrix(m_device, matrix, m_orientation)) {
QList<float> list; QList<float> list;
list.reserve(16); list.reserve(16);
for (uchar row = 0; row < 4; ++row) { for (uchar row = 0; row < 4; ++row) {
for (uchar col = 0; col < 4; ++col) { for (uchar col = 0; col < 4; ++col) {
list << matrix(row,col); list << matrix(row, col);
} }
} }
writeEntry(ConfigKey::Calibration, list); 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 #ifndef KWIN_BUILD_TESTING
if(slug.isEmpty()) { auto outputs = kwinApp()->platform()->enabledOutputs();
return; for(int i = 0; i < outputs.count(); ++i) {
} if (outputs[i]->name() == name) {
setOutput(outputs[i]);
auto parts = slug.split(';'); writeEntry(ConfigKey::Screen, outputs[i]->uuid().toString());
if(parts.size() != 4) { Q_EMIT screenChanged();
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; break;
} }
} }
}
if(match) {
setOutput(match);
}
#else #else
Q_UNUSED(slug) Q_UNUSED(name)
#endif #endif
} }
@ -691,9 +686,6 @@ AbstractOutput *Device::output() const
void Device::setOutput(AbstractOutput *output) void Device::setOutput(AbstractOutput *output)
{ {
m_output = output; m_output = output;
QString slug = output->name() + ';' + output->manufacturer() + ';' + output->model() + ';' + output->serialNumber();
writeEntry(ConfigKey::Screen, slug);
} }
static libinput_led toLibinputLEDS(LEDs leds) static libinput_led toLibinputLEDS(LEDs leds)

View file

@ -349,18 +349,22 @@ public:
*/ */
void setLeftHanded(bool set); void setLeftHanded(bool set);
QMatrix4x4 defaultCalibrationMatrix() const { QMatrix4x4 defaultCalibrationMatrix() const
{
return m_defaultCalibrationMatrix; return m_defaultCalibrationMatrix;
} }
QMatrix4x4 calibrationMatrix() const { QMatrix4x4 calibrationMatrix() const
{
return m_calibrationMatrix; return m_calibrationMatrix;
} }
void setCalibrationMatrix(QMatrix4x4 matrix); void setCalibrationMatrix(const QMatrix4x4 &matrix);
Qt::ScreenOrientation defaultOrientation() const { Qt::ScreenOrientation defaultOrientation() const
{
return Qt::PrimaryOrientation; return Qt::PrimaryOrientation;
} }
Qt::ScreenOrientation orientation() const { Qt::ScreenOrientation orientation() const
{
return m_orientation; return m_orientation;
} }
void setOrientation(Qt::ScreenOrientation orientation); void setOrientation(Qt::ScreenOrientation orientation);
@ -464,8 +468,8 @@ public:
/** /**
* Used to deserialize monitor data from KConfig when initializing a device * Used to deserialize monitor data from KConfig when initializing a device
*/ */
void setScreenSlug(QString slug); void setScreen(QString uuid);
QString defaultScreenSlug() const { return {}; } QString defaultScreen() const { return {}; }
/** /**
* Loads the configuration and applies it to the Device * Loads the configuration and applies it to the Device