Plumb InputDevice in tablet events

The InputDevice is useful for determining the origin of the event.
TabletPadId acts like it, but it still suffers from issues where we
need to access the InputDevice.
wilder/Plasma/6.3
Vlad Zahorodnii 1 year ago
parent 6de1d456be
commit 75af8293a5
  1. 10
      autotests/integration/test_helpers.cpp
  2. 10
      src/backends/libinput/connection.cpp
  3. 11
      src/core/inputdevice.h
  4. 3
      src/input_event.cpp
  5. 12
      src/input_event.h
  6. 2
      src/plugins/buttonrebinds/buttonrebindsfilter.cpp
  7. 21
      src/tablet_input.cpp
  8. 12
      src/tablet_input.h

@ -1741,7 +1741,7 @@ void tabletPadButtonPressed(quint32 button, quint32 time)
TabletPadId padId{
.name = virtualTabletPad->name(),
};
Q_EMIT virtualTabletPad->tabletPadButtonEvent(button, true, padId, std::chrono::milliseconds(time));
Q_EMIT virtualTabletPad->tabletPadButtonEvent(button, true, padId, std::chrono::milliseconds(time), virtualTabletPad);
}
void tabletPadButtonReleased(quint32 button, quint32 time)
@ -1750,7 +1750,7 @@ void tabletPadButtonReleased(quint32 button, quint32 time)
TabletPadId padId{
.name = virtualTabletPad->name(),
};
Q_EMIT virtualTabletPad->tabletPadButtonEvent(button, false, padId, std::chrono::milliseconds(time));
Q_EMIT virtualTabletPad->tabletPadButtonEvent(button, false, padId, std::chrono::milliseconds(time), virtualTabletPad);
}
void tabletToolButtonPressed(quint32 button, quint32 time)
@ -1759,7 +1759,7 @@ void tabletToolButtonPressed(quint32 button, quint32 time)
TabletToolId toolId{
.m_name = virtualTabletTool->name(),
};
Q_EMIT virtualTabletTool->tabletToolButtonEvent(button, true, toolId, std::chrono::milliseconds(time));
Q_EMIT virtualTabletTool->tabletToolButtonEvent(button, true, toolId, std::chrono::milliseconds(time), virtualTabletTool);
}
void tabletToolButtonReleased(quint32 button, quint32 time)
@ -1768,7 +1768,7 @@ void tabletToolButtonReleased(quint32 button, quint32 time)
TabletToolId toolId{
.m_name = virtualTabletTool->name(),
};
Q_EMIT virtualTabletTool->tabletToolButtonEvent(button, false, toolId, std::chrono::milliseconds(time));
Q_EMIT virtualTabletTool->tabletToolButtonEvent(button, false, toolId, std::chrono::milliseconds(time), virtualTabletTool);
}
void tabletToolEvent(InputRedirection::TabletEventType type, const QPointF &pos,
@ -1779,7 +1779,7 @@ void tabletToolEvent(InputRedirection::TabletEventType type, const QPointF &pos,
TabletToolId toolId{
.m_name = virtualTabletTool->name(),
};
Q_EMIT virtualTabletTool->tabletToolEvent(type, pos, pressure, xTilt, yTilt, rotation, tipDown, tipNear, toolId, std::chrono::milliseconds(time));
Q_EMIT virtualTabletTool->tabletToolEvent(type, pos, pressure, xTilt, yTilt, rotation, tipDown, tipNear, toolId, std::chrono::milliseconds(time), virtualTabletTool);
}
}
}

@ -541,7 +541,7 @@ void Connection::processEvents()
Q_EMIT event->device()->tabletToolEvent(tabletEventType,
globalPos, pressure,
tte->xTilt(), tte->yTilt(), tte->rotation(),
tte->isTipDown(), tte->isNearby(), createTabletId(tte->tool(), event->device()), tte->time());
tte->isTipDown(), tte->isNearby(), createTabletId(tte->tool(), event->device()), tte->time(), tte->device());
}
break;
}
@ -549,14 +549,14 @@ void Connection::processEvents()
auto *tabletEvent = static_cast<TabletToolButtonEvent *>(event.get());
Q_EMIT event->device()->tabletToolButtonEvent(tabletEvent->buttonId(),
tabletEvent->isButtonPressed(),
createTabletId(tabletEvent->tool(), event->device()), tabletEvent->time());
createTabletId(tabletEvent->tool(), event->device()), tabletEvent->time(), tabletEvent->device());
break;
}
case LIBINPUT_EVENT_TABLET_PAD_BUTTON: {
auto *tabletEvent = static_cast<TabletPadButtonEvent *>(event.get());
Q_EMIT event->device()->tabletPadButtonEvent(tabletEvent->buttonId(),
tabletEvent->isButtonPressed(),
createTabletPadId(event->device()), tabletEvent->time());
createTabletPadId(event->device()), tabletEvent->time(), tabletEvent->device());
break;
}
case LIBINPUT_EVENT_TABLET_PAD_RING: {
@ -565,7 +565,7 @@ void Connection::processEvents()
Q_EMIT event->device()->tabletPadRingEvent(tabletEvent->number(),
tabletEvent->position(),
tabletEvent->source() == LIBINPUT_TABLET_PAD_RING_SOURCE_FINGER,
createTabletPadId(event->device()), tabletEvent->time());
createTabletPadId(event->device()), tabletEvent->time(), tabletEvent->device());
break;
}
case LIBINPUT_EVENT_TABLET_PAD_STRIP: {
@ -573,7 +573,7 @@ void Connection::processEvents()
Q_EMIT event->device()->tabletPadStripEvent(tabletEvent->number(),
tabletEvent->position(),
tabletEvent->source() == LIBINPUT_TABLET_PAD_STRIP_SOURCE_FINGER,
createTabletPadId(event->device()), tabletEvent->time());
createTabletPadId(event->device()), tabletEvent->time(), tabletEvent->device());
break;
}
default:

@ -77,12 +77,11 @@ Q_SIGNALS:
void tabletToolEvent(InputRedirection::TabletEventType type, const QPointF &pos,
qreal pressure, int xTilt, int yTilt, qreal rotation, bool tipDown,
bool tipNear, const TabletToolId &tabletToolId, std::chrono::microseconds time);
void tabletToolButtonEvent(uint button, bool isPressed, const TabletToolId &tabletToolId, std::chrono::microseconds time);
void tabletPadButtonEvent(uint button, bool isPressed, const TabletPadId &tabletPadId, std::chrono::microseconds time);
void tabletPadStripEvent(int number, int position, bool isFinger, const TabletPadId &tabletPadId, std::chrono::microseconds time);
void tabletPadRingEvent(int number, int position, bool isFinger, const TabletPadId &tabletPadId, std::chrono::microseconds time);
bool tipNear, const TabletToolId &tabletToolId, std::chrono::microseconds time, InputDevice *device);
void tabletToolButtonEvent(uint button, bool isPressed, const TabletToolId &tabletToolId, std::chrono::microseconds time, InputDevice *device);
void tabletPadButtonEvent(uint button, bool isPressed, const TabletPadId &tabletPadId, std::chrono::microseconds time, InputDevice *device);
void tabletPadStripEvent(int number, int position, bool isFinger, const TabletPadId &tabletPadId, std::chrono::microseconds time, InputDevice *device);
void tabletPadRingEvent(int number, int position, bool isFinger, const TabletPadId &tabletPadId, std::chrono::microseconds time, InputDevice *device);
};
} // namespace KWin

@ -69,9 +69,10 @@ SwitchEvent::SwitchEvent(State state, std::chrono::microseconds timestamp, Input
TabletEvent::TabletEvent(Type t, const QPointingDevice *dev, const QPointF &pos, const QPointF &globalPos,
qreal pressure, float xTilt, float yTilt,
float tangentialPressure, qreal rotation, float z,
Qt::KeyboardModifiers keyState, Qt::MouseButton button, Qt::MouseButtons buttons, const TabletToolId &tabletId)
Qt::KeyboardModifiers keyState, Qt::MouseButton button, Qt::MouseButtons buttons, const TabletToolId &tabletId, InputDevice *device)
: QTabletEvent(t, dev, pos, globalPos, pressure, xTilt, yTilt, tangentialPressure, rotation, z, keyState, button, buttons)
, m_id(tabletId)
, m_device(device)
{
}

@ -219,7 +219,12 @@ public:
TabletEvent(Type t, const QPointingDevice *dev, const QPointF &pos, const QPointF &globalPos,
qreal pressure, float xTilt, float yTilt,
float tangentialPressure, qreal rotation, float z,
Qt::KeyboardModifiers keyState, Qt::MouseButton button, Qt::MouseButtons buttons, const TabletToolId &tabletId);
Qt::KeyboardModifiers keyState, Qt::MouseButton button, Qt::MouseButtons buttons, const TabletToolId &tabletId, InputDevice *device);
InputDevice *device() const
{
return m_device;
}
const TabletToolId &tabletId() const
{
@ -228,10 +233,12 @@ public:
private:
const TabletToolId m_id;
InputDevice *m_device;
};
struct TabletToolButtonEvent
{
InputDevice *device;
uint button;
bool pressed;
TabletToolId tabletToolId;
@ -240,6 +247,7 @@ struct TabletToolButtonEvent
struct TabletPadButtonEvent
{
InputDevice *device;
uint button;
bool pressed;
TabletPadId tabletPadId;
@ -248,6 +256,7 @@ struct TabletPadButtonEvent
struct TabletPadStripEvent
{
InputDevice *device;
int number;
int position;
bool isFinger;
@ -257,6 +266,7 @@ struct TabletPadStripEvent
struct TabletPadRingEvent
{
InputDevice *device;
int number;
int position;
bool isFinger;

@ -450,7 +450,7 @@ bool ButtonRebindsFilter::sendTabletToolButton(quint32 button, bool pressed, std
return false;
}
RebindScope scope;
Q_EMIT m_inputDevice.tabletToolButtonEvent(button, pressed, *m_tabletTool, time);
Q_EMIT m_inputDevice.tabletToolButtonEvent(button, pressed, *m_tabletTool, time, &m_inputDevice);
return true;
}

@ -266,7 +266,8 @@ TabletToolV2Interface *TabletInputRedirection::ensureTabletTool(const TabletTool
void TabletInputRedirection::tabletToolEvent(KWin::InputRedirection::TabletEventType type, const QPointF &pos,
qreal pressure, int xTilt, int yTilt, qreal rotation, bool tipDown,
bool tipNear, const TabletToolId &tabletToolId,
std::chrono::microseconds time)
std::chrono::microseconds time,
InputDevice *device)
{
if (!inited()) {
return;
@ -310,7 +311,7 @@ void TabletInputRedirection::tabletToolEvent(KWin::InputRedirection::TabletEvent
0, // tangentialPressure
rotation,
0, // z
Qt::NoModifier, button, button, tabletToolId);
Qt::NoModifier, button, button, tabletToolId, device);
ev.setTimestamp(std::chrono::duration_cast<std::chrono::milliseconds>(time).count());
input()->processSpies(std::bind(&InputEventSpy::tabletToolEvent, std::placeholders::_1, &ev));
@ -321,10 +322,10 @@ void TabletInputRedirection::tabletToolEvent(KWin::InputRedirection::TabletEvent
m_tipNear = tipNear;
}
void KWin::TabletInputRedirection::tabletToolButtonEvent(uint button, bool isPressed,
const TabletToolId &tabletToolId, std::chrono::microseconds time)
void KWin::TabletInputRedirection::tabletToolButtonEvent(uint button, bool isPressed, const TabletToolId &tabletToolId, std::chrono::microseconds time, InputDevice *device)
{
TabletToolButtonEvent event{
.device = device,
.button = button,
.pressed = isPressed,
.tabletToolId = tabletToolId,
@ -336,10 +337,10 @@ void KWin::TabletInputRedirection::tabletToolButtonEvent(uint button, bool isPre
input()->setLastInputHandler(this);
}
void KWin::TabletInputRedirection::tabletPadButtonEvent(uint button, bool isPressed,
const TabletPadId &tabletPadId, std::chrono::microseconds time)
void KWin::TabletInputRedirection::tabletPadButtonEvent(uint button, bool isPressed, const TabletPadId &tabletPadId, std::chrono::microseconds time, InputDevice *device)
{
TabletPadButtonEvent event{
.device = device,
.button = button,
.pressed = isPressed,
.tabletPadId = tabletPadId,
@ -350,10 +351,10 @@ void KWin::TabletInputRedirection::tabletPadButtonEvent(uint button, bool isPres
input()->setLastInputHandler(this);
}
void KWin::TabletInputRedirection::tabletPadStripEvent(int number, int position, bool isFinger,
const TabletPadId &tabletPadId, std::chrono::microseconds time)
void KWin::TabletInputRedirection::tabletPadStripEvent(int number, int position, bool isFinger, const TabletPadId &tabletPadId, std::chrono::microseconds time, InputDevice *device)
{
TabletPadStripEvent event{
.device = device,
.number = number,
.position = position,
.isFinger = isFinger,
@ -366,10 +367,10 @@ void KWin::TabletInputRedirection::tabletPadStripEvent(int number, int position,
input()->setLastInputHandler(this);
}
void KWin::TabletInputRedirection::tabletPadRingEvent(int number, int position, bool isFinger,
const TabletPadId &tabletPadId, std::chrono::microseconds time)
void KWin::TabletInputRedirection::tabletPadRingEvent(int number, int position, bool isFinger, const TabletPadId &tabletPadId, std::chrono::microseconds time, InputDevice *device)
{
TabletPadRingEvent event{
.device = device,
.number = number,
.position = position,
.isFinger = isFinger,

@ -45,12 +45,12 @@ public:
void tabletToolEvent(KWin::InputRedirection::TabletEventType type, const QPointF &pos,
qreal pressure, int xTilt, int yTilt, qreal rotation, bool tipDown,
bool tipNear, const TabletToolId &tabletToolId,
std::chrono::microseconds time);
void tabletToolButtonEvent(uint button, bool isPressed, const TabletToolId &tabletToolId, std::chrono::microseconds time);
void tabletPadButtonEvent(uint button, bool isPressed, const TabletPadId &tabletPadId, std::chrono::microseconds time);
void tabletPadStripEvent(int number, int position, bool isFinger, const TabletPadId &tabletPadId, std::chrono::microseconds time);
void tabletPadRingEvent(int number, int position, bool isFinger, const TabletPadId &tabletPadId, std::chrono::microseconds time);
std::chrono::microseconds time,
InputDevice *device);
void tabletToolButtonEvent(uint button, bool isPressed, const TabletToolId &tabletToolId, std::chrono::microseconds time, InputDevice *device);
void tabletPadButtonEvent(uint button, bool isPressed, const TabletPadId &tabletPadId, std::chrono::microseconds time, InputDevice *device);
void tabletPadStripEvent(int number, int position, bool isFinger, const TabletPadId &tabletPadId, std::chrono::microseconds time, InputDevice *device);
void tabletPadRingEvent(int number, int position, bool isFinger, const TabletPadId &tabletPadId, std::chrono::microseconds time, InputDevice *device);
bool positionValid() const override
{

Loading…
Cancel
Save