libinput: Successfully set the output of a device from the dbus interface

This commit is contained in:
Aleix Pol 2021-11-03 04:33:16 +01:00 committed by Aleix Pol Gonzalez
parent 449da861f3
commit 5ff22d7765
3 changed files with 31 additions and 14 deletions

View file

@ -476,8 +476,10 @@ void Connection::processEvents()
if (workspace()) { if (workspace()) {
#ifndef KWIN_BUILD_TESTING #ifndef KWIN_BUILD_TESTING
auto client = workspace()->activeClient(); AbstractWaylandOutput *output = static_cast<AbstractWaylandOutput *>(tte->device()->output());
auto *output = static_cast<AbstractWaylandOutput *>(client ? client->output() : tte->device()->output()); if (!output && workspace()->activeClient()) {
output = static_cast<AbstractWaylandOutput *>(workspace()->activeClient()->output());
}
if (!output) { if (!output) {
output = static_cast<AbstractWaylandOutput *>(workspace()->activeOutput()); output = static_cast<AbstractWaylandOutput *>(workspace()->activeOutput());
} }

View file

@ -109,7 +109,7 @@ enum class ConfigKey {
ScrollFactor, ScrollFactor,
Orientation, Orientation,
Calibration, Calibration,
Screen OutputName
}; };
struct ConfigData { struct ConfigData {
@ -188,8 +188,7 @@ 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::setScreen, &Device::defaultScreen)} {ConfigKey::OutputName, ConfigData(QByteArrayLiteral("OutputName"), &Device::setOutputName, &Device::defaultOutputName)}};
};
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)
@ -661,15 +660,17 @@ void Device::setOrientation(Qt::ScreenOrientation orientation)
} }
} }
void Device::setScreen(QString name) void Device::setOutputName(QString name)
{ {
#ifndef KWIN_BUILD_TESTING #ifndef KWIN_BUILD_TESTING
auto outputs = kwinApp()->platform()->enabledOutputs(); if (name.isEmpty()) {
for(int i = 0; i < outputs.count(); ++i) { setOutput(nullptr);
return;
}
auto outputs = kwinApp()->platform()->enabledOutputs();
for (int i = 0; i < outputs.count(); ++i) {
if (outputs[i]->name() == name) { if (outputs[i]->name() == name) {
setOutput(outputs[i]); setOutput(outputs[i]);
writeEntry(ConfigKey::Screen, outputs[i]->uuid().toString());
Q_EMIT screenChanged();
break; break;
} }
} }
@ -686,6 +687,12 @@ AbstractOutput *Device::output() const
void Device::setOutput(AbstractOutput *output) void Device::setOutput(AbstractOutput *output)
{ {
m_output = output; m_output = output;
if (m_output) {
writeEntry(ConfigKey::OutputName, output->name());
} else {
writeEntry(ConfigKey::OutputName, QString());
}
Q_EMIT outputNameChanged();
} }
static libinput_led toLibinputLEDS(LEDs leds) static libinput_led toLibinputLEDS(LEDs leds)

View file

@ -47,7 +47,7 @@ class KWIN_EXPORT Device : public InputDevice
Q_PROPERTY(bool gestureSupport READ supportsGesture CONSTANT) Q_PROPERTY(bool gestureSupport READ supportsGesture CONSTANT)
Q_PROPERTY(QString name READ name CONSTANT) Q_PROPERTY(QString name READ name CONSTANT)
Q_PROPERTY(QString sysName READ sysName CONSTANT) Q_PROPERTY(QString sysName READ sysName CONSTANT)
Q_PROPERTY(QString outputName READ outputName CONSTANT) Q_PROPERTY(QString outputName READ outputName WRITE setOutputName NOTIFY outputNameChanged)
Q_PROPERTY(QSizeF size READ size CONSTANT) Q_PROPERTY(QSizeF size READ size CONSTANT)
Q_PROPERTY(quint32 product READ product CONSTANT) Q_PROPERTY(quint32 product READ product CONSTANT)
Q_PROPERTY(quint32 vendor READ vendor CONSTANT) Q_PROPERTY(quint32 vendor READ vendor CONSTANT)
@ -60,6 +60,7 @@ class KWIN_EXPORT Device : public InputDevice
Q_PROPERTY(QMatrix4x4 defaultCalibrationMatrix READ defaultCalibrationMatrix CONSTANT) Q_PROPERTY(QMatrix4x4 defaultCalibrationMatrix READ defaultCalibrationMatrix CONSTANT)
Q_PROPERTY(QMatrix4x4 calibrationMatrix READ calibrationMatrix WRITE setCalibrationMatrix NOTIFY calibrationMatrixChanged) Q_PROPERTY(QMatrix4x4 calibrationMatrix READ calibrationMatrix WRITE setCalibrationMatrix NOTIFY calibrationMatrixChanged)
Q_PROPERTY(Qt::ScreenOrientation orientation READ orientation WRITE setOrientation NOTIFY orientationChanged) Q_PROPERTY(Qt::ScreenOrientation orientation READ orientation WRITE setOrientation NOTIFY orientationChanged)
Q_PROPERTY(int orientationDBus READ orientation WRITE setOrientationDBus NOTIFY orientationChanged)
Q_PROPERTY(bool supportsLeftHanded READ supportsLeftHanded CONSTANT) Q_PROPERTY(bool supportsLeftHanded READ supportsLeftHanded CONSTANT)
Q_PROPERTY(bool leftHandedEnabledByDefault READ leftHandedEnabledByDefault CONSTANT) Q_PROPERTY(bool leftHandedEnabledByDefault READ leftHandedEnabledByDefault CONSTANT)
@ -368,6 +369,10 @@ public:
return m_orientation; return m_orientation;
} }
void setOrientation(Qt::ScreenOrientation orientation); void setOrientation(Qt::ScreenOrientation orientation);
void setOrientationDBus(int orientation)
{
setOrientation(Qt::ScreenOrientation(orientation));
}
qreal defaultPointerAcceleration() const { qreal defaultPointerAcceleration() const {
return m_defaultPointerAcceleration; return m_defaultPointerAcceleration;
@ -468,8 +473,11 @@ public:
/** /**
* Used to deserialize monitor data from KConfig when initializing a device * Used to deserialize monitor data from KConfig when initializing a device
*/ */
void setScreen(QString uuid); void setOutputName(QString uuid);
QString defaultScreen() const { return {}; } QString defaultOutputName() const
{
return {};
}
/** /**
* Loads the configuration and applies it to the Device * Loads the configuration and applies it to the Device
@ -514,7 +522,7 @@ Q_SIGNALS:
void tapButtonMapChanged(); void tapButtonMapChanged();
void calibrationMatrixChanged(); void calibrationMatrixChanged();
void orientationChanged(); void orientationChanged();
void screenChanged(); void outputNameChanged();
void leftHandedChanged(); void leftHandedChanged();
void disableWhileTypingChanged(); void disableWhileTypingChanged();
void pointerAccelerationChanged(); void pointerAccelerationChanged();