input: Introduce a outputArea property for tablet devices

It's important for tablet devices to be able to specify to which section
of the display we'll be fitting the tablet. This setting allows to
specify this by providing some options that will do so relative to the
output size.

CCBUG: 433045
This commit is contained in:
Aleix Pol 2022-07-10 18:35:11 +02:00 committed by Aleix Pol Gonzalez
parent 8407f88585
commit 27f24d1449
5 changed files with 67 additions and 7 deletions

View file

@ -967,3 +967,23 @@ libinput_device_get_user_data(struct libinput_device *device)
{
return device->userData;
}
double
libinput_event_tablet_tool_get_x_transformed(struct libinput_event_tablet_tool *event,
uint32_t width)
{
Q_UNUSED(event)
Q_UNUSED(width)
// it's unused at the moment, it doesn't really matter what we return
return 0;
}
double
libinput_event_tablet_tool_get_y_transformed(struct libinput_event_tablet_tool *event,
uint32_t height)
{
Q_UNUSED(event)
Q_UNUSED(height)
return 4;
}

View file

@ -95,7 +95,8 @@ enum class ConfigKey {
ScrollFactor,
Orientation,
Calibration,
OutputName
OutputName,
OutputArea,
};
struct ConfigDataBase
@ -201,7 +202,9 @@ static const QMap<ConfigKey, ConfigDataBase *> s_configData{
{ConfigKey::ScrollFactor, new ConfigData<qreal>(QByteArrayLiteral("ScrollFactor"), &Device::setScrollFactor, &Device::scrollFactorDefault)},
{ConfigKey::Orientation, new ConfigData<DeviceOrientation>{}},
{ConfigKey::Calibration, new ConfigData<CalibrationMatrix>{}},
{ConfigKey::OutputName, new ConfigData<QString>(QByteArrayLiteral("OutputName"), &Device::setOutputName, &Device::defaultOutputName)}};
{ConfigKey::OutputName, new ConfigData<QString>(QByteArrayLiteral("OutputName"), &Device::setOutputName, &Device::defaultOutputName)},
{ConfigKey::OutputArea, new ConfigData<QRectF>(QByteArrayLiteral("OutputArea"), &Device::setOutputArea, &Device::defaultOutputArea)},
};
namespace
{
@ -706,5 +709,28 @@ void Device::setLeds(LEDs leds)
}
}
bool Device::supportsOutputArea() const
{
return m_tabletTool;
}
QRectF Device::defaultOutputArea() const
{
return QRectF(0, 0, 1, 1);
}
QRectF Device::outputArea() const
{
return m_outputArea;
}
void Device::setOutputArea(const QRectF &outputArea)
{
if (m_outputArea != outputArea) {
m_outputArea = outputArea;
writeEntry(ConfigKey::OutputArea, m_outputArea);
Q_EMIT outputAreaChanged();
}
}
}
}

View file

@ -138,6 +138,10 @@ class KWIN_EXPORT Device : public InputDevice
Q_PROPERTY(bool defaultClickMethodClickfinger READ defaultClickMethodClickfinger CONSTANT)
Q_PROPERTY(bool clickMethodClickfinger READ isClickMethodClickfinger WRITE setClickMethodClickfinger NOTIFY clickMethodChanged)
Q_PROPERTY(bool supportsOutputArea READ supportsOutputArea CONSTANT)
Q_PROPERTY(QRectF defaultOutputArea READ defaultOutputArea CONSTANT)
Q_PROPERTY(QRectF outputArea READ outputArea WRITE setOutputArea NOTIFY outputAreaChanged)
public:
explicit Device(libinput_device *device, QObject *parent = nullptr);
~Device() override;
@ -619,6 +623,11 @@ public:
LEDs leds() const override;
void setLeds(LEDs leds) override;
QRectF defaultOutputArea() const;
bool supportsOutputArea() const;
QRectF outputArea() const;
void setOutputArea(const QRectF &outputArea);
/**
* Gets the Device for @p native. @c null if there is no Device for @p native.
*/
@ -643,6 +652,7 @@ Q_SIGNALS:
void scrollButtonChanged();
void scrollFactorChanged();
void clickMethodChanged();
void outputAreaChanged();
private:
template<typename T>
@ -729,6 +739,7 @@ private:
enum libinput_config_click_method m_clickMethod;
LEDs m_leds;
QRectF m_outputArea = QRectF(0, 0, 1, 1);
};
}

View file

@ -368,6 +368,13 @@ TabletToolEvent::TabletToolEvent(libinput_event *event, libinput_event_type type
{
}
QPointF TabletToolEvent::transformedPosition(const QSize &size) const
{
const QRectF outputArea = device()->outputArea();
return {size.width() * outputArea.x() + libinput_event_tablet_tool_get_x_transformed(m_tabletToolEvent, size.width() * outputArea.width()),
size.height() * outputArea.y() + libinput_event_tablet_tool_get_y_transformed(m_tabletToolEvent, size.height() * outputArea.height())};
}
TabletToolButtonEvent::TabletToolButtonEvent(libinput_event *event, libinput_event_type type)
: Event(event, type)
, m_tabletToolEvent(libinput_event_get_tablet_tool_event(event))

View file

@ -307,11 +307,7 @@ public:
return state == LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN;
}
QPointF transformedPosition(const QSize &size) const
{
return {libinput_event_tablet_tool_get_x_transformed(m_tabletToolEvent, size.width()),
libinput_event_tablet_tool_get_y_transformed(m_tabletToolEvent, size.height())};
}
QPointF transformedPosition(const QSize &size) const;
struct libinput_tablet_tool *tool()
{